Fix up WS2812 SPI driver on F072. (#13022)
This commit is contained in:
parent
35dbe8ba03
commit
597d2e0e7b
19 changed files with 61 additions and 11 deletions
|
@ -72,7 +72,9 @@ WS2812_DRIVER = spi
|
||||||
Configure the hardware via your config.h:
|
Configure the hardware via your config.h:
|
||||||
```c
|
```c
|
||||||
#define WS2812_SPI SPID1 // default: SPID1
|
#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
|
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:
|
While not an exhaustive list, the following table provides the scenarios that have been partially validated:
|
||||||
|
|
||||||
| | SPI1 | SPI2 | SPI3 |
|
| | SPI1 | SPI2 | SPI3 |
|
||||||
|-|-|-|-|
|
|------|---------------------------------------------|-----------------------------------------|-----------------------|
|
||||||
| f072 | ? | B15 :heavy_check_mark: | N/A |
|
| f072 | ? | B15 :heavy_check_mark: (needs SCK: B13) | N/A |
|
||||||
| f103 | A7 :heavy_check_mark: | 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: |
|
| 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.*
|
*Other supported ChibiOS boards and/or pins may function, it will be highly chip and configuration dependent.*
|
||||||
|
|
||||||
|
|
|
@ -16,19 +16,23 @@
|
||||||
# define WS2812_SPI_MOSI_PAL_MODE 5
|
# define WS2812_SPI_MOSI_PAL_MODE 5
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef WS2812_SPI_SCK_PAL_MODE
|
||||||
|
# define WS2812_SPI_SCK_PAL_MODE 5
|
||||||
|
#endif
|
||||||
|
|
||||||
// Push Pull or Open Drain Configuration
|
// Push Pull or Open Drain Configuration
|
||||||
// Default Push Pull
|
// Default Push Pull
|
||||||
#ifndef WS2812_EXTERNAL_PULLUP
|
#ifndef WS2812_EXTERNAL_PULLUP
|
||||||
# if defined(USE_GPIOV1)
|
# if defined(USE_GPIOV1)
|
||||||
# define WS2812_OUTPUT_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL
|
# define WS2812_MOSI_OUTPUT_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL
|
||||||
# else
|
# 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
|
# endif
|
||||||
#else
|
#else
|
||||||
# if defined(USE_GPIOV1)
|
# if defined(USE_GPIOV1)
|
||||||
# define WS2812_OUTPUT_MODE PAL_MODE_STM32_ALTERNATE_OPENDRAIN
|
# define WS2812_MOSI_OUTPUT_MODE PAL_MODE_STM32_ALTERNATE_OPENDRAIN
|
||||||
# else
|
# 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
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -63,6 +67,12 @@
|
||||||
# define WS2812_SPI_BUFFER_MODE 0 // normal buffer
|
# define WS2812_SPI_BUFFER_MODE 0 // normal buffer
|
||||||
#endif
|
#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 BYTES_FOR_LED_BYTE 4
|
||||||
#define NB_COLORS 3
|
#define NB_COLORS 3
|
||||||
#define BYTES_FOR_LED (BYTES_FOR_LED_BYTE * NB_COLORS)
|
#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) {
|
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
|
// 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};
|
static const SPIConfig spicfg = {WS2812_SPI_BUFFER_MODE, NULL, PAL_PORT(RGB_DI_PIN), PAL_PAD(RGB_DI_PIN), WS2812_SPI_DIVISOR};
|
||||||
|
|
|
@ -51,6 +51,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
//SPI
|
//SPI
|
||||||
#define WS2812_SPI SPID2
|
#define WS2812_SPI SPID2
|
||||||
#define WS2812_SPI_MOSI_PAL_MODE 0
|
#define WS2812_SPI_MOSI_PAL_MODE 0
|
||||||
|
#define WS2812_SPI_SCK_PAL_MODE 0
|
||||||
|
#define WS2812_SPI_SCK_PIN B13
|
||||||
#define WS2812_EXTERNAL_PULLUP
|
#define WS2812_EXTERNAL_PULLUP
|
||||||
|
|
||||||
// I2C OLED defines
|
// I2C OLED defines
|
||||||
|
|
|
@ -56,6 +56,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#define RGBLED_NUM 14
|
#define RGBLED_NUM 14
|
||||||
#define WS2812_SPI SPID2
|
#define WS2812_SPI SPID2
|
||||||
#define WS2812_SPI_MOSI_PAL_MODE 0
|
#define WS2812_SPI_MOSI_PAL_MODE 0
|
||||||
|
#define WS2812_SPI_SCK_PAL_MODE 0
|
||||||
|
#define WS2812_SPI_SCK_PIN B13
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Feature disable options
|
* Feature disable options
|
||||||
|
|
|
@ -50,6 +50,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#define RGB_DI_PIN B15
|
#define RGB_DI_PIN B15
|
||||||
#define RGBLED_NUM 22
|
#define RGBLED_NUM 22
|
||||||
#define WS2812_SPI_MOSI_PAL_MODE 0
|
#define WS2812_SPI_MOSI_PAL_MODE 0
|
||||||
|
#define WS2812_SPI_SCK_PAL_MODE 0
|
||||||
|
#define WS2812_SPI_SCK_PIN B13
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Feature disable options
|
* Feature disable options
|
||||||
|
|
|
@ -55,6 +55,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#define RGB_DI_PIN B15
|
#define RGB_DI_PIN B15
|
||||||
#define RGBLED_NUM 20
|
#define RGBLED_NUM 20
|
||||||
#define WS2812_SPI_MOSI_PAL_MODE 0
|
#define WS2812_SPI_MOSI_PAL_MODE 0
|
||||||
|
#define WS2812_SPI_SCK_PAL_MODE 0
|
||||||
|
#define WS2812_SPI_SCK_PIN B13
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Feature disable options
|
* Feature disable options
|
||||||
|
|
|
@ -56,6 +56,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#define RGBLED_NUM 20
|
#define RGBLED_NUM 20
|
||||||
#define WS2812_SPI SPID2
|
#define WS2812_SPI SPID2
|
||||||
#define WS2812_SPI_MOSI_PAL_MODE 0
|
#define WS2812_SPI_MOSI_PAL_MODE 0
|
||||||
|
#define WS2812_SPI_SCK_PAL_MODE 0
|
||||||
|
#define WS2812_SPI_SCK_PIN B13
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Feature disable options
|
* Feature disable options
|
||||||
|
|
|
@ -56,6 +56,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#define RGBLED_NUM 14
|
#define RGBLED_NUM 14
|
||||||
#define WS2812_SPI SPID2
|
#define WS2812_SPI SPID2
|
||||||
#define WS2812_SPI_MOSI_PAL_MODE 0
|
#define WS2812_SPI_MOSI_PAL_MODE 0
|
||||||
|
#define WS2812_SPI_SCK_PAL_MODE 0
|
||||||
|
#define WS2812_SPI_SCK_PIN B13
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Feature disable options
|
* Feature disable options
|
||||||
|
|
|
@ -56,6 +56,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#define RGBLED_NUM 20
|
#define RGBLED_NUM 20
|
||||||
#define WS2812_SPI SPID2
|
#define WS2812_SPI SPID2
|
||||||
#define WS2812_SPI_MOSI_PAL_MODE 0
|
#define WS2812_SPI_MOSI_PAL_MODE 0
|
||||||
|
#define WS2812_SPI_SCK_PAL_MODE 0
|
||||||
|
#define WS2812_SPI_SCK_PIN B13
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -56,6 +56,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#define RGBLED_NUM 20
|
#define RGBLED_NUM 20
|
||||||
#define WS2812_SPI SPID2
|
#define WS2812_SPI SPID2
|
||||||
#define WS2812_SPI_MOSI_PAL_MODE 0
|
#define WS2812_SPI_MOSI_PAL_MODE 0
|
||||||
|
#define WS2812_SPI_SCK_PAL_MODE 0
|
||||||
|
#define WS2812_SPI_SCK_PIN B13
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -60,6 +60,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#define RGBLED_NUM 8
|
#define RGBLED_NUM 8
|
||||||
#define WS2812_SPI SPID2
|
#define WS2812_SPI SPID2
|
||||||
#define WS2812_SPI_MOSI_PAL_MODE 0
|
#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
|
#define DYNAMIC_KEYMAP_LAYER_COUNT 2
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#define RGBLED_NUM 20
|
#define RGBLED_NUM 20
|
||||||
#define WS2812_SPI SPID2
|
#define WS2812_SPI SPID2
|
||||||
#define WS2812_SPI_MOSI_PAL_MODE 0
|
#define WS2812_SPI_MOSI_PAL_MODE 0
|
||||||
|
#define WS2812_SPI_SCK_PAL_MODE 0
|
||||||
|
#define WS2812_SPI_SCK_PIN B13
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -56,6 +56,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#define RGBLED_NUM 22
|
#define RGBLED_NUM 22
|
||||||
#define WS2812_SPI SPID2
|
#define WS2812_SPI SPID2
|
||||||
#define WS2812_SPI_MOSI_PAL_MODE 0
|
#define WS2812_SPI_MOSI_PAL_MODE 0
|
||||||
|
#define WS2812_SPI_SCK_PAL_MODE 0
|
||||||
|
#define WS2812_SPI_SCK_PIN B13
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Feature disable options
|
* Feature disable options
|
||||||
|
|
|
@ -56,6 +56,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#define RGBLED_NUM 20
|
#define RGBLED_NUM 20
|
||||||
#define WS2812_SPI SPID2
|
#define WS2812_SPI SPID2
|
||||||
#define WS2812_SPI_MOSI_PAL_MODE 0
|
#define WS2812_SPI_MOSI_PAL_MODE 0
|
||||||
|
#define WS2812_SPI_SCK_PAL_MODE 0
|
||||||
|
#define WS2812_SPI_SCK_PIN B13
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -100,6 +100,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
#define WS2812_SPI SPID2 // default: SPID1
|
#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_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
|
#define RGB_DI_PIN B15
|
||||||
#ifdef RGB_DI_PIN
|
#ifdef RGB_DI_PIN
|
||||||
|
|
|
@ -36,6 +36,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#define RGBLED_NUM 3
|
#define RGBLED_NUM 3
|
||||||
#define WS2812_SPI SPID2
|
#define WS2812_SPI SPID2
|
||||||
#define WS2812_SPI_MOSI_PAL_MODE 0
|
#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 */
|
/* Set 0 if debouncing isn't needed */
|
||||||
#define DEBOUNCE 5
|
#define DEBOUNCE 5
|
||||||
|
|
|
@ -56,6 +56,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#define RGBLED_NUM 14
|
#define RGBLED_NUM 14
|
||||||
#define WS2812_SPI SPID2
|
#define WS2812_SPI SPID2
|
||||||
#define WS2812_SPI_MOSI_PAL_MODE 0
|
#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_0 A0
|
||||||
#define INDICATOR_PIN_1 A1
|
#define INDICATOR_PIN_1 A1
|
||||||
|
|
|
@ -56,6 +56,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#define RGBLED_NUM 14
|
#define RGBLED_NUM 14
|
||||||
#define WS2812_SPI SPID2
|
#define WS2812_SPI SPID2
|
||||||
#define WS2812_SPI_MOSI_PAL_MODE 0
|
#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_0 A9
|
||||||
#define INDICATOR_PIN_1 A8
|
#define INDICATOR_PIN_1 A8
|
||||||
|
|
|
@ -67,6 +67,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
// SPI RGB Driver
|
// SPI RGB Driver
|
||||||
#define WS2812_SPI SPID2
|
#define WS2812_SPI SPID2
|
||||||
#define WS2812_SPI_MOSI_PAL_MODE 0
|
#define WS2812_SPI_MOSI_PAL_MODE 0
|
||||||
|
#define WS2812_SPI_SCK_PAL_MODE 0
|
||||||
|
#define WS2812_SPI_SCK_PIN B13
|
||||||
|
|
||||||
// OLED defines
|
// OLED defines
|
||||||
#define OLED_TIMEOUT 60000
|
#define OLED_TIMEOUT 60000
|
||||||
|
|
Loading…
Reference in a new issue