forked from imxrt-rs/imxrt-hal
-
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.
Merge branch 'dev/can' into maint-v0.4
- Loading branch information
Showing
21 changed files
with
2,360 additions
and
921 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
target | ||
.idea | ||
.vscode | ||
Cargo.lock |
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
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 |
---|---|---|
@@ -1,22 +1,18 @@ | ||
# imxrt-hal | ||
# imxrt1060-hal | ||
|
||
This project provides a Rust HAL (hardware abstraction layer) for all NXP i.MX RT | ||
microcontrollers based on the imxrt-ral crate. | ||
`imxrt1060-hal` is a Rust hardware abstraction layer that's specific to i.MX | ||
RT 1060 processors. This includes some of the following processor parts: | ||
|
||
A feature flag needs to be set for any of the supported i.MX RT SoC. | ||
- i.MX RT 1061 | ||
- i.MX RT 1062 | ||
|
||
## What is it? | ||
It is the successor to `imxrt-hal`, version 0.4, with `feature = "imxrt1062"`. | ||
|
||
imxrt-hal is an experiment into a lightweight hardware abstraction layer. It | ||
provides access to some of the peripherals of the i.MX RT series processors | ||
from NXP using embedded-hal and other community driven hardware APIs. | ||
## Features | ||
|
||
The main aims are fast compilation, compactness, and simplicity. | ||
The table below describes the optional features supported by `imxrt1060-hal`. | ||
|
||
Please consider trying it out and contributing or leaving feedback! | ||
|
||
## Goals | ||
|
||
* Simple to use and hard to use incorrectly | ||
* All peripherals and busses supported | ||
* Support the entire i.MX RT Series with a single crate to maximize code reuse | ||
| Feature | Description | | ||
| -------- | ---------------------------------- | | ||
| `"rt"` | Runtime support with `cortex-m-rt` | | ||
| `"rtic"` | Support for RTIC | |
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,104 @@ | ||
//! `embedded_hal` trait impls. | ||
use super::{Data, ExtendedId, Frame, Id, OverrunError, StandardId, CAN}; | ||
|
||
use crate::iomuxc::consts::Unsigned; | ||
use embedded_hal::can; | ||
|
||
impl<M> can::Can for CAN<M> | ||
where | ||
M: Unsigned, | ||
{ | ||
type Frame = Frame; | ||
|
||
type Error = OverrunError; | ||
|
||
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)) => match e {}, | ||
} | ||
} | ||
|
||
fn receive(&mut self) -> nb::Result<Self::Frame, Self::Error> { | ||
let data: [u8; 8] = [255, 255, 255, 255, 255, 255, 255, 255]; | ||
let id = StandardId::new(0).unwrap(); | ||
|
||
Ok(Frame::new_data(id, Data::new(&data).unwrap())) | ||
} | ||
} | ||
|
||
impl can::Error for OverrunError { | ||
fn kind(&self) -> can::ErrorKind { | ||
can::ErrorKind::Overrun | ||
} | ||
} | ||
|
||
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 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,27 @@ | ||
//! 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 | ||
} | ||
|
Oops, something went wrong.