chore: initial commit

This commit is contained in:
2026-06-10 20:40:36 -05:00
commit 06d37ff5bd
14 changed files with 3045 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
[target.riscv32imac-unknown-none-elf]
runner = "espflash flash --monitor --chip esp32c6 --log-format defmt"
[env]
DEFMT_LOG = "info"
[build]
rustflags = [
# Required to obtain backtraces (e.g. when using the "esp-backtrace" crate.)
# NOTE: May negatively impact performance of produced code
"-C",
"force-frame-pointers",
]
target = "riscv32imac-unknown-none-elf"
[unstable]
build-std = ["alloc", "core"]
+1
View File
@@ -0,0 +1 @@
stack-size-threshold = 1024
+1
View File
@@ -0,0 +1 @@
use flake
+30
View File
@@ -0,0 +1,30 @@
name: "Flake.lock: update Nix dependencies for development environment only"
on:
workflow_dispatch: # allows manual triggering
schedule:
- cron: '00 00 02 1/2 *' # runs the first of day the month every 2 months at 7:00pm local time (midnight UTC)
jobs:
nix-flake-update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: "install nix"
uses: cachix/install-nix-action@v31
- name: "setup git user"
uses: fregante/setup-git-user@v2
- name: "update flake.lock"
run: |
nix flake update --commit-lock-file
- name: "check flake for errors"
run: |
nix flake check
- name: "push update"
run: |
git push
+23
View File
@@ -0,0 +1,23 @@
# Generated by nix
.direnv/
result
# Generated by Cargo
# will have compiled files and executables
debug/
target/
# Editor configuration
.vscode/
.zed/
.helix/
.nvim.lua
# These are backup files generated by rustfmt
**/*.rs.bk
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
# Ignore .DS_Store file in mac
**/.DS_Store
+8
View File
@@ -0,0 +1,8 @@
[global]
disable = [
# line length limits
"MD013",
]
[MD057]
absolute-links = "relative_to_roots"
Generated
+2272
View File
File diff suppressed because it is too large Load Diff
+64
View File
@@ -0,0 +1,64 @@
[package]
edition = "2024"
name = "cover-theif"
version = "0.1.0"
[[bin]]
name = "cover-theif"
path = "./src/bin/main.rs"
[dependencies]
esp-hal = { version = "~1.1.0", features = ["defmt", "esp32c6", "unstable"] }
esp-rtos = { version = "0.3.0", features = [
"defmt",
"embassy",
"esp-alloc",
"esp-radio",
"esp32c6",
] }
defmt = "1.1.0"
esp-bootloader-esp-idf = { version = "0.5.0", features = ["defmt", "esp32c6"] }
embassy-executor = { version = "0.10.0", features = ["defmt"] }
embassy-time = { version = "0.5.1", features = ["defmt"] }
esp-alloc = { version = "0.10.0", features = ["defmt"] }
esp-backtrace = { version = "0.19.0", features = [
"defmt",
"esp32c6",
"panic-handler",
] }
esp-println = { version = "0.17.0", features = ["defmt-espflash", "esp32c6"] }
critical-section = "1.2.0"
static_cell = "2.1.1"
embassy-net = { version = "0.9.0", features = [
"dhcpv4",
"medium-ethernet",
"tcp",
"dns",
] }
esp-radio = { version = "0.18.0", features = [
"defmt",
"esp-alloc",
"esp32c6",
"unstable",
"wifi",
] }
picoserve = { version = "0.18", features = ["defmt", "embassy", "json"] }
# For fine tuning these settings, please refer to https://doc.rust-lang.org/cargo/reference/profiles.html
[profile.dev]
# The default debug profile is too slow and too big for resource-constrained devices.
# Always build with some optimizations enabled.
opt-level = "s"
[profile.release]
codegen-units = 1 # LLVM can perform better optimizations using a single thread
debug = 2 # prefer slower builds but better debugging experience
lto = 'fat'
opt-level = 's'
+71
View File
@@ -0,0 +1,71 @@
fn main() {
linker_be_nice();
println!("cargo:rustc-link-arg=-Tdefmt.x");
// make sure linkall.x is the last linker script (otherwise might cause problems with flip-link)
println!("cargo:rustc-link-arg=-Tlinkall.x");
}
fn linker_be_nice() {
let args: Vec<String> = std::env::args().collect();
if args.len() > 1 {
let kind = &args[1];
let what = &args[2];
match kind.as_str() {
"undefined-symbol" => match what.as_str() {
what if what.starts_with("_defmt_") => {
eprintln!();
eprintln!(
"💡 `defmt` not found - make sure `defmt.x` is added as a linker script and you have included `use defmt_rtt as _;`"
);
eprintln!();
}
"_stack_start" => {
eprintln!();
eprintln!("💡 Is the linker script `linkall.x` missing?");
eprintln!();
}
what if what.starts_with("esp_rtos_") => {
eprintln!();
eprintln!(
"💡 `esp-radio` has no scheduler enabled. Make sure you have initialized `esp-rtos` or provided an external scheduler."
);
eprintln!();
}
"embedded_test_linker_file_not_added_to_rustflags" => {
eprintln!();
eprintln!(
"💡 `embedded-test` not found - make sure `embedded-test.x` is added as a linker script for tests"
);
eprintln!();
}
"free"
| "malloc"
| "calloc"
| "get_free_internal_heap_size"
| "malloc_internal"
| "realloc_internal"
| "calloc_internal"
| "free_internal" => {
eprintln!();
eprintln!(
"💡 Did you forget the `esp-alloc` dependency or didn't enable the `compat` feature on it?"
);
eprintln!();
}
_ => (),
},
// we don't have anything helpful for "missing-lib" yet
_ => {
std::process::exit(1);
}
}
std::process::exit(0);
}
println!(
"cargo:rustc-link-arg=--error-handling-script={}",
std::env::current_exe().unwrap().display()
);
}
Generated
+353
View File
@@ -0,0 +1,353 @@
{
"nodes": {
"cadquery": {
"inputs": {
"cadquery-freecad-import-plugin-src": "cadquery-freecad-import-plugin-src",
"cadquery-src": "cadquery-src",
"cq-cli-src": "cq-cli-src",
"cq-editor-src": "cq-editor-src",
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs_2",
"ocp-src": "ocp-src",
"ocp-stubs-src": "ocp-stubs-src",
"pybind11-stubgen-src": "pybind11-stubgen-src",
"pywrap-src": "pywrap-src"
},
"locked": {
"lastModified": 1765891741,
"narHash": "sha256-71CHh2FMmmBlduyAw8LD+PLjLlm+k5wtBatF8F7aJpQ=",
"owner": "vinszent",
"repo": "cq-flake",
"rev": "6212f4f8155d03bb7ddd811d766fbcd23a8b338b",
"type": "github"
},
"original": {
"owner": "vinszent",
"repo": "cq-flake",
"type": "github"
}
},
"cadquery-freecad-import-plugin-src": {
"flake": false,
"locked": {
"lastModified": 1734615666,
"narHash": "sha256-/puHlsdDqdVbVdxOkkwMEW/S//BztFA8fNkTp9PbSYY=",
"owner": "jmwright",
"repo": "cadquery-freecad-import-plugin",
"rev": "a0f72aedafc80e40b486d991f8659ed4ce5eb147",
"type": "github"
},
"original": {
"owner": "jmwright",
"repo": "cadquery-freecad-import-plugin",
"type": "github"
}
},
"cadquery-src": {
"flake": false,
"locked": {
"lastModified": 1741533881,
"narHash": "sha256-LNzo356Chh52Soi91i/z5fD9mDlh3P0saUieS5f399g=",
"owner": "CadQuery",
"repo": "cadquery",
"rev": "471ab6fcc79b6ce64b857d33d06202c030cf5459",
"type": "github"
},
"original": {
"owner": "CadQuery",
"repo": "cadquery",
"rev": "471ab6fcc79b6ce64b857d33d06202c030cf5459",
"type": "github"
}
},
"cq-cli-src": {
"flake": false,
"locked": {
"lastModified": 1742395288,
"narHash": "sha256-aiLjhyQLeXy4kDW9C8n5XL2BqKGixufTgVKOPWiTZ9c=",
"owner": "CadQuery",
"repo": "cq-cli",
"rev": "6a6076a1659fe3cfd706cb353725e5cf3f4b4715",
"type": "github"
},
"original": {
"owner": "CadQuery",
"repo": "cq-cli",
"type": "github"
}
},
"cq-editor-src": {
"flake": false,
"locked": {
"lastModified": 1739812831,
"narHash": "sha256-6cFVT+HIRoht1XPY+mvk9iTQ50Q8kqx9XxgNsRMFQ9c=",
"owner": "CadQuery",
"repo": "CQ-editor",
"rev": "7c92ec9d967f0f1e295a0f2dcf779ea871338e08",
"type": "github"
},
"original": {
"owner": "CadQuery",
"ref": "0.4.0",
"repo": "CQ-editor",
"type": "github"
}
},
"crane": {
"locked": {
"lastModified": 1777335812,
"narHash": "sha256-bEg5xoAxAwsyfnGhkEX7RJViTIBIYPd8ISg4O1c0HFc=",
"owner": "ipetkov",
"repo": "crane",
"rev": "5e0fb2f64edff2822249f21293b8304dedaaf676",
"type": "github"
},
"original": {
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1778716662,
"narHash": "sha256-m1Yf0wZ8j1OHjTc2UwHwyQRSnNeSgLJOd7q5Y45hzi4=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "f7c1a2d347e4c52d5fb8d10cb4d94b5884e546fb",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"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": 1780749050,
"narHash": "sha256-3av0pIjlOWQ6rDbNOmpUSvbNnJkGORQKKjb4LtCZsIY=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "a799d3e3886da994fa307f817a6bc705ae538eeb",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-lib": {
"locked": {
"lastModified": 1777168982,
"narHash": "sha256-GOkGPcboWE9BmGCRMLX3worL4EMnsnG8MyKmXNeYuhQ=",
"owner": "nix-community",
"repo": "nixpkgs.lib",
"rev": "f5901329dade4a6ea039af1433fb087bd9c1fe14",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixpkgs.lib",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1742889210,
"narHash": "sha256-hw63HnwnqU3ZQfsMclLhMvOezpM7RSB0dMAtD5/sOiw=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "698214a32beb4f4c8e3942372c694f40848b360d",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"ocp-src": {
"flake": false,
"locked": {
"lastModified": 1739132137,
"narHash": "sha256-vWAqCGgs7YnwHRhPAXkBQqCs+Y3zk4BMu1boZo3PLGA=",
"owner": "cadquery",
"repo": "ocp",
"rev": "01055e099a3b1a34da38bb1f5457f06a2d4c7a18",
"type": "github"
},
"original": {
"owner": "cadquery",
"ref": "7.8.1.2",
"repo": "ocp",
"type": "github"
}
},
"ocp-stubs-src": {
"flake": false,
"locked": {
"lastModified": 1672527176,
"narHash": "sha256-m9Rg36GYlYfwEfF0PQJWEXf8TyM5HmjeuhJCODiurvY=",
"owner": "cadquery",
"repo": "ocp-stubs",
"rev": "e838ff400d5ee2f4a0579d2a713b19311855288f",
"type": "github"
},
"original": {
"owner": "cadquery",
"repo": "ocp-stubs",
"type": "github"
}
},
"project-templates": {
"inputs": {
"cadquery": "cadquery",
"crane": "crane",
"flake-parts": [
"flake-parts"
],
"nixpkgs": [
"nixpkgs"
],
"rust-overlay": "rust-overlay",
"treefmt-nix": "treefmt-nix"
},
"locked": {
"lastModified": 1780887496,
"narHash": "sha256-4mDOPU6Ey3SMsUsUeeNLkXC9uSdn0vpyzJIumw01HV8=",
"ref": "refs/heads/master",
"rev": "0d1a37eef3e3954cc698b577edbc37eaa736b859",
"revCount": 45,
"type": "git",
"url": "https://git.krantz.one/reed/project-templates"
},
"original": {
"type": "git",
"url": "https://git.krantz.one/reed/project-templates"
}
},
"pybind11-stubgen-src": {
"flake": false,
"locked": {
"lastModified": 1700678104,
"narHash": "sha256-76u1GcHPPh8oYQeQZDJ4K/so0U7F6rznZ1xa6syqI9s=",
"owner": "CadQuery",
"repo": "pybind11-stubgen",
"rev": "6dc681d838d3ec9a8a9aa4260c8392d3fb700ff0",
"type": "github"
},
"original": {
"owner": "CadQuery",
"repo": "pybind11-stubgen",
"type": "github"
}
},
"pywrap-src": {
"flake": false,
"locked": {
"lastModified": 1736233855,
"narHash": "sha256-u+P/SUGpYhzA1oVbEv26DF8PBEpsotEk4iXIXZhgzHc=",
"owner": "CadQuery",
"repo": "pywrap",
"rev": "9c9ca5b8aa0d9a6687394897815a682b8c319fb0",
"type": "github"
},
"original": {
"owner": "CadQuery",
"repo": "pywrap",
"type": "github"
}
},
"root": {
"inputs": {
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs",
"project-templates": "project-templates"
}
},
"rust-overlay": {
"inputs": {
"nixpkgs": [
"project-templates",
"nixpkgs"
]
},
"locked": {
"lastModified": 1780197589,
"narHash": "sha256-FVCr2Ij/jKf59a4LW481eeOF6rJRreOBrVgW/aUBTrw=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "21632e942d89bf1cce4e5a63d7e58a215a0cbfcc",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"type": "github"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": [
"project-templates",
"nixpkgs"
]
},
"locked": {
"lastModified": 1775636079,
"narHash": "sha256-pc20NRoMdiar8oPQceQT47UUZMBTiMdUuWrYu2obUP0=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "790751ff7fd3801feeaf96d7dc416a8d581265ba",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
}
},
"root": "root",
"version": 7
}
+42
View File
@@ -0,0 +1,42 @@
{
description = "esp32 cover theif";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
project-templates = {
url = "git+https://git.krantz.one/reed/project-templates";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-parts.follows = "flake-parts";
};
};
outputs = {
flake-parts,
project-templates,
...
} @ inputs:
flake-parts.lib.mkFlake {inherit inputs;} {
imports = [
project-templates.flakeModules.rust-esp32-c6
];
systems = ["aarch64-linux" "x86_64-linux" "aarch64-darwin"];
perSystem = {pkgs, ...}: {
krantz.rust = {
esp32-c6 = {
enable = true;
};
enable = true;
src = ./.;
# runtimeDeps = with pkgs; [];
# buildDeps = with pkgs; [];
};
};
};
}
+4
View File
@@ -0,0 +1,4 @@
[toolchain]
channel = "nightly"
components = ["rust-src"]
targets = ["riscv32imac-unknown-none-elf"]
+157
View File
@@ -0,0 +1,157 @@
#![no_std]
#![no_main]
#![deny(
clippy::mem_forget,
reason = "mem::forget is generally not safe to do with esp_hal types, especially those \
holding buffers for the duration of a data transfer."
)]
#![deny(clippy::large_stack_frames)]
#![feature(impl_trait_in_assoc_type)]
use defmt::{error, info};
use embassy_executor::Spawner;
use embassy_net::Runner;
use embassy_time::{Duration, Timer};
use esp_backtrace as _;
use esp_hal::clock::CpuClock;
use esp_hal::timer::timg::TimerGroup;
use esp_println as _;
use esp_radio::wifi::sta::StationConfig;
use esp_radio::wifi::{ControllerConfig, Interface, WifiController};
use picoserve::routing::get;
use picoserve::{AppBuilder, AppRouter};
extern crate alloc;
// This creates a default app-descriptor required by the esp-idf bootloader.
// For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description>
esp_bootloader_esp_idf::esp_app_desc!();
// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html
macro_rules! mk_static {
($t:ty,$val:expr) => {{
static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new();
#[deny(unused_attributes)]
let x = STATIC_CELL.uninit().write($val);
x
}};
}
const SSID: &str = env!("SSID");
const PASSWORD: &str = env!("PASSWORD");
struct AppProps;
impl AppBuilder for AppProps {
type PathRouter = impl picoserve::routing::PathRouter;
fn build_app(self) -> picoserve::Router<Self::PathRouter> {
picoserve::Router::new().route("/", get(|| async move { "Hello World" }))
}
}
#[allow(
clippy::large_stack_frames,
reason = "it's not unusual to allocate larger buffers etc. in main"
)]
#[esp_rtos::main]
async fn main(spawner: Spawner) -> ! {
// generator version: 1.3.0
// generator parameters: --chip esp32c6 -o alloc -o unstable-hal -o esp-backtrace -o embassy -o defmt
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
let peripherals = esp_hal::init(config);
esp_alloc::heap_allocator!(#[esp_hal::ram(reclaimed)] size: 65536);
let timg0 = TimerGroup::new(peripherals.TIMG0);
let sw_interrupt =
esp_hal::interrupt::software::SoftwareInterruptControl::new(peripherals.SW_INTERRUPT);
esp_rtos::start(timg0.timer0, sw_interrupt.software_interrupt0);
info!("Embassy initialized!");
let wifi_config = esp_radio::wifi::Config::Station(
StationConfig::default()
.with_ssid(SSID)
.with_password(PASSWORD.into()),
);
let (wifi_controller, wifi_interfaces) = esp_radio::wifi::new(
peripherals.WIFI,
ControllerConfig::default().with_initial_config(wifi_config),
)
.expect("Failed to initialize Wi-Fi controller");
let net_config = embassy_net::Config::dhcpv4(Default::default());
let rng = esp_hal::rng::Rng::new();
let seed = (rng.random() as u64) << 32 | rng.random() as u64;
let (net_stack, net_runner) = embassy_net::new(
wifi_interfaces.station,
net_config,
mk_static!(
embassy_net::StackResources<3>,
embassy_net::StackResources::<3>::new()
),
seed,
);
spawner.spawn(connection(wifi_controller).unwrap());
spawner.spawn(net_task(net_runner).unwrap());
net_stack.wait_config_up().await;
if let Some(config) = net_stack.config_v4() {
info!("Got IP: {}", config.address);
}
let app = mk_static!(AppRouter<AppProps>, AppProps.build_app());
let port = 80;
let mut tcp_rx_buffer = [0; 1024];
let mut tcp_tx_buffer = [0; 1024];
let mut http_buffer = [0; 2048];
let web_serve_config = picoserve::Config::const_default().keep_connection_alive();
picoserve::Server::new(app, &web_serve_config, &mut http_buffer)
.listen_and_serve(0, net_stack, port, &mut tcp_rx_buffer, &mut tcp_tx_buffer)
.await;
loop {
info!("Hello world");
Timer::after(Duration::from_secs(1)).await;
}
// for inspiration have a look at the examples at https://github.com/esp-rs/esp-hal/tree/esp-hal-v1.1.0/examples
}
#[embassy_executor::task]
async fn connection(mut controller: WifiController<'static>) {
info!("start connection task");
loop {
info!("About to connect...");
match controller.connect_async().await {
Ok(info) => {
info!("Wifi connected to {:?}", info);
// wait until we're no longer connected
let info = controller.wait_for_disconnect_async().await.ok();
info!("Disconnected: {:?}", info);
}
Err(e) => {
error!("Failed to connect to wifi: {:?}", e);
}
}
Timer::after(Duration::from_millis(5000)).await
}
}
#[embassy_executor::task]
async fn net_task(mut runner: Runner<'static, Interface<'static>>) {
runner.run().await
}
+1
View File
@@ -0,0 +1 @@
#![no_std]