-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gpio: rearrange Pad into Alternate and other structures
Simplify inner structures into `Inner` struct. Now struct Pad is split into Disabled, Input, Output and Alternate structures to make code clearer. Signed-off-by: Zhouqi Jiang <[email protected]>
- Loading branch information
Showing
11 changed files
with
668 additions
and
623 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
use super::{ | ||
convert::{IntoPad, IntoPadv2}, | ||
Check warning on line 2 in bouffalo-hal/src/gpio/alternate.rs GitHub Actions / Test (bouffalo-hal)
|
||
input::Input, | ||
output::Output, | ||
typestate::{self, Floating, PullDown, PullUp}, | ||
}; | ||
use crate::glb::RegisterBlock; | ||
use core::ops::Deref; | ||
|
||
/// GPIO pad with alternate mode. | ||
pub struct Alternate<GLB, const N: usize, M> { | ||
inner: super::Inner<GLB, N, M>, | ||
} | ||
|
||
impl<GLB: Deref<Target = RegisterBlock>, const N: usize, M> IntoPad<GLB, N> | ||
for Alternate<GLB, N, M> | ||
{ | ||
#[inline] | ||
fn into_pull_up_output(self) -> Output<GLB, N, PullUp> { | ||
self.inner.into_pull_up_output().into() | ||
} | ||
#[inline] | ||
fn into_pull_down_output(self) -> Output<GLB, N, PullDown> { | ||
self.inner.into_pull_down_output().into() | ||
} | ||
#[inline] | ||
fn into_floating_output(self) -> Output<GLB, N, Floating> { | ||
self.inner.into_floating_output().into() | ||
} | ||
#[inline] | ||
fn into_pull_up_input(self) -> Input<GLB, N, PullUp> { | ||
self.inner.into_pull_up_input().into() | ||
} | ||
#[inline] | ||
fn into_pull_down_input(self) -> Input<GLB, N, PullDown> { | ||
self.inner.into_pull_down_input().into() | ||
} | ||
#[inline] | ||
fn into_floating_input(self) -> Input<GLB, N, Floating> { | ||
self.inner.into_floating_input().into() | ||
} | ||
} | ||
|
||
#[cfg(any(doc, feature = "glb-v2"))] | ||
impl<GLB: Deref<Target = RegisterBlock>, const N: usize, M> IntoPadv2<GLB, N> | ||
for Alternate<GLB, N, M> | ||
{ | ||
#[inline] | ||
fn into_spi<const I: usize>(self) -> Alternate<GLB, N, typestate::Spi<I>> { | ||
self.inner.into_spi().into() | ||
} | ||
#[inline] | ||
fn into_sdh(self) -> Alternate<GLB, N, typestate::Sdh> { | ||
self.inner.into_sdh().into() | ||
} | ||
#[inline] | ||
fn into_uart(self) -> Alternate<GLB, N, typestate::Uart> { | ||
self.inner.into_uart().into() | ||
} | ||
#[inline] | ||
fn into_mm_uart(self) -> Alternate<GLB, N, typestate::MmUart> { | ||
self.inner.into_mm_uart().into() | ||
} | ||
#[inline] | ||
fn into_pull_up_pwm<const I: usize>(self) -> Alternate<GLB, N, typestate::Pwm<I>> { | ||
self.inner.into_pull_up_pwm().into() | ||
} | ||
#[inline] | ||
fn into_pull_down_pwm<const I: usize>(self) -> Alternate<GLB, N, typestate::Pwm<I>> { | ||
self.inner.into_pull_down_pwm().into() | ||
} | ||
#[inline] | ||
fn into_floating_pwm<const I: usize>(self) -> Alternate<GLB, N, typestate::Pwm<I>> { | ||
self.inner.into_floating_pwm().into() | ||
} | ||
#[inline] | ||
fn into_i2c<const I: usize>(self) -> Alternate<GLB, N, typestate::I2c<I>> { | ||
self.inner.into_i2c().into() | ||
} | ||
#[inline] | ||
fn into_jtag_d0(self) -> Alternate<GLB, N, typestate::JtagD0> { | ||
self.inner.into_jtag_d0().into() | ||
} | ||
#[inline] | ||
fn into_jtag_m0(self) -> Alternate<GLB, N, typestate::JtagM0> { | ||
self.inner.into_jtag_m0().into() | ||
} | ||
#[inline] | ||
fn into_jtag_lp(self) -> Alternate<GLB, N, typestate::JtagLp> { | ||
self.inner.into_jtag_lp().into() | ||
} | ||
} | ||
|
||
impl<GLB, const N: usize, M> From<super::Inner<GLB, N, M>> for Alternate<GLB, N, M> { | ||
#[inline] | ||
fn from(inner: super::Inner<GLB, N, M>) -> Self { | ||
Self { inner } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.