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

Furi: more gpio checks in HAL (#2549)

* Furi: more gpio checks in HAL
* Nfc: do not spawn service thread if it is already spawned

Co-authored-by: Sergey Gavrilov <who.just.the.doctor@gmail.com>
あく 2 лет назад
Родитель
Сommit
2a26680acb
2 измененных файлов с 16 добавлено и 13 удалено
  1. 3 3
      firmware/targets/f7/furi_hal/furi_hal_gpio.c
  2. 13 10
      lib/ST25RFAL002/platform.c

+ 3 - 3
firmware/targets/f7/furi_hal/furi_hal_gpio.c

@@ -53,8 +53,8 @@ void furi_hal_gpio_init(
     const GpioPull pull,
     const GpioPull pull,
     const GpioSpeed speed) {
     const GpioSpeed speed) {
     // we cannot set alternate mode in this function
     // we cannot set alternate mode in this function
-    furi_assert(mode != GpioModeAltFunctionPushPull);
-    furi_assert(mode != GpioModeAltFunctionOpenDrain);
+    furi_check(mode != GpioModeAltFunctionPushPull);
+    furi_check(mode != GpioModeAltFunctionOpenDrain);
 
 
     furi_hal_gpio_init_ex(gpio, mode, pull, speed, GpioAltFnUnused);
     furi_hal_gpio_init_ex(gpio, mode, pull, speed, GpioAltFnUnused);
 }
 }
@@ -178,7 +178,7 @@ void furi_hal_gpio_add_int_callback(const GpioPin* gpio, GpioExtiCallback cb, vo
 
 
     FURI_CRITICAL_ENTER();
     FURI_CRITICAL_ENTER();
     uint8_t pin_num = furi_hal_gpio_get_pin_num(gpio);
     uint8_t pin_num = furi_hal_gpio_get_pin_num(gpio);
-    furi_assert(gpio_interrupt[pin_num].callback == NULL);
+    furi_check(gpio_interrupt[pin_num].callback == NULL);
     gpio_interrupt[pin_num].callback = cb;
     gpio_interrupt[pin_num].callback = cb;
     gpio_interrupt[pin_num].context = ctx;
     gpio_interrupt[pin_num].context = ctx;
     gpio_interrupt[pin_num].ready = true;
     gpio_interrupt[pin_num].ready = true;

+ 13 - 10
lib/ST25RFAL002/platform.c

@@ -45,16 +45,19 @@ void platformDisableIrqCallback() {
 
 
 void platformSetIrqCallback(PlatformIrqCallback callback) {
 void platformSetIrqCallback(PlatformIrqCallback callback) {
     rfal_platform.callback = callback;
     rfal_platform.callback = callback;
-    rfal_platform.thread =
-        furi_thread_alloc_ex("RfalIrqDriver", 1024, rfal_platform_irq_thread, NULL);
-    furi_thread_mark_as_service(rfal_platform.thread);
-    furi_thread_set_priority(rfal_platform.thread, FuriThreadPriorityIsr);
-    furi_thread_start(rfal_platform.thread);
-
-    furi_hal_gpio_add_int_callback(&gpio_nfc_irq_rfid_pull, nfc_isr, NULL);
-    // Disable interrupt callback as the pin is shared between 2 apps
-    // It is enabled in rfalLowPowerModeStop()
-    furi_hal_gpio_disable_int_callback(&gpio_nfc_irq_rfid_pull);
+
+    if(!rfal_platform.thread) {
+        rfal_platform.thread =
+            furi_thread_alloc_ex("RfalIrqDriver", 1024, rfal_platform_irq_thread, NULL);
+        furi_thread_mark_as_service(rfal_platform.thread);
+        furi_thread_set_priority(rfal_platform.thread, FuriThreadPriorityIsr);
+        furi_thread_start(rfal_platform.thread);
+
+        furi_hal_gpio_add_int_callback(&gpio_nfc_irq_rfid_pull, nfc_isr, NULL);
+        // Disable interrupt callback as the pin is shared between 2 apps
+        // It is enabled in rfalLowPowerModeStop()
+        furi_hal_gpio_disable_int_callback(&gpio_nfc_irq_rfid_pull);
+    }
 }
 }
 
 
 bool platformSpiTxRx(const uint8_t* txBuf, uint8_t* rxBuf, uint16_t len) {
 bool platformSpiTxRx(const uint8_t* txBuf, uint8_t* rxBuf, uint16_t len) {