aboutsummaryrefslogtreecommitdiff
path: root/include/drv/ws2812B/ws2812b.h
blob: d7137a10c6dcf0bfab30f4b0cafe27317a3acb8a (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
#ifndef WS2812B_H_
#define WS2812B_H_

#include "kern/common.h"
#include "kern/spi/spi_manager.h"

typedef struct {
  /* why is it out of order? Don't know! That's the way the hardware was
   * designed! */
  uint8_t g;
  uint8_t r;
  uint8_t b;
} PACKED rgb_t;

typedef struct {
  spi_t* spi;
} ws2812b_t;

static_assert(sizeof(rgb_t) == 3, "Sizeof rgb_t should be 3.");

ws2812b_t* ws2812b_new(spi_select_t spi_select, int* ec);

void ws2812b_latch(ws2812b_t* drv);

uint8_t* ws2812b_compile_rgb(rgb_t* out, size_t arr_len);

void ws2812b_write_rgb_sync(ws2812b_t* drv, uint8_t r, uint8_t g, uint8_t b);

void ws2812b_write_rgb_arr_sync(ws2812b_t* drv, rgb_t* arr, size_t arr_len);

void ws2812b_delete(ws2812b_t* drv);

#endif /* WS2812B_H_ */