From d140baf50edd18ee10ef519d83eaf8dcb930e728 Mon Sep 17 00:00:00 2001 From: Attila BODY Date: Sun, 16 Dec 2018 16:10:14 +0100 Subject: [PATCH] the first effect --- Inc/bitband.h | 27 ------------------------- Src/main.c | 56 ++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 44 insertions(+), 39 deletions(-) delete mode 100644 Inc/bitband.h diff --git a/Inc/bitband.h b/Inc/bitband.h deleted file mode 100644 index 4d3221d..0000000 --- a/Inc/bitband.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * bitband.h - * - * Created on: Dec 14, 2018 - * Author: abody - */ - -#ifndef BITBAND_H_ -#define BITBAND_H_ - -#include - -#define RAM_BASE 0x20000000 -#define RAM_BB_BASE 0x22000000 -#define RAM_ResetBit_BB(VarAddr, BitNumber) (*(volatile uint32_t *) (RAM_BB_BASE | ((VarAddr - RAM_BASE) << 5) | ((BitNumber) << 2)) = 0) -#define RAM_SetBit_BB(VarAddr, BitNumber) (*(volatile uint32_t *) (RAM_BB_BASE | ((VarAddr - RAM_BASE) << 5) | ((BitNumber) << 2)) = 1) -#define RAM_GetBit_BB(VarAddr, BitNumber) (*(volatile uint32_t *) (RAM_BB_BASE | ((VarAddr - RAM_BASE) << 5) | ((BitNumber) << 2))) -#define BITBAND_RAM(address, bit) ( (__IO uint32_t *) (RAM_BB_BASE + (((uint32_t)address) - RAM_BASE) * 32 + (bit) * 4)) - -#define IO_BASE 0x20000000 -#define IO_BB_BASE 0x22000000 -#define IO_ResetBit_BB(VarAddr, BitNumber) (*(volatile uint32_t *) (IO_BB_BASE | ((VarAddr - IO_BASE) << 5) | ((BitNumber) << 2)) = 0) -#define IO_SetBit_BB(VarAddr, BitNumber) (*(volatile uint32_t *) (IO_BB_BASE | ((VarAddr - IO_BASE) << 5) | ((BitNumber) << 2)) = 1) -#define IO_GetBit_BB(VarAddr, BitNumber) (*(volatile uint32_t *) (IO_BB_BASE | ((VarAddr - IO_BASE) << 5) | ((BitNumber) << 2))) -#define BITBAND_IO(address, bit) ( (__IO uint32_t *) (IO_BB_BASE + (((uint32_t)address) - IO_BASE) * 32 + (bit) * 4)) - -#endif /* BITBAND_H_ */ diff --git a/Src/main.c b/Src/main.c index 6a3f284..11481e8 100644 --- a/Src/main.c +++ b/Src/main.c @@ -44,16 +44,22 @@ #include "gpio.h" /* USER CODE BEGIN Includes */ -#include "bitband.h" +#include /* USER CODE END Includes */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ /* Private variables ---------------------------------------------------------*/ +#define NUMPIXELS 144 volatile uint8_t g_done = 0; -uint8_t g_ledBytes[] = {0, 0xff, 0, 0xff, 0x55, 0xaa}; -uint8_t g_ledBits[sizeof(g_ledBytes) * 8 / 2 + 1]; +typedef struct { + uint8_t g; + uint8_t r; + uint8_t b; +} pixel_t; +pixel_t g_pixels[NUMPIXELS]; +uint8_t g_ledBits[sizeof(g_pixels) * 8 / 2 + 1]; /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ @@ -113,24 +119,50 @@ int main(void) MX_DMA_Init(); MX_SPI1_Init(); /* USER CODE BEGIN 2 */ - convert(g_ledBytes, g_ledBits, sizeof(g_ledBytes)); + /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ - while(1) - { - HAL_StatusTypeDef st; - g_ledBits[sizeof(g_ledBits)-1] = 0; - st = HAL_SPI_Transmit_DMA(&hspi1, g_ledBits, sizeof(g_ledBits)); - while(!g_done); - HAL_Delay(1); +#define BRIGHTNESS 2 +#define DELAY 10 + + g_ledBits[sizeof(g_ledBits)-1] = 0; + memset(g_pixels, 0, sizeof(g_pixels)); + + while(1) + { + for(uint16_t idx=0; idx < NUMPIXELS; idx++) + { + if(idx % 3 == 0) g_pixels[idx].r = BRIGHTNESS; + else if(idx % 3 == 1) g_pixels[idx].g = BRIGHTNESS; + else g_pixels[idx].b = BRIGHTNESS; + + convert((uint8_t*)g_pixels, g_ledBits, sizeof(g_pixels)); + + HAL_SPI_Transmit_DMA(&hspi1, g_ledBits, sizeof(g_ledBits)); + while(!g_done); + HAL_Delay(DELAY); + } + + for(uint16_t idx=0; idx < NUMPIXELS; idx++) + { + if(idx % 3 == 0) g_pixels[idx].r = 0; + else if(idx % 3 == 1) g_pixels[idx].g = 0; + else g_pixels[idx].b = 0; + + convert((uint8_t*)g_pixels, g_ledBits, sizeof(g_pixels)); + + HAL_SPI_Transmit_DMA(&hspi1, g_ledBits, sizeof(g_ledBits)); + while(!g_done); + HAL_Delay(DELAY); + } /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ - } + } /* USER CODE END 3 */ }