Add two running state machines.

This commit is contained in:
giomba 2022-10-10 21:48:16 +02:00
parent 73195267cb
commit c17a9b1018
2 changed files with 44 additions and 14 deletions

View File

@ -32,12 +32,11 @@ typedef struct Frame
static Frame frames[FRAMES] = {0};
static void vga_program_init(PIO pio, uint sm, uint offset)
static void vga_pixel_program_init(PIO pio, uint sm, uint offset)
{
// magic definition of the called function?
pio_sm_config c = vga_free_run_program_get_default_config(offset);
sm_config_set_out_pins(&c, 22, 1);
pio_gpio_init(pio, 22);
pio_sm_set_consecutive_pindirs(pio, sm, 22, 1, true);
@ -53,6 +52,20 @@ static void vga_program_init(PIO pio, uint sm, uint offset)
pio_sm_set_enabled(pio, sm, true);
}
static void vga_sync_program_init(PIO pio, uint sm, uint offset)
{
pio_sm_config config = vga_sync_program_get_default_config(offset);
sm_config_set_out_pins(&config, 20, 2);
pio_gpio_init(pio, 20);
pio_sm_set_consecutive_pindirs(pio, sm, 20, 2, true);
pio_sm_init(pio, sm, offset, &config);
pio_sm_set_clkdiv_int_frac(pio, sm, 1, 0);
pio_sm_set_enabled(pio, sm, true);
}
int main()
{
// main clock = VCO / divider1 / divider2 = 126MHz
@ -60,12 +73,6 @@ int main()
stdio_init_all();
#if 0
const uint LED_PIN = PICO_DEFAULT_LED_PIN;
gpio_init(LED_PIN);
gpio_set_dir(LED_PIN, GPIO_OUT);
#endif
// "draw" an horizontal dotted line (?)
for (unsigned int c = 0; c < 20; c += 3)
{
@ -76,18 +83,31 @@ int main()
frames[0].data[80 * 128 + 20 + c] = 0x99;
}
// PIO and state machines
PIO pio = pio0;
uint offset = pio_add_program(pio, &vga_free_run_program);
uint sm = pio_claim_unused_sm(pio, true);
vga_program_init(pio, sm, offset);
sleep_ms(5000);
// VGA pixel program
uint offset0 = pio_add_program(pio, &vga_free_run_program);
uint sm0 = pio_claim_unused_sm(pio, true);
printf("Starting VGA pixel machine on %u...\n", sm0);
vga_pixel_program_init(pio, sm0, offset0);
// VGA sync program
uint offset1 = pio_add_program(pio, &vga_sync_program);
uint sm1 = pio_claim_unused_sm(pio, true);
printf("Starting VGA sync machine on %u...\n", sm1);
vga_sync_program_init(pio, sm1, offset1);
printf("Welcome.\n");
// feed pixel program
while (true)
{
for (size_t i = 0; i < sizeof(frames[0].data); ++i)
{
pio_sm_put_blocking(pio, sm, frames[0].data[i]);
pio_sm_put_blocking(pio, sm0, frames[0].data[i]);
}
printf(".");
sleep_ms(1000);

View File

@ -1,9 +1,19 @@
.program vga_free_run
entrypoint:
entrypoint_vga_free_run:
pull
loop:
out pins, 1 [2]
jmp loop
.program vga_sync
entrypoint_vga_sync:
loop:
set x, 31
mov osr, x
out pins, 1 [30]
set x, 0
mov osr, x
out pins, 1 [30]
jmp loop