nrf24l01: Optimize status reading.

The value of the STATUS register is always transmitted by the chip when
reading any command.  So a R_REGISTER command and the turnaround time can
be spared by issuing a NOP command instead.

This implementation suggested by the datasheet.

This operation is compatible with both nRF24L01 and nRF24L01+.

Signed-off-by: Marcell Pünkösd <punkosdmarcell@rocketmail.com>
pull/955/head
marcsello 2024-12-30 16:10:49 +01:00 zatwierdzone przez Damien George
rodzic bd1ab77324
commit c7103bb464
1 zmienionych plików z 9 dodań i 1 usunięć

Wyświetl plik

@ -130,6 +130,13 @@ class NRF24L01:
self.cs(1)
return ret
def read_status(self):
self.cs(0)
# STATUS register is always shifted during command transmit
self.spi.readinto(self.buf, NOP)
self.cs(1)
return self.buf[0]
def flush_rx(self):
self.cs(0)
self.spi.readinto(self.buf, FLUSH_RX)
@ -250,7 +257,8 @@ class NRF24L01:
# returns None if send still in progress, 1 for success, 2 for fail
def send_done(self):
if not (self.reg_read(STATUS) & (TX_DS | MAX_RT)):
status = self.read_status()
if not (status & (TX_DS | MAX_RT)):
return None # tx not finished
# either finished or failed: get and clear status flags, power down