Skip to content

Commit

Permalink
SNS - Shared IO (#49)
Browse files Browse the repository at this point in the history
Co-authored-by: jpfbastos <jpfbastos05@gmail.com>
  • Loading branch information
davidbeechey and jpfbastos authored Nov 26, 2024
1 parent 1fbfb77 commit f72a841
Show file tree
Hide file tree
Showing 15 changed files with 114 additions and 96 deletions.
31 changes: 12 additions & 19 deletions Cargo.lock

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

25 changes: 7 additions & 18 deletions boards/stm32f767zi/Cargo.lock

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

2 changes: 1 addition & 1 deletion boards/stm32f767zi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"

[dependencies]
embassy-stm32 = { version = "0.1.0", features = ["defmt", "stm32f767zi", "memory-x", "unstable-pac", "time-driver-any", "exti"] , git = "https://github.com/embassy-rs/embassy", rev = "1c466b81e6af6b34b1f706318cc0870a459550b7"}
embassy-sync = { version = "0.6.0", features = ["defmt"], git = "https://github.com/embassy-rs/embassy"}
embassy-sync = { version = "0.6.0", features = ["defmt"], git = "https://github.com/embassy-rs/embassy", rev = "1c466b81e6af6b34b1f706318cc0870a459550b7"}
embassy-executor = { version = "0.6.0", features = ["task-arena-size-32768", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"], git = "https://github.com/embassy-rs/embassy", rev = "1c466b81e6af6b34b1f706318cc0870a459550b7"}
embassy-time = { version = "0.3.1", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"], git = "https://github.com/embassy-rs/embassy", rev = "1c466b81e6af6b34b1f706318cc0870a459550b7"}
embassy-net = { version = "0.4.0", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet"], git = "https://github.com/embassy-rs/embassy", rev = "1c466b81e6af6b34b1f706318cc0870a459550b7"}
Expand Down
4 changes: 3 additions & 1 deletion boards/stm32f767zi/src/io.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use core::cell::RefCell;
use embassy_stm32::adc::{Adc, AnyAdcChannel, Instance};
use embassy_stm32::gpio::Input;
use embassy_stm32::{i2c::I2c, mode::Blocking};
use embassy_sync::blocking_mutex::{raw::CriticalSectionRawMutex, Mutex};

use hyped_adc::HypedAdc;
use hyped_adc_derive::HypedAdc;
Expand All @@ -22,5 +24,5 @@ pub struct Stm32f767ziGpioInput {

#[derive(HypedI2c)]
pub struct Stm32f767ziI2c<'d> {
i2c: I2c<'d, Blocking>,
i2c: Mutex<CriticalSectionRawMutex, RefCell<I2c<'d, Blocking>>>,
}
10 changes: 9 additions & 1 deletion boards/stm32f767zi/src/tasks/temperature.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
use crate::io::Stm32f767ziI2c;
use core::cell::RefCell;
use defmt_rtt as _;
use embassy_stm32::i2c::I2c;
use embassy_stm32::time::Hertz;
use embassy_sync::blocking_mutex::Mutex;
use hyped_sensors::temperature::{Status, Temperature, TemperatureAddresses};

/// Test task that just reads the temperature from the sensor and prints it to the console
#[embassy_executor::task]
pub async fn read_temp() -> ! {
let p = embassy_stm32::init(Default::default());
let i2c = I2c::new_blocking(p.I2C1, p.PB8, p.PB9, Hertz(100_000), Default::default());
let i2c = Mutex::new(RefCell::new(I2c::new_blocking(
p.I2C1,
p.PB8,
p.PB9,
Hertz(100_000),
Default::default(),
)));
let mut hyped_i2c = Stm32f767ziI2c::new(i2c);

let mut temperature_sensor = Temperature::new(&mut hyped_i2c, TemperatureAddresses::Address3f)
Expand Down
25 changes: 7 additions & 18 deletions boards/stm32l476rg/Cargo.lock

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

2 changes: 1 addition & 1 deletion boards/stm32l476rg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"

[dependencies]
embassy-stm32 = { version = "0.1.0", features = ["defmt", "stm32l476rg", "memory-x", "unstable-pac", "time-driver-any", "exti"] , git = "https://github.com/embassy-rs/embassy", rev = "1c466b81e6af6b34b1f706318cc0870a459550b7"}
embassy-sync = { version = "0.6.0", features = ["defmt"], git = "https://github.com/embassy-rs/embassy"}
embassy-sync = { version = "0.6.0", features = ["defmt"], git = "https://github.com/embassy-rs/embassy", rev = "1c466b81e6af6b34b1f706318cc0870a459550b7"}
embassy-executor = { version = "0.6.0", features = ["task-arena-size-32768", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"], git = "https://github.com/embassy-rs/embassy", rev = "1c466b81e6af6b34b1f706318cc0870a459550b7"}
embassy-time = { version = "0.3.1", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"], git = "https://github.com/embassy-rs/embassy", rev = "1c466b81e6af6b34b1f706318cc0870a459550b7"}
embassy-net = { version = "0.4.0", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet"], git = "https://github.com/embassy-rs/embassy", rev = "1c466b81e6af6b34b1f706318cc0870a459550b7"}
Expand Down
5 changes: 4 additions & 1 deletion boards/stm32l476rg/src/io.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use core::cell::RefCell;

use embassy_stm32::adc::{Adc, AnyAdcChannel, Instance};
use embassy_stm32::gpio::Input;
use embassy_stm32::{i2c::I2c, mode::Blocking};
use embassy_sync::blocking_mutex::{raw::CriticalSectionRawMutex, Mutex};

use hyped_adc::HypedAdc;
use hyped_adc_derive::HypedAdc;
Expand All @@ -22,5 +25,5 @@ pub struct Stm32l476rgGpioInput {

#[derive(HypedI2c)]
pub struct Stm32l476rgI2c<'d> {
i2c: I2c<'d, Blocking>,
i2c: Mutex<CriticalSectionRawMutex, RefCell<I2c<'d, Blocking>>>,
}
10 changes: 9 additions & 1 deletion boards/stm32l476rg/src/tasks/temperature.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
use crate::io::Stm32l476rgI2c;
use core::cell::RefCell;
use defmt_rtt as _;
use embassy_stm32::i2c::I2c;
use embassy_stm32::time::Hertz;
use embassy_sync::blocking_mutex::Mutex;
use hyped_sensors::temperature::{Status, Temperature, TemperatureAddresses};

/// Test task that just reads the temperature from the sensor and prints it to the console
#[embassy_executor::task]
pub async fn read_temp() -> ! {
let p = embassy_stm32::init(Default::default());
let i2c = I2c::new_blocking(p.I2C1, p.PB8, p.PB9, Hertz(100_000), Default::default());
let i2c = Mutex::new(RefCell::new(I2c::new_blocking(
p.I2C1,
p.PB8,
p.PB9,
Hertz(100_000),
Default::default(),
)));
let mut hyped_i2c = Stm32l476rgI2c::new(i2c);

let mut temperature_sensor = Temperature::new(&mut hyped_i2c, TemperatureAddresses::Address3f)
Expand Down
3 changes: 2 additions & 1 deletion lib/io/hyped_i2c/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ version = "0.1.0"
edition = "2021"

[dependencies]
heapless = "0.8.0"
heapless = "0.8.0"
embassy-sync = { version = "0.6.0", features = ["defmt"], git = "https://github.com/embassy-rs/embassy", rev = "1c466b81e6af6b34b1f706318cc0870a459550b7"}
Loading

0 comments on commit f72a841

Please sign in to comment.