Switch panel firmware to DDP and match portal W5500 pinout.
Replace custom UDP RGB with DDP on 4048, fix picotool -f ordering for v1.1.2, and chunk test frames under MTU so the W5500 receives them. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
f7beac2095
commit
881e0ecaeb
5 files changed
+188
-196
No files matched your search
+1
-1
@@ -108,7 +108,7 @@ reconfigure:
|
||||
deploy: build
|
||||
@command -v picotool >/dev/null || { echo "Error: picotool not found"; exit 1; }
|
||||
@echo "==> Uploading $(UF2) over USB"
|
||||
@picotool load -x -f "$(UF2)"
|
||||
@picotool load -x "$(UF2)" -f
|
||||
|
||||
flash: deploy
|
||||
upload: deploy
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
#ifndef BOARD_CONFIG_H
|
||||
#define BOARD_CONFIG_H
|
||||
|
||||
/* W5500 on SPI1; eight WS2812 strips (portal UDP protocol) */
|
||||
/* W5500 on SPI1; eight WS2812 strips (DDP protocol) */
|
||||
|
||||
#define PIN_LED_STATUS 25
|
||||
|
||||
#define SPI_PORT spi1
|
||||
#define SPI_CLK_MHZ 15
|
||||
|
||||
/* This adapter board: CS=13, RST=9 (some portal PCBs use CS=9 / RST=13) */
|
||||
#define PIN_CS 13
|
||||
/* This adapter board: CS=9, RST=13 (some portal PCBs use CS=13 / RST=9) */
|
||||
#define PIN_CS 9
|
||||
#define PIN_SCK 10
|
||||
#define PIN_MOSI 11
|
||||
#define PIN_MISO 12
|
||||
#define PIN_RST 9
|
||||
#define PIN_RST 13
|
||||
|
||||
/* Strip 0 / 1 overridable; remaining pins fixed in DEFAULT_STRIP_PINS */
|
||||
#ifndef PIN_WS2812
|
||||
@@ -42,8 +42,8 @@
|
||||
#define SOCKET_DHCP 0
|
||||
#define SOCKET_UDP 1
|
||||
|
||||
/* UDP port (same as CircuitPython adapter / portal) */
|
||||
#define UDP_PORT 50007
|
||||
/* DDP (Distributed Display Protocol) default port */
|
||||
#define UDP_PORT 4048
|
||||
|
||||
/* Compile-time panel index for filtered frames (0–4). 255 = accept all. */
|
||||
#ifndef PANEL_ID
|
||||
|
||||
+100
-132
@@ -1,17 +1,15 @@
|
||||
/**
|
||||
* Portal panel firmware — W5500 UDP + WS2812 (Pico SDK).
|
||||
* Portal panel firmware — W5500 DDP + WS2812 (Pico SDK).
|
||||
*
|
||||
* UDP protocol (port 50007):
|
||||
* - N×3 bytes: raw RGB → strip 0 (N = 1…MAX_LEDS)
|
||||
* - 1 + N×3 bytes: strip_id (byte 0) + RGB
|
||||
* strip_id 0…MAX_STRIPS-1 → that strip
|
||||
* strip_id 255 → all active strips
|
||||
* - 5 bytes "PIN\\0" + gpio: bind strip 0 to gpio
|
||||
* - 8 bytes "PIN\\0" + strip + gpio + len_lo + len_hi: bind strip (len=0 → unset)
|
||||
* - 4 bytes "SHOW": reserved (frames already show on receive)
|
||||
* DDP (Distributed Display Protocol) on UDP 4048:
|
||||
* - 10-byte header (+4 if timecode flag set), then RGB payload
|
||||
* - destination ID 1 (or 255): one linear frame for all strips
|
||||
* - payload layout: strip0 RGB | strip1 RGB | … | strip7 RGB
|
||||
* (equal LED count per strip = total_pixels / MAX_STRIPS)
|
||||
* - offset = byte offset into that linear frame (network order)
|
||||
* - PUSH flag → split buffer onto strips and show
|
||||
*
|
||||
* One Pico can drive up to MAX_STRIPS displays on separate GPIOs.
|
||||
* Each strip’s pixel count comes from its own UDP frame length (strips may differ).
|
||||
* One Pico drives up to MAX_STRIPS displays on separate GPIOs.
|
||||
* MAX_LEDS is per-strip capacity.
|
||||
*/
|
||||
|
||||
@@ -35,6 +33,17 @@
|
||||
#define ETH_BUF_SIZE 2048
|
||||
#define DHCP_RETRY_MAX 10
|
||||
|
||||
#define DDP_HEADER_LEN 10
|
||||
#define DDP_HEADER_LEN_TIME 14
|
||||
#define DDP_FLAGS1_VER1 0x40
|
||||
#define DDP_FLAGS1_VER_MASK 0xc0
|
||||
#define DDP_FLAGS1_TIME 0x10
|
||||
#define DDP_FLAGS1_PUSH 0x01
|
||||
#define DDP_ID_DEFAULT 1
|
||||
#define DDP_ID_ALL 255
|
||||
|
||||
#define FRAME_RGB_BYTES ((uint32_t)MAX_STRIPS * (uint32_t)LED_RGB_BYTES)
|
||||
|
||||
static wiz_NetInfo g_net_info = {
|
||||
.mac = MAC_ADDR,
|
||||
.ip = STATIC_IP,
|
||||
@@ -49,10 +58,9 @@ static wiz_NetInfo g_net_info = {
|
||||
};
|
||||
|
||||
static uint8_t g_eth_buf[ETH_BUF_SIZE];
|
||||
static uint8_t g_pixel_buf[MAX_STRIPS][LED_RGB_BYTES];
|
||||
static uint16_t g_frame_pixels[MAX_STRIPS];
|
||||
static uint16_t g_strip_leds[MAX_STRIPS];
|
||||
static uint8_t g_frame_dirty[MAX_STRIPS];
|
||||
static uint8_t g_frame_buf[FRAME_RGB_BYTES];
|
||||
static uint32_t g_frame_end;
|
||||
static uint8_t g_need_show;
|
||||
static volatile uint16_t g_ms_tick;
|
||||
static uint8_t g_dhcp_ready;
|
||||
|
||||
@@ -116,7 +124,7 @@ static int udp_socket_open(void) {
|
||||
printf("UDP socket open failed: %d\n", sn);
|
||||
return -1;
|
||||
}
|
||||
printf("UDP listening on port %d\n", UDP_PORT);
|
||||
printf("DDP listening on UDP %d (1 packet, %d strips)\n", UDP_PORT, MAX_STRIPS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -143,131 +151,93 @@ static void led_boot_test(unsigned int strip) {
|
||||
ws2812_show(strip);
|
||||
}
|
||||
|
||||
static int buffer_frame(unsigned int strip, const uint8_t *rgb, uint16_t nbytes) {
|
||||
if (strip >= MAX_STRIPS || !ws2812_strip_active(strip)) {
|
||||
return -1;
|
||||
static void buffer_frame(uint32_t offset, const uint8_t *rgb, uint16_t nbytes) {
|
||||
if (nbytes == 0) {
|
||||
return;
|
||||
}
|
||||
if (nbytes == 0 || (nbytes % 3u) != 0) {
|
||||
return -1;
|
||||
if (offset >= FRAME_RGB_BYTES) {
|
||||
return;
|
||||
}
|
||||
uint16_t pixels = nbytes / 3u;
|
||||
if (pixels > MAX_LEDS) {
|
||||
pixels = MAX_LEDS;
|
||||
nbytes = (uint16_t)(pixels * 3u);
|
||||
uint32_t room = FRAME_RGB_BYTES - offset;
|
||||
if (nbytes > room) {
|
||||
nbytes = (uint16_t)room;
|
||||
}
|
||||
memcpy(g_pixel_buf[strip], rgb, nbytes);
|
||||
if (nbytes < LED_RGB_BYTES) {
|
||||
memset(g_pixel_buf[strip] + nbytes, 0, LED_RGB_BYTES - nbytes);
|
||||
}
|
||||
g_frame_pixels[strip] = pixels;
|
||||
g_frame_dirty[strip] = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void buffer_frame_all(const uint8_t *rgb, uint16_t nbytes) {
|
||||
for (unsigned int s = 0; s < MAX_STRIPS; s++) {
|
||||
if (ws2812_strip_active(s)) {
|
||||
buffer_frame(s, rgb, nbytes);
|
||||
}
|
||||
memcpy(g_frame_buf + offset, rgb, nbytes);
|
||||
uint32_t end = offset + nbytes;
|
||||
if (end > g_frame_end) {
|
||||
g_frame_end = end;
|
||||
}
|
||||
}
|
||||
|
||||
static void show_dirty_frames(void) {
|
||||
static void show_frame(void) {
|
||||
if (g_frame_end < (uint32_t)MAX_STRIPS * 3u) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t total_pixels = g_frame_end / 3u;
|
||||
uint16_t per_strip = (uint16_t)(total_pixels / (uint32_t)MAX_STRIPS);
|
||||
if (per_strip == 0) {
|
||||
return;
|
||||
}
|
||||
if (per_strip > MAX_LEDS) {
|
||||
per_strip = MAX_LEDS;
|
||||
}
|
||||
|
||||
uint32_t strip_bytes = (uint32_t)per_strip * 3u;
|
||||
for (unsigned int s = 0; s < MAX_STRIPS; s++) {
|
||||
if (!g_frame_dirty[s]) {
|
||||
if (!ws2812_strip_active(s)) {
|
||||
continue;
|
||||
}
|
||||
ws2812_set_rgb(s, g_pixel_buf[s], g_frame_pixels[s]);
|
||||
const uint8_t *rgb = g_frame_buf + (uint32_t)s * strip_bytes;
|
||||
ws2812_set_rgb(s, rgb, per_strip);
|
||||
ws2812_show(s);
|
||||
g_frame_dirty[s] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int pin_is_reserved(uint8_t pin) {
|
||||
switch (pin) {
|
||||
case PIN_CS:
|
||||
case PIN_SCK:
|
||||
case PIN_MOSI:
|
||||
case PIN_MISO:
|
||||
case PIN_RST:
|
||||
case PIN_LED_STATUS:
|
||||
return 1;
|
||||
default:
|
||||
return pin > 29;
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_pin_command(uint8_t strip, uint8_t pin, uint16_t leds) {
|
||||
if (strip >= MAX_STRIPS) {
|
||||
printf("PIN strip %u out of range (max %u)\n", (unsigned)strip, MAX_STRIPS);
|
||||
return;
|
||||
}
|
||||
if (pin_is_reserved(pin)) {
|
||||
printf("PIN GP%u rejected (reserved)\n", (unsigned)pin);
|
||||
return;
|
||||
}
|
||||
if (leds > MAX_LEDS) {
|
||||
printf("PIN leds %u clamped to max_leds=%u\n", (unsigned)leds, MAX_LEDS);
|
||||
leds = MAX_LEDS;
|
||||
}
|
||||
for (unsigned int s = 0; s < MAX_STRIPS; s++) {
|
||||
if (s != strip && ws2812_strip_active(s) && ws2812_get_pin(s) == pin) {
|
||||
printf("PIN GP%u: releasing strip %u\n", (unsigned)pin, s);
|
||||
ws2812_release_strip(s);
|
||||
g_strip_leds[s] = 0;
|
||||
g_frame_pixels[s] = 0;
|
||||
g_frame_dirty[s] = 0;
|
||||
}
|
||||
}
|
||||
if (ws2812_set_pin(strip, pin) != 0) {
|
||||
printf("PIN strip %u GP%u failed (no PIO SM?)\n", (unsigned)strip, (unsigned)pin);
|
||||
return;
|
||||
}
|
||||
g_strip_leds[strip] = leds;
|
||||
if (leds) {
|
||||
printf("strip %u ws2812=GP%u leds=%u\n", (unsigned)strip,
|
||||
(unsigned)ws2812_get_pin(strip), (unsigned)leds);
|
||||
} else {
|
||||
printf("strip %u ws2812=GP%u\n", (unsigned)strip, (unsigned)ws2812_get_pin(strip));
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_packet(const uint8_t *data, int16_t len) {
|
||||
if (len == 4 && memcmp(data, "SHOW", 4) == 0) {
|
||||
static void handle_ddp(const uint8_t *data, int16_t len) {
|
||||
if (len < DDP_HEADER_LEN) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (len == 5 && data[0] == 'P' && data[1] == 'I' && data[2] == 'N' && data[3] == 0) {
|
||||
handle_pin_command(0, data[4], 0);
|
||||
uint8_t flags1 = data[0];
|
||||
if ((flags1 & DDP_FLAGS1_VER_MASK) != DDP_FLAGS1_VER1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (len == 8 && data[0] == 'P' && data[1] == 'I' && data[2] == 'N' && data[3] == 0) {
|
||||
uint16_t leds = (uint16_t)data[6] | ((uint16_t)data[7] << 8);
|
||||
handle_pin_command(data[4], data[5], leds);
|
||||
return;
|
||||
}
|
||||
|
||||
if (len >= 3 && (len % 3) == 0) {
|
||||
buffer_frame(0, data, (uint16_t)len);
|
||||
return;
|
||||
}
|
||||
|
||||
if (len >= 4 && ((len - 1) % 3) == 0) {
|
||||
uint8_t id = data[0];
|
||||
uint16_t nbytes = (uint16_t)(len - 1);
|
||||
if (id == 255) {
|
||||
buffer_frame_all(data + 1, nbytes);
|
||||
uint8_t hdr_len = DDP_HEADER_LEN;
|
||||
if (flags1 & DDP_FLAGS1_TIME) {
|
||||
hdr_len = DDP_HEADER_LEN_TIME;
|
||||
if (len < hdr_len) {
|
||||
return;
|
||||
}
|
||||
if (id < MAX_STRIPS) {
|
||||
buffer_frame(id, data + 1, nbytes);
|
||||
return;
|
||||
}
|
||||
if (id == (uint8_t)PANEL_ID) {
|
||||
buffer_frame(0, data + 1, nbytes);
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t id = data[3];
|
||||
if (id != DDP_ID_DEFAULT && id != DDP_ID_ALL) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t offset = ((uint32_t)data[4] << 24) | ((uint32_t)data[5] << 16) |
|
||||
((uint32_t)data[6] << 8) | (uint32_t)data[7];
|
||||
uint16_t dlen = ((uint16_t)data[8] << 8) | (uint16_t)data[9];
|
||||
|
||||
int16_t avail = (int16_t)(len - hdr_len);
|
||||
if (avail < 0) {
|
||||
return;
|
||||
}
|
||||
if (dlen > (uint16_t)avail) {
|
||||
dlen = (uint16_t)avail;
|
||||
}
|
||||
|
||||
if (dlen > 0) {
|
||||
if (offset == 0) {
|
||||
g_frame_end = 0;
|
||||
}
|
||||
buffer_frame(offset, data + hdr_len, dlen);
|
||||
}
|
||||
|
||||
if (flags1 & DDP_FLAGS1_PUSH) {
|
||||
g_need_show = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,19 +257,15 @@ static void poll_udp(void) {
|
||||
if (n <= 0) {
|
||||
return;
|
||||
}
|
||||
handle_packet(g_eth_buf, n);
|
||||
handle_ddp(g_eth_buf, n);
|
||||
}
|
||||
}
|
||||
|
||||
static void print_strip_map(void) {
|
||||
printf("strips=%d", MAX_STRIPS);
|
||||
printf("strips=%d ddp=1pkt", MAX_STRIPS);
|
||||
for (unsigned int s = 0; s < MAX_STRIPS; s++) {
|
||||
if (ws2812_strip_active(s)) {
|
||||
if (g_strip_leds[s]) {
|
||||
printf(" [%u]=GP%u/%u", s, ws2812_get_pin(s), g_strip_leds[s]);
|
||||
} else {
|
||||
printf(" [%u]=GP%u", s, ws2812_get_pin(s));
|
||||
}
|
||||
printf(" [%u]=GP%u", s, ws2812_get_pin(s));
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
@@ -312,7 +278,7 @@ int main(void) {
|
||||
gpio_init(PIN_LED_STATUS);
|
||||
gpio_set_dir(PIN_LED_STATUS, GPIO_OUT);
|
||||
|
||||
printf("portal panel firmware (Pico SDK)\n");
|
||||
printf("portal panel firmware (Pico SDK, DDP)\n");
|
||||
printf("max_leds=%d max_strips=%d panel_id=%d mac=02:50:52:54:4C:%02X "
|
||||
"ip=%u.%u.%u.%u %s\n",
|
||||
MAX_LEDS, MAX_STRIPS, PANEL_ID, (unsigned)PANEL_ID, g_net_info.ip[0],
|
||||
@@ -326,10 +292,9 @@ int main(void) {
|
||||
wizchip_check();
|
||||
|
||||
ws2812_init(MAX_LEDS);
|
||||
memset(g_pixel_buf, 0, sizeof(g_pixel_buf));
|
||||
memset(g_frame_pixels, 0, sizeof(g_frame_pixels));
|
||||
memset(g_strip_leds, 0, sizeof(g_strip_leds));
|
||||
memset(g_frame_dirty, 0, sizeof(g_frame_dirty));
|
||||
memset(g_frame_buf, 0, sizeof(g_frame_buf));
|
||||
g_frame_end = 0;
|
||||
g_need_show = 0;
|
||||
|
||||
static const unsigned int default_pins[MAX_STRIPS] = DEFAULT_STRIP_PINS;
|
||||
for (unsigned int s = 0; s < MAX_STRIPS; s++) {
|
||||
@@ -355,7 +320,10 @@ int main(void) {
|
||||
DHCP_run();
|
||||
#endif
|
||||
poll_udp();
|
||||
show_dirty_frames();
|
||||
if (g_need_show) {
|
||||
show_frame();
|
||||
g_need_show = 0;
|
||||
}
|
||||
if (++heartbeat >= 500) {
|
||||
gpio_xor_mask(1u << PIN_LED_STATUS);
|
||||
heartbeat = 0;
|
||||
|
||||
Reference in new issue
Block a user