view dac.pio @ 3:b10097c3383d

DMA test data repeatedly into PIO FIFO
author Daniel O'Connor <darius@dons.net.au>
date Mon, 29 Mar 2021 18:05:05 +1030
parents 0d653f60dec8
children 2db42eaba3c8
line wrap: on
line source

;
; Copyright (c) 2021 Daniel O'Connor
;

.program dac

.side_set 1
; Clock DAC and write data from the FIFO

.wrap_target
    pull side 1
    out pins 8 side 0
    nop side 1
    out pins 8 side 0
    nop side 1
    out pins 8 side 0
    nop side 1
    out pins 8 side 0
.wrap

% c-sdk {
static inline void dac_program_init(PIO pio, uint sm, uint offset, uint pin) {
    pio_sm_config c = dac_program_get_default_config(offset);

    // Set the OUT base pin to the provided `pin` parameter.
    // First 8 pins are data, last is clock
    sm_config_set_out_pins(&c, pin, 9);
    // Set the pin directions to output at the PIO
    pio_sm_set_consecutive_pindirs(pio, sm, pin, 9, true);
    // Connect these GPIOs to this PIO block
    for (int i = 0; i < 9; i++)
        pio_gpio_init(pio, pin + i);

    sm_config_set_out_shift(
        &c,
        true,  // Shift-to-right
        false, // Autopull enabled
        8      // Autopull threshold (bits!)
    );

    // Configure clock as sideset pin
    sm_config_set_sideset_pins(&c, pin + 7);

    // We only send, so disable the RX FIFO to make the TX FIFO deeper.
    sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX);

//    sm_config_set_clkdiv(&c, 100);

    // Load our configuration, and start the program from the beginning
    pio_sm_init(pio, sm, offset, &c);
    pio_sm_set_enabled(pio, sm, true);
}
%}