Erase TWAI (#2359)

* Swap order of generics

* Don't refer to Instance in irq handler

* Deduplicate a bit

* Take &self

* Reduce nesting

* Erase TWAI instance
This commit is contained in:
Dániel Buga 2024-10-24 08:47:02 +02:00 committed by GitHub
parent 1de2483609
commit c163b0586a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 524 additions and 415 deletions

View File

@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `AnyPin` now implements `From<GpioPin<N>>`. (#2326) - `AnyPin` now implements `From<GpioPin<N>>`. (#2326)
- Added `AnySpi` and `AnySpiDmaChannel`. (#2334) - Added `AnySpi` and `AnySpiDmaChannel`. (#2334)
- Added `AnyI2s` and `AnyI2sDmaChannel`. (#2367) - Added `AnyI2s` and `AnyI2sDmaChannel`. (#2367)
- Added `AnyTwai`. (#2359)
- `Pins::steal()` to unsafely obtain GPIO. (#2335) - `Pins::steal()` to unsafely obtain GPIO. (#2335)
- `I2c::with_timeout` (#2361) - `I2c::with_timeout` (#2361)
@ -23,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Peripheral type erasure for SPI (#2334) - Peripheral type erasure for SPI (#2334)
- Peripheral type erasure for I2S (#2367) - Peripheral type erasure for I2S (#2367)
- Peripheral type erasure for I2C (#2361) - Peripheral type erasure for I2C (#2361)
- Peripheral type erasure for TWAI (#2359)
### Fixed ### Fixed

View File

@ -31,6 +31,7 @@ peripherals:
- SPI (both master and slave) - SPI (both master and slave)
- I2S - I2S
- I2C - I2C
- TWAI
```diff ```diff
-Spi<'static, SPI2, FullDuplexMode> -Spi<'static, SPI2, FullDuplexMode>

View File

@ -67,7 +67,7 @@ crate::peripherals! {
TIMG0 <= TIMG0, TIMG0 <= TIMG0,
TIMG1 <= TIMG1, TIMG1 <= TIMG1,
TOUCH <= virtual, TOUCH <= virtual,
TWAI0 <= TWAI0, [Twai0] TWAI0 <= TWAI0,
UART0 <= UART0, UART0 <= UART0,
UART1 <= UART1, UART1 <= UART1,
UART2 <= UART2, UART2 <= UART2,

View File

@ -53,7 +53,7 @@ crate::peripherals! {
SW_INTERRUPT <= virtual, SW_INTERRUPT <= virtual,
TIMG0 <= TIMG0, TIMG0 <= TIMG0,
TIMG1 <= TIMG1, TIMG1 <= TIMG1,
TWAI0 <= TWAI0, [Twai0] TWAI0 <= TWAI0,
UART0 <= UART0, UART0 <= UART0,
UART1 <= UART1, UART1 <= UART1,
UHCI0 <= UHCI0, UHCI0 <= UHCI0,

View File

@ -81,8 +81,8 @@ crate::peripherals! {
TIMG0 <= TIMG0, TIMG0 <= TIMG0,
TIMG1 <= TIMG1, TIMG1 <= TIMG1,
TRACE0 <= TRACE, TRACE0 <= TRACE,
TWAI0 <= TWAI0, [Twai0] TWAI0 <= TWAI0,
TWAI1 <= TWAI1, [Twai1] TWAI1 <= TWAI1,
UART0 <= UART0, UART0 <= UART0,
UART1 <= UART1, UART1 <= UART1,
UHCI0 <= UHCI0, UHCI0 <= UHCI0,

View File

@ -73,7 +73,7 @@ crate::peripherals! {
TIMG0 <= TIMG0, TIMG0 <= TIMG0,
TIMG1 <= TIMG1, TIMG1 <= TIMG1,
TRACE0 <= TRACE, TRACE0 <= TRACE,
TWAI0 <= TWAI0, [Twai0] TWAI0 <= TWAI0,
UART0 <= UART0, UART0 <= UART0,
UART1 <= UART1, UART1 <= UART1,
UHCI0 <= UHCI0, UHCI0 <= UHCI0,

View File

@ -60,7 +60,7 @@ crate::peripherals! {
SW_INTERRUPT <= virtual, SW_INTERRUPT <= virtual,
TIMG0 <= TIMG0, TIMG0 <= TIMG0,
TIMG1 <= TIMG1, TIMG1 <= TIMG1,
TWAI0 <= TWAI0, [Twai0] TWAI0 <= TWAI0,
UART0 <= UART0, UART0 <= UART0,
UART1 <= UART1, UART1 <= UART1,
UHCI0 <= UHCI0, UHCI0 <= UHCI0,

View File

@ -66,7 +66,7 @@ crate::peripherals! {
SW_INTERRUPT <= virtual, SW_INTERRUPT <= virtual,
TIMG0 <= TIMG0, TIMG0 <= TIMG0,
TIMG1 <= TIMG1, TIMG1 <= TIMG1,
TWAI0 <= TWAI0, [Twai0] TWAI0 <= TWAI0,
UART0 <= UART0, UART0 <= UART0,
UART1 <= UART1, UART1 <= UART1,
UART2 <= UART2, UART2 <= UART2,

File diff suppressed because it is too large Load Diff

View File

@ -36,8 +36,6 @@ use embedded_can::{Frame, Id};
use esp_backtrace as _; use esp_backtrace as _;
use esp_hal::{ use esp_hal::{
gpio::Io, gpio::Io,
interrupt,
peripherals::{self, TWAI0},
timer::timg::TimerGroup, timer::timg::TimerGroup,
twai::{self, EspTwaiFrame, StandardId, TwaiMode, TwaiRx, TwaiTx}, twai::{self, EspTwaiFrame, StandardId, TwaiMode, TwaiRx, TwaiTx},
}; };
@ -47,10 +45,7 @@ use static_cell::StaticCell;
type TwaiOutbox = Channel<NoopRawMutex, EspTwaiFrame, 16>; type TwaiOutbox = Channel<NoopRawMutex, EspTwaiFrame, 16>;
#[embassy_executor::task] #[embassy_executor::task]
async fn receiver( async fn receiver(mut rx: TwaiRx<'static, esp_hal::Async>, channel: &'static TwaiOutbox) -> ! {
mut rx: TwaiRx<'static, TWAI0, esp_hal::Async>,
channel: &'static TwaiOutbox,
) -> ! {
loop { loop {
let frame = rx.receive_async().await; let frame = rx.receive_async().await;
@ -72,10 +67,7 @@ async fn receiver(
} }
#[embassy_executor::task] #[embassy_executor::task]
async fn transmitter( async fn transmitter(mut tx: TwaiTx<'static, esp_hal::Async>, channel: &'static TwaiOutbox) -> ! {
mut tx: TwaiTx<'static, TWAI0, esp_hal::Async>,
channel: &'static TwaiOutbox,
) -> ! {
loop { loop {
let frame = channel.receive().await; let frame = channel.receive().await;
let result = tx.transmit_async(&frame).await; let result = tx.transmit_async(&frame).await;
@ -141,12 +133,6 @@ async fn main(spawner: Spawner) {
// Get separate transmit and receive halves of the peripheral. // Get separate transmit and receive halves of the peripheral.
let (rx, tx) = twai.split(); let (rx, tx) = twai.split();
interrupt::enable(
peripherals::Interrupt::TWAI0,
interrupt::Priority::Priority1,
)
.unwrap();
static CHANNEL: StaticCell<TwaiOutbox> = StaticCell::new(); static CHANNEL: StaticCell<TwaiOutbox> = StaticCell::new();
let channel = &*CHANNEL.init(Channel::new()); let channel = &*CHANNEL.init(Channel::new());

View File

@ -8,7 +8,6 @@
use embedded_hal_02::can::Frame; use embedded_hal_02::can::Frame;
use esp_hal::{ use esp_hal::{
gpio::Io, gpio::Io,
peripherals::TWAI0,
prelude::*, prelude::*,
twai::{self, filter::SingleStandardFilter, EspTwaiFrame, StandardId, TwaiMode}, twai::{self, filter::SingleStandardFilter, EspTwaiFrame, StandardId, TwaiMode},
Blocking, Blocking,
@ -17,7 +16,7 @@ use hil_test as _;
use nb::block; use nb::block;
struct Context { struct Context {
twai: twai::Twai<'static, TWAI0, Blocking>, twai: twai::Twai<'static, Blocking>,
} }
#[cfg(test)] #[cfg(test)]