Added public interfaces for vals::Dir and vals::Oamsk, so they can be used outside the crate

This commit is contained in:
anton smeenk
2023-10-28 08:25:41 +02:00
parent 0fe0bc60fe
commit 26e37c673d
4 changed files with 97 additions and 55 deletions

View File

@ -9,8 +9,7 @@ use core::fmt::{self, Write};
use embassy_executor::Spawner;
use embassy_stm32::dma::NoDma;
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::i2c::{Error, I2c};
use embassy_stm32::pac::i2c::vals;
use embassy_stm32::i2c::{Address2Mask, Dir, Error, I2c};
use embassy_stm32::time::Hertz;
use embassy_stm32::usart::UartTx;
use embassy_stm32::{bind_interrupts, i2c, peripherals, usart};
@ -25,7 +24,7 @@ bind_interrupts!(struct Irqs {
macro_rules! checkIsWrite {
($writer:ident, $direction:ident) => {
match $direction {
vals::Dir::WRITE => (),
Dir::WRITE => (),
_ => {
write!($writer, "Error incorrect direction {:?}\r", $direction as usize).unwrap();
continue;
@ -36,7 +35,7 @@ macro_rules! checkIsWrite {
macro_rules! checkIsRead {
($writer:ident, $direction:ident) => {
match $direction {
vals::Dir::READ => (),
Dir::READ => (),
_ => {
write!($writer, "Error incorrect direction {:?}\r", $direction as usize).unwrap();
continue;
@ -108,7 +107,7 @@ async fn main(spawner: Spawner) {
let mut config = i2c::Config::default();
config.slave_address_7bits(0x10); // for arbitration lost test
config.slave_address_2(0x41, vals::Oamsk::MASK4);
config.slave_address_2(0x41, Address2Mask::MASK4);
let i2c = I2c::new(p.I2C1, p.PB8, p.PB9, Irqs, NoDma, NoDma, Hertz(100_000), config);
@ -116,9 +115,10 @@ async fn main(spawner: Spawner) {
let mut buf_20 = [0; 20]; // buffer is shorter than master will send: wait for STOP condition
let mut buf_20a = [0; 20];
let mut buf_2 = [0; 2];
let mut buf_1 = [0; 1];
let mut errors = 0;
let mut address = 0;
let mut dir = vals::Dir::READ;
let mut dir = Dir::READ;
let mut tcount = 0;
let mut counter = 0;
let mut result: Option<Error> = None;
@ -360,7 +360,7 @@ async fn main(spawner: Spawner) {
tcount = 0;
errors = 0;
}
0x10 => {
0x4 => {
// Arbitration lost test Master does read 2 bytes on address 0x10
// this slave will send 0xFF04, the other slave will send 0xFF03
// This slave should generate a arbitration lost if the other slave is online

View File

@ -10,12 +10,10 @@ use core::fmt::{self, Write};
use embassy_executor::Spawner;
use embassy_stm32::dma::NoDma;
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::i2c::{Error, I2c};
use embassy_stm32::pac::i2c::vals;
use embassy_stm32::i2c::{Dir, Error, I2c};
use embassy_stm32::time::Hertz;
use embassy_stm32::usart::UartTx;
use embassy_stm32::{bind_interrupts, i2c, peripherals, usart};
use embassy_time::{Duration, Timer};
use {defmt_rtt as _, panic_probe as _};
bind_interrupts!(struct Irqs {
@ -23,29 +21,6 @@ bind_interrupts!(struct Irqs {
USART1 => usart::InterruptHandler<peripherals::USART1>;
});
macro_rules! checkIsWrite {
($writer:ident, $direction:ident) => {
match $direction {
vals::Dir::WRITE => (),
_ => {
write!($writer, "Error incorrect direction {:?}\r", $direction as usize).unwrap();
continue;
}
}
};
}
macro_rules! checkIsRead {
($writer:ident, $direction:ident) => {
match $direction {
vals::Dir::READ => (),
_ => {
write!($writer, "Error incorrect direction {:?}\r", $direction as usize).unwrap();
continue;
}
}
};
}
pub struct SerialWriter {
tx: UartTx<'static, peripherals::USART1, peripherals::DMA1_CH1>,
}
@ -106,7 +81,7 @@ async fn main(spawner: Spawner) {
let mut buf_2 = [0; 2];
let mut address = 0;
let mut dir = vals::Dir::READ;
let mut dir = Dir::READ;
let mut counter = 0;
let mut result: Option<Error> = None;
@ -119,7 +94,7 @@ async fn main(spawner: Spawner) {
// content for test 0x10
buf_2[0] = 0xFF;
buf_2[1] = 0x03;
_ = i2c.slave_write_buffer(&mut buf_2, i2c::AddressType::MainAddress);
_ = i2c.slave_write_buffer(&mut buf_2, i2c::AddressType::Address1);
writeln!(&mut writer, "Waiting for master activity\r").unwrap();
@ -137,7 +112,6 @@ async fn main(spawner: Spawner) {
// this slave will send 0xFF03, the other slave will send 0xFF04
// This slave should win , so no error here
writeln!(&mut writer, "Evaluate arbitration lost test 0x10.\r\n").unwrap();
checkIsRead!(writer, dir);
match result {
None => {
writeln!(&mut writer, "Test 0x10 Passed\n\r").unwrap();