diff options
| author | nerwalt <[email protected]> | 2024-07-15 13:21:30 -0600 |
|---|---|---|
| committer | nerwalt <[email protected]> | 2024-07-15 13:21:30 -0600 |
| commit | 8a6cb98e45c45743bc8c8a2b678067d3e1660232 (patch) | |
| tree | 2cbbb8741539d7b180325f5c78095906ff93ca20 /embassy-nrf/src/lib.rs | |
| parent | 4340d74e19bb99e2afdfb97232e8556aca7584b4 (diff) | |
Adding _nrf91 feature
Combining _nrf9160 and _nrf9120 in many places to reduce cfgs
Diffstat (limited to 'embassy-nrf/src/lib.rs')
| -rw-r--r-- | embassy-nrf/src/lib.rs | 65 |
1 files changed, 44 insertions, 21 deletions
diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs index 15d2e65b2..75cdb34b6 100644 --- a/embassy-nrf/src/lib.rs +++ b/embassy-nrf/src/lib.rs | |||
| @@ -26,8 +26,32 @@ | |||
| 26 | feature = "nrf9160-ns", | 26 | feature = "nrf9160-ns", |
| 27 | feature = "nrf9120-s", | 27 | feature = "nrf9120-s", |
| 28 | feature = "nrf9120-ns", | 28 | feature = "nrf9120-ns", |
| 29 | feature = "nrf9151-s", | ||
| 30 | feature = "nrf9151-ns", | ||
| 31 | feature = "nrf9161-s", | ||
| 32 | feature = "nrf9161-ns", | ||
| 29 | )))] | 33 | )))] |
| 30 | compile_error!("No chip feature activated. You must activate exactly one of the following features: nrf52810, nrf52811, nrf52832, nrf52833, nrf52840"); | 34 | compile_error!("No chip feature activated. You must activate exactly one of the following features: |
| 35 | nrf51, | ||
| 36 | nrf52805, | ||
| 37 | nrf52810, | ||
| 38 | nrf52811, | ||
| 39 | nrf52820, | ||
| 40 | nrf52832, | ||
| 41 | nrf52833, | ||
| 42 | nrf52840, | ||
| 43 | nrf5340-app-s, | ||
| 44 | nrf5340-app-ns, | ||
| 45 | nrf5340-net, | ||
| 46 | nrf9160-s, | ||
| 47 | nrf9160-ns, | ||
| 48 | nrf9120-s, | ||
| 49 | nrf9120-ns, | ||
| 50 | nrf9151-s, | ||
| 51 | nrf9151-ns, | ||
| 52 | nrf9161-s, | ||
| 53 | nrf9161-ns, | ||
| 54 | "); | ||
| 31 | 55 | ||
| 32 | #[cfg(all(feature = "reset-pin-as-gpio", not(feature = "_nrf52")))] | 56 | #[cfg(all(feature = "reset-pin-as-gpio", not(feature = "_nrf52")))] |
| 33 | compile_error!("feature `reset-pin-as-gpio` is only valid for nRF52 series chips."); | 57 | compile_error!("feature `reset-pin-as-gpio` is only valid for nRF52 series chips."); |
| @@ -49,7 +73,7 @@ pub mod gpio; | |||
| 49 | pub mod gpiote; | 73 | pub mod gpiote; |
| 50 | 74 | ||
| 51 | // TODO: tested on other chips | 75 | // TODO: tested on other chips |
| 52 | #[cfg(not(any(feature = "_nrf9160", feature = "_nrf9120", feature = "_nrf5340-app")))] | 76 | #[cfg(not(any(feature = "_nrf91", feature = "_nrf5340-app")))] |
| 53 | pub mod radio; | 77 | pub mod radio; |
| 54 | 78 | ||
| 55 | #[cfg(not(feature = "nrf51"))] | 79 | #[cfg(not(feature = "nrf51"))] |
| @@ -64,8 +88,7 @@ pub mod nvmc; | |||
| 64 | feature = "nrf52833", | 88 | feature = "nrf52833", |
| 65 | feature = "nrf52840", | 89 | feature = "nrf52840", |
| 66 | feature = "_nrf5340-app", | 90 | feature = "_nrf5340-app", |
| 67 | feature = "_nrf9160", | 91 | feature = "_nrf91", |
| 68 | feature = "_nrf9120" | ||
| 69 | ))] | 92 | ))] |
| 70 | pub mod pdm; | 93 | pub mod pdm; |
| 71 | pub mod ppi; | 94 | pub mod ppi; |
| @@ -76,11 +99,11 @@ pub mod ppi; | |||
| 76 | feature = "_nrf5340-net" | 99 | feature = "_nrf5340-net" |
| 77 | )))] | 100 | )))] |
| 78 | pub mod pwm; | 101 | pub mod pwm; |
| 79 | #[cfg(not(any(feature = "nrf51", feature = "_nrf9160", feature = "_nrf9120", feature = "_nrf5340-net")))] | 102 | #[cfg(not(any(feature = "nrf51", feature = "_nrf91", feature = "_nrf5340-net")))] |
| 80 | pub mod qdec; | 103 | pub mod qdec; |
| 81 | #[cfg(any(feature = "nrf52840", feature = "_nrf5340-app"))] | 104 | #[cfg(any(feature = "nrf52840", feature = "_nrf5340-app"))] |
| 82 | pub mod qspi; | 105 | pub mod qspi; |
| 83 | #[cfg(not(any(feature = "_nrf5340-app", feature = "_nrf9160", feature = "_nrf9120")))] | 106 | #[cfg(not(any(feature = "_nrf5340-app", feature = "_nrf91")))] |
| 84 | pub mod rng; | 107 | pub mod rng; |
| 85 | #[cfg(not(any(feature = "nrf51", feature = "nrf52820", feature = "_nrf5340-net")))] | 108 | #[cfg(not(any(feature = "nrf51", feature = "nrf52820", feature = "_nrf5340-net")))] |
| 86 | pub mod saadc; | 109 | pub mod saadc; |
| @@ -88,7 +111,7 @@ pub mod saadc; | |||
| 88 | pub mod spim; | 111 | pub mod spim; |
| 89 | #[cfg(not(feature = "nrf51"))] | 112 | #[cfg(not(feature = "nrf51"))] |
| 90 | pub mod spis; | 113 | pub mod spis; |
| 91 | #[cfg(not(any(feature = "_nrf5340", feature = "_nrf9160", feature = "_nrf9120")))] | 114 | #[cfg(not(any(feature = "_nrf5340", feature = "_nrf91")))] |
| 92 | pub mod temp; | 115 | pub mod temp; |
| 93 | pub mod timer; | 116 | pub mod timer; |
| 94 | #[cfg(not(feature = "nrf51"))] | 117 | #[cfg(not(feature = "nrf51"))] |
| @@ -200,15 +223,15 @@ pub mod config { | |||
| 200 | /// Internal RC oscillator | 223 | /// Internal RC oscillator |
| 201 | InternalRC, | 224 | InternalRC, |
| 202 | /// Synthesized from the high frequency clock source. | 225 | /// Synthesized from the high frequency clock source. |
| 203 | #[cfg(not(any(feature = "_nrf5340", feature = "_nrf9160", feature = "_nrf9120")))] | 226 | #[cfg(not(any(feature = "_nrf5340", feature = "_nrf91")))] |
| 204 | Synthesized, | 227 | Synthesized, |
| 205 | /// External source from xtal. | 228 | /// External source from xtal. |
| 206 | ExternalXtal, | 229 | ExternalXtal, |
| 207 | /// External source from xtal with low swing applied. | 230 | /// External source from xtal with low swing applied. |
| 208 | #[cfg(not(any(feature = "_nrf5340", feature = "_nrf9160", feature = "_nrf9120")))] | 231 | #[cfg(not(any(feature = "_nrf5340", feature = "_nrf91")))] |
| 209 | ExternalLowSwing, | 232 | ExternalLowSwing, |
| 210 | /// External source from xtal with full swing applied. | 233 | /// External source from xtal with full swing applied. |
| 211 | #[cfg(not(any(feature = "_nrf5340", feature = "_nrf9160", feature = "_nrf9120")))] | 234 | #[cfg(not(any(feature = "_nrf5340", feature = "_nrf91")))] |
| 212 | ExternalFullSwing, | 235 | ExternalFullSwing, |
| 213 | } | 236 | } |
| 214 | 237 | ||
| @@ -226,7 +249,7 @@ pub mod config { | |||
| 226 | } | 249 | } |
| 227 | 250 | ||
| 228 | /// Settings for enabling the built in DCDC converters. | 251 | /// Settings for enabling the built in DCDC converters. |
| 229 | #[cfg(not(any(feature = "_nrf5340", feature = "_nrf9160", feature = "_nrf9120")))] | 252 | #[cfg(not(any(feature = "_nrf5340", feature = "_nrf91")))] |
| 230 | pub struct DcdcConfig { | 253 | pub struct DcdcConfig { |
| 231 | /// Config for the first stage DCDC (VDDH -> VDD), if disabled LDO will be used. | 254 | /// Config for the first stage DCDC (VDDH -> VDD), if disabled LDO will be used. |
| 232 | #[cfg(feature = "nrf52840")] | 255 | #[cfg(feature = "nrf52840")] |
| @@ -268,7 +291,7 @@ pub mod config { | |||
| 268 | } | 291 | } |
| 269 | 292 | ||
| 270 | /// Settings for enabling the built in DCDC converter. | 293 | /// Settings for enabling the built in DCDC converter. |
| 271 | #[cfg(any(feature = "_nrf9160", feature = "_nrf9120"))] | 294 | #[cfg(feature = "_nrf91")] |
| 272 | pub struct DcdcConfig { | 295 | pub struct DcdcConfig { |
| 273 | /// Config for the main rail, if disabled LDO will be used. | 296 | /// Config for the main rail, if disabled LDO will be used. |
| 274 | pub regmain: bool, | 297 | pub regmain: bool, |
| @@ -302,7 +325,7 @@ pub mod config { | |||
| 302 | // xtals if they know they have them. | 325 | // xtals if they know they have them. |
| 303 | hfclk_source: HfclkSource::Internal, | 326 | hfclk_source: HfclkSource::Internal, |
| 304 | lfclk_source: LfclkSource::InternalRC, | 327 | lfclk_source: LfclkSource::InternalRC, |
| 305 | #[cfg(not(any(feature = "_nrf5340", feature = "_nrf9160", feature = "_nrf9120")))] | 328 | #[cfg(not(any(feature = "_nrf5340", feature = "_nrf91")))] |
| 306 | dcdc: DcdcConfig { | 329 | dcdc: DcdcConfig { |
| 307 | #[cfg(feature = "nrf52840")] | 330 | #[cfg(feature = "nrf52840")] |
| 308 | reg0: false, | 331 | reg0: false, |
| @@ -316,7 +339,7 @@ pub mod config { | |||
| 316 | regmain: false, | 339 | regmain: false, |
| 317 | regradio: false, | 340 | regradio: false, |
| 318 | }, | 341 | }, |
| 319 | #[cfg(any(feature = "_nrf9160", feature = "_nrf9120"))] | 342 | #[cfg(feature = "_nrf91")] |
| 320 | dcdc: DcdcConfig { regmain: false }, | 343 | dcdc: DcdcConfig { regmain: false }, |
| 321 | #[cfg(feature = "gpiote")] | 344 | #[cfg(feature = "gpiote")] |
| 322 | gpiote_interrupt_priority: crate::interrupt::Priority::P0, | 345 | gpiote_interrupt_priority: crate::interrupt::Priority::P0, |
| @@ -333,7 +356,7 @@ pub mod config { | |||
| 333 | } | 356 | } |
| 334 | } | 357 | } |
| 335 | 358 | ||
| 336 | #[cfg(any(feature = "_nrf9160", feature = "_nrf9120"))] | 359 | #[cfg(feature = "_nrf91")] |
| 337 | #[allow(unused)] | 360 | #[allow(unused)] |
| 338 | mod consts { | 361 | mod consts { |
| 339 | pub const UICR_APPROTECT: *mut u32 = 0x00FF8000 as *mut u32; | 362 | pub const UICR_APPROTECT: *mut u32 = 0x00FF8000 as *mut u32; |
| @@ -472,7 +495,7 @@ pub fn init(config: config::Config) -> Peripherals { | |||
| 472 | // UICR.APPROTECT = Enabled | 495 | // UICR.APPROTECT = Enabled |
| 473 | let res = uicr_write(consts::UICR_APPROTECT, consts::APPROTECT_ENABLED); | 496 | let res = uicr_write(consts::UICR_APPROTECT, consts::APPROTECT_ENABLED); |
| 474 | needs_reset |= res == WriteResult::Written; | 497 | needs_reset |= res == WriteResult::Written; |
| 475 | #[cfg(any(feature = "_nrf5340-app", feature = "_nrf9160", feature = "_nrf9120"))] | 498 | #[cfg(any(feature = "_nrf5340-app", feature = "_nrf91"))] |
| 476 | { | 499 | { |
| 477 | let res = uicr_write(consts::UICR_SECUREAPPROTECT, consts::APPROTECT_ENABLED); | 500 | let res = uicr_write(consts::UICR_SECUREAPPROTECT, consts::APPROTECT_ENABLED); |
| 478 | needs_reset |= res == WriteResult::Written; | 501 | needs_reset |= res == WriteResult::Written; |
| @@ -556,7 +579,7 @@ pub fn init(config: config::Config) -> Peripherals { | |||
| 556 | } | 579 | } |
| 557 | 580 | ||
| 558 | // Configure LFCLK. | 581 | // Configure LFCLK. |
| 559 | #[cfg(not(any(feature = "nrf51", feature = "_nrf5340", feature = "_nrf9160", feature = "_nrf9120")))] | 582 | #[cfg(not(any(feature = "nrf51", feature = "_nrf5340", feature = "_nrf91")))] |
| 560 | match config.lfclk_source { | 583 | match config.lfclk_source { |
| 561 | config::LfclkSource::InternalRC => r.lfclksrc.write(|w| w.src().rc()), | 584 | config::LfclkSource::InternalRC => r.lfclksrc.write(|w| w.src().rc()), |
| 562 | config::LfclkSource::Synthesized => r.lfclksrc.write(|w| w.src().synth()), | 585 | config::LfclkSource::Synthesized => r.lfclksrc.write(|w| w.src().synth()), |
| @@ -576,7 +599,7 @@ pub fn init(config: config::Config) -> Peripherals { | |||
| 576 | w | 599 | w |
| 577 | }), | 600 | }), |
| 578 | } | 601 | } |
| 579 | #[cfg(any(feature = "_nrf9160", feature = "_nrf9120"))] | 602 | #[cfg(feature = "_nrf91")] |
| 580 | match config.lfclk_source { | 603 | match config.lfclk_source { |
| 581 | config::LfclkSource::InternalRC => r.lfclksrc.write(|w| w.src().lfrc()), | 604 | config::LfclkSource::InternalRC => r.lfclksrc.write(|w| w.src().lfrc()), |
| 582 | config::LfclkSource::ExternalXtal => r.lfclksrc.write(|w| w.src().lfxo()), | 605 | config::LfclkSource::ExternalXtal => r.lfclksrc.write(|w| w.src().lfxo()), |
| @@ -589,7 +612,7 @@ pub fn init(config: config::Config) -> Peripherals { | |||
| 589 | r.tasks_lfclkstart.write(|w| unsafe { w.bits(1) }); | 612 | r.tasks_lfclkstart.write(|w| unsafe { w.bits(1) }); |
| 590 | while r.events_lfclkstarted.read().bits() == 0 {} | 613 | while r.events_lfclkstarted.read().bits() == 0 {} |
| 591 | 614 | ||
| 592 | #[cfg(not(any(feature = "_nrf5340", feature = "_nrf9160", feature = "_nrf9120")))] | 615 | #[cfg(not(any(feature = "_nrf5340", feature = "_nrf91")))] |
| 593 | { | 616 | { |
| 594 | // Setup DCDCs. | 617 | // Setup DCDCs. |
| 595 | let pwr = unsafe { &*pac::POWER::ptr() }; | 618 | let pwr = unsafe { &*pac::POWER::ptr() }; |
| @@ -601,7 +624,7 @@ pub fn init(config: config::Config) -> Peripherals { | |||
| 601 | pwr.dcdcen.write(|w| w.dcdcen().set_bit()); | 624 | pwr.dcdcen.write(|w| w.dcdcen().set_bit()); |
| 602 | } | 625 | } |
| 603 | } | 626 | } |
| 604 | #[cfg(any(feature = "_nrf9160", feature = "_nrf9120"))] | 627 | #[cfg(feature = "_nrf91")] |
| 605 | { | 628 | { |
| 606 | // Setup DCDC. | 629 | // Setup DCDC. |
| 607 | let reg = unsafe { &*pac::REGULATORS::ptr() }; | 630 | let reg = unsafe { &*pac::REGULATORS::ptr() }; |
| @@ -633,7 +656,7 @@ pub fn init(config: config::Config) -> Peripherals { | |||
| 633 | time_driver::init(config.time_interrupt_priority); | 656 | time_driver::init(config.time_interrupt_priority); |
| 634 | 657 | ||
| 635 | // Disable UARTE (enabled by default for some reason) | 658 | // Disable UARTE (enabled by default for some reason) |
| 636 | #[cfg(any(feature = "_nrf9160", feature = "_nrf9120"))] | 659 | #[cfg(feature = "_nrf91")] |
| 637 | unsafe { | 660 | unsafe { |
| 638 | (*pac::UARTE0::ptr()).enable.write(|w| w.enable().disabled()); | 661 | (*pac::UARTE0::ptr()).enable.write(|w| w.enable().disabled()); |
| 639 | (*pac::UARTE1::ptr()).enable.write(|w| w.enable().disabled()); | 662 | (*pac::UARTE1::ptr()).enable.write(|w| w.enable().disabled()); |
