Просмотр исходного кода

Nrf24Scan: Port save path, gpio, appid changes

Willy-JL 2 лет назад
Родитель
Сommit
016715dc28
4 измененных файлов с 23 добавлено и 3 удалено
  1. 1 1
      nrf24scan/application.fam
  2. 16 0
      nrf24scan/lib/nrf24/nrf24.c
  3. 4 1
      nrf24scan/lib/nrf24/nrf24.h
  4. 2 1
      nrf24scan/nrf24scan.c

+ 1 - 1
nrf24scan/application.fam

@@ -1,5 +1,5 @@
 App(
-    appid="nrf24_scanner",
+    appid="nrf24scan",
     name="[NRF24] Scanner",
     apptype=FlipperAppType.EXTERNAL,
     entry_point="nrf24scan_app",

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

@@ -8,6 +8,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);
@@ -19,6 +28,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(

+ 4 - 1
nrf24scan/lib/nrf24/nrf24.h

@@ -2,6 +2,7 @@
 #include <stdbool.h>
 #include <stdint.h>
 #include <furi_hal_spi.h>
+#include <xtreme.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -52,7 +53,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 */
 

+ 2 - 1
nrf24scan/nrf24scan.c

@@ -18,7 +18,7 @@
 #define MAX_CHANNEL	125
 #define MAX_ADDR	6
 
-#define SCAN_APP_PATH_FOLDER "/ext/nrf24scan"
+#define SCAN_APP_PATH_FOLDER STORAGE_APP_DATA_PATH_PREFIX
 #define SETTINGS_FILENAME "addresses.txt"// Settings file format (1 parameter per line): 
 									// SNIFF - if present then sniff mode
 									// Rate: 0/1/2 - rate in Mbps (=0.25/1/2)
@@ -1148,6 +1148,7 @@ int32_t nrf24scan_app(void* p) {
 	gui_add_view_port(APP->gui, APP->view_port, GuiLayerFullscreen);
 	APP->notification = furi_record_open(RECORD_NOTIFICATION);
 	APP->storage = furi_record_open(RECORD_STORAGE);
+    storage_common_migrate(APP->storage, EXT_PATH("nrf24scan"), SCAN_APP_PATH_FOLDER);
 	storage_common_mkdir(APP->storage, SCAN_APP_PATH_FOLDER);
 	Stream* file_stream = file_stream_alloc(APP->storage);
 	FuriString* path = furi_string_alloc();