Removed refcell container from Interface

This commit is contained in:
Jonah Dahlquist 2021-01-19 21:47:08 -08:00
commit d6574b8c23
2 changed files with 10 additions and 12 deletions

View file

@ -9,18 +9,16 @@ use crate::uninitialized_device::{InitializeError, UninitializedDevice};
use crate::{MacAddress, Mode};
pub struct Interface<SpiBus: ActiveBus, HostImpl: Host> {
pub device: RefCell<Device<SpiBus, HostImpl>>,
pub device: Device<SpiBus, HostImpl>,
}
impl<SpiBus: ActiveBus, HostImpl: Host> Interface<SpiBus, HostImpl> {
fn new(device: Device<SpiBus, HostImpl>) -> Self {
Self {
device: RefCell::new(device),
}
Self { device }
}
pub fn release(self) -> Device<SpiBus, HostImpl> {
self.device.into_inner()
self.device
}
}

View file

@ -187,7 +187,7 @@ where
type Error = UdpSocketError<SpiBus::Error>;
fn socket(&mut self) -> Result<Self::UdpSocket, Self::Error> {
let mut device = self.device.borrow_mut();
let mut device = &mut self.device;
if let Some(socket) = device.take_socket() {
Ok(UdpSocket::new(socket))
} else {
@ -200,7 +200,7 @@ where
socket: &mut Self::UdpSocket,
remote: SocketAddr,
) -> Result<(), Self::Error> {
let mut device = self.device.borrow_mut();
let mut device = &mut self.device;
if let SocketAddr::V4(remote) = remote {
// TODO find a random port
socket.open(&mut device.bus, 4000)?;
@ -211,7 +211,7 @@ where
}
}
fn send(&mut self, socket: &mut Self::UdpSocket, buffer: &[u8]) -> nb::Result<(), Self::Error> {
socket.send(&mut self.device.borrow_mut().bus, buffer)?;
socket.send(&mut self.device.bus, buffer)?;
Ok(())
}
fn receive(
@ -219,10 +219,10 @@ where
socket: &mut Self::UdpSocket,
buffer: &mut [u8],
) -> nb::Result<(usize, SocketAddr), Self::Error> {
Ok(socket.receive(&mut self.device.borrow_mut().bus, buffer)?)
Ok(socket.receive(&mut self.device.bus, buffer)?)
}
fn close(&mut self, socket: Self::UdpSocket) -> Result<(), Self::Error> {
let mut device = self.device.borrow_mut();
let mut device = &mut self.device;
socket.close(&mut device.bus)?;
device.release_socket(socket.socket);
Ok(())
@ -235,7 +235,7 @@ where
HostImpl: Host,
{
fn bind(&mut self, socket: &mut Self::UdpSocket, local_port: u16) -> Result<(), Self::Error> {
let mut device = self.device.borrow_mut();
let mut device = &mut self.device;
socket.open(&mut device.bus, local_port)?;
Ok(())
}
@ -246,7 +246,7 @@ where
buffer: &[u8],
) -> nb::Result<(), Self::Error> {
if let SocketAddr::V4(remote) = remote {
socket.send_to(&mut self.device.borrow_mut().bus, remote, buffer)?;
socket.send_to(&mut self.device.bus, remote, buffer)?;
Ok(())
} else {
Err(nb::Error::Other(Self::Error::UnsupportedAddress))