mirror of
https://github.com/italicsjenga/rp-hal-boards.git
synced 2025-01-11 13:01:30 +11:00
Update SPI implementation of embedded-hal 1.x to 1.0.0-alpha.6
This commit is contained in:
parent
0f3bb8e88c
commit
1294f556e9
|
@ -186,6 +186,27 @@ 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.
|
||||||
|
#[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),+]) => {
|
||||||
|
|
||||||
|
@ -221,16 +242,16 @@ macro_rules! impl_write {
|
||||||
|
|
||||||
#[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> {
|
||||||
type Error = Infallible;
|
type Error = SpiInfallible;
|
||||||
|
|
||||||
fn read(&mut self) -> Result<$type, nb::Error<Infallible>> {
|
fn read(&mut self) -> Result<$type, nb::Error<SpiInfallible>> {
|
||||||
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<Infallible>> {
|
fn write(&mut self, word: $type) -> Result<(), nb::Error<SpiInfallible>> {
|
||||||
// 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.
|
||||||
|
|
Loading…
Reference in a new issue