-
Notifications
You must be signed in to change notification settings - Fork 40
FlexCAN peripheral addition #122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
2afe1a7
Prototype a FlexCAN peripheral
dstric-aqueduct fd8e1ae
Remove StandardId and ExtendedId structs in favor of embedded-hal
dstric-aqueduct df48822
use get_clock() instead of hard code freq for baud rate calc
dstric-aqueduct f73b2b8
PR updates
dstric-aqueduct 228a000
remove unused import, added derives to FlexCanMailboxCSCode
dstric-aqueduct c6f055e
fix to mod.rs docs
dstric-aqueduct 11daf65
PR updates
dstric-aqueduct a87433c
Prototype a FlexCAN peripheral
dstric-aqueduct 3b882b3
Merge branch 'dev/can' of https://github.com/dstric-aqueduct/imxrt-ha…
dstric-aqueduct 3350979
fix clippy warnings
dstric-aqueduct 2ca7328
Fix formatting
mciantyre 18ca5f9
Run 'cargo clippy --fix' to resolve some warnings
mciantyre 5ad3713
Simplify conditional expressions with u32::from
mciantyre 87c27f5
update to address overflow in baud rate calc
dstric-aqueduct File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| target | ||
| .idea | ||
| .vscode | ||
| Cargo.lock |
This file contains hidden or 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
This file contains hidden or 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,110 @@ | ||
| //! `embedded_hal` trait impls. | ||
|
|
||
| use super::{Data, Error, Frame, CAN}; | ||
| use crate::iomuxc::consts::Unsigned; | ||
|
|
||
| use embedded_hal::can; | ||
| pub(crate) use embedded_hal::can::ErrorKind; | ||
| pub use embedded_hal::can::{ExtendedId, Id, StandardId}; | ||
|
|
||
| impl<M> can::Can for CAN<M> | ||
| where | ||
| M: Unsigned, | ||
| { | ||
| type Frame = Frame; | ||
|
|
||
| type Error = Error; | ||
|
|
||
| fn transmit(&mut self, frame: &Self::Frame) -> nb::Result<Option<Self::Frame>, Self::Error> { | ||
| match self.transmit(frame) { | ||
| Ok(_status) => Ok(Some(frame.clone())), | ||
| Err(nb::Error::WouldBlock) => Err(nb::Error::WouldBlock), | ||
| Err(nb::Error::Other(e)) => Err(nb::Error::Other(e)), | ||
| } | ||
| } | ||
|
|
||
| fn receive(&mut self) -> nb::Result<Self::Frame, Self::Error> { | ||
| match self.read_mailboxes() { | ||
| Some(d) => Ok(d.frame), | ||
| None => Err(nb::Error::Other(Error::NoRxData)), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl can::Error for Error { | ||
| fn kind(&self) -> can::ErrorKind { | ||
| match self { | ||
| Self::NoRxData => can::ErrorKind::Other, | ||
| Self::NoTxMailbox => can::ErrorKind::Other, | ||
| Self::EmbeddedHal(e) => e.kind(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl can::Frame for Frame { | ||
| fn new(id: impl Into<can::Id>, data: &[u8]) -> Option<Self> { | ||
| let id = match id.into() { | ||
| can::Id::Standard(id) => unsafe { | ||
| Id::Standard(StandardId::new_unchecked(id.as_raw())) | ||
| }, | ||
| can::Id::Extended(id) => unsafe { | ||
| Id::Extended(ExtendedId::new_unchecked(id.as_raw())) | ||
| }, | ||
| }; | ||
|
|
||
| let data = Data::new(data)?; | ||
| Some(Frame::new_data(id, data)) | ||
| } | ||
|
|
||
| fn new_remote(id: impl Into<can::Id>, dlc: usize) -> Option<Self> { | ||
| let id = match id.into() { | ||
| can::Id::Standard(id) => unsafe { | ||
| Id::Standard(StandardId::new_unchecked(id.as_raw())) | ||
| }, | ||
| can::Id::Extended(id) => unsafe { | ||
| Id::Extended(ExtendedId::new_unchecked(id.as_raw())) | ||
| }, | ||
| }; | ||
|
|
||
| if dlc <= 8 { | ||
| Some(Frame::new_remote(id, dlc as u8)) | ||
| } else { | ||
| None | ||
| } | ||
| } | ||
|
|
||
| #[inline] | ||
| fn is_extended(&self) -> bool { | ||
| self.is_extended() | ||
| } | ||
|
|
||
| #[inline] | ||
| fn is_remote_frame(&self) -> bool { | ||
| self.is_remote_frame() | ||
| } | ||
|
|
||
| #[inline] | ||
| fn id(&self) -> can::Id { | ||
| match self.id() { | ||
| Id::Standard(id) => unsafe { | ||
| can::Id::Standard(can::StandardId::new_unchecked(id.as_raw())) | ||
| }, | ||
| Id::Extended(id) => unsafe { | ||
| can::Id::Extended(can::ExtendedId::new_unchecked(id.as_raw())) | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| #[inline] | ||
| fn dlc(&self) -> usize { | ||
| self.dlc().into() | ||
| } | ||
|
|
||
| fn data(&self) -> &[u8] { | ||
| if let Some(data) = self.data() { | ||
| data | ||
| } else { | ||
| &[] | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,38 @@ | ||
| //! Filter bank API. | ||
|
|
||
| #[derive(Debug, Copy, Clone, Eq, PartialEq, Default)] | ||
| pub enum FlexCanIde { | ||
| #[default] | ||
| None = 0, | ||
| Ext = 1, | ||
| Rtr = 2, | ||
| Std = 3, | ||
| Inactive, | ||
| } | ||
|
|
||
| #[derive(Debug, Copy, Clone, Eq, PartialEq, Default)] | ||
| pub enum FlexCanFlten { | ||
| AcceptAll = 0, | ||
| #[default] | ||
| RejectAll = 1, | ||
| } | ||
|
|
||
| #[derive(Debug, Copy, Clone, Eq, PartialEq, Default)] | ||
| pub struct FlexCanFilter { | ||
| pub filter_id: u8, | ||
| pub id: u32, | ||
| pub ide: FlexCanIde, | ||
| pub remote: FlexCanIde, | ||
| } | ||
|
|
||
| impl FlexCanFilter { | ||
| /// Create a new [`FlexCanFilter`]. | ||
| pub fn new(filter_id: u8, id: u32, ide: FlexCanIde, remote: FlexCanIde) -> Self { | ||
| Self { | ||
| filter_id, | ||
| id, | ||
| ide, | ||
| remote, | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.