From fed8829bba4a72c215bee9829b2b4dce86bf65fe Mon Sep 17 00:00:00 2001 From: Mitchell M Date: Mon, 13 Jan 2025 22:43:51 -0600 Subject: [PATCH] configure for 8MHz --- src/neopixel_driver.h | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/src/neopixel_driver.h b/src/neopixel_driver.h index 8e8f3b4..7ae44a8 100755 --- a/src/neopixel_driver.h +++ b/src/neopixel_driver.h @@ -3,6 +3,9 @@ #include +// #define CLK_24MHZ +#define CLK_8MHZ + void SPINeoPixelDriverInit(void) { GPIO_InitTypeDef GPIO_InitStructure={0}; SPI_InitTypeDef SPI_InitStructure={0}; @@ -23,8 +26,14 @@ void SPINeoPixelDriverInit(void) { SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; - SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; + +#ifdef CLK_24MHZ + SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8; +#endif +#ifdef CLK_8MHZ + SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4; +#endif SPI_Init(SPI1, &SPI_InitStructure); SPI_Cmd(SPI1, ENABLE); @@ -39,20 +48,25 @@ void SPISendByte(uint8_t byte) { } void SendNeoPixel0() { +#ifdef CLK_24MHZ // 420ns High at 24MHz SPISendByte(0b11000000); +#endif +#ifdef CLK_8MHZ + // ???????? + SPISendByte(0b10000000); +#endif } void SendNeoPixel1() { +#ifdef CLK_24MHZ // 750ns High at 24MHz SPISendByte(0b11110000); -} - -void SendNeoPixelColor(uint8_t red, uint8_t green, uint8_t blue) { - // Send in GRB order, MSB first - SendNeoPixelByte(green); - SendNeoPixelByte(red); - SendNeoPixelByte(blue); +#endif +#ifdef CLK_8MHZ + // ???????? + SPISendByte(0b1110000); +#endif } void SendNeoPixelByte(uint8_t byte) { @@ -65,4 +79,11 @@ void SendNeoPixelByte(uint8_t byte) { } } +void SendNeoPixelColor(uint8_t red, uint8_t green, uint8_t blue) { + // Send in GRB order, MSB first + SendNeoPixelByte(green); + SendNeoPixelByte(red); + SendNeoPixelByte(blue); +} + #endif // NEOPIXEL_DRIVER_H \ No newline at end of file