aboutsummaryrefslogtreecommitdiffstats
path: root/src/neopix.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/neopix.c')
-rw-r--r--src/neopix.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/neopix.c b/src/neopix.c
new file mode 100644
index 0000000..ddc78a3
--- /dev/null
+++ b/src/neopix.c
@@ -0,0 +1,22 @@
+#include "hardware/pio.h"
+
+#include "neopix.h"
+#include "ws2812.pio.h"
+
+void
+neopix_init(struct neopix *pix, PIO pio, uint sm, uint pin)
+{
+ uint offset;
+
+ pix->sm = sm;
+ pix->pio = pio;
+ pix->pin = pin;
+ offset = pio_add_program(pix->pio, &ws2812_program);
+ ws2812_program_init(pix->pio, pix->sm, offset,
+ pix->pin, 800000, false);
+}
+
+void
+neopix_put(struct neopix *pix, uint32_t rgb) {
+ pio_sm_put_blocking(pix->pio, pix->sm, rgb << 8u);
+}