From 9fcb7b3e996ea16e0eb3d43b4280a75aafa95e0d Mon Sep 17 00:00:00 2001 From: giomba Date: Sun, 27 Nov 2022 22:07:01 +0100 Subject: [PATCH] Adjustments for front porch calculation. --- src/main.c | 32 +++++++++++++++++++++++++++----- src/vga.pio | 7 +++---- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/main.c b/src/main.c index ef453fa..88080c5 100644 --- a/src/main.c +++ b/src/main.c @@ -134,6 +134,17 @@ void set_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) + { + if (horizontal) + set_pixel(x + i, y); + else + set_pixel(x, y + i); + } +} + /** * @brief Represents a program running on the SM of a PIO. * @@ -157,17 +168,28 @@ int main() // horizontal lines for (uint16_t x = 0; x < 639; ++x) // last pixel high -> bad { - set_pixel(x, 0); + if ((x / 32) % 2 == 0) + set_pixel(x, 21); set_pixel(x, 239); set_pixel(x, 479); } // vertical lines - for (uint16_t y = 0; y < 480; ++y) + for (uint16_t y = 21; y < 480; ++y) { - set_pixel(0, y); + set_pixel(0 + ((y - 20) / 10) * 4, y); set_pixel(239, y); set_pixel(638, y); } + // try to find strangeness using stairs + for (uint16_t x = 0; x < 639; ++x) + { + set_pixel(x, (x / 32) * 4 + 120); + } + // draw "E" - nice because it's not symmetrical along X + draw_simple_line(100, 100, 8, true); + draw_simple_line(100, 100, 8, false); + draw_simple_line(100, 104, 8, true); + draw_simple_line(100, 108, 8, true); // Running programs on PIO PIORun vga_hsync, vga_vsync, vga_pixel; @@ -188,8 +210,8 @@ int main() vga_hsync.sm = pio_claim_unused_sm(vga_hsync.pio, true); vga_hsync_program_init(vga_hsync.pio, vga_hsync.sm, vga_hsync.offset); // low pulse is X pixels long, and SM runs at 4x of pixel clock - pio_sm_put_blocking(vga_hsync.pio, vga_hsync.sm, (64 - 1)); - pio_sm_put_blocking(vga_hsync.pio, vga_hsync.sm, (640 - 1)); + pio_sm_put_blocking(vga_hsync.pio, vga_hsync.sm, (64 - 2)); + pio_sm_put_blocking(vga_hsync.pio, vga_hsync.sm, (640 + 16 - 1)); // 16 is front porch printf("OK\n"); // VGA VSYNC program diff --git a/src/vga.pio b/src/vga.pio index 1516745..3f41d26 100644 --- a/src/vga.pio +++ b/src/vga.pio @@ -8,7 +8,7 @@ entrypoint_vga_free_run: mov x, y wait irq 7 loop: - out pins, 1 [3] + out pins, 1 [2] jmp x-- loop .wrap @@ -27,10 +27,9 @@ hsync_pulse: jmp x-- hsync_pulse [3] set pins, 1 [1] - set y, 24 + set y, 27 hsync_back_porch: - jmp y-- hsync_back_porch [19] - + jmp y-- hsync_back_porch [16] irq set 7 mov x, osr [3]