-
Notifications
You must be signed in to change notification settings - Fork 0
/
stepper.pio
37 lines (29 loc) · 977 Bytes
/
stepper.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
.program stepper_1
;.side_set 1
.define public STD 1
.wrap_target
bitloop:
out x, 1 ; Side-set still takes place when instruction stalls
jmp !x do_zero ; Branch on the bit we shifted out
do_one:
set pins 1 [STD + 3]
set pins 0 [STD]
jmp bitloop
do_zero:
set pins 0 ; Or drive low, for a short pulse
.wrap
% c-sdk {
#include "hardware/clocks.h"
static inline void stepper_1_program_init(PIO pio, uint sm, uint offset, uint pin, float freq, bool step) {
pio_gpio_init(pio, pin);
pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true);
pio_sm_config c = stepper_1_program_get_default_config(offset);
sm_config_set_set_pins(&c, pin, 1);
sm_config_set_out_shift(&c, false, true, step ? 32 : 32);
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX);
float div = clock_get_hz(clk_sys) / (freq);
sm_config_set_clkdiv(&c, div);
pio_sm_init(pio, sm, offset, &c);
pio_sm_set_enabled(pio, sm, true);
}
%}