diff --git a/Core/Inc/main.h b/Core/Inc/main.h index 6835a52..2ce8c2d 100644 --- a/Core/Inc/main.h +++ b/Core/Inc/main.h @@ -141,7 +141,7 @@ void Error_Handler(void); /* * STM32WL55, STM32WLE5 Clock=48Mhz 48,000,000/800khz = 60 */ -#define STS_LAMP_BAR_PWM_TIM_PERIOD (120 - 1) +#define STS_LAMP_BAR_PWM_TIM_PERIOD (240 - 1) #define STS_LAMP_BAR_HTIM htim1 #define STS_LAMP_BAR_LED_NUM (60) //60 for 46CM length LED strip #define LED_COUNT 18 // for 30 cm lamp bar diff --git a/Core/Src/sts_lamp_bar.c b/Core/Src/sts_lamp_bar.c index 041eacf..cd3aca8 100644 --- a/Core/Src/sts_lamp_bar.c +++ b/Core/Src/sts_lamp_bar.c @@ -28,12 +28,13 @@ #include "yunhorn_sts_sensors.h" -#define ONE_PULSE (40) //36 -#define ZERO_PULSE (20) +#define ONE_PULSE (36) //(36) //36 +#define ZERO_PULSE (12) //(12) #define LED_DATA_LEN 24 -#define WS2812B_DATA_LEN (LED_DATA_LEN * (STS_LAMP_BAR_LED_NUM)) -#define RESET_PULSE (150) //(80) TO FIX DARK_COLOR AND SM2 +//#define WS2812B_DATA_LEN (LED_DATA_LEN * (STS_LAMP_BAR_LED_NUM)) +#define WS2812B_DATA_LEN (LED_DATA_LEN * (LED_COUNT)) +#define RESET_PULSE (24) //(80) TO FIX DARK_COLOR AND SM2 typedef struct ws2812b_e { @@ -49,6 +50,9 @@ volatile WS2812B_FrameTypeDef rgb_buf = { .tail = 0 }; +uint8_t ws2812b_crr_value[LED_COUNT*24+RESET_PULSE]={00}; +uint8_t ws2812b_data[LED_COUNT*3]={0}; + uint8_t color_rgb[8][3] = { //STS_COLOR R G B MAPPING TABLE {0,0,0},{0,1,0},{1,0,0},{0,0,1},{1,1,0},{1,0,1},{0,1,1},{1,1,1} }; @@ -92,16 +96,93 @@ extern SysTime_t mems_event_time; extern volatile uint32_t event_start_time, event_stop_time; extern volatile uint32_t event_door_lock_start_time, event_door_lock_stop_time; volatile uint8_t luminance_level = DEFAULT_LUMINANCE_LEVEL; +void ws2812b_data_transfer(uint8_t *src, uint32_t len); +void ws2812b_light_custom(uint8_t red, uint8_t green, uint8_t blue); +void ws2812b_light_all_with_lum_level(uint8_t color, uint8_t lum_level); +void ws2812b_light_all(uint8_t color); +void ws2812b_data_transfer(uint8_t *src, uint32_t len) +{ + uint8_t i =0; + uint32_t bits = 0; + uint32_t bytes = 0; + while(len--) + { + for (i=0; i < 8; i++) + { + ws2812b_crr_value[bits] = (((*(src+bytes))<= start_position) { @@ -189,19 +289,32 @@ static void STS_Lamp_Bar_Set_RGB_Color_FadeIn(uint8_t red, uint8_t green, uint8_ uint8_t lin = (rev * 0xFF / fade_len); uint8_t bri = (lin * lin) >> 8; - STS_WS2812B_Set_RGB((red*bri)>>8, (green*bri)>>8, (blue*bri)>>8, ((idx))); + //STS_WS2812B_Set_RGB((red*bri)>>8, (green*bri)>>8, (blue*bri)>>8, ((idx))); + //ws2812b_light_one_rgb((red*bri)>>8, (green*bri)>>8, (blue*bri)>>8, ((idx))); + { + ws2812b_data[3*idx] = (green*bri)>>8; + ws2812b_data[3*idx+1] = (red*bri)>>8; + ws2812b_data[3*idx+2] = (blue*bri)>>8; + } + } else { // shorter than tail, set to dark //STS_WS2812B_Set_RGB(red, green, blue, idx); - STS_WS2812B_Set_RGB(0, 0, 0, idx); + //STS_WS2812B_Set_RGB(0, 0, 0, idx); + ws2812b_data[3*idx] = 0; + ws2812b_data[3*idx+1] = 0; + ws2812b_data[3*idx+2] = 0; } } + ws2812b_data_transfer(ws2812b_data, sizeof(ws2812b_data)); } static void STS_Lamp_Bar_Set_RGB_Color_FadeOut(uint8_t red, uint8_t green, uint8_t blue, uint8_t start_position, uint8_t fade_length) { uint8_t fade_len = fade_length; + //UTIL_MEM_set_8((void*)rgb_buf.GRB,0x00,(WS2812B_DATA_LEN+RESET_PULSE)); + memset(ws2812b_data, 0, sizeof(ws2812b_data)); for (uint8_t idx = 0; idx < LED_COUNT; idx++) { if ((idx >= start_position) && (idx <= (start_position+fade_len))) { @@ -212,15 +325,28 @@ static void STS_Lamp_Bar_Set_RGB_Color_FadeOut(uint8_t red, uint8_t green, uint8 //uint8_t lin = (idx/(2*tail_len)); //uint8_t bri = lin; - STS_WS2812B_Set_RGB((red*bri)>>8, (green*bri)>>8, (blue*bri)>>8, ((idx))); + //STS_WS2812B_Set_RGB((red*bri)>>8, (green*bri)>>8, (blue*bri)>>8, ((idx))); + //ws2812b_light_one_rgb((red*bri)>>8, (green*bri)>>8, (blue*bri)>>8, ((idx))); + + { + ws2812b_data[3*idx] = (green*bri)>>8; + ws2812b_data[3*idx+1] = (red*bri)>>8; + ws2812b_data[3*idx+2] = (blue*bri)>>8; + } + //ws2812b_light_one_rgb(uint8_t red, uint8_t green, uint8_t blue, uint8_t idx) //STS_WS2812B_Set_RGB((red*bri), (green*bri), (blue*bri), ((idx + start_position)%LED_COUNT)); } else if ((idx < start_position)||(idx > fade_len)) { // shorter than start position or longer than fade length, set to dark //STS_WS2812B_Set_RGB(red, green, blue, idx); - STS_WS2812B_Set_RGB(0, 0, 0, idx); + //STS_WS2812B_Set_RGB(0, 0, 0, idx); + //ws2812b_light_one_rgb(0, 0, 0, (idx)); + ws2812b_data[3*idx] = 0; + ws2812b_data[3*idx+1] = 0; + ws2812b_data[3*idx+2] = 0; } } + ws2812b_data_transfer(ws2812b_data, sizeof(ws2812b_data)); } void STS_Lamp_Bar_Refresh(void) @@ -235,7 +361,7 @@ void STS_Lamp_Bar_Set_STS_RGB_Color_FadeIn(uint8_t sts_lamp_color, uint8_t max_l switch (sts_lamp_color) { case STS_DARK: - STS_Lamp_Bar_Set_RGB_Color(0x0, 0x0, 0x0); + // STS_Lamp_Bar_Set_RGB_Color(0x0, 0x0, 0x0); break; case STS_GREEN: STS_Lamp_Bar_Set_RGB_Color_FadeIn(0x0, max_lum_level, 0x0, LED_COUNT/2, fade_length); @@ -270,7 +396,7 @@ void STS_Lamp_Bar_Set_STS_RGB_Color_FadeOut(uint8_t sts_lamp_color, uint8_t max_ switch (sts_lamp_color) { case STS_DARK: - STS_Lamp_Bar_Set_RGB_Color(0x0, 0x0, 0x0); +// STS_Lamp_Bar_Set_RGB_Color(0x0, 0x0, 0x0); break; case STS_GREEN: STS_Lamp_Bar_Set_RGB_Color_FadeOut(0x0, max_lum_level, 0x0, 0, fade_length); @@ -300,6 +426,8 @@ void STS_Lamp_Bar_Set_STS_RGB_Color_FadeOut(uint8_t sts_lamp_color, uint8_t max_ } void STS_Lamp_Bar_Set_STS_RGB_Color(uint8_t sts_lamp_color, uint8_t lum) { + ws2812b_light_all_with_lum_level(sts_lamp_color, lum); + /* if (sts_lamp_color <=8) { switch (sts_lamp_color) @@ -330,7 +458,7 @@ void STS_Lamp_Bar_Set_STS_RGB_Color(uint8_t sts_lamp_color, uint8_t lum) break; } } - +*/ } void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim) @@ -369,11 +497,11 @@ void STS_Lamp_Bar_Self_Test_Fade(void) APP_LOG(TS_OFF, VLEVEL_M, "\rFade Out %04d\r", lum_level); STS_Lamp_Bar_Set_STS_RGB_Color_FadeOut(color, lum_level, LED_COUNT/2); - HAL_Delay(2000); + HAL_Delay(1000); //lum_level += 5; //} while (lum_level < 200); - //STS_Lamp_Bar_Set_Dark(); - STS_Lamp_Bar_Refresh(); + STS_Lamp_Bar_Set_Dark(); + //STS_Lamp_Bar_Refresh(); } APP_LOG(TS_OFF, VLEVEL_M, "\r\n [#1] RGB Space Fade In Testing Start\r\n"); for (color=STS_GREEN; color < STS_COLOR_MAX; color++) @@ -383,11 +511,11 @@ void STS_Lamp_Bar_Self_Test_Fade(void) APP_LOG(TS_OFF, VLEVEL_M, "\rFade In %04d\r", lum_level); STS_Lamp_Bar_Set_STS_RGB_Color_FadeIn(color, lum_level, LED_COUNT/2); - HAL_Delay(2000); + HAL_Delay(1000); //lum_level += 5; //} while (lum_level < 200); - //STS_Lamp_Bar_Set_Dark(); - STS_Lamp_Bar_Refresh(); + STS_Lamp_Bar_Set_Dark(); + //STS_Lamp_Bar_Refresh(); } APP_LOG(TS_OFF, VLEVEL_M, "\r\n [#1] RGB Space Fade Out Fade In Testing Finished\r\n"); @@ -397,7 +525,7 @@ void STS_Lamp_Bar_Self_Test_Fade(void) void STS_Lamp_Bar_Self_Test(void) { uint8_t color=0, lum_level=DEFAULT_LUMINANCE_LEVEL; - +/* APP_LOG(TS_OFF, VLEVEL_H, "\r\n YunHorn STS Indicative Lamp Self Test\r\n"); STS_Lamp_Bar_Self_Test_Simple(); @@ -410,7 +538,18 @@ void STS_Lamp_Bar_Self_Test(void) STS_Lamp_Bar_Scoller(color, lum_level); } } +*/ + for (color = STS_GREEN; color < STS_COLOR_MAX; color++) + { + //for (lum_level=1; lum_level<250; lum_level+=50) + { + ws2812b_light_all(color); + } + HAL_Delay(1000); + } + STS_Lamp_Bar_Set_Dark(); + HAL_Delay(1000); STS_Lamp_Bar_Self_Test_Fade(); APP_LOG(TS_OFF, VLEVEL_H, "\r\n [##] YunHorn STS Indicative Lamp Self Test Finished\r\n"); diff --git a/STM32CubeIDE/Release/STS_O7.bin b/STM32CubeIDE/Release/STS_O7.bin index 6869593..94f2631 100644 Binary files a/STM32CubeIDE/Release/STS_O7.bin and b/STM32CubeIDE/Release/STS_O7.bin differ