Skip to content

Commit e6973f3

Browse files
committed
Add safety notes to some gpio unsafe calls
1 parent 5ad2cea commit e6973f3

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/gpio.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@ where
626626
Edge::Falling => (false as u32, true as u32),
627627
Edge::RisingFalling => (true as u32, true as u32),
628628
};
629+
// SAFETY: Unguarded write to the register, but behind a &mut
629630
unsafe {
630631
modify_at!(reg_for_cpu!(exti, rtsr), BITWIDTH, index, rise);
631632
modify_at!(reg_for_cpu!(exti, ftsr), BITWIDTH, index, fall);
@@ -644,6 +645,7 @@ where
644645

645646
let index = self.index.index();
646647
let value = u32::from(enable);
648+
// SAFETY: Unguarded write to the register, but behind a &mut
647649
unsafe { modify_at!(reg_for_cpu!(exti, imr), BITWIDTH, index, value) };
648650
}
649651

@@ -659,11 +661,13 @@ where
659661

660662
/// Clear the interrupt pending bit for this pin
661663
pub fn clear_interrupt(&mut self) {
664+
// SAFETY: Atomic write to register without side-effects.
662665
unsafe { reg_for_cpu!((*EXTI::ptr()), pr).write(|w| w.bits(1 << self.index.index())) };
663666
}
664667

665668
/// Reads the interrupt pending bit for this pin
666669
pub fn is_interrupt_pending(&self) -> bool {
670+
// SAFETY: Atomic write to register without side-effects.
667671
unsafe { reg_for_cpu!((*EXTI::ptr()), pr).read().bits() & (1 << self.index.index()) != 0 }
668672
}
669673
}

0 commit comments

Comments
 (0)