Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade: Depend on esp-idf-svc #14

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
5 changes: 3 additions & 2 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ build-std = ["std", "panic_abort"]

[env]
CARGO_WORKSPACE_DIR = { value = "", relative = true }
LIBCLANG_PATH = "/home/mdesilva/.espressif/tools/xtensa-esp32-elf-clang/esp-15.0.0-20221014-x86_64-unknown-linux-gnu/esp-clang/lib"
# LIBCLANG_PATH = "/home/mdesilva/.espressif/tools/xtensa-esp32-elf-clang/esp-15.0.0-20221014-x86_64-unknown-linux-gnu/esp-clang/lib"
LIBCLANG_PATH = "/home/mdesilva/.espup/esp-clang"
# Uncomment this to build against ESP-IDF master (currently unreleased ESP IDF 5.1)
#ESP_IDF_VERSION = "master"
# Don't forget to uncomment also the `rustflags` parameter in your "target" section above

# Uncomment this to build against ESP-IDF 5.0
# Don't forget to uncomment also the `rustflags` parameter in your "target" section above
ESP_IDF_VERSION = "release/v5.0"
ESP_IDF_VERSION = "v5.1.1"

# Comment out this when using the PlatformIO build, i.e. `cargo build --features pio` (it only supports `v4.3.2`)
# ESP_IDF_VERSION = "release/v4.4"
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ members = [
# exclude = []

[patch.crates-io]
embedded-hal = { git = "https://github.com/rust-embedded/embedded-hal" }
crossbeam-utils = { git = "https://github.com/crossbeam-rs/crossbeam" }
# embedded-hal = { git = "https://github.com/rust-embedded/embedded-hal" }
# embedded-svc = { git = "https://github.com/esp-rs/embedded-svc" }
# esp-idf-hal = { git = "https://github.com/esp-rs/esp-idf-hal" }
# esp-idf-svc = { git = "https://github.com/esp-rs/esp-idf-svc" }
# edge-frame = { git = "https://github.com/ivmarkov/edge-frame" }
embedded-io = { git = "https://github.com/ivmarkov/embedded-io" }
shared-bus = { git = "https://github.com/taks/shared-bus", branch = "embedded-hal-1.0.0-alpha.9" }
# shared-bus = { git = "https://github.com/taks/shared-bus" }

#socket2 = { git = "https://github.com/esp-rs-compat/socket2" }
#polling = { git = "https://github.com/esp-rs-compat/polling" }
Expand Down
53 changes: 28 additions & 25 deletions rued-esp32/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
[package]
name = "rued-esp32"
version = "4.0.0"
version = "5.0.0"
authors = ["Michael de Silva <michael@mwdesilva.com>"]
edition = "2021"
resolver = "2"
license = "MIT OR Apache-2.0"
readme = "README.md"
rust-version = "1.75"

[features]
pio = ["esp-idf-sys/pio"]
default = ["edge-executor", "system", "experimental"] # Note that edge-executor requires alloc
default = ["system", "experimental"]
# system = ["display-i2c"]
system = ["display-spi", "nvs", "external-rtc", "board"]
system = ["display-spi", "nvs", "external-rtc", "board1"]

external-rtc = []
nvs = []
Expand All @@ -19,7 +21,8 @@ display-binary-color = []
display-spi = ["profont", "ili9342"]
ili9342 = ["profont", "mipidsi"]

board = ["micromod-data-logging-carrier"]
board1 = ["micromod-data-logging-carrier"]
board2 = ["micromod-qwiic-carrier-single", "micromod-main-board-single", "pwm"]
micromod-qwiic-carrier-single = []
micromod-main-board-single = []
micromod-data-logging-carrier = []
Expand All @@ -28,30 +31,28 @@ experimental = ["esp-idf-svc/experimental", "embedded-svc/experimental"]

[dependencies]
anyhow = "1"
heapless = { version = "0.7" }
enumset = "1"
log = { version = "0.4", features = [
"max_level_debug",
"release_max_level_debug",
] }
futures = {version = "0.3", features = ["async-await"] }
serde = { version = "1", default-features = false }
postcard = "0.7"
serde = { version = "1", default-features = false, features = ["derive"] }
postcard = { git = "https://github.com/jamesmunns/postcard" }
heapless = { version = "0.7", features = ["serde"] }
critical-section = "1.1"
embedded-hal = { git = "https://github.com/rust-embedded/embedded-hal" }
embedded-hal-0-2 = { package = "embedded-hal", version = "0.2.7", features = ["unproven"] }
embedded-svc = { version = "0.24.0", features = ["nightly", "experimental"] }
esp-idf-sys = { version = "0.32.1", features = ["binstart"] }
esp-idf-svc = { version = "0.45.0", features = ["nightly", "experimental", "embassy-time-isr-queue"] }
# esp-idf-svc = { path = "/home/mdesilva/esp/esp-idf-svc_fork", features = ["nightly", "experimental", "embassy-time-isr-queue"] }
esp-idf-hal = { version = "0.40.1", features = ["edge-executor", "embassy-sync", "critical-section"] }
embedded-hal = { version = "^1.0" }
embedded-hal-async = "^1.0"
embedded-hal-0-2 = { package = "embedded-hal", version = "0.2", features = ["unproven"] }
embedded-svc = { version = "0.27.1", features = ["nightly"] }
esp-idf-svc = { version = "0.48.1", features = ["nightly", "critical-section", "embassy-time-driver", "wake-from-isr"] }
embassy-futures = { version = "0.1" }
embassy-sync = { version = "0.1", features = ["std"] }
embassy-time = { version = "0.1" }
static_cell = { version = "1" }
edge-frame = { version = "0.5", default-features = false, features = ["dto"], git = "https://github.com/ivmarkov/edge-frame" }
edge-executor = { version = "0.3", optional = true }
channel-bridge = { version = "0.2", git = "https://github.com/ivmarkov/channel-bridge", default-features = false, features = ["notification", "nightly", "embedded-svc"] }
embassy-sync = { version = "^0.5", features = ["std"] }
# embassy-time = { version = "0.1.0" }
static_cell = { version = "2" }
edge-frame = { version = "0.7", default-features = false, features = ["dto"] }
edge-executor = { version = "^0.4" }
channel-bridge = { version = "0.8", default-features = false, features = ["embedded-svc"] }
http = "0.2"

# time = { version = "0.3.17", features = ["macros"] }
Expand All @@ -63,16 +64,18 @@ gfx-xtra = "0.1"
serde_json = "1.0.87"
cstr_core = "0.2.6"
uncased = { version = "0.9.7" }
shared-bus = { version = "0.2", features = ["std"] }
rv8803-rs = { git = "https://github.com/bsodmike/rv8803-rs" }
rv8803 = { path = "../../rv8803" }

# monkey patched to remove atomic-polyfill in favour of portable-atomic
embedded-sdmmc = { git = "https://github.com/rust-embedded-community/embedded-sdmmc-rs", branch = "develop" }
shared-bus = { git = "https://github.com/bsodmike/shared-bus", branch = "upgrade_to_portable_atomic", features = ["std"] }

# optional dependencies
profont = { version = "0.5", optional = true }
ssd1306 = { version = "0.7", optional = true }
ssd1351 = { version = "0.4", optional = true }
mipidsi = { git = "https://github.com/almindor/mipidsi", optional = true }
mipidsi = { version = "0.5", default-features = false, optional = true }

[build-dependencies]
embuild = { version = "0.30.4", features = ["elf"] }
embuild = { version = "0.31", features = ["espidf", "elf"] }
anyhow = "1"
6 changes: 3 additions & 3 deletions rued-esp32/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Necessary because of this issue: https://github.com/rust-lang/cargo/issues/9641
fn main() -> anyhow::Result<()> {
embuild::build::CfgArgs::output_propagated("ESP_IDF")?;
embuild::build::LinkArgs::output_propagated("ESP_IDF")
embuild::espidf::sysenv::output();

Ok(())
}
24 changes: 13 additions & 11 deletions rued-esp32/src/core/internal/battery.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
use core::fmt::Debug;

use embassy_time::{Duration, Timer};

use embedded_hal_0_2::adc;
use embedded_hal_0_2::digital::v2::InputPin;
use embedded_hal::digital::InputPin;

use super::state::State;

pub use super::dto::battery::*;

pub trait Adc {
type Error: Debug;

async fn read(&mut self) -> Result<u16, Self::Error>;
}

pub static STATE: State<BatteryState> = State::new(
"BATTERY",
BatteryState::new(),
Expand All @@ -19,20 +26,15 @@ pub static STATE: State<BatteryState> = State::new(
],
);

pub async fn process<ADC, BP>(
mut one_shot: impl adc::OneShot<ADC, u16, BP>,
mut battery_pin: BP,
power_pin: impl InputPin,
) where
BP: adc::Channel<ADC>,
{
pub async fn process(mut battery_adc: impl Adc, power_pin: impl InputPin) {
const ROUND_UP: u16 = 50; // TODO: Make it smaller once ADC is connected

loop {
Timer::after(Duration::from_secs(2)).await;

let voltage = one_shot
.read(&mut battery_pin)
let voltage = battery_adc
.read()
.await
.ok()
.map(|voltage| voltage / ROUND_UP * ROUND_UP);

Expand Down
Loading