diff --git a/src/lib.rs b/src/lib.rs index b957b3195d3f4ad9f4d73351ef8a640dabdd404e..6fcc0faaaf3f54488de62b23400ed995cc8f22e0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -81,10 +81,13 @@ where matches!(self.state, InternalState::Idle) } - pub fn start_rx(&mut self, rx_forever: bool) -> Result<(), Spi::Error> { + // Len is none when using a variable-length packet + pub fn start_rx(&mut self, len: Option<usize>, rx_forever: bool) -> Result<(), Spi::Error> { self.radio.clear_fifo()?; self.radio.clear_ph_and_modem_interrupts()?; + let len = len.unwrap_or(0); + self.state = InternalState::Rx { data: [0; MAX_PACKET_LEN], i: 0, @@ -96,8 +99,8 @@ where START_RX, self.channel, 0, - (MAX_PACKET_LEN >> 8).try_into().unwrap(), - (MAX_PACKET_LEN & 0xff).try_into().unwrap(), + (len >> 8).try_into().unwrap(), + (len & 0xff).try_into().unwrap(), State::Rx.into(), if rx_forever { State::Rx.into()