ESPHome 2026.12.0-dev
Loading...
Searching...
No Matches
pixoo.h
Go to the documentation of this file.
1#pragma once
2
8
9namespace esphome::pixoo {
10
11// The Pixoo's main board (where ESPHome runs) talks to a separate LED-driver board (a GD32/AT32
12// MCU) over SPI using Divoom's packet protocol:
13// 0xAA, len_lo, len_hi, cmd, <data...>, 0xBB
14// The image is sent as a DATA (0x00) packet carrying width*height*3 bytes of RGB888; brightness is
15// a separate LIGHT (0x01) command; the LED current is set once via SET_RGB_IOUT (0x22). Command
16// packets are padded out to the LED board's 240-byte DMA chunk with an UNUSED (0x21) packet.
17// The model selects the (square) panel side length.
18enum PixooModel : uint8_t {
20};
21
22static constexpr size_t PACKET_STATIC_LEN = 5; // header + tail
23
24class Pixoo : public display::Display,
25 public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING,
26 spi::DATA_RATE_8MHZ> {
27 public:
28 // frame_buffer holds frame_size(model) bytes, word-aligned for the SPI DMA transfer.
29 Pixoo(PixooModel model, uint8_t *frame_buffer) : model_(model), frame_buffer_(frame_buffer) {}
30
31 // RGB888 image bytes.
32 static constexpr size_t data_size(PixooModel model) { return static_cast<size_t>(model) * model * 3; }
33 // Full SPI frame: a DATA packet (header + RGB888 + tail), then a DMA-chunk-sized UNUSED packet so the
34 // LED board completes its final DMA block.
35 static constexpr size_t frame_size(PixooModel model) { return data_size(model) + PACKET_STATIC_LEN + DMA_CHUNK; }
36
37 void setup() override;
38 void update() override;
39 void dump_config() override;
40 float get_setup_priority() const override;
41
42 // Brightness is controlled exclusively via the light platform: send a LIGHT command to the LED
43 // board (brightness 0..1 -> 0..100%).
44 void set_panel_brightness(float brightness);
45
47
48 void fill(Color color) override;
49 void draw_pixel_at(int x, int y, Color color) override;
50
51 protected:
52 void draw_pixels_internal(int x_start, int y_start, int w, int h, const uint8_t *ptr, display::ColorBitness bitness,
53 bool big_endian, int x_offset, int y_offset, int x_pad) override;
54
55 int get_width_internal() override { return static_cast<int>(this->model_); }
56 int get_height_internal() override { return static_cast<int>(this->model_); }
57
58 void set_pixel_(uint32_t index, Color color);
59 void send_command_(uint8_t cmd, const uint8_t *data, uint16_t len);
60
61 // Size of the LED board's SPI DMA chunk; the command scratch buffer is one chunk.
62 static constexpr size_t DMA_CHUNK = 240;
63
65
67 uint8_t *frame_buffer_;
69};
70
71} // namespace esphome::pixoo
int int int const uint8_t ColorOrder ColorBitness bitness
Definition display.h:394
int int int const uint8_t ColorOrder ColorBitness bool int int y_offset
Definition display.h:394
int int int const uint8_t ColorOrder ColorBitness bool int int int x_pad
Definition display.h:394
int int int const uint8_t * ptr
Definition display.h:393
int int int const uint8_t ColorOrder ColorBitness bool big_endian
Definition display.h:394
int int int const uint8_t ColorOrder ColorBitness bool int x_offset
Definition display.h:394
uint8_t cmd_buffer_[DMA_CHUNK]
Definition pixoo.h:68
int get_width_internal() override
Definition pixoo.h:55
void send_command_(uint8_t cmd, const uint8_t *data, uint16_t len)
Definition pixoo.cpp:72
void fill(Color color) override
Definition pixoo.cpp:160
static constexpr size_t frame_size(PixooModel model)
Definition pixoo.h:35
void setup() override
Definition pixoo.cpp:46
split_buffer::SplitBuffer buffer_
Definition pixoo.h:66
PixooModel model_
Definition pixoo.h:64
void set_panel_brightness(float brightness)
Definition pixoo.cpp:82
int get_height_internal() override
Definition pixoo.h:56
void set_pixel_(uint32_t index, Color color)
Definition pixoo.cpp:97
void draw_pixel_at(int x, int y, Color color) override
Definition pixoo.cpp:104
static constexpr size_t DMA_CHUNK
Definition pixoo.h:62
float get_setup_priority() const override
Definition pixoo.cpp:44
display::DisplayType get_display_type() override
Definition pixoo.h:46
uint8_t * frame_buffer_
Definition pixoo.h:67
void update() override
Definition pixoo.cpp:87
Pixoo(PixooModel model, uint8_t *frame_buffer)
Definition pixoo.h:29
void draw_pixels_internal(int x_start, int y_start, int w, int h, const uint8_t *ptr, display::ColorBitness bitness, bool big_endian, int x_offset, int y_offset, int x_pad) override
void dump_config() override
Definition pixoo.cpp:173
static constexpr size_t data_size(PixooModel model)
Definition pixoo.h:32
The SPIDevice is what components using the SPI will create.
Definition spi.h:445
A SplitBuffer allocates a large memory buffer potentially as multiple smaller buffers to facilitate a...
const void size_t len
Definition hal.h:68
static void uint32_t
uint16_t x
Definition tt21100.cpp:5
uint16_t y
Definition tt21100.cpp:6