; Program name .program rgb2 .wrap_target set pins, 0 ; Zero RGB pins in blanking mov x, y ; Initialize counter variable wait 1 irq 2 [3] ; Wait for vsync active mode (starts 5 cycles after execution) colorout: ;pull block ; Pull color value (use autopull) out pins, 8 [7] ; Push out to pins (byte pixel) jmp x-- colorout ; Stay here thru horizontal active mode .wrap % c-sdk { static inline void rgb2_program_init(PIO pio, uint sm, uint offset, uint pin) { // creates state machine configuration object c, sets // to default configurations. I believe this function is auto-generated // and gets a name of _program_get_default_config // Yes, page 40 of SDK guide pio_sm_config c = rgb_program_get_default_config(offset); // Map the state machine's SET and OUT pin group to 8 pins, the `pin` // parameter to this function is the lowest one. These groups overlap. sm_config_set_set_pins(&c, pin, 8); sm_config_set_out_pins(&c, pin, 8); // turn off autopull //sm_config_set_out_shift (pio_sm_config *c, bool shift_right, bool autopull, uint pull_threshold) sm_config_set_out_shift (&c, 0, 1, 3) ; // Set clock division (Commented out, this one runs at full speed) // sm_config_set_clkdiv(&c, 5) ; // Set this pin's GPIO function (connect PIO to the pad) pio_gpio_init(pio, pin); pio_gpio_init(pio, pin+1); pio_gpio_init(pio, pin+2); pio_gpio_init(pio, pin+3); pio_gpio_init(pio, pin+4); pio_gpio_init(pio, pin+5); pio_gpio_init(pio, pin+6); pio_gpio_init(pio, pin+7); // Set the pin direction to output at the PIO (8 pins) pio_sm_set_consecutive_pindirs(pio, sm, pin, 8, true); // Load our configuration, and jump to the start of the program pio_sm_init(pio, sm, offset, &c); // // three lines copied from PWM example to into a register in a sm // (and therefore save two insructions in the sm program) pio_sm_put_blocking(pio, sm, 319); // (horizontal active) - 1 pio_sm_exec(pio, sm, pio_encode_pull(false, false)); pio_sm_exec(pio, sm, pio_encode_out(pio_y, 32)); // Set the state machine running (commented out, I'll start this in the C) // pio_sm_set_enabled(pio, sm, true); } %}