Adding _nrf91 feature

Combining _nrf9160 and _nrf9120 in many places to reduce cfgs
This commit is contained in:
nerwalt 2024-07-15 13:21:30 -06:00
parent 4340d74e19
commit 8a6cb98e45
7 changed files with 67 additions and 44 deletions

View file

@ -97,18 +97,18 @@ nrf5340-app-ns = ["_nrf5340-app", "_ns"]
## nRF5340 network core ## nRF5340 network core
nrf5340-net = ["_nrf5340-net"] nrf5340-net = ["_nrf5340-net"]
## nRF9160 in Secure mode ## nRF9160 in Secure mode
nrf9160-s = ["_nrf9160", "_s"] nrf9160-s = ["_nrf9160", "_s", "_nrf91"]
## nRF9160 in Non-Secure mode ## nRF9160 in Non-Secure mode
nrf9160-ns = ["_nrf9160", "_ns"] nrf9160-ns = ["_nrf9160", "_ns", "_nrf91"]
## The nRF9120 is the internal part number for the nRF9161 and nRF9151. ## The nRF9120 is the internal part number for the nRF9161 and nRF9151.
## nRF9120 in Secure mode ## nRF9120 in Secure mode
nrf9120-s = ["_nrf9120", "_s"] nrf9120-s = ["_nrf9120", "_s", "_nrf91"]
nrf9151-s = ["_nrf9120", "_s"] nrf9151-s = ["_nrf9120", "_s", "_nrf91"]
nrf9161-s = ["_nrf9120", "_s"] nrf9161-s = ["_nrf9120", "_s", "_nrf91"]
## nRF9120 in Non-Secure mode ## nRF9120 in Non-Secure mode
nrf9120-ns = ["_nrf9120", "_ns"] nrf9120-ns = ["_nrf9120", "_ns", "_nrf91"]
nrf9151-ns = ["_nrf9120", "_ns"] nrf9151-ns = ["_nrf9120", "_ns", "_nrf91"]
nrf9161-ns = ["_nrf9120", "_ns"] nrf9161-ns = ["_nrf9120", "_ns", "_nrf91"]
# Features starting with `_` are for internal use only. They're not intended # Features starting with `_` are for internal use only. They're not intended
# to be enabled by other crates, and are not covered by semver guarantees. # to be enabled by other crates, and are not covered by semver guarantees.
@ -120,6 +120,7 @@ _nrf9160 = ["nrf9160-pac", "_dppi"]
_nrf9120 = ["nrf9120-pac", "_dppi"] _nrf9120 = ["nrf9120-pac", "_dppi"]
_nrf52 = ["_ppi"] _nrf52 = ["_ppi"]
_nrf51 = ["_ppi"] _nrf51 = ["_ppi"]
_nrf91 = []
_time-driver = ["dep:embassy-time-driver", "embassy-time-driver?/tick-hz-32_768"] _time-driver = ["dep:embassy-time-driver", "embassy-time-driver?/tick-hz-32_768"]

View file

@ -166,7 +166,6 @@ unsafe fn handle_gpiote_interrupt() {
} }
} }
#[cfg(not(feature = "_nrf51"))] #[cfg(not(feature = "_nrf51"))]
struct BitIter(u32); struct BitIter(u32);

View file

