From 1d1f6d7c3005373bbce241bbb4a1779d8ad1c90d Mon Sep 17 00:00:00 2001 From: Jan Vos Date: Thu, 26 Nov 2026 13:10:34 +0100 Subject: [PATCH 1/2] Send the whole chip ID with every frame Frames now go out as block type 0x55aa, with all 8 bytes of the RP2350's chip ID between the pixel header and the pixels, in the ID's byte order. A receiver has the ID with the first frame instead of after two, so it no longer has to hold a frame back for it. The header, pixel header and ID are five words in the TX FIFO before start_spi(); joined, it holds eight. --- src/dmdreader.cpp | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/dmdreader.cpp b/src/dmdreader.cpp index e0e7dcc..ea74f6b 100644 --- a/src/dmdreader.cpp +++ b/src/dmdreader.cpp @@ -23,12 +23,10 @@ typedef struct buf32_t { // SPI data types and header blocks // header block length should always be a multiple of 32bit #define SPI_BLOCK_PIX 0xcc33 // DMD frame -// DMD frame with 4 more bytes between its header and its pixels. Receivers -// that know nothing of them skip them. They carry half of the RP2350's chip -// ID, the half named in the pixel header's padding (SPI_CHIP_ID_TAG | half), -// so that a receiver has the whole ID after two frames. -#define SPI_BLOCK_PIX_ID 0x44ee -#define SPI_CHIP_ID_TAG 0xc100 +// DMD frame with the RP2350's whole ID, 8 bytes, between its pixel header +// and its pixels, so that a receiver has the ID with the first frame. It +// replaces 0x44ee, which carried half of the ID per frame. +#define SPI_BLOCK_PIX_ID 0x55aa typedef struct __attribute__((__packed__)) block_header_t { uint16_t block_type; // block type @@ -44,10 +42,9 @@ typedef struct __attribute__((__packed__)) block_pix_header_t { block_header_t h = {}; block_pix_header_t ph = {}; -// The chip ID's bytes 0..3 and 4..7, each sent as one word, most significant +// The ID's bytes 0..3 and 4..7, each sent as one word, most significant // byte first, so that they arrive in the ID's order. -uint32_t chip_id_halves[2] = {}; -uint8_t chip_id_half = 0; +uint32_t id_words[2] = {}; DmdType dmd_type; @@ -275,11 +272,11 @@ bool spi_send_pix(uint8_t *pixbuf, bool skip_when_busy) { if (spi_busy()) return false; } - ph.padding = SPI_CHIP_ID_TAG | chip_id_half; + // Five words before the pixels: the joined TX FIFO holds eight, so this + // does not block before start_spi() lets the receiver clock them out. spi_send_blocking((uint32_t *)&h, sizeof(h)); spi_send_blocking((uint32_t *)&ph, sizeof(ph)); - spi_send_blocking(&chip_id_halves[chip_id_half], sizeof(uint32_t)); - chip_id_half ^= 1; + spi_send_blocking(id_words, sizeof(id_words)); spi_send_dma((uint32_t *)pixbuf, target_bytes); start_spi(); @@ -1602,14 +1599,14 @@ void dmdreader_spi_init() { // Set up SPI header h.len = (((target_bytes + 3) / 4) * 4) + sizeof(h) + sizeof(ph) + - sizeof(uint32_t); + sizeof(id_words); h.block_type = SPI_BLOCK_PIX_ID; pico_unique_board_id_t id; pico_get_unique_board_id(&id); - for (int half = 0; half < 2; half++) { - const uint8_t *b = id.id + 4 * half; - chip_id_halves[half] = (uint32_t(b[0]) << 24) | (uint32_t(b[1]) << 16) | - (uint32_t(b[2]) << 8) | b[3]; + for (int word = 0; word < 2; word++) { + const uint8_t *b = id.id + 4 * word; + id_words[word] = (uint32_t(b[0]) << 24) | (uint32_t(b[1]) << 16) | + (uint32_t(b[2]) << 8) | b[3]; } ph.columns = source_width; ph.rows = source_height; From 636bc4c4dd01e204a8d209f817e3fe7fb5e5cbad Mon Sep 17 00:00:00 2001 From: Jan Vos Date: Thu, 26 Nov 2026 13:42:36 +0100 Subject: [PATCH 2/2] Clarify comment for SPI_BLOCK_PIX_ID definition, removing outdated reference to previous ID format --- src/dmdreader.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/dmdreader.cpp b/src/dmdreader.cpp index ea74f6b..e93be80 100644 --- a/src/dmdreader.cpp +++ b/src/dmdreader.cpp @@ -24,8 +24,7 @@ typedef struct buf32_t { // header block length should always be a multiple of 32bit #define SPI_BLOCK_PIX 0xcc33 // DMD frame // DMD frame with the RP2350's whole ID, 8 bytes, between its pixel header -// and its pixels, so that a receiver has the ID with the first frame. It -// replaces 0x44ee, which carried half of the ID per frame. +// and its pixels, so that a receiver has the ID with the first frame. #define SPI_BLOCK_PIX_ID 0x55aa typedef struct __attribute__((__packed__)) block_header_t {