Skip to content

Instantly share code, notes, and snippets.

@knight-ryu12
Created September 14, 2021 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knight-ryu12/4ee7ed2559846a5b89f0d69cf610c722 to your computer and use it in GitHub Desktop.
Save knight-ryu12/4ee7ed2559846a5b89f0d69cf610c722 to your computer and use it in GitHub Desktop.
; this program is basically parallel 8bit IO.
.program ym2413_io
.side_set 1
.wrap_target
out pins, 8 side 0 ; output 8 bit into GPIO n ~ n+7
nop side 1
.wrap
% c-sdk {
void ym2413_io_program_init(PIO pio, uint sm, uint offset,float clk_div,uint pinbase, uint wr_pin) {
pio_gpio_init(pio, wr_pin);
for(int i=pinbase; i<pinbase+8; i++)
pio_gpio_init(pio, i);
pio_sm_set_consecutive_pindirs(pio, sm, pinbase, 8, true);
pio_sm_set_consecutive_pindirs(pio, sm, wr_pin, 1, true);
pio_sm_config c = ym2413_io_program_get_default_config(offset);
sm_config_set_sideset_pins(&c, wr_pin);
sm_config_set_out_pins(&c, pinbase, 8);
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX);
sm_config_set_clkdiv(&c, clk_div);
sm_config_set_out_shift(&c, false, true, 8);
pio_sm_init(pio, sm, offset, &c);
pio_sm_set_enabled(pio, sm, true);
}
static inline void ym2413_io_put(PIO pio, uint sm, uint8_t x) {
while (pio_sm_is_tx_fifo_full(pio, sm));
*(volatile uint8_t*)&pio->txf[sm] = x;
}
static inline void st7789_lcd_wait_idle(PIO pio, uint sm) {
uint32_t sm_stall_mask = 1u << (sm + PIO_FDEBUG_TXSTALL_LSB);
pio->fdebug = sm_stall_mask;
while (!(pio->fdebug & sm_stall_mask));
}
%}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment