From 48883e6e3d480039673c43bc915d85f4b82e0282 Mon Sep 17 00:00:00 2001 From: Attila BODY Date: Mon, 17 Dec 2018 21:43:19 +0100 Subject: [PATCH] interrupt works --- App/App.cpp | 22 +++++++++++++++++----- App/Config.h | 6 +++--- Src/stm32f1xx_it.c | 2 +- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/App/App.cpp b/App/App.cpp index 2c03ac8..d52a4b5 100644 --- a/App/App.cpp +++ b/App/App.cpp @@ -56,30 +56,42 @@ uint16_t ChoosePixel() void StartSparkle( Sparkle &s ) { - s.Start(g_pixels+ChoosePixel(), Pixel(255,255,255), Pixel(rr(5)+1,rr(5)+1,rr(5)+1)); + s.Start(g_pixels+ChoosePixel(), Pixel(255,255,255), Pixel(rr(8)+3,rr(8)+3,rr(8)+3)); +} + +extern "C" void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi) +{ + if(hspi == &hspi1) { + g_done = true; + } } extern "C" void App() { g_ledBits[sizeof(g_ledBits)-1] = 0; memset(g_pixels, 0, sizeof(g_pixels)); - + uint32_t lastTick = HAL_GetTick() - FRAMETIME; while(1) { + while(HAL_GetTick() - lastTick < FRAMETIME ); + lastTick += FRAMETIME; + HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13); + for(int16_t spi = 0; spi < NUMSPARKLES; ++spi) { if(static_cast(g_s[spi])) g_s[spi].Step(); else StartSparkle(g_s[spi]); } + HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13); convert((uint8_t*)g_pixels, g_ledBits, sizeof(g_pixels)); + HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13); + g_done = false; - GPIOC->BSRR = 1 << (13+16); HAL_SPI_Transmit_DMA(&hspi1, g_ledBits, sizeof(g_ledBits)); - GPIOC->BSRR = 1 << 13; while(!g_done); - HAL_Delay(5); + HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13); } } diff --git a/App/Config.h b/App/Config.h index 692a66d..1fb417c 100644 --- a/App/Config.h +++ b/App/Config.h @@ -8,7 +8,7 @@ #ifndef CONFIG_H_ #define CONFIG_H_ -#define NUMPIXELS 300 -#define NUMSPARKLES 25 - +#define NUMPIXELS 144 +#define NUMSPARKLES (NUMPIXELS/12) +#define FRAMETIME 20 #endif /* CONFIG_H_ */ diff --git a/Src/stm32f1xx_it.c b/Src/stm32f1xx_it.c index 6bd764c..90703bc 100644 --- a/Src/stm32f1xx_it.c +++ b/Src/stm32f1xx_it.c @@ -198,7 +198,7 @@ void SysTick_Handler(void) void DMA1_Channel3_IRQHandler(void) { /* USER CODE BEGIN DMA1_Channel3_IRQn 0 */ - g_done = 1; + /* USER CODE END DMA1_Channel3_IRQn 0 */ HAL_DMA_IRQHandler(&hdma_spi1_tx); /* USER CODE BEGIN DMA1_Channel3_IRQn 1 */