/** * @file main.c * @author giomba@glgprograms.it * @brief * * @copyright Copyright Retrofficina GLG Programs (c) 2022 * */ #include "hardware/clocks.h" #include "hardware/pll.h" #include "pico/stdlib.h" #include #include #include #include #include "draw_demo.h" #include "framebuffer.h" #include "vga.h" void setup_clocks(void) { // disable resuscitation clock clocks_hw->resus.ctrl = 0; // before changing PLL, switch sys and ref cleanly away from their aux sources hw_clear_bits(&clocks_hw->clk[clk_sys].ctrl, CLOCKS_CLK_SYS_CTRL_SRC_BITS); while (clocks_hw->clk[clk_sys].selected != 0x1) tight_loop_contents(); hw_clear_bits(&clocks_hw->clk[clk_ref].ctrl, CLOCKS_CLK_REF_CTRL_SRC_BITS); while (clocks_hw->clk[clk_ref].selected != 0x1) tight_loop_contents(); // set PLL at 126 MHz, and wait for it to stabilize pll_init(pll_sys, 1, 1512 * MHZ, 6, 2); // re-configure sys_clk to use PLL clock_configure(clk_sys, CLOCKS_CLK_SYS_CTRL_SRC_VALUE_CLKSRC_CLK_SYS_AUX, CLOCKS_CLK_SYS_CTRL_AUXSRC_VALUE_CLKSRC_PLL_SYS, 126 * MHZ, 126 * MHZ); // re-configure CLK PERI = clk_sys clock_configure(clk_peri, 0, CLOCKS_CLK_PERI_CTRL_AUXSRC_VALUE_CLK_SYS, 126 * MHZ, 126 * MHZ); } int main() { setup_clocks(); stdio_init_all(); draw_demo(); vga_machines_init(); for (;;) { // moving sine const uint16_t fc = frame_counter; const uint16_t x = fc % 640; const uint16_t y = 380 + 100 * (abs(320 - x) / 640.0) * sin((fc % 640) / 12.738); set_pixel(x, y); // 13 ms <=> 75 Hz // Actually, there is a point in going in sync with vertical refresh, // but let's just forget this for the demo. sleep_ms(13); clear_pixel(x, y); } }