Skip to content

Add WS2811BB bit-banged LED driver for BK7231N (Action HDMI sync box) - #2312

Open
NassimDIB wants to merge 2 commits into
openshwprojects:mainfrom
NassimDIB:add-ws2811bb-driver
Open

NassimDIB wants to merge 2 commits into
openshwprojects:mainfrom
NassimDIB:add-ws2811bb-driver

Conversation

@NassimDIB

@NassimDIB NassimDIB commented Nov 16, 2026 •

Copy link
Copy Markdown

This adds a WS2811BB driver: a bit-banged single-wire driver for WS2811/WS2812 style strips on the BK7231N, plugged into the shared LED layer (drv_leds_shared). SM16703P_Init, SM16703P_SetPixel, SM16703P_Start and the DDP driver work on top of it, so a strip can be driven in real time from Hyperion (udpddp).

It was written for the Action "LSC Smart Connect HDMI Sync Box" (Tuya based, BK7231N/CBU), following the discussion in https://www.elektroda.com/rtvforum/topic4123137.html. On that box, P0 and P8 are the two inputs of a NOR gate whose output is the strip data line: P8 must be held low (pin role AlwaysLow) and the data goes out on P0 (pin role UCS1912_DIN) as inverted WS2812B (idle high, pulses low). P0 is UART2_TXD, so SPI is not an option, hence bit-banging. Pinout credit: emarck, in the thread above.

How it works

  • The GPIO config register is written directly, with interrupts disabled during one frame.
  • The send loop is a separate function placed in a dedicated section (.text.WS2811BB_SendRam) so that it can run from ITCM, where instruction fetch time is constant.
  • Commands: WS2811BB_Timing n0h n0l n1h n1l (loop iterations), WS2811BB_Invert 0|1 (default 1), WS2811BB_Calib (measures the real bit period, result in the log).
  • ENABLE_DRIVER_WS2811BB is enabled for the standard BK7231N SDK build only (PLATFORM_BK7231N && !PLATFORM_BEKEN_NEW), not for OpenBK7231N_ALT (beken_freertos_sdk), where it has not been tested.

Dependency on the SDK (separate repository)
For reliable timing the function above must actually be linked into ITCM. That needs one line in the SDK linker script bk7231n_ota.ld (*(.text.WS2811BB_SendRam)), which lives in openshwprojects/OpenBK7231N: openshwprojects/OpenBK7231N#30. Without it the code runs from flash. I tried exactly that: with Hyperion streaming frames over DDP the strip visibly flickered (observed by eye; the measured delay-loop iteration was about 87 ns instead of about 55 ns with ITCM, so the pulse widths also move). Code placed in .data RAM crashed the device (watchdog), ITCM works.

Note: this PR compiles and works on its own, but until that SDK change is merged and the sdk/OpenBK7231N submodule here points to a commit that contains it, the send loop stays in flash and the output will flicker.

Testing

  • Hardware: one Action HDMI sync box, 28 pixels, GRB, 12 V strip. Verified with solid colours, individual pixels, a rainbow over DDP, and live video through Hyperion.
  • Build: compiles on main (168cba5) and on tag 1.18.219 for OpenBK7231N; CI is green, including the OpenBK7231N_ALT builds where the driver is not enabled.
  • Not tested: other BK7231N boards, other strip lengths, other timings. Interrupts are off for the whole frame, so the driver caps a frame at 450 bytes (150 RGB pixels).

Questions for the maintainers

  • Is a driver tied to a linker-script line acceptable, or would you prefer another way to get the function into ITCM?
  • The repository currently has no licence file. Would you consider adding an open licence? It would make contributions like this one clearer for everyone. (Our own code in this PR is MIT.)

Documentation and build notes: https://github.com/NassimDIB/hdmi-sync-box-ambilight

Disclosure: this work was developed with the help of Claude Code (Anthropic); all results were checked on real hardware.

Single-wire WS2811/WS2812 driver that plugs into the shared LED layer, so
SM16703P_Init/SetPixel/Start and the DDP driver work on top of it. Written
for the Action HDMI sync box, where the data goes out on P0 (UCS1912_DIN)
as inverted WS2812B with P8 held low (AlwaysLow).

The send loop is placed in section .text.WS2811BB_SendRam so it can run
from ITCM; this needs a matching line in the SDK linker script
(openshwprojects/OpenBK7231N). Enabled for PLATFORM_BK7231N only.
The OpenBK7231N_ALT build uses sdk/beken_freertos_sdk (PLATFORM_BEKEN_NEW)
and an explicit source list in platforms/obk_main.mk, so drv_ws2811bb.c was
not compiled there and drv_main.c failed to link (undefined reference to
WS2811BB_Init/WS2811BB_Shutdown). The driver relies on the standard SDK
linker script (ITCM section), headers and interrupt macros, and has not been
tested on the ALT SDK, so it is not enabled there.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant