|
| 1 | +#ifndef DMD_INTERFACE_DESEGA_H |
| 2 | +#define DMD_INTERFACE_DESEGA_H |
| 3 | + |
| 4 | +#include "dmd_interface_desega.pio.h" |
| 5 | +#include "hardware/gpio.h" |
| 6 | +#include "hardware/pio.h" |
| 7 | + |
| 8 | +static inline void dmd_reader_desega_program_init(PIO pio, uint sm, |
| 9 | + uint offset) { |
| 10 | + pio_sm_config c = dmd_reader_desega_program_get_default_config(offset); |
| 11 | + |
| 12 | + // Set the IN pin, we don't use any other |
| 13 | + sm_config_set_in_pins(&c, desega_SDATA); |
| 14 | + |
| 15 | + // Set the pin direction at the PIO |
| 16 | + pio_sm_set_consecutive_pindirs(pio, sm, desega_SDATA, 2, |
| 17 | + false); // SDATA, DOTCLK |
| 18 | + |
| 19 | + // Connect these GPIOs to this PIO block |
| 20 | + pio_gpio_init(pio, desega_DOTCLK); |
| 21 | + pio_gpio_init(pio, desega_SDATA); |
| 22 | + |
| 23 | + // Shifting to left matches the customary MSB-first ordering of SPI. |
| 24 | + sm_config_set_in_shift(&c, |
| 25 | + false, // Shift-to-right = false |
| 26 | + true, // Autopull enabled |
| 27 | + 32 // Autopull threshold |
| 28 | + ); |
| 29 | + |
| 30 | + // We only send, so disable the TX FIFO to make the RX FIFO deeper. |
| 31 | + sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_RX); |
| 32 | + |
| 33 | + // Load our configuration, do not yet start the program |
| 34 | + pio_sm_init(pio, sm, offset, &c); |
| 35 | +} |
| 36 | + |
| 37 | +static inline void dmd_framedetect_desega_program_init(PIO pio, uint sm, |
| 38 | + uint offset) { |
| 39 | + pio_sm_config c = dmd_framedetect_desega_program_get_default_config(offset); |
| 40 | + // DE is used for jump control |
| 41 | + sm_config_set_jmp_pin(&c, desega_DE); |
| 42 | + |
| 43 | + // Set the pin direction at the PIO |
| 44 | + pio_sm_set_consecutive_pindirs(pio, sm, desega_DE, 1, false); |
| 45 | + |
| 46 | + // Connect this GPIO to this PIO block |
| 47 | + pio_gpio_init(pio, desega_DE); |
| 48 | + |
| 49 | + // Load our configuration, do not yet start the program |
| 50 | + pio_sm_init(pio, sm, offset, &c); |
| 51 | +} |
| 52 | + |
| 53 | +#endif // DMD_INTERFACE_DESEGA_H |
0 commit comments