From 597d2e0e7bdc3f2629965a5b393b725e9ab8442b Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Thu, 3 Jun 2021 09:48:16 +1000 Subject: [PATCH] Fix up WS2812 SPI driver on F072. (#13022) --- docs/ws2812_driver.md | 14 +++++++----- drivers/chibios/ws2812_spi.c | 24 ++++++++++++++++---- keyboards/aeboards/ext65/rev2/config.h | 2 ++ keyboards/cannonkeys/an_c/config.h | 2 ++ keyboards/cannonkeys/atlas/config.h | 2 ++ keyboards/cannonkeys/db60/config.h | 2 ++ keyboards/cannonkeys/devastatingtkl/config.h | 2 ++ keyboards/cannonkeys/instant60/config.h | 2 ++ keyboards/cannonkeys/instant65/config.h | 2 ++ keyboards/cannonkeys/obliterated75/config.h | 2 ++ keyboards/cannonkeys/sagittarius/config.h | 2 ++ keyboards/cannonkeys/savage65/config.h | 2 ++ keyboards/cannonkeys/tmov2/config.h | 2 ++ keyboards/cannonkeys/tsukuyomi/config.h | 2 ++ keyboards/nebula12/config.h | 2 ++ keyboards/primekb/meridian/config.h | 2 ++ keyboards/projectkb/alice/rev1/config.h | 2 ++ keyboards/projectkb/alice/rev2/config.h | 2 ++ keyboards/zoo/wampus/config.h | 2 ++ 19 files changed, 61 insertions(+), 11 deletions(-) diff --git a/docs/ws2812_driver.md b/docs/ws2812_driver.md index e69400364cb9ab66a28fddd9d1deb67c771ee026..101798f211131e977566f85533b967edece23266 100644 --- a/docs/ws2812_driver.md +++ b/docs/ws2812_driver.md @@ -72,7 +72,9 @@ WS2812_DRIVER = spi Configure the hardware via your config.h: ```c #define WS2812_SPI SPID1 // default: SPID1 -#define WS2812_SPI_MOSI_PAL_MODE 5 // Pin "alternate function", see the respective datasheet for the appropriate values for your MCU. default: 5 +#define WS2812_SPI_MOSI_PAL_MODE 5 // MOSI pin "alternate function", see the respective datasheet for the appropriate values for your MCU. default: 5 +#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 +#define WS2812_SPI_SCK_PAL_MODE 5 // SCK pin "alternate function", see the respective datasheet for the appropriate values for your MCU. default: 5 ``` 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. While not an exhaustive list, the following table provides the scenarios that have been partially validated: -| | SPI1 | SPI2 | SPI3 | -|-|-|-|-| -| f072 | ? | B15 :heavy_check_mark: | N/A | -| f103 | A7 :heavy_check_mark: | B15 :heavy_check_mark: | N/A | -| f303 | A7 :heavy_check_mark: B5 :heavy_check_mark: | B15 :heavy_check_mark: | B5 :heavy_check_mark: | +| | SPI1 | SPI2 | SPI3 | +|------|---------------------------------------------|-----------------------------------------|-----------------------| +| f072 | ? | B15 :heavy_check_mark: (needs SCK: B13) | N/A | +| f103 | A7 :heavy_check_mark: | B15 :heavy_check_mark: | N/A | +| f303 | A7 :heavy_check_mark: B5 :heavy_check_mark: | B15 :heavy_check_mark: | B5 :heavy_check_mark: | *Other supported ChibiOS boards and/or pins may function, it will be highly chip and configuration dependent.* diff --git a/drivers/chibios/ws2812_spi.c b/drivers/chibios/ws2812_spi.c index e02cbabc02df01a8117223473772d5932eec08b7..377a929b9445f125cd063c760a121ae88664f09e 100644 --- a/drivers/chibios/ws2812_spi.c +++ b/drivers/chibios/ws2812_spi.c @@ -16,19 +16,23 @@ # define WS2812_SPI_MOSI_PAL_MODE 5 #endif +#ifndef WS2812_SPI_SCK_PAL_MODE +# define WS2812_SPI_SCK_PAL_MODE 5 +#endif + // Push Pull or Open Drain Configuration // Default Push Pull #ifndef WS2812_EXTERNAL_PULLUP # if defined(USE_GPIOV1) -# define WS2812_OUTPUT_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL +# define WS2812_MOSI_OUTPUT_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL # else -# define WS2812_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_SPI_MOSI_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL +# define WS2812_MOSI_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_SPI_MOSI_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL # endif #else # if defined(USE_GPIOV1) -# define WS2812_OUTPUT_MODE PAL_MODE_STM32_ALTERNATE_OPENDRAIN +# define WS2812_MOSI_OUTPUT_MODE PAL_MODE_STM32_ALTERNATE_OPENDRAIN # else -# define WS2812_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_SPI_MOSI_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN +# define WS2812_MOSI_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_SPI_MOSI_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN # endif #endif @@ -63,6 +67,12 @@ # define WS2812_SPI_BUFFER_MODE 0 // normal buffer #endif +#if defined(USE_GPIOV1) +# define WS2812_SCK_OUTPUT_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL +#else +# define WS2812_SCK_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_SPI_SCK_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL +#endif + #define BYTES_FOR_LED_BYTE 4 #define NB_COLORS 3 #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) { } void ws2812_init(void) { - palSetLineMode(RGB_DI_PIN, WS2812_OUTPUT_MODE); + palSetLineMode(RGB_DI_PIN, WS2812_MOSI_OUTPUT_MODE); + +#ifdef WS2812_SPI_SCK_PIN + palSetLineMode(WS2812_SPI_SCK_PIN, WS2812_SCK_OUTPUT_MODE); +#endif // WS2812_SPI_SCK_PIN // TODO: more dynamic baudrate static const SPIConfig spicfg = {WS2812_SPI_BUFFER_MODE, NULL, PAL_PORT(RGB_DI_PIN), PAL_PAD(RGB_DI_PIN), WS2812_SPI_DIVISOR}; diff --git a/keyboards/aeboards/ext65/rev2/config.h b/keyboards/aeboards/ext65/rev2/config.h index dc1bfb71c28c7890518959a4587278e071b63f53..778fc3ea6ce71d09e1f65515c463575452383085 100644 --- a/keyboards/aeboards/ext65/rev2/config.h +++ b/keyboards/aeboards/ext65/rev2/config.h @@ -51,6 +51,8 @@ along with this program. If not, see . //SPI #define WS2812_SPI SPID2 #define WS2812_SPI_MOSI_PAL_MODE 0 +#define WS2812_SPI_SCK_PAL_MODE 0 +#define WS2812_SPI_SCK_PIN B13 #define WS2812_EXTERNAL_PULLUP // I2C OLED defines diff --git a/keyboards/cannonkeys/an_c/config.h b/keyboards/cannonkeys/an_c/config.h index 922ea37b2be627dd0aeec64eb2b5546f592add0f..83e98c2e280435ddd163946bd06268b89079f29b 100644 --- a/keyboards/cannonkeys/an_c/config.h +++ b/keyboards/cannonkeys/an_c/config.h @@ -56,6 +56,8 @@ along with this program. If not, see . #define RGBLED_NUM 14 #define WS2812_SPI SPID2 #define WS2812_SPI_MOSI_PAL_MODE 0 +#define WS2812_SPI_SCK_PAL_MODE 0 +#define WS2812_SPI_SCK_PIN B13 /* * Feature disable options diff --git a/keyboards/cannonkeys/atlas/config.h b/keyboards/cannonkeys/atlas/config.h index 72ee927e2fa17c5a6a4a05f9908e27fc19e28032..1ba5c0fb0e97e9152920cad16c954f412b43a1c6 100644 --- a/keyboards/cannonkeys/atlas/config.h +++ b/keyboards/cannonkeys/atlas/config.h @@ -50,6 +50,8 @@ along with this program. If not, see . #define RGB_DI_PIN B15 #define RGBLED_NUM 22 #define WS2812_SPI_MOSI_PAL_MODE 0 +#define WS2812_SPI_SCK_PAL_MODE 0 +#define WS2812_SPI_SCK_PIN B13 /* * Feature disable options diff --git a/keyboards/cannonkeys/db60/config.h b/keyboards/cannonkeys/db60/config.h index db7269071cbdd9e20b5b36248fcc7c4c8543c31b..dc2007c17cbe5c321705b2cba2003859fa77f4d8 100644 --- a/keyboards/cannonkeys/db60/config.h +++ b/keyboards/cannonkeys/db60/config.h @@ -55,6 +55,8 @@ along with this program. If not, see . #define RGB_DI_PIN B15 #define RGBLED_NUM 20 #define WS2812_SPI_MOSI_PAL_MODE 0 +#define WS2812_SPI_SCK_PAL_MODE 0 +#define WS2812_SPI_SCK_PIN B13 /* * Feature disable options diff --git a/keyboards/cannonkeys/devastatingtkl/config.h b/keyboards/cannonkeys/devastatingtkl/config.h index 15c0d4e35647ad0f20bde4ec06133b8a7564a955..0a76a3466fc97b6439acfc5558be5928c842103f 100644 --- a/keyboards/cannonkeys/devastatingtkl/config.h +++ b/keyboards/cannonkeys/devastatingtkl/config.h @@ -56,6 +56,8 @@ along with this program. If not, see . #define RGBLED_NUM 20 #define WS2812_SPI SPID2 #define WS2812_SPI_MOSI_PAL_MODE 0 +#define WS2812_SPI_SCK_PAL_MODE 0 +#define WS2812_SPI_SCK_PIN B13 /* * Feature disable options diff --git a/keyboards/cannonkeys/instant60/config.h b/keyboards/cannonkeys/instant60/config.h index bd0ae316021f404d6b95b0832adb32f759fdac82..d34bc0003e8f87950fe20c210102b40dc4ce6216 100644 --- a/keyboards/cannonkeys/instant60/config.h +++ b/keyboards/cannonkeys/instant60/config.h @@ -56,6 +56,8 @@ along with this program. If not, see . #define RGBLED_NUM 14 #define WS2812_SPI SPID2 #define WS2812_SPI_MOSI_PAL_MODE 0 +#define WS2812_SPI_SCK_PAL_MODE 0 +#define WS2812_SPI_SCK_PIN B13 /* * Feature disable options diff --git a/keyboards/cannonkeys/instant65/config.h b/keyboards/cannonkeys/instant65/config.h index ecfb55fe006a222db8c1899df28c2517d1d4218e..dc097494b2ebaf4859c128580bb5d2a304183fea 100644 --- a/keyboards/cannonkeys/instant65/config.h +++ b/keyboards/cannonkeys/instant65/config.h @@ -56,6 +56,8 @@ along with this program. If not, see . #define RGBLED_NUM 20 #define WS2812_SPI SPID2 #define WS2812_SPI_MOSI_PAL_MODE 0 +#define WS2812_SPI_SCK_PAL_MODE 0 +#define WS2812_SPI_SCK_PIN B13 /* diff --git a/keyboards/cannonkeys/obliterated75/config.h b/keyboards/cannonkeys/obliterated75/config.h index b2edfecd3da1d00707a5e3f3ceefbd388a829bcd..7a8a7ff28cbe98c2195b329ba9dc5580d70d3c1e 100644 --- a/keyboards/cannonkeys/obliterated75/config.h +++ b/keyboards/cannonkeys/obliterated75/config.h @@ -56,6 +56,8 @@ along with this program. If not, see . #define RGBLED_NUM 20 #define WS2812_SPI SPID2 #define WS2812_SPI_MOSI_PAL_MODE 0 +#define WS2812_SPI_SCK_PAL_MODE 0 +#define WS2812_SPI_SCK_PIN B13 /* diff --git a/keyboards/cannonkeys/sagittarius/config.h b/keyboards/cannonkeys/sagittarius/config.h index 6c1648713e64c90871e93a21ab5b0c73650849ee..a263ebc71312dc36cbf9a24d8c1651f2dc44a86a 100644 --- a/keyboards/cannonkeys/sagittarius/config.h +++ b/keyboards/cannonkeys/sagittarius/config.h @@ -60,6 +60,8 @@ along with this program. If not, see . #define RGBLED_NUM 8 #define WS2812_SPI SPID2 #define WS2812_SPI_MOSI_PAL_MODE 0 +#define WS2812_SPI_SCK_PAL_MODE 0 +#define WS2812_SPI_SCK_PIN B13 #define DYNAMIC_KEYMAP_LAYER_COUNT 2 diff --git a/keyboards/cannonkeys/savage65/config.h b/keyboards/cannonkeys/savage65/config.h index 07672643ed2260f3503aea0d9203434dd338bd11..3c3166c9193876da54c6ef89a9ad0ed44b03e647 100644 --- a/keyboards/cannonkeys/savage65/config.h +++ b/keyboards/cannonkeys/savage65/config.h @@ -56,6 +56,8 @@ along with this program. If not, see . #define RGBLED_NUM 20 #define WS2812_SPI SPID2 #define WS2812_SPI_MOSI_PAL_MODE 0 +#define WS2812_SPI_SCK_PAL_MODE 0 +#define WS2812_SPI_SCK_PIN B13 /* diff --git a/keyboards/cannonkeys/tmov2/config.h b/keyboards/cannonkeys/tmov2/config.h index 5f44584e0d2715d41c5d3f7cf9bd97dada53a217..cddff4ce7eb33c594b46b13848d7a7fd6e63aa07 100644 --- a/keyboards/cannonkeys/tmov2/config.h +++ b/keyboards/cannonkeys/tmov2/config.h @@ -56,6 +56,8 @@ along with this program. If not, see . #define RGBLED_NUM 22 #define WS2812_SPI SPID2 #define WS2812_SPI_MOSI_PAL_MODE 0 +#define WS2812_SPI_SCK_PAL_MODE 0 +#define WS2812_SPI_SCK_PIN B13 /* * Feature disable options diff --git a/keyboards/cannonkeys/tsukuyomi/config.h b/keyboards/cannonkeys/tsukuyomi/config.h index 00cd0eee99a2933e84bfbe76947658ad8356a17c..d3e955450fbfb78e10fb60002d1e1d833e260134 100644 --- a/keyboards/cannonkeys/tsukuyomi/config.h +++ b/keyboards/cannonkeys/tsukuyomi/config.h @@ -56,6 +56,8 @@ along with this program. If not, see . #define RGBLED_NUM 20 #define WS2812_SPI SPID2 #define WS2812_SPI_MOSI_PAL_MODE 0 +#define WS2812_SPI_SCK_PAL_MODE 0 +#define WS2812_SPI_SCK_PIN B13 /* diff --git a/keyboards/nebula12/config.h b/keyboards/nebula12/config.h index 6f596beb37388c09a42a15a19ab00494255081de..da9fd105757cd04edf8e254a7b81425fdb4e699b 100755 --- a/keyboards/nebula12/config.h +++ b/keyboards/nebula12/config.h @@ -100,6 +100,8 @@ along with this program. If not, see . #define WS2812_SPI SPID2 // default: SPID1 #define WS2812_SPI_MOSI_PAL_MODE 0 // Pin "alternate function", see the respective datasheet for the appropriate values for your MCU. default: 5 +#define WS2812_SPI_SCK_PAL_MODE 0 +#define WS2812_SPI_SCK_PIN B13 #define RGB_DI_PIN B15 #ifdef RGB_DI_PIN diff --git a/keyboards/primekb/meridian/config.h b/keyboards/primekb/meridian/config.h index 9194023abb33434947032a17199b7e63e566e002..082392c6bd2cbec564021b771e31deaf1600db8d 100644 --- a/keyboards/primekb/meridian/config.h +++ b/keyboards/primekb/meridian/config.h @@ -36,6 +36,8 @@ along with this program. If not, see . #define RGBLED_NUM 3 #define WS2812_SPI SPID2 #define WS2812_SPI_MOSI_PAL_MODE 0 +#define WS2812_SPI_SCK_PAL_MODE 0 +#define WS2812_SPI_SCK_PIN B13 /* Set 0 if debouncing isn't needed */ #define DEBOUNCE 5 diff --git a/keyboards/projectkb/alice/rev1/config.h b/keyboards/projectkb/alice/rev1/config.h index fcf9817fa313e050d618d03a185efab4a8ea0a89..05180c756f8e9f154730b0d9792b170a12ed7402 100644 --- a/keyboards/projectkb/alice/rev1/config.h +++ b/keyboards/projectkb/alice/rev1/config.h @@ -56,6 +56,8 @@ along with this program. If not, see . #define RGBLED_NUM 14 #define WS2812_SPI SPID2 #define WS2812_SPI_MOSI_PAL_MODE 0 +#define WS2812_SPI_SCK_PAL_MODE 0 +#define WS2812_SPI_SCK_PIN B13 #define INDICATOR_PIN_0 A0 #define INDICATOR_PIN_1 A1 diff --git a/keyboards/projectkb/alice/rev2/config.h b/keyboards/projectkb/alice/rev2/config.h index 174889d62881bee80f9ee89e47d31c5146b598b0..0b017936c58cfda13dc3adb5fbdd05d59db974be 100644 --- a/keyboards/projectkb/alice/rev2/config.h +++ b/keyboards/projectkb/alice/rev2/config.h @@ -56,6 +56,8 @@ along with this program. If not, see . #define RGBLED_NUM 14 #define WS2812_SPI SPID2 #define WS2812_SPI_MOSI_PAL_MODE 0 +#define WS2812_SPI_SCK_PAL_MODE 0 +#define WS2812_SPI_SCK_PIN B13 #define INDICATOR_PIN_0 A9 #define INDICATOR_PIN_1 A8 diff --git a/keyboards/zoo/wampus/config.h b/keyboards/zoo/wampus/config.h index c3a13ec355e06f1a1d31e3081ba4d89d1fc87e78..f572c91fc7f030025d4f8ee73c5230fab4eba6ae 100644 --- a/keyboards/zoo/wampus/config.h +++ b/keyboards/zoo/wampus/config.h @@ -67,6 +67,8 @@ along with this program. If not, see . // SPI RGB Driver #define WS2812_SPI SPID2 #define WS2812_SPI_MOSI_PAL_MODE 0 +#define WS2812_SPI_SCK_PAL_MODE 0 +#define WS2812_SPI_SCK_PIN B13 // OLED defines #define OLED_TIMEOUT 60000