ambiq_hal/
lib.rs

1#![allow(incomplete_features)]
2#![feature(adt_const_params)]
3#![feature(never_type)]
4#![cfg_attr(not(test), no_std)]
5
6extern crate cortex_m;
7
8pub extern crate embedded_hal as hal;
9pub extern crate ambiq_apollo3_pac2 as pac;
10
11#[cfg(feature = "rt")]
12#[cortex_m_rt::pre_init]
13unsafe fn pre_init() {
14    // The sparkfun bootloader does not update the VTOR to point to our programs
15    // interrupt vector.
16    //
17    // The Ambiq Secure bootloader requires magic bytes to be set before it loads the
18    // Sparkfun Variable Bootloader at 0xC000, so we can't just replace it.
19    //
20    // The Sparkfun bootloader loads our program from 0x10000. In the arduino hal the
21    // `startup_gcc.c` runtime updates the VTOR, but ideally this should have been done
22    // in the bootloader to be a bit more robust.
23    //
24    // If someone re-defines the `pre_init` interrupts will stop working. Pretty sure
25    // that wouldn't compile anyway.
26    //
27    //
28    // https://github.com/sparkfun/Apollo3_Uploader_SVL/issues/7
29    (*cortex_m::peripheral::SCB::PTR).vtor.write(0x10000);
30}
31
32
33#[cfg(feature = "ambiq-sdk")]
34pub extern crate ambiq_hal_sys as halc;
35
36pub mod clock;
37pub mod rtc;
38pub mod time;
39pub mod delay;
40pub mod gpio;
41pub mod adc;
42pub mod watchdog;
43
44#[cfg(feature = "ambiq-sdk")]
45pub mod uart;
46
47#[cfg(feature = "ambiq-sdk")]
48pub mod iom;
49#[cfg(feature = "ambiq-sdk")]
50pub use iom::{i2c, spi};
51
52pub mod prelude {
53    pub use hal::prelude::*;
54    pub use hal::digital::v2::{InputPin, OutputPin, ToggleableOutputPin};
55
56    #[cfg(feature = "ambiq-sdk")]
57    pub use halc;
58
59    #[cfg(feature = "ambiq-sdk")]
60    pub use halc::c_types::*;
61}
62
63#[cfg(test)]
64mod tests {
65    #[test]
66    fn it_works() {
67        assert_eq!(2 + 2, 4);
68    }
69}