2020-10-18 22:09:48 +00:00
|
|
|
#include "platform.h"
|
|
|
|
#include <assert.h>
|
2021-02-10 08:56:05 +00:00
|
|
|
#include <furi.h>
|
2022-01-05 16:10:18 +00:00
|
|
|
#include <furi_hal_spi.h>
|
FL-53: new NFC worker, A/B/F/V poll and display. (#283)
* GUI: view. Flooper-blooper fix compilation error.
* GUI: view and viewdispatcher bones
* GUI: view implementation, view models, view dispatcher
* GUI: view navigation, model refinement. Power: use view, view dispatcher.
* HAL Flash: proper page write. Dolphin: views. Power: views
* Dolphin: transition idle scree to Views
* Dolphin: input events on stats view. Format sources.
* HAL: flash erase. Dolphin: permanent state storage.
* Dolphin: first start welcome. HAL: flash operation status, errata 2.2.9 crutch.
* NFC: rewrite worker
* NFC: add support for B,F,V.
* NFC: replace rfal irq hanlder with realtime thread, more details about cards.
* Bootloader: LSE and RTS shenanigans, LED control, morse code for LSE failure error.
* F4: stop in Error_Handler
* BLE: handle working FUS, but empty radio stack.
* HAL: alive FUS is now sufficient for flash controller access
* Dolphin: update model after state load
* NFC: detect navigation
* RFAL: use osPriorityISR for isr thread
* NFC: emulation
* Bootloader: rollback incorrectly merged rename
* Dolphin: rollback incorrectly merged changes
* RFAL: remove volatile from thread attr
* RFAL: do not call platform ErrorHandler, error codes is enough
* NFC: improved error handling
* Format sources
* NFC: reset detect view model on start
* Format sources
* update codeowners
* NFC: hide last info if no card detected
2021-01-11 12:42:25 +00:00
|
|
|
|
2022-06-20 14:54:48 +00:00
|
|
|
typedef struct {
|
|
|
|
FuriThread* thread;
|
|
|
|
volatile PlatformIrqCallback callback;
|
2022-07-03 14:51:50 +00:00
|
|
|
bool need_spi_lock;
|
2022-06-20 14:54:48 +00:00
|
|
|
} RfalPlatform;
|
2022-02-13 19:24:03 +00:00
|
|
|
|
2022-06-20 14:54:48 +00:00
|
|
|
static volatile RfalPlatform rfal_platform = {
|
|
|
|
.thread = NULL,
|
|
|
|
.callback = NULL,
|
2022-07-03 14:51:50 +00:00
|
|
|
.need_spi_lock = true,
|
2022-06-20 14:54:48 +00:00
|
|
|
};
|
FL-53: new NFC worker, A/B/F/V poll and display. (#283)
* GUI: view. Flooper-blooper fix compilation error.
* GUI: view and viewdispatcher bones
* GUI: view implementation, view models, view dispatcher
* GUI: view navigation, model refinement. Power: use view, view dispatcher.
* HAL Flash: proper page write. Dolphin: views. Power: views
* Dolphin: transition idle scree to Views
* Dolphin: input events on stats view. Format sources.
* HAL: flash erase. Dolphin: permanent state storage.
* Dolphin: first start welcome. HAL: flash operation status, errata 2.2.9 crutch.
* NFC: rewrite worker
* NFC: add support for B,F,V.
* NFC: replace rfal irq hanlder with realtime thread, more details about cards.
* Bootloader: LSE and RTS shenanigans, LED control, morse code for LSE failure error.
* F4: stop in Error_Handler
* BLE: handle working FUS, but empty radio stack.
* HAL: alive FUS is now sufficient for flash controller access
* Dolphin: update model after state load
* NFC: detect navigation
* RFAL: use osPriorityISR for isr thread
* NFC: emulation
* Bootloader: rollback incorrectly merged rename
* Dolphin: rollback incorrectly merged changes
* RFAL: remove volatile from thread attr
* RFAL: do not call platform ErrorHandler, error codes is enough
* NFC: improved error handling
* Format sources
* NFC: reset detect view model on start
* Format sources
* update codeowners
* NFC: hide last info if no card detected
2021-01-11 12:42:25 +00:00
|
|
|
|
2021-04-29 08:51:48 +00:00
|
|
|
void nfc_isr(void* _ctx) {
|
2022-05-06 13:37:10 +00:00
|
|
|
UNUSED(_ctx);
|
2022-06-20 14:54:48 +00:00
|
|
|
if(rfal_platform.callback && platformGpioIsHigh(ST25R_INT_PORT, ST25R_INT_PIN)) {
|
|
|
|
furi_thread_flags_set(furi_thread_get_id(rfal_platform.thread), 0x1);
|
FL-53: new NFC worker, A/B/F/V poll and display. (#283)
* GUI: view. Flooper-blooper fix compilation error.
* GUI: view and viewdispatcher bones
* GUI: view implementation, view models, view dispatcher
* GUI: view navigation, model refinement. Power: use view, view dispatcher.
* HAL Flash: proper page write. Dolphin: views. Power: views
* Dolphin: transition idle scree to Views
* Dolphin: input events on stats view. Format sources.
* HAL: flash erase. Dolphin: permanent state storage.
* Dolphin: first start welcome. HAL: flash operation status, errata 2.2.9 crutch.
* NFC: rewrite worker
* NFC: add support for B,F,V.
* NFC: replace rfal irq hanlder with realtime thread, more details about cards.
* Bootloader: LSE and RTS shenanigans, LED control, morse code for LSE failure error.
* F4: stop in Error_Handler
* BLE: handle working FUS, but empty radio stack.
* HAL: alive FUS is now sufficient for flash controller access
* Dolphin: update model after state load
* NFC: detect navigation
* RFAL: use osPriorityISR for isr thread
* NFC: emulation
* Bootloader: rollback incorrectly merged rename
* Dolphin: rollback incorrectly merged changes
* RFAL: remove volatile from thread attr
* RFAL: do not call platform ErrorHandler, error codes is enough
* NFC: improved error handling
* Format sources
* NFC: reset detect view model on start
* Format sources
* update codeowners
* NFC: hide last info if no card detected
2021-01-11 12:42:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-20 14:54:48 +00:00
|
|
|
int32_t rfal_platform_irq_thread(void* context) {
|
|
|
|
UNUSED(context);
|
|
|
|
|
FL-53: new NFC worker, A/B/F/V poll and display. (#283)
* GUI: view. Flooper-blooper fix compilation error.
* GUI: view and viewdispatcher bones
* GUI: view implementation, view models, view dispatcher
* GUI: view navigation, model refinement. Power: use view, view dispatcher.
* HAL Flash: proper page write. Dolphin: views. Power: views
* Dolphin: transition idle scree to Views
* Dolphin: input events on stats view. Format sources.
* HAL: flash erase. Dolphin: permanent state storage.
* Dolphin: first start welcome. HAL: flash operation status, errata 2.2.9 crutch.
* NFC: rewrite worker
* NFC: add support for B,F,V.
* NFC: replace rfal irq hanlder with realtime thread, more details about cards.
* Bootloader: LSE and RTS shenanigans, LED control, morse code for LSE failure error.
* F4: stop in Error_Handler
* BLE: handle working FUS, but empty radio stack.
* HAL: alive FUS is now sufficient for flash controller access
* Dolphin: update model after state load
* NFC: detect navigation
* RFAL: use osPriorityISR for isr thread
* NFC: emulation
* Bootloader: rollback incorrectly merged rename
* Dolphin: rollback incorrectly merged changes
* RFAL: remove volatile from thread attr
* RFAL: do not call platform ErrorHandler, error codes is enough
* NFC: improved error handling
* Format sources
* NFC: reset detect view model on start
* Format sources
* update codeowners
* NFC: hide last info if no card detected
2021-01-11 12:42:25 +00:00
|
|
|
while(1) {
|
2022-06-20 14:54:48 +00:00
|
|
|
uint32_t flags = furi_thread_flags_wait(0x1, osFlagsWaitAny, osWaitForever);
|
2022-01-05 16:10:18 +00:00
|
|
|
if(flags & 0x1) {
|
2022-06-20 14:54:48 +00:00
|
|
|
rfal_platform.callback();
|
FL-53: new NFC worker, A/B/F/V poll and display. (#283)
* GUI: view. Flooper-blooper fix compilation error.
* GUI: view and viewdispatcher bones
* GUI: view implementation, view models, view dispatcher
* GUI: view navigation, model refinement. Power: use view, view dispatcher.
* HAL Flash: proper page write. Dolphin: views. Power: views
* Dolphin: transition idle scree to Views
* Dolphin: input events on stats view. Format sources.
* HAL: flash erase. Dolphin: permanent state storage.
* Dolphin: first start welcome. HAL: flash operation status, errata 2.2.9 crutch.
* NFC: rewrite worker
* NFC: add support for B,F,V.
* NFC: replace rfal irq hanlder with realtime thread, more details about cards.
* Bootloader: LSE and RTS shenanigans, LED control, morse code for LSE failure error.
* F4: stop in Error_Handler
* BLE: handle working FUS, but empty radio stack.
* HAL: alive FUS is now sufficient for flash controller access
* Dolphin: update model after state load
* NFC: detect navigation
* RFAL: use osPriorityISR for isr thread
* NFC: emulation
* Bootloader: rollback incorrectly merged rename
* Dolphin: rollback incorrectly merged changes
* RFAL: remove volatile from thread attr
* RFAL: do not call platform ErrorHandler, error codes is enough
* NFC: improved error handling
* Format sources
* NFC: reset detect view model on start
* Format sources
* update codeowners
* NFC: hide last info if no card detected
2021-01-11 12:42:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-29 08:51:48 +00:00
|
|
|
void platformEnableIrqCallback() {
|
2022-06-20 14:54:48 +00:00
|
|
|
furi_hal_gpio_init(&gpio_nfc_irq_rfid_pull, GpioModeInterruptRise, GpioPullDown, GpioSpeedLow);
|
|
|
|
furi_hal_gpio_enable_int_callback(&gpio_nfc_irq_rfid_pull);
|
2021-04-29 08:51:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void platformDisableIrqCallback() {
|
2022-06-20 14:54:48 +00:00
|
|
|
furi_hal_gpio_init(&gpio_nfc_irq_rfid_pull, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow);
|
|
|
|
furi_hal_gpio_disable_int_callback(&gpio_nfc_irq_rfid_pull);
|
2021-04-29 08:51:48 +00:00
|
|
|
}
|
|
|
|
|
FL-53: new NFC worker, A/B/F/V poll and display. (#283)
* GUI: view. Flooper-blooper fix compilation error.
* GUI: view and viewdispatcher bones
* GUI: view implementation, view models, view dispatcher
* GUI: view navigation, model refinement. Power: use view, view dispatcher.
* HAL Flash: proper page write. Dolphin: views. Power: views
* Dolphin: transition idle scree to Views
* Dolphin: input events on stats view. Format sources.
* HAL: flash erase. Dolphin: permanent state storage.
* Dolphin: first start welcome. HAL: flash operation status, errata 2.2.9 crutch.
* NFC: rewrite worker
* NFC: add support for B,F,V.
* NFC: replace rfal irq hanlder with realtime thread, more details about cards.
* Bootloader: LSE and RTS shenanigans, LED control, morse code for LSE failure error.
* F4: stop in Error_Handler
* BLE: handle working FUS, but empty radio stack.
* HAL: alive FUS is now sufficient for flash controller access
* Dolphin: update model after state load
* NFC: detect navigation
* RFAL: use osPriorityISR for isr thread
* NFC: emulation
* Bootloader: rollback incorrectly merged rename
* Dolphin: rollback incorrectly merged changes
* RFAL: remove volatile from thread attr
* RFAL: do not call platform ErrorHandler, error codes is enough
* NFC: improved error handling
* Format sources
* NFC: reset detect view model on start
* Format sources
* update codeowners
* NFC: hide last info if no card detected
2021-01-11 12:42:25 +00:00
|
|
|
void platformSetIrqCallback(PlatformIrqCallback callback) {
|
2022-06-20 14:54:48 +00:00
|
|
|
rfal_platform.callback = callback;
|
|
|
|
rfal_platform.thread = furi_thread_alloc();
|
|
|
|
|
|
|
|
furi_thread_set_name(rfal_platform.thread, "RfalIrqDriver");
|
|
|
|
furi_thread_set_callback(rfal_platform.thread, rfal_platform_irq_thread);
|
|
|
|
furi_thread_set_stack_size(rfal_platform.thread, 1024);
|
|
|
|
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);
|
2021-04-29 08:51:48 +00:00
|
|
|
// Disable interrupt callback as the pin is shared between 2 apps
|
|
|
|
// It is enabled in rfalLowPowerModeStop()
|
2022-06-20 14:54:48 +00:00
|
|
|
furi_hal_gpio_disable_int_callback(&gpio_nfc_irq_rfid_pull);
|
FL-53: new NFC worker, A/B/F/V poll and display. (#283)
* GUI: view. Flooper-blooper fix compilation error.
* GUI: view and viewdispatcher bones
* GUI: view implementation, view models, view dispatcher
* GUI: view navigation, model refinement. Power: use view, view dispatcher.
* HAL Flash: proper page write. Dolphin: views. Power: views
* Dolphin: transition idle scree to Views
* Dolphin: input events on stats view. Format sources.
* HAL: flash erase. Dolphin: permanent state storage.
* Dolphin: first start welcome. HAL: flash operation status, errata 2.2.9 crutch.
* NFC: rewrite worker
* NFC: add support for B,F,V.
* NFC: replace rfal irq hanlder with realtime thread, more details about cards.
* Bootloader: LSE and RTS shenanigans, LED control, morse code for LSE failure error.
* F4: stop in Error_Handler
* BLE: handle working FUS, but empty radio stack.
* HAL: alive FUS is now sufficient for flash controller access
* Dolphin: update model after state load
* NFC: detect navigation
* RFAL: use osPriorityISR for isr thread
* NFC: emulation
* Bootloader: rollback incorrectly merged rename
* Dolphin: rollback incorrectly merged changes
* RFAL: remove volatile from thread attr
* RFAL: do not call platform ErrorHandler, error codes is enough
* NFC: improved error handling
* Format sources
* NFC: reset detect view model on start
* Format sources
* update codeowners
* NFC: hide last info if no card detected
2021-01-11 12:42:25 +00:00
|
|
|
}
|
2020-10-18 22:09:48 +00:00
|
|
|
|
2022-03-30 15:23:40 +00:00
|
|
|
bool platformSpiTxRx(const uint8_t* txBuf, uint8_t* rxBuf, uint16_t len) {
|
2021-03-31 17:52:26 +00:00
|
|
|
bool ret = false;
|
2022-01-05 16:10:18 +00:00
|
|
|
if(txBuf && rxBuf) {
|
|
|
|
ret =
|
|
|
|
furi_hal_spi_bus_trx(&furi_hal_spi_bus_handle_nfc, (uint8_t*)txBuf, rxBuf, len, 1000);
|
|
|
|
} else if(txBuf) {
|
2021-11-30 12:09:43 +00:00
|
|
|
ret = furi_hal_spi_bus_tx(&furi_hal_spi_bus_handle_nfc, (uint8_t*)txBuf, len, 1000);
|
2022-01-05 16:10:18 +00:00
|
|
|
} else if(rxBuf) {
|
2021-11-30 12:09:43 +00:00
|
|
|
ret = furi_hal_spi_bus_rx(&furi_hal_spi_bus_handle_nfc, (uint8_t*)rxBuf, len, 1000);
|
2020-10-18 22:09:48 +00:00
|
|
|
}
|
2021-03-31 17:52:26 +00:00
|
|
|
|
2022-03-30 15:23:40 +00:00
|
|
|
return ret;
|
2020-10-18 22:09:48 +00:00
|
|
|
}
|
|
|
|
|
2022-07-03 14:51:50 +00:00
|
|
|
// Until we completely remove RFAL, NFC works with SPI from rfal_platform_irq_thread and nfc_worker
|
|
|
|
// threads. Some nfc features already stop using RFAL and work with SPI from nfc_worker only.
|
|
|
|
// rfal_platform_spi_acquire() and rfal_platform_spi_release() functions are used to lock SPI for a
|
|
|
|
// long term without locking it for each SPI transaction. This is needed for time critical communications.
|
|
|
|
void rfal_platform_spi_acquire() {
|
|
|
|
platformDisableIrqCallback();
|
|
|
|
rfal_platform.need_spi_lock = false;
|
2021-11-30 12:09:43 +00:00
|
|
|
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_nfc);
|
2020-10-18 22:09:48 +00:00
|
|
|
}
|
|
|
|
|
2022-07-03 14:51:50 +00:00
|
|
|
void rfal_platform_spi_release() {
|
2021-11-30 12:09:43 +00:00
|
|
|
furi_hal_spi_release(&furi_hal_spi_bus_handle_nfc);
|
2022-07-03 14:51:50 +00:00
|
|
|
rfal_platform.need_spi_lock = true;
|
|
|
|
platformEnableIrqCallback();
|
|
|
|
}
|
|
|
|
|
|
|
|
void platformProtectST25RComm() {
|
|
|
|
if(rfal_platform.need_spi_lock) {
|
|
|
|
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_nfc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void platformUnprotectST25RComm() {
|
|
|
|
if(rfal_platform.need_spi_lock) {
|
|
|
|
furi_hal_spi_release(&furi_hal_spi_bus_handle_nfc);
|
|
|
|
}
|
2020-10-18 22:09:48 +00:00
|
|
|
}
|