Skip to content

Commit

Permalink
Share common pads across 1050 and 1060
Browse files Browse the repository at this point in the history
Before this commit, a diff of the 1050 and 1060 directories, like

    diff -ur src/imxrt1050 src/imxrt1060

showed that these modules were basically identical. The only
differences:

1. The 1060 has additional GPIO_SPI_* pads that aren't on the 1050.
2. The 1060 has FlexIO3.
3. The 1060 has SAI3.

We can handle these similarities through the module system, instead of
duplicating code. This commit consolidates the common pad definitions
and implementations into their own module. We build with that module
whenever the user enables a 1050 or 1060 feature. By consolidating most
pin implementations here, they'll be available on both MCUs without
duplication.

The 1050 directory re-exports all common pad modules and defines the
top-level `Pads` type. The 1060 does the same, and it also defines those
GPIO_SPI_* modules. This handles difference 1.

The 1060 defines its own flexio and sai modules where it provides its
additional implementations. This handles differences 2 and 3.
  • Loading branch information
mciantyre authored and Hatim Thayyil committed Nov 29, 2024
1 parent fd6d9e0 commit a5d7f77
Show file tree
Hide file tree
Showing 24 changed files with 98 additions and 2,512 deletions.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/imxrt1050/flexio.rs → src/common_1050_1060/flexio.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! FlexIO pin implementation
use super::pads::{gpio_ad_b1::*, gpio_b0::*, gpio_b1::*, gpio_emc::*};
use super::pads::{gpio_b0::*, gpio_b1::*, gpio_emc::*};

use crate::{flexio::Pin, Daisy};

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 17 additions & 0 deletions src/common_1050_1060/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//! Definitions shared between the 1050 and 1060 MCUs.
//!
//! The 1060 pads are an extension of the 1050 pads. This module contains the
//! definitions common to both MCUs.
mod adc;
mod flexcan;
mod flexio;
mod flexpwm;
mod lpi2c;
mod lpspi;
mod lpuart;
mod sai;
mod usdhc;

use pads::*;
pub(crate) mod pads;
64 changes: 0 additions & 64 deletions src/imxrt1050/pads.rs → src/common_1050_1060/pads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1761,67 +1761,3 @@ pub mod gpio_sd_b1 {
}
}
}

/// All of the pads.
pub struct Pads {
pub gpio_emc: gpio_emc::Pads,
pub gpio_ad_b0: gpio_ad_b0::Pads,
pub gpio_ad_b1: gpio_ad_b1::Pads,
pub gpio_b0: gpio_b0::Pads,
pub gpio_b1: gpio_b1::Pads,
pub gpio_sd_b0: gpio_sd_b0::Pads,
pub gpio_sd_b1: gpio_sd_b1::Pads,
}

impl Pads {
/// Take all pads from this group
///
/// # Safety
///
/// You may safely call this once to acquire all of the pads.
/// Subsequent calls may return pads that are mutably aliased
/// elsewhere. Consider calling new() at the start of your program.
#[inline]
pub const unsafe fn new() -> Self {
Self {
gpio_emc: gpio_emc::Pads::new(),
gpio_ad_b0: gpio_ad_b0::Pads::new(),
gpio_ad_b1: gpio_ad_b1::Pads::new(),
gpio_b0: gpio_b0::Pads::new(),
gpio_b1: gpio_b1::Pads::new(),
gpio_sd_b0: gpio_sd_b0::Pads::new(),
gpio_sd_b1: gpio_sd_b1::Pads::new(),
}
}

/// Erase all of the pads
///
/// The return type is an array, where the index indicates the
/// pad offset from the start of the group. For example, AD_B0_03
/// would be referenced as erased_pads\[3\].
///
/// See `ErasedPads` for more information.
#[inline]
pub const fn erase(self) -> ErasedPads {
ErasedPads {
gpio_emc: self.gpio_emc.erase(),
gpio_ad_b0: self.gpio_ad_b0.erase(),
gpio_ad_b1: self.gpio_ad_b1.erase(),
gpio_b0: self.gpio_b0.erase(),
gpio_b1: self.gpio_b1.erase(),
gpio_sd_b0: self.gpio_sd_b0.erase(),
gpio_sd_b1: self.gpio_sd_b1.erase(),
}
}
}

