Skip to content
Snippets Groups Projects
ring.RP2040PIO.pio 1.16 KiB
Newer Older
  • Learn to ignore specific revisions
  • Quentin Bolsee's avatar
    Quentin Bolsee committed
    //
    // ring.RP2040PIO.pio
    //    RP2040 ring oscillator test with PIO
    //    connect P1 and P2
    //
    // Quentin Bolsee 12/27/22
    //
    // This work may be reproduced, modified, distributed,
    // performed, and displayed for any purpose, but must
    // acknowledge this project. Copyright is retained and
    // must be preserved. The work is provided as is; no
    // warranty is provided, and users accept all liability.
    //
    
    .program ring
        mov pins, !pins
    .wrap
    
    
    % c-sdk {
    static inline void ring_program_init(PIO pio, uint sm, uint offset, uint pin_in, uint pin_out) {
        pio_sm_config c = ring_program_get_default_config(offset);
    
        sm_config_set_in_pins(&c, pin_in);
        sm_config_set_out_pins(&c, pin_out, 1);
    
        // Set this pin's GPIO function (connect PIO to the pad)
        pio_gpio_init(pio, pin_in);
        pio_gpio_init(pio, pin_out);
    
        // Set the pin direction to output at the PIO
        pio_sm_set_consecutive_pindirs(pio, sm, pin_in, 1, false);
        pio_sm_set_consecutive_pindirs(pio, sm, pin_out, 1, true);
    
        // Load our configuration, and jump to the start of the program
        pio_sm_init(pio, sm, offset, &c);
        // Set the state machine running
        pio_sm_set_enabled(pio, sm, true);
    }
    %}