A cross. Sort of. Also, remember that program is 32 words per PIO, not SM.

This commit is contained in:
giomba 2022-10-16 20:00:26 +02:00
parent d40f208ce0
commit 1d68748f50
2 changed files with 47 additions and 20 deletions

View File

@ -15,11 +15,11 @@
#include "pico/stdlib.h" #include "pico/stdlib.h"
#include <stdint.h> #include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "vga.pio.h" #include "vga.pio.h"
#include <stdio.h>
#define FRAMES 2 #define FRAMES 2
#define HPIXEL 640 #define HPIXEL 640
@ -108,34 +108,56 @@ void setup_clocks(void)
clock_configure(clk_peri, 0, CLOCKS_CLK_PERI_CTRL_AUXSRC_VALUE_CLK_SYS, 126 * MHZ, 126 * MHZ); clock_configure(clk_peri, 0, CLOCKS_CLK_PERI_CTRL_AUXSRC_VALUE_CLK_SYS, 126 * MHZ, 126 * MHZ);
} }
static bool dma_ready = false;
static int dma_channel; static int dma_channel;
void dma_handler() void new_frame_handler(void)
{ {
// restart DMA
if (dma_ready)
dma_channel_set_read_addr(dma_channel, &frames[0].data[0], true);
pio_interrupt_clear(pio0_hw, 1);
}
void dma_handler(void)
{
// acknoweledge DMA
dma_hw->ints0 = 1 << dma_channel; dma_hw->ints0 = 1 << dma_channel;
dma_channel_set_read_addr(dma_channel, &frames[0].data[5120], true); }
// printf(".");
void set_pixel(uint16_t x, uint16_t y)
{
frames[0].data[y * 80 + x / 8] |= (1 << x % 8);
} }
int main() int main()
{ {
setup_clocks(); setup_clocks();
stdio_init_all(); stdio_init_all();
sleep_ms(5000); sleep_ms(1000);
// "draw" an horizontal dotted line (?) // clear frame buffer
for (unsigned int c = 0; c < 5; c++) memset(&frames[0].data[0], 0, sizeof(frames[0].data));
{ // horizontal line
frames[0].data[80 * 64 + 60 + c] = 0x55; for (uint16_t x = 400; x < 620; ++x)
} set_pixel(x, 64);
// vertical line
for (uint16_t y = 20; y < 460; ++y)
set_pixel(400, y);
// PIO and state machines // PIO and state machines
PIO pio = pio0; PIO pio = pio0;
// Prepare frame interrupt
pio_set_irq1_source_enabled(pio, pis_interrupt1, true);
irq_set_exclusive_handler(PIO0_IRQ_1, new_frame_handler);
irq_set_enabled(PIO0_IRQ_1, true);
// VGA HSYNC 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 hsync machine on %u...\n", sm1);
vga_hsync_program_init(pio, sm1, offset1); vga_hsync_program_init(pio, sm1, offset1);
printf("Feeding horizontal sync...\n"); printf("Feeding horizontal sync...\n");
// low pulse is X pixels long, and SM runs at 4x of pixel clock // low pulse is X pixels long, and SM runs at 4x of pixel clock
@ -154,8 +176,12 @@ int main()
printf("OK\n"); printf("OK\n");
// VGA pixel program // VGA pixel program
printf("pio_add_program...\n");
uint offset0 = pio_add_program(pio, &vga_free_run_program); uint offset0 = pio_add_program(pio, &vga_free_run_program);
uint sm0 = pio_claim_unused_sm(pio, true); printf("pio_claim_unused_sm...\n");
uint sm0 = pio_claim_unused_sm(pio, false);
printf("sm0 = %u\n", sm0);
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);
pio_sm_put_blocking(pio, sm0, 640 - 1); pio_sm_put_blocking(pio, sm0, 640 - 1);
@ -173,12 +199,13 @@ int main()
irq_set_exclusive_handler(DMA_IRQ_0, dma_handler); irq_set_exclusive_handler(DMA_IRQ_0, dma_handler);
irq_set_enabled(DMA_IRQ_0, true); irq_set_enabled(DMA_IRQ_0, true);
dma_channel_configure(dma_channel, &dma_config, &pio0_hw->txf[2], &frames[0].data[0], 80, true); dma_channel_configure(dma_channel, &dma_config, &pio0_hw->txf[2], &frames[0].data[0], 38400,
false);
// dma_handler(); dma_ready = true;
printf("Start!\n"); printf("Start!\n");
for (;;) for (;;)
; tight_loop_contents();
} }

View File

@ -19,8 +19,7 @@ entrypoint_vga_hsync:
pull pull
loop: loop:
nop irq set 0 [1]
irq set 0
mov x, isr mov x, isr
set pins, 0 set pins, 0
@ -31,8 +30,7 @@ hsync_pulse:
set pins, 1 set pins, 1
hsync_idle: hsync_idle:
jmp x-- hsync_idle jmp x-- hsync_idle
nop jmp loop [1]
jmp loop
.program vga_vsync .program vga_vsync
@ -56,4 +54,6 @@ vsync_idle:
set pins, 1 set pins, 1
jmp x-- vsync_idle jmp x-- vsync_idle
irq set 1
jmp loop jmp loop