diff --git a/build-number.txt b/build-number.txt index 6bb2f4e..102c15d 100644 --- a/build-number.txt +++ b/build-number.txt @@ -1 +1 @@ -389 +409 diff --git a/src/animation.c b/src/animation.c index a89b36c..44f219f 100644 --- a/src/animation.c +++ b/src/animation.c @@ -1,6 +1,8 @@ #include "animation.h" #include "light_sensor.h" +volatile bool Animation_FrameFlag = false; + const unsigned int Animation_LEDOrder[LED_COUNT] = { 19, 27, 21, 13, 0, 4, 24, 8, 12, 15, 6, 5, 28, @@ -303,12 +305,24 @@ void Animation_DrawGradient(unsigned int step_bottom, unsigned int step_top, } } +void Animation_Init(void) +{ + RCC->APB2ENR |= RCC_APB2ENR_TIM17EN; + + TIM17->PSC = 8000 - 1; + TIM17->ARR = 1000 / ANIMATION_REFRESH_RATE; + TIM17->DIER = TIM_DIER_UIE; + TIM17->CR1 = TIM_CR1_CEN; + NVIC_EnableIRQ(TIM17_IRQn); +} + void Animation_Poll(void) { - if(!LED_FrameFlag) + if(!Animation_FrameFlag) { return; } + Animation_FrameFlag = false; static unsigned int bottom = 0; static unsigned int top = 0; @@ -321,5 +335,10 @@ void Animation_Poll(void) Animation_DrawGradient(bottom, top, LightSensor_RelativeBrightness); LED_Commit(); - LED_FrameFlag = false; +} + +void TIM17_IRQHandler(void) +{ + Animation_FrameFlag = true; + TIM17->SR &= ~TIM_SR_UIF; } \ No newline at end of file diff --git a/src/animation.h b/src/animation.h index f9abe60..eecdd54 100644 --- a/src/animation.h +++ b/src/animation.h @@ -1,14 +1,19 @@ #pragma once +#include + #include "led.h" -#define ANIMATION_STEPS 65535 +#define ANIMATION_STEPS (1 << 24) + +#define ANIMATION_REFRESH_RATE 10 #define ANIMATION_DURATION_BOTTOM \ - 1000 + 6048000 -#define ANIMATION_DURATION_TOP 5000 +#define ANIMATION_DURATION_TOP 6652800 extern const unsigned int Animation_LEDOrder[LED_COUNT]; +void Animation_Init(void); void Animation_Poll(void); \ No newline at end of file diff --git a/src/main.c b/src/main.c index 57c9d0e..bb229ca 100644 --- a/src/main.c +++ b/src/main.c @@ -14,6 +14,7 @@ int main(void) } LED_Init(); + Animation_Init(); while(1) {