blob: 9cf35e4e67e5dbad6063e1e9db10f33655ec922e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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_ */
|