Skip to content

Commit

Permalink
Merge pull request #55 from pmnxis/dev/tyde-embassy-rs-stable
Browse files Browse the repository at this point in the history
Tyde to stable embassy-rs stable
  • Loading branch information
pmnxis committed Apr 29, 2024
2 parents 71b07b5 + 5aa1ead commit 98edbc3
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 55 deletions.
18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[package]
name = "billmock-app-rs"
edition = "2021"
version = "0.3.1"
version = "0.3.2"
authors = ["Jinwoo Park <[email protected]>"]
license = "MIT OR Apache-2.0"
description = "application side of billmock hardware, powered by rust-embedded"
Expand All @@ -24,16 +24,16 @@ hw_mini_0v4 = ["eeprom"]
hw_mini_0v5 = ["eeprom", "svc_button"]

[dependencies]
embassy-sync = { version = "0.4.0", git = "https://github.com/embassy-rs/embassy.git", rev = "5bc75578260f4c644cc060e6458a05d7fc0ffb41", features = ["defmt"] }
embassy-executor = { version = "0.3.3", git = "https://github.com/embassy-rs/embassy.git", rev = "5bc75578260f4c644cc060e6458a05d7fc0ffb41", 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 = "5bc75578260f4c644cc060e6458a05d7fc0ffb41", features = ["defmt"] }
embassy-time = { version = "0.1.5", git = "https://github.com/embassy-rs/embassy.git", rev = "5bc75578260f4c644cc060e6458a05d7fc0ffb41", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
embassy-stm32 = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy.git", rev = "5bc75578260f4c644cc060e6458a05d7fc0ffb41", 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 = "5bc75578260f4c644cc060e6458a05d7fc0ffb41", features = ["nightly"] }
defmt = "0.3"
embassy-sync = { version = "0.5.0", features = ["defmt"] }
embassy-executor = { version = "0.5.0", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
embassy-futures = { version = "0.1.0", features = ["defmt"] }
embassy-time = { version = "0.3.0", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
embassy-stm32 = { version = "0.1.0", features = ["defmt", "time-driver-any", "stm32g030c8", "memory-x", "unstable-pac", "exti", "time"] } # "unstable-traits" for use InputPin trait for gpio
embassy-embedded-hal = { version = "^0.1.0" }
defmt = "0.3.6"
defmt-rtt = "0.4"

cortex-m = { version = "0.7.7", features = ["inline-asm", "critical-section-single-core"] } # 0.7.6
cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } # 0.7.6
cortex-m-rt = "0.7.3" # 0.7.0
panic-probe = { version = "0.3", features = ["print-defmt"] }
futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
Expand Down
3 changes: 2 additions & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
# Before upgrading check that everything is available on all tier1 targets here:
# https://rust-lang.github.io/rustup-components-history
[toolchain]
channel = "nightly-2023-11-01"
# channel = "nightly-2023-11-01"
channel = "nightly-2024-04-14"
components = [ "rust-src", "rustfmt", "llvm-tools", "rust-analyzer" ]
targets = [
"thumbv6m-none-eabi",
Expand Down
15 changes: 12 additions & 3 deletions src/boards/billmock_mini_0v5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use embassy_stm32::i2c::I2c;
use embassy_stm32::time::Hertz;
use embassy_stm32::usart::{Config as UsartConfig, Uart};
use embassy_stm32::{bind_interrupts, peripherals};
use embassy_time::Duration;
use {defmt_rtt as _, panic_probe as _};

use super::{Hardware, SharedResource};
Expand All @@ -33,18 +34,20 @@ use crate::types::player::Player;

bind_interrupts!(struct Irqs {
USART2 => embassy_stm32::usart::InterruptHandler<peripherals::USART2>;
I2C1 => embassy_stm32::i2c::InterruptHandler<peripherals::I2C1>;
I2C1 => embassy_stm32::i2c::EventInterruptHandler<peripherals::I2C1>, embassy_stm32::i2c::ErrorInterruptHandler<peripherals::I2C1>;
});

static mut USART2_RX_BUF: [u8; components::serial_device::CARD_READER_RX_BUFFER_SIZE] =
[0u8; components::serial_device::CARD_READER_RX_BUFFER_SIZE];

const WAIT_DURATION_PER_PAGE: Duration = Duration::from_millis(20); // heuristic value

pub fn hardware_init_mini_0v5(
p: embassy_stm32::Peripherals,
shared_resource: &'static SharedResource,
) -> Hardware {
// USART2 initialization for CardReaderDevice
let usart2_rx_buf = unsafe { &mut USART2_RX_BUF };
let usart2_rx_buf = unsafe { &mut *core::ptr::addr_of_mut!(USART2_RX_BUF) };

let usart2_config = {
let mut ret: UsartConfig = UsartConfig::default();
Expand All @@ -69,6 +72,12 @@ pub fn hardware_init_mini_0v5(
(tx, rx.into_ring_buffered(usart2_rx_buf))
};

let i2c_config = {
let mut ret: embassy_stm32::i2c::Config = embassy_stm32::i2c::Config::default();
ret.timeout = WAIT_DURATION_PER_PAGE;
ret
};

let i2c = I2c::new(
p.I2C1,
p.PB8,
Expand All @@ -77,7 +86,7 @@ pub fn hardware_init_mini_0v5(
p.DMA1_CH4,
p.DMA1_CH3,
Hertz(400_000),
Default::default(),
i2c_config,
);

// InputReverseConfig::Halfword
Expand Down
68 changes: 26 additions & 42 deletions src/components/eeprom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,6 @@ const PAGE_SHIFT: usize = 4;
const SECTION_NUM: usize = 8;
const ROM_7B_ADDRESS: u8 = 0b1010000; // Embassy require 7bits address as parameter.
// const ROM_ADDRESS_FIELD_SIZE: usize = core::mem::size_of::<u8>();
const WAIT_DURATION_PER_PAGE: Duration = Duration::from_millis(20); // heuristic value
const CHECKSUM_SIZE: usize = core::mem::size_of::<Checksum>();
const UPTIME_SIZE: usize = core::mem::size_of::<Duration>();
const TOTAL_SLOT_NUM: usize = 96; // should be calculated in compile time
Expand Down Expand Up @@ -732,18 +731,14 @@ impl Novella {
let i2c_address = ROM_7B_ADDRESS | ((raw_addr >> 8) as DevSelAddress & 0x7);

// blocking function can detect NACK, but async type does not
bus.blocking_write_read_timeout(
i2c_address,
&data_address_slice,
rx_buffer,
WAIT_DURATION_PER_PAGE,
)
.map_err(|e| match e {
embassy_stm32::i2c::Error::Timeout | embassy_stm32::i2c::Error::Nack => {
NovellaReadError::MissingEeprom
}
_ => NovellaReadError::Unknown,
})?;
// WAIT_DURATION_PER_PAGE,
bus.blocking_write_read(i2c_address, &data_address_slice, rx_buffer)
.map_err(|e| match e {
embassy_stm32::i2c::Error::Timeout | embassy_stm32::i2c::Error::Nack => {
NovellaReadError::MissingEeprom
}
_ => NovellaReadError::Unknown,
})?;

if Self::consider_initial_uptime(page_idx) {
// Grab time::Duration of slot
Expand Down Expand Up @@ -885,10 +880,10 @@ impl Novella {

self.clr_write_protect();

match bus.blocking_write_timeout(
// WAIT_DURATION_PER_PAGE,
match bus.blocking_write(
i2c_address,
unsafe { &*self.buffer.get() }, // when page is 16, include 1+16 byte will be tx.
WAIT_DURATION_PER_PAGE,
) {
Ok(_) => {}
Err(e) => {
Expand Down Expand Up @@ -922,16 +917,12 @@ impl Novella {
// #[cfg(i2c_addr_bits_include_msb)]
let i2c_address = ROM_7B_ADDRESS | ((raw_addr >> 8) as DevSelAddress & 0x7);

bus.blocking_write_read_timeout(
i2c_address,
addr_buffer,
data_buffer,
WAIT_DURATION_PER_PAGE,
)
.map_err(|e| match e {
embassy_stm32::i2c::Error::Timeout => NovellaWriteError::MissingEeprom,
_ => NovellaWriteError::Unknown,
})?;
// WAIT_DURATION_PER_PAGE,
bus.blocking_write_read(i2c_address, addr_buffer, data_buffer)
.map_err(|e| match e {
embassy_stm32::i2c::Error::Timeout => NovellaWriteError::MissingEeprom,
_ => NovellaWriteError::Unknown,
})?;

if Self::consider_initial_uptime(page_idx) {
// Grab time::Duration of slot
Expand Down Expand Up @@ -1080,10 +1071,10 @@ impl Novella {

self.clr_write_protect();

match bus.blocking_write_timeout(
// WAIT_DURATION_PER_PAGE,
match bus.blocking_write(
i2c_address,
unsafe { &*self.buffer.get() }, // when page is 16, include 1+16 byte will be tx.
WAIT_DURATION_PER_PAGE,
) {
Ok(_) => {}
Err(e) => {
Expand Down Expand Up @@ -1118,16 +1109,12 @@ impl Novella {
// #[cfg(i2c_addr_bits_include_msb)]
let i2c_address = ROM_7B_ADDRESS | ((raw_addr >> 8) as DevSelAddress & 0x7);

bus.blocking_write_read_timeout(
i2c_address,
addr_buffer,
data_buffer,
WAIT_DURATION_PER_PAGE,
)
.map_err(|e| match e {
embassy_stm32::i2c::Error::Timeout => NovellaWriteError::MissingEeprom,
_ => NovellaWriteError::Unknown,
})?;
// WAIT_DURATION_PER_PAGE,
bus.blocking_write_read(i2c_address, addr_buffer, data_buffer)
.map_err(|e| match e {
embassy_stm32::i2c::Error::Timeout => NovellaWriteError::MissingEeprom,
_ => NovellaWriteError::Unknown,
})?;

if Self::consider_initial_uptime(page_idx) {
// Grab time::Duration of slot
Expand Down Expand Up @@ -1337,11 +1324,8 @@ impl Novella {
// #[cfg(i2c_addr_bits_include_msb)]
let i2c_address = ROM_7B_ADDRESS | ((raw_addr >> 8) as DevSelAddress & 0x7);

let result = bus.blocking_write_timeout(
i2c_address,
unsafe { &*self.buffer.get() },
WAIT_DURATION_PER_PAGE,
);
// WAIT_DURATION_PER_PAGE,
let result = bus.blocking_write(i2c_address, unsafe { &*self.buffer.get() });

delay_write_time_blocking();
}
Expand Down

0 comments on commit 98edbc3

Please sign in to comment.