aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf/src
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2024-02-04 21:36:19 +0100
committerDario Nieuwenhuis <[email protected]>2024-02-04 21:36:19 +0100
commitd5d86b866fd5ceb8081cbfcce832be4c68b82691 (patch)
tree8884048c369632e1d96370010ec96b4caf1eab90 /embassy-nrf/src
parent711dd120d1802dd43b003b2536a290a1c53cfeba (diff)
nrf/gpiote: add support for nrf51.
Diffstat (limited to 'embassy-nrf/src')
-rw-r--r--embassy-nrf/src/gpiote.rs58
1 files changed, 45 insertions, 13 deletions
diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs
index a459446a2..12f4ed0a0 100644
--- a/embassy-nrf/src/gpiote.rs
+++ b/embassy-nrf/src/gpiote.rs
@@ -13,6 +13,10 @@ use crate::interrupt::InterruptExt;
13use crate::ppi::{Event, Task}; 13use crate::ppi::{Event, Task};
14use crate::{interrupt, pac, peripherals}; 14use crate::{interrupt, pac, peripherals};
15 15
16#[cfg(feature = "nrf51")]
17/// Amount of GPIOTE channels in the chip.
18const CHANNEL_COUNT: usize = 4;
19#[cfg(not(feature = "_nrf51"))]
16/// Amount of GPIOTE channels in the chip. 20/// Amount of GPIOTE channels in the chip.
17const CHANNEL_COUNT: usize = 8; 21const CHANNEL_COUNT: usize = 8;
18 22
@@ -61,16 +65,20 @@ fn regs() -> &'static pac::gpiote::RegisterBlock {
61} 65}
62 66
63pub(crate) fn init(irq_prio: crate::interrupt::Priority) { 67pub(crate) fn init(irq_prio: crate::interrupt::Priority) {
64 #[cfg(any(feature = "nrf52833", feature = "nrf52840"))] 68 // no latched GPIO detect in nrf51.
65 let ports = unsafe { &[&*pac::P0::ptr(), &*pac::P1::ptr()] }; 69 #[cfg(not(feature = "_nrf51"))]
66 #[cfg(not(any(feature = "nrf52833", feature = "nrf52840")))] 70 {
67 let ports = unsafe { &[&*pac::P0::ptr()] }; 71 #[cfg(any(feature = "nrf52833", feature = "nrf52840"))]
68 72 let ports = unsafe { &[&*pac::P0::ptr(), &*pac::P1::ptr()] };
69 for &p in ports { 73 #[cfg(not(any(feature = "_nrf51", feature = "nrf52833", feature = "nrf52840")))]
70 // Enable latched detection 74 let ports = unsafe { &[&*pac::P0::ptr()] };
71 p.detectmode.write(|w| w.detectmode().ldetect()); 75
72 // Clear latch 76 for &p in ports {
73 p.latch.write(|w| unsafe { w.bits(0xFFFFFFFF) }) 77 // Enable latched detection
78 p.detectmode.write(|w| w.detectmode().ldetect());
79 // Clear latch
80 p.latch.write(|w| unsafe { w.bits(0xFFFFFFFF) })
81 }
74 } 82 }
75 83
76 // Enable interrupts 84 // Enable interrupts
@@ -78,7 +86,7 @@ pub(crate) fn init(irq_prio: crate::interrupt::Priority) {
78 let irq = interrupt::GPIOTE0; 86 let irq = interrupt::GPIOTE0;
79 #[cfg(any(feature = "nrf5340-app-ns", feature = "nrf9160-ns"))] 87 #[cfg(any(feature = "nrf5340-app-ns", feature = "nrf9160-ns"))]
80 let irq = interrupt::GPIOTE1; 88 let irq = interrupt::GPIOTE1;
81 #[cfg(any(feature = "_nrf52", feature = "nrf5340-net"))] 89 #[cfg(any(feature = "_nrf51", feature = "_nrf52", feature = "nrf5340-net"))]
82 let irq = interrupt::GPIOTE; 90 let irq = interrupt::GPIOTE;
83 91
84 irq.unpend(); 92 irq.unpend();
@@ -103,7 +111,7 @@ fn GPIOTE1() {
103 unsafe { handle_gpiote_interrupt() }; 111 unsafe { handle_gpiote_interrupt() };
104} 112}
105 113
106#[cfg(any(feature = "_nrf52", feature = "nrf5340-net"))] 114#[cfg(any(feature = "_nrf51", feature = "_nrf52", feature = "nrf5340-net"))]
107#[cfg(feature = "rt")] 115#[cfg(feature = "rt")]
108#[interrupt] 116#[interrupt]
109fn GPIOTE() { 117fn GPIOTE() {
@@ -125,9 +133,29 @@ unsafe fn handle_gpiote_interrupt() {
125 133
126 #[cfg(any(feature = "nrf52833", feature = "nrf52840"))] 134 #[cfg(any(feature = "nrf52833", feature = "nrf52840"))]
127 let ports = &[&*pac::P0::ptr(), &*pac::P1::ptr()]; 135 let ports = &[&*pac::P0::ptr(), &*pac::P1::ptr()];
128 #[cfg(not(any(feature = "nrf52833", feature = "nrf52840")))] 136 #[cfg(not(any(feature = "_nrf51", feature = "nrf52833", feature = "nrf52840")))]
129 let ports = &[&*pac::P0::ptr()]; 137 let ports = &[&*pac::P0::ptr()];
138 #[cfg(feature = "_nrf51")]
139 let ports = unsafe { &[&*pac::GPIO::ptr()] };
140
141 #[cfg(feature = "_nrf51")]
142 for (port, &p) in ports.iter().enumerate() {
143 let inp = p.in_.read().bits();
144 for pin in 0..32 {
145 let fired = match p.pin_cnf[pin as usize].read().sense().variant() {
146 Some(pac::gpio::pin_cnf::SENSE_A::HIGH) => inp & (1 << pin) != 0,
147 Some(pac::gpio::pin_cnf::SENSE_A::LOW) => inp & (1 << pin) == 0,
148 _ => false,
149 };
150
151 if fired {
152 PORT_WAKERS[port * 32 + pin as usize].wake();
153 p.pin_cnf[pin as usize].modify(|_, w| w.sense().disabled());
154 }
155 }
156 }
130 157
158 #[cfg(not(feature = "_nrf51"))]
131 for (port, &p) in ports.iter().enumerate() { 159 for (port, &p) in ports.iter().enumerate() {
132 let bits = p.latch.read().bits(); 160 let bits = p.latch.read().bits();
133 for pin in BitIter(bits) { 161 for pin in BitIter(bits) {
@@ -476,9 +504,13 @@ impl_channel!(GPIOTE_CH0, 0);
476impl_channel!(GPIOTE_CH1, 1); 504impl_channel!(GPIOTE_CH1, 1);
477impl_channel!(GPIOTE_CH2, 2); 505impl_channel!(GPIOTE_CH2, 2);
478impl_channel!(GPIOTE_CH3, 3); 506impl_channel!(GPIOTE_CH3, 3);
507#[cfg(not(feature = "nrf51"))]
479impl_channel!(GPIOTE_CH4, 4); 508impl_channel!(GPIOTE_CH4, 4);
509#[cfg(not(feature = "nrf51"))]
480impl_channel!(GPIOTE_CH5, 5); 510impl_channel!(GPIOTE_CH5, 5);
511#[cfg(not(feature = "nrf51"))]
481impl_channel!(GPIOTE_CH6, 6); 512impl_channel!(GPIOTE_CH6, 6);
513#[cfg(not(feature = "nrf51"))]
482impl_channel!(GPIOTE_CH7, 7); 514impl_channel!(GPIOTE_CH7, 7);
483 515
484// ==================== 516// ====================