@ -26,8 +26,32 @@
feature = "nrf9160-ns", feature = "nrf9160-ns",
feature = "nrf9120-s", feature = "nrf9120-s",
feature = "nrf9120-ns", feature = "nrf9120-ns",
feature = "nrf9151-s",
feature = "nrf9151-ns",
feature = "nrf9161-s",
feature = "nrf9161-ns",
)))] )))]
compile_error!("No chip feature activated. You must activate exactly one of the following features: nrf52810, nrf52811, nrf52832, nrf52833, nrf52840"); compile_error!("No chip feature activated. You must activate exactly one of the following features:
nrf51,
nrf52805,
nrf52810,
nrf52811,
nrf52820,
nrf52832,
nrf52833,
nrf52840,
nrf5340-app-s,
nrf5340-app-ns,
nrf5340-net,
nrf9160-s,
nrf9160-ns,
nrf9120-s,
nrf9120-ns,
nrf9151-s,
nrf9151-ns,
nrf9161-s,
nrf9161-ns,
");
#[cfg(all(feature = "reset-pin-as-gpio", not(feature = "_nrf52")))] #[cfg(all(feature = "reset-pin-as-gpio", not(feature = "_nrf52")))]
compile_error!("feature `reset-pin-as-gpio` is only valid for nRF52 series chips."); compile_error!("feature `reset-pin-as-gpio` is only valid for nRF52 series chips.");
@ -49,7 +73,7 @@ pub mod gpio;
pub mod gpiote; pub mod gpiote;
// TODO: tested on other chips // TODO: tested on other chips
#[cfg(not(any(feature = "_nrf9160", feature = "_nrf9120", feature = "_nrf5340-app")))] #[cfg(not(any(feature = "_nrf91", feature = "_nrf5340-app")))]
pub mod radio; pub mod radio;
#[cfg(not(feature = "nrf51"))] #[cfg(not(feature = "nrf51"))]
@ -64,8 +88,7 @@ pub mod nvmc;
feature = "nrf52833", feature = "nrf52833",
feature = "nrf52840", feature = "nrf52840",
feature = "_nrf5340-app", feature = "_nrf5340-app",
feature = "_nrf9160", feature = "_nrf91",
feature = "_nrf9120"
))] ))]
pub mod pdm; pub mod pdm;
pub mod ppi; pub mod ppi;
@ -76,11 +99,11 @@ pub mod ppi;
feature = "_nrf5340-net" feature = "_nrf5340-net"
)))] )))]
pub mod pwm; pub mod pwm;
#[cfg(not(any(feature = "nrf51", feature = "_nrf9160", feature = "_nrf9120", feature = "_nrf5340-net")))] #[cfg(not(any(feature = "nrf51", feature = "_nrf91", feature = "_nrf5340-net")))]
pub mod qdec; pub mod qdec;
#[cfg(any(feature = "nrf52840", feature = "_nrf5340-app"))] #[cfg(any(feature = "nrf52840", feature = "_nrf5340-app"))]
pub mod qspi; pub mod qspi;
#[cfg(not(any(feature = "_nrf5340-app", feature = "_nrf9160", feature = "_nrf9120")))] #[cfg(not(any(feature = "_nrf5340-app", feature = "_nrf91")))]
pub mod rng; pub mod rng;
#[cfg(not(any(feature = "nrf51", feature = "nrf52820", feature = "_nrf5340-net")))] #[cfg(not(any(feature = "nrf51", feature = "nrf52820", feature = "_nrf5340-net")))]
pub mod saadc; pub mod saadc;
@ -88,7 +111,7 @@ pub mod saadc;
pub mod spim; pub mod spim;
#[cfg(not(feature = "nrf51"))] #[cfg(not(feature = "nrf51"))]
pub mod spis; pub mod spis;
#[cfg(not(any(feature = "_nrf5340", feature = "_nrf9160", feature = "_nrf9120")))] #[cfg(not(any(feature = "_nrf5340", feature = "_nrf91")))]
pub mod temp; pub mod temp;
pub mod timer; pub mod timer;
#[cfg(not(feature = "nrf51"))] #[cfg(not(feature = "nrf51"))]
@ -200,15 +223,15 @@ pub mod config {
/// Internal RC oscillator /// Internal RC oscillator
InternalRC, InternalRC,
/// Synthesized from the high frequency clock source. /// Synthesized from the high frequency clock source.
#[cfg(not(any(feature = "_nrf5340", feature = "_nrf9160", feature = "_nrf9120")))] #[cfg(not(any(feature = "_nrf5340", feature = "_nrf91")))]
Synthesized, Synthesized,
/// External source from xtal. /// External source from xtal.
ExternalXtal, ExternalXtal,
/// External source from xtal with low swing applied. /// External source from xtal with low swing applied.
#[cfg(not(any(feature = "_nrf5340", feature = "_nrf9160", feature = "_nrf9120")))] #[cfg(not(any(feature = "_nrf5340", feature = "_nrf91")))]
ExternalLowSwing, ExternalLowSwing,
/// External source from xtal with full swing applied. /// External source from xtal with full swing applied.
#[cfg(not(any(feature = "_nrf5340", feature = "_nrf9160", feature = "_nrf9120")))] #[cfg(not(any(feature = "_nrf5340", feature = "_nrf91")))]
ExternalFullSwing, ExternalFullSwing,
} }
@ -226,7 +249,7 @@ pub mod config {
} }
/// Settings for enabling the built in DCDC converters. /// Settings for enabling the built in DCDC converters.
#[cfg(not(any(feature = "_nrf5340", feature = "_nrf9160", feature = "_nrf9120")))] #[cfg(not(any(feature = "_nrf5340", feature = "_nrf91")))]
pub struct DcdcConfig { pub struct DcdcConfig {
/// Config for the first stage DCDC (VDDH -> VDD), if disabled LDO will be used. /// Config for the first stage DCDC (VDDH -> VDD), if disabled LDO will be used.
#[cfg(feature = "nrf52840")] #[cfg(feature = "nrf52840")]
@ -268,7 +291,7 @@ pub mod config {
} }
/// Settings for enabling the built in DCDC converter. /// Settings for enabling the built in DCDC converter.
#[cfg(any(feature = "_nrf9160", feature = "_nrf9120"))] #[cfg(feature = "_nrf91")]
pub struct DcdcConfig { pub struct DcdcConfig {
/// Config for the main rail, if disabled LDO will be used. /// Config for the main rail, if disabled LDO will be used.
pub regmain: bool, pub regmain: bool,
@ -302,7 +325,7 @@ pub mod config {
// xtals if they know they have them. // xtals if they know they have them.
hfclk_source: HfclkSource::Internal, hfclk_source: HfclkSource::Internal,
lfclk_source: LfclkSource::InternalRC, lfclk_source: LfclkSource::InternalRC,
#[cfg(not(any(feature = "_nrf5340", feature = "_nrf9160", feature = "_nrf9120")))] #[cfg(not(any(feature = "_nrf5340", feature = "_nrf91")))]
dcdc: DcdcConfig { dcdc: DcdcConfig {
#[cfg(feature = "nrf52840")] #[cfg(feature = "nrf52840")]
reg0: false, reg0: false,
@ -316,7 +339,7 @@ pub mod config {
regmain: false, regmain: false,
regradio: false, regradio: false,
}, },
#[cfg(any(feature = "_nrf9160", feature = "_nrf9120"))] #[cfg(feature = "_nrf91")]
dcdc: DcdcConfig { regmain: false }, dcdc: DcdcConfig { regmain: false },
#[cfg(feature = "gpiote")] #[cfg(feature = "gpiote")]
gpiote_interrupt_priority: crate::interrupt::Priority::P0, gpiote_interrupt_priority: crate::interrupt::Priority::P0,
@ -333,7 +356,7 @@ pub mod config {
} }
} }
#[cfg(any(feature = "_nrf9160", feature = "_nrf9120"))] #[cfg(feature = "_nrf91")]
#[allow(unused)] #[allow(unused)]
mod consts { mod consts {
pub const UICR_APPROTECT: *mut u32 = 0x00FF8000 as *mut u32; pub const UICR_APPROTECT: *mut u32 = 0x00FF8000 as *mut u32;
@ -472,7 +495,7 @@ pub fn init(config: config::Config) -> Peripherals {
// UICR.APPROTECT = Enabled // UICR.APPROTECT = Enabled
let res = uicr_write(consts::UICR_APPROTECT, consts::APPROTECT_ENABLED); let res = uicr_write(consts::UICR_APPROTECT, consts::APPROTECT_ENABLED);
needs_reset |= res == WriteResult::Written; needs_reset |= res == WriteResult::Written;
#[cfg(any(feature = "_nrf5340-app", feature = "_nrf9160", feature = "_nrf9120"))] #[cfg(any(feature = "_nrf5340-app", feature = "_nrf91"))]
{ {
let res = uicr_write(consts::UICR_SECUREAPPROTECT, consts::APPROTECT_ENABLED); let res = uicr_write(consts::UICR_SECUREAPPROTECT, consts::APPROTECT_ENABLED);
needs_reset |= res == WriteResult::Written; needs_reset |= res == WriteResult::Written;
@ -556,7 +579,7 @@ pub fn init(config: config::Config) -> Peripherals {
} }
// Configure LFCLK. // Configure LFCLK.
#[cfg(not(any(feature = "nrf51", feature = "_nrf5340", feature = "_nrf9160", feature = "_nrf9120")))] #[cfg(not(any(feature = "nrf51", feature = "_nrf5340", feature = "_nrf91")))]
match config.lfclk_source { match config.lfclk_source {
config::LfclkSource::InternalRC => r.lfclksrc.write(|w| w.src().rc()), config::LfclkSource::InternalRC => r.lfclksrc.write(|w| w.src().rc()),
config::LfclkSource::Synthesized => r.lfclksrc.write(|w| w.src().synth()), config::LfclkSource::Synthesized => r.lfclksrc.write(|w| w.src().synth()),
@ -576,7 +599,7 @@ pub fn init(config: config::Config) -> Peripherals {
w w
}), }),
} }
#[cfg(any(feature = "_nrf9160", feature = "_nrf9120"))] #[cfg(feature = "_nrf91")]
match config.lfclk_source { match config.lfclk_source {
config::LfclkSource::InternalRC => r.lfclksrc.write(|w| w.src().lfrc()), config::LfclkSource::InternalRC => r.lfclksrc.write(|w| w.src().lfrc()),
config::LfclkSource::ExternalXtal => r.lfclksrc.write(|w| w.src().lfxo()), config::LfclkSource::ExternalXtal => r.lfclksrc.write(|w| w.src().lfxo()),
@ -589,7 +612,7 @@ pub fn init(config: config::Config) -> Peripherals {
r.tasks_lfclkstart.write(|w| unsafe { w.bits(1) }); r.tasks_lfclkstart.write(|w| unsafe { w.bits(1) });
while r.events_lfclkstarted.read().bits() == 0 {} while r.events_lfclkstarted.read().bits() == 0 {}
#[cfg(not(any(feature = "_nrf5340", feature = "_nrf9160", feature = "_nrf9120")))] #[cfg(not(any(feature = "_nrf5340", feature = "_nrf91")))]
{ {
// Setup DCDCs. // Setup DCDCs.
let pwr = unsafe { &*pac::POWER::ptr() }; let pwr = unsafe { &*pac::POWER::ptr() };
@ -601,7 +624,7 @@ pub fn init(config: config::Config) -> Peripherals {
pwr.dcdcen.write(|w| w.dcdcen().set_bit()); pwr.dcdcen.write(|w| w.dcdcen().set_bit());
} }
} }
#[cfg(any(feature = "_nrf9160", feature = "_nrf9120"))] #[cfg(feature = "_nrf91")]
{ {
// Setup DCDC. // Setup DCDC.
let reg = unsafe { &*pac::REGULATORS::ptr() }; let reg = unsafe { &*pac::REGULATORS::ptr() };
@ -633,7 +656,7 @@ pub fn init(config: config::Config) -> Peripherals {
time_driver::init(config.time_interrupt_priority); time_driver::init(config.time_interrupt_priority);
// Disable UARTE (enabled by default for some reason) // Disable UARTE (enabled by default for some reason)
#[cfg(any(feature = "_nrf9160", feature = "_nrf9120"))] #[cfg(feature = "_nrf91")]
unsafe { unsafe {
(*pac::UARTE0::ptr()).enable.write(|w| w.enable().disabled()); (*pac::UARTE0::ptr()).enable.write(|w| w.enable().disabled());
(*pac::UARTE1::ptr()).enable.write(|w| w.enable().disabled()); (*pac::UARTE1::ptr()).enable.write(|w| w.enable().disabled());

View file

@ -60,23 +60,23 @@ impl<'d> Nvmc<'d> {
while p.ready.read().ready().is_busy() {} while p.ready.read().ready().is_busy() {}
} }
#[cfg(not(any(feature = "_nrf9160", feature = "_nrf5340")))] #[cfg(not(any(feature = "_nrf91", feature = "_nrf5340")))]
fn wait_ready_write(&mut self) { fn wait_ready_write(&mut self) {
self.wait_ready(); self.wait_ready();
} }
#[cfg(any(feature = "_nrf9160", feature = "_nrf5340"))] #[cfg(any(feature = "_nrf91", feature = "_nrf5340"))]
fn wait_ready_write(&mut self) { fn wait_ready_write(&mut self) {
let p = Self::regs(); let p = Self::regs();
while p.readynext.read().readynext().is_busy() {} while p.readynext.read().readynext().is_busy() {}
} }
#[cfg(not(any(feature = "_nrf9160", feature = "_nrf9120", feature = "_nrf5340")))] #[cfg(not(any(feature = "_nrf91", feature = "_nrf5340")))]
fn erase_page(&mut self, page_addr: u32) { fn erase_page(&mut self, page_addr: u32) {
Self::regs().erasepage().write(|w| unsafe { w.bits(page_addr) }); Self::regs().erasepage().write(|w| unsafe { w.bits(page_addr) });
} }
#[cfg(any(feature = "_nrf9160", feature = "_nrf9120", feature = "_nrf5340"))] #[cfg(any(feature = "_nrf91", feature = "_nrf5340"))]
fn erase_page(&mut self, page_addr: u32) { fn erase_page(&mut self, page_addr: u32) {
let first_page_word = page_addr as *mut u32; let first_page_word = page_addr as *mut u32;
unsafe { unsafe {

View file

@ -21,7 +21,7 @@ pub use crate::pac::pdm::pdmclkctrl::FREQ_A as Frequency;
feature = "nrf52840", feature = "nrf52840",
feature = "nrf52833", feature = "nrf52833",
feature = "_nrf5340-app", feature = "_nrf5340-app",
feature = "_nrf9160", feature = "_nrf91",
))] ))]
pub use crate::pac::pdm::ratio::RATIO_A as Ratio; pub use crate::pac::pdm::ratio::RATIO_A as Ratio;
use crate::{interrupt, Peripheral}; use crate::{interrupt, Peripheral};
@ -121,7 +121,7 @@ impl<'d, T: Instance> Pdm<'d, T> {
feature = "nrf52840", feature = "nrf52840",
feature = "nrf52833", feature = "nrf52833",
feature = "_nrf5340-app", feature = "_nrf5340-app",
feature = "_nrf9160", feature = "_nrf91",
))] ))]
r.ratio.write(|w| w.ratio().variant(config.ratio)); r.ratio.write(|w| w.ratio().variant(config.ratio));
r.mode.write(|w| { r.mode.write(|w| {
@ -374,7 +374,7 @@ pub struct Config {
feature = "nrf52840", feature = "nrf52840",
feature = "nrf52833", feature = "nrf52833",
feature = "_nrf5340-app", feature = "_nrf5340-app",
feature = "_nrf9160", feature = "_nrf91",
))] ))]
pub ratio: Ratio, pub ratio: Ratio,
/// Gain left in dB /// Gain left in dB
@ -393,7 +393,7 @@ impl Default for Config {
feature = "nrf52840", feature = "nrf52840",
feature = "nrf52833", feature = "nrf52833",
feature = "_nrf5340-app", feature = "_nrf5340-app",
feature = "_nrf9160", feature = "_nrf91",
))] ))]
ratio: Ratio::RATIO80, ratio: Ratio::RATIO80,
gain_left: I7F1::ZERO, gain_left: I7F1::ZERO,

