generated from Weckyy702/pico-nix
Compare commits
4 Commits
ceb9d9fc17
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a5f4a1e3a8 | ||
|
|
74b74dcb6e | ||
|
|
7cdfb565f3 | ||
|
|
41bf80157b |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@ build/
|
||||
.cache
|
||||
.direnv
|
||||
pico_sdk_import.cmake
|
||||
compile_commands.json
|
||||
|
||||
27
flake.lock
generated
27
flake.lock
generated
@@ -1,5 +1,23 @@
|
||||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1731533236,
|
||||
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1771369470,
|
||||
@@ -18,8 +36,8 @@
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs",
|
||||
"systems": "systems"
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
@@ -32,8 +50,9 @@
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"id": "systems",
|
||||
"type": "indirect"
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
68
flake.nix
68
flake.nix
@@ -1,51 +1,41 @@
|
||||
{
|
||||
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
};
|
||||
|
||||
outputs =
|
||||
inputs @ { nixpkgs
|
||||
, systems
|
||||
{ nixpkgs
|
||||
, flake-utils
|
||||
, ...
|
||||
}:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
inherit (nixpkgs) lib;
|
||||
eachSystem = lib.genAttrs (import systems);
|
||||
pkgsFor = eachSystem (system:
|
||||
import nixpkgs {
|
||||
localSystem = system;
|
||||
});
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
pico-sdk = pkgs.pico-sdk.override {
|
||||
withSubmodules = true;
|
||||
};
|
||||
PICO_SDK_PATH = "${pico-sdk}/lib/pico-sdk";
|
||||
in
|
||||
{
|
||||
devShells =
|
||||
eachSystem
|
||||
(system: {
|
||||
default =
|
||||
let
|
||||
pkgs = pkgsFor.${system};
|
||||
pico-sdk = pkgs.pico-sdk.override {
|
||||
withSubmodules = true;
|
||||
};
|
||||
PICO_SDK_PATH = "${pico-sdk}/lib/pico-sdk";
|
||||
in
|
||||
pkgs.mkShell {
|
||||
name = "PicoVGA dev shell";
|
||||
inputsFrom = [ pico-sdk ];
|
||||
packages = with pkgs;
|
||||
[
|
||||
gcc-arm-embedded
|
||||
python3
|
||||
devShell = pkgs.mkShell {
|
||||
name = "PicoVGA dev shell";
|
||||
inputsFrom = [ pico-sdk ];
|
||||
packages = with pkgs; [
|
||||
gcc-arm-embedded
|
||||
python3
|
||||
pico-sdk
|
||||
|
||||
usbutils
|
||||
picotool
|
||||
picocom
|
||||
]
|
||||
++ [ pico-sdk ];
|
||||
picocom
|
||||
|
||||
shellHook = ''
|
||||
ln -sf ${PICO_SDK_PATH}/external/pico_sdk_import.cmake pico_sdk_import.cmake
|
||||
'';
|
||||
usbutils
|
||||
picotool
|
||||
];
|
||||
shellHook = ''
|
||||
ln -sf ${PICO_SDK_PATH}/external/pico_sdk_import.cmake pico_sdk_import.cmake
|
||||
'';
|
||||
|
||||
inherit PICO_SDK_PATH;
|
||||
};
|
||||
});
|
||||
};
|
||||
inherit PICO_SDK_PATH;
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
29
src/main.cpp
29
src/main.cpp
@@ -1,25 +1,42 @@
|
||||
#include "hardware/gpio.h"
|
||||
#include "pico/stdlib.h"
|
||||
#include <pico/time.h>
|
||||
|
||||
#include <concepts>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <pico/time.h>
|
||||
|
||||
constexpr static uint start_pin = 2;
|
||||
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() {
|
||||
stdio_init_all();
|
||||
|
||||
for (uint offset{}; offset != 14; ++offset) {
|
||||
auto const pin = start_pin + offset;
|
||||
std::printf("Initializing GPIO %d\n", pin);
|
||||
gpio_init(pin);
|
||||
gpio_set_dir(pin, GPIO_OUT);
|
||||
}
|
||||
|
||||
for (uint16_t pixel{};; ++pixel) {
|
||||
auto const set_mask = (pixel & 0xFFF) << start_pin;
|
||||
printf("Set mask=%03x", pixel);
|
||||
gpio_put_masked(pin_mask, set_mask);
|
||||
sleep_ms(100);
|
||||
for (uint32_t y{}; y != 525; ++y) {
|
||||
for (uint32_t x{}; x != 800; ++x) {
|
||||
const auto is_blanking = y >= 480 || x >= 640;
|
||||
const auto hsync = between(x, 656ul, 752ul);
|
||||
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