Merge pull request #461 from jannic/upgrade-eh-alpha

Upgrade eh alpha
This commit is contained in:
Jan Niehusmann 2022-09-30 21:41:36 +02:00 committed by GitHub
commit 6a040a8042
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 37 additions and 67 deletions

View file

@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Changed
- Update embedded-hal alpha support to version 1.0.0-alpha.9 - @jannic
(Non-blocking traits were moved to embedded-hal-nb, which is not yet supported)
## [0.6.0] - 2022-08-26 ## [0.6.0] - 2022-08-26
### Added ### Added

View file

@ -13,7 +13,7 @@ license = "MIT OR Apache-2.0"
cortex-m = "0.7.2" cortex-m = "0.7.2"
cortex-m-rt = ">=0.6.15,<0.8" cortex-m-rt = ">=0.6.15,<0.8"
embedded-hal = { version = "0.2.5", features = ["unproven"] } embedded-hal = { version = "0.2.5", features = ["unproven"] }
eh1_0_alpha = { package = "embedded-hal", version = "=1.0.0-alpha.8", optional = true } eh1_0_alpha = { package = "embedded-hal", version = "=1.0.0-alpha.9", optional = true }
fugit = "0.3.6" fugit = "0.3.6"
itertools = { version = "0.10.1", default-features = false } itertools = { version = "0.10.1", default-features = false }
nb = "1.0" nb = "1.0"

View file

