RM2_1 #2
|
@ -32,20 +32,20 @@
|
|||
#define ZERO_PULSE (20)
|
||||
|
||||
#define LED_DATA_LEN 24
|
||||
#define WS2812B_DATA_LEN (24 * (STS_LAMP_BAR_LED_NUM+1))
|
||||
#define RESET_PULSE (24) //(80) TO FIX DARK_COLOR AND SM2
|
||||
#define WS2812B_DATA_LEN (LED_DATA_LEN * (STS_LAMP_BAR_LED_NUM+1))
|
||||
#define RESET_PULSE (16) //(80) TO FIX DARK_COLOR AND SM2
|
||||
|
||||
|
||||
typedef struct ws2812b_e {
|
||||
uint16_t head[3];
|
||||
//uint16_t head[3];
|
||||
uint16_t GRB[WS2812B_DATA_LEN];
|
||||
uint16_t tail;
|
||||
} WS2812B_FrameTypeDef;
|
||||
|
||||
volatile WS2812B_FrameTypeDef rgb_buf = {
|
||||
.head[0] = 0,
|
||||
.head[1] = 0,
|
||||
.head[2] = 0,
|
||||
// .head[0] = 0,
|
||||
// .head[1] = 0,
|
||||
// .head[2] = 0,
|
||||
.tail = 0
|
||||
};
|
||||
|
||||
|
@ -101,11 +101,9 @@ void STS_Lamp_Bar_Set_Dark(void)
|
|||
|
||||
void STS_WS2812B_Refresh(void)
|
||||
{
|
||||
STS_WS2812B_Set_RGB(0,0,0,STS_LAMP_BAR_LED_NUM );
|
||||
|
||||
__disable_irq();
|
||||
HAL_TIM_PWM_Start_DMA(&STS_LAMP_BAR_HTIM, STS_LAMP_BAR_TIM_CHANNEL, (uint32_t *)rgb_buf.GRB, (uint16_t)(sizeof(rgb_buf.GRB)));
|
||||
__enable_irq();
|
||||
//__disable_irq();
|
||||
HAL_TIM_PWM_Start_DMA(&STS_LAMP_BAR_HTIM, STS_LAMP_BAR_TIM_CHANNEL, (uint32_t *)&rgb_buf, (WS2812B_DATA_LEN+1));
|
||||
//__enable_irq();
|
||||
//HAL_TIM_PWM_Start_IT(&STS_LAMP_BAR_HTIM, STS_LAMP_BAR_TIM_CHANNEL);
|
||||
}
|
||||
|
||||
|
@ -143,15 +141,15 @@ void STS_Lamp_Bar_Scoller(uint8_t color, uint8_t lum_level)
|
|||
}
|
||||
|
||||
|
||||
void STS_WS2812B_Set_RGB(uint8_t R, uint8_t G, uint8_t B, uint8_t idx)
|
||||
void STS_WS2812B_Set_RGB(uint8_t red, uint8_t green, uint8_t blue, uint8_t idx)
|
||||
{
|
||||
if (idx < STS_LAMP_BAR_LED_NUM)
|
||||
//if (idx < STS_LAMP_BAR_LED_NUM)
|
||||
{
|
||||
for (uint8_t j = 0; j < 8; j ++)
|
||||
{
|
||||
rgb_buf.GRB[idx*24+j] = (uint16_t)(((G<<j)&0x80)? ONE_PULSE : ZERO_PULSE);
|
||||
rgb_buf.GRB[idx*24+8+j] = (uint16_t)(((R<<j)&0x80)? ONE_PULSE : ZERO_PULSE);
|
||||
rgb_buf.GRB[idx*24+16+j] = (uint16_t)(((B<<j)&0x80)? ONE_PULSE : ZERO_PULSE);
|
||||
rgb_buf.GRB[idx*24+j] = (uint16_t)(((green<<j)&0x80)? ONE_PULSE : ZERO_PULSE);
|
||||
rgb_buf.GRB[idx*24+8+j] = (uint16_t)(((red<<j)&0x80)? ONE_PULSE : ZERO_PULSE);
|
||||
rgb_buf.GRB[idx*24+16+j] = (uint16_t)(((blue<<j)&0x80)? ONE_PULSE : ZERO_PULSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -159,21 +157,27 @@ void STS_WS2812B_Set_RGB(uint8_t R, uint8_t G, uint8_t B, uint8_t idx)
|
|||
void STS_Lamp_Bar_Set_RGB_Color(uint8_t red, uint8_t green, uint8_t blue )
|
||||
{
|
||||
uint8_t i =0;
|
||||
HAL_Delay(1);
|
||||
//HAL_Delay(1);
|
||||
|
||||
__disable_irq();
|
||||
UTIL_MEM_set_8((void*)rgb_buf.GRB,0x0,(WS2812B_DATA_LEN));
|
||||
__enable_irq();
|
||||
//__disable_irq();
|
||||
//UTIL_MEM_set_8((void*)rgb_buf.GRB,0x0,(WS2812B_DATA_LEN));
|
||||
//__enable_irq();
|
||||
|
||||
for(i = 0; i < STS_LAMP_BAR_LED_NUM; i++)
|
||||
{
|
||||
STS_WS2812B_Set_RGB(red, green, blue, i);
|
||||
//STS_WS2812B_Set_RGB(red, green, blue, i);
|
||||
for (uint8_t j = 0; j < 8; j ++)
|
||||
{
|
||||
rgb_buf.GRB[i*24+j] = (uint16_t)(((green<<j)&0x80)? ONE_PULSE : ZERO_PULSE);
|
||||
rgb_buf.GRB[i*24+8+j] = (uint16_t)(((red<<j)&0x80)? ONE_PULSE : ZERO_PULSE);
|
||||
rgb_buf.GRB[i*24+16+j] = (uint16_t)(((blue<<j)&0x80)? ONE_PULSE : ZERO_PULSE);
|
||||
}
|
||||
STS_WS2812B_Set_RGB(0,0,0, i);
|
||||
}
|
||||
//STS_WS2812B_Set_RGB(0,0,0, i);
|
||||
|
||||
if (sts_service_mask == STS_SERVICE_MASK_L0) {
|
||||
//if (sts_service_mask == STS_SERVICE_MASK_L0) {
|
||||
STS_WS2812B_Refresh();
|
||||
}
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
|
@ -184,6 +188,7 @@ void STS_Lamp_Bar_Refresh(void)
|
|||
|
||||
void STS_Lamp_Bar_Set_STS_RGB_Color(uint8_t sts_lamp_color, uint8_t lum)
|
||||
{
|
||||
|
||||
switch (sts_lamp_color&0x0f)
|
||||
{
|
||||
case STS_DARK:
|
||||
|
|
|
@ -53,7 +53,7 @@ void MX_TIM1_Init(void)
|
|||
htim1.Init.Period = STS_LAMP_BAR_PWM_TIM_PERIOD;
|
||||
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
htim1.Init.RepetitionCounter = 0;
|
||||
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;//TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
|
@ -131,9 +131,9 @@ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)
|
|||
hdma_tim1_ch1.Init.PeriphInc = DMA_PINC_DISABLE;
|
||||
hdma_tim1_ch1.Init.MemInc = DMA_MINC_ENABLE;
|
||||
hdma_tim1_ch1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
|
||||
hdma_tim1_ch1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; //DMA_MDATAALIGN_HALFWORD;
|
||||
hdma_tim1_ch1.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; //DMA_MDATAALIGN_HALFWORD; //DMA_MDATAALIGN_HALFWORD;
|
||||
hdma_tim1_ch1.Init.Mode = DMA_CIRCULAR;
|
||||
hdma_tim1_ch1.Init.Priority = DMA_PRIORITY_LOW; //was HIGH
|
||||
hdma_tim1_ch1.Init.Priority = DMA_PRIORITY_HIGH; //was HIGH
|
||||
|
||||
if (HAL_DMA_Init(&hdma_tim1_ch1) != HAL_OK)
|
||||
{
|
||||
|
|
|
@ -1112,15 +1112,23 @@ static void OnYunhornSTSLampBarColorTimerEvent(void *context)
|
|||
{
|
||||
if (last_sts_lamp_bar_color != sts_lamp_bar_color)
|
||||
{
|
||||
|
||||
STS_Lamp_Bar_Set_STS_RGB_Color(sts_lamp_bar_color, DEFAULT_LUMINANCE_LEVEL);
|
||||
STS_WS2812B_Refresh();
|
||||
last_sts_lamp_bar_color = sts_lamp_bar_color;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (r_b)
|
||||
{
|
||||
|
||||
STS_Lamp_Bar_Set_STS_RGB_Color(high4, DEFAULT_LUMINANCE_LEVEL);
|
||||
else
|
||||
STS_WS2812B_Refresh();
|
||||
}
|
||||
else {
|
||||
STS_Lamp_Bar_Set_STS_RGB_Color(low4, DEFAULT_LUMINANCE_LEVEL);
|
||||
STS_WS2812B_Refresh();
|
||||
}
|
||||
|
||||
r_b = !r_b;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue