/**
Project template for TV Pong - The final project of the Raspberry Pi Pico (RP2040) Deep Dive Course.
https://hackaday.io/project/180374-pi-pico-pal-tv-pong
Good luck!
*/
#include "sync.pio.h"
#include "data.pio.h"
#include "hardware/irq.h"
const uint8_t sync_pin = 2;
const uint8_t data_pin = 3;
#define LINES 305
#define BITS_PER_LINE 256
#define PIXEL_COUNT (LINES * BITS_PER_LINE)
uint8_t pixels[PIXEL_COUNT] = {0};
void data_handler() {
static size_t i = 0;
pio_sm_put(pio0, 1, ((uint32_t *)&pixels)[i]);
i += 4;
if (i == PIXEL_COUNT / 4) {
i = 0;
}
}
void setup() {
memset(pixels, 0x01, sizeof(pixels));
auto sync_offset = pio_add_program(pio0, &sync_program);
sync_program_init(pio0, 0, sync_offset, 1000000, sync_pin, 305);
auto data_offset = pio_add_program(pio0, &data_program);
data_program_init(pio0, 1, data_offset, 10000000, data_pin, 256);
irq_set_exclusive_handler(PIO0_IRQ_0, data_handler);
pio_set_irq0_source_enabled(pio0, pis_sm1_tx_fifo_not_full , true);
irq_set_enabled(PIO0_IRQ_0, true);
}
void loop() {
}