@ -556,7 +556,7 @@ impl eh1::ErrorType for DynPin {
} }
#[cfg(feature = "eh1_0_alpha")] #[cfg(feature = "eh1_0_alpha")]
impl eh1::blocking::OutputPin for DynPin { impl eh1::OutputPin for DynPin {
#[inline] #[inline]
fn set_high(&mut self) -> Result<(), Self::Error> { fn set_high(&mut self) -> Result<(), Self::Error> {
self._set_high() self._set_high()
@ -568,7 +568,7 @@ impl eh1::blocking::OutputPin for DynPin {
} }
#[cfg(feature = "eh1_0_alpha")] #[cfg(feature = "eh1_0_alpha")]
impl eh1::blocking::InputPin for DynPin { impl eh1::InputPin for DynPin {
#[inline] #[inline]
fn is_high(&self) -> Result<bool, Self::Error> { fn is_high(&self) -> Result<bool, Self::Error> {
self._is_high() self._is_high()
@ -580,7 +580,7 @@ impl eh1::blocking::InputPin for DynPin {
} }
#[cfg(feature = "eh1_0_alpha")] #[cfg(feature = "eh1_0_alpha")]
impl eh1::blocking::ToggleableOutputPin for DynPin { impl eh1::ToggleableOutputPin for DynPin {
#[inline] #[inline]
fn toggle(&mut self) -> Result<(), Self::Error> { fn toggle(&mut self) -> Result<(), Self::Error> {
self._toggle() self._toggle()
@ -588,7 +588,7 @@ impl eh1::blocking::ToggleableOutputPin for DynPin {
} }
#[cfg(feature = "eh1_0_alpha")] #[cfg(feature = "eh1_0_alpha")]
impl eh1::blocking::StatefulOutputPin for DynPin { impl eh1::StatefulOutputPin for DynPin {
#[inline] #[inline]
fn is_set_high(&self) -> Result<bool, Self::Error> { fn is_set_high(&self) -> Result<bool, Self::Error> {
self._is_set_high() self._is_set_high()

View file

@ -881,7 +881,7 @@ where
} }
#[cfg(feature = "eh1_0_alpha")] #[cfg(feature = "eh1_0_alpha")]
impl<I, C> eh1::blocking::OutputPin for Pin<I, Output<C>> impl<I, C> eh1::OutputPin for Pin<I, Output<C>>
where where
I: PinId, I: PinId,
C: OutputConfig, C: OutputConfig,
@ -899,7 +899,7 @@ where
} }
#[cfg(feature = "eh1_0_alpha")] #[cfg(feature = "eh1_0_alpha")]
impl<I> eh1::blocking::InputPin for Pin<I, ReadableOutput> impl<I> eh1::InputPin for Pin<I, ReadableOutput>
where where
I: PinId, I: PinId,
{ {
@ -923,7 +923,7 @@ where
} }
#[cfg(feature = "eh1_0_alpha")] #[cfg(feature = "eh1_0_alpha")]
impl<I, C> eh1::blocking::InputPin for Pin<I, Input<C>> impl<I, C> eh1::InputPin for Pin<I, Input<C>>
where where
I: PinId, I: PinId,
C: InputConfig, C: InputConfig,
@ -939,7 +939,7 @@ where
} }
#[cfg(feature = "eh1_0_alpha")] #[cfg(feature = "eh1_0_alpha")]
impl<I, C> eh1::blocking::ToggleableOutputPin for Pin<I, Output<C>> impl<I, C> eh1::ToggleableOutputPin for Pin<I, Output<C>>
where where
I: PinId, I: PinId,
C: OutputConfig, C: OutputConfig,
@ -952,7 +952,7 @@ where
} }
#[cfg(feature = "eh1_0_alpha")] #[cfg(feature = "eh1_0_alpha")]
impl<I, C> eh1::blocking::StatefulOutputPin for Pin<I, Output<C>> impl<I, C> eh1::StatefulOutputPin for Pin<I, Output<C>>
where where
I: PinId, I: PinId,
C: OutputConfig, C: OutputConfig,

View file

@ -279,7 +279,7 @@ impl<T: Deref<Target = Block>, PINS> eh1::ErrorType for I2C<T, PINS, Controller>
} }
#[cfg(feature = "eh1_0_alpha")] #[cfg(feature = "eh1_0_alpha")]
impl<T: Deref<Target = Block>, PINS> eh1::blocking::I2c for I2C<T, PINS, Controller> { impl<T: Deref<Target = Block>, PINS> eh1::I2c for I2C<T, PINS, Controller> {
fn write(&mut self, addr: u8, bytes: &[u8]) -> Result<(), Self::Error> { fn write(&mut self, addr: u8, bytes: &[u8]) -> Result<(), Self::Error> {
Write::write(self, addr, bytes) Write::write(self, addr, bytes)
} }
@ -330,15 +330,15 @@ impl<T: Deref<Target = Block>, PINS> eh1::blocking::I2c for I2C<T, PINS, Control
fn transaction<'a>( fn transaction<'a>(
&mut self, &mut self,
address: u8, address: u8,
operations: &mut [eh1::blocking::Operation<'a>], operations: &mut [eh1::Operation<'a>],
) -> Result<(), Self::Error> { ) -> Result<(), Self::Error> {
let addr: u16 = address.into(); let addr: u16 = address.into();
self.setup(addr); self.setup(addr);
for i in 0..operations.len() { for i in 0..operations.len() {
let last = i == operations.len() - 1; let last = i == operations.len() - 1;
match &mut operations[i] { match &mut operations[i] {
eh1::blocking::Operation::Read(buf) => self.read_internal(buf, false, last)?, eh1::Operation::Read(buf) => self.read_internal(buf, false, last)?,
eh1::blocking::Operation::Write(buf) => self.write_internal(buf, last)?, eh1::Operation::Write(buf) => self.write_internal(buf, last)?,
} }
} }
Ok(()) Ok(())
@ -346,7 +346,7 @@ impl<T: Deref<Target = Block>, PINS> eh1::blocking::I2c for I2C<T, PINS, Control
fn transaction_iter<'a, O>(&mut self, address: u8, operations: O) -> Result<(), Self::Error> fn transaction_iter<'a, O>(&mut self, address: u8, operations: O) -> Result<(), Self::Error>
where where
O: IntoIterator<Item = eh1::blocking::Operation<'a>>, O: IntoIterator<Item = eh1::Operation<'a>>,
{ {
let addr: u16 = address.into(); let addr: u16 = address.into();
self.setup(addr); self.setup(addr);
@ -354,8 +354,8 @@ impl<T: Deref<Target = Block>, PINS> eh1::blocking::I2c for I2C<T, PINS, Control
while let Some(operation) = peekable.next() { while let Some(operation) = peekable.next() {
let last = peekable.peek().is_none(); let last = peekable.peek().is_none();
match operation { match operation {
eh1::blocking::Operation::Read(buf) => self.read_internal(buf, false, last)?, eh1::Operation::Read(buf) => self.read_internal(buf, false, last)?,
eh1::blocking::Operation::Write(buf) => self.write_internal(buf, last)?, eh1::Operation::Write(buf) => self.write_internal(buf, last)?,
} }
} }
Ok(()) Ok(())

View file

@ -192,29 +192,6 @@ impl<D: SpiDevice, const DS: u8> Spi<Enabled, D, DS> {
} }
} }
/// Same as core::convert::Infallible, but implementing spi::Error
///
/// For eh 1.0.0-alpha.6, Infallible doesn't implement spi::Error,
/// so use a locally defined type instead.
/// This should be removed with the next release of e-h.
/// (https://github.com/rust-embedded/embedded-hal/pull/328)
#[cfg(feature = "eh1_0_alpha")]
pub enum SpiInfallible {}
#[cfg(feature = "eh1_0_alpha")]
impl core::fmt::Debug for SpiInfallible {
fn fmt(&self, _f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match *self {}
}
}
#[cfg(feature = "eh1_0_alpha")]
impl eh1::Error for SpiInfallible {
fn kind(&self) -> eh1::ErrorKind {
match *self {}
}
}
macro_rules! impl_write { macro_rules! impl_write {
($type:ident, [$($nr:expr),+]) => { ($type:ident, [$($nr:expr),+]) => {
@ -250,19 +227,20 @@ macro_rules! impl_write {
#[cfg(feature = "eh1_0_alpha")] #[cfg(feature = "eh1_0_alpha")]
impl<D: SpiDevice> eh1::ErrorType for Spi<Enabled, D, $nr> { impl<D: SpiDevice> eh1::ErrorType for Spi<Enabled, D, $nr> {
type Error = SpiInfallible; type Error = Infallible;
} }
/* disabled for now - nb was migrated to separate crate
#[cfg(feature = "eh1_0_alpha")] #[cfg(feature = "eh1_0_alpha")]
impl<D: SpiDevice> eh1::nb::FullDuplex<$type> for Spi<Enabled, D, $nr> { impl<D: SpiDevice> eh1::nb::FullDuplex<$type> for Spi<Enabled, D, $nr> {
fn read(&mut self) -> Result<$type, nb::Error<SpiInfallible>> { fn read(&mut self) -> Result<$type, nb::Error<Infallible>> {
if !self.is_readable() { if !self.is_readable() {
return Err(nb::Error::WouldBlock); return Err(nb::Error::WouldBlock);
} }
Ok(self.device.sspdr.read().data().bits() as $type) Ok(self.device.sspdr.read().data().bits() as $type)
} }
fn write(&mut self, word: $type) -> Result<(), nb::Error<SpiInfallible>> { fn write(&mut self, word: $type) -> Result<(), nb::Error<Infallible>> {
// Write to TX FIFO whilst ignoring RX, then clean up afterward. When RX // Write to TX FIFO whilst ignoring RX, then clean up afterward. When RX
// is full, PL022 inhibits RX pushes, and sets a sticky flag on // is full, PL022 inhibits RX pushes, and sets a sticky flag on
// push-on-full, but continues shifting. Safe if SSPIMSC_RORIM is not set. // push-on-full, but continues shifting. Safe if SSPIMSC_RORIM is not set.
@ -276,6 +254,7 @@ macro_rules! impl_write {
Ok(()) Ok(())
} }
} }
*/
)+ )+

View file

@ -357,6 +357,7 @@ impl<D: UartDevice, P: ValidUartPinout<D>> eh1::ErrorType for UartPeripheral<Ena
type Error = ReadErrorType; type Error = ReadErrorType;
} }
/* disabled for now - nb was migrated to separate crate
#[cfg(feature = "eh1_0_alpha")] #[cfg(feature = "eh1_0_alpha")]
impl<D: UartDevice, P: ValidUartPinout<D>> eh1::nb::Read<u8> for UartPeripheral<Enabled, D, P> { impl<D: UartDevice, P: ValidUartPinout<D>> eh1::nb::Read<u8> for UartPeripheral<Enabled, D, P> {
fn read(&mut self) -> nb::Result<u8, Self::Error> { fn read(&mut self) -> nb::Result<u8, Self::Error> {
@ -371,6 +372,8 @@ impl<D: UartDevice, P: ValidUartPinout<D>> eh1::nb::Read<u8> for UartPeripheral<
} }
} }
} }
*/
impl<D: UartDevice, P: ValidUartPinout<D>> Write<u8> for UartPeripheral<Enabled, D, P> { impl<D: UartDevice, P: ValidUartPinout<D>> Write<u8> for UartPeripheral<Enabled, D, P> {
type Error = Infallible; type Error = Infallible;
@ -387,6 +390,7 @@ impl<D: UartDevice, P: ValidUartPinout<D>> Write<u8> for UartPeripheral<Enabled,
} }
} }
/* disabled for now - nb was migrated to separate crate
#[cfg(feature = "eh1_0_alpha")] #[cfg(feature = "eh1_0_alpha")]
impl<D: UartDevice, P: ValidUartPinout<D>> eh1::nb::Write<u8> for UartPeripheral<Enabled, D, P> { impl<D: UartDevice, P: ValidUartPinout<D>> eh1::nb::Write<u8> for UartPeripheral<Enabled, D, P> {
fn write(&mut self, word: u8) -> nb::Result<(), Self::Error> { fn write(&mut self, word: u8) -> nb::Result<(), Self::Error> {
@ -404,6 +408,7 @@ impl<D: UartDevice, P: ValidUartPinout<D>> eh1::nb::Write<u8> for UartPeripheral
}) })
} }
} }
*/
impl<D: UartDevice, P: ValidUartPinout<D>> fmt::Write for UartPeripheral<Enabled, D, P> { impl<D: UartDevice, P: ValidUartPinout<D>> fmt::Write for UartPeripheral<Enabled, D, P> {
fn write_str(&mut self, s: &str) -> fmt::Result { fn write_str(&mut self, s: &str) -> fmt::Result {

View file

@ -239,6 +239,7 @@ impl<D: UartDevice, P: ValidUartPinout<D>> eh1::ErrorType for Reader<D, P> {
type Error = ReadErrorType; type Error = ReadErrorType;
} }
/* disabled for now - nb was migrated to separate crate
#[cfg(feature = "eh1_0_alpha")] #[cfg(feature = "eh1_0_alpha")]
impl<D: UartDevice, P: ValidUartPinout<D>> eh1::nb::Read<u8> for Reader<D, P> { impl<D: UartDevice, P: ValidUartPinout<D>> eh1::nb::Read<u8> for Reader<D, P> {
fn read(&mut self) -> nb::Result<u8, Self::Error> { fn read(&mut self) -> nb::Result<u8, Self::Error> {
@ -253,3 +254,4 @@ impl<D: UartDevice, P: ValidUartPinout<D>> eh1::nb::Read<u8> for Reader<D, P> {
} }
} }
} }
*/

View file

@ -116,26 +116,3 @@ impl Default for UartConfig {
} }
} }
} }
/// Same as core::convert::Infallible, but implementing serial::Error
///
/// For eh 1.0.0-alpha.6, Infallible doesn't implement serial::Error,
/// so use a locally defined type instead.
/// This should be removed with the next release of e-h.
/// (https://github.com/rust-embedded/embedded-hal/pull/328)
#[cfg(feature = "eh1_0_alpha")]
pub enum SerialInfallible {}
#[cfg(feature = "eh1_0_alpha")]
impl core::fmt::Debug for SerialInfallible {
fn fmt(&self, _f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match *self {}
}
}
#[cfg(feature = "eh1_0_alpha")]
impl eh1_0_alpha::serial::Error for SerialInfallible {
fn kind(&self) -> eh1_0_alpha::serial::ErrorKind {
match *self {}
}
}

View file

@ -184,9 +184,10 @@ impl<D: UartDevice, P: ValidUartPinout<D>> Write<u8> for Writer<D, P> {
#[cfg(feature = "eh1_0_alpha")] #[cfg(feature = "eh1_0_alpha")]
impl<D: UartDevice, P: ValidUartPinout<D>> eh1::ErrorType for Writer<D, P> { impl<D: UartDevice, P: ValidUartPinout<D>> eh1::ErrorType for Writer<D, P> {
type Error = super::utils::SerialInfallible; type Error = core::convert::Infallible;
} }
/* disabled for now - nb was migrated to separate crate
#[cfg(feature = "eh1_0_alpha")] #[cfg(feature = "eh1_0_alpha")]
impl<D: UartDevice, P: ValidUartPinout<D>> eh1::nb::Write<u8> for Writer<D, P> { impl<D: UartDevice, P: ValidUartPinout<D>> eh1::nb::Write<u8> for Writer<D, P> {
fn write(&mut self, word: u8) -> nb::Result<(), Self::Error> { fn write(&mut self, word: u8) -> nb::Result<(), Self::Error> {
@ -204,6 +205,7 @@ impl<D: UartDevice, P: ValidUartPinout<D>> eh1::nb::Write<u8> for Writer<D, P> {
}) })
} }
} }
*/
impl<D: UartDevice, P: ValidUartPinout<D>> fmt::Write for Writer<D, P> { impl<D: UartDevice, P: ValidUartPinout<D>> fmt::Write for Writer<D, P> {
fn write_str(&mut self, s: &str) -> fmt::Result { fn write_str(&mut self, s: &str) -> fmt::Result {