#nxp #imxrt #gpio-pin #no-std

no-std imxrt-iomuxc-build

Build support for the imxrt-iomuxc crate. Not for general use. Part of the imxrt-rs project.

1 unstable release

0.1.0 Aug 29, 2020

#15 in #imxrt

Download history 37/week @ 2024-03-11 36/week @ 2024-03-18 41/week @ 2024-03-25 65/week @ 2024-04-01 31/week @ 2024-04-08 38/week @ 2024-04-15 39/week @ 2024-04-22 25/week @ 2024-04-29 34/week @ 2024-05-06 29/week @ 2024-05-13 43/week @ 2024-05-20 28/week @ 2024-05-27 31/week @ 2024-06-03 21/week @ 2024-06-10 37/week @ 2024-06-17 30/week @ 2024-06-24

124 downloads per month

MIT/Apache

19KB
250 lines

Build script support for the imxrt-iomuxc crate

Audience

This crate is intended for i.MX RT IOMUXC crate developers. End users should not use this crate directly.

Generate type aliases

Create type aliases for processor pads. Use a combination of PadRange and write_pads() in a build script to generate your module. Then, include! it in your crate.

For example, a build.rs build script resembling

// ~~ build.rs ~~
use imxrt_iomuxc_build as build;
use std::{env, fs, io, path::PathBuf};

fn main() -> io::Result<()> {
    let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
    let mut pads_rs = fs::File::create(out_dir.join("pads.rs"))?;

    let emc = build::PadRange::new("EMC", 0..42);
    let ad_b0 = build::PadRange::new("AD_B0", 0..16);
    let ad_b1 = build::PadRange::new("AD_B1", 0..16);
    let b0 = build::PadRange::new("B0", 0..16);
    let b1 = build::PadRange::new("B1", 0..16);
    let sd_b0 = build::PadRange::new("SD_B0", 0..6);
    let sd_b1 = build::PadRange::new("SD_B1", 0..12);

    build::write_pads(
        &mut pads_rs,
        vec![&emc, &ad_b0, &ad_b1, &b0, &b1, &sd_b0, &sd_b1],
    )?;
    Ok(())
}

would generate type aliases that could be included in your lib.rs

// ~~ lib.rs ~~
include!(concat!(env!("OUT_DIR"), "/pads.rs"));

See the write_pads() function for details on the generated module.

Implement GPIO Pin traits

For the type aliases created in crate type aliases, you can implement GPIO Pin traits by using ImplGpioPin and write_impl_gpio_pins().

build::write_impl_gpio_pins(
    &mut pads_rs,
    vec![
        // GPIO1
        build::ImplGpioPin::from_range(&ad_b0, build::GpioRange::no_offset(1, 5)),
        build::ImplGpioPin::from_range(&ad_b1, build::GpioRange {
            module: 1,
            offset: 16,
            alt: 5,
        }),
        // GPIO2
        build::ImplGpioPin::from_range(&b0, build::GpioRange::no_offset(2, 5)),
        build::ImplGpioPin::from_range(&b1, build::GpioRange {
            module: 2,
            offset: 16,
            alt: 5,
        }),
    ],
).unwrap();

Dependencies

~83KB