Skip to content

Commit

Permalink
better shared i2c, use official esp32 v0.18 update
Browse files Browse the repository at this point in the history
  • Loading branch information
Sycrosity committed Jan 25, 2024
1 parent d86f5f6 commit ffb397a
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 71 deletions.
74 changes: 39 additions & 35 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 19 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
license = "MIT OR Apache-2.0"

[dependencies]
esp32-hal = { version = "0.17.0", features = ["embassy", "embassy-executor-thread", "async", "embassy-time-timg0", "embassy-time", "log", "bluetooth"] }
esp32-hal = { version = "0.18.0", features = ["embassy", "embassy-executor-thread", "async", "embassy-time-timg0", "log", "bluetooth", "embedded-io"] }
esp-backtrace = { version = "0.10.0", features = ["esp32", "panic-handler", "exception-handler", "print-uart"] }
esp-println = { version = "0.8.0", features = ["esp32", "log", "uart"] }

Expand All @@ -15,21 +15,29 @@ esp-alloc = { version = "0.3.0", optional = true }
# esp-wifi = { version = "0.2.0", features = ["esp32", "wifi", "embassy-net", "wifi-logs"], optional = true }
# smoltcp = { version = "0.11.0", default-features = false, features = ["proto-igmp", "proto-ipv4", "socket-tcp", "socket-icmp", "socket-udp", "medium-ethernet", "proto-dhcpv4", "socket-raw", "socket-dhcpv4"] }

#the gold standard for logging in rust
log = "0.4.20"
embedded-error-chain = "1.0.0"
#implimentation of the c "libm" maths library
libm = "0.2.8"

shared-bus = { version = "0.4.0", features = ["xtensa"] }
#traits and functions for working with embedded graphics in rust
embedded-graphics = { version = "0.8.1", features = ["nalgebra_support"] }
#a general purpose linear algebra library
nalgebra = { version = "0.32.3", default-features = false }

embedded-svc = { version = "0.26.4", default-features = false, features = ["log"] }

embedded-svc = { version = "0.26.4", default-features = false, features = ["log"], optional = true }
embedded-io = "0.6.1"
embedded-hal = "^1.0"
# embedded-hal-async = { version = "1.0.0" }
embedded-io-async = "0.6.1"

heapless = { version = "0.8.0", default-features = false }
embedded-hal = "^1.0"
embedded-hal-async = "^1.0"

embedded-hal-bus = { version = "0.1.0", features = ["async"] }
critical-section = "1.1.2"

# heapless = { version = "0.8.0", default-features = false }

embassy-executor = { version = "0.5.0", features = ["nightly", "log"] }
embassy-time = { version = "0.3.0", features = ["log"] }
Expand All @@ -38,17 +46,17 @@ embassy-net = { version = "0.4.0", features = ["log", "proto-ipv4", "dns", "tcp"

mpu6050 = { version = "0.1.6", git = "https://github.com/Sycrosity/mpu6050" }
ssd1306 = { version = "0.8.4", git = "https://github.com/Sycrosity/ssd1306" }
#for the bmp280 senosr
bme280 = { version = "0.4.4", features = [], git = "https://github.com/Sycrosity/bme280-rs" }
bme280 = { version = "0.4.4" }

[features]
alloc = ["dep:esp-alloc"]
net = [
# "dep:esp-wifi",
"dep:embassy-net"
"dep:embassy-net",
"dep:embedded-svc"
]
# log = ["dep:log",""]
defmt = []

[patch.crates-io]
esp32-hal = { git = "https://github.com/Sycrosity/esp-hal" }
shared-bus = { version = "0.4.0", git = "https://github.com/Sycrosity/shared-bus" }
bme280 = { version = "0.4.4", git = "https://github.com/VersBinarii/bme280-rs" }
15 changes: 15 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use std::{env, error::Error, path::PathBuf};

fn main() -> Result<(), Box<dyn Error>> {
// Put the linker script somewhere the linker can find it
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
println!("cargo:rustc-link-search={}", out.display());

// Only re-run the build script when build.rs is changed - aka never
println!("cargo:rerun-if-changed=build.rs");

#[cfg(feature = "defmt")]
println!("cargo:rustc-link-arg=-Tdefmt.x");

Ok(())
}
24 changes: 9 additions & 15 deletions src/bme280.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,7 @@ impl From<bme280::Error<hal::i2c::Error>> for BMEError {
fn from(value: bme280::Error<hal::i2c::Error>) -> Self {
match value {
bme280::Error::CompensationFailed => Self::DataErr,
bme280::Error::Bus(e) => match e {
hal::i2c::Error::ExceedingFifo => todo!(),
hal::i2c::Error::AckCheckFailed => Self::Ack,
hal::i2c::Error::TimeOut => Self::TimeoutError,
hal::i2c::Error::ArbitrationLost => todo!(),
hal::i2c::Error::ExecIncomplete => todo!(),
hal::i2c::Error::CommandNrExceeded => todo!(),
},
bme280::Error::Bus(_) => Self::InterfaceError,
// Self::InterfaceError,
bme280::Error::InvalidData => Self::DataErr,
bme280::Error::NoCalibrationData => Self::InitialisationError,
Expand All @@ -48,18 +41,12 @@ pub struct BME280 {

impl BME280 {
pub fn new(i2c: SharedI2C) -> Result<Self> {
println!("a");

let mut bme280 = Self {
bme: bme280::i2c::BME280::new_primary(i2c),
};

info!("g");

bme280.init()?;

info!("e");

// bme280.try_init().await?;

Ok(bme280)
Expand Down Expand Up @@ -112,7 +99,7 @@ pub async fn bme280_stream(
) {
let mut delay: Delay = Delay;

bme.init().unwrap();
bme.init().print_warn();

loop {
let bme_data: BmeData = bme
Expand All @@ -122,6 +109,13 @@ pub async fn bme280_stream(
.map_err(|e| error!("{e:?}"))
.unwrap_or_default();

// let mpu_data = MpuData {
// roll_pitch: mpu.get_acc_angles().unwrap(),
// temp: mpu.get_temp().unwrap(),
// gyro: mpu.get_gyro().unwrap(),
// acc: mpu.get_acc().unwrap(),
// };

info!("{bme_data:?}");

BME_SIGNAL.signal(bme_data);
Expand Down
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ pub mod alloc {

pub mod prelude {

pub type SharedI2C = shared_bus::I2cProxy<
pub type SharedI2C = embedded_hal_bus::i2c::CriticalSectionDevice<
'static,
shared_bus::XtensaMutex<hal::i2c::I2C<'static, hal::peripherals::I2C0>>,
hal::i2c::I2C<'static, hal::peripherals::I2C0>,
>;

pub const DEFAULT_INTERVAL: Duration = Duration::from_millis(500);
Expand All @@ -44,6 +44,8 @@ pub mod prelude {

pub use crate::{errors::*, utils::*};

pub use critical_section::Mutex;

pub use esp32_hal as hal;
#[allow(unused)]
pub use esp_backtrace as _;
Expand Down
Loading

0 comments on commit ffb397a

Please sign in to comment.