From 5e9c29da0df045b03ada9278c34f37b22349a6f7 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Thu, 25 Nov 2021 19:35:06 +0000 Subject: Tidy up adjustable ws2812 timing (#15299) --- drivers/ws2812.h | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/ws2812.h b/drivers/ws2812.h index f179fcb0ef..945b3d0728 100644 --- a/drivers/ws2812.h +++ b/drivers/ws2812.h @@ -17,11 +17,41 @@ #include "quantum/color.h" +/* + * The WS2812 datasheets define T1H 900ns, T0H 350ns, T1L 350ns, T0L 900ns. Hence, by default, these + * are chosen to be conservative and avoid problems rather than for maximum throughput; in the code, + * this is done by default using a WS2812_TIMING parameter that accounts for the whole window (1250ns) + * and defining T1H and T0H; T1L and T0L are obtained by subtracting their low counterparts from the window. + * + * However, there are certain "WS2812"-like LEDs, like the SK6812s, which work in a similar + * communication topology but use different timings for the window and the T1L, T1H, T0L and T0H. + * This means that, albeit the same driver being applicable, the timings must be adapted. + */ + +#ifndef WS2812_TIMING +# define WS2812_TIMING 1250 +#endif + +#ifndef WS2812_T1H +# define WS2812_T1H 900 // Width of a 1 bit in ns +#endif + +#ifndef WS2812_T1L +# define WS2812_T1L (WS2812_TIMING - WS2812_T1H) // Width of a 1 bit in ns +#endif + +#ifndef WS2812_T0H +# define WS2812_T0H 350 // Width of a 0 bit in ns +#endif + +#ifndef WS2812_T0L +# define WS2812_T0L (WS2812_TIMING - WS2812_T0H) // Width of a 0 bit in ns +#endif + /* * Older WS2812s can handle a reset time (TRST) of 50us, but recent * component revisions require a minimum of 280us. */ - #if !defined(WS2812_TRST_US) # define WS2812_TRST_US 280 #endif -- cgit v1.2.3