Added bus model and InactiveW5500 state
This commit is contained in:
parent
03e30ef699
commit
a43f86d744
7 changed files with 130 additions and 40 deletions
|
|
@ -1,15 +1,13 @@
|
|||
use embedded_hal::digital::v2::OutputPin;
|
||||
use embedded_hal::spi::FullDuplex;
|
||||
|
||||
use crate::bus::Bus;
|
||||
use crate::bus::{ActiveBus, Bus};
|
||||
|
||||
pub struct FourWire<ChipSelect: OutputPin> {
|
||||
cs: ChipSelect
|
||||
cs: ChipSelect,
|
||||
}
|
||||
|
||||
impl<ChipSelect: OutputPin>
|
||||
FourWire<ChipSelect>
|
||||
{
|
||||
impl<ChipSelect: OutputPin> FourWire<ChipSelect> {
|
||||
pub fn new(cs: ChipSelect) -> Self {
|
||||
Self { cs }
|
||||
}
|
||||
|
|
@ -18,12 +16,22 @@ impl<ChipSelect: OutputPin>
|
|||
}
|
||||
}
|
||||
|
||||
impl<Spi: FullDuplex<u8>, ChipSelect: OutputPin> Bus<Spi>
|
||||
for FourWire<ChipSelect>
|
||||
{
|
||||
impl<ChipSelect: OutputPin> Bus for FourWire<ChipSelect> {}
|
||||
|
||||
impl<ChipSelect: OutputPin> FourWire<ChipSelect> {
|
||||
pub fn activate<Spi: FullDuplex<u8>>(self, spi: Spi) -> ActiveFourWire<Spi, ChipSelect> {
|
||||
ActiveFourWire { cs: self.cs, spi }
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ActiveFourWire<Spi: FullDuplex<u8>, ChipSelect: OutputPin> {
|
||||
cs: ChipSelect,
|
||||
spi: Spi,
|
||||
}
|
||||
|
||||
impl<Spi: FullDuplex<u8>, ChipSelect: OutputPin> ActiveBus for ActiveFourWire<Spi, ChipSelect> {
|
||||
type Error = FourWireError<Spi::Error, ChipSelect::Error>;
|
||||
fn transfer_frame<'a, 'b>(
|
||||
spi: &'b mut Spi,
|
||||
fn transfer_frame<'a>(
|
||||
address_phase: [u8; 2],
|
||||
control_phase: u8,
|
||||
data_phase: &'a mut [u8],
|
||||
|
|
@ -32,6 +40,11 @@ impl<Spi: FullDuplex<u8>, ChipSelect: OutputPin> Bus<Spi>
|
|||
Ok(data_phase)
|
||||
}
|
||||
}
|
||||
impl<Spi: FullDuplex<u8>, ChipSelect: OutputPin> ActiveFourWire<Spi, ChipSelect> {
|
||||
pub fn deactivate(self) -> (FourWire<ChipSelect>, Spi) {
|
||||
(FourWire::new(self.cs), self.spi)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum FourWireError<SpiError, ChipSelectError> {
|
||||
SpiError(SpiError),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue