atsamd_hal/
util.rs

1#[cfg(feature = "async")]
2/// Iterate over all bits that are `1`, returning the bit's position.
3/// Shamelessly stolen from [embassy](https://github.com/embassy-rs/embassy/blob/3d1501c02038e5fe6f6d3b72bd18bd7a52595a77/embassy-stm32/src/exti.rs#L67)
4pub struct BitIter(pub u32);
5
6#[cfg(feature = "async")]
7impl Iterator for BitIter {
8    type Item = u32;
9
10    fn next(&mut self) -> Option<Self::Item> {
11        match self.0.trailing_zeros() {
12            32 => None,
13            b => {
14                self.0 &= !(1 << b);
15                Some(b)
16            }
17        }
18    }
19}