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:
jimmyandCursor committed 2026-10-06 16:58:47 +13:00
1 parent f7beac2095
commit 881e0ecaeb
5 files changed
+188 -196

No files matched your search

+58 -44
View File
@@ -1,9 +1,9 @@
#!/usr/bin/env python3
"""Drive-test all 8 WS2812 strips on led-driver-8 over UDP.
"""Drive-test all 8 WS2812 strips on led-driver-8 over DDP.
Protocol (port 50007):
- 1 + N×3 bytes: strip_id (0–7, or 255=all) + RGB
- 8 bytes PIN\\0 + strip + gpio + len_lo + len_hi
One DDP packet (UDP 4048, destination ID 1) carries every strip:
strip0 RGB | strip1 RGB | … | strip7 RGB
(equal LED count per strip). PUSH shows the frame.
Defaults match firmware board_config.h strip map.
@@ -17,10 +17,13 @@ from __future__ import annotations
import argparse
import socket
import struct
import time
NUM_STRIPS = 8
DEFAULT_STRIPS = (
# (strip_id, gpio)
# (strip_index, gpio)
(0, 18),
(1, 19),
(2, 20),
@@ -49,42 +52,55 @@ ALL_COLOURS = (
("WHITE", (255, 255, 255)),
)
DDP_VER1 = 0x40
DDP_PUSH = 0x01
DDP_TYPE_RGB888 = 0x0B
DDP_ID = 1
def pin_bind(sock: socket.socket, addr: tuple[str, int], strip: int, gpio: int, leds: int) -> None:
payload = bytes(
[
ord("P"),
ord("I"),
ord("N"),
0,
strip & 0xFF,
gpio & 0xFF,
leds & 0xFF,
(leds >> 8) & 0xFF,
]
)
sock.sendto(payload, addr)
# Stay under typical UDP/IPv4 MTU (1472). W5500 does not reassemble fragments.
# 10-byte DDP header → keep RGB chunks ≤ 1398 (multiple of 3).
DDP_MAX_DATA = 1398
def send_solid(
sock: socket.socket,
addr: tuple[str, int],
strip_id: int,
leds: int,
rgb: tuple[int, int, int],
) -> None:
sock.sendto(bytes([strip_id & 0xFF]) + bytes(rgb) * leds, addr)
def ddp_packet(rgb: bytes, *, offset: int = 0, push: bool = True) -> bytes:
flags = DDP_VER1 | (DDP_PUSH if push else 0)
header = struct.pack("!BBBBLH", flags, 0, DDP_TYPE_RGB888, DDP_ID, offset, len(rgb))
return header + rgb
def frame_from_strips(leds: int, colours: list[tuple[int, int, int]]) -> bytes:
"""Build strip0|…|strip7 payload; each strip is a solid colour × leds."""
if len(colours) != NUM_STRIPS:
raise ValueError(f"need {NUM_STRIPS} colours, got {len(colours)}")
parts = [bytes(rgb) * leds for rgb in colours]
return b"".join(parts)
def send_frame(sock: socket.socket, addr: tuple[str, int], payload: bytes) -> None:
"""Send one logical frame; split into MTU-safe DDP packets (PUSH on last)."""
if not payload:
sock.sendto(ddp_packet(b"", push=True), addr)
return
offset = 0
remaining = len(payload)
while remaining > 0:
chunk = min(remaining, DDP_MAX_DATA)
push = chunk >= remaining
sock.sendto(ddp_packet(payload[offset : offset + chunk], offset=offset, push=push), addr)
offset += chunk
remaining -= chunk
if remaining:
time.sleep(0.002)
def off_all(sock: socket.socket, addr: tuple[str, int], leds: int) -> None:
for strip, _gpio in DEFAULT_STRIPS:
send_solid(sock, addr, strip, leds, (0, 0, 0))
send_frame(sock, addr, frame_from_strips(leds, [(0, 0, 0)] * NUM_STRIPS))
def main() -> int:
parser = argparse.ArgumentParser(description="Test all 8 led-driver-8 strips over UDP")
parser = argparse.ArgumentParser(description="Test all 8 led-driver-8 strips over DDP")
parser.add_argument("--host", default="10.1.1.10", help="Panel IP (default: 10.1.1.10)")
parser.add_argument("--port", type=int, default=50007, help="UDP RGB port")
parser.add_argument("--port", type=int, default=4048, help="DDP UDP port")
parser.add_argument("--leds", type=int, default=64, help="LEDs lit per strip (capacity test)")
parser.add_argument("--pause", type=float, default=0.7, help="Seconds between steps")
parser.add_argument(
@@ -92,7 +108,6 @@ def main() -> int:
action="store_true",
help="Skip per-strip identity; only flash all strips together",
)
parser.add_argument("--no-bind", action="store_true", help="Skip PIN bind commands")
args = parser.parse_args()
if args.leds < 1:
@@ -100,28 +115,27 @@ def main() -> int:
addr = (args.host, args.port)
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
black = (0, 0, 0)
print(f"Testing {len(DEFAULT_STRIPS)} strips @ {args.host}:{args.port} ({args.leds} LEDs each)")
print(
f"Testing {NUM_STRIPS} strips @ {args.host}:{args.port} "
f"DDP ({args.leds} LEDs each, MTU-safe chunks)"
)
try:
if not args.no_bind:
for strip, gpio in DEFAULT_STRIPS:
pin_bind(sock, addr, strip, gpio, args.leds)
print(f" bind strip {strip} GP{gpio}")
time.sleep(0.02)
if not args.all_only:
print(" per-strip identity colours")
print(" per-strip identity colours (one packet each)")
for (strip, gpio), rgb in zip(DEFAULT_STRIPS, IDENTITY_COLOURS):
off_all(sock, addr, args.leds)
send_solid(sock, addr, strip, args.leds, rgb)
colours = [black] * NUM_STRIPS
colours[strip] = rgb
send_frame(sock, addr, frame_from_strips(args.leds, colours))
print(f" strip {strip} GP{gpio} -> {rgb}")
time.sleep(args.pause)
print(" all strips together (strip_id=255)")
print(" all strips together")
for label, rgb in ALL_COLOURS:
print(f" {label}")
send_solid(sock, addr, 255, args.leds, rgb)
send_frame(sock, addr, frame_from_strips(args.leds, [rgb] * NUM_STRIPS))
time.sleep(args.pause)
off_all(sock, addr, args.leds)