Skip to content

Commit

Permalink
Merge pull request #10 from akloboucnik/get-ready-packet-size
Browse files Browse the repository at this point in the history
Expose reading of ready packet size as separate public method
  • Loading branch information
mr-glt authored Jan 24, 2022
2 parents cc7e894 + 4622029 commit 6d4a8ac
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,12 @@ where
}
}

/// Returns the contents of the fifo as a fixed 255 u8 array. This should only be called is there is a
/// Returns the contents of the fifo as a fixed 255 u8 array. This should only be called if there is a
/// new packet ready to be read.
pub fn read_packet(&mut self) -> Result<[u8; 255], Error<E, CS::Error, RESET::Error>> {
let mut buffer = [0 as u8; 255];
self.clear_irq()?;
let size = self.read_register(Register::RegRxNbBytes.addr())?;
let size = self.get_ready_packet_size()?;
let fifo_addr = self.read_register(Register::RegFifoRxCurrentAddr.addr())?;
self.write_register(Register::RegFifoAddrPtr.addr(), fifo_addr)?;
for i in 0..size {
Expand All @@ -351,6 +351,12 @@ where
Ok(buffer)
}

/// Returns size of a packet read into FIFO. This should only be calle if there is a new packet
/// ready to be read.
pub fn get_ready_packet_size(&mut self) -> Result<u8, Error<E, CS::Error, RESET::Error>> {
self.read_register(Register::RegRxNbBytes.addr())
}

/// Returns true if the radio is currently transmitting a packet.
pub fn transmitting(&mut self) -> Result<bool, Error<E, CS::Error, RESET::Error>> {
let op_mode = self.read_register(Register::RegOpMode.addr())?;
Expand Down

0 comments on commit 6d4a8ac

Please sign in to comment.