/****************************** File: ws2812.h ********************************* * Author : wizard2001 22.03.2023 * Version : V1.0.0 * Settings : MounRiver Studio V1.84 MCU CH32V003F4P6 CH32F003_Board SSOP20 * Description : Control WS2812 Chain over GPIO * PC.1 - WS2812 Data * PC.2 - LED1 OnBoard * PC.4 - LED2 OnBoard * Updates : 23.03.2023 Extension of the Luminance table to 256 Values ******************************************************************************/ #include #ifndef __WS2812_H #define __WS2812_H //--------------------------- Includes #define LED_X 1 #define LED_Y 32 #define Max_LED LED_X * LED_Y // n lines #define MaxLumiTab 256 // steps 0~max typedef struct __attribute__ ((__packed__)){ // ------ uint8_t G; uint8_t R; uint8_t B; } WS_LED_t; static const uint8_t dim_tab[] = { 0, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 16, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 20, 20, 20, 21, 21, 22, 22, 22, 23, 23, 24, 24, 25, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 30, 30, 31, 32, 32, 33, 33, 34, 35, 35, 36, 36, 37, 38, 38, 39, 40, 40, 41, 42, 43, 43, 44, 45, 46, 47, 48, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 68, 69, 70, 71, 73, 74, 75, 76, 78, 79, 81, 82, 83, 85, 86, 88, 90, 91, 93, 94, 96, 98, 99, 101, 103, 105, 107, 109, 110, 112, 114, 116, 118, 121, 123, 125, 127, 129, 132, 134, 136, 139, 141, 144, 146, 149, 151, 154, 157, 159, 162, 165, 168, 171, 174, 177, 180, 183, 186, 190, 193, 196, 200, 203, 207, 211, 214, 218, 222, 226, 230, 234, 238, 242, 248, 255, }; //--------------------------- Defines Pins, Ports #define Dext GPIO_Pin_3 // check / debug #define WS_OUT GPIO_Pin_1 // PC.1 Dout for WS2812 #define WS_PORT GPIOC // GPIO Port C #define WS_GPIO_CLK RCC_APB2Periph_GPIOC #define LED1 GPIO_Pin_2 // PC.2 OnBoard LED1 & #define LED2 GPIO_Pin_4 // PC.3 LED2 handwired #define LED_PORT GPIOC #define LED_GPIO_CLK RCC_APB2Periph_GPIOC //--------------------------- Macros #define LED1_on LED_PORT->BCR = LED1; // LED1=LOW -> on #define LED1_off LED_PORT->BSHR = LED1; // LED1=HIGH -> off #define LED2_on LED_PORT->BCR = LED2; // LED2=LOW -> on #define LED2_off LED_PORT->BSHR = LED2; // LED2=HIGH -> off #define WS_OUT_L WS_PORT->BCR = WS_OUT; // DatPin Low #define WS_OUT_H WS_PORT->BSHR = WS_OUT; // DatPin Hight //--------------------------- Globale Funktionen void WS2812_IO_init(void); void WS_CHAIN_init(void); void LED_init(void); void WS2812_wr(uint8_t nLED); void WS2812_dimm(void); //-------------------------------------------------------------- #endif // __WS2812_H