96 lines
2.0 KiB
C
96 lines
2.0 KiB
C
/**
|
|
* @file main.c
|
|
* @author giomba@glgprograms.it
|
|
* @brief
|
|
*
|
|
* @copyright Copyright Retrofficina GLG Programs (c) 2022
|
|
*
|
|
*/
|
|
|
|
#include "hardware/clocks.h"
|
|
#include "hardware/pio.h"
|
|
#include "hardware/pll.h"
|
|
#include "hardware/structs/pio.h"
|
|
#include "pico/stdlib.h"
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "vga.pio.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#define FRAMES 2
|
|
|
|
#define HPIXEL 640
|
|
#define VPIXEL 480
|
|
#define BPP 1
|
|
|
|
typedef struct Frame
|
|
{
|
|
uint8_t data[HPIXEL * VPIXEL * BPP / 8];
|
|
} Frame;
|
|
|
|
static Frame frames[FRAMES] = {0};
|
|
|
|
static void vga_program_init(PIO pio, uint sm, uint offset)
|
|
{
|
|
// magic definition of the called function?
|
|
pio_sm_config c = vga_free_run_program_get_default_config(offset);
|
|
sm_config_set_out_pins(&c, 22, 1);
|
|
|
|
pio_gpio_init(pio, 22);
|
|
pio_sm_set_consecutive_pindirs(pio, sm, 22, 1, true);
|
|
|
|
pio_sm_init(pio, sm, offset, &c);
|
|
|
|
pio_sm_set_clkdiv_int_frac(pio, sm, 1, 0);
|
|
|
|
pio->sm->shiftctrl = (1 << PIO_SM0_SHIFTCTRL_FJOIN_TX_LSB) |
|
|
(1 << PIO_SM0_SHIFTCTRL_OUT_SHIFTDIR_LSB) |
|
|
(1 << PIO_SM0_SHIFTCTRL_OUT_SHIFTDIR_LSB) |
|
|
(1 << PIO_SM0_SHIFTCTRL_AUTOPULL_LSB);
|
|
|
|
pio_sm_set_enabled(pio, sm, true);
|
|
}
|
|
|
|
int main()
|
|
{
|
|
// main clock = VCO / divider1 / divider2 = 126MHz
|
|
pll_init(pll_sys, 1, 1500 * MHZ, 6, 2);
|
|
|
|
stdio_init_all();
|
|
|
|
#if 0
|
|
const uint LED_PIN = PICO_DEFAULT_LED_PIN;
|
|
gpio_init(LED_PIN);
|
|
gpio_set_dir(LED_PIN, GPIO_OUT);
|
|
#endif
|
|
|
|
// "draw" an horizontal dotted line (?)
|
|
for (unsigned int c = 0; c < 20; c += 3)
|
|
{
|
|
frames[0].data[80 * 64 + 20 + c] = 0x55;
|
|
}
|
|
for (unsigned int c = 0; c < 20; c += 3)
|
|
{
|
|
frames[0].data[80 * 128 + 20 + c] = 0x99;
|
|
}
|
|
|
|
PIO pio = pio0;
|
|
uint offset = pio_add_program(pio, &vga_free_run_program);
|
|
uint sm = pio_claim_unused_sm(pio, true);
|
|
vga_program_init(pio, sm, offset);
|
|
|
|
printf("Welcome.\n");
|
|
|
|
while (true)
|
|
{
|
|
for (size_t i = 0; i < sizeof(frames[0].data); ++i)
|
|
{
|
|
pio_sm_put_blocking(pio, sm, frames[0].data[i]);
|
|
}
|
|
printf(".");
|
|
sleep_ms(1000);
|
|
}
|
|
}
|