ups-esp32c3-rust/src/main.rs

68 lines
2.1 KiB
Rust

use esp_idf_sys as _;
use std::{thread, time::Duration};
mod beep;
mod blink;
mod dc_out_controller;
mod manager;
mod screen;
fn main() {
// Temporary. Will disappear once ESP-IDF 4.4 is released, but for now it is necessary to call this function once,
// or else some patches to the runtime implemented by esp-idf-sys might not link properly.
esp_idf_sys::link_patches();
let peripherals = esp_idf_hal::peripherals::Peripherals::take().unwrap();
let gpio5 = peripherals.pins.gpio5;
let gpio6 = peripherals.pins.gpio6;
let ledc_timer0 = peripherals.ledc.timer0;
let ledc_channel0 = peripherals.ledc.channel0;
let dc_out_ctl_pin = peripherals.pins.gpio3;
let i2c0 = peripherals.i2c0;
let gpio9 = peripherals.pins.gpio9;
let gpio10 = peripherals.pins.gpio10;
let adc1 = peripherals.adc1;
let adapter_pin = peripherals.pins.gpio1;
let battery_pin = peripherals.pins.gpio2;
println!("Starting screen");
let display = screen::Screen::new(i2c0, gpio9, gpio10).expect("Failed to create screen");
thread::spawn(move || {
let mut blink =
blink::Blink::new(gpio5.into_output().expect("Failed to set GPIO5 as output"));
blink.play();
});
thread::spawn(move || {
thread::sleep(Duration::from_millis(5000));
});
thread::spawn(move || {
let mut beep = beep::Beep::new(
gpio6.into_output().expect("Failed to set GPIO6 as output"),
ledc_timer0,
ledc_channel0,
)
.expect("Failed to create beep");
beep.play();
});
let mut dc_out_ctl = dc_out_controller::DcOutController::new(
dc_out_ctl_pin
.into_output()
.expect("Failed to set GPIO3 as output"),
);
let mut manager = manager::Manager::new(
dc_out_ctl,
display,
adc1,
adapter_pin.into_analog_atten_11db().expect("Failed to set GPIO1 as analog input"),
battery_pin.into_analog_atten_11db().expect("Failed to set GPIO2 as analog input"),
).expect("Failed to create manager");
loop {
manager.handling_once().expect("Failed to handle once");
}
}