You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
597 B
C

#include "ws2812.h"
uint16_t ws2812_data[RST_PERIOD_NUM + WS2812_NUM * 24] = { 0 };
void ws2812_data_set(uint8_t led_id, uint8_t r, uint8_t g, uint8_t b) {
uint16_t *p = ws2812_data + RST_PERIOD_NUM + led_id * 24;
for (uint8_t i = 0; i < 8; i++) {
p[i] = (r << i) & (0x80) ? CODE_ONE_DUTY : CODE_ZERO_DUTY;
p[i + 8] = (g << i) & (0x80) ? CODE_ONE_DUTY : CODE_ZERO_DUTY;
p[i + 16] = (b << i) & (0x80) ? CODE_ONE_DUTY : CODE_ZERO_DUTY;
}
}
void ws2812_updata(void) {
HAL_TIM_PWM_Start_DMA(&htim3, TIM_CHANNEL_1, ws2812_data,
RST_PERIOD_NUM + WS2812_NUM * 24);
}