diff --git a/CMakeLists.txt b/CMakeLists.txt index f22f1bb..842a853 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,12 +10,6 @@ set(CMAKE_CXX_STANDARD 17) # Initialize SDK pico_sdk_init() -# include(example_auto_set_url.cmake) -# Add blink example -# add_subdirectory(blink) -# Add hello world example -# add_subdirectory(hello_world) - add_compile_options(-Wall -Wno-format # int != int32_t as far as the compiler is concerned because gcc has int32_t as long int -Wno-unused-function # we have some for the docs that aren't called @@ -41,6 +35,8 @@ pico_add_extra_outputs(ceda2vga) target_link_libraries(ceda2vga pico_stdlib hardware_pio + hardware_dma + hardware_irq ) # add url via pico_set_program_url diff --git a/src/main.c b/src/main.c index a17d0a2..d040039 100644 --- a/src/main.c +++ b/src/main.c @@ -8,6 +8,7 @@ */ #include "hardware/clocks.h" +#include "hardware/dma.h" #include "hardware/pio.h" #include "hardware/pll.h" #include "hardware/structs/pio.h" @@ -107,6 +108,15 @@ void setup_clocks(void) clock_configure(clk_peri, 0, CLOCKS_CLK_PERI_CTRL_AUXSRC_VALUE_CLK_SYS, 126 * MHZ, 126 * MHZ); } +static int dma_channel; + +void dma_handler() +{ + dma_hw->ints0 = 1 << dma_channel; + dma_channel_set_read_addr(dma_channel, &frames[0].data[5120], true); + // printf("."); +} + int main() { setup_clocks(); @@ -116,7 +126,7 @@ int main() // "draw" an horizontal dotted line (?) for (unsigned int c = 0; c < 5; c++) { - frames[0].data[80 * 64 + 30 + c] = 0x55; + frames[0].data[80 * 64 + 60 + c] = 0x55; } // PIO and state machines @@ -145,22 +155,30 @@ int main() // VGA pixel program uint offset0 = pio_add_program(pio, &vga_free_run_program); - uint sm0 = pio_claim_unused_sm(pio, false); + uint sm0 = pio_claim_unused_sm(pio, true); printf("Starting VGA pixel machine on %u...\n", sm0); vga_pixel_program_init(pio, sm0, offset0); pio_sm_put_blocking(pio, sm0, 640 - 1); + printf("Setting up DMA...\n"); + dma_channel = dma_claim_unused_channel(true); + dma_channel_config dma_config = dma_channel_get_default_config(dma_channel); + channel_config_set_transfer_data_size(&dma_config, DMA_SIZE_32); + channel_config_set_read_increment(&dma_config, true); + channel_config_set_write_increment(&dma_config, false); + channel_config_set_dreq(&dma_config, DREQ_PIO0_TX2); + + dma_channel_set_irq0_enabled(dma_channel, true); + + 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], 80, true); + + // dma_handler(); + printf("Start!\n"); - while (true) - { - for (size_t i = 0; i < sizeof(frames[0].data);) - { - // feed pixel machine - pio_sm_put_blocking(pio, sm0, frames[0].data[i++]); - // printf("%d.", i); - } - // sleep_ms(1000); - // printf("."); - } + for (;;) + ; }