42#define CHIP_NAME "Worldsemi WS2812B"
43#define MANUFACTURER_NAME "Worldsemi "
44#define SUPPLY_VOLTAGE_MIN 3.7f
45#define SUPPLY_VOLTAGE_MAX 5.3f
46#define MAX_CURRENT 16.0f
47#define TEMPERATURE_MIN -25.0f
48#define TEMPERATURE_MAX 85.0f
49#define DRIVER_VERSION 1000
73 handle->
debug_print(
"ws2812b: spi_10mhz_init is null.\n");
79 handle->
debug_print(
"ws2812b: spi_deinit is null.\n");
85 handle->
debug_print(
"ws2812b: spi_write_cmd is null.\n");
91 handle->
debug_print(
"ws2812b: delay_ms is null.\n");
113static void a_ws2812b_write_one_frame(uint32_t rgb, uint8_t temp[48])
118 const uint16_t one_code = 0xFFF8U;
119 const uint16_t zero_code = 0xE000U;
121 r = (uint8_t)((rgb >> 16) & 0xFF);
122 g = (uint8_t)((rgb >> 8) & 0xFF);
123 b = (uint8_t)((rgb >> 0) & 0xFF);
124 c = ((uint32_t)(g) << 16) | ((uint32_t)(r) << 8) | b;
126 memset(temp, 0,
sizeof(uint8_t) * 48);
129 for (i = 0; i < 24; i++)
131 if (((c >> (23 - i)) & 0x01) != 0)
133 for (j = 0; j < 16; j ++)
135 if (((one_code >> (15 - j)) & 0x01) != 0)
137 temp[point / 8] |= 1 << (7 - (point % 8));
141 temp[point / 8] |= 0 << (7 - (point % 8));
148 for (j = 0; j < 16; j ++)
150 if (((zero_code >> (15 - j)) & 0x01) != 0)
152 temp[point / 8] |= 1 << (7 - (point % 8));
156 temp[point / 8] |= 0 << (7 - (point % 8));
208 bit_size = bit_size / 8;
209 if (bit_size > temp_len)
211 handle->
debug_print(
"ws2812b: temp buffer is too small and "
212 "size will be %d.\n", bit_size);
216 for (i = 0; i < bit_size; i++)
222 handle->
debug_print(
"ws2812b: write command failed.\n");
227 bit_size = 24 * 16 * len;
228 bit_size = bit_size / 8;
229 if (bit_size > temp_len)
231 handle->
debug_print(
"ws2812b: temp buffer is too small and "
232 "size will be %d.\n", bit_size);
237 for (i = 0; i < len; i++)
239 a_ws2812b_write_one_frame(rgb[i], &temp[i * 48]);
244 handle->
debug_print(
"ws2812b: write command failed.\n");
288 bit_size = bit_size / 8;
289 if (bit_size > temp_len)
291 handle->
debug_print(
"ws2812b: temp buffer is too small and "
292 "size will be %d.\n", bit_size);
297 for (i = 0; i < bit_size; i++)
304 handle->
debug_print(
"ws2812b: write command failed.\n");
355 bit_size = 24 * 16 * len;
356 bit_size = bit_size / 8;
357 if (bit_size > temp_len)
359 handle->
debug_print(
"ws2812b: temp buffer is too small and "
360 "size will be %d.\n", bit_size);
365 for (i = 0; i < len; i++)
367 a_ws2812b_write_one_frame(rgb[i], &temp[i * 48]);
372 handle->
debug_print(
"ws2812b: write command failed.\n");
406 handle->
debug_print(
"ws2812b: spi deinit failed.\n");
#define SUPPLY_VOLTAGE_MAX
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define CHIP_NAME
chip register definition
driver ws2812b header file
uint8_t ws2812b_info(ws2812b_info_t *info)
get chip's information
struct ws2812b_info_s ws2812b_info_t
ws2812b information structure definition
uint8_t ws2812b_write(ws2812b_handle_t *handle, uint32_t *rgb, uint32_t len, uint8_t *temp, uint32_t temp_len)
write reset and color frame
uint8_t ws2812b_deinit(ws2812b_handle_t *handle)
close the chip
struct ws2812b_handle_s ws2812b_handle_t
ws2812b handle structure definition
uint8_t ws2812b_write_only_reset(ws2812b_handle_t *handle, uint32_t len, uint8_t *temp, uint32_t temp_len)
write the reset frame
uint8_t ws2812b_write_only_color(ws2812b_handle_t *handle, uint32_t *rgb, uint32_t len, uint8_t *temp, uint32_t temp_len)
write the color frame
#define WS2812B_EACH_RESET_BIT_FRAME_LEN
ws2812b each reset bit frame length definition
uint8_t ws2812b_init(ws2812b_handle_t *handle)
initialize the chip
uint8_t ws2812b_set_reg(ws2812b_handle_t *handle, uint8_t *buf, uint16_t len)
set the chip register
void(* delay_ms)(uint32_t ms)
void(* debug_print)(const char *const fmt,...)
uint8_t(* spi_deinit)(void)
uint8_t(* spi_10mhz_init)(void)
uint8_t(* spi_write_cmd)(uint8_t *buf, uint16_t len)
float supply_voltage_max_v
char manufacturer_name[32]
float supply_voltage_min_v