feat(pin): implement static pin struct (MAYBE WILL BE REMOVED)
This commit is contained in:
parent
610a1f7bc0
commit
c0ff27a40e
|
@ -1,5 +1,64 @@
|
|||
use arduino_hal::{hal::port::*, pac::*};
|
||||
|
||||
pub struct StaticPin<T, P>
|
||||
where
|
||||
P: StaticPinOps + PinOps,
|
||||
T: PinMode,
|
||||
{
|
||||
_p: Pin<T, P>,
|
||||
}
|
||||
|
||||
impl<T, P> StaticPin<T, P>
|
||||
where
|
||||
P: StaticPinOps + PinOps,
|
||||
T: PinMode,
|
||||
{
|
||||
#[inline]
|
||||
pub fn new(_p: Pin<T, P>) -> Self {
|
||||
Self { _p }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_high(&self) -> bool {
|
||||
!self.is_low()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_low(&self) -> bool {
|
||||
P::read() & (1 << P::PIN_NUM) == 0
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_high(&self) {
|
||||
P::write(P::read() | (1 << P::PIN_NUM));
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_low(&self) {
|
||||
P::write(P::read() & !(1 << P::PIN_NUM));
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn toggle(&self) {
|
||||
P::write(P::read() ^ (1 << P::PIN_NUM));
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn into_output(&self) {
|
||||
P::into_output();
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn into_pull_up_input(&self) {
|
||||
P::into_pull_up_input();
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn into_input(&self) {
|
||||
P::into_input();
|
||||
}
|
||||
}
|
||||
|
||||
impl_static_pins!(
|
||||
PB0, PB1, PB2, PB3, PB4, PB5, PB6, PB7, PC6, PC7, PD0, PD1, PD2, PD3, PD4, PD5, PD6, PD7, PE2,
|
||||
PE6, PF0, PF1, PF4, PF5, PF6, PF7
|
||||
|
|
Loading…
Reference in New Issue