init commit
This commit is contained in:
17
.cargo/config.toml
Normal file
17
.cargo/config.toml
Normal file
@ -0,0 +1,17 @@
|
||||
[target.riscv32imc-unknown-none-elf]
|
||||
runner = "espflash flash --monitor --chip esp32c3 --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 = "riscv32imc-unknown-none-elf"
|
||||
|
||||
[unstable]
|
||||
build-std = ["alloc", "core"]
|
||||
22
.gitignore
vendored
Normal file
22
.gitignore
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
# 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
|
||||
|
||||
# RustRover
|
||||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
1
.~lock.data.csv#
Normal file
1
.~lock.data.csv#
Normal file
@ -0,0 +1 @@
|
||||
,albin,oct-artix,27.11.2025 07:26,file:///home/albin/.config/libreoffice/4;
|
||||
1591
Cargo.lock
generated
Normal file
1591
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
48
Cargo.toml
Normal file
48
Cargo.toml
Normal file
@ -0,0 +1,48 @@
|
||||
[package]
|
||||
edition = "2024"
|
||||
name = "co2-meter"
|
||||
rust-version = "1.88"
|
||||
version = "0.1.0"
|
||||
|
||||
[[bin]]
|
||||
name = "co2-meter"
|
||||
path = "./src/bin/main.rs"
|
||||
|
||||
[dependencies]
|
||||
esp-hal = { version = "1.0.0", features = ["defmt", "esp32c3", "unstable"] }
|
||||
|
||||
|
||||
defmt = "1.0.1"
|
||||
esp-bootloader-esp-idf = { version = "0.4.0", features = ["defmt", "esp32c3"] }
|
||||
|
||||
critical-section = "1.2.0"
|
||||
esp-alloc = { version = "0.9.0", features = ["defmt"] }
|
||||
esp-backtrace = { version = "0.18.1", features = [
|
||||
"defmt",
|
||||
"esp32c3",
|
||||
"panic-handler",
|
||||
] }
|
||||
esp-println = { version = "0.16.1", features = ["defmt-espflash", "esp32c3"] }
|
||||
aht20-driver = { version = "2.0", default-features = false }
|
||||
|
||||
ens160 = { version = "0.6", default-features = false}
|
||||
embedded-hal-bus = "0.3.0"
|
||||
mipidsi = "0.9.0"
|
||||
embedded-graphics = "0.8.1"
|
||||
lcd-async = "0.1.1"
|
||||
profont = "0.7.0"
|
||||
|
||||
|
||||
[profile.dev]
|
||||
# Rust debug is too slow.
|
||||
# For debug builds always builds with some optimization
|
||||
opt-level = "s"
|
||||
|
||||
[profile.release]
|
||||
codegen-units = 1 # LLVM can perform better optimizations using a single thread
|
||||
debug = 2
|
||||
debug-assertions = false
|
||||
incremental = false
|
||||
lto = 'fat'
|
||||
opt-level = 's'
|
||||
overflow-checks = false
|
||||
57
build.rs
Normal file
57
build.rs
Normal file
@ -0,0 +1,57 @@
|
||||
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() {
|
||||
"_defmt_timestamp" => {
|
||||
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!();
|
||||
}
|
||||
"esp_rtos_initialized" | "esp_rtos_yield_task" | "esp_rtos_task_create" => {
|
||||
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!();
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
// 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()
|
||||
);
|
||||
}
|
||||
4
rust-toolchain.toml
Normal file
4
rust-toolchain.toml
Normal file
@ -0,0 +1,4 @@
|
||||
[toolchain]
|
||||
channel = "stable"
|
||||
components = ["rust-src"]
|
||||
targets = ["riscv32imc-unknown-none-elf"]
|
||||
205
src/bin/main.rs
Normal file
205
src/bin/main.rs
Normal file
@ -0,0 +1,205 @@
|
||||
#![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."
|
||||
)]
|
||||
#![allow(unreachable_code)]
|
||||
|
||||
use defmt::info;
|
||||
use embedded_graphics::Drawable;
|
||||
use embedded_graphics::framebuffer::{Framebuffer, buffer_size};
|
||||
use embedded_graphics::image::{Image, ImageRaw};
|
||||
use embedded_graphics::pixelcolor::Rgb565;
|
||||
use embedded_graphics::pixelcolor::raw::{BigEndian, LittleEndian};
|
||||
use embedded_graphics::prelude::{Angle, DrawTarget, Point, Primitive, RgbColor, WebColors};
|
||||
use embedded_graphics::primitives::{
|
||||
Circle, PrimitiveStyle, PrimitiveStyleBuilder, Sector, StyledDrawable, Triangle,
|
||||
};
|
||||
use embedded_graphics::text::renderer::TextRenderer;
|
||||
use embedded_hal_bus::spi::ExclusiveDevice;
|
||||
use esp_hal::clock::CpuClock;
|
||||
use esp_hal::delay::Delay;
|
||||
use esp_hal::gpio::{Level, Output, OutputConfig};
|
||||
use esp_hal::main;
|
||||
use esp_hal::riscv::asm::delay;
|
||||
use esp_hal::rtc_cntl::Rtc;
|
||||
use esp_hal::time::{Duration, Instant, Rate};
|
||||
use esp_hal::timer::Timer;
|
||||
use esp_hal::timer::timg::TimerGroup;
|
||||
use mipidsi::interface::{Interface, SpiInterface};
|
||||
use mipidsi::models::ST7789;
|
||||
use {esp_backtrace as _, esp_println as _};
|
||||
|
||||
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!();
|
||||
|
||||
#[main]
|
||||
fn main() -> ! {
|
||||
// generator version: 1.0.1
|
||||
|
||||
esp_alloc::heap_allocator!(size: 32 * 1024);
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
let peripherals = esp_hal::init(config);
|
||||
let mut timer = Delay::new();
|
||||
|
||||
let spi = esp_hal::spi::master::Spi::new(
|
||||
peripherals.SPI2,
|
||||
esp_hal::spi::master::Config::default()
|
||||
.with_mode(esp_hal::spi::Mode::_0)
|
||||
.with_frequency(Rate::from_mhz(80)),
|
||||
)
|
||||
.unwrap()
|
||||
.with_sck(peripherals.GPIO4)
|
||||
.with_mosi(peripherals.GPIO6);
|
||||
|
||||
let mut cs_output = Output::new(peripherals.GPIO1, Level::High, OutputConfig::default());
|
||||
cs_output.set_high();
|
||||
let spi_device = ExclusiveDevice::new_no_delay(spi, cs_output).unwrap();
|
||||
let _ = Output::new(peripherals.GPIO0, Level::High, OutputConfig::default());
|
||||
|
||||
let mut buffer = [0_u8; 512];
|
||||
|
||||
// Define the display interface with no chip select
|
||||
let di = SpiInterface::new(
|
||||
spi_device,
|
||||
Output::new(peripherals.GPIO2, Level::Low, OutputConfig::default()),
|
||||
&mut buffer,
|
||||
);
|
||||
|
||||
let mut display = mipidsi::Builder::new(ST7789, di)
|
||||
.reset_pin(Output::new(
|
||||
peripherals.GPIO3,
|
||||
Level::Low,
|
||||
OutputConfig::default(),
|
||||
))
|
||||
.invert_colors(mipidsi::options::ColorInversion::Inverted)
|
||||
.init(&mut timer)
|
||||
.unwrap();
|
||||
|
||||
display
|
||||
.set_tearing_effect(mipidsi::options::TearingEffect::Vertical)
|
||||
.unwrap();
|
||||
|
||||
// Create styles used by the drawing operations.
|
||||
let sector_style = PrimitiveStyleBuilder::new()
|
||||
.stroke_color(Rgb565::BLACK)
|
||||
.stroke_width(2)
|
||||
.fill_color(Rgb565::YELLOW)
|
||||
.build();
|
||||
let eye_style = PrimitiveStyleBuilder::new()
|
||||
.stroke_color(Rgb565::BLACK)
|
||||
.stroke_width(1)
|
||||
.fill_color(Rgb565::BLACK)
|
||||
.build();
|
||||
|
||||
//let output_settings = ::new().scale(4).build();
|
||||
//let mut window = Window::new("Pacman", &output_settings);
|
||||
|
||||
// The current progress of the animation
|
||||
const STEPS: i32 = 10;
|
||||
let mut progress: i32 = 0;
|
||||
let delay = Delay::new();
|
||||
|
||||
loop {
|
||||
let mut fb = Framebuffer::<
|
||||
Rgb565,
|
||||
_,
|
||||
LittleEndian,
|
||||
320,
|
||||
240,
|
||||
{ buffer_size::<Rgb565>(320, 240) },
|
||||
>::new();
|
||||
fb.clear(Rgb565::WHITE).unwrap();
|
||||
|
||||
let p = (progress - STEPS).abs();
|
||||
|
||||
// Draw a Sector as the main Pacman feature.
|
||||
let _ = Sector::new(
|
||||
Point::new(2, 2),
|
||||
61,
|
||||
Angle::from_degrees((p * 30 / STEPS) as f32),
|
||||
Angle::from_degrees((360 - 2 * p * 30 / STEPS) as f32),
|
||||
)
|
||||
.draw_styled(§or_style, &mut fb);
|
||||
|
||||
// Draw a Circle as the eye.
|
||||
let _ = Circle::new(Point::new(36, 16), 5).draw_styled(&eye_style, &mut fb);
|
||||
|
||||
delay.delay_millis(50);
|
||||
|
||||
progress = (progress + 1) % (2 * STEPS + 1);
|
||||
|
||||
let img_raw = ImageRaw::<Rgb565, LittleEndian>::new(fb.data(), 320);
|
||||
let image = Image::new(&img_raw, Point::zero());
|
||||
image.draw(&mut display).unwrap();
|
||||
}
|
||||
|
||||
// display
|
||||
// .set_pixels(0, 0, 50, 50, core::iter::repeat(Rgb565::BLUE))
|
||||
// .unwrap();
|
||||
// //display.set_pixel(10, 10, Rgb565::WHITE).unwrap();
|
||||
|
||||
// let i2c = I2c::new(peripherals.I2C0, Config::default())
|
||||
// .unwrap()
|
||||
// .with_sda(peripherals.GPIO8)
|
||||
// .with_scl(peripherals.GPIO9);
|
||||
//
|
||||
// esp_alloc::heap_allocator!(#[esp_hal::ram(reclaimed)] size: 66320);
|
||||
//
|
||||
// let rc = RefCell::new(i2c);
|
||||
//
|
||||
// let mut device = Ens160::new(embedded_hal_bus::i2c::RefCellDevice::new(&rc), 0x53);
|
||||
// timer.delay_millis(500);
|
||||
// device.reset().unwrap();
|
||||
// info!("Reset device");
|
||||
// timer.delay_millis(500);
|
||||
// device.operational().unwrap();
|
||||
// info!("Device operational");
|
||||
//
|
||||
// // Configure the AHT20 temperature and humidity sensor.
|
||||
// let mut aht20_uninit = aht20_driver::AHT20::new(
|
||||
// embedded_hal_bus::i2c::RefCellDevice::new(&rc),
|
||||
// aht20_driver::SENSOR_ADDRESS,
|
||||
// );
|
||||
// let mut aht20 = aht20_uninit.init(&mut timer).unwrap();
|
||||
//
|
||||
// // Take the temperature and humidity measurement.
|
||||
//
|
||||
// loop {
|
||||
// //timer.delay_millis(5000);
|
||||
// if let Ok(status) = device.status() {
|
||||
// if status.data_is_ready() {
|
||||
// let aht20_measurement = aht20.measure(&mut timer).unwrap();
|
||||
// //println!("temperature (aht20): {}C", aht20_measurement.temperature);
|
||||
// //println!("humidity (aht20): {}%", aht20_measurement.humidity);
|
||||
//
|
||||
// let tvoc = device.tvoc().unwrap();
|
||||
// let eco2 = device.eco2().unwrap();
|
||||
// //info!("eco2: {}, tvoc: {}", *eco2, tvoc);
|
||||
// print!(
|
||||
// "{}, {}, {}, {}\n",
|
||||
// *eco2, tvoc, aht20_measurement.temperature, aht20_measurement.humidity
|
||||
// );
|
||||
// // from eCO2
|
||||
// // directly
|
||||
// //let air_quality_index = device.air_quality_index().unwrap();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
loop {
|
||||
info!("Hello world!");
|
||||
let delay_start = Instant::now();
|
||||
while delay_start.elapsed() < Duration::from_millis(500) {}
|
||||
}
|
||||
|
||||
// for inspiration have a look at the examples at https://github.com/esp-rs/esp-hal/tree/esp-hal-v1.0.0/examples/src/bin
|
||||
}
|
||||
|
||||
fn draw_interface<T: DrawTarget>(target: &mut T) {}
|
||||
1
src/lib.rs
Normal file
1
src/lib.rs
Normal file
@ -0,0 +1 @@
|
||||
#![no_std]
|
||||
Reference in New Issue
Block a user