mirror of
https://github.com/openstenoproject/qmk
synced 2024-11-10 10:39:09 +00:00
STM32 WS2812 Open Drain Configuration (#9414)
* update docs stm32 only and applies to all 3 driver * cformat
This commit is contained in:
parent
b43bdc1c69
commit
c785148445
4 changed files with 54 additions and 11 deletions
|
@ -99,3 +99,14 @@ While not an exhaustive list, the following table provides the scenarios that ha
|
|||
| f401/f411 | :heavy_check_mark: |
|
||||
|
||||
*Other supported ChibiOS boards and/or pins may function, it will be highly chip and configuration dependent.*
|
||||
|
||||
### Push Pull and Open Drain Configuration
|
||||
The default configuration is a push pull on the defined pin.
|
||||
This can be configured for bitbang, PWM and SPI.
|
||||
|
||||
Note: This only applies to STM32 boards.
|
||||
|
||||
To configure the `RGB_DI_PIN` to open drain configuration add this to your config.h file:
|
||||
```c
|
||||
#define WS2812_EXTERNAL_PULLUP
|
||||
```
|
||||
|
|
|
@ -14,6 +14,14 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
// Push Pull or Open Drain Configuration
|
||||
// Default Push Pull
|
||||
#ifndef WS2812_EXTERNAL_PULLUP
|
||||
# define WS2812_OUTPUT_MODE PAL_MODE_OUTPUT_PUSHPULL
|
||||
#else
|
||||
# define WS2812_OUTPUT_MODE PAL_MODE_OUTPUT_OPENDRAIN
|
||||
#endif
|
||||
|
||||
#define NUMBER_NOPS 6
|
||||
#define CYCLES_PER_SEC (STM32_SYSCLK / NUMBER_NOPS * NOP_FUDGE)
|
||||
#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
|
||||
|
@ -66,7 +74,7 @@ void sendByte(uint8_t byte) {
|
|||
}
|
||||
}
|
||||
|
||||
void ws2812_init(void) { setPinOutput(RGB_DI_PIN); }
|
||||
void ws2812_init(void) { palSetLineMode(RGB_DI_PIN, WS2812_OUTPUT_MODE); }
|
||||
|
||||
// Setleds for standard RGB
|
||||
void ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) {
|
||||
|
|
|
@ -24,6 +24,22 @@
|
|||
# define WS2812_DMA_CHANNEL 2 // DMA Channel for TIMx_UP
|
||||
#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
|
||||
# else
|
||||
# define WS2812_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_PWM_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUPDR_FLOATING
|
||||
# endif
|
||||
#else
|
||||
# if defined(USE_GPIOV1)
|
||||
# define WS2812_OUTPUT_MODE PAL_MODE_STM32_ALTERNATE_OPENDRAIN
|
||||
# else
|
||||
# define WS2812_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_PWM_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUPDR_FLOATING
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef WS2812_PWM_TARGET_PERIOD
|
||||
//# define WS2812_PWM_TARGET_PERIOD 800000 // Original code is 800k...?
|
||||
# define WS2812_PWM_TARGET_PERIOD 80000 // TODO: work out why 10x less on f303/f4x1
|
||||
|
@ -142,11 +158,7 @@ void ws2812_init(void) {
|
|||
for (i = 0; i < WS2812_COLOR_BIT_N; i++) ws2812_frame_buffer[i] = WS2812_DUTYCYCLE_0; // All color bits are zero duty cycle
|
||||
for (i = 0; i < WS2812_RESET_BIT_N; i++) ws2812_frame_buffer[i + WS2812_COLOR_BIT_N] = 0; // All reset bits are zero
|
||||
|
||||
#if defined(USE_GPIOV1)
|
||||
palSetLineMode(RGB_DI_PIN, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
|
||||
#else
|
||||
palSetLineMode(RGB_DI_PIN, PAL_MODE_ALTERNATE(WS2812_PWM_PAL_MODE) | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUPDR_FLOATING);
|
||||
#endif
|
||||
palSetLineMode(RGB_DI_PIN, WS2812_OUTPUT_MODE);
|
||||
|
||||
// PWM Configuration
|
||||
//#pragma GCC diagnostic ignored "-Woverride-init" // Turn off override-init warning for this struct. We use the overriding ability to set a "default" channel config
|
||||
|
|
|
@ -16,6 +16,22 @@
|
|||
# define WS2812_SPI_MOSI_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
|
||||
# else
|
||||
# define WS2812_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
|
||||
# else
|
||||
# define WS2812_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_SPI_MOSI_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define BYTES_FOR_LED_BYTE 4
|
||||
#define NB_COLORS 3
|
||||
#define BYTES_FOR_LED (BYTES_FOR_LED_BYTE * NB_COLORS)
|
||||
|
@ -52,11 +68,7 @@ static void set_led_color_rgb(LED_TYPE color, int pos) {
|
|||
}
|
||||
|
||||
void ws2812_init(void) {
|
||||
#if defined(USE_GPIOV1)
|
||||
palSetLineMode(RGB_DI_PIN, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
|
||||
#else
|
||||
palSetLineMode(RGB_DI_PIN, PAL_MODE_ALTERNATE(WS2812_SPI_MOSI_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL);
|
||||
#endif
|
||||
palSetLineMode(RGB_DI_PIN, WS2812_OUTPUT_MODE);
|
||||
|
||||
// TODO: more dynamic baudrate
|
||||
static const SPIConfig spicfg = {
|
||||
|
|
Loading…
Reference in a new issue