Initial support for nrf9160
This commit is contained in:
@@ -22,6 +22,18 @@ pub const PIN_COUNT: usize = 48;
|
||||
#[cfg(not(any(feature = "nrf52833", feature = "nrf52840")))]
|
||||
pub const PIN_COUNT: usize = 32;
|
||||
|
||||
#[cfg(not(feature = "nrf9160"))]
|
||||
pub(crate) use pac::P0;
|
||||
#[cfg(feature = "nrf9160")]
|
||||
pub(crate) use pac::P0_NS as P0;
|
||||
#[cfg(not(feature = "nrf9160"))]
|
||||
pub(crate) use pac::P1;
|
||||
|
||||
#[cfg(not(feature = "nrf9160"))]
|
||||
pub(crate) use pac::GPIOTE;
|
||||
#[cfg(feature = "nrf9160")]
|
||||
pub(crate) use pac::GPIOTE1_NS as GPIOTE;
|
||||
|
||||
const NEW_AW: AtomicWaker = AtomicWaker::new();
|
||||
static CHANNEL_WAKERS: [AtomicWaker; CHANNEL_COUNT] = [NEW_AW; CHANNEL_COUNT];
|
||||
static PORT_WAKERS: [AtomicWaker; PIN_COUNT] = [NEW_AW; PIN_COUNT];
|
||||
@@ -42,9 +54,9 @@ pub enum OutputChannelPolarity {
|
||||
|
||||
pub(crate) fn init(irq_prio: crate::interrupt::Priority) {
|
||||
#[cfg(any(feature = "nrf52833", feature = "nrf52840"))]
|
||||
let ports = unsafe { &[&*pac::P0::ptr(), &*pac::P1::ptr()] };
|
||||
let ports = unsafe { &[&*P0::ptr(), &*P1::ptr()] };
|
||||
#[cfg(not(any(feature = "nrf52833", feature = "nrf52840")))]
|
||||
let ports = unsafe { &[&*pac::P0::ptr()] };
|
||||
let ports = unsafe { &[&*P0::ptr()] };
|
||||
|
||||
for &p in ports {
|
||||
// Enable latched detection
|
||||
@@ -55,19 +67,34 @@ pub(crate) fn init(irq_prio: crate::interrupt::Priority) {
|
||||
|
||||
// Enable interrupts
|
||||
|
||||
#[cfg(not(feature = "nrf9160"))]
|
||||
let irq = unsafe { interrupt::GPIOTE::steal() };
|
||||
#[cfg(feature = "nrf9160")]
|
||||
let irq = unsafe { interrupt::GPIOTE1::steal() };
|
||||
|
||||
irq.unpend();
|
||||
irq.set_priority(irq_prio);
|
||||
irq.enable();
|
||||
|
||||
let g = unsafe { &*pac::GPIOTE::ptr() };
|
||||
let g = unsafe { &*GPIOTE::ptr() };
|
||||
g.events_port.write(|w| w);
|
||||
g.intenset.write(|w| w.port().set());
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "nrf9160"))]
|
||||
#[interrupt]
|
||||
unsafe fn GPIOTE() {
|
||||
let g = &*pac::GPIOTE::ptr();
|
||||
fn GPIOTE() {
|
||||
unsafe { handle_gpiote_interrupt() };
|
||||
}
|
||||
|
||||
#[cfg(feature = "nrf9160")]
|
||||
#[interrupt]
|
||||
fn GPIOTE1() {
|
||||
unsafe { handle_gpiote_interrupt() };
|
||||
}
|
||||
|
||||
unsafe fn handle_gpiote_interrupt() {
|
||||
let g = &*GPIOTE::ptr();
|
||||
|
||||
for i in 0..CHANNEL_COUNT {
|
||||
if g.events_in[i].read().bits() != 0 {
|
||||
@@ -80,9 +107,9 @@ unsafe fn GPIOTE() {
|
||||
g.events_port.write(|w| w);
|
||||
|
||||
#[cfg(any(feature = "nrf52833", feature = "nrf52840"))]
|
||||
let ports = &[&*pac::P0::ptr(), &*pac::P1::ptr()];
|
||||
let ports = &[&*P0::ptr(), &*P1::ptr()];
|
||||
#[cfg(not(any(feature = "nrf52833", feature = "nrf52840")))]
|
||||
let ports = &[&*pac::P0::ptr()];
|
||||
let ports = &[&*P0::ptr()];
|
||||
|
||||
for (port, &p) in ports.iter().enumerate() {
|
||||
let bits = p.latch.read().bits();
|
||||
@@ -119,7 +146,7 @@ pub struct InputChannel<'d, C: Channel, T: GpioPin> {
|
||||
|
||||
impl<'d, C: Channel, T: GpioPin> Drop for InputChannel<'d, C, T> {
|
||||
fn drop(&mut self) {
|
||||
let g = unsafe { &*pac::GPIOTE::ptr() };
|
||||
let g = unsafe { &*GPIOTE::ptr() };
|
||||
let num = self.ch.number();
|
||||
g.config[num].write(|w| w.mode().disabled());
|
||||
g.intenclr.write(|w| unsafe { w.bits(1 << num) });
|
||||
@@ -128,7 +155,7 @@ impl<'d, C: Channel, T: GpioPin> Drop for InputChannel<'d, C, T> {
|
||||
|
||||
impl<'d, C: Channel, T: GpioPin> InputChannel<'d, C, T> {
|
||||
pub fn new(ch: C, pin: Input<'d, T>, polarity: InputChannelPolarity) -> Self {
|
||||
let g = unsafe { &*pac::GPIOTE::ptr() };
|
||||
let g = unsafe { &*GPIOTE::ptr() };
|
||||
let num = ch.number();
|
||||
|
||||
g.config[num].write(|w| {
|
||||
@@ -152,7 +179,7 @@ impl<'d, C: Channel, T: GpioPin> InputChannel<'d, C, T> {
|
||||
}
|
||||
|
||||
pub async fn wait(&self) {
|
||||
let g = unsafe { &*pac::GPIOTE::ptr() };
|
||||
let g = unsafe { &*GPIOTE::ptr() };
|
||||
let num = self.ch.number();
|
||||
|
||||
// Enable interrupt
|
||||
@@ -173,7 +200,7 @@ impl<'d, C: Channel, T: GpioPin> InputChannel<'d, C, T> {
|
||||
|
||||
/// Returns the IN event, for use with PPI.
|
||||
pub fn event_in(&self) -> Event {
|
||||
let g = unsafe { &*pac::GPIOTE::ptr() };
|
||||
let g = unsafe { &*GPIOTE::ptr() };
|
||||
Event::from_reg(&g.events_in[self.ch.number()])
|
||||
}
|
||||
}
|
||||
@@ -198,7 +225,7 @@ pub struct OutputChannel<'d, C: Channel, T: GpioPin> {
|
||||
|
||||
impl<'d, C: Channel, T: GpioPin> Drop for OutputChannel<'d, C, T> {
|
||||
fn drop(&mut self) {
|
||||
let g = unsafe { &*pac::GPIOTE::ptr() };
|
||||
let g = unsafe { &*GPIOTE::ptr() };
|
||||
let num = self.ch.number();
|
||||
g.config[num].write(|w| w.mode().disabled());
|
||||
g.intenclr.write(|w| unsafe { w.bits(1 << num) });
|
||||
@@ -207,7 +234,7 @@ impl<'d, C: Channel, T: GpioPin> Drop for OutputChannel<'d, C, T> {
|
||||
|
||||
impl<'d, C: Channel, T: GpioPin> OutputChannel<'d, C, T> {
|
||||
pub fn new(ch: C, pin: Output<'d, T>, polarity: OutputChannelPolarity) -> Self {
|
||||
let g = unsafe { &*pac::GPIOTE::ptr() };
|
||||
let g = unsafe { &*GPIOTE::ptr() };
|
||||
let num = ch.number();
|
||||
|
||||
g.config[num].write(|w| {
|
||||
@@ -234,41 +261,41 @@ impl<'d, C: Channel, T: GpioPin> OutputChannel<'d, C, T> {
|
||||
|
||||
/// Triggers `task out` (as configured with task_out_polarity, defaults to Toggle).
|
||||
pub fn out(&self) {
|
||||
let g = unsafe { &*pac::GPIOTE::ptr() };
|
||||
let g = unsafe { &*GPIOTE::ptr() };
|
||||
g.tasks_out[self.ch.number()].write(|w| unsafe { w.bits(1) });
|
||||
}
|
||||
|
||||
/// Triggers `task set` (set associated pin high).
|
||||
#[cfg(not(feature = "51"))]
|
||||
pub fn set(&self) {
|
||||
let g = unsafe { &*pac::GPIOTE::ptr() };
|
||||
let g = unsafe { &*GPIOTE::ptr() };
|
||||
g.tasks_set[self.ch.number()].write(|w| unsafe { w.bits(1) });
|
||||
}
|
||||
|
||||
/// Triggers `task clear` (set associated pin low).
|
||||
#[cfg(not(feature = "51"))]
|
||||
pub fn clear(&self) {
|
||||
let g = unsafe { &*pac::GPIOTE::ptr() };
|
||||
let g = unsafe { &*GPIOTE::ptr() };
|
||||
g.tasks_clr[self.ch.number()].write(|w| unsafe { w.bits(1) });
|
||||
}
|
||||
|
||||
/// Returns the OUT task, for use with PPI.
|
||||
pub fn task_out(&self) -> Task {
|
||||
let g = unsafe { &*pac::GPIOTE::ptr() };
|
||||
let g = unsafe { &*GPIOTE::ptr() };
|
||||
Task::from_reg(&g.tasks_out[self.ch.number()])
|
||||
}
|
||||
|
||||
/// Returns the CLR task, for use with PPI.
|
||||
#[cfg(not(feature = "51"))]
|
||||
pub fn task_clr(&self) -> Task {
|
||||
let g = unsafe { &*pac::GPIOTE::ptr() };
|
||||
let g = unsafe { &*GPIOTE::ptr() };
|
||||
Task::from_reg(&g.tasks_clr[self.ch.number()])
|
||||
}
|
||||
|
||||
/// Returns the SET task, for use with PPI.
|
||||
#[cfg(not(feature = "51"))]
|
||||
pub fn task_set(&self) -> Task {
|
||||
let g = unsafe { &*pac::GPIOTE::ptr() };
|
||||
let g = unsafe { &*GPIOTE::ptr() };
|
||||
Task::from_reg(&g.tasks_set[self.ch.number()])
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user