view trigger.pio @ 24:c7845db23ab2

Add sideset for trigger output. Trigger both SMs
author Daniel O'Connor <darius@dons.net.au>
date Tue, 25 Feb 2025 16:47:00 +1030
parents 283955273884
children 6070d2e66b4c
line wrap: on
line source

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

.program trigger
.define DAC_TRIGGER_IRQ 0
.define CTRL_TRIGGER_IRQ 1
; Use 1 side set pin for debugging
.side_set 1

.wrap_target
; Wait for trigger to be low
    wait 0 pin 0 side 0
; Wait for rising edge
    wait 1 pin 0 side 0
; Signal other state machines
    irq nowait DAC_TRIGGER_IRQ side 1
    irq nowait CTRL_TRIGGER_IRQ side 1
.wrap

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

    // Configure SM input pin mapping to point to trigger pin
    sm_config_set_in_pins(&c, pin);
    // Set to input
    pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, false);
    // Connect this GPIO to this PIO block
    pio_gpio_init(pio, pin);

    // Configure side pin mapping to point to debug pin
    sm_config_set_sideset_pins(&c, pin + 1);
    // Set to output
    pio_sm_set_consecutive_pindirs(pio, sm, pin + 1, 1, true);
    // Connect this GPIO to this PIO block
    pio_gpio_init(pio, pin + 1);

    sm_config_set_clkdiv(&c, clkdiv);

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