Fix cursor: wrapping_add for ptr, immutable sock
This commit is contained in:
parent
388f92c557
commit
1eb9b25c7e
2 changed files with 8 additions and 8 deletions
|
|
@ -6,7 +6,7 @@ pub(crate) struct RxCursor<'a, SpiBus>
|
||||||
where
|
where
|
||||||
SpiBus: Bus,
|
SpiBus: Bus,
|
||||||
{
|
{
|
||||||
sock: &'a mut Socket,
|
sock: &'a Socket,
|
||||||
bus: &'a mut SpiBus,
|
bus: &'a mut SpiBus,
|
||||||
ptr: u16,
|
ptr: u16,
|
||||||
size: u16,
|
size: u16,
|
||||||
|
|
@ -16,7 +16,7 @@ impl<'a, SpiBus> RxCursor<'a, SpiBus>
|
||||||
where
|
where
|
||||||
SpiBus: Bus,
|
SpiBus: Bus,
|
||||||
{
|
{
|
||||||
pub fn new(sock: &'a mut Socket, bus: &'a mut SpiBus) -> Result<Self, SpiBus::Error> {
|
pub fn new(sock: &'a Socket, bus: &'a mut SpiBus) -> Result<Self, SpiBus::Error> {
|
||||||
let size = sock.get_receive_size(bus)?;
|
let size = sock.get_receive_size(bus)?;
|
||||||
let ptr = sock.get_rx_read_pointer(bus)?;
|
let ptr = sock.get_rx_read_pointer(bus)?;
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
|
|
@ -57,7 +57,7 @@ where
|
||||||
/// Skip up to count bytes. The actual number of bytes skipped is bounded by available().
|
/// Skip up to count bytes. The actual number of bytes skipped is bounded by available().
|
||||||
pub fn skip(&mut self, count: u16) -> u16 {
|
pub fn skip(&mut self, count: u16) -> u16 {
|
||||||
let bounded_count = self.available().min(count);
|
let bounded_count = self.available().min(count);
|
||||||
self.ptr += bounded_count;
|
self.ptr = self.ptr.wrapping_add(bounded_count);
|
||||||
self.size -= bounded_count;
|
self.size -= bounded_count;
|
||||||
bounded_count
|
bounded_count
|
||||||
}
|
}
|
||||||
|
|
@ -75,7 +75,7 @@ pub(crate) struct TxCursor<'a, SpiBus>
|
||||||
where
|
where
|
||||||
SpiBus: Bus,
|
SpiBus: Bus,
|
||||||
{
|
{
|
||||||
sock: &'a mut Socket,
|
sock: &'a Socket,
|
||||||
bus: &'a mut SpiBus,
|
bus: &'a mut SpiBus,
|
||||||
ptr: u16,
|
ptr: u16,
|
||||||
size: u16,
|
size: u16,
|
||||||
|
|
@ -85,7 +85,7 @@ impl<'a, SpiBus> TxCursor<'a, SpiBus>
|
||||||
where
|
where
|
||||||
SpiBus: Bus,
|
SpiBus: Bus,
|
||||||
{
|
{
|
||||||
pub fn new(sock: &'a mut Socket, bus: &'a mut SpiBus) -> Result<Self, SpiBus::Error> {
|
pub fn new(sock: &'a Socket, bus: &'a mut SpiBus) -> Result<Self, SpiBus::Error> {
|
||||||
let size = sock.get_tx_free_size(bus)?;
|
let size = sock.get_tx_free_size(bus)?;
|
||||||
let ptr = sock.get_tx_write_pointer(bus)?;
|
let ptr = sock.get_tx_write_pointer(bus)?;
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
|
|
@ -111,7 +111,7 @@ where
|
||||||
let count = buf.len() as u16;
|
let count = buf.len() as u16;
|
||||||
self.bus
|
self.bus
|
||||||
.write_frame(self.sock.tx_buffer(), self.ptr, &buf[..count as _])?;
|
.write_frame(self.sock.tx_buffer(), self.ptr, &buf[..count as _])?;
|
||||||
self.ptr += count;
|
self.ptr = self.ptr.wrapping_add(count);
|
||||||
self.size -= count;
|
self.size -= count;
|
||||||
Ok(count)
|
Ok(count)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ impl<SpiBus: Bus> RawDevice<SpiBus> {
|
||||||
/// # Returns
|
/// # Returns
|
||||||
/// The number of bytes read into the provided frame buffer.
|
/// The number of bytes read into the provided frame buffer.
|
||||||
pub fn read_frame(&mut self, frame: &mut [u8]) -> Result<usize, SpiBus::Error> {
|
pub fn read_frame(&mut self, frame: &mut [u8]) -> Result<usize, SpiBus::Error> {
|
||||||
let mut rx_cursor = crate::cursor::RxCursor::new(&mut self.raw_socket, &mut self.bus)?;
|
let mut rx_cursor = crate::cursor::RxCursor::new(&self.raw_socket, &mut self.bus)?;
|
||||||
|
|
||||||
// Check if there is anything to receive.
|
// Check if there is anything to receive.
|
||||||
if rx_cursor.available() == 0 {
|
if rx_cursor.available() == 0 {
|
||||||
|
|
@ -84,7 +84,7 @@ impl<SpiBus: Bus> RawDevice<SpiBus> {
|
||||||
self.raw_socket
|
self.raw_socket
|
||||||
.reset_interrupt(&mut self.bus, register::socketn::Interrupt::SendOk)?;
|
.reset_interrupt(&mut self.bus, register::socketn::Interrupt::SendOk)?;
|
||||||
|
|
||||||
let mut tx_cursor = crate::cursor::TxCursor::new(&mut self.raw_socket, &mut self.bus)?;
|
let mut tx_cursor = crate::cursor::TxCursor::new(&self.raw_socket, &mut self.bus)?;
|
||||||
let count = tx_cursor.write(frame)?;
|
let count = tx_cursor.write(frame)?;
|
||||||
tx_cursor.commit()?;
|
tx_cursor.commit()?;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue