Skip to content

Commit 02ffe6f

Browse files
committed
Check edges
1 parent e538f49 commit 02ffe6f

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/gpiohs.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,23 @@ impl<MODE> Gpiohs0<MODE> {
7373
GPIOHS::set_low_ie(0, edge.contains(Edge::LOW));
7474
}
7575

76+
pub fn check_edges(&self) -> Edge {
77+
let mut ans = Edge::empty();
78+
if GPIOHS::has_rise_ip(0) {
79+
ans |= Edge::RISING;
80+
}
81+
if GPIOHS::has_fall_ip(0) {
82+
ans |= Edge::FALLING;
83+
}
84+
if GPIOHS::has_high_ip(0) {
85+
ans |= Edge::HIGH;
86+
}
87+
if GPIOHS::has_low_ip(0) {
88+
ans |= Edge::LOW;
89+
}
90+
ans
91+
}
92+
7693
pub fn clear_interrupt_pending_bits(&mut self) {
7794
if GPIOHS::has_rise_ie(0) {
7895
GPIOHS::set_rise_ie(0, false);
@@ -291,6 +308,34 @@ trait GpiohsAccess {
291308
u32_bit_is_set(p, index)
292309
}
293310
}
311+
312+
fn has_rise_ip(index: usize) -> bool {
313+
unsafe {
314+
let p = &mut Self::peripheral().rise_ip as *mut _ as *mut _;
315+
u32_bit_is_set(p, index)
316+
}
317+
}
318+
319+
fn has_fall_ip(index: usize) -> bool {
320+
unsafe {
321+
let p = &mut Self::peripheral().fall_ip as *mut _ as *mut _;
322+
u32_bit_is_set(p, index)
323+
}
324+
}
325+
326+
fn has_high_ip(index: usize) -> bool {
327+
unsafe {
328+
let p = &mut Self::peripheral().high_ip as *mut _ as *mut _;
329+
u32_bit_is_set(p, index)
330+
}
331+
}
332+
333+
fn has_low_ip(index: usize) -> bool {
334+
unsafe {
335+
let p = &mut Self::peripheral().low_ip as *mut _ as *mut _;
336+
u32_bit_is_set(p, index)
337+
}
338+
}
294339

295340
}
296341

0 commit comments

Comments
 (0)