Skip to content

Commit a082441

Browse files
authored
Fix up WS2812 SPI driver on F072. (qmk#13022)
1 parent 8b32bf5 commit a082441

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

docs/ws2812_driver.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ WS2812_DRIVER = spi
7272
Configure the hardware via your config.h:
7373
```c
7474
#define WS2812_SPI SPID1 // default: SPID1
75-
#define WS2812_SPI_MOSI_PAL_MODE 5 // Pin "alternate function", see the respective datasheet for the appropriate values for your MCU. default: 5
75+
#define WS2812_SPI_MOSI_PAL_MODE 5 // MOSI pin "alternate function", see the respective datasheet for the appropriate values for your MCU. default: 5
76+
#define WS2812_SPI_SCK_PIN B3 // Required for F072, may be for others -- SCK pin, see the respective datasheet for the appropriate values for your MCU. default: unspecified
77+
#define WS2812_SPI_SCK_PAL_MODE 5 // SCK pin "alternate function", see the respective datasheet for the appropriate values for your MCU. default: 5
7678
```
7779
7880
You must also turn on the SPI feature in your halconf.h and mcuconf.h
@@ -100,11 +102,11 @@ Only divisors of 2, 4, 8, 16, 32, 64, 128 and 256 are supported by hardware.
100102

101103
While not an exhaustive list, the following table provides the scenarios that have been partially validated:
102104

103-
| | SPI1 | SPI2 | SPI3 |
104-
|-|-|-|-|
105-
| f072 | ? | B15 :heavy_check_mark: | N/A |
106-
| f103 | A7 :heavy_check_mark: | B15 :heavy_check_mark: | N/A |
107-
| f303 | A7 :heavy_check_mark: B5 :heavy_check_mark: | B15 :heavy_check_mark: | B5 :heavy_check_mark: |
105+
| | SPI1 | SPI2 | SPI3 |
106+
|------|---------------------------------------------|-----------------------------------------|-----------------------|
107+
| f072 | ? | B15 :heavy_check_mark: (needs SCK: B13) | N/A |
108+
| f103 | A7 :heavy_check_mark: | B15 :heavy_check_mark: | N/A |
109+
| f303 | A7 :heavy_check_mark: B5 :heavy_check_mark: | B15 :heavy_check_mark: | B5 :heavy_check_mark: |
108110

109111
*Other supported ChibiOS boards and/or pins may function, it will be highly chip and configuration dependent.*
110112

drivers/chibios/ws2812_spi.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,23 @@
1616
# define WS2812_SPI_MOSI_PAL_MODE 5
1717
#endif
1818

19+
#ifndef WS2812_SPI_SCK_PAL_MODE
20+
# define WS2812_SPI_SCK_PAL_MODE 5
21+
#endif
22+
1923
// Push Pull or Open Drain Configuration
2024
// Default Push Pull
2125
#ifndef WS2812_EXTERNAL_PULLUP
2226
# if defined(USE_GPIOV1)
23-
# define WS2812_OUTPUT_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL
27+
# define WS2812_MOSI_OUTPUT_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL
2428
# else
25-
# define WS2812_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_SPI_MOSI_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL
29+
# define WS2812_MOSI_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_SPI_MOSI_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL
2630
# endif
2731
#else
2832
# if defined(USE_GPIOV1)
29-
# define WS2812_OUTPUT_MODE PAL_MODE_STM32_ALTERNATE_OPENDRAIN
33+
# define WS2812_MOSI_OUTPUT_MODE PAL_MODE_STM32_ALTERNATE_OPENDRAIN
3034
# else
31-
# define WS2812_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_SPI_MOSI_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN
35+
# define WS2812_MOSI_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_SPI_MOSI_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN
3236
# endif
3337
#endif
3438

@@ -63,6 +67,12 @@
6367
# define WS2812_SPI_BUFFER_MODE 0 // normal buffer
6468
#endif
6569

70+
#if defined(USE_GPIOV1)
71+
# define WS2812_SCK_OUTPUT_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL
72+
#else
73+
# define WS2812_SCK_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_SPI_SCK_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL
74+
#endif
75+
6676
#define BYTES_FOR_LED_BYTE 4
6777
#define NB_COLORS 3
6878
#define BYTES_FOR_LED (BYTES_FOR_LED_BYTE * NB_COLORS)
@@ -109,7 +119,11 @@ static void set_led_color_rgb(LED_TYPE color, int pos) {
109119
}
110120

111121
void ws2812_init(void) {
112-
palSetLineMode(RGB_DI_PIN, WS2812_OUTPUT_MODE);
122+
palSetLineMode(RGB_DI_PIN, WS2812_MOSI_OUTPUT_MODE);
123+
124+
#ifdef WS2812_SPI_SCK_PIN
125+
palSetLineMode(WS2812_SPI_SCK_PIN, WS2812_SCK_OUTPUT_MODE);
126+
#endif // WS2812_SPI_SCK_PIN
113127

114128
// TODO: more dynamic baudrate
115129
static const SPIConfig spicfg = {WS2812_SPI_BUFFER_MODE, NULL, PAL_PORT(RGB_DI_PIN), PAL_PAD(RGB_DI_PIN), WS2812_SPI_DIVISOR};

0 commit comments

Comments
 (0)