Newer
Older
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
//
// ring.RP2040PIO.pio
// RP2040 ring oscillator test with PIO
// connect P1 and P2
//
// Quentin Bolsee 12/27/22
//
// This work may be reproduced, modified, distributed,
// performed, and displayed for any purpose, but must
// acknowledge this project. Copyright is retained and
// must be preserved. The work is provided as is; no
// warranty is provided, and users accept all liability.
//
.program ring
mov pins, !pins
.wrap
% c-sdk {
static inline void ring_program_init(PIO pio, uint sm, uint offset, uint pin_in, uint pin_out) {
pio_sm_config c = ring_program_get_default_config(offset);
sm_config_set_in_pins(&c, pin_in);
sm_config_set_out_pins(&c, pin_out, 1);
// Set this pin's GPIO function (connect PIO to the pad)
pio_gpio_init(pio, pin_in);
pio_gpio_init(pio, pin_out);
// Set the pin direction to output at the PIO
pio_sm_set_consecutive_pindirs(pio, sm, pin_in, 1, false);
pio_sm_set_consecutive_pindirs(pio, sm, pin_out, 1, true);
// 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);
}
%}