Mercurial > ~darius > hgwebdir.cgi > modulator
annotate dac.pio @ 9:3acdebd7eec7
Make it actually work
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Fri, 21 Feb 2025 17:27:22 +1030 |
parents | 2db42eaba3c8 |
children | 98880b18bcc1 |
rev | line source |
---|---|
0
a55e39064a71
First commit of code that compiles.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
1 ; |
9 | 2 ; Copyright (c) 2025 Daniel O'Connor |
0
a55e39064a71
First commit of code that compiles.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
3 ; |
a55e39064a71
First commit of code that compiles.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
4 |
a55e39064a71
First commit of code that compiles.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
5 .program dac |
9 | 6 .define TRIGGER_IRQ 0 |
7 ; Need 1 side set pin, the clock | |
8 .side_set 1 | |
9 ; Force load at address 0 so DMA handler can force a jump | |
10 ; presumably we could calculate the address but this is easier. | |
11 .origin 0 | |
0
a55e39064a71
First commit of code that compiles.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
12 |
9 | 13 ; Clock in a 0 byte |
14 ; mov pins, null side 0 | |
15 ; nop side 1 | |
16 ; Wait for start trigger | |
17 ; wait 1 irq TRIGGER_IRQ side 0 | |
2
0d653f60dec8
Actually get data moving out.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
18 ; Clock DAC and write data from the FIFO |
9 | 19 ; DAC clocks data in on the rising clock edge |
20 ; Autopull is enabled so no need to pull | |
2
0d653f60dec8
Actually get data moving out.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
21 .wrap_target |
0d653f60dec8
Actually get data moving out.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
22 out pins 8 side 0 |
0d653f60dec8
Actually get data moving out.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
23 nop side 1 |
0d653f60dec8
Actually get data moving out.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
24 out pins 8 side 0 |
0d653f60dec8
Actually get data moving out.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
25 nop side 1 |
0d653f60dec8
Actually get data moving out.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
26 out pins 8 side 0 |
0d653f60dec8
Actually get data moving out.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
27 nop side 1 |
0d653f60dec8
Actually get data moving out.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
28 out pins 8 side 0 |
9 | 29 nop side 1 |
2
0d653f60dec8
Actually get data moving out.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
30 .wrap |
0
a55e39064a71
First commit of code that compiles.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
31 |
a55e39064a71
First commit of code that compiles.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
32 % c-sdk { |
5 | 33 static inline void dac_program_init(PIO pio, uint sm, uint offset, uint pin, uint clkdiv) { |
0
a55e39064a71
First commit of code that compiles.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
34 pio_sm_config c = dac_program_get_default_config(offset); |
a55e39064a71
First commit of code that compiles.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
35 |
2
0d653f60dec8
Actually get data moving out.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
36 // Set the OUT base pin to the provided `pin` parameter. |
0d653f60dec8
Actually get data moving out.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
37 // First 8 pins are data, last is clock |
0d653f60dec8
Actually get data moving out.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
38 sm_config_set_out_pins(&c, pin, 9); |
0d653f60dec8
Actually get data moving out.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
39 // Set the pin directions to output at the PIO |
0d653f60dec8
Actually get data moving out.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
40 pio_sm_set_consecutive_pindirs(pio, sm, pin, 9, true); |
0
a55e39064a71
First commit of code that compiles.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
41 // Connect these GPIOs to this PIO block |
2
0d653f60dec8
Actually get data moving out.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
42 for (int i = 0; i < 9; i++) |
0d653f60dec8
Actually get data moving out.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
43 pio_gpio_init(pio, pin + i); |
0
a55e39064a71
First commit of code that compiles.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
44 |
2
0d653f60dec8
Actually get data moving out.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
45 sm_config_set_out_shift( |
0
a55e39064a71
First commit of code that compiles.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
46 &c, |
2
0d653f60dec8
Actually get data moving out.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
47 true, // Shift-to-right |
9 | 48 true, // Autopull enabled |
5 | 49 32 // Autopull threshold (bits!) |
0
a55e39064a71
First commit of code that compiles.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
50 ); |
a55e39064a71
First commit of code that compiles.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
51 |
9 | 52 // Configure sideset pin to use for clock |
53 sm_config_set_sideset_pins(&c, pin + 8); | |
2
0d653f60dec8
Actually get data moving out.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
54 |
0d653f60dec8
Actually get data moving out.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
55 // We only send, so disable the RX FIFO to make the TX FIFO deeper. |
0d653f60dec8
Actually get data moving out.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
56 sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX); |
0d653f60dec8
Actually get data moving out.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
57 |
5 | 58 sm_config_set_clkdiv(&c, clkdiv); |
0
a55e39064a71
First commit of code that compiles.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
59 |
a55e39064a71
First commit of code that compiles.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
60 // Load our configuration, and start the program from the beginning |
a55e39064a71
First commit of code that compiles.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
61 pio_sm_init(pio, sm, offset, &c); |
a55e39064a71
First commit of code that compiles.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
62 pio_sm_set_enabled(pio, sm, true); |
a55e39064a71
First commit of code that compiles.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
63 } |
a55e39064a71
First commit of code that compiles.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
64 %} |