-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0328d95
commit 9625226
Showing
11 changed files
with
208 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
build | ||
release | ||
generated/* | ||
generated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#pragma once | ||
|
||
#define FW_VERSION 0x08 | ||
#define FW_VERSION 0x09 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#include "pico/stdlib.h" | ||
#include "hardware/pio.h" | ||
#include "hardware/clocks.h" | ||
#include "ws2812.pio.h" | ||
|
||
#include "hardware.h" | ||
|
||
static uint pio_offset = 0; | ||
|
||
void ws2812_setup() { | ||
pio_offset = pio_add_program(WS2812_PIO, &ws2812_program); | ||
} | ||
|
||
void ws2812_enable(bool rgbw) { | ||
ws2812_program_init(WS2812_PIO, 0, pio_offset, SAO_IO0_PIN, 800000, rgbw); | ||
} | ||
|
||
void ws2812_disable() { | ||
pio_sm_set_enabled(WS2812_PIO, 0, false); | ||
} | ||
|
||
void ws2812_put(uint32_t data) { | ||
pio_sm_put_blocking(WS2812_PIO, 0, data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#pragma once | ||
|
||
void ws2812_setup(); | ||
void ws2812_enable(bool rgbw); | ||
void ws2812_disable(); | ||
void ws2812_put(uint32_t data); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
; | ||
; Copyright (c) 2020 Raspberry Pi (Trading) Ltd. | ||
; | ||
; SPDX-License-Identifier: BSD-3-Clause | ||
; | ||
|
||
.program ws2812 | ||
.side_set 1 | ||
|
||
.define public T1 2 | ||
.define public T2 5 | ||
.define public T3 3 | ||
|
||
.lang_opt python sideset_init = pico.PIO.OUT_HIGH | ||
.lang_opt python out_init = pico.PIO.OUT_HIGH | ||
.lang_opt python out_shiftdir = 1 | ||
|
||
.wrap_target | ||
bitloop: | ||
out x, 1 side 0 [T3 - 1] ; Side-set still takes place when instruction stalls | ||
jmp !x do_zero side 1 [T1 - 1] ; Branch on the bit we shifted out. Positive pulse | ||
do_one: | ||
jmp bitloop side 1 [T2 - 1] ; Continue driving high, for a long pulse | ||
do_zero: | ||
nop side 0 [T2 - 1] ; Or drive low, for a short pulse | ||
.wrap | ||
|
||
% c-sdk { | ||
#include "hardware/clocks.h" | ||
|
||
static inline void ws2812_program_init(PIO pio, uint sm, uint offset, uint pin, float freq, bool rgbw) { | ||
|
||
pio_gpio_init(pio, pin); | ||
pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true); | ||
|
||
pio_sm_config c = ws2812_program_get_default_config(offset); | ||
sm_config_set_sideset_pins(&c, pin); | ||
sm_config_set_out_shift(&c, false, true, rgbw ? 32 : 24); | ||
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX); | ||
|
||
int cycles_per_bit = ws2812_T1 + ws2812_T2 + ws2812_T3; | ||
float div = clock_get_hz(clk_sys) / (freq * cycles_per_bit); | ||
sm_config_set_clkdiv(&c, div); | ||
|
||
pio_sm_init(pio, sm, offset, &c); | ||
pio_sm_set_enabled(pio, sm, true); | ||
} | ||
%} | ||
|
||
.program ws2812_parallel | ||
|
||
.define public T1 2 | ||
.define public T2 5 | ||
.define public T3 3 | ||
|
||
.wrap_target | ||
out x, 32 | ||
mov pins, !null [T1-1] | ||
mov pins, x [T2-1] | ||
mov pins, null [T3-2] | ||
.wrap | ||
|
||
% c-sdk { | ||
#include "hardware/clocks.h" | ||
|
||
static inline void ws2812_parallel_program_init(PIO pio, uint sm, uint offset, uint pin_base, uint pin_count, float freq) { | ||
for(uint i=pin_base; i<pin_base+pin_count; i++) { | ||
pio_gpio_init(pio, i); | ||
} | ||
pio_sm_set_consecutive_pindirs(pio, sm, pin_base, pin_count, true); | ||
|
||
pio_sm_config c = ws2812_parallel_program_get_default_config(offset); | ||
sm_config_set_out_shift(&c, true, true, 32); | ||
sm_config_set_out_pins(&c, pin_base, pin_count); | ||
sm_config_set_set_pins(&c, pin_base, pin_count); | ||
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX); | ||
|
||
int cycles_per_bit = ws2812_parallel_T1 + ws2812_parallel_T2 + ws2812_parallel_T3; | ||
float div = clock_get_hz(clk_sys) / (freq * cycles_per_bit); | ||
sm_config_set_clkdiv(&c, div); | ||
|
||
pio_sm_init(pio, sm, offset, &c); | ||
pio_sm_set_enabled(pio, sm, true); | ||
} | ||
%} |