forked from DangerousPrototypes/BusPirate5-firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wavegen.pio
50 lines (38 loc) · 1.3 KB
/
wavegen.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
;
; Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
;
; SPDX-License-Identifier: BSD-3-Clause
;
.program wavegen
; Repeatedly get one word of data from the TX FIFO, stalling when the FIFO is
; empty. Write the least significant bit to the OUT pin group.
.wrap_target
out pins, 8
.wrap
;loop:
; pull
; out pins, 2
; jmp loop
% c-sdk {
static inline void wavegen_program_init(PIO pio, uint sm, uint offset, uint pin) {
pio_sm_set_enabled(pio, sm, false);
pio_sm_clear_fifos(pio, sm);
pio_sm_restart(pio, sm);
pio_sm_config c = wavegen_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, 8);
// Set this pin's GPIO function (connect PIO to the pad)
for(uint8_t i=0; i<8; i++)
pio_gpio_init(pio, pin+i);
// Set the pin direction to output at the PIO
pio_sm_set_consecutive_pindirs(pio, sm, pin, 8, true);
//sm_config_set_out_shift(&c, false, true, 8);
sm_config_set_out_shift(&c, true, true, 8);
sm_config_set_clkdiv(&c, 1);
// 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);
}
%}