Track suspend status in LED driver

This commit is contained in:
fruchti 2020-07-17 00:17:35 +02:00
parent 38d3a3846b
commit bf50402ce2

View file

@ -4,6 +4,7 @@
LED_Colour_t LED_PixelData[LED_COUNT] = {{0}}; LED_Colour_t LED_PixelData[LED_COUNT] = {{0}};
volatile bool LED_FrameFlag = false; volatile bool LED_FrameFlag = false;
volatile bool LED_SuspendFlag = false; volatile bool LED_SuspendFlag = false;
bool LED_Suspended = false;
#define LED_ODR_MASK ((1 << PIN_LED_R_0) | (1 << PIN_LED_G_0) \ #define LED_ODR_MASK ((1 << PIN_LED_R_0) | (1 << PIN_LED_G_0) \
| (1 << PIN_LED_B_0) | (1 << PIN_LED_R_1) \ | (1 << PIN_LED_B_0) | (1 << PIN_LED_R_1) \
@ -59,6 +60,11 @@ static volatile bool LED_QueuePageFlip = false;
void LED_Commit(void) void LED_Commit(void)
{ {
if(LED_Suspended)
{
return;
}
// Wait for the current data to be displayed in case LED_Commit was called // Wait for the current data to be displayed in case LED_Commit was called
// more than one time during a single frame. Otherwise, a race condition // more than one time during a single frame. Otherwise, a race condition
// might occur. // might occur.
@ -248,6 +254,11 @@ void LED_Init(void)
void LED_Suspend(void) void LED_Suspend(void)
{ {
if(LED_Suspended)
{
return;
}
LED_SuspendFlag = true; LED_SuspendFlag = true;
while(LED_SuspendFlag); while(LED_SuspendFlag);
@ -272,11 +283,20 @@ void LED_Suspend(void)
// Disable timer and DMA clocks // Disable timer and DMA clocks
RCC->AHBENR &= ~RCC_AHBENR_DMA1EN; RCC->AHBENR &= ~RCC_AHBENR_DMA1EN;
RCC->APB1ENR &= ~RCC_APB1ENR_TIM3EN; RCC->APB1ENR &= ~RCC_APB1ENR_TIM3EN;
LED_Suspended = true;
} }
void LED_WakeUp(void) void LED_WakeUp(void)
{ {
if(!LED_Suspended)
{
return;
}
LED_Init(); LED_Init();
LED_Suspended = false;
} }
void DMA1_Channel2_3_IRQHandler(void) void DMA1_Channel2_3_IRQHandler(void)