aboutsummaryrefslogtreecommitdiff
path: root/platforms/chibios
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2021-11-25 19:35:06 +0000
committerGitHub <noreply@github.com>2021-11-25 19:35:06 +0000
commit5e9c29da0df045b03ada9278c34f37b22349a6f7 (patch)
tree3dbe67afa346513de1132e23c636b5ad01bc3550 /platforms/chibios
parent3d0062071133ad76504ede49a66063115c4a06c5 (diff)
downloadqmk_firmware-5e9c29da0df045b03ada9278c34f37b22349a6f7.tar.gz
qmk_firmware-5e9c29da0df045b03ada9278c34f37b22349a6f7.zip
Tidy up adjustable ws2812 timing (#15299)
Diffstat (limited to 'platforms/chibios')
-rw-r--r--platforms/chibios/drivers/ws2812.c36
-rw-r--r--platforms/chibios/drivers/ws2812_pwm.c2
-rw-r--r--platforms/chibios/drivers/ws2812_spi.c2
3 files changed, 8 insertions, 32 deletions
diff --git a/platforms/chibios/drivers/ws2812.c b/platforms/chibios/drivers/ws2812.c
index 8c882c8ee..7e870661d 100644
--- a/platforms/chibios/drivers/ws2812.c
+++ b/platforms/chibios/drivers/ws2812.c
@@ -22,6 +22,12 @@
22# define WS2812_OUTPUT_MODE PAL_MODE_OUTPUT_OPENDRAIN 22# define WS2812_OUTPUT_MODE PAL_MODE_OUTPUT_OPENDRAIN
23#endif 23#endif
24 24
25// The reset gap can be 6000 ns, but depending on the LED strip it may have to be increased
26// to values like 600000 ns. If it is too small, the pixels will show nothing most of the time.
27#ifndef WS2812_RES
28# define WS2812_RES (1000 * WS2812_TRST_US) // Width of the low gap between bits to cause a frame to latch
29#endif
30
25#define NUMBER_NOPS 6 31#define NUMBER_NOPS 6
26#define CYCLES_PER_SEC (CPU_CLOCK / NUMBER_NOPS * NOP_FUDGE) 32#define CYCLES_PER_SEC (CPU_CLOCK / NUMBER_NOPS * NOP_FUDGE)
27#define NS_PER_SEC (1000000000L) // Note that this has to be SIGNED since we want to be able to check for negative values of derivatives 33#define NS_PER_SEC (1000000000L) // Note that this has to be SIGNED since we want to be able to check for negative values of derivatives
@@ -40,36 +46,6 @@
40 } \ 46 } \
41 } while (0) 47 } while (0)
42 48
43/* 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.
44However, 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. The following defines are done such that the adjustment of these timings can be done in the keyboard's config.h; if nothing is said, the defines default to the WS2812 ones.
45*/
46
47#ifndef WS2812_TIMING
48# define WS2812_TIMING 1250
49#endif
50
51#ifndef WS2812_T1H
52# define WS2812_T1H 900 // Width of a 1 bit in ns
53#endif
54
55#ifndef WS2812_T1L
56# define WS2812_T1L (WS2812_TIMING - WS2812_T1H) // Width of a 1 bit in ns
57#endif
58
59#ifndef WS2812_T0H
60# define WS2812_T0H 350 // Width of a 0 bit in ns
61#endif
62
63#ifndef WS2812_T0L
64# define WS2812_T0L (WS2812_TIMING - WS2812_T0H) // Width of a 0 bit in ns
65#endif
66
67// The reset gap can be 6000 ns, but depending on the LED strip it may have to be increased
68// to values like 600000 ns. If it is too small, the pixels will show nothing most of the time.
69#ifndef WS2812_RES
70# define WS2812_RES (1000 * WS2812_TRST_US) // Width of the low gap between bits to cause a frame to latch
71#endif
72
73void sendByte(uint8_t byte) { 49void sendByte(uint8_t byte) {
74 // WS2812 protocol wants most significant bits first 50 // WS2812 protocol wants most significant bits first
75 for (unsigned char bit = 0; bit < 8; bit++) { 51 for (unsigned char bit = 0; bit < 8; bit++) {
diff --git a/platforms/chibios/drivers/ws2812_pwm.c b/platforms/chibios/drivers/ws2812_pwm.c
index c17b9cd4e..19ea3cfe8 100644
--- a/platforms/chibios/drivers/ws2812_pwm.c
+++ b/platforms/chibios/drivers/ws2812_pwm.c
@@ -71,7 +71,7 @@
71 * Calculate the number of zeroes to add at the end assuming 1.25 uS/bit: 71 * Calculate the number of zeroes to add at the end assuming 1.25 uS/bit:
72 */ 72 */
73#define WS2812_COLOR_BITS (WS2812_CHANNELS * 8) 73#define WS2812_COLOR_BITS (WS2812_CHANNELS * 8)
74#define WS2812_RESET_BIT_N (1000 * WS2812_TRST_US / 1250) 74#define WS2812_RESET_BIT_N (1000 * WS2812_TRST_US / WS2812_TIMING)
75#define WS2812_COLOR_BIT_N (RGBLED_NUM * WS2812_COLOR_BITS) /**< Number of data bits */ 75#define WS2812_COLOR_BIT_N (RGBLED_NUM * WS2812_COLOR_BITS) /**< Number of data bits */
76#define WS2812_BIT_N (WS2812_COLOR_BIT_N + WS2812_RESET_BIT_N) /**< Total number of bits in a frame */ 76#define WS2812_BIT_N (WS2812_COLOR_BIT_N + WS2812_RESET_BIT_N) /**< Total number of bits in a frame */
77 77
diff --git a/platforms/chibios/drivers/ws2812_spi.c b/platforms/chibios/drivers/ws2812_spi.c
index 62722f466..ba471e0b8 100644
--- a/platforms/chibios/drivers/ws2812_spi.c
+++ b/platforms/chibios/drivers/ws2812_spi.c
@@ -77,7 +77,7 @@
77#endif 77#endif
78#define BYTES_FOR_LED (BYTES_FOR_LED_BYTE * WS2812_CHANNELS) 78#define BYTES_FOR_LED (BYTES_FOR_LED_BYTE * WS2812_CHANNELS)
79#define DATA_SIZE (BYTES_FOR_LED * RGBLED_NUM) 79#define DATA_SIZE (BYTES_FOR_LED * RGBLED_NUM)
80#define RESET_SIZE (1000 * WS2812_TRST_US / (2 * 1250)) 80#define RESET_SIZE (1000 * WS2812_TRST_US / (2 * WS2812_TIMING))
81#define PREAMBLE_SIZE 4 81#define PREAMBLE_SIZE 4
82 82
83static uint8_t txbuf[PREAMBLE_SIZE + DATA_SIZE + RESET_SIZE] = {0}; 83static uint8_t txbuf[PREAMBLE_SIZE + DATA_SIZE + RESET_SIZE] = {0};