-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restructure and implement embedded-nal UDP traits #26
Changes from 1 commit
03e30ef
a43f86d
16e813e
aa0c69b
d47de54
3177bad
ce36644
7dd4c04
fd9e861
d2fb6b9
e74f7f4
b30e4d0
e8c8e3c
bd78b82
715cdea
b82bb92
65a9552
36df284
95ca1be
d0f5792
423d2f6
332ab92
63890a5
b9f9166
b6a52cb
adc7005
4ff4bc9
3dbb2d4
074e01e
41cd42e
8aa5656
b1e83e3
f546ff2
3cad9ca
1d533b2
79b1f52
6caeeae
79dc9a4
cc4db22
1cac758
dcfa655
839367b
2b59081
2f26a50
90604fc
259da58
d3ca4a3
da2bcd4
9a05719
d844a11
d6574b8
5509732
ca8268a
a3e0911
daa1c00
b49f41c
dfa252f
52f0d06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…traits to allow users to use shared-bus
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,15 @@ | ||
use core::fmt::Debug; | ||
use embedded_hal::spi::FullDuplex; | ||
|
||
mod four_wire; | ||
mod three_wire; | ||
|
||
pub use self::four_wire::ActiveFourWire; | ||
pub use self::four_wire::FourWire; | ||
pub use self::three_wire::ActiveThreeWire; | ||
pub use self::three_wire::ThreeWire; | ||
|
||
pub trait Bus {} | ||
|
||
pub trait ActiveBus { | ||
pub trait Bus { | ||
type Error: Debug; | ||
|
||
fn read_frame(&mut self, block: u8, address: u16, data: &mut [u8]) -> Result<(), Self::Error>; | ||
|
||
fn write_frame(&mut self, block: u8, address: u16, data: &[u8]) -> Result<(), Self::Error>; | ||
|
||
fn read_bytes<Spi: FullDuplex<u8>>(spi: &mut Spi, bytes: &mut [u8]) -> Result<(), Spi::Error> { | ||
for byte in bytes.iter_mut() { | ||
*byte = Self::transfer_byte(spi, *byte)?; | ||
} | ||
Ok(()) | ||
} | ||
|
||
fn write_bytes<Spi: FullDuplex<u8>>(spi: &mut Spi, bytes: &[u8]) -> Result<(), Spi::Error> { | ||
for byte in bytes.iter() { | ||
Self::transfer_byte(spi, *byte)?; | ||
} | ||
Ok(()) | ||
} | ||
|
||
fn transfer_byte<Spi: FullDuplex<u8>>(spi: &mut Spi, byte: u8) -> Result<u8, Spi::Error> { | ||
block!(spi.send(byte)).and_then(|_| block!(spi.read())) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,18 +3,14 @@ use crate::uninitialized_device::UninitializedDevice; | |
use bit_field::BitArray; | ||
use bus::{ActiveBus, ActiveFourWire, ActiveThreeWire, FourWire, ThreeWire}; | ||
use embedded_hal::digital::v2::OutputPin; | ||
use embedded_hal::spi::FullDuplex; | ||
|
||
use interface::Interface; | ||
use network::Network; | ||
use crate::bus::{ActiveBus, ActiveFourWire, ActiveThreeWire, FourWire, ThreeWire}; | ||
use crate::bus::{Bus, FourWire, ThreeWire}; | ||
use crate::host::Host; | ||
use crate::inactive_device::InactiveDevice; | ||
use crate::register; | ||
use crate::socket::Socket; | ||
use crate::uninitialized_device::UninitializedDevice; | ||
|
||
pub struct Device<SpiBus: ActiveBus, HostImpl: Host> { | ||
pub struct Device<SpiBus: Bus, HostImpl: Host> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldnt this be called something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I felt that was kind of repetitive, considering the crate is already called |
||
pub bus: SpiBus, | ||
host: HostImpl, | ||
sockets: [u8; 1], | ||
|
@@ -31,7 +27,7 @@ impl<E> From<E> for ResetError<E> { | |
} | ||
} | ||
|
||
impl<SpiBus: ActiveBus, HostImpl: Host> Device<SpiBus, HostImpl> { | ||
impl<SpiBus: Bus, HostImpl: Host> Device<SpiBus, HostImpl> { | ||
pub fn new(bus: SpiBus, host: HostImpl) -> Self { | ||
Device { | ||
bus, | ||
|
@@ -58,6 +54,7 @@ impl<SpiBus: ActiveBus, HostImpl: Host> Device<SpiBus, HostImpl> { | |
} | ||
|
||
pub fn take_socket(&mut self) -> Option<Socket> { | ||
// TODO maybe return Future that resolves when release_socket invoked | ||
for index in 0..8 { | ||
if self.sockets.get_bit(index) { | ||
self.sockets.set_bit(index, false); | ||
|
@@ -82,19 +79,3 @@ impl<SpiBus: ActiveBus, HostImpl: Host> Device<SpiBus, HostImpl> { | |
(self.bus, self.host) | ||
} | ||
} | ||
|
||
impl<Spi: FullDuplex<u8>, ChipSelect: OutputPin, HostImpl: Host> | ||
Device<ActiveFourWire<Spi, ChipSelect>, HostImpl> | ||
{ | ||
pub fn deactivate(self) -> (InactiveDevice<FourWire<ChipSelect>, HostImpl>, Spi) { | ||
let (bus, spi) = self.bus.deactivate(); | ||
(InactiveDevice::new(bus, self.host), spi) | ||
} | ||
} | ||
|
||
impl<Spi: FullDuplex<u8>, HostImpl: Host> Device<ActiveThreeWire<Spi>, HostImpl> { | ||
pub fn deactivate(self) -> (InactiveDevice<ThreeWire, HostImpl>, Spi) { | ||
let (bus, spi) = self.bus.deactivate(); | ||
(InactiveDevice::new(bus, self.host), spi) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What stands FDM for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed length Data Mode (see screenshot of datasheet above).