configure for 8MHz

This commit is contained in:
Mitchell Marino 2025-01-13 22:43:51 -06:00
parent 771c264425
commit fed8829bba

View File

@ -3,6 +3,9 @@
#include <ch32v00x.h>
// #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