diff --git a/src/gpio.rs b/src/gpio.rs
index 9268c3dc2..735948145 100644
--- a/src/gpio.rs
+++ b/src/gpio.rs
@@ -107,10 +107,11 @@ macro_rules! gpio {
gpio_mapped_iorst: $iopxrst:ident,
partially_erased_pin: $PXx:ident,
pins: [
- $($PXi:ident: ($pxi:ident, $i:expr, $MODE:ty, $AFR:ident, [
- $($AFi_common:ty: ($into_afi_common:ident, $afi_common:expr,),)*
+ $($PXi:ident: ($pxi:ident, $i:expr, $MODE:ty, $moderi:ident, $AFR:ident, $afri:ident,
+ $bsi:ident, $bri:ident, $odri:ident, $idri:ident, $pupdri:ident, $oti:ident, [
+ $($AFi_common:ty: ($into_afi_common:ident, $afi_common:ident,),)*
], [
- $($AFi:ty: ($into_afi:ident, $afi:expr, [$($afi_devices:expr,)*],),)*
+ $($AFi:ty: ($into_afi:ident, $afi:ident, [$($afi_devices:expr,)*],),)*
]),)+
],
},)+
@@ -440,19 +441,8 @@ macro_rules! gpio {
moder: &mut MODER,
afr: &mut $AFR,
) -> $PXi<$AFi_common> {
- let offset = 2 * $i;
-
- // alternate function mode
- let mode = 0b10;
- moder.moder().modify(|r, w| unsafe {
- w.bits((r.bits() & !(0b11 << offset)) | (mode << offset))
- });
-
- let offset = 4 * ($i % 8);
- afr.afr().modify(|r, w| unsafe {
- w.bits((r.bits() & !(0b1111 << offset)) | ($afi_common << offset))
- });
-
+ moder.moder().modify(|_, w| w.$moderi().alternate());
+ afr.afr().modify(|_, w| w.$afri().$afi_common());
$PXi { _mode: PhantomData }
}
)*
@@ -467,19 +457,8 @@ macro_rules! gpio {
moder: &mut MODER,
afr: &mut $AFR,
) -> $PXi<$AFi> {
- let offset = 2 * $i;
-
- // alternate function mode
- let mode = 0b10;
- moder.moder().modify(|r, w| unsafe {
- w.bits((r.bits() & !(0b11 << offset)) | (mode << offset))
- });
-
- let offset = 4 * ($i % 8);
- afr.afr().modify(|r, w| unsafe {
- w.bits((r.bits() & !(0b1111 << offset)) | ($afi << offset))
- });
-
+ moder.moder().modify(|_, w| w.$moderi().alternate());
+ afr.afr().modify(|_, w| w.$afri().$afi());
$PXi { _mode: PhantomData }
}
)*
@@ -490,18 +469,8 @@ macro_rules! gpio {
moder: &mut MODER,
pupdr: &mut PUPDR,
) -> $PXi> {
- let offset = 2 * $i;
-
- // input mode
- moder
- .moder()
- .modify(|r, w| unsafe { w.bits(r.bits() & !(0b11 << offset)) });
-
- // no pull-up or pull-down
- pupdr
- .pupdr()
- .modify(|r, w| unsafe { w.bits(r.bits() & !(0b11 << offset)) });
-
+ moder.moder().modify(|_, w| w.$moderi().input());
+ pupdr.pupdr().modify(|_,w| w.$pupdri().floating());
$PXi { _mode: PhantomData }
}
@@ -511,18 +480,8 @@ macro_rules! gpio {
moder: &mut MODER,
pupdr: &mut PUPDR,
) -> $PXi> {
- let offset = 2 * $i;
-
- // input mode
- moder
- .moder()
- .modify(|r, w| unsafe { w.bits(r.bits() & !(0b11 << offset)) });
-
- // pull-down
- pupdr.pupdr().modify(|r, w| unsafe {
- w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))
- });
-
+ moder.moder().modify(|_, w| w.$moderi().input());
+ pupdr.pupdr().modify(|_,w| w.$pupdri().pull_down());
$PXi { _mode: PhantomData }
}
@@ -532,18 +491,8 @@ macro_rules! gpio {
moder: &mut MODER,
pupdr: &mut PUPDR,
) -> $PXi> {
- let offset = 2 * $i;
-
- // input mode
- moder
- .moder()
- .modify(|r, w| unsafe { w.bits(r.bits() & !(0b11 << offset)) });
-
- // pull-up
- pupdr.pupdr().modify(|r, w| unsafe {
- w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))
- });
-
+ moder.moder().modify(|_, w| w.$moderi().input());
+ pupdr.pupdr().modify(|_,w| w.$pupdri().pull_up());
$PXi { _mode: PhantomData }
}
@@ -553,19 +502,8 @@ macro_rules! gpio {
moder: &mut MODER,
otyper: &mut OTYPER,
) -> $PXi