Przeglądaj źródła

checks NRF24 hardware faults

vad7 2 lat temu
rodzic
commit
0e4bb3d141
2 zmienionych plików z 8 dodań i 1 usunięć
  1. 5 1
      lib/nrf24/nrf24.c
  2. 3 0
      nrf24batch.c

+ 5 - 1
lib/nrf24/nrf24.c

@@ -189,18 +189,22 @@ uint8_t nrf24_set_packetlen(FuriHalSpiBusHandle* handle, uint8_t len) {
 }
 
 // packet_size: 0 - dyn payload (read from PL_WID), 1 - read from pipe size, >1 - override
+// Return STATUS reg + additional: RX_DR - new data available, 0x80 - NRF24 hardware error
 uint8_t nrf24_rxpacket(FuriHalSpiBusHandle* handle, uint8_t* packet, uint8_t* ret_packetsize, uint8_t packet_size) {
     uint8_t status = 0;
     uint8_t buf[33]; // 32 max payload size + 1 for command
 
     status = nrf24_status(handle);
     if(!(status & RX_DR)) {
-        if((nrf24_read_register(handle, REG_FIFO_STATUS) & 1) == 0) {
+        uint8_t st = nrf24_read_register(handle, REG_FIFO_STATUS);
+        if(st == 0xFF || st == 0) return 0x80; // hardware error
+        if((st & 1) == 0) {
             FURI_LOG_D("NRF", "FIFO PKT");
             status |= RX_DR; // packet in FIFO buffer
         }
     }
     if(status & RX_DR) {
+        if(status & 0x80) return 0x80; // hardware error
         if(packet_size == 1)
             packet_size = nrf24_get_packetlen(handle, (status >> 1) & 7);
         else if(packet_size == 0){

+ 3 - 0
nrf24batch.c

@@ -504,6 +504,9 @@ bool nrf24_read_newpacket() {
 		}
 		//notification_message(APP->notification, &sequence_blink_white_100);
 		found = true;
+	} else if(st & 0x80) { // NRF24 hardware error
+		NRF_ERROR = 1;
+		NRF_INITED = 0;
 	}
 	return found;
 }