diff options
Diffstat (limited to 'embassy-mspm0/src/lib.rs')
| -rw-r--r-- | embassy-mspm0/src/lib.rs | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/embassy-mspm0/src/lib.rs b/embassy-mspm0/src/lib.rs new file mode 100644 index 000000000..ee629f063 --- /dev/null +++ b/embassy-mspm0/src/lib.rs | |||
| @@ -0,0 +1,112 @@ | |||
| 1 | #![no_std] | ||
| 2 | // Doc feature labels can be tested locally by running RUSTDOCFLAGS="--cfg=docsrs" cargo +nightly doc | ||
| 3 | #![cfg_attr( | ||
| 4 | docsrs, | ||
| 5 | feature(doc_auto_cfg, doc_cfg_hide), | ||
| 6 | doc(cfg_hide(doc, docsrs)) | ||
| 7 | )] | ||
| 8 | |||
| 9 | // This mod MUST go first, so that the others see its macros. | ||
| 10 | pub(crate) mod fmt; | ||
| 11 | |||
| 12 | pub mod gpio; | ||
| 13 | pub mod timer; | ||
| 14 | |||
| 15 | #[cfg(feature = "_time-driver")] | ||
| 16 | mod time_driver; | ||
| 17 | |||
| 18 | // Interrupt group handlers. | ||
| 19 | #[cfg_attr(feature = "mspm0c110x", path = "int_group/c110x.rs")] | ||
| 20 | #[cfg_attr(feature = "mspm0g110x", path = "int_group/g110x.rs")] | ||
| 21 | #[cfg_attr(feature = "mspm0g150x", path = "int_group/g150x.rs")] | ||
| 22 | #[cfg_attr(feature = "mspm0g151x", path = "int_group/g151x.rs")] | ||
| 23 | #[cfg_attr(feature = "mspm0g310x", path = "int_group/g310x.rs")] | ||
| 24 | #[cfg_attr(feature = "mspm0g350x", path = "int_group/g350x.rs")] | ||
| 25 | #[cfg_attr(feature = "mspm0g351x", path = "int_group/g351x.rs")] | ||
| 26 | #[cfg_attr(feature = "mspm0l110x", path = "int_group/l110x.rs")] | ||
| 27 | #[cfg_attr(feature = "mspm0l122x", path = "int_group/l122x.rs")] | ||
| 28 | #[cfg_attr(feature = "mspm0l130x", path = "int_group/l130x.rs")] | ||
| 29 | #[cfg_attr(feature = "mspm0l134x", path = "int_group/l134x.rs")] | ||
| 30 | #[cfg_attr(feature = "mspm0l222x", path = "int_group/l222x.rs")] | ||
| 31 | mod int_group; | ||
| 32 | |||
| 33 | pub(crate) mod _generated { | ||
| 34 | #![allow(dead_code)] | ||
| 35 | #![allow(unused_imports)] | ||
| 36 | #![allow(non_snake_case)] | ||
| 37 | #![allow(missing_docs)] | ||
| 38 | |||
| 39 | include!(concat!(env!("OUT_DIR"), "/_generated.rs")); | ||
| 40 | } | ||
| 41 | |||
| 42 | // Reexports | ||
| 43 | pub use _generated::{peripherals, Peripherals}; | ||
| 44 | pub use embassy_hal_internal::{into_ref, Peripheral, PeripheralRef}; | ||
| 45 | #[cfg(feature = "unstable-pac")] | ||
| 46 | pub use mspm0_metapac as pac; | ||
| 47 | #[cfg(not(feature = "unstable-pac"))] | ||
| 48 | pub(crate) use mspm0_metapac as pac; | ||
| 49 | |||
| 50 | pub use crate::_generated::interrupt; | ||
| 51 | pub(crate) use _generated::gpio_pincm; | ||
| 52 | |||
| 53 | |||
| 54 | /// `embassy-mspm0` global configuration. | ||
| 55 | #[non_exhaustive] | ||
| 56 | #[derive(Clone, Copy)] | ||
| 57 | pub struct Config { | ||
| 58 | // TODO | ||
| 59 | } | ||
| 60 | |||
| 61 | impl Default for Config { | ||
| 62 | fn default() -> Self { | ||
| 63 | Self { | ||
| 64 | // TODO | ||
| 65 | } | ||
| 66 | } | ||
| 67 | } | ||
| 68 | |||
| 69 | pub fn init(_config: Config) -> Peripherals { | ||
| 70 | critical_section::with(|cs| { | ||
| 71 | let peripherals = Peripherals::take_with_cs(cs); | ||
| 72 | |||
| 73 | // TODO: Further clock configuration | ||
| 74 | |||
| 75 | pac::SYSCTL.mclkcfg().modify(|w| { | ||
| 76 | // Enable MFCLK | ||
| 77 | w.set_usemftick(true); | ||
| 78 | // MDIV must be disabled if MFCLK is enabled. | ||
| 79 | w.set_mdiv(0); | ||
| 80 | }); | ||
| 81 | |||
| 82 | // Enable MFCLK for peripheral use | ||
| 83 | // | ||
| 84 | // TODO: Optional? | ||
| 85 | pac::SYSCTL.genclken().modify(|w| { | ||
| 86 | w.set_mfpclken(true); | ||
| 87 | }); | ||
| 88 | |||
| 89 | pac::SYSCTL.borthreshold().modify(|w| { | ||
| 90 | w.set_level(0); | ||
| 91 | }); | ||
| 92 | |||
| 93 | gpio::init(pac::GPIOA); | ||
| 94 | #[cfg(gpio_pb)] | ||
| 95 | gpio::init(pac::GPIOB); | ||
| 96 | #[cfg(gpio_pc)] | ||
| 97 | gpio::init(pac::GPIOC); | ||
| 98 | |||
| 99 | _generated::enable_group_interrupts(cs); | ||
| 100 | |||
| 101 | #[cfg(feature = "mspm0c110x")] | ||
| 102 | unsafe { | ||
| 103 | use crate::_generated::interrupt::typelevel::Interrupt; | ||
| 104 | crate::interrupt::typelevel::GPIOA::enable(); | ||
| 105 | } | ||
| 106 | |||
| 107 | #[cfg(feature = "_time-driver")] | ||
| 108 | time_driver::init(cs); | ||
| 109 | |||
| 110 | peripherals | ||
| 111 | }) | ||
| 112 | } | ||
