diff options
| author | Emil Fresk <[email protected]> | 2023-04-26 20:03:43 +0200 |
|---|---|---|
| committer | Emil Fresk <[email protected]> | 2023-04-26 21:24:50 +0200 |
| commit | f8b359dc5ade1e3961b0534941ee2cf3756e09d8 (patch) | |
| tree | 2d62acd696010218e690cf3519cf1b7511d96c89 /embassy-nrf | |
| parent | deadf40c85721db3a16473040c5f17ffd0ca3ac8 (diff) | |
Add support for setting up the nRFs internal DCDCs
Diffstat (limited to 'embassy-nrf')
| -rw-r--r-- | embassy-nrf/src/lib.rs | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs index 8defc551b..6e7aaa57a 100644 --- a/embassy-nrf/src/lib.rs +++ b/embassy-nrf/src/lib.rs | |||
| @@ -184,6 +184,34 @@ pub mod config { | |||
| 184 | NotConfigured, | 184 | NotConfigured, |
| 185 | } | 185 | } |
| 186 | 186 | ||
| 187 | /// Settings for enabling the built in DCDC converters. | ||
| 188 | #[cfg(not(any(feature = "_nrf5340", feature = "_nrf9160")))] | ||
| 189 | pub struct DcdcConfig { | ||
| 190 | /// Config for the first stage DCDC (VDDH -> VDD), if disabled LDO will be used. | ||
| 191 | #[cfg(feature = "nrf52840")] | ||
| 192 | pub reg0: bool, | ||
| 193 | /// Config for the second stage DCDC (VDD -> DEC4), if disabled LDO will be used. | ||
| 194 | pub reg1: bool, | ||
| 195 | } | ||
| 196 | |||
| 197 | /// Settings for enabling the built in DCDC converters. | ||
| 198 | #[cfg(feature = "_nrf5340-app")] | ||
| 199 | pub struct DcdcConfig { | ||
| 200 | /// Config for the high voltage stage, if disabled LDO will be used. | ||
| 201 | pub regh: bool, | ||
| 202 | /// Config for the main rail, if disabled LDO will be used. | ||
| 203 | pub regmain: bool, | ||
| 204 | /// Config for the radio rail, if disabled LDO will be used. | ||
| 205 | pub regradio: bool, | ||
| 206 | } | ||
| 207 | |||
| 208 | /// Settings for enabling the built in DCDC converter. | ||
| 209 | #[cfg(feature = "_nrf9160")] | ||
| 210 | pub struct DcdcConfig { | ||
| 211 | /// Config for the main rail, if disabled LDO will be used. | ||
| 212 | pub regmain: bool, | ||
| 213 | } | ||
| 214 | |||
| 187 | /// Configuration for peripherals. Default configuration should work on any nRF chip. | 215 | /// Configuration for peripherals. Default configuration should work on any nRF chip. |
| 188 | #[non_exhaustive] | 216 | #[non_exhaustive] |
| 189 | pub struct Config { | 217 | pub struct Config { |
| @@ -191,6 +219,9 @@ pub mod config { | |||
| 191 | pub hfclk_source: HfclkSource, | 219 | pub hfclk_source: HfclkSource, |
| 192 | /// Low frequency clock source. | 220 | /// Low frequency clock source. |
| 193 | pub lfclk_source: LfclkSource, | 221 | pub lfclk_source: LfclkSource, |
| 222 | #[cfg(not(feature = "_nrf5340-net"))] | ||
| 223 | /// DCDC configuration. | ||
| 224 | pub dcdc: DcdcConfig, | ||
| 194 | /// GPIOTE interrupt priority. Should be lower priority than softdevice if used. | 225 | /// GPIOTE interrupt priority. Should be lower priority than softdevice if used. |
| 195 | #[cfg(feature = "gpiote")] | 226 | #[cfg(feature = "gpiote")] |
| 196 | pub gpiote_interrupt_priority: crate::interrupt::Priority, | 227 | pub gpiote_interrupt_priority: crate::interrupt::Priority, |
| @@ -209,6 +240,20 @@ pub mod config { | |||
| 209 | // xtals if they know they have them. | 240 | // xtals if they know they have them. |
| 210 | hfclk_source: HfclkSource::Internal, | 241 | hfclk_source: HfclkSource::Internal, |
| 211 | lfclk_source: LfclkSource::InternalRC, | 242 | lfclk_source: LfclkSource::InternalRC, |
| 243 | #[cfg(not(any(feature = "_nrf5340", feature = "_nrf9160")))] | ||
| 244 | dcdc: DcdcConfig { | ||
| 245 | #[cfg(feature = "nrf52840")] | ||
| 246 | reg0: false, | ||
| 247 | reg1: false, | ||
| 248 | }, | ||
| 249 | #[cfg(feature = "_nrf5340-app")] | ||
| 250 | dcdc: DcdcConfig { | ||
| 251 | regh: false, | ||
| 252 | regmain: false, | ||
| 253 | regradio: false, | ||
| 254 | }, | ||
| 255 | #[cfg(feature = "_nrf9160")] | ||
| 256 | dcdc: DcdcConfig { regmain: false }, | ||
| 212 | #[cfg(feature = "gpiote")] | 257 | #[cfg(feature = "gpiote")] |
| 213 | gpiote_interrupt_priority: crate::interrupt::Priority::P0, | 258 | gpiote_interrupt_priority: crate::interrupt::Priority::P0, |
| 214 | #[cfg(feature = "_time-driver")] | 259 | #[cfg(feature = "_time-driver")] |
| @@ -454,6 +499,41 @@ pub fn init(config: config::Config) -> Peripherals { | |||
| 454 | r.tasks_lfclkstart.write(|w| unsafe { w.bits(1) }); | 499 | r.tasks_lfclkstart.write(|w| unsafe { w.bits(1) }); |
| 455 | while r.events_lfclkstarted.read().bits() == 0 {} | 500 | while r.events_lfclkstarted.read().bits() == 0 {} |
| 456 | 501 | ||
| 502 | #[cfg(not(any(feature = "_nrf5340", feature = "_nrf9160")))] | ||
| 503 | { | ||
| 504 | // Setup DCDCs. | ||
| 505 | let pwr = unsafe { &*pac::POWER::ptr() }; | ||
| 506 | #[cfg(feature = "nrf52840")] | ||
| 507 | if config.dcdc.reg0 { | ||
| 508 | pwr.dcdcen0.write(|w| w.dcdcen().set_bit()); | ||
| 509 | } | ||
| 510 | if config.dcdc.reg1 { | ||
| 511 | pwr.dcdcen.write(|w| w.dcdcen().set_bit()); | ||
| 512 | } | ||
| 513 | } | ||
| 514 | #[cfg(feature = "_nrf9160")] | ||
| 515 | { | ||
| 516 | // Setup DCDC. | ||
| 517 | let reg = unsafe { &*pac::REGULATORS::ptr() }; | ||
| 518 | if config.dcdc.regmain { | ||
| 519 | reg.dcdcen.write(|w| w.dcdcen().set_bit()); | ||
| 520 | } | ||
| 521 | } | ||
| 522 | #[cfg(feature = "_nrf5340-app")] | ||
| 523 | { | ||
| 524 | // Setup DCDC. | ||
| 525 | let reg = unsafe { &*pac::REGULATORS::ptr() }; | ||
| 526 | if config.dcdc.regh { | ||
| 527 | reg.vregh.dcdcen.write(|w| w.dcdcen().set_bit()); | ||
| 528 | } | ||
| 529 | if config.dcdc.regmain { | ||
| 530 | reg.vregmain.dcdcen.write(|w| w.dcdcen().set_bit()); | ||
| 531 | } | ||
| 532 | if config.dcdc.regradio { | ||
| 533 | reg.vregradio.dcdcen.write(|w| w.dcdcen().set_bit()); | ||
| 534 | } | ||
| 535 | } | ||
| 536 | |||
| 457 | // Init GPIOTE | 537 | // Init GPIOTE |
| 458 | #[cfg(feature = "gpiote")] | 538 | #[cfg(feature = "gpiote")] |
| 459 | gpiote::init(config.gpiote_interrupt_priority); | 539 | gpiote::init(config.gpiote_interrupt_priority); |
