generated from Weckyy702/pico-nix
Add hsync and vsync signals for 480x640 resolution
This commit is contained in:
29
src/main.cpp
29
src/main.cpp
@@ -1,25 +1,42 @@
|
|||||||
#include "hardware/gpio.h"
|
#include "hardware/gpio.h"
|
||||||
#include "pico/stdlib.h"
|
#include "pico/stdlib.h"
|
||||||
|
#include <pico/time.h>
|
||||||
|
|
||||||
|
#include <concepts>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <pico/time.h>
|
|
||||||
|
|
||||||
constexpr static uint start_pin = 2;
|
constexpr static uint start_pin = 2;
|
||||||
constexpr static uint pin_mask = (0xFFF) << start_pin;
|
constexpr static uint pin_mask = (0xFFF) << start_pin;
|
||||||
|
|
||||||
|
template <std::integral T> constexpr bool between(T x, T min, T max) {
|
||||||
|
return (x >= min) && (x < max);
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
stdio_init_all();
|
stdio_init_all();
|
||||||
|
|
||||||
for (uint offset{}; offset != 14; ++offset) {
|
for (uint offset{}; offset != 14; ++offset) {
|
||||||
auto const pin = start_pin + offset;
|
auto const pin = start_pin + offset;
|
||||||
|
std::printf("Initializing GPIO %d\n", pin);
|
||||||
gpio_init(pin);
|
gpio_init(pin);
|
||||||
gpio_set_dir(pin, GPIO_OUT);
|
gpio_set_dir(pin, GPIO_OUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint16_t pixel{};; ++pixel) {
|
for (uint32_t y{}; y != 525; ++y) {
|
||||||
auto const set_mask = (pixel & 0xFFF) << start_pin;
|
for (uint32_t x{}; x != 800; ++x) {
|
||||||
printf("Set mask=%03x", pixel);
|
const auto is_blanking = y >= 480 || x >= 640;
|
||||||
gpio_put_masked(pin_mask, set_mask);
|
const auto hsync = between(x, 656ul, 752ul);
|
||||||
sleep_ms(100);
|
const auto vsync = between(y, 490ul, 492ul);
|
||||||
|
|
||||||
|
auto const pixel = (0u << 8) | ((y & 0xF) << 4) | (x & 0xF);
|
||||||
|
auto const set_mask =
|
||||||
|
(((uint32_t)vsync << 13) | ((uint32_t)hsync << 12) | (pixel & 0xFFF))
|
||||||
|
<< start_pin;
|
||||||
|
|
||||||
|
std::printf("Set mask=%04X\n", set_mask >> start_pin);
|
||||||
|
gpio_put_masked(pin_mask, set_mask);
|
||||||
|
sleep_ms(10);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user