the first effect
This commit is contained in:
parent
f02188bf2d
commit
d140baf50e
2 changed files with 44 additions and 39 deletions
|
@ -1,27 +0,0 @@
|
||||||
/*
|
|
||||||
* bitband.h
|
|
||||||
*
|
|
||||||
* Created on: Dec 14, 2018
|
|
||||||
* Author: abody
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef BITBAND_H_
|
|
||||||
#define BITBAND_H_
|
|
||||||
|
|
||||||
#include <inttypes.h>
|
|
||||||
|
|
||||||
#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_ */
|
|
48
Src/main.c
48
Src/main.c
|
@ -44,16 +44,22 @@
|
||||||
#include "gpio.h"
|
#include "gpio.h"
|
||||||
|
|
||||||
/* USER CODE BEGIN Includes */
|
/* USER CODE BEGIN Includes */
|
||||||
#include "bitband.h"
|
#include <string.h>
|
||||||
/* USER CODE END Includes */
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
/* Private variables ---------------------------------------------------------*/
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
|
||||||
/* USER CODE BEGIN PV */
|
/* USER CODE BEGIN PV */
|
||||||
/* Private variables ---------------------------------------------------------*/
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
#define NUMPIXELS 144
|
||||||
volatile uint8_t g_done = 0;
|
volatile uint8_t g_done = 0;
|
||||||
uint8_t g_ledBytes[] = {0, 0xff, 0, 0xff, 0x55, 0xaa};
|
typedef struct {
|
||||||
uint8_t g_ledBits[sizeof(g_ledBytes) * 8 / 2 + 1];
|
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 */
|
/* USER CODE END PV */
|
||||||
|
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
@ -113,19 +119,45 @@ int main(void)
|
||||||
MX_DMA_Init();
|
MX_DMA_Init();
|
||||||
MX_SPI1_Init();
|
MX_SPI1_Init();
|
||||||
/* USER CODE BEGIN 2 */
|
/* USER CODE BEGIN 2 */
|
||||||
convert(g_ledBytes, g_ledBits, sizeof(g_ledBytes));
|
|
||||||
/* USER CODE END 2 */
|
/* USER CODE END 2 */
|
||||||
|
|
||||||
/* Infinite loop */
|
/* Infinite loop */
|
||||||
/* USER CODE BEGIN WHILE */
|
/* USER CODE BEGIN WHILE */
|
||||||
|
|
||||||
|
#define BRIGHTNESS 2
|
||||||
|
#define DELAY 10
|
||||||
|
|
||||||
|
g_ledBits[sizeof(g_ledBits)-1] = 0;
|
||||||
|
memset(g_pixels, 0, sizeof(g_pixels));
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
HAL_StatusTypeDef st;
|
for(uint16_t idx=0; idx < NUMPIXELS; idx++)
|
||||||
g_ledBits[sizeof(g_ledBits)-1] = 0;
|
{
|
||||||
st = HAL_SPI_Transmit_DMA(&hspi1, g_ledBits, sizeof(g_ledBits));
|
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);
|
while(!g_done);
|
||||||
HAL_Delay(1);
|
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 END WHILE */
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue