src/bsp.c
void send_rgb(void)
{
    disableInterrupts();

    rgb_data_cnt = RGB_LEDS_NUM*RGB_LED_BITS - 1u;
    // rgb_data_cnt = RGB_LED_BITS - 1u;

    //Load first PWM value
    TIM2CH2_TO_PWM();
    TIM2->CCR2H = 0u;
    TIM2->CCR2L = *(rgb_codes + rgb_data_cnt);
    //Generate an event to copy PWM value
    //from the shadow register to the TIM2 register
    TIM2_GenerateEvent(TIM2_EVENTSOURCE_UPDATE);
    //Next value
    rgb_data_cnt--;

    //Load second PWM value and increment data counter
    TIM2->CCR2H = 0u;
    TIM2->CCR2L = *(rgb_codes + rgb_data_cnt);
    rgb_data_cnt--;
    //Enable TIM2 IRQ, run TIM2 and enable global IRQ
    TIM2_ITConfig(TIM2_IT_UPDATE, ENABLE);
    TIM4_ITConfig(TIM4_IT_UPDATE, DISABLE);
    
    TIM2_Cmd(ENABLE);
    enableInterrupts();

    //Wait until transfer is ended
    while(rgb_data_cnt != 0u) {};

    //Disable TIM2
    disableInterrupts();
    
    TIM2CH2_TO_LOW();
    TIM2_Cmd(DISABLE);
    
    //Always clear counter !
    TIM2->CNTRL = 0u;
    TIM2->CNTRH = 0u;
    
    TIM2_ITConfig(TIM2_IT_UPDATE, DISABLE);
    TIM4_ITConfig(TIM4_IT_UPDATE, ENABLE);
    
    enableInterrupts();
}
/**
 * @brief Send RGB data to the LEDs using TIM4
 * 
 */
@brief Send RGB data to the LEDs using TIM4
@brief Send RGB data to the LEDs using TIM4
void send_rgb(void)
{
    disableInterrupts();
    rgb_data_cnt = RGB_LEDS_NUM*RGB_LED_BITS - 1u;
    TIM2CH2_TO_PWM();
    TIM2->CCR2H = 0u;
    TIM2->CCR2L = *(rgb_codes + rgb_data_cnt);
    TIM2_GenerateEvent(TIM2_EVENTSOURCE_UPDATE);
    rgb_data_cnt--;
    TIM2->CCR2H = 0u;
    TIM2->CCR2L = *(rgb_codes + rgb_data_cnt);
    rgb_data_cnt--;
    TIM2_ITConfig(TIM2_IT_UPDATE, ENABLE);
    TIM4_ITConfig(TIM4_IT_UPDATE, DISABLE);
    TIM2_Cmd(ENABLE);
    enableInterrupts();
    while(rgb_data_cnt != 0u) {};
    disableInterrupts();
    TIM2CH2_TO_LOW();
    TIM2_Cmd(DISABLE);
    TIM2->CNTRL = 0u;
    TIM2->CNTRH = 0u;
    TIM2_ITConfig(TIM2_IT_UPDATE, DISABLE);
    TIM4_ITConfig(TIM4_IT_UPDATE, ENABLE);
    enableInterrupts();
}
void send_rgb ( void ) { disableInterrupts ( ) ; rgb_data_cnt = RGB_LEDS_NUM * RGB_LED_BITS - 1u ; TIM2CH2_TO_PWM ( ) ; TIM2 -> CCR2H = 0u ; TIM2 -> CCR2L = * ( rgb_codes + rgb_data_cnt ) ; TIM2_GenerateEvent ( TIM2_EVENTSOURCE_UPDATE ) ; rgb_data_cnt -- ; TIM2 -> CCR2H = 0u ; TIM2 -> CCR2L = * ( rgb_codes + rgb_data_cnt ) ; rgb_data_cnt -- ; TIM2_ITConfig ( TIM2_IT_UPDATE , ENABLE ) ; TIM4_ITConfig ( TIM4_IT_UPDATE , DISABLE ) ; TIM2_Cmd ( ENABLE ) ; enableInterrupts ( ) ; while ( rgb_data_cnt != 0u ) { } ; disableInterrupts ( ) ; TIM2CH2_TO_LOW ( ) ; TIM2_Cmd ( DISABLE ) ; TIM2 -> CNTRL = 0u ; TIM2 -> CNTRH = 0u ; TIM2_ITConfig ( TIM2_IT_UPDATE , DISABLE ) ; TIM4_ITConfig ( TIM4_IT_UPDATE , ENABLE ) ; enableInterrupts ( ) ; }
@brief Send RGB data to the LEDs using TIM4
@brief Send RGB data to the LEDs using TIM4
// rgb_data_cnt = RGB_LED_BITS - 1u; //Load first PWM value //Generate an event to copy PWM value //from the shadow register to the TIM2 register //Next value //Load second PWM value and increment data counter //Enable TIM2 IRQ, run TIM2 and enable global IRQ //Wait until transfer is ended //Disable TIM2 //Always clear counter !