-
Notifications
You must be signed in to change notification settings - Fork 0
/
tx-miso.pio
38 lines (27 loc) · 1.11 KB
/
tx-miso.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
; Sony MI-SPI state machine for sending data in the MISO direction
; (Emulating a flash to a real body)
; 2023/04 Andrew Villeneuve
; Pin mapping:
; IN 0 = CLK
; OUT 0 = DATA
; The MISO START pulse will have already been evaluated when the SM starts,
; so the first CLK pulse we see should be for a data bit
.program miso
.wrap_target
wait 1 pin 0 ;wait for rising edge of clock (IN pin 0)
out pins, 1 ;assert the next (1) bit from the OSR onto the DATA pin
wait 0 pin 0 ;wait for falling edge of clock (IN pin 0)
.wrap
% c-sdk {
static inline void miso_program_init(PIO pio, uint sm, uint offset, uint clkpin, uint datapin) {
pio_sm_config c = miso_program_get_default_config(offset);
// Map Clock to IN pin 0, Data to OUT pin 0
sm_config_set_in_pins(&c, clkpin);
sm_config_set_out_pins(&c, datapin, 1);
// Deliberately not selecting the PIO function for the DATA pin yet
// OSR Shift: LSB first, Autopull enabled, every 8 bits
sm_config_set_out_shift(&c, true, true, 8);
// Load our configuration, and jump to the start of the program
pio_sm_init(pio, sm, offset, &c);
}
%}