Skip to content

Commit

Permalink
Support all nRF52 devices as well as the nRF9160
Browse files Browse the repository at this point in the history
  • Loading branch information
huntc committed Jul 17, 2021
1 parent 78aadda commit 1b4606e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion nrf-hal-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub mod i2s;
pub mod ieee802154;
#[cfg(not(any(feature = "52811", feature = "52810", feature = "9160")))]
pub mod lpcomp;
#[cfg(any(feature = "52840", feature = "9160"))]
#[cfg(not(feature = "51"))]
pub mod nvmc;
#[cfg(not(feature = "9160"))]
pub mod ppi;
Expand Down
30 changes: 15 additions & 15 deletions nrf-hal-common/src/nvmc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
use core::ops::Deref;

#[cfg(any(feature = "52840"))]
#[cfg(not(feature = "9160"))]
use crate::pac::nvmc;
#[cfg(any(feature = "9160"))]
#[cfg(feature = "9160")]
use crate::pac::nvmc_ns as nvmc;
#[cfg(any(feature = "52840"))]
#[cfg(not(feature = "9160"))]
use crate::pac::NVMC;
#[cfg(any(feature = "9160"))]
#[cfg(feature = "9160")]
use crate::pac::NVMC_NS as NVMC;

use embedded_storage::nor_flash::{NorFlash, ReadNorFlash};
Expand All @@ -34,23 +34,23 @@ where
}

fn enable_erase(&self) {
#[cfg(any(feature = "52840"))]
#[cfg(not(feature = "9160"))]
self.nvmc.config.write(|w| w.wen().een());
#[cfg(any(feature = "9160"))]
#[cfg(feature = "9160")]
self.nvmc.configns.write(|w| w.wen().een());
}

fn enable_read(&self) {
#[cfg(any(feature = "52840"))]
#[cfg(not(feature = "9160"))]
self.nvmc.config.write(|w| w.wen().ren());
#[cfg(any(feature = "9160"))]
#[cfg(feature = "9160")]
self.nvmc.configns.write(|w| w.wen().ren());
}

fn enable_write(&self) {
#[cfg(any(feature = "52840"))]
#[cfg(not(feature = "9160"))]
self.nvmc.config.write(|w| w.wen().wen());
#[cfg(any(feature = "9160"))]
#[cfg(feature = "9160")]
self.nvmc.configns.write(|w| w.wen().wen());
}

Expand All @@ -59,21 +59,21 @@ where
while !self.nvmc.ready.read().ready().bit_is_set() {}
}

#[cfg(any(feature = "9160"))]
#[cfg(feature = "9160")]
#[inline]
fn wait_write_ready(&self) {
while !self.nvmc.readynext.read().readynext().bit_is_set() {}
}

#[cfg(any(feature = "52840"))]
#[cfg(not(feature = "9160"))]
#[inline]
fn erase_page(&mut self, offset: usize) {
let bits = &mut (self.storage[offset as usize >> 2]) as *mut _ as u32;
self.nvmc.erasepage().write(|w| unsafe { w.bits(bits) });
self.wait_ready();
}

#[cfg(any(feature = "9160"))]
#[cfg(feature = "9160")]
#[inline]
fn erase_page(&mut self, offset: usize) {
self.storage[offset as usize >> 2] = 0xffffffff;
Expand All @@ -82,9 +82,9 @@ where

#[inline]
fn write_word(&mut self, offset: usize, word: u32) {
#[cfg(any(feature = "52840"))]
#[cfg(not(feature = "9160"))]
self.wait_ready();
#[cfg(any(feature = "9160"))]
#[cfg(feature = "9160")]
self.wait_write_ready();
self.storage[offset] = word;
cortex_m::asm::dmb();
Expand Down

0 comments on commit 1b4606e

Please sign in to comment.