-
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: use reference of glb RegisterBlock other than struct with Deref…
… to RegisterBlock This change shortens code and number of type generics. Code cleanup, pass tests on all feature gate options. Signed-off-by: Zhouqi Jiang <[email protected]>
- Loading branch information
Showing
24 changed files
with
889 additions
and
780 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 |
---|---|---|
@@ -1,99 +1,95 @@ | ||
use super::{ | ||
convert::{IntoPad, IntoPadv2}, | ||
convert::IntoPad, | ||
input::Input, | ||
output::Output, | ||
typestate::{self, Floating, PullDown, PullUp}, | ||
typestate::{Floating, PullDown, PullUp}, | ||
}; | ||
use crate::glb::RegisterBlock; | ||
use core::ops::Deref; | ||
#[cfg(any(doc, feature = "glb-v2"))] | ||
use super::{convert::IntoPadv2, typestate}; | ||
|
||
/// GPIO pad with alternate mode. | ||
pub struct Alternate<GLB, const N: usize, M> { | ||
inner: super::Inner<GLB, N, M>, | ||
pub struct Alternate<'a, const N: usize, M> { | ||
inner: super::Inner<'a, N, M>, | ||
} | ||
|
||
impl<GLB: Deref<Target = RegisterBlock>, const N: usize, M> IntoPad<GLB, N> | ||
for Alternate<GLB, N, M> | ||
{ | ||
impl<'a, const N: usize, M> IntoPad<'a, N> for Alternate<'a, N, M> { | ||
#[inline] | ||
fn into_pull_up_output(self) -> Output<GLB, N, PullUp> { | ||
fn into_pull_up_output(self) -> Output<'a, N, PullUp> { | ||
self.inner.into_pull_up_output().into() | ||
} | ||
#[inline] | ||
fn into_pull_down_output(self) -> Output<GLB, N, PullDown> { | ||
fn into_pull_down_output(self) -> Output<'a, N, PullDown> { | ||
self.inner.into_pull_down_output().into() | ||
} | ||
#[inline] | ||
fn into_floating_output(self) -> Output<GLB, N, Floating> { | ||
fn into_floating_output(self) -> Output<'a, N, Floating> { | ||
self.inner.into_floating_output().into() | ||
} | ||
#[inline] | ||
fn into_pull_up_input(self) -> Input<GLB, N, PullUp> { | ||
fn into_pull_up_input(self) -> Input<'a, N, PullUp> { | ||
self.inner.into_pull_up_input().into() | ||
} | ||
#[inline] | ||
fn into_pull_down_input(self) -> Input<GLB, N, PullDown> { | ||
fn into_pull_down_input(self) -> Input<'a, N, PullDown> { | ||
self.inner.into_pull_down_input().into() | ||
} | ||
#[inline] | ||
fn into_floating_input(self) -> Input<GLB, N, Floating> { | ||
fn into_floating_input(self) -> Input<'a, 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> | ||
{ | ||
impl<'a, const N: usize, M> IntoPadv2<'a, N> for Alternate<'a, N, M> { | ||
#[inline] | ||
fn into_spi<const I: usize>(self) -> Alternate<GLB, N, typestate::Spi<I>> { | ||
fn into_spi<const I: usize>(self) -> Alternate<'a, N, typestate::Spi<I>> { | ||
self.inner.into_spi().into() | ||
} | ||
#[inline] | ||
fn into_sdh(self) -> Alternate<GLB, N, typestate::Sdh> { | ||
fn into_sdh(self) -> Alternate<'a, N, typestate::Sdh> { | ||
self.inner.into_sdh().into() | ||
} | ||
#[inline] | ||
fn into_uart(self) -> Alternate<GLB, N, typestate::Uart> { | ||
fn into_uart(self) -> Alternate<'a, N, typestate::Uart> { | ||
self.inner.into_uart().into() | ||
} | ||
#[inline] | ||
fn into_mm_uart(self) -> Alternate<GLB, N, typestate::MmUart> { | ||
fn into_mm_uart(self) -> Alternate<'a, 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>> { | ||
fn into_pull_up_pwm<const I: usize>(self) -> Alternate<'a, 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>> { | ||
fn into_pull_down_pwm<const I: usize>(self) -> Alternate<'a, 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>> { | ||
fn into_floating_pwm<const I: usize>(self) -> Alternate<'a, N, typestate::Pwm<I>> { | ||
self.inner.into_floating_pwm().into() | ||
} | ||
#[inline] | ||
fn into_i2c<const I: usize>(self) -> Alternate<GLB, N, typestate::I2c<I>> { | ||
fn into_i2c<const I: usize>(self) -> Alternate<'a, N, typestate::I2c<I>> { | ||
self.inner.into_i2c().into() | ||
} | ||
#[inline] | ||
fn into_jtag_d0(self) -> Alternate<GLB, N, typestate::JtagD0> { | ||
fn into_jtag_d0(self) -> Alternate<'a, N, typestate::JtagD0> { | ||
self.inner.into_jtag_d0().into() | ||
} | ||
#[inline] | ||
fn into_jtag_m0(self) -> Alternate<GLB, N, typestate::JtagM0> { | ||
fn into_jtag_m0(self) -> Alternate<'a, N, typestate::JtagM0> { | ||
self.inner.into_jtag_m0().into() | ||
} | ||
#[inline] | ||
fn into_jtag_lp(self) -> Alternate<GLB, N, typestate::JtagLp> { | ||
fn into_jtag_lp(self) -> Alternate<'a, 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> { | ||
impl<'a, const N: usize, M> From<super::Inner<'a, N, M>> for Alternate<'a, N, M> { | ||
#[inline] | ||
fn from(inner: super::Inner<GLB, N, M>) -> Self { | ||
fn from(inner: super::Inner<'a, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,95 @@ | ||
#[cfg(any(doc, feature = "glb-v2"))] | ||
use super::{alternate::Alternate, convert::IntoPadv2}; | ||
use super::{ | ||
alternate::Alternate, | ||
convert::{IntoPad, IntoPadv2}, | ||
convert::IntoPad, | ||
input::Input, | ||
output::Output, | ||
typestate::{self, Floating, PullDown, PullUp}, | ||
}; | ||
use crate::glb::RegisterBlock; | ||
use core::ops::Deref; | ||
|
||
/// GPIO pad which is disabled. | ||
pub struct Disabled<GLB, const N: usize> { | ||
inner: super::Inner<GLB, N, typestate::Disabled>, | ||
pub struct Disabled<'a, const N: usize> { | ||
inner: super::Inner<'a, N, typestate::Disabled>, | ||
} | ||
|
||
impl<GLB: Deref<Target = RegisterBlock>, const N: usize> IntoPad<GLB, N> for Disabled<GLB, N> { | ||
impl<'a, const N: usize> IntoPad<'a, N> for Disabled<'a, N> { | ||
#[inline] | ||
fn into_pull_up_output(self) -> Output<GLB, N, PullUp> { | ||
fn into_pull_up_output(self) -> Output<'a, N, PullUp> { | ||
self.inner.into_pull_up_output().into() | ||
} | ||
#[inline] | ||
fn into_pull_down_output(self) -> Output<GLB, N, PullDown> { | ||
fn into_pull_down_output(self) -> Output<'a, N, PullDown> { | ||
self.inner.into_pull_down_output().into() | ||
} | ||
#[inline] | ||
fn into_floating_output(self) -> Output<GLB, N, Floating> { | ||
fn into_floating_output(self) -> Output<'a, N, Floating> { | ||
self.inner.into_floating_output().into() | ||
} | ||
#[inline] | ||
fn into_pull_up_input(self) -> Input<GLB, N, PullUp> { | ||
fn into_pull_up_input(self) -> Input<'a, N, PullUp> { | ||
self.inner.into_pull_up_input().into() | ||
} | ||
#[inline] | ||
fn into_pull_down_input(self) -> Input<GLB, N, PullDown> { | ||
fn into_pull_down_input(self) -> Input<'a, N, PullDown> { | ||
self.inner.into_pull_down_input().into() | ||
} | ||
#[inline] | ||
fn into_floating_input(self) -> Input<GLB, N, Floating> { | ||
fn into_floating_input(self) -> Input<'a, N, Floating> { | ||
self.inner.into_floating_input().into() | ||
} | ||
} | ||
|
||
#[cfg(any(doc, feature = "glb-v2"))] | ||
impl<GLB: Deref<Target = RegisterBlock>, const N: usize> IntoPadv2<GLB, N> for Disabled<GLB, N> { | ||
impl<'a, const N: usize> IntoPadv2<'a, N> for Disabled<'a, N> { | ||
#[inline] | ||
fn into_spi<const I: usize>(self) -> Alternate<GLB, N, typestate::Spi<I>> { | ||
fn into_spi<const I: usize>(self) -> Alternate<'a, N, typestate::Spi<I>> { | ||
self.inner.into_spi().into() | ||
} | ||
#[inline] | ||
fn into_sdh(self) -> Alternate<GLB, N, typestate::Sdh> { | ||
fn into_sdh(self) -> Alternate<'a, N, typestate::Sdh> { | ||
self.inner.into_sdh().into() | ||
} | ||
#[inline] | ||
fn into_uart(self) -> Alternate<GLB, N, typestate::Uart> { | ||
fn into_uart(self) -> Alternate<'a, N, typestate::Uart> { | ||
self.inner.into_uart().into() | ||
} | ||
#[inline] | ||
fn into_mm_uart(self) -> Alternate<GLB, N, typestate::MmUart> { | ||
fn into_mm_uart(self) -> Alternate<'a, 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>> { | ||
fn into_pull_up_pwm<const I: usize>(self) -> Alternate<'a, 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>> { | ||
fn into_pull_down_pwm<const I: usize>(self) -> Alternate<'a, 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>> { | ||
fn into_floating_pwm<const I: usize>(self) -> Alternate<'a, N, typestate::Pwm<I>> { | ||
self.inner.into_floating_pwm().into() | ||
} | ||
#[inline] | ||
fn into_i2c<const I: usize>(self) -> Alternate<GLB, N, typestate::I2c<I>> { | ||
fn into_i2c<const I: usize>(self) -> Alternate<'a, N, typestate::I2c<I>> { | ||
self.inner.into_i2c().into() | ||
} | ||
#[inline] | ||
fn into_jtag_d0(self) -> Alternate<GLB, N, typestate::JtagD0> { | ||
fn into_jtag_d0(self) -> Alternate<'a, N, typestate::JtagD0> { | ||
self.inner.into_jtag_d0().into() | ||
} | ||
#[inline] | ||
fn into_jtag_m0(self) -> Alternate<GLB, N, typestate::JtagM0> { | ||
fn into_jtag_m0(self) -> Alternate<'a, N, typestate::JtagM0> { | ||
self.inner.into_jtag_m0().into() | ||
} | ||
#[inline] | ||
fn into_jtag_lp(self) -> Alternate<GLB, N, typestate::JtagLp> { | ||
fn into_jtag_lp(self) -> Alternate<'a, N, typestate::JtagLp> { | ||
self.inner.into_jtag_lp().into() | ||
} | ||
} | ||
|
||
impl<GLB, const N: usize> From<super::Inner<GLB, N, typestate::Disabled>> for Disabled<GLB, N> { | ||
impl<'a, const N: usize> From<super::Inner<'a, N, typestate::Disabled>> for Disabled<'a, N> { | ||
#[inline] | ||
fn from(inner: super::Inner<GLB, N, typestate::Disabled>) -> Self { | ||
fn from(inner: super::Inner<'a, N, typestate::Disabled>) -> Self { | ||
Self { inner } | ||
} | ||
} |
Oops, something went wrong.