aboutsummaryrefslogtreecommitdiffstats
path: root/src/ws2812.h
blob: 8c878ff6817f7336745308327aa4889826d882bc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#pragma once

#include "hardware/pio.h"
#include "hardware/gpio.h"

#include <stdbool.h>

#define _WS2812_U8(v, si, so) ((((uint32_t) (v) >> si) & 0xFF) << so)
#define WS2812_U32RGB(rgb) (_WS2812_U8(rgb, 16, 0) \
	| _WS2812_U8(rgb, 0, 8) | _WS2812_U8(rgb, 8, 16))

struct ws2812 {
	PIO pio;
	uint sm;
	uint pin;
	bool init;
};

void ws2812_init(struct ws2812 *pix, PIO pio, uint pin);
void ws2812_put(struct ws2812 *pix, uint32_t rgb);