Skip to content

Commit

Permalink
align with head of maint-v0.4 branch
Browse files Browse the repository at this point in the history
align with head of maint-v0.4 branch

Delete interrupt.rs

fix implementation of `embedded_hal` `receive` function for Can trait

Fix to `embedded_hal` trait
  • Loading branch information
dstric-aqueduct committed Dec 14, 2022
1 parent 66ff65d commit 8b52ac3
Show file tree
Hide file tree
Showing 5 changed files with 457 additions and 55 deletions.
28 changes: 16 additions & 12 deletions imxrt-hal/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
# imxrt1060-hal
# imxrt-hal

`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:
This project provides a Rust HAL (hardware abstraction layer) for all NXP i.MX RT
microcontrollers based on the imxrt-ral crate.

- i.MX RT 1061
- i.MX RT 1062
A feature flag needs to be set for any of the supported i.MX RT SoC.

It is the successor to `imxrt-hal`, version 0.4, with `feature = "imxrt1062"`.
## What is it?

## Features
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.

The table below describes the optional features supported by `imxrt1060-hal`.
The main aims are fast compilation, compactness, and simplicity.

| Feature | Description |
| -------- | ---------------------------------- |
| `"rt"` | Runtime support with `cortex-m-rt` |
| `"rtic"` | Support for RTIC |
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
14 changes: 7 additions & 7 deletions imxrt-hal/src/can/embedded_hal.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! `embedded_hal` trait impls.
use super::{Data, ExtendedId, Frame, Id, OverrunError, StandardId, CAN};
use super::{Data, ExtendedId, Frame, Id, NoDataError, StandardId, CAN};

use crate::iomuxc::consts::Unsigned;
use embedded_hal::can;
Expand All @@ -11,7 +11,7 @@ where
{
type Frame = Frame;

type Error = OverrunError;
type Error = NoDataError;

fn transmit(&mut self, frame: &Self::Frame) -> nb::Result<Option<Self::Frame>, Self::Error> {
match self.transmit(frame) {
Expand All @@ -22,14 +22,14 @@ where
}

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()))
match self.read_mailboxes() {
Some(d) => Ok(d.frame),
None => Err(nb::Error::Other(NoDataError { _priv: () })),
}
}
}

impl can::Error for OverrunError {
impl can::Error for NoDataError {
fn kind(&self) -> can::ErrorKind {
can::ErrorKind::Overrun
}
Expand Down
9 changes: 5 additions & 4 deletions imxrt-hal/src/can/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ use crate::ral;
use core::convert::Infallible;
use core::marker::PhantomData;

/// Error that indicates that an incoming message has been lost due to buffer overrun.
/// Error that indicates that no received frames are available
/// in the FlexCAN mailboxes
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct OverrunError {
pub struct NoDataError {
_priv: (),
}

Expand Down Expand Up @@ -911,7 +912,7 @@ where
return;
}

pub fn read_mailboxes(&mut self) -> Option<()> {
pub fn read_mailboxes(&mut self) -> Option<MailboxData> {
let mut iflag: u64;
let mut cycle_limit: u8 = 3;
let offset = self.mailbox_offset();
Expand Down Expand Up @@ -946,7 +947,7 @@ where
}
match self.read_mailbox(self._mailbox_reader_index) {
Some(mailbox_data) => {
log::info!("RX Data: {:?}", &mailbox_data,);
return Some(mailbox_data);
}
_ => {}
}
Expand Down
28 changes: 28 additions & 0 deletions imxrt-hal/src/ccm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ impl PLL1 {
PLL1(())
}

#[cfg(any(feature = "imxrt1011", feature = "imxrt1015"))]
pub const ARM_HZ: u32 = 500_000_000;

#[cfg(any(feature = "imxrt1064", feature = "imxrt1062", feature = "imxrt1061"))]
pub const ARM_HZ: u32 = 600_000_000;

/// Set the clock speed for the ARM core. This represents the base processor frequency.
Expand Down Expand Up @@ -921,6 +925,30 @@ pub mod spi {
LPSPI_PODF_6 = ccm::CBCMR::LPSPI_PODF::RW::LPSPI_PODF_6,
/// 0b0111: divide by 8
LPSPI_PODF_7 = ccm::CBCMR::LPSPI_PODF::RW::LPSPI_PODF_7,
/// 0b1000: divide by 9
#[cfg(features = "imxrt1011")]
LPSPI_PODF_8 = ccm::CBCMR::LPSPI_PODF::RW::LPSPI_PODF_8,
/// 0b1001: divide by 10
#[cfg(features = "imxrt1011")]
LPSPI_PODF_9 = ccm::CBCMR::LPSPI_PODF::RW::LPSPI_PODF_9,
/// 0b1010: divide by 11
#[cfg(features = "imxrt1011")]
LPSPI_PODF_10 = ccm::CBCMR::LPSPI_PODF::RW::LPSPI_PODF_10,
/// 0b1011: divide by 12
#[cfg(features = "imxrt1011")]
LPSPI_PODF_11 = ccm::CBCMR::LPSPI_PODF::RW::LPSPI_PODF_11,
/// 0b1100: divide by 13
#[cfg(features = "imxrt1011")]
LPSPI_PODF_12 = ccm::CBCMR::LPSPI_PODF::RW::LPSPI_PODF_12,
/// 0b1101: divide by 14
#[cfg(features = "imxrt1011")]
LPSPI_PODF_13 = ccm::CBCMR::LPSPI_PODF::RW::LPSPI_PODF_13,
/// 0b1110: divide by 15
#[cfg(features = "imxrt1011")]
LPSPI_PODF_14 = ccm::CBCMR::LPSPI_PODF::RW::LPSPI_PODF_14,
/// 0b1111: divide by 16
#[cfg(features = "imxrt1011")]
LPSPI_PODF_15 = ccm::CBCMR::LPSPI_PODF::RW::LPSPI_PODF_15,
}

impl From<ClockSelect> for Frequency {
Expand Down
Loading

0 comments on commit 8b52ac3

Please sign in to comment.