RP2040-code/Function Generator/FastDAC.pio

26 wiersze
1.6 KiB
Plaintext

.program pio_FastDAC
; Repeatedly get one word of data from the TX FIFO, stalling when the FIFO is
; empty. Write the data to the OUT pin group.
.wrap_target
; Get data bits from DMA via Output Shift Register (OSR) to PINS.
out PINS, 8 ; 1 machine cycle
; ===================
; 1 machine cycle
; ===================
.wrap ; Loop back to wrap_target
% c-sdk {
// This is a raw helper function for use by the user which sets up the GPIO output, and configures the SM
// to output on a particular pin.
// Note: No divider is specified for the SM, so it will default to the same speed as the CPU.
void pio_FastDAC_program_init(PIO pio, uint sm, uint offset, uint pin) {
for (uint i=0; i<DAC_Bits; i++) { pio_gpio_init(pio, i+2); } // Allow PIO to control GPIO pins as outputs
pio_sm_set_consecutive_pindirs(pio, sm, 2, DAC_Bits, true); // Set the pin direction to output (in PIO)
pio_sm_config c = pio_FastDAC_program_get_default_config(offset); // Define PIO Configuration structure
sm_config_set_out_pins(&c, 2, DAC_Bits); // Configure pins to be targeted by the OUT (and MOV) commands
sm_config_set_out_shift(&c, true, true, DAC_Bits); // Shift right, Autopull enabled, 6/8 bits
pio_sm_init(pio, sm, offset, &c); // Load configuration and jump to start of the program
pio_sm_set_enabled(pio, sm, true);
}
%}