Skip to content

Commit 3151583

Browse files
authored
feat: Add ehal 1.0 InputPin impl for ExtInt (#826)
1 parent b05f8f8 commit 3151583

File tree

2 files changed

+58
-30
lines changed

2 files changed

+58
-30
lines changed

hal/src/peripherals/eic/d11/pin.rs

+29-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use atsamd_hal_macros::hal_cfg;
22

3-
use crate::ehal_02::digital::v2::InputPin;
3+
use core::convert::Infallible;
4+
use crate::ehal_02::digital::v2::InputPin as InputPin_02;
5+
use crate::ehal::digital::{ErrorType, InputPin};
46
use crate::eic::*;
57
use crate::gpio::{
68
self, pin::*, AnyPin, FloatingInterrupt, PinMode, PullDownInterrupt, PullUpInterrupt,
@@ -133,13 +135,13 @@ where
133135
}
134136
}
135137

136-
impl<P, C, Id, F> InputPin for ExtInt<P, Id, F>
138+
impl<P, C, Id, F> InputPin_02 for ExtInt<P, Id, F>
137139
where
138140
P: EicPin + AnyPin<Mode = Interrupt<C>>,
139141
Id: ChId,
140142
C: InterruptConfig,
141143
{
142-
type Error = core::convert::Infallible;
144+
type Error = Infallible;
143145
#[inline]
144146
fn is_high(&self) -> Result<bool, Self::Error> {
145147
self.pin.is_high()
@@ -150,11 +152,32 @@ where
150152
}
151153
}
152154

155+
impl<P, Id, F> InputPin for ExtInt<P, Id, F>
156+
where Self: ErrorType,
157+
P: EicPin,
158+
Id: ChId,
159+
{
160+
#[inline]
161+
fn is_high(&mut self) -> Result<bool, Self::Error> {
162+
Ok(self.pin._is_high())
163+
}
164+
165+
#[inline]
166+
fn is_low(&mut self) -> Result<bool, Self::Error> {
167+
Ok(self.pin._is_low())
168+
}
169+
}
170+
171+
impl<P, Id, F> ErrorType for ExtInt<P, Id, F>
172+
where
173+
P: EicPin,
174+
Id: ChId,
175+
{
176+
type Error = Infallible;
177+
}
178+
153179
#[cfg(feature = "async")]
154180
mod async_impls {
155-
use core::convert::Infallible;
156-
157-
use embedded_hal_1::digital::ErrorType;
158181
use embedded_hal_async::digital::Wait;
159182

160183
use super::super::async_api::WAKERS;
@@ -210,15 +233,6 @@ mod async_impls {
210233
}
211234
}
212235

213-
impl<P, Id> ErrorType for ExtInt<P, Id, EicFuture>
214-
where
215-
P: EicPin,
216-
Id: ChId,
217-
Self: InputPin<Error = Infallible>,
218-
{
219-
type Error = Infallible;
220-
}
221-
222236
impl<P, Id> Wait for ExtInt<P, Id, EicFuture>
223237
where
224238
P: EicPin,

hal/src/peripherals/eic/d5x/pin.rs

+29-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use atsamd_hal_macros::hal_cfg;
22

3-
use crate::ehal_02::digital::v2::InputPin;
3+
use core::convert::Infallible;
4+
use crate::ehal_02::digital::v2::InputPin as InputPin_02;
5+
use crate::ehal::digital::{ErrorType, InputPin};
46
use crate::eic::*;
57
use crate::gpio::{
68
self, pin::*, AnyPin, FloatingInterrupt, PinMode, PullDownInterrupt, PullUpInterrupt,
@@ -156,13 +158,13 @@ where
156158
}
157159
}
158160

159-
impl<P, C, Id, F> InputPin for ExtInt<P, Id, F>
161+
impl<P, C, Id, F> InputPin_02 for ExtInt<P, Id, F>
160162
where
161163
P: EicPin + AnyPin<Mode = Interrupt<C>>,
162164
C: InterruptConfig,
163165
Id: ChId,
164166
{
165-
type Error = core::convert::Infallible;
167+
type Error = Infallible;
166168
#[inline]
167169
fn is_high(&self) -> Result<bool, Self::Error> {
168170
self.pin.is_high()
@@ -173,11 +175,32 @@ where
173175
}
174176
}
175177

178+
impl<P, Id, F> InputPin for ExtInt<P, Id, F>
179+
where Self: ErrorType,
180+
P: EicPin,
181+
Id: ChId,
182+
{
183+
#[inline]
184+
fn is_high(&mut self) -> Result<bool, Self::Error> {
185+
Ok(self.pin._is_high())
186+
}
187+
188+
#[inline]
189+
fn is_low(&mut self) -> Result<bool, Self::Error> {
190+
Ok(self.pin._is_low())
191+
}
192+
}
193+
194+
impl<P, Id, F> ErrorType for ExtInt<P, Id, F>
195+
where
196+
P: EicPin,
197+
Id: ChId,
198+
{
199+
type Error = Infallible;
200+
}
201+
176202
#[cfg(feature = "async")]
177203
mod async_impls {
178-
use core::convert::Infallible;
179-
180-
use embedded_hal_1::digital::ErrorType;
181204
use embedded_hal_async::digital::Wait;
182205

183206
use crate::{
@@ -248,15 +271,6 @@ mod async_impls {
248271
}
249272
}
250273

251-
impl<P, Id> ErrorType for ExtInt<P, Id, EicFuture>
252-
where
253-
P: EicPin,
254-
Self: InputPin<Error = Infallible>,
255-
Id: ChId,
256-
{
257-
type Error = Infallible;
258-
}
259-
260274
impl<P, Id> Wait for ExtInt<P, Id, EicFuture>
261275
where
262276
P: EicPin,

0 commit comments

Comments
 (0)