/****************************** File: ws2812.c ********************************* * 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 : ******************************************************************************/ //--------------------------- Includes #include "debug.h" #include "ws2812.h" //--------------------------- Variable WS_LED_t WS_LEDa[Max_LED]; // aktueller Wert WS_LED_t WS_LEDs[Max_LED]; // Ziel Wert //--------------------------- Konstanten //--------------------------- LED GPIO Init void LED_init(void) // init OnBoard LEDs { GPIO_InitTypeDef GPIO_InitStructure = {0}; RCC_APB2PeriphClockCmd(LED_GPIO_CLK, ENABLE); GPIO_InitStructure.GPIO_Pin = LED1 | LED2; // set output PB8-9 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(LED_PORT, &GPIO_InitStructure); } //--------------------------- GPIO Init void WS2812_IO_init(void) // init GPIOs { GPIO_InitTypeDef GPIO_InitStructure = {0}; RCC_APB2PeriphClockCmd(WS_GPIO_CLK, ENABLE); GPIO_InitStructure.GPIO_Pin = WS_OUT | Dext; // set output PB8-9 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(WS_PORT, &GPIO_InitStructure); } WS_LED_t rnd_color(void) // random values { WS_LED_t WS_rnd; WS_rnd.G = (uint8_t)(rand() % MaxLumiTab); printf("Green:%d\r\n",WS_rnd.G); WS_rnd.R = (uint8_t)(rand() % MaxLumiTab); printf("Red :%d\r\n",WS_rnd.R); WS_rnd.B = (uint8_t)(rand() % MaxLumiTab); printf("Blue :%d\r\n",WS_rnd.B); return(WS_rnd); } void WS_CHAIN_init(void) { for (uint8_t i=0; i> 5; // fading up value fade_d = (abs(85-offset) * saturation) >> 5; // fading down if( section ) { if( section == 1) { // section 1: 85..169 WS_LEDa[n].R = 0; WS_LEDa[n].B = (uint8_t) (fade_u); WS_LEDa[n].G = (uint8_t) (fade_d); } else { // section 2; 170..255 WS_LEDa[n].R = (uint8_t) (fade_u); WS_LEDa[n].B = (uint8_t) (fade_d); WS_LEDa[n].G = 0; } } else { // section 0: 00..84 WS_LEDa[n].R = (uint8_t) (fade_d); WS_LEDa[n].B = 0; WS_LEDa[n].G = (uint8_t) (fade_u); } } void WS2812_dimm(void) // alle LEDs GRB { // zwischen ZUfallswerten // dimmen for (uint8_t i=0; i>= 1; // next Bit } } }