aboutsummaryrefslogtreecommitdiff
path: root/crates/imxrt/src/lib.rs
blob: 781fc50ddd1886c98e5b5b580f75db234bae45b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// SPDX-License-Identifier: MPL-2.0
// SPDX-FileCopyrightText: Copyright 2025 Ian McIntyre

#![no_std]
#![feature(rustc_private)]
extern crate fusible;

pub use ral_registers::{Instance, modify_reg, read_reg, write_reg};

pub mod ral {
    pub use imxrt_drivers_enet as enet;
    pub use imxrt_drivers_gpio as gpio;
}

pub mod drivers {
    pub mod enet;
    pub mod gpio;

    /// TODO: remove this, use embedded-hal or something else.
    pub trait ToggleOutput: Send + 'static {
        fn toggle(&self);
    }

    /// TODO: remove this, use embedded-hal or something else.
    pub trait BlockingInput: Send + 'static {
        fn block_on_interrupt(&self);
    }
}

/// TODO: A REAL RANDOM NUMBER GENERATOR.
///
/// This is needed by NetX Duo for port allocation.
/// I'm being very lazy and spoofing the required
/// implementation.
#[unsafe(no_mangle)]
pub extern "C" fn rand() -> core::ffi::c_int {
    use core::sync::atomic::{AtomicI32, Ordering};
    static SOME_RANDOM_NUMBER: AtomicI32 = AtomicI32::new(0);
    SOME_RANDOM_NUMBER.fetch_add(1, Ordering::Relaxed)
}