void ws2812b_Reset_l(void)
{
for(int i = LED_RESET - 16;i < LED_RESET;i++)
{
l_buff[i] = 2;
}
}
/**RGB L**/
void led_rgb_pwm_ch0_DMA_ch4_init(void)
{
dma_parameter_struct dma_str;
rcu_periph_clock_enable(RCU_DMA1);
dma_deinit(DMA1, DMA_CH4);
dma_str.direction = DMA_MEMORY_TO_PERIPHERAL;
dma_str.memory_addr = (uint32_t)l_buff;
dma_str.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
dma_str.memory_width = DMA_MEMORY_WIDTH_8BIT;
dma_str.number = TRANSFER_NUM;
dma_str.periph_addr = (uint32_t)&TIMER_CH0CV(TIMER4);
dma_str.periph_inc = DMA_PERIPH_INCREASE_DISABLE;
dma_str.periph_width = DMA_PERIPHERAL_WIDTH_16BIT;
dma_str.priority = DMA_PRIORITY_MEDIUM;
dma_init(DMA1,DMA_CH4,&dma_str);
dma_circulation_enable(DMA1,DMA_CH4);
dma_memory_to_memory_disable(DMA1,DMA_CH4);
dma_channel_enable(DMA1,DMA_CH4);
}
/**RGB L**/
void led_rgb_timer4_ch0_init(void)
{
timer_oc_parameter_struct timer_oc_str;
timer_parameter_struct timer_str;
rcu_periph_clock_enable(RCU_TIMER4);
timer_str.prescaler = 0;
timer_str.period = 135-1;
timer_str.alignedmode = TIMER_COUNTER_EDGE;
timer_str.counterdirection = TIMER_COUNTER_UP;
timer_str.repetitioncounter = 0;
timer_str.clockdivision = TIMER_CKDIV_DIV1;
timer_init(TIMER4,&timer_str);
timer_oc_str.outputstate = TIMER_CCX_ENABLE;
timer_oc_str.outputnstate = TIMER_CCXN_DISABLE;
timer_oc_str.ocpolarity = TIMER_OC_POLARITY_HIGH;
timer_oc_str.ocnpolarity = TIMER_OCN_POLARITY_HIGH;
timer_oc_str.ocidlestate = TIMER_OC_IDLE_STATE_HIGH;
timer_oc_str.ocnidlestate = TIMER_OCN_IDLE_STATE_LOW;
timer_channel_output_config(TIMER4,TIMER_CH_0,&timer_oc_str);
timer_channel_output_pulse_value_config(TIMER4,TIMER_CH_0,0);
timer_channel_output_mode_config(TIMER4,TIMER_CH_0,TIMER_OC_MODE_PWM0);
timer_channel_output_shadow_config(TIMER4,TIMER_CH_0,TIMER_OC_SHADOW_ENABLE);
timer_primary_output_config(TIMER4,ENABLE);
timer_dma_enable(TIMER4,TIMER_DMA_CH0D);
timer_auto_reload_shadow_enable(TIMER4);
timer_enable(TIMER4);
}
void led_rgb_write_l(int index,int color)
{
u8 i = 0;
u8 r = (u8)(color >> 16);
u8 g = (u8)(color >> 8);
u8 b = (u8)(color);
u32 offset = LED_RESET + index * 24;
for(i = 0;i < 8;i++)
{
if((g << i)&0x80){
l_buff[offset+i] = HIGH;
}else{
l_buff[offset+i] = LOW;
}
}
offset+=8;
for(i = 0;i < 8;i++)
{
if((r << i)&0x80){
l_buff[offset+i] = HIGH;
}else{
l_buff[offset+i] = LOW;
}
}
offset+=8;
for(i = 0;i < 8;i++)
{
if((b << i)&0x80){
l_buff[offset+i] = HIGH;
}else{
l_buff[offset+i] = LOW;
}
}
}
void led_rgb_show_color_all(void)
{
uint32_t i = 0;
uint32_t color = save_Reg[46]&0x0000ffff;
color <<= 16;
color |= save_Reg[47];
input_Reg[46] = save_Reg[46];
input_Reg[47] = save_Reg[47];
l_color = color;
r_color = color;
curr_l_color = l_color;
curr_r_color = r_color;
for(i = 0;i < LED_NUMBER;i++){
led_rgb_write_l(i,l_color);
led_rgb_write_r(i,r_color);
}
}
#define LED_NUMBER 55
#define LED_RESET 300
#define TRANSFER_NUM LED_NUMBER * 24+LED_RESET
uint8_t l_buff[TRANSFER_NUM]={0};
uint8_t r_buff[TRANSFER_NUM]={0};