소스 검색

Nrf23Sniff: Gpio, appid, back button changes

Willy-JL 2 년 전
부모
커밋
d9c46e8f19
4개의 변경된 파일33개의 추가작업 그리고 15개의 파일을 삭제
  1. 1 1
      nrf24sniff/application.fam
  2. 16 0
      nrf24sniff/lib/nrf24/nrf24.c
  3. 5 1
      nrf24sniff/lib/nrf24/nrf24.h
  4. 11 13
      nrf24sniff/nrfsniff.c

+ 1 - 1
nrf24sniff/application.fam

@@ -1,5 +1,5 @@
 App(
-    appid="nrf24_sniffer",
+    appid="nrf24sniff",
     name="[NRF24] Sniffer",
     apptype=FlipperAppType.EXTERNAL,
     entry_point="nrfsniff_app",

+ 16 - 0
nrf24sniff/lib/nrf24/nrf24.c

@@ -6,6 +6,15 @@
 #include <string.h>
 
 void nrf24_init() {
+    // this is needed if multiple SPI devices are connected to the same bus but with different CS pins
+    if(xtreme_settings.spi_nrf24_handle == SpiDefault) {
+        furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeOutputPushPull);
+        furi_hal_gpio_write(&gpio_ext_pc3, true);
+    } else if(xtreme_settings.spi_nrf24_handle == SpiExtra) {
+        furi_hal_gpio_init_simple(&gpio_ext_pa4, GpioModeOutputPushPull);
+        furi_hal_gpio_write(&gpio_ext_pa4, true);
+    }
+
     furi_hal_spi_bus_handle_init(nrf24_HANDLE);
     furi_hal_spi_acquire(nrf24_HANDLE);
     furi_hal_gpio_init(nrf24_CE_PIN, GpioModeOutputPushPull, GpioPullUp, GpioSpeedVeryHigh);
@@ -17,6 +26,13 @@ void nrf24_deinit() {
     furi_hal_spi_bus_handle_deinit(nrf24_HANDLE);
     furi_hal_gpio_write(nrf24_CE_PIN, false);
     furi_hal_gpio_init(nrf24_CE_PIN, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
+
+    // resetting the CS pins to floating
+    if(xtreme_settings.spi_nrf24_handle == SpiDefault) {
+        furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeAnalog);
+    } else if(xtreme_settings.spi_nrf24_handle == SpiExtra) {
+        furi_hal_gpio_init_simple(&gpio_ext_pa4, GpioModeAnalog);
+    }
 }
 
 void nrf24_spi_trx(

+ 5 - 1
nrf24sniff/lib/nrf24/nrf24.h

@@ -3,6 +3,8 @@
 #include <stdint.h>
 #include <furi_hal_spi.h>
 
+#include <xtreme.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -40,7 +42,9 @@ extern "C" {
 
 #define nrf24_TIMEOUT 500
 #define nrf24_CE_PIN &gpio_ext_pb2
-#define nrf24_HANDLE &furi_hal_spi_bus_handle_external
+#define nrf24_HANDLE                                                                         \
+    (xtreme_settings.spi_nrf24_handle == SpiDefault ? &furi_hal_spi_bus_handle_external : \
+                                                         &furi_hal_spi_bus_handle_external_extra)
 
 /* Low level API */
 

+ 11 - 13
nrf24sniff/nrfsniff.c

@@ -10,7 +10,7 @@
 
 #define LOGITECH_MAX_CHANNEL 85
 #define COUNT_THRESHOLD 2
-#define DEFAULT_SAMPLE_TIME 8000
+#define DEFAULT_SAMPLE_TIME 4000
 #define MAX_ADDRS 100
 #define MAX_CONFIRMED 32
 
@@ -426,21 +426,19 @@ int32_t nrfsniff_app(void* p) {
 
                         break;
                     case InputKeyBack:
-                        if(event.input.type == InputTypeLong) {
-                            if(nrf_ready) {
-                                if(sniffing_state) {
-                                    wrap_up(storage, notification);
-                                }
+                        if(nrf_ready) {
+                            if(sniffing_state) {
+                                wrap_up(storage, notification);
+                            }
+                        } else {
+                            if(nrf24_check_connected(nrf24_HANDLE)) {
+                                nrf_ready = true;
                             } else {
-                                if(nrf24_check_connected(nrf24_HANDLE)) {
-                                    nrf_ready = true;
-                                } else {
-                                    nrf_ready = false;
-                                    FURI_LOG_E(TAG, "NRF24 not connected");
-                                }
+                                nrf_ready = false;
+                                FURI_LOG_E(TAG, "NRF24 not connected");
                             }
-                            processing = false;
                         }
+                        processing = false;
                         break;
                     default:
                         break;