forked from imxrt-rs/imxrt-iomuxc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add FlexCAN pin trait, FlexCAN1 and 2 1060 impls
1060 pins implementations checked against section 44.3 in the 1060 reference manual. See imxrt-rs/imxrt-hal#122 for a related FlexCAN driver.
- Loading branch information
1 parent
7c3f4e0
commit c12adda
Showing
4 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//! Can pad configurations | ||
/// A Can signal | ||
pub trait Signal: private::Sealed {} | ||
|
||
/// A tag that indicates a Can TX pad | ||
pub enum Tx {} | ||
/// A tag that indicates a Can Rx pad | ||
pub enum Rx {} | ||
|
||
impl Signal for Tx {} | ||
impl Signal for Rx {} | ||
mod private { | ||
pub trait Sealed {} | ||
impl Sealed for super::Tx {} | ||
impl Sealed for super::Rx {} | ||
} | ||
|
||
/// A Can pin | ||
pub trait Pin: super::IOMUX { | ||
/// Alternate value for this pin | ||
const ALT: u32; | ||
/// Daisy register | ||
const DAISY: Option<super::Daisy>; | ||
/// CAN signal | ||
type Signal: Signal; | ||
/// CAN module; `U1` for `CAN1` | ||
type Module: super::consts::Unsigned; | ||
} | ||
|
||
/// Prepare a Can pin | ||
/// | ||
/// # Safety | ||
/// | ||
/// `prepare()` inherits all the unsafety that comes from the `IOMUX` supertrait. | ||
pub fn prepare<P: Pin>(pin: &mut P) { | ||
super::alternate(pin, P::ALT); | ||
super::set_sion(pin); | ||
if let Some(daisy) = P::DAISY { | ||
unsafe { daisy.write() }; | ||
} | ||
} | ||
|
||
#[allow(unused)] // Used in chip-specific modules... | ||
macro_rules! can { | ||
(module: $module:ty, alt: $alt:expr, pad: $pad:ty, signal: $signal:ty, daisy: $daisy:expr) => { | ||
impl Pin for $pad { | ||
const ALT: u32 = $alt; | ||
const DAISY: Option<Daisy> = $daisy; | ||
type Signal = $signal; | ||
type Module = $module; | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
//! Can pin implementation | ||
use super::pads::{ad_b0::*, ad_b1::*, b0::*, b1::*, emc::*, sd_b1::*}; | ||
|
||
use crate::{ | ||
can::{Pin, Rx, Tx}, | ||
consts::*, | ||
Daisy, | ||
}; | ||
|
||
// | ||
// CAN1 | ||
// | ||
can!(module: U1, alt: 2, pad: AD_B1_08, signal: Tx, daisy: None); | ||
can!(module: U1, alt: 2, pad: B0_02, signal: Tx, daisy: None); | ||
can!(module: U1, alt: 3, pad: EMC_17, signal: Tx, daisy: None); | ||
can!(module: U1, alt: 4, pad: SD_B1_02, signal: Tx, daisy: None); | ||
can!(module: U1, alt: 2, pad: AD_B1_09, signal: Rx, daisy: Some(DAISY_CAN1_RX_GPIO_AD_B1_09)); | ||
can!(module: U1, alt: 2, pad: B0_03, signal: Rx, daisy: Some(DAISY_CAN1_RX_GPIO_B0_03)); | ||
can!(module: U1, alt: 3, pad: EMC_18, signal: Rx, daisy: Some(DAISY_CAN1_RX_GPIO_EMC_18)); | ||
can!(module: U1, alt: 4, pad: SD_B1_03, signal: Rx, daisy: Some(DAISY_CAN1_RX_GPIO_SD_B1_03)); | ||
|
||
// | ||
// CAN2 | ||
// | ||
can!(module: U2, alt: 0, pad: AD_B0_02, signal: Tx, daisy: None); | ||
can!(module: U2, alt: 3, pad: EMC_09, signal: Tx, daisy: None); | ||
can!(module: U2, alt: 6, pad: B1_08, signal: Tx, daisy: None); | ||
can!(module: U2, alt: 6, pad: AD_B0_14, signal: Tx, daisy: None); | ||
can!(module: U2, alt: 0, pad: AD_B0_03, signal: Rx, daisy: Some(DAISY_CAN2_RX_GPIO_AD_B0_03)); | ||
can!(module: U2, alt: 3, pad: EMC_10, signal: Rx, daisy: Some(DAISY_CAN2_RX_GPIO_EMC_10)); | ||
can!(module: U2, alt: 6, pad: AD_B0_15, signal: Rx, daisy: Some(DAISY_CAN2_RX_GPIO_AD_B0_15)); | ||
can!(module: U2, alt: 6, pad: B1_09, signal: Rx, daisy: Some(DAISY_CAN2_RX_GPIO_B1_09)); | ||
|
||
/// Auto-generated DAISY values | ||
mod daisy { | ||
#![allow(unused)] | ||
|
||
use super::Daisy; | ||
|
||
pub const DAISY_CAN1_RX_GPIO_SD_B1_03: Daisy = Daisy::new(0x401F_844C as *mut u32, 0); | ||
pub const DAISY_CAN1_RX_GPIO_EMC_18: Daisy = Daisy::new(0x401F_844C as *mut u32, 1); | ||
pub const DAISY_CAN1_RX_GPIO_AD_B1_09: Daisy = Daisy::new(0x401F_844C as *mut u32, 2); | ||
pub const DAISY_CAN1_RX_GPIO_B0_03: Daisy = Daisy::new(0x401F_844C as *mut u32, 3); | ||
|
||
pub const DAISY_CAN2_RX_GPIO_EMC_10: Daisy = Daisy::new(0x401F_8450 as *mut u32, 0); | ||
pub const DAISY_CAN2_RX_GPIO_AD_B0_03: Daisy = Daisy::new(0x401F_8450 as *mut u32, 1); | ||
pub const DAISY_CAN2_RX_GPIO_AD_B0_15: Daisy = Daisy::new(0x401F_8450 as *mut u32, 2); | ||
pub const DAISY_CAN2_RX_GPIO_B1_09: Daisy = Daisy::new(0x401F_8450 as *mut u32, 3); | ||
} | ||
|
||
use daisy::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,6 +89,7 @@ | |
//! ``` | ||
mod adc; | ||
mod can; | ||
mod i2c; | ||
mod pwm; | ||
mod sai; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,6 +87,8 @@ | |
|
||
#[macro_use] | ||
pub mod adc; | ||
#[macro_use] | ||
pub mod can; | ||
mod config; | ||
#[macro_use] | ||
pub mod i2c; | ||
|