Fixed representation of enum to be u8, fixed FourWire bus to set CS pin low during communication, instead of high

This commit is contained in:
Jonah Dahlquist 2019-10-23 22:40:13 -05:00 committed by Jonah Dahlquist
commit adc7005255
2 changed files with 4 additions and 2 deletions

View file

@ -50,14 +50,14 @@ impl<Spi: FullDuplex<u8>, ChipSelect: OutputPin> ActiveBus for ActiveFourWire<Sp
BigEndian::write_u16(&mut address_phase, address); BigEndian::write_u16(&mut address_phase, address);
self.cs self.cs
.set_high() .set_low()
.map_err(|e| FourWireError::ChipSelectError(e))?; .map_err(|e| FourWireError::ChipSelectError(e))?;
block!(Self::transfer_bytes(&mut self.spi, &mut address_phase) block!(Self::transfer_bytes(&mut self.spi, &mut address_phase)
.and_then(|_| Self::transfer_byte(&mut self.spi, &mut control_phase)) .and_then(|_| Self::transfer_byte(&mut self.spi, &mut control_phase))
.and_then(|_| Self::transfer_bytes(&mut self.spi, data_phase))) .and_then(|_| Self::transfer_bytes(&mut self.spi, data_phase)))
.map_err(|e| FourWireError::SpiError(e))?; .map_err(|e| FourWireError::SpiError(e))?;
self.cs self.cs
.set_low() .set_high()
.map_err(|e| FourWireError::ChipSelectError(e))?; .map_err(|e| FourWireError::ChipSelectError(e))?;
Ok(data_phase) Ok(data_phase)
@ -69,6 +69,7 @@ impl<Spi: FullDuplex<u8>, ChipSelect: OutputPin> ActiveFourWire<Spi, ChipSelect>
} }
} }
#[repr(u8)]
pub enum FourWireError<SpiError, ChipSelectError> { pub enum FourWireError<SpiError, ChipSelectError> {
SpiError(SpiError), SpiError(SpiError),
ChipSelectError(ChipSelectError), ChipSelectError(ChipSelectError),

View file

@ -12,6 +12,7 @@ pub struct UninitializedW5500<SpiBus: ActiveBus> {
bus: SpiBus, bus: SpiBus,
} }
#[repr(u8)]
pub enum InitializeError<SpiError> { pub enum InitializeError<SpiError> {
SpiError(SpiError), SpiError(SpiError),
ChipNotConnected, ChipNotConnected,