diff --git a/esp-hal/src/twai/mod.rs b/esp-hal/src/twai/mod.rs index 935f545e7..a3e56560c 100644 --- a/esp-hal/src/twai/mod.rs +++ b/esp-hal/src/twai/mod.rs @@ -1194,10 +1194,7 @@ where return Err(EspTwaiError::BusOff); } // Check that the peripheral is not already transmitting a packet. - if !status.tx_buf_st().bit_is_set() { - return Err(EspTwaiError::WouldBlock); // TODO: Is this the right - // error? - } + while !status.tx_buf_st().bit_is_set() {} write_frame(register_block, frame); @@ -1227,9 +1224,7 @@ where } // Check that we actually have packets to receive. - if !status.rx_buf_st().bit_is_set() { - return Err(EspTwaiError::WouldBlock); - } + while !status.rx_buf_st().bit_is_set() {} // Check if the packet in the receive buffer is valid or overrun. if status.miss_st().bit_is_set() { @@ -1252,8 +1247,6 @@ pub enum EspTwaiError { NonCompliantDlc(u8), /// Encapsulates errors defined by the embedded-hal crate. EmbeddedHAL(ErrorKind), - /// This operation requires blocking behavior to complete - WouldBlock, } #[cfg(any(doc, feature = "unstable"))] diff --git a/examples/src/bin/twai.rs b/examples/src/bin/twai.rs index e49e04a01..41970e88b 100644 --- a/examples/src/bin/twai.rs +++ b/examples/src/bin/twai.rs @@ -81,7 +81,7 @@ fn main() -> ! { // Send a frame to the other ESP // Use `new_self_reception` if you want to use self-testing. let frame = EspTwaiFrame::new(StandardId::ZERO, &[1, 2, 3]).unwrap(); - while twai.transmit(&frame).is_err() {} + twai.transmit(&frame).unwrap(); println!("Sent a frame"); } @@ -89,18 +89,14 @@ fn main() -> ! { let delay = Delay::new(); loop { // Wait for a frame to be received. - let frame = loop { - if let Ok(frame) = twai.receive() { - break frame; - } - }; + let frame = twai.receive().unwrap(); println!("Received a frame: {frame:?}"); delay.delay_millis(250); let frame = EspTwaiFrame::new(StandardId::ZERO, &[1, 2, 3]).unwrap(); // Transmit a new frame back to the other ESP - while twai.transmit(&frame).is_err() {} + twai.transmit(&frame).unwrap(); println!("Sent a frame"); } } diff --git a/hil-test/tests/twai.rs b/hil-test/tests/twai.rs index e0d78496e..95efad208 100644 --- a/hil-test/tests/twai.rs +++ b/hil-test/tests/twai.rs @@ -51,13 +51,9 @@ mod tests { #[test] fn test_send_receive(mut ctx: Context) { let frame = EspTwaiFrame::new_self_reception(StandardId::ZERO, &[1, 2, 3]).unwrap(); - while ctx.twai.transmit(&frame).is_err() {} + ctx.twai.transmit(&frame).unwrap(); - let frame = loop { - if let Ok(frame) = ctx.twai.receive() { - break frame; - } - }; + let frame = ctx.twai.receive().unwrap(); assert_eq!(frame.data(), &[1, 2, 3]) }