// -------------------------------------------------- //
// This file is autogenerated by pioasm; do not edit! //
// -------------------------------------------------- //

#pragma once

#if !PICO_NO_HARDWARE
#include "hardware/pio.h"
#endif

// -------------- //
// dvi_serialiser //
// -------------- //

#define dvi_serialiser_wrap_target 0
#define dvi_serialiser_wrap 1

static const uint16_t dvi_serialiser_program_instructions[] = {
            //     .wrap_target
    0x70a1, //  0: out    pc, 1           side 2     
    0x68a1, //  1: out    pc, 1           side 1     
            //     .wrap
};

#if !PICO_NO_HARDWARE
static const struct pio_program dvi_serialiser_program = {
    .instructions = dvi_serialiser_program_instructions,
    .length = 2,
    .origin = 0,
};

static inline pio_sm_config dvi_serialiser_program_get_default_config(uint offset) {
    pio_sm_config c = pio_get_default_sm_config();
    sm_config_set_wrap(&c, offset + dvi_serialiser_wrap_target, offset + dvi_serialiser_wrap);
    sm_config_set_sideset(&c, 2, false, false);
    return c;
}
#endif

// -------------------- //
// dvi_serialiser_debug //
// -------------------- //

#define dvi_serialiser_debug_wrap_target 0
#define dvi_serialiser_debug_wrap 11

static const uint16_t dvi_serialiser_debug_program_instructions[] = {
            //     .wrap_target
    0x98e0, //  0: pull   ifempty block   side 1     
    0xb042, //  1: nop                    side 0     
    0x6001, //  2: out    pins, 1                    
    0x6001, //  3: out    pins, 1                    
    0x6001, //  4: out    pins, 1                    
    0x6001, //  5: out    pins, 1                    
    0x6001, //  6: out    pins, 1                    
    0x6001, //  7: out    pins, 1                    
    0x6001, //  8: out    pins, 1                    
    0x6001, //  9: out    pins, 1                    
    0x6001, // 10: out    pins, 1                    
    0x6001, // 11: out    pins, 1                    
            //     .wrap
};

#if !PICO_NO_HARDWARE
static const struct pio_program dvi_serialiser_debug_program = {
    .instructions = dvi_serialiser_debug_program_instructions,
    .length = 12,
    .origin = -1,
};

static inline pio_sm_config dvi_serialiser_debug_program_get_default_config(uint offset) {
    pio_sm_config c = pio_get_default_sm_config();
    sm_config_set_wrap(&c, offset + dvi_serialiser_debug_wrap_target, offset + dvi_serialiser_debug_wrap);
    sm_config_set_sideset(&c, 2, true, false);
    return c;
}

#include "dvi_config_defs.h"
static inline void dvi_serialiser_program_init(PIO pio, uint sm, uint offset, uint data_pins, bool debug) {
    pio_sm_set_pins_with_mask(pio, sm, 2u << data_pins, 3u << data_pins);
    pio_sm_set_pindirs_with_mask(pio, sm, ~0u, 3u << data_pins);
    pio_gpio_init(pio, data_pins);
    pio_gpio_init(pio, data_pins + 1);
    pio_sm_config c;
    if (debug) {
        c = dvi_serialiser_debug_program_get_default_config(offset);
    }
    else {
        c = dvi_serialiser_program_get_default_config(offset);
    }
    sm_config_set_sideset_pins(&c, data_pins);
    if (debug)
	    sm_config_set_out_pins(&c, data_pins, 1);
    sm_config_set_out_shift(&c, true, !debug, 10 * DVI_SYMBOLS_PER_WORD);
    sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX);
    pio_sm_init(pio, sm, offset, &c);
    pio_sm_set_enabled(pio, sm, false);
}

#endif