View file

@ -722,9 +722,9 @@ macro_rules! impl_saadc_input {
pub struct VddInput; pub struct VddInput;
impl_peripheral!(VddInput); impl_peripheral!(VddInput);
#[cfg(not(any(feature = "_nrf9160", feature = "_nrf9120")))] #[cfg(not(feature = "_nrf91"))]
impl_saadc_input!(@local, VddInput, VDD); impl_saadc_input!(@local, VddInput, VDD);
#[cfg(not(any(feature = "_nrf9160", feature = "_nrf9120")))] #[cfg(not(feature = "_nrf91"))]
impl_saadc_input!(@local, VddInput, VDDGPIO); impl_saadc_input!(@local, VddInput, VDDGPIO);
/// A dummy `Input` pin implementation for SAADC peripheral sampling from the /// A dummy `Input` pin implementation for SAADC peripheral sampling from the

View file

@ -30,9 +30,9 @@ impl Config {
pub fn try_new(_wdt: &peripherals::WDT) -> Option<Self> { pub fn try_new(_wdt: &peripherals::WDT) -> Option<Self> {
let r = unsafe { &*WDT::ptr() }; let r = unsafe { &*WDT::ptr() };
#[cfg(not(any(feature = "_nrf9160", feature = "_nrf9120")))] #[cfg(not(feature = "_nrf91"))]
let runstatus = r.runstatus.read().runstatus().bit(); let runstatus = r.runstatus.read().runstatus().bit();
#[cfg(any(feature = "_nrf9160", feature = "_nrf9120"))] #[cfg(feature = "_nrf91")]
let runstatus = r.runstatus.read().runstatuswdt().bit(); let runstatus = r.runstatus.read().runstatuswdt().bit();
if runstatus { if runstatus {
@ -83,9 +83,9 @@ impl Watchdog {
let crv = config.timeout_ticks.max(MIN_TICKS); let crv = config.timeout_ticks.max(MIN_TICKS);
let rren = (1u32 << N) - 1; let rren = (1u32 << N) - 1;
#[cfg(not(any(feature = "_nrf9160", feature = "_nrf9120")))] #[cfg(not(feature = "_nrf91"))]
let runstatus = r.runstatus.read().runstatus().bit(); let runstatus = r.runstatus.read().runstatus().bit();
#[cfg(any(feature = "_nrf9160", feature = "_nrf9120"))] #[cfg(feature = "_nrf91")]
let runstatus = r.runstatus.read().runstatuswdt().bit(); let runstatus = r.runstatus.read().runstatuswdt().bit();
if runstatus { if runstatus {