Add vertical sync to VGA (out of phase).

This commit is contained in:
giomba 2022-10-12 20:44:26 +02:00
parent ed29e27f80
commit a5339f6fcf
2 changed files with 48 additions and 3 deletions

View File

@ -57,9 +57,26 @@ static void vga_hsync_program_init(PIO pio, uint sm, uint offset)
{ {
pio_sm_config config = vga_hsync_program_get_default_config(offset); pio_sm_config config = vga_hsync_program_get_default_config(offset);
// destination pins for SET instructions // destination pins for SET instructions
sm_config_set_set_pins(&config, 20, 2); sm_config_set_set_pins(&config, 20, 1);
pio_gpio_init(pio, 20); pio_gpio_init(pio, 20);
pio_sm_set_consecutive_pindirs(pio, sm, 20, 2, true); pio_sm_set_consecutive_pindirs(pio, sm, 20, 1, true);
pio_sm_init(pio, sm, offset, &config);
pio_sm_set_clkdiv_int_frac(pio, sm, 1, 0);
pio->sm->shiftctrl = (1 << PIO_SM0_SHIFTCTRL_FJOIN_TX_LSB);
pio_sm_set_enabled(pio, sm, true);
}
static void vga_vsync_program_init(PIO pio, uint sm, uint offset)
{
pio_sm_config config = vga_vsync_program_get_default_config(offset);
// destination pins for SET instructions
sm_config_set_set_pins(&config, 21, 1);
pio_gpio_init(pio, 21);
pio_sm_set_consecutive_pindirs(pio, sm, 21, 1, true);
pio_sm_init(pio, sm, offset, &config); pio_sm_init(pio, sm, offset, &config);
@ -98,7 +115,7 @@ int main()
printf("Starting VGA pixel machine on %u...\n", sm0); printf("Starting VGA pixel machine on %u...\n", sm0);
vga_pixel_program_init(pio, sm0, offset0); vga_pixel_program_init(pio, sm0, offset0);
// VGA sync program // VGA HSYNC program
uint offset1 = pio_add_program(pio, &vga_hsync_program); uint offset1 = pio_add_program(pio, &vga_hsync_program);
uint sm1 = pio_claim_unused_sm(pio, true); uint sm1 = pio_claim_unused_sm(pio, true);
printf("Starting VGA sync machine on %u...\n", sm1); printf("Starting VGA sync machine on %u...\n", sm1);
@ -108,6 +125,15 @@ int main()
pio_sm_put_blocking(pio, sm1, 63 * 4); pio_sm_put_blocking(pio, sm1, 63 * 4);
pio_sm_put_blocking(pio, sm1, 775 * 4); pio_sm_put_blocking(pio, sm1, 775 * 4);
// VGA VSYNC program
uint offset2 = pio_add_program(pio, &vga_vsync_program);
uint sm2 = pio_claim_unused_sm(pio, true);
printf("Starting VGA vsync machine on %u...\n", sm2);
vga_vsync_program_init(pio, sm2, offset2);
printf("Feeding vertical sync...\n");
pio_sm_put_blocking(pio, sm2, 2520 * 4);
pio_sm_put_blocking(pio, sm2, 420000 * 4);
printf("Start!\n"); printf("Start!\n");
while (true) while (true)

View File

@ -24,3 +24,22 @@ hsync_pulse:
hsync_idle: hsync_idle:
jmp x-- hsync_idle jmp x-- hsync_idle
jmp loop jmp loop
.program vga_vsync
entrypoint_vga_vsync:
pull
mov isr, osr
pull
loop:
mov x, isr
set pins, 0
vsync_pulse:
jmp x-- vsync_pulse
mov x, osr
set pins, 1
vsync_idle:
jmp x-- vsync_idle
jmp loop