diff options
| -rw-r--r-- | drivers/chibios/ws2812_spi.c | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/drivers/chibios/ws2812_spi.c b/drivers/chibios/ws2812_spi.c index bc0a54acc..e02cbabc0 100644 --- a/drivers/chibios/ws2812_spi.c +++ b/drivers/chibios/ws2812_spi.c | |||
| @@ -34,7 +34,7 @@ | |||
| 34 | 34 | ||
| 35 | // Define SPI config speed | 35 | // Define SPI config speed |
| 36 | // baudrate should target 3.2MHz | 36 | // baudrate should target 3.2MHz |
| 37 | // F072 fpclk = 48MHz | 37 | // F072 fpclk = 48MHz |
| 38 | // 48/16 = 3Mhz | 38 | // 48/16 = 3Mhz |
| 39 | #if WS2812_SPI_DIVISOR == 2 | 39 | #if WS2812_SPI_DIVISOR == 2 |
| 40 | # define WS2812_SPI_DIVISOR (0) | 40 | # define WS2812_SPI_DIVISOR (0) |
| @@ -42,7 +42,7 @@ | |||
| 42 | # define WS2812_SPI_DIVISOR (SPI_CR1_BR_0) | 42 | # define WS2812_SPI_DIVISOR (SPI_CR1_BR_0) |
| 43 | #elif WS2812_SPI_DIVISOR == 8 | 43 | #elif WS2812_SPI_DIVISOR == 8 |
| 44 | # define WS2812_SPI_DIVISOR (SPI_CR1_BR_1) | 44 | # define WS2812_SPI_DIVISOR (SPI_CR1_BR_1) |
| 45 | #elif WS2812_SPI_DIVISOR == 16 //same as default | 45 | #elif WS2812_SPI_DIVISOR == 16 // same as default |
| 46 | # define WS2812_SPI_DIVISOR (SPI_CR1_BR_1 | SPI_CR1_BR_0) | 46 | # define WS2812_SPI_DIVISOR (SPI_CR1_BR_1 | SPI_CR1_BR_0) |
| 47 | #elif WS2812_SPI_DIVISOR == 32 | 47 | #elif WS2812_SPI_DIVISOR == 32 |
| 48 | # define WS2812_SPI_DIVISOR (SPI_CR1_BR_2) | 48 | # define WS2812_SPI_DIVISOR (SPI_CR1_BR_2) |
| @@ -53,14 +53,14 @@ | |||
| 53 | #elif WS2812_SPI_DIVISOR == 256 | 53 | #elif WS2812_SPI_DIVISOR == 256 |
| 54 | # define WS2812_SPI_DIVISOR (SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_BR_0) | 54 | # define WS2812_SPI_DIVISOR (SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_BR_0) |
| 55 | #else | 55 | #else |
| 56 | # define WS2812_SPI_DIVISOR (SPI_CR1_BR_1 | SPI_CR1_BR_0) //default | 56 | # define WS2812_SPI_DIVISOR (SPI_CR1_BR_1 | SPI_CR1_BR_0) // default |
| 57 | #endif | 57 | #endif |
| 58 | 58 | ||
| 59 | // Use SPI circular buffer | 59 | // Use SPI circular buffer |
| 60 | #ifdef WS2812_SPI_USE_CIRCULAR_BUFFER | 60 | #ifdef WS2812_SPI_USE_CIRCULAR_BUFFER |
| 61 | # define WS2812_SPI_BUFFER_MODE 1 //circular buffer | 61 | # define WS2812_SPI_BUFFER_MODE 1 // circular buffer |
| 62 | #else | 62 | #else |
| 63 | # define WS2812_SPI_BUFFER_MODE 0 //normal buffer | 63 | # define WS2812_SPI_BUFFER_MODE 0 // normal buffer |
| 64 | #endif | 64 | #endif |
| 65 | 65 | ||
| 66 | #define BYTES_FOR_LED_BYTE 4 | 66 | #define BYTES_FOR_LED_BYTE 4 |
| @@ -112,10 +112,7 @@ void ws2812_init(void) { | |||
| 112 | palSetLineMode(RGB_DI_PIN, WS2812_OUTPUT_MODE); | 112 | palSetLineMode(RGB_DI_PIN, WS2812_OUTPUT_MODE); |
| 113 | 113 | ||
| 114 | // TODO: more dynamic baudrate | 114 | // TODO: more dynamic baudrate |
| 115 | static const SPIConfig spicfg = { | 115 | static const SPIConfig spicfg = {WS2812_SPI_BUFFER_MODE, NULL, PAL_PORT(RGB_DI_PIN), PAL_PAD(RGB_DI_PIN), WS2812_SPI_DIVISOR}; |
| 116 | WS2812_SPI_BUFFER_MODE, NULL, PAL_PORT(RGB_DI_PIN), PAL_PAD(RGB_DI_PIN), | ||
| 117 | WS2812_SPI_DIVISOR | ||
| 118 | }; | ||
| 119 | 116 | ||
| 120 | spiAcquireBus(&WS2812_SPI); /* Acquire ownership of the bus. */ | 117 | spiAcquireBus(&WS2812_SPI); /* Acquire ownership of the bus. */ |
| 121 | spiStart(&WS2812_SPI, &spicfg); /* Setup transfer parameters. */ | 118 | spiStart(&WS2812_SPI, &spicfg); /* Setup transfer parameters. */ |
