2022-07-03 21:54:01 +00:00
|
|
|
#![macro_use]
|
2022-07-10 04:47:08 +00:00
|
|
|
use core::future::Future;
|
|
|
|
use core::pin::Pin as FuturePin;
|
|
|
|
use core::task::{Context, Poll};
|
2021-03-29 02:11:32 +00:00
|
|
|
|
2022-07-10 04:47:08 +00:00
|
|
|
use embassy::waitqueue::AtomicWaker;
|
|
|
|
use embassy_cortex_m::interrupt::{Interrupt, InterruptExt};
|
2022-07-22 20:00:12 +00:00
|
|
|
use embassy_hal_common::{impl_unborrow, unborrow, Unborrowed};
|
2022-06-12 20:15:44 +00:00
|
|
|
|
2021-06-25 01:38:03 +00:00
|
|
|
use crate::pac::common::{Reg, RW};
|
2021-03-29 02:11:32 +00:00
|
|
|
use crate::pac::SIO;
|
2022-07-10 04:47:08 +00:00
|
|
|
use crate::{interrupt, pac, peripherals, Unborrow};
|
|
|
|
|
|
|
|
const PIN_COUNT: usize = 30;
|
|
|
|
const NEW_AW: AtomicWaker = AtomicWaker::new();
|
|
|
|
static INTERRUPT_WAKERS: [AtomicWaker; PIN_COUNT] = [NEW_AW; PIN_COUNT];
|
2021-03-29 02:11:32 +00:00
|
|
|
|
|
|
|
/// Represents a digital input or output level.
|
|
|
|
#[derive(Debug, Eq, PartialEq)]
|
|
|
|
pub enum Level {
|
|
|
|
Low,
|
|
|
|
High,
|
|
|
|
}
|
|
|
|
|
2022-07-12 23:22:46 +00:00
|
|
|
impl From<bool> for Level {
|
|
|
|
fn from(val: bool) -> Self {
|
|
|
|
match val {
|
|
|
|
true => Self::High,
|
|
|
|
false => Self::Low,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Into<bool> for Level {
|
|
|
|
fn into(self) -> bool {
|
|
|
|
match self {
|
|
|
|
Level::Low => false,
|
|
|
|
Level::High => true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-29 02:11:32 +00:00
|
|
|
/// Represents a pull setting for an input.
|
|
|
|
#[derive(Debug, Eq, PartialEq)]
|
|
|
|
pub enum Pull {
|
|
|
|
None,
|
|
|
|
Up,
|
|
|
|
Down,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A GPIO bank with up to 32 pins.
|
|
|
|
#[derive(Debug, Eq, PartialEq)]
|
|
|
|
pub enum Bank {
|
|
|
|
Bank0 = 0,
|
|
|
|
Qspi = 1,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Input<'d, T: Pin> {
|
2022-07-09 00:12:17 +00:00
|
|
|
pin: Flex<'d, T>,
|
2021-03-29 02:11:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'d, T: Pin> Input<'d, T> {
|
2022-07-12 23:22:46 +00:00
|
|
|
#[inline]
|
2021-04-14 17:59:52 +00:00
|
|
|
pub fn new(pin: impl Unborrow<Target = T> + 'd, pull: Pull) -> Self {
|
2022-07-09 00:12:17 +00:00
|
|
|
let mut pin = Flex::new(pin);
|
|
|
|
pin.set_as_input();
|
|
|
|
pin.set_pull(pull);
|
|
|
|
Self { pin }
|
2021-03-29 02:11:32 +00:00
|
|
|
}
|
2021-06-25 04:20:45 +00:00
|
|
|
|
2022-07-12 23:22:46 +00:00
|
|
|
#[inline]
|
2021-06-25 04:20:45 +00:00
|
|
|
pub fn is_high(&self) -> bool {
|
2022-07-09 00:12:17 +00:00
|
|
|
self.pin.is_high()
|
2021-06-25 04:20:45 +00:00
|
|
|
}
|
|
|
|
|
2022-07-12 23:22:46 +00:00
|
|
|
#[inline]
|
2021-06-25 04:20:45 +00:00
|
|
|
pub fn is_low(&self) -> bool {
|
2022-07-09 00:12:17 +00:00
|
|
|
self.pin.is_low()
|
2021-03-29 02:11:32 +00:00
|
|
|
}
|
2022-07-12 23:22:46 +00:00
|
|
|
|
|
|
|
/// Returns current pin level
|
|
|
|
#[inline]
|
|
|
|
pub fn get_level(&self) -> Level {
|
2022-07-12 23:45:37 +00:00
|
|
|
self.pin.get_level()
|
2022-07-12 23:22:46 +00:00
|
|
|
}
|
2022-07-10 04:47:08 +00:00
|
|
|
|
2022-07-22 05:09:26 +00:00
|
|
|
#[inline]
|
2022-07-10 04:47:08 +00:00
|
|
|
pub async fn wait_for_high<'a>(&mut self) {
|
|
|
|
self.pin.wait_for_high().await;
|
|
|
|
}
|
|
|
|
|
2022-07-22 05:09:26 +00:00
|
|
|
#[inline]
|
2022-07-10 04:47:08 +00:00
|
|
|
pub async fn wait_for_low<'a>(&mut self) {
|
|
|
|
self.pin.wait_for_low().await;
|
|
|
|
}
|
|
|
|
|
2022-07-22 05:09:26 +00:00
|
|
|
#[inline]
|
2022-07-10 04:47:08 +00:00
|
|
|
pub async fn wait_for_rising_edge<'a>(&mut self) {
|
|
|
|
self.pin.wait_for_rising_edge().await;
|
|
|
|
}
|
|
|
|
|
2022-07-22 05:09:26 +00:00
|
|
|
#[inline]
|
2022-07-10 04:47:08 +00:00
|
|
|
pub async fn wait_for_falling_edge<'a>(&mut self) {
|
|
|
|
self.pin.wait_for_falling_edge().await;
|
|
|
|
}
|
|
|
|
|
2022-07-22 05:09:26 +00:00
|
|
|
#[inline]
|
2022-07-10 04:47:08 +00:00
|
|
|
pub async fn wait_for_any_edge<'a>(&mut self) {
|
|
|
|
self.pin.wait_for_any_edge().await;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Interrupt trigger levels.
|
|
|
|
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
|
|
|
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
|
|
|
pub enum InterruptTrigger {
|
|
|
|
LevelLow,
|
|
|
|
LevelHigh,
|
|
|
|
EdgeLow,
|
|
|
|
EdgeHigh,
|
|
|
|
AnyEdge,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl InterruptTrigger {
|
|
|
|
fn from_u32(value: u32) -> Option<InterruptTrigger> {
|
|
|
|
match value {
|
|
|
|
1 => Some(InterruptTrigger::LevelLow),
|
|
|
|
2 => Some(InterruptTrigger::LevelHigh),
|
|
|
|
3 => Some(InterruptTrigger::EdgeLow),
|
|
|
|
4 => Some(InterruptTrigger::EdgeHigh),
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[interrupt]
|
|
|
|
unsafe fn IO_IRQ_BANK0() {
|
|
|
|
let cpu = SIO.cpuid().read() as usize;
|
|
|
|
// There are two sets of interrupt registers, one for cpu0 and one for cpu1
|
|
|
|
// and here we are selecting the set that belongs to the currently executing
|
|
|
|
// cpu.
|
|
|
|
let proc_intx: pac::io::Int = pac::IO_BANK0.int_proc(cpu);
|
|
|
|
for pin in 0..PIN_COUNT {
|
|
|
|
// There are 4 raw interrupt status registers, PROCx_INTS0, PROCx_INTS1,
|
|
|
|
// PROCx_INTS2, and PROCx_INTS3, and we are selecting the one that the
|
|
|
|
// current pin belongs to.
|
|
|
|
let intsx = proc_intx.ints(pin / 8);
|
|
|
|
// The status register is divided into groups of four, one group for
|
|
|
|
// each pin. Each group consists of four trigger levels LEVEL_LOW,
|
|
|
|
// LEVEL_HIGH, EDGE_LOW, and EDGE_HIGH for each pin.
|
|
|
|
let pin_group = (pin % 8) as usize;
|
|
|
|
let event = (intsx.read().0 >> pin_group * 4) & 0xf as u32;
|
|
|
|
|
|
|
|
if let Some(trigger) = InterruptTrigger::from_u32(event) {
|
|
|
|
proc_intx.inte(pin / 8).write(|w| match trigger {
|
|
|
|
InterruptTrigger::AnyEdge => {
|
|
|
|
w.set_edge_high(pin_group, false);
|
|
|
|
w.set_edge_low(pin_group, false);
|
|
|
|
}
|
|
|
|
InterruptTrigger::LevelHigh => {
|
|
|
|
debug!("IO_IRQ_BANK0 pin {} LevelHigh triggered\n", pin);
|
|
|
|
w.set_level_high(pin_group, false);
|
|
|
|
}
|
|
|
|
InterruptTrigger::LevelLow => {
|
|
|
|
w.set_level_low(pin_group, false);
|
|
|
|
}
|
|
|
|
InterruptTrigger::EdgeHigh => {
|
|
|
|
w.set_edge_high(pin_group, false);
|
|
|
|
}
|
|
|
|
InterruptTrigger::EdgeLow => {
|
|
|
|
w.set_edge_low(pin_group, false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
INTERRUPT_WAKERS[pin as usize].wake();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct InputFuture<'a, T: Pin> {
|
2022-07-03 21:54:01 +00:00
|
|
|
pin: Unborrowed<'a, T>,
|
2022-07-10 04:47:08 +00:00
|
|
|
level: InterruptTrigger,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'d, T: Pin> InputFuture<'d, T> {
|
2022-07-03 21:54:01 +00:00
|
|
|
pub fn new(pin: impl Unborrow<Target = T> + 'd, level: InterruptTrigger) -> Self {
|
|
|
|
unborrow!(pin);
|
2022-07-10 04:47:08 +00:00
|
|
|
unsafe {
|
|
|
|
let irq = interrupt::IO_IRQ_BANK0::steal();
|
|
|
|
irq.disable();
|
|
|
|
irq.set_priority(interrupt::Priority::P6);
|
|
|
|
|
|
|
|
// Each INTR register is divided into 8 groups, one group for each
|
|
|
|
// pin, and each group consists of LEVEL_LOW, LEVEL_HIGH, EDGE_LOW,
|
|
|
|
// and EGDE_HIGH.
|
|
|
|
let pin_group = (pin.pin() % 8) as usize;
|
|
|
|
pin.int_proc().inte((pin.pin() / 8) as usize).write(|w| match level {
|
|
|
|
InterruptTrigger::LevelHigh => {
|
|
|
|
debug!("InputFuture::new enable LevelHigh for pin {} \n", pin.pin());
|
|
|
|
w.set_level_high(pin_group, true);
|
|
|
|
}
|
|
|
|
InterruptTrigger::LevelLow => {
|
|
|
|
w.set_level_low(pin_group, true);
|
|
|
|
}
|
|
|
|
InterruptTrigger::EdgeHigh => {
|
|
|
|
w.set_edge_high(pin_group, true);
|
|
|
|
}
|
|
|
|
InterruptTrigger::EdgeLow => {
|
|
|
|
w.set_edge_low(pin_group, true);
|
|
|
|
}
|
|
|
|
InterruptTrigger::AnyEdge => {
|
|
|
|
// noop
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
irq.enable();
|
|
|
|
}
|
|
|
|
|
2022-07-03 21:54:01 +00:00
|
|
|
Self { pin, level }
|
2022-07-10 04:47:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'d, T: Pin> Future for InputFuture<'d, T> {
|
|
|
|
type Output = ();
|
|
|
|
|
|
|
|
fn poll(self: FuturePin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
|
|
|
// We need to register/re-register the waker for each poll because any
|
|
|
|
// calls to wake will deregister the waker.
|
|
|
|
INTERRUPT_WAKERS[self.pin.pin() as usize].register(cx.waker());
|
|
|
|
|
|
|
|
// self.int_proc() will get the register offset for the current cpu,
|
|
|
|
// then we want to access the interrupt enable register for our
|
|
|
|
// pin (there are 4 of these PROC0_INTE0, PROC0_INTE1, PROC0_INTE2, and
|
|
|
|
// PROC0_INTE3 per cpu).
|
|
|
|
let inte: pac::io::regs::Int = unsafe { self.pin.int_proc().inte((self.pin.pin() / 8) as usize).read() };
|
|
|
|
// The register is divided into groups of four, one group for
|
|
|
|
// each pin. Each group consists of four trigger levels LEVEL_LOW,
|
|
|
|
// LEVEL_HIGH, EDGE_LOW, and EDGE_HIGH for each pin.
|
|
|
|
let pin_group = (self.pin.pin() % 8) as usize;
|
|
|
|
|
|
|
|
// This should check the the level of the interrupt trigger level of
|
|
|
|
// the pin and if it has been disabled that means it was done by the
|
|
|
|
// interrupt service routine, so we then know that the event/trigger
|
|
|
|
// happened and Poll::Ready will be returned.
|
|
|
|
debug!("{:?} for pin {}\n", self.level, self.pin.pin());
|
|
|
|
match self.level {
|
|
|
|
InterruptTrigger::AnyEdge => {
|
|
|
|
if !inte.edge_high(pin_group) && !inte.edge_low(pin_group) {
|
|
|
|
#[rustfmt::skip]
|
|
|
|
debug!("{:?} for pin {} was cleared, return Poll::Ready\n", self.level, self.pin.pin());
|
|
|
|
return Poll::Ready(());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
InterruptTrigger::LevelHigh => {
|
|
|
|
if !inte.level_high(pin_group) {
|
|
|
|
#[rustfmt::skip]
|
|
|
|
debug!("{:?} for pin {} was cleared, return Poll::Ready\n", self.level, self.pin.pin());
|
|
|
|
return Poll::Ready(());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
InterruptTrigger::LevelLow => {
|
|
|
|
if !inte.level_low(pin_group) {
|
|
|
|
#[rustfmt::skip]
|
|
|
|
debug!("{:?} for pin {} was cleared, return Poll::Ready\n", self.level, self.pin.pin());
|
|
|
|
return Poll::Ready(());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
InterruptTrigger::EdgeHigh => {
|
|
|
|
if !inte.edge_high(pin_group) {
|
|
|
|
#[rustfmt::skip]
|
|
|
|
debug!("{:?} for pin {} was cleared, return Poll::Ready\n", self.level, self.pin.pin());
|
|
|
|
return Poll::Ready(());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
InterruptTrigger::EdgeLow => {
|
|
|
|
if !inte.edge_low(pin_group) {
|
|
|
|
#[rustfmt::skip]
|
|
|
|
debug!("{:?} for pin {} was cleared, return Poll::Ready\n", self.level, self.pin.pin());
|
|
|
|
return Poll::Ready(());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
debug!("InputFuture::poll return Poll::Pending\n");
|
|
|
|
Poll::Pending
|
|
|
|
}
|
2021-03-29 02:11:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Output<'d, T: Pin> {
|
2022-07-09 00:12:17 +00:00
|
|
|
pin: Flex<'d, T>,
|
2021-03-29 02:11:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'d, T: Pin> Output<'d, T> {
|
2022-07-09 00:12:17 +00:00
|
|
|
#[inline]
|
2021-04-14 17:59:52 +00:00
|
|
|
pub fn new(pin: impl Unborrow<Target = T> + 'd, initial_output: Level) -> Self {
|
2022-07-09 00:12:17 +00:00
|
|
|
let mut pin = Flex::new(pin);
|
|
|
|
match initial_output {
|
|
|
|
Level::High => pin.set_high(),
|
|
|
|
Level::Low => pin.set_low(),
|
2021-03-29 02:11:32 +00:00
|
|
|
}
|
|
|
|
|
2022-07-09 00:12:17 +00:00
|
|
|
pin.set_as_output();
|
|
|
|
Self { pin }
|
2021-03-29 02:11:32 +00:00
|
|
|
}
|
2021-06-25 04:20:45 +00:00
|
|
|
|
|
|
|
/// Set the output as high.
|
2022-07-09 00:12:17 +00:00
|
|
|
#[inline]
|
2021-06-25 04:20:45 +00:00
|
|
|
pub fn set_high(&mut self) {
|
2022-07-09 00:12:17 +00:00
|
|
|
self.pin.set_high()
|
2021-06-25 04:20:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Set the output as low.
|
2022-07-09 00:12:17 +00:00
|
|
|
#[inline]
|
2021-06-25 04:20:45 +00:00
|
|
|
pub fn set_low(&mut self) {
|
2022-07-09 00:12:17 +00:00
|
|
|
self.pin.set_low()
|
2021-06-25 04:20:45 +00:00
|
|
|
}
|
|
|
|
|
2022-07-12 23:22:46 +00:00
|
|
|
/// Set the output level.
|
|
|
|
#[inline]
|
|
|
|
pub fn set_level(&mut self, level: Level) {
|
2022-07-12 23:45:37 +00:00
|
|
|
self.pin.set_level(level)
|
2022-07-12 23:22:46 +00:00
|
|
|
}
|
|
|
|
|
2021-06-25 04:20:45 +00:00
|
|
|
/// Is the output pin set as high?
|
2022-07-09 00:12:17 +00:00
|
|
|
#[inline]
|
2021-06-25 04:20:45 +00:00
|
|
|
pub fn is_set_high(&self) -> bool {
|
2022-07-09 00:12:17 +00:00
|
|
|
self.pin.is_set_high()
|
2021-06-25 04:20:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Is the output pin set as low?
|
2022-07-09 00:12:17 +00:00
|
|
|
#[inline]
|
2021-06-25 04:20:45 +00:00
|
|
|
pub fn is_set_low(&self) -> bool {
|
2022-07-09 00:12:17 +00:00
|
|
|
self.pin.is_set_low()
|
2021-06-25 04:20:45 +00:00
|
|
|
}
|
2022-05-19 03:33:42 +00:00
|
|
|
|
2022-07-12 23:22:46 +00:00
|
|
|
/// What level output is set to
|
|
|
|
#[inline]
|
2022-07-12 23:25:09 +00:00
|
|
|
pub fn get_output_level(&self) -> Level {
|
2022-07-12 23:45:37 +00:00
|
|
|
self.pin.get_output_level()
|
2022-07-12 23:22:46 +00:00
|
|
|
}
|
|
|
|
|
2022-05-19 03:33:42 +00:00
|
|
|
/// Toggle pin output
|
|
|
|
#[inline]
|
|
|
|
pub fn toggle(&mut self) {
|
2022-07-09 00:12:17 +00:00
|
|
|
self.pin.toggle()
|
2022-05-19 03:33:42 +00:00
|
|
|
}
|
2021-03-29 02:11:32 +00:00
|
|
|
}
|
|
|
|
|
2022-07-09 00:12:17 +00:00
|
|
|
/// GPIO output open-drain.
|
|
|
|
pub struct OutputOpenDrain<'d, T: Pin> {
|
|
|
|
pin: Flex<'d, T>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'d, T: Pin> OutputOpenDrain<'d, T> {
|
|
|
|
#[inline]
|
|
|
|
pub fn new(pin: impl Unborrow<Target = T> + 'd, initial_output: Level) -> Self {
|
|
|
|
let mut pin = Flex::new(pin);
|
|
|
|
pin.set_low();
|
|
|
|
match initial_output {
|
|
|
|
Level::High => pin.set_as_input(),
|
|
|
|
Level::Low => pin.set_as_output(),
|
|
|
|
}
|
|
|
|
Self { pin }
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Set the output as high.
|
|
|
|
#[inline]
|
|
|
|
pub fn set_high(&mut self) {
|
|
|
|
// For Open Drain High, disable the output pin.
|
|
|
|
self.pin.set_as_input()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Set the output as low.
|
|
|
|
#[inline]
|
|
|
|
pub fn set_low(&mut self) {
|
|
|
|
// For Open Drain Low, enable the output pin.
|
|
|
|
self.pin.set_as_output()
|
|
|
|
}
|
|
|
|
|
2022-07-12 23:22:46 +00:00
|
|
|
/// Set the output level.
|
|
|
|
#[inline]
|
|
|
|
pub fn set_level(&mut self, level: Level) {
|
|
|
|
match level {
|
|
|
|
Level::Low => self.set_low(),
|
|
|
|
Level::High => self.set_high(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-09 00:12:17 +00:00
|
|
|
/// Is the output level high?
|
|
|
|
#[inline]
|
|
|
|
pub fn is_set_high(&self) -> bool {
|
|
|
|
!self.is_set_low()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Is the output level low?
|
|
|
|
#[inline]
|
|
|
|
pub fn is_set_low(&self) -> bool {
|
|
|
|
self.pin.is_set_as_output()
|
|
|
|
}
|
|
|
|
|
2022-07-12 23:22:46 +00:00
|
|
|
/// What level output is set to
|
|
|
|
#[inline]
|
2022-07-12 23:25:09 +00:00
|
|
|
pub fn get_output_level(&self) -> Level {
|
2022-07-12 23:22:46 +00:00
|
|
|
self.is_set_high().into()
|
|
|
|
}
|
|
|
|
|
2022-07-09 00:12:17 +00:00
|
|
|
/// Toggle pin output
|
|
|
|
#[inline]
|
|
|
|
pub fn toggle(&mut self) {
|
|
|
|
self.pin.toggle_set_as_output()
|
2021-03-29 02:11:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-09 00:12:17 +00:00
|
|
|
/// GPIO flexible pin.
|
|
|
|
///
|
|
|
|
/// This pin can be either an input or output pin. The output level register bit will remain
|
|
|
|
/// set while not in output mode, so the pin's level will be 'remembered' when it is not in output
|
|
|
|
/// mode.
|
|
|
|
pub struct Flex<'d, T: Pin> {
|
2022-07-03 21:54:01 +00:00
|
|
|
pin: Unborrowed<'d, T>,
|
2022-05-13 13:19:03 +00:00
|
|
|
}
|
|
|
|
|
2022-07-09 00:12:17 +00:00
|
|
|
impl<'d, T: Pin> Flex<'d, T> {
|
2022-05-13 13:19:03 +00:00
|
|
|
#[inline]
|
2022-07-09 00:12:17 +00:00
|
|
|
pub fn new(pin: impl Unborrow<Target = T> + 'd) -> Self {
|
2022-05-13 13:19:03 +00:00
|
|
|
unborrow!(pin);
|
|
|
|
|
|
|
|
unsafe {
|
2022-07-09 00:12:17 +00:00
|
|
|
pin.pad_ctrl().write(|w| {
|
|
|
|
w.set_ie(true);
|
|
|
|
});
|
|
|
|
|
2022-05-13 13:19:03 +00:00
|
|
|
pin.io().ctrl().write(|w| {
|
|
|
|
w.set_funcsel(pac::io::vals::Gpio0CtrlFuncsel::SIO_0.0);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-07-03 21:54:01 +00:00
|
|
|
Self { pin }
|
2022-05-13 13:19:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2022-07-09 00:12:17 +00:00
|
|
|
fn bit(&self) -> u32 {
|
|
|
|
1 << self.pin.pin()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Set the pin's pull.
|
|
|
|
#[inline]
|
|
|
|
pub fn set_pull(&mut self, pull: Pull) {
|
2022-05-13 13:19:03 +00:00
|
|
|
unsafe {
|
2022-07-09 00:12:17 +00:00
|
|
|
self.pin.pad_ctrl().write(|w| {
|
|
|
|
w.set_ie(true);
|
|
|
|
match pull {
|
|
|
|
Pull::Up => w.set_pue(true),
|
|
|
|
Pull::Down => w.set_pde(true),
|
|
|
|
Pull::None => {}
|
|
|
|
}
|
|
|
|
});
|
2022-05-13 13:19:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-09 00:12:17 +00:00
|
|
|
/// Put the pin into input mode.
|
|
|
|
///
|
|
|
|
/// The pull setting is left unchanged.
|
|
|
|
#[inline]
|
|
|
|
pub fn set_as_input(&mut self) {
|
|
|
|
unsafe { self.pin.sio_oe().value_clr().write_value(self.bit()) }
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Put the pin into output mode.
|
|
|
|
///
|
|
|
|
/// The pin level will be whatever was set before (or low by default). If you want it to begin
|
|
|
|
/// at a specific level, call `set_high`/`set_low` on the pin first.
|
|
|
|
#[inline]
|
|
|
|
pub fn set_as_output(&mut self) {
|
|
|
|
unsafe { self.pin.sio_oe().value_set().write_value(self.bit()) }
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn is_set_as_output(&self) -> bool {
|
|
|
|
unsafe { (self.pin.sio_oe().value().read() & self.bit()) != 0 }
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
pub fn toggle_set_as_output(&mut self) {
|
|
|
|
unsafe { self.pin.sio_oe().value_xor().write_value(self.bit()) }
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
pub fn is_high(&self) -> bool {
|
|
|
|
!self.is_low()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
pub fn is_low(&self) -> bool {
|
|
|
|
unsafe { self.pin.sio_in().read() & self.bit() == 0 }
|
|
|
|
}
|
|
|
|
|
2022-07-12 23:22:46 +00:00
|
|
|
/// Returns current pin level
|
|
|
|
#[inline]
|
|
|
|
pub fn get_level(&self) -> Level {
|
|
|
|
self.is_high().into()
|
|
|
|
}
|
|
|
|
|
2022-07-09 00:12:17 +00:00
|
|
|
/// Set the output as high.
|
|
|
|
#[inline]
|
|
|
|
pub fn set_high(&mut self) {
|
|
|
|
unsafe { self.pin.sio_out().value_set().write_value(self.bit()) }
|
|
|
|
}
|
|
|
|
|
2022-05-13 13:19:03 +00:00
|
|
|
/// Set the output as low.
|
|
|
|
#[inline]
|
|
|
|
pub fn set_low(&mut self) {
|
2022-07-09 00:12:17 +00:00
|
|
|
unsafe { self.pin.sio_out().value_clr().write_value(self.bit()) }
|
2022-05-13 13:19:03 +00:00
|
|
|
}
|
|
|
|
|
2022-07-12 23:22:46 +00:00
|
|
|
/// Set the output level.
|
|
|
|
#[inline]
|
|
|
|
pub fn set_level(&mut self, level: Level) {
|
|
|
|
match level {
|
|
|
|
Level::Low => self.set_low(),
|
|
|
|
Level::High => self.set_high(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-13 13:19:03 +00:00
|
|
|
/// Is the output level high?
|
|
|
|
#[inline]
|
|
|
|
pub fn is_set_high(&self) -> bool {
|
2022-07-09 00:12:17 +00:00
|
|
|
unsafe { (self.pin.sio_out().value().read() & self.bit()) == 0 }
|
2022-05-13 13:19:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Is the output level low?
|
|
|
|
#[inline]
|
|
|
|
pub fn is_set_low(&self) -> bool {
|
|
|
|
!self.is_set_high()
|
|
|
|
}
|
|
|
|
|
2022-07-12 23:22:46 +00:00
|
|
|
/// What level output is set to
|
|
|
|
#[inline]
|
2022-07-12 23:25:09 +00:00
|
|
|
pub fn get_output_level(&self) -> Level {
|
2022-07-12 23:22:46 +00:00
|
|
|
self.is_set_high().into()
|
|
|
|
}
|
|
|
|
|
2022-05-13 13:19:03 +00:00
|
|
|
/// Toggle pin output
|
|
|
|
#[inline]
|
|
|
|
pub fn toggle(&mut self) {
|
2022-07-09 00:12:17 +00:00
|
|
|
unsafe { self.pin.sio_out().value_xor().write_value(self.bit()) }
|
|
|
|
}
|
2022-07-10 04:47:08 +00:00
|
|
|
|
2022-07-22 05:09:26 +00:00
|
|
|
#[inline]
|
2022-07-10 04:47:08 +00:00
|
|
|
pub async fn wait_for_high<'a>(&mut self) {
|
|
|
|
InputFuture::new(&mut self.pin, InterruptTrigger::LevelHigh).await;
|
|
|
|
}
|
|
|
|
|
2022-07-22 05:09:26 +00:00
|
|
|
#[inline]
|
2022-07-10 04:47:08 +00:00
|
|
|
pub async fn wait_for_low<'a>(&mut self) {
|
|
|
|
InputFuture::new(&mut self.pin, InterruptTrigger::LevelLow).await;
|
|
|
|
}
|
|
|
|
|
2022-07-22 05:09:26 +00:00
|
|
|
#[inline]
|
2022-07-10 04:47:08 +00:00
|
|
|
pub async fn wait_for_rising_edge<'a>(&mut self) {
|
|
|
|
self.wait_for_low().await;
|
|
|
|
self.wait_for_high().await;
|
|
|
|
}
|
|
|
|
|
2022-07-22 05:09:26 +00:00
|
|
|
#[inline]
|
2022-07-10 04:47:08 +00:00
|
|
|
pub async fn wait_for_falling_edge<'a>(&mut self) {
|
|
|
|
self.wait_for_high().await;
|
|
|
|
self.wait_for_low().await;
|
|
|
|
}
|
|
|
|
|
2022-07-22 05:09:26 +00:00
|
|
|
#[inline]
|
2022-07-10 04:47:08 +00:00
|
|
|
pub async fn wait_for_any_edge<'a>(&mut self) {
|
|
|
|
if self.is_high() {
|
|
|
|
self.wait_for_low().await;
|
|
|
|
} else {
|
|
|
|
self.wait_for_high().await;
|
|
|
|
}
|
|
|
|
}
|
2022-07-09 00:12:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'d, T: Pin> Drop for Flex<'d, T> {
|
|
|
|
#[inline]
|
|
|
|
fn drop(&mut self) {
|
2022-05-13 13:19:03 +00:00
|
|
|
unsafe {
|
2022-07-09 00:12:17 +00:00
|
|
|
self.pin.pad_ctrl().write(|_| {});
|
|
|
|
self.pin.io().ctrl().write(|w| {
|
|
|
|
w.set_funcsel(pac::io::vals::Gpio0CtrlFuncsel::NULL.0);
|
|
|
|
});
|
2022-05-13 13:19:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-29 02:11:32 +00:00
|
|
|
pub(crate) mod sealed {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
pub trait Pin: Sized {
|
|
|
|
fn pin_bank(&self) -> u8;
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn pin(&self) -> u8 {
|
|
|
|
self.pin_bank() & 0x1f
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn bank(&self) -> Bank {
|
|
|
|
if self.pin_bank() & 0x20 == 0 {
|
|
|
|
Bank::Bank0
|
|
|
|
} else {
|
|
|
|
Bank::Qspi
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn io(&self) -> pac::io::Gpio {
|
|
|
|
let block = match self.bank() {
|
|
|
|
Bank::Bank0 => crate::pac::IO_BANK0,
|
|
|
|
Bank::Qspi => crate::pac::IO_QSPI,
|
|
|
|
};
|
|
|
|
block.gpio(self.pin() as _)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn pad_ctrl(&self) -> Reg<pac::pads::regs::GpioCtrl, RW> {
|
|
|
|
let block = match self.bank() {
|
|
|
|
Bank::Bank0 => crate::pac::PADS_BANK0,
|
|
|
|
Bank::Qspi => crate::pac::PADS_QSPI,
|
|
|
|
};
|
|
|
|
block.gpio(self.pin() as _)
|
|
|
|
}
|
2022-05-19 11:45:40 +00:00
|
|
|
|
2021-03-29 02:11:32 +00:00
|
|
|
fn sio_out(&self) -> pac::sio::Gpio {
|
|
|
|
SIO.gpio_out(self.bank() as _)
|
|
|
|
}
|
2022-05-19 11:45:40 +00:00
|
|
|
|
2021-03-29 02:11:32 +00:00
|
|
|
fn sio_oe(&self) -> pac::sio::Gpio {
|
|
|
|
SIO.gpio_oe(self.bank() as _)
|
|
|
|
}
|
2022-05-19 11:45:40 +00:00
|
|
|
|
2021-03-29 02:11:32 +00:00
|
|
|
fn sio_in(&self) -> Reg<u32, RW> {
|
|
|
|
SIO.gpio_in(self.bank() as _)
|
|
|
|
}
|
2022-07-10 04:47:08 +00:00
|
|
|
|
|
|
|
fn int_proc(&self) -> pac::io::Int {
|
|
|
|
let io_block = match self.bank() {
|
|
|
|
Bank::Bank0 => crate::pac::IO_BANK0,
|
|
|
|
Bank::Qspi => crate::pac::IO_QSPI,
|
|
|
|
};
|
|
|
|
let proc = unsafe { SIO.cpuid().read() };
|
|
|
|
io_block.int_proc(proc as _)
|
|
|
|
}
|
2021-03-29 02:11:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-25 16:17:59 +00:00
|
|
|
pub trait Pin: Unborrow<Target = Self> + sealed::Pin {
|
2021-03-29 02:11:32 +00:00
|
|
|
/// Degrade to a generic pin struct
|
|
|
|
fn degrade(self) -> AnyPin {
|
|
|
|
AnyPin {
|
|
|
|
pin_bank: self.pin_bank(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct AnyPin {
|
|
|
|
pin_bank: u8,
|
|
|
|
}
|
2022-07-03 21:54:01 +00:00
|
|
|
|
|
|
|
impl AnyPin {
|
|
|
|
pub(crate) fn unborrow_and_degrade<'a>(pin: impl Unborrow<Target = impl Pin + 'a> + 'a) -> Unborrowed<'a, Self> {
|
|
|
|
Unborrowed::new(AnyPin {
|
|
|
|
pin_bank: pin.unborrow().pin_bank(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! unborrow_and_degrade {
|
|
|
|
($($name:ident),*) => {
|
|
|
|
$(
|
|
|
|
let $name = $crate::gpio::AnyPin::unborrow_and_degrade($name);
|
|
|
|
)*
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-07-22 20:00:12 +00:00
|
|
|
impl_unborrow!(AnyPin);
|
2022-07-03 21:54:01 +00:00
|
|
|
|
2021-03-29 02:11:32 +00:00
|
|
|
impl Pin for AnyPin {}
|
|
|
|
impl sealed::Pin for AnyPin {
|
|
|
|
fn pin_bank(&self) -> u8 {
|
|
|
|
self.pin_bank
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-25 16:17:59 +00:00
|
|
|
// ==========================
|
|
|
|
|
2021-03-29 02:11:32 +00:00
|
|
|
macro_rules! impl_pin {
|
|
|
|
($name:ident, $bank:expr, $pin_num:expr) => {
|
|
|
|
impl Pin for peripherals::$name {}
|
|
|
|
impl sealed::Pin for peripherals::$name {
|
|
|
|
fn pin_bank(&self) -> u8 {
|
|
|
|
($bank as u8) * 32 + $pin_num
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
impl_pin!(PIN_0, Bank::Bank0, 0);
|
|
|
|
impl_pin!(PIN_1, Bank::Bank0, 1);
|
|
|
|
impl_pin!(PIN_2, Bank::Bank0, 2);
|
|
|
|
impl_pin!(PIN_3, Bank::Bank0, 3);
|
|
|
|
impl_pin!(PIN_4, Bank::Bank0, 4);
|
|
|
|
impl_pin!(PIN_5, Bank::Bank0, 5);
|
|
|
|
impl_pin!(PIN_6, Bank::Bank0, 6);
|
|
|
|
impl_pin!(PIN_7, Bank::Bank0, 7);
|
|
|
|
impl_pin!(PIN_8, Bank::Bank0, 8);
|
|
|
|
impl_pin!(PIN_9, Bank::Bank0, 9);
|
|
|
|
impl_pin!(PIN_10, Bank::Bank0, 10);
|
|
|
|
impl_pin!(PIN_11, Bank::Bank0, 11);
|
|
|
|
impl_pin!(PIN_12, Bank::Bank0, 12);
|
|
|
|
impl_pin!(PIN_13, Bank::Bank0, 13);
|
|
|
|
impl_pin!(PIN_14, Bank::Bank0, 14);
|
|
|
|
impl_pin!(PIN_15, Bank::Bank0, 15);
|
|
|
|
impl_pin!(PIN_16, Bank::Bank0, 16);
|
|
|
|
impl_pin!(PIN_17, Bank::Bank0, 17);
|
|
|
|
impl_pin!(PIN_18, Bank::Bank0, 18);
|
|
|
|
impl_pin!(PIN_19, Bank::Bank0, 19);
|
|
|
|
impl_pin!(PIN_20, Bank::Bank0, 20);
|
|
|
|
impl_pin!(PIN_21, Bank::Bank0, 21);
|
|
|
|
impl_pin!(PIN_22, Bank::Bank0, 22);
|
|
|
|
impl_pin!(PIN_23, Bank::Bank0, 23);
|
|
|
|
impl_pin!(PIN_24, Bank::Bank0, 24);
|
|
|
|
impl_pin!(PIN_25, Bank::Bank0, 25);
|
|
|
|
impl_pin!(PIN_26, Bank::Bank0, 26);
|
|
|
|
impl_pin!(PIN_27, Bank::Bank0, 27);
|
|
|
|
impl_pin!(PIN_28, Bank::Bank0, 28);
|
|
|
|
impl_pin!(PIN_29, Bank::Bank0, 29);
|
|
|
|
|
|
|
|
impl_pin!(PIN_QSPI_SCLK, Bank::Qspi, 0);
|
|
|
|
impl_pin!(PIN_QSPI_SS, Bank::Qspi, 1);
|
|
|
|
impl_pin!(PIN_QSPI_SD0, Bank::Qspi, 2);
|
|
|
|
impl_pin!(PIN_QSPI_SD1, Bank::Qspi, 3);
|
|
|
|
impl_pin!(PIN_QSPI_SD2, Bank::Qspi, 4);
|
|
|
|
impl_pin!(PIN_QSPI_SD3, Bank::Qspi, 5);
|
2022-02-15 16:28:48 +00:00
|
|
|
|
|
|
|
// ====================
|
|
|
|
|
|
|
|
mod eh02 {
|
2022-07-21 19:45:04 +00:00
|
|
|
use core::convert::Infallible;
|
2022-07-10 04:47:08 +00:00
|
|
|
|
2022-02-15 16:28:48 +00:00
|
|
|
use super::*;
|
|
|
|
|
|
|
|
impl<'d, T: Pin> embedded_hal_02::digital::v2::InputPin for Input<'d, T> {
|
|
|
|
type Error = Infallible;
|
|
|
|
|
|
|
|
fn is_high(&self) -> Result<bool, Self::Error> {
|
|
|
|
Ok(self.is_high())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_low(&self) -> Result<bool, Self::Error> {
|
|
|
|
Ok(self.is_low())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'d, T: Pin> embedded_hal_02::digital::v2::OutputPin for Output<'d, T> {
|
|
|
|
type Error = Infallible;
|
|
|
|
|
|
|
|
fn set_high(&mut self) -> Result<(), Self::Error> {
|
|
|
|
Ok(self.set_high())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn set_low(&mut self) -> Result<(), Self::Error> {
|
|
|
|
Ok(self.set_low())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for Output<'d, T> {
|
|
|
|
fn is_set_high(&self) -> Result<bool, Self::Error> {
|
|
|
|
Ok(self.is_set_high())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_set_low(&self) -> Result<bool, Self::Error> {
|
|
|
|
Ok(self.is_set_low())
|
|
|
|
}
|
|
|
|
}
|
2022-05-19 03:33:42 +00:00
|
|
|
|
|
|
|
impl<'d, T: Pin> embedded_hal_02::digital::v2::ToggleableOutputPin for Output<'d, T> {
|
|
|
|
type Error = Infallible;
|
|
|
|
#[inline]
|
|
|
|
fn toggle(&mut self) -> Result<(), Self::Error> {
|
|
|
|
Ok(self.toggle())
|
|
|
|
}
|
|
|
|
}
|
2022-05-19 03:43:18 +00:00
|
|
|
|
|
|
|
impl<'d, T: Pin> embedded_hal_02::digital::v2::OutputPin for OutputOpenDrain<'d, T> {
|
|
|
|
type Error = Infallible;
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn set_high(&mut self) -> Result<(), Self::Error> {
|
|
|
|
Ok(self.set_high())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn set_low(&mut self) -> Result<(), Self::Error> {
|
|
|
|
Ok(self.set_low())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for OutputOpenDrain<'d, T> {
|
|
|
|
fn is_set_high(&self) -> Result<bool, Self::Error> {
|
|
|
|
Ok(self.is_set_high())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_set_low(&self) -> Result<bool, Self::Error> {
|
|
|
|
Ok(self.is_set_low())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'d, T: Pin> embedded_hal_02::digital::v2::ToggleableOutputPin for OutputOpenDrain<'d, T> {
|
|
|
|
type Error = Infallible;
|
|
|
|
#[inline]
|
|
|
|
fn toggle(&mut self) -> Result<(), Self::Error> {
|
|
|
|
Ok(self.toggle())
|
|
|
|
}
|
|
|
|
}
|
2022-07-09 00:12:17 +00:00
|
|
|
|
|
|
|
impl<'d, T: Pin> embedded_hal_02::digital::v2::InputPin for Flex<'d, T> {
|
|
|
|
type Error = Infallible;
|
|
|
|
|
|
|
|
fn is_high(&self) -> Result<bool, Self::Error> {
|
|
|
|
Ok(self.is_high())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_low(&self) -> Result<bool, Self::Error> {
|
|
|
|
Ok(self.is_low())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'d, T: Pin> embedded_hal_02::digital::v2::OutputPin for Flex<'d, T> {
|
|
|
|
type Error = Infallible;
|
|
|
|
|
|
|
|
fn set_high(&mut self) -> Result<(), Self::Error> {
|
|
|
|
Ok(self.set_high())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn set_low(&mut self) -> Result<(), Self::Error> {
|
|
|
|
Ok(self.set_low())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for Flex<'d, T> {
|
|
|
|
fn is_set_high(&self) -> Result<bool, Self::Error> {
|
|
|
|
Ok(self.is_set_high())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_set_low(&self) -> Result<bool, Self::Error> {
|
|
|
|
Ok(self.is_set_low())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'d, T: Pin> embedded_hal_02::digital::v2::ToggleableOutputPin for Flex<'d, T> {
|
|
|
|
type Error = Infallible;
|
|
|
|
#[inline]
|
|
|
|
fn toggle(&mut self) -> Result<(), Self::Error> {
|
|
|
|
Ok(self.toggle())
|
|
|
|
}
|
|
|
|
}
|
2022-02-15 16:28:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "unstable-traits")]
|
|
|
|
mod eh1 {
|
2022-07-21 19:45:04 +00:00
|
|
|
use core::convert::Infallible;
|
|
|
|
|
|
|
|
#[cfg(feature = "nightly")]
|
|
|
|
use futures::FutureExt;
|
|
|
|
|
2022-02-15 16:28:48 +00:00
|
|
|
use super::*;
|
|
|
|
|
|
|
|
impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Input<'d, T> {
|
|
|
|
type Error = Infallible;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'d, T: Pin> embedded_hal_1::digital::blocking::InputPin for Input<'d, T> {
|
|
|
|
fn is_high(&self) -> Result<bool, Self::Error> {
|
|
|
|
Ok(self.is_high())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_low(&self) -> Result<bool, Self::Error> {
|
|
|
|
Ok(self.is_low())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Output<'d, T> {
|
|
|
|
type Error = Infallible;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'d, T: Pin> embedded_hal_1::digital::blocking::OutputPin for Output<'d, T> {
|
|
|
|
fn set_high(&mut self) -> Result<(), Self::Error> {
|
|
|
|
Ok(self.set_high())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn set_low(&mut self) -> Result<(), Self::Error> {
|
|
|
|
Ok(self.set_low())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'d, T: Pin> embedded_hal_1::digital::blocking::StatefulOutputPin for Output<'d, T> {
|
|
|
|
fn is_set_high(&self) -> Result<bool, Self::Error> {
|
|
|
|
Ok(self.is_set_high())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_set_low(&self) -> Result<bool, Self::Error> {
|
|
|
|
Ok(self.is_set_low())
|
|
|
|
}
|
|
|
|
}
|
2022-07-09 00:12:17 +00:00
|
|
|
|
|
|
|
impl<'d, T: Pin> embedded_hal_1::digital::blocking::ToggleableOutputPin for Output<'d, T> {
|
|
|
|
fn toggle(&mut self) -> Result<(), Self::Error> {
|
|
|
|
Ok(self.toggle())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for OutputOpenDrain<'d, T> {
|
|
|
|
type Error = Infallible;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'d, T: Pin> embedded_hal_1::digital::blocking::OutputPin for OutputOpenDrain<'d, T> {
|
|
|
|
fn set_high(&mut self) -> Result<(), Self::Error> {
|
|
|
|
Ok(self.set_high())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn set_low(&mut self) -> Result<(), Self::Error> {
|
|
|
|
Ok(self.set_low())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'d, T: Pin> embedded_hal_1::digital::blocking::StatefulOutputPin for OutputOpenDrain<'d, T> {
|
|
|
|
fn is_set_high(&self) -> Result<bool, Self::Error> {
|
|
|
|
Ok(self.is_set_high())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_set_low(&self) -> Result<bool, Self::Error> {
|
|
|
|
Ok(self.is_set_low())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'d, T: Pin> embedded_hal_1::digital::blocking::ToggleableOutputPin for OutputOpenDrain<'d, T> {
|
|
|
|
fn toggle(&mut self) -> Result<(), Self::Error> {
|
|
|
|
Ok(self.toggle())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Flex<'d, T> {
|
|
|
|
type Error = Infallible;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'d, T: Pin> embedded_hal_1::digital::blocking::InputPin for Flex<'d, T> {
|
|
|
|
fn is_high(&self) -> Result<bool, Self::Error> {
|
|
|
|
Ok(self.is_high())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_low(&self) -> Result<bool, Self::Error> {
|
|
|
|
Ok(self.is_low())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'d, T: Pin> embedded_hal_1::digital::blocking::OutputPin for Flex<'d, T> {
|
|
|
|
fn set_high(&mut self) -> Result<(), Self::Error> {
|
|
|
|
Ok(self.set_high())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn set_low(&mut self) -> Result<(), Self::Error> {
|
|
|
|
Ok(self.set_low())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'d, T: Pin> embedded_hal_1::digital::blocking::StatefulOutputPin for Flex<'d, T> {
|
|
|
|
fn is_set_high(&self) -> Result<bool, Self::Error> {
|
|
|
|
Ok(self.is_set_high())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_set_low(&self) -> Result<bool, Self::Error> {
|
|
|
|
Ok(self.is_set_low())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'d, T: Pin> embedded_hal_1::digital::blocking::ToggleableOutputPin for Flex<'d, T> {
|
|
|
|
fn toggle(&mut self) -> Result<(), Self::Error> {
|
|
|
|
Ok(self.toggle())
|
|
|
|
}
|
|
|
|
}
|
2022-07-21 19:45:04 +00:00
|
|
|
|
|
|
|
#[cfg(feature = "nightly")]
|
|
|
|
impl<'d, T: Pin> embedded_hal_async::digital::Wait for Flex<'d, T> {
|
|
|
|
type WaitForHighFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
|
|
|
|
fn wait_for_high<'a>(&'a mut self) -> Self::WaitForHighFuture<'a> {
|
|
|
|
self.wait_for_high().map(Ok)
|
|
|
|
}
|
|
|
|
|
|
|
|
type WaitForLowFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
|
|
|
|
fn wait_for_low<'a>(&'a mut self) -> Self::WaitForLowFuture<'a> {
|
|
|
|
self.wait_for_low().map(Ok)
|
|
|
|
}
|
|
|
|
|
|
|
|
type WaitForRisingEdgeFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
|
|
|
|
fn wait_for_rising_edge<'a>(&'a mut self) -> Self::WaitForRisingEdgeFuture<'a> {
|
|
|
|
self.wait_for_rising_edge().map(Ok)
|
|
|
|
}
|
|
|
|
|
|
|
|
type WaitForFallingEdgeFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
|
|
|
|
fn wait_for_falling_edge<'a>(&'a mut self) -> Self::WaitForFallingEdgeFuture<'a> {
|
|
|
|
self.wait_for_falling_edge().map(Ok)
|
|
|
|
}
|
|
|
|
|
|
|
|
type WaitForAnyEdgeFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
|
|
|
|
fn wait_for_any_edge<'a>(&'a mut self) -> Self::WaitForAnyEdgeFuture<'a> {
|
|
|
|
self.wait_for_any_edge().map(Ok)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "nightly")]
|
|
|
|
impl<'d, T: Pin> embedded_hal_async::digital::Wait for Input<'d, T> {
|
|
|
|
type WaitForHighFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
|
|
|
|
fn wait_for_high<'a>(&'a mut self) -> Self::WaitForHighFuture<'a> {
|
|
|
|
self.wait_for_high().map(Ok)
|
|
|
|
}
|
|
|
|
|
|
|
|
type WaitForLowFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
|
|
|
|
fn wait_for_low<'a>(&'a mut self) -> Self::WaitForLowFuture<'a> {
|
|
|
|
self.wait_for_low().map(Ok)
|
|
|
|
}
|
|
|
|
|
|
|
|
type WaitForRisingEdgeFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
|
|
|
|
fn wait_for_rising_edge<'a>(&'a mut self) -> Self::WaitForRisingEdgeFuture<'a> {
|
|
|
|
self.wait_for_rising_edge().map(Ok)
|
|
|
|
}
|
|
|
|
|
|
|
|
type WaitForFallingEdgeFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
|
|
|
|
fn wait_for_falling_edge<'a>(&'a mut self) -> Self::WaitForFallingEdgeFuture<'a> {
|
|
|
|
self.wait_for_falling_edge().map(Ok)
|
|
|
|
}
|
|
|
|
|
|
|
|
type WaitForAnyEdgeFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
|
|
|
|
fn wait_for_any_edge<'a>(&'a mut self) -> Self::WaitForAnyEdgeFuture<'a> {
|
|
|
|
self.wait_for_any_edge().map(Ok)
|
|
|
|
}
|
|
|
|
}
|
2022-02-15 16:28:48 +00:00
|
|
|
}
|