Skip to content

Commit

Permalink
Merge pull request #32 from pmnxis/dev/i32_embassy#2033_del_i2c_polli…
Browse files Browse the repository at this point in the history
…ng_set_timeout

Tyding for embassy#2033
  • Loading branch information
pmnxis committed Oct 17, 2023
2 parents 00479a0 + 8b95682 commit b6b5e3e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 37 deletions.
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ hw_0v4 = ["eeprom"]
hw_mini_0v4 = ["eeprom"]

[dependencies]
embassy-sync = { version = "0.3.0", git = "https://github.com/embassy-rs/embassy.git", rev = "c0a6c78a146a6e0ec57a03e64ff83a3fa87b4bdd", features = ["defmt"] }
embassy-executor = { version = "0.3.0", git = "https://github.com/embassy-rs/embassy.git", rev = "c0a6c78a146a6e0ec57a03e64ff83a3fa87b4bdd", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
embassy-futures = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy.git", rev = "c0a6c78a146a6e0ec57a03e64ff83a3fa87b4bdd", features = ["defmt"] }
embassy-time = { version = "0.1.2", git = "https://github.com/embassy-rs/embassy.git", rev = "c0a6c78a146a6e0ec57a03e64ff83a3fa87b4bdd", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
embassy-stm32 = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy.git", rev = "c0a6c78a146a6e0ec57a03e64ff83a3fa87b4bdd", features = ["nightly", "defmt", "time-driver-any", "stm32g030c8", "memory-x", "unstable-pac", "exti", "unstable-traits"] } # "unstable-traits" for use InputPin trait for gpio
embassy-embedded-hal = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy.git", rev = "c0a6c78a146a6e0ec57a03e64ff83a3fa87b4bdd", features = ["nightly"] }
embassy-sync = { version = "0.3.0", git = "https://github.com/embassy-rs/embassy.git", rev = "d94b9fe6fb6adee82c1427e72450f77a0d0973c3", features = ["defmt"] }
embassy-executor = { version = "0.3.0", git = "https://github.com/embassy-rs/embassy.git", rev = "d94b9fe6fb6adee82c1427e72450f77a0d0973c3", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
embassy-futures = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy.git", rev = "d94b9fe6fb6adee82c1427e72450f77a0d0973c3", features = ["defmt"] }
embassy-time = { version = "0.1.3", git = "https://github.com/embassy-rs/embassy.git", rev = "d94b9fe6fb6adee82c1427e72450f77a0d0973c3", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
embassy-stm32 = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy.git", rev = "d94b9fe6fb6adee82c1427e72450f77a0d0973c3", features = ["nightly", "defmt", "time-driver-any", "stm32g030c8", "memory-x", "unstable-pac", "exti", "unstable-traits"] } # "unstable-traits" for use InputPin trait for gpio
embassy-embedded-hal = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy.git", rev = "d94b9fe6fb6adee82c1427e72450f77a0d0973c3", features = ["nightly"] }
defmt = "0.3"
defmt-rtt = "0.4"

Expand Down
6 changes: 3 additions & 3 deletions src/boards/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ impl Hardware {
let mut ret = Stm32Config::default();
ret.rcc.mux = embassy_stm32::rcc::ClockSrc::PLL(embassy_stm32::rcc::PllConfig {
source: embassy_stm32::rcc::PllSrc::HSI16,
m: embassy_stm32::rcc::Pllm::Div1,
n: 8,
r: embassy_stm32::rcc::Pllr::Div2,
m: embassy_stm32::rcc::Pllm::DIV1,
n: embassy_stm32::rcc::Plln::MUL8,
r: embassy_stm32::rcc::Pllr::DIV2,
q: None,
p: None,
});
Expand Down
30 changes: 2 additions & 28 deletions src/components/eeprom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,26 +428,6 @@ const TOTAL_SLOT_NUM: usize = 96; // should be calculated in compile time
const TOTAL_SLOT_ARR_LEN: usize =
(TOTAL_SLOT_NUM + core::mem::size_of::<u8>() - 1) / (core::mem::size_of::<u8>() * 8);

static mut I2C_WAIT_UNTIL: Instant = Instant::from_ticks(0);

fn novella_i2c_polling_check_timeout() -> Result<(), embassy_stm32::i2c::Error> {
if Instant::now() < unsafe { I2C_WAIT_UNTIL } {
Ok(())
} else {
Err(embassy_stm32::i2c::Error::Timeout)
}
}

fn novella_i2c_polling_set_timeout(duration: Duration) {
unsafe {
I2C_WAIT_UNTIL = Instant::now() + duration;
}
}

fn novella_i2c_polling_set_default_timeout() {
novella_i2c_polling_set_timeout(WAIT_DURATION_PER_PAGE);
}

pub struct NovellaModuleControlBlock {
data: MemStorage,
controls: [NovellaSectionControlBlock; SECTION_NUM],
Expand Down Expand Up @@ -642,15 +622,13 @@ impl Novella {
let data_address_slice = (raw_addr as EepromAddress).to_be_bytes();
let i2c_address = ROM_7B_ADDRESS | ((raw_addr >> 8) as DevSelAddress & 0x7);

novella_i2c_polling_set_default_timeout(); // preinit for blocking_write_read_timeout

// blocking function can detect NACK, but async type does not
let result = bus
.blocking_write_read_timeout(
i2c_address,
&data_address_slice,
rx_buffer,
novella_i2c_polling_check_timeout,
WAIT_DURATION_PER_PAGE,
)
// .await
.map_err(|e| match e {
Expand Down Expand Up @@ -799,8 +777,6 @@ impl Novella {

self.clr_write_protect();

novella_i2c_polling_set_default_timeout();

let result = bus
.write(
i2c_address,
Expand Down Expand Up @@ -836,13 +812,11 @@ impl Novella {
// #[cfg(i2c_addr_bits_include_msb)]
let i2c_address = ROM_7B_ADDRESS | ((raw_addr >> 8) as DevSelAddress & 0x7);

novella_i2c_polling_set_default_timeout(); // preinit for blocking_write_read_timeout

bus.write_read_timeout(
i2c_address,
addr_buffer,
data_buffer,
novella_i2c_polling_check_timeout,
WAIT_DURATION_PER_PAGE,
)
.await
.map_err(|e| match e {
Expand Down

0 comments on commit b6b5e3e

Please sign in to comment.