Skip to content

Commit

Permalink
Initial TWAI Driver Implementation (#192)
Browse files Browse the repository at this point in the history
* wip: initial implementation of transmission only.

* Moved TWAI to its own directory and added initial reception of packets.

* Added extended id transmit and receive.

* Added maybe better code for making packet filters.

* Fixed bug with ids and improved methods of copying data to the peripheral.

* Added some guards against Bus Off

* Added reception of remote frames.

* Clean up of comments, etc

* Updated TWAI naming and cleaned up example a bit.

* Updated bitselector to include better unpacking methods.

* Add embedded-can and limit initial TWAI implementation to esp32c3.

* Added embedded-can to esp32c3 twai example.

* Switched twai filter to using bytestrings.

Co-authored-by: dimi <dimi.polonski@gmail.com>

* Implemented new() for twai filters.

* Clean up TWAI docs and example.

* Fix filter constructors and add examples.

* pre driver PeripheralRef update.

* PeripheralRef/twai

* Format comments with nightly rustfmt.

* Add gpio PeripheralRef and use volatile for direct register access.

Co-authored-by: dimi <dimi.polonski@gmail.com>
  • Loading branch information
alexbohm and dimpolo authored Dec 22, 2022
1 parent 452fde2 commit 1f68037
Show file tree
Hide file tree
Showing 9 changed files with 1,349 additions and 2 deletions.
3 changes: 2 additions & 1 deletion esp-hal-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ critical-section = "1.1.1"
embedded-hal = { version = "0.2.7", features = ["unproven"] }
embedded-hal-1 = { version = "=1.0.0-alpha.9", optional = true, package = "embedded-hal" }
embedded-hal-nb = { version = "=1.0.0-alpha.1", optional = true }
embedded-can = { version = "0.4.1", optional = true }
fugit = "0.3.6"
lock_api = { version = "0.4.9", optional = true }
nb = "1.0.0"
Expand Down Expand Up @@ -67,7 +68,7 @@ esp32c2_40mhz = []
esp32c2_26mhz = []

# Implement the `embedded-hal==1.0.0-alpha.x` traits
eh1 = ["embedded-hal-1", "embedded-hal-nb"]
eh1 = ["embedded-hal-1", "embedded-hal-nb", "embedded-can"]

# To use the external `smart_led` crate
smartled = ["smart-leds-trait"]
Expand Down
2 changes: 2 additions & 0 deletions esp-hal-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ pub mod system;
#[cfg(systimer)]
pub mod systimer;
pub mod timer;
#[cfg(any(esp32c3))]
pub mod twai;
pub mod uart;
#[cfg(usb_serial_jtag)]
pub mod usb_serial_jtag;
Expand Down
1 change: 1 addition & 0 deletions esp-hal-common/src/peripherals/esp32c3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ mod peripherals {
TIMG0,
TIMG1,
APB_SARADC,
TWAI,
}
}
7 changes: 7 additions & 0 deletions esp-hal-common/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ pub enum Peripheral {
I2s1,
#[cfg(usb_otg)]
Usb,
#[cfg(any(esp32c3))]
Twai,
}

/// Controls the enablement of peripheral clocks.
Expand Down Expand Up @@ -149,6 +151,11 @@ impl PeripheralClockControl {
perip_clk_en0.modify(|_, w| w.usb_clk_en().set_bit());
perip_rst_en0.modify(|_, w| w.usb_rst().clear_bit());
}
#[cfg(any(esp32c3))]
Peripheral::Twai => {
perip_clk_en0.modify(|_, w| w.can_clk_en().set_bit());
perip_rst_en0.modify(|_, w| w.can_rst().clear_bit());
}
}
}
}
Expand Down
Loading

0 comments on commit 1f68037

Please sign in to comment.