net-w5500: integrate into main repo.

This commit is contained in:
Dario Nieuwenhuis
2023-05-31 01:01:30 +02:00
parent 82d765689a
commit d70994e4a8
10 changed files with 55 additions and 149 deletions

View File

@ -1,17 +1,13 @@
use crate::device::RegisterBlock;
use embedded_hal_async::spi::{Operation, SpiDevice};
use crate::device::RegisterBlock;
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct SpiInterface<SPI>(pub SPI);
impl<SPI: SpiDevice> SpiInterface<SPI> {
pub async fn read_frame(
&mut self,
block: RegisterBlock,
address: u16,
data: &mut [u8],
) -> Result<(), SPI::Error> {
pub async fn read_frame(&mut self, block: RegisterBlock, address: u16, data: &mut [u8]) -> Result<(), SPI::Error> {
let address_phase = address.to_be_bytes();
let control_phase = [(block as u8) << 3];
let operations = &mut [
@ -22,12 +18,7 @@ impl<SPI: SpiDevice> SpiInterface<SPI> {
self.0.transaction(operations).await
}
pub async fn write_frame(
&mut self,
block: RegisterBlock,
address: u16,
data: &[u8],
) -> Result<(), SPI::Error> {
pub async fn write_frame(&mut self, block: RegisterBlock, address: u16, data: &[u8]) -> Result<(), SPI::Error> {
let address_phase = address.to_be_bytes();
let control_phase = [(block as u8) << 3 | 0b0000_0100];
let data_phase = data;