diff options
Diffstat (limited to 'include/drv/ws2812b.h')
-rw-r--r-- | include/drv/ws2812b.h | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/include/drv/ws2812b.h b/include/drv/ws2812b.h new file mode 100644 index 0000000..9cf35e4 --- /dev/null +++ b/include/drv/ws2812b.h @@ -0,0 +1,42 @@ +#pragma once +#ifndef INCLUDE_DRV_WS2812B_H_ +#define INCLUDE_DRV_WS2812B_H_ + +#include <stdint.h> +#include "driver/spi_master.h" + +typedef struct { + uint8_t r; + uint8_t g; + uint8_t b; +} ws2812b_rgb_t; + +typedef struct { + uint8_t* buf_; /* Buffer to hold the value to spi. */ + + uint32_t n_rgb; /* Number of rgb values which exist. */ + ws2812b_rgb_t rgb[]; /* Colors to write. */ +} ws2812b_buffer_t; + +struct WS2812B; +typedef struct WS2812B ws2812b_t; + +ws2812b_buffer_t* ws2812b_new_buffer(uint32_t size); + +ws2812b_t* ws2812b_init(spi_device_handle_t spi); + +esp_err_t ws2812b_write_sync(ws2812b_t* drv, ws2812b_buffer_t* buffer); + +static inline void ws2812b_buffer_set_rgb( + ws2812b_buffer_t* buf, size_t idx, uint8_t r, uint8_t g, uint8_t b) +{ + if (idx >= buf->n_rgb) { + return; + } + + buf->rgb[idx].r = r; + buf->rgb[idx].g = g; + buf->rgb[idx].b = b; +} + +#endif /* INCLUDE_DRV_WS2812B_H_ */ |