本帖最后由 TJM2613 于 2023-2-14 14:43 编辑
定时器等初始化已完成
驱动代码移植ch57X的ws2812代码如下:
typedef struct {
uint32_t g;
uint32_t r;
uint32_t b;
}ws2812_in_spi_buffer_t;
__attribute__((aligned(4))) ws2812_in_spi_buffer_t ws2812_buf[1];
uint32_t map_table[8] = {
0x8e888888,
0xe8888888,
0x888e8888,
0x88e88888,
0x88888e88,
0x8888e888,
0x8888888e,
0x888888e8,
};
void ws2812_set_rgb(ws2812_in_spi_buffer_t *buf,uint8_t r,uint8_t g,uint8_t b){
buf->r = 0x88888888;
for(uint8_t i=0;i<8;i++){
if(r&0x1) {
buf->r |= map_table;
}
r>>=1;
}
buf->g = 0x88888888;
for(uint8_t i=0;i<8;i++){
if(g&0x1) {
buf->g |= map_table;
}
g>>=1;
}
buf->b = 0x88888888;
for(uint8_t i=0;i<8;i++){
if(b&0x1) {
buf->b |= map_table;
}
b>>=1;
}
}
void ws2812_test(char argc ,char *argv) {
SPI0_MasterDMATrans((uint8_t *)ws2812_buf, 12*1);
}
void ws2812_off_all(void) {
for(uint32_t i=0;i<1;i++) {
ws2812_set_rgb(&ws2812_buf,0,0,0);
}
SPI0_MasterDMATrans((uint8_t *)ws2812_buf, 12*1);
}
uint8_t LED_cnt = 0;
void SPI_LED()
{
if(LED_cnt == 0)
{
for(uint32_t i=0;i<30;i++) {
ws2812_set_rgb(&ws2812_buf,0xff,0xff,0xff);//白色最亮不正常
}
SPI0_MasterDMATrans((uint8_t *)ws2812_buf, 12*1);
}else if(LED_cnt == 1)
{
for(uint32_t i=0;i<30;i++) {
ws2812_set_rgb(&ws2812_buf,0xff,0,0);//红色最亮正常
}
SPI0_MasterDMATrans((uint8_t *)ws2812_buf, 12*1);
}else if(LED_cnt == 2)
{
for(uint32_t i=0;i<30;i++) {
ws2812_set_rgb(&ws2812_buf,0x00,0xff,0);//绿色最亮正常
}
SPI0_MasterDMATrans((uint8_t *)ws2812_buf, 12*1);
}else if(LED_cnt == 3)
{
for(uint32_t i=0;i<30;i++) {
ws2812_set_rgb(&ws2812_buf,0x00,0,0xff);//蓝色最亮正常
}
SPI0_MasterDMATrans((uint8_t *)ws2812_buf, 12*1);
}
LED_cnt++;
if(LED_cnt >= 4)
{
LED_cnt = 0;
}
}
白色灯并没有亮,而是只亮红色,随后尝试了RGB = 0Xff,0xff,0和RGB = 0xff,0,0xff,均不正常,全是只亮红色 ,而RGB = 0,0xff,0xff时是正常亮青色,请问是哪里出现了问题
|