-
Notifications
You must be signed in to change notification settings - Fork 53
/
sounder.pio
43 lines (33 loc) · 980 Bytes
/
sounder.pio
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
43
.program sounder
.wrap_target
pull; blocks
out X, 31;
out Y, 1;
loop:
set pins, 0 [31];
jmp !Y, noSound [31];
set pins, 1 [ 0];
noSound:
nop [30];
jmp X--, loop [31];
irq 1;
.wrap
% c-sdk {
#include "hardware/clocks.h"
static inline void sounder_program_init(PIO pio, uint sm, uint offset, uint pin)
{
pio_gpio_init(pio, pin);
pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true);
pio_sm_config c = sounder_program_get_default_config(offset);
// OSR shift_right, auto_pull, threshould
sm_config_set_out_shift(&c, true, false, 32);
//sm_config_set_out_pins(&c, pin, 1);
sm_config_set_set_pins(&c, pin, 1);
// all the FIFOs is TX
//sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX);
sm_config_set_clkdiv(&c, (float)clock_get_hz(clk_sys) / (2000UL));
// start state machine
pio_sm_init(pio, sm, offset, &c);
pio_sm_set_enabled(pio, sm, true);
}
%}