Finally a stable 640x480.

This commit is contained in:
giomba 2022-11-27 23:07:38 +01:00
parent 9fcb7b3e99
commit 4f26826d4b
2 changed files with 35 additions and 19 deletions

View File

@ -114,11 +114,26 @@ void setup_clocks(void)
static bool dma_ready = false;
static int dma_channel;
/**
* @brief Represents a program running on the SM of a PIO.
*
*/
typedef struct PIORun
{
PIO pio; //< executing PIO
uint offset; //< PIO memory offset for program
uint sm; //< executing SM
} PIORun;
PIORun *vga_pixel_ptr = NULL;
void new_frame_handler(void)
{
// restart DMA
if (dma_ready)
dma_channel_set_read_addr(dma_channel, &frames[0].data[0], true);
if (vga_pixel_ptr && dma_ready)
{
pio_sm_put_blocking(vga_pixel_ptr->pio, vga_pixel_ptr->sm, 0);
dma_channel_set_read_addr(dma_channel, &frames[0].data[4], true);
}
pio_interrupt_clear(pio0_hw, 1);
}
@ -134,6 +149,11 @@ void set_pixel(uint16_t x, uint16_t y)
frames[0].data[y * 80 + x / 8] |= (1 << x % 8);
}
void clear_pixel(uint16_t x, uint16_t y)
{
frames[0].data[y * 80 + x / 8] &= ~(1 << x % 8);
}
void draw_simple_line(uint16_t x, uint16_t y, uint16_t len, bool horizontal)
{
for (uint16_t i = 0; i < len; ++i)
@ -145,17 +165,6 @@ void draw_simple_line(uint16_t x, uint16_t y, uint16_t len, bool horizontal)
}
}
/**
* @brief Represents a program running on the SM of a PIO.
*
*/
typedef struct PIORun
{
PIO pio; //< executing PIO
uint offset; //< PIO memory offset for program
uint sm; //< executing SM
} PIORun;
int main()
{
setup_clocks();
@ -169,7 +178,9 @@ int main()
for (uint16_t x = 0; x < 639; ++x) // last pixel high -> bad
{
if ((x / 32) % 2 == 0)
set_pixel(x, 21);
set_pixel(x, 20);
if ((x / 32) % 2 == 1)
set_pixel(x, 23);
set_pixel(x, 239);
set_pixel(x, 479);
}
@ -177,7 +188,8 @@ int main()
for (uint16_t y = 21; y < 480; ++y)
{
set_pixel(0 + ((y - 20) / 10) * 4, y);
set_pixel(239, y);
set_pixel(0, y);
set_pixel(319, y);
set_pixel(638, y);
}
// try to find strangeness using stairs
@ -191,6 +203,8 @@ int main()
draw_simple_line(100, 104, 8, true);
draw_simple_line(100, 108, 8, true);
clear_pixel(639, 479);
// Running programs on PIO
PIORun vga_hsync, vga_vsync, vga_pixel;
vga_hsync.pio = vga_vsync.pio = vga_pixel.pio = pio0;
@ -227,6 +241,7 @@ int main()
printf("OK\n");
// VGA pixel program
vga_pixel_ptr = &vga_pixel;
printf("Starting VGA pixel machine... ");
if (!pio_can_add_program(vga_pixel.pio, &vga_free_run_program))
panic("cannot add program");
@ -249,8 +264,8 @@ int main()
irq_set_exclusive_handler(DMA_IRQ_0, dma_handler);
irq_set_enabled(DMA_IRQ_0, true);
dma_channel_configure(dma_channel, &dma_config, &pio0_hw->txf[2], &frames[0].data[0], 9600,
false);
dma_channel_configure(dma_channel, &dma_config, &pio0_hw->txf[2], &frames[0].data[0], 9600 - 1,
true);
dma_ready = true;
printf("OK\n");

View File

@ -52,11 +52,12 @@ vsync_pulse:
set pins, 0
jmp x-- vsync_pulse
irq set 1
mov x, osr
vsync_idle:
wait irq 0
set pins, 1
jmp x-- vsync_idle
irq set 1
.wrap