/// All erased pads.
pub struct ErasedPads {
pub gpio_emc: gpio_emc::ErasedPads,
pub gpio_ad_b0: gpio_ad_b0::ErasedPads,
pub gpio_ad_b1: gpio_ad_b1::ErasedPads,
pub gpio_b0: gpio_b0::ErasedPads,
pub gpio_b1: gpio_b1::ErasedPads,
pub gpio_sd_b0: gpio_sd_b0::ErasedPads,
pub gpio_sd_b1: gpio_sd_b1::ErasedPads,
}
File renamed without changes.
File renamed without changes.
81 changes: 0 additions & 81 deletions src/imxrt1050/flexpwm.rs

This file was deleted.

75 changes: 64 additions & 11 deletions src/imxrt1050/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,68 @@
//! The module exports all of the i.MX RT 1050 processor's pads. Pads that can support peripheral
//! functions are tagged with `imxrt-iomuxc` traits.
mod adc;
mod flexcan;
mod flexio;
mod flexpwm;
mod lpi2c;
mod lpspi;
mod lpuart;
mod sai;
mod usdhc;
pub use crate::common_1050_1060::pads::*;

mod pads;
pub use pads::*;
/// All of the pads.
pub struct Pads {
pub gpio_emc: gpio_emc::Pads,
pub gpio_ad_b0: gpio_ad_b0::Pads,
pub gpio_ad_b1: gpio_ad_b1::Pads,
pub gpio_b0: gpio_b0::Pads,
pub gpio_b1: gpio_b1::Pads,
pub gpio_sd_b0: gpio_sd_b0::Pads,
pub gpio_sd_b1: gpio_sd_b1::Pads,
}

impl Pads {
/// Take all pads from this group
///
/// # Safety
///
/// You may safely call this once to acquire all of the pads.
/// Subsequent calls may return pads that are mutably aliased
/// elsewhere. Consider calling new() at the start of your program.
#[inline]
pub const unsafe fn new() -> Self {
Self {
gpio_emc: gpio_emc::Pads::new(),
gpio_ad_b0: gpio_ad_b0::Pads::new(),
gpio_ad_b1: gpio_ad_b1::Pads::new(),
gpio_b0: gpio_b0::Pads::new(),
gpio_b1: gpio_b1::Pads::new(),
gpio_sd_b0: gpio_sd_b0::Pads::new(),
gpio_sd_b1: gpio_sd_b1::Pads::new(),
}
}

/// Erase all of the pads
///
/// The return type is an array, where the index indicates the
/// pad offset from the start of the group. For example, AD_B0_03
/// would be referenced as erased_pads\[3\].
///
/// See `ErasedPads` for more information.
#[inline]
pub const fn erase(self) -> ErasedPads {
ErasedPads {
gpio_emc: self.gpio_emc.erase(),
gpio_ad_b0: self.gpio_ad_b0.erase(),
gpio_ad_b1: self.gpio_ad_b1.erase(),
gpio_b0: self.gpio_b0.erase(),
gpio_b1: self.gpio_b1.erase(),
gpio_sd_b0: self.gpio_sd_b0.erase(),
gpio_sd_b1: self.gpio_sd_b1.erase(),
}
}
}

/// All erased pads.
pub struct ErasedPads {
pub gpio_emc: gpio_emc::ErasedPads,
pub gpio_ad_b0: gpio_ad_b0::ErasedPads,
pub gpio_ad_b1: gpio_ad_b1::ErasedPads,
pub gpio_b0: gpio_b0::ErasedPads,
pub gpio_b1: gpio_b1::ErasedPads,
pub gpio_sd_b0: gpio_sd_b0::ErasedPads,
pub gpio_sd_b1: gpio_sd_b1::ErasedPads,
}
49 changes: 0 additions & 49 deletions src/imxrt1060/adc.rs

This file was deleted.

54 changes: 0 additions & 54 deletions src/imxrt1060/flexcan.rs

This file was deleted.

Loading

0 comments on commit a5d7f77

Please sign in to comment.