-
Notifications
You must be signed in to change notification settings - Fork 54
/
lightning_tx.pio
74 lines (58 loc) · 1.88 KB
/
lightning_tx.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
.program lightning_tx
; 1 NOP is 0.5us
SET PINS 1
SET PINDIRS 1
send:
; Pull in one byte from OSR
PULL
; Output counter (reg X)
SET X, 7
continue_send:
; Pull 1 bit from OSR
OUT Y 1
; if Y is zero we send a (you guessed it) zero
JMP !Y send_zero
; otherwise we send a 1
send_one:
SET PINS 0 [3]
SET PINS 1 [11]
JMP send_done
send_zero:
SET PINS 0 [13]
SET PINS 1 [2]
send_done:
JMP X-- continue_send
NOP [14]
PUSH [15]
% c-sdk {
static inline pio_sm_config lightning_tx_program_init(PIO pio, uint sm, uint offset, uint pin, float clkdiv) {
pio_sm_set_pins_with_mask(pio, sm, 1u << pin, 1u << pin);
pio_sm_set_pindirs_with_mask(pio, sm, 1u << pin, 1u << pin);
//pio_sm_set_pindirs_with_mask(pio, sm, 1u << 19, 0u << pin);
pio_gpio_init(pio, 19);
pio_sm_config c = lightning_tx_program_get_default_config(offset);
// Map the state machine's OUT pin group to one pin, namely the `pin`
// parameter to this function.
sm_config_set_out_pins(&c, pin, 1);
sm_config_set_set_pins(&c, pin, 1);
sm_config_set_in_pins(&c, pin);
sm_config_set_jmp_pin(&c, pin);
//pio_sm_set_sideset_pins(pio, sm, 19);
//sm_config_set_sideset_pins(&c, 19);
// shift_right = false, auto_push = false
sm_config_set_in_shift(&c, false, false, 32);
// shift_right = true, auto_pull = false
sm_config_set_out_shift(&c, true, false, 32);
// Set this pin's GPIO function (connect PIO to the pad)
pio_gpio_init(pio, pin);
pio_gpio_init(pio, 19);
// Set the pin direction to output at the PIO
//pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, false);
sm_config_set_clkdiv(&c, clkdiv);
// Load our configuration, and jump to the start of the program
pio_sm_init(pio, sm, offset, &c);
// Set the state machine running
pio_sm_set_enabled(pio, sm, true);
return c;
}
%}