aboutsummaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/chibios/ws2812.c10
-rw-r--r--drivers/chibios/ws2812_pwm.c22
-rw-r--r--drivers/chibios/ws2812_spi.c22
3 files changed, 43 insertions, 11 deletions
diff --git a/drivers/chibios/ws2812.c b/drivers/chibios/ws2812.c
index bdca565d8..2c2d9fb2d 100644
--- a/drivers/chibios/ws2812.c
+++ b/drivers/chibios/ws2812.c
@@ -14,6 +14,14 @@
14# endif 14# endif
15#endif 15#endif
16 16
17// Push Pull or Open Drain Configuration
18// Default Push Pull
19#ifndef WS2812_EXTERNAL_PULLUP
20# define WS2812_OUTPUT_MODE PAL_MODE_OUTPUT_PUSHPULL
21#else
22# define WS2812_OUTPUT_MODE PAL_MODE_OUTPUT_OPENDRAIN
23#endif
24
17#define NUMBER_NOPS 6 25#define NUMBER_NOPS 6
18#define CYCLES_PER_SEC (STM32_SYSCLK / NUMBER_NOPS * NOP_FUDGE) 26#define CYCLES_PER_SEC (STM32_SYSCLK / NUMBER_NOPS * NOP_FUDGE)
19#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 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
@@ -66,7 +74,7 @@ void sendByte(uint8_t byte) {
66 } 74 }
67} 75}
68 76
69void ws2812_init(void) { setPinOutput(RGB_DI_PIN); } 77void ws2812_init(void) { palSetLineMode(RGB_DI_PIN, WS2812_OUTPUT_MODE); }
70 78
71// Setleds for standard RGB 79// Setleds for standard RGB
72void ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) { 80void ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) {
diff --git a/drivers/chibios/ws2812_pwm.c b/drivers/chibios/ws2812_pwm.c
index 1a1721029..ba45d0042 100644
--- a/drivers/chibios/ws2812_pwm.c
+++ b/drivers/chibios/ws2812_pwm.c
@@ -24,6 +24,22 @@
24# define WS2812_DMA_CHANNEL 2 // DMA Channel for TIMx_UP 24# define WS2812_DMA_CHANNEL 2 // DMA Channel for TIMx_UP
25#endif 25#endif
26 26
27// Push Pull or Open Drain Configuration
28// Default Push Pull
29#ifndef WS2812_EXTERNAL_PULLUP
30# if defined(USE_GPIOV1)
31# define WS2812_OUTPUT_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL
32# else
33# define WS2812_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_PWM_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUPDR_FLOATING
34# endif
35#else
36# if defined(USE_GPIOV1)
37# define WS2812_OUTPUT_MODE PAL_MODE_STM32_ALTERNATE_OPENDRAIN
38# else
39# define WS2812_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_PWM_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUPDR_FLOATING
40# endif
41#endif
42
27#ifndef WS2812_PWM_TARGET_PERIOD 43#ifndef WS2812_PWM_TARGET_PERIOD
28//# define WS2812_PWM_TARGET_PERIOD 800000 // Original code is 800k...? 44//# define WS2812_PWM_TARGET_PERIOD 800000 // Original code is 800k...?
29# define WS2812_PWM_TARGET_PERIOD 80000 // TODO: work out why 10x less on f303/f4x1 45# define WS2812_PWM_TARGET_PERIOD 80000 // TODO: work out why 10x less on f303/f4x1
@@ -142,11 +158,7 @@ void ws2812_init(void) {
142 for (i = 0; i < WS2812_COLOR_BIT_N; i++) ws2812_frame_buffer[i] = WS2812_DUTYCYCLE_0; // All color bits are zero duty cycle 158 for (i = 0; i < WS2812_COLOR_BIT_N; i++) ws2812_frame_buffer[i] = WS2812_DUTYCYCLE_0; // All color bits are zero duty cycle
143 for (i = 0; i < WS2812_RESET_BIT_N; i++) ws2812_frame_buffer[i + WS2812_COLOR_BIT_N] = 0; // All reset bits are zero 159 for (i = 0; i < WS2812_RESET_BIT_N; i++) ws2812_frame_buffer[i + WS2812_COLOR_BIT_N] = 0; // All reset bits are zero
144 160
145#if defined(USE_GPIOV1) 161 palSetLineMode(RGB_DI_PIN, WS2812_OUTPUT_MODE);
146 palSetLineMode(RGB_DI_PIN, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
147#else
148 palSetLineMode(RGB_DI_PIN, PAL_MODE_ALTERNATE(WS2812_PWM_PAL_MODE) | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUPDR_FLOATING);
149#endif
150 162
151 // PWM Configuration 163 // PWM Configuration
152 //#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 164 //#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
diff --git a/drivers/chibios/ws2812_spi.c b/drivers/chibios/ws2812_spi.c
index 36e08e39e..3bbada7fe 100644
--- a/drivers/chibios/ws2812_spi.c
+++ b/drivers/chibios/ws2812_spi.c
@@ -16,6 +16,22 @@
16# define WS2812_SPI_MOSI_PAL_MODE 5 16# define WS2812_SPI_MOSI_PAL_MODE 5
17#endif 17#endif
18 18
19// Push Pull or Open Drain Configuration
20// Default Push Pull
21#ifndef WS2812_EXTERNAL_PULLUP
22# if defined(USE_GPIOV1)
23# define WS2812_OUTPUT_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL
24# else
25# define WS2812_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_SPI_MOSI_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL
26# endif
27#else
28# if defined(USE_GPIOV1)
29# define WS2812_OUTPUT_MODE PAL_MODE_STM32_ALTERNATE_OPENDRAIN
30# else
31# define WS2812_OUTPUT_MODE PAL_MODE_ALTERNATE(WS2812_SPI_MOSI_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN
32# endif
33#endif
34
19#define BYTES_FOR_LED_BYTE 4 35#define BYTES_FOR_LED_BYTE 4
20#define NB_COLORS 3 36#define NB_COLORS 3
21#define BYTES_FOR_LED (BYTES_FOR_LED_BYTE * NB_COLORS) 37#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) {
52} 68}
53 69
54void ws2812_init(void) { 70void ws2812_init(void) {
55#if defined(USE_GPIOV1) 71 palSetLineMode(RGB_DI_PIN, WS2812_OUTPUT_MODE);
56 palSetLineMode(RGB_DI_PIN, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
57#else
58 palSetLineMode(RGB_DI_PIN, PAL_MODE_ALTERNATE(WS2812_SPI_MOSI_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL);
59#endif
60 72
61 // TODO: more dynamic baudrate 73 // TODO: more dynamic baudrate
62 static const SPIConfig spicfg = { 74 static const SPIConfig spicfg = {