2020-10-19 01:09:48 +03:00
|
|
|
#include "platform.h"
|
|
|
|
#include <assert.h>
|
2020-11-06 11:31:59 +03:00
|
|
|
#include <main.h>
|
2021-02-10 11:56:05 +03:00
|
|
|
#include <furi.h>
|
2021-08-08 21:03:25 +03: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 15:42:25 +03:00
|
|
|
|
|
|
|
static osThreadAttr_t platform_irq_thread_attr;
|
|
|
|
static volatile osThreadId_t platform_irq_thread_id = NULL;
|
|
|
|
static volatile PlatformIrqCallback platform_irq_callback = NULL;
|
2021-08-08 21:03:25 +03:00
|
|
|
static FuriHalSpiDevice* platform_st25r3916 = NULL;
|
2021-04-29 11:51:48 +03:00
|
|
|
static const GpioPin pin = {ST25R_INT_PORT, ST25R_INT_PIN};
|
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 15:42:25 +03:00
|
|
|
|
2021-04-29 11:51:48 +03:00
|
|
|
void nfc_isr(void* _ctx) {
|
|
|
|
if(platform_irq_callback
|
|
|
|
&& platformGpioIsHigh(ST25R_INT_PORT, ST25R_INT_PIN)) {
|
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 15:42:25 +03:00
|
|
|
osThreadFlagsSet(platform_irq_thread_id, 0x1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void platformIrqWorker() {
|
|
|
|
while(1) {
|
|
|
|
uint32_t flags = osThreadFlagsWait(0x1, osFlagsWaitAny, osWaitForever);
|
|
|
|
if (flags & 0x1) {
|
|
|
|
platform_irq_callback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-29 11:51:48 +03:00
|
|
|
void platformEnableIrqCallback() {
|
2021-08-03 20:24:20 +03:00
|
|
|
hal_gpio_init(&pin, GpioModeInterruptRise, GpioPullDown, GpioSpeedLow);
|
2021-04-29 11:51:48 +03:00
|
|
|
hal_gpio_enable_int_callback(&pin);
|
|
|
|
}
|
|
|
|
|
|
|
|
void platformDisableIrqCallback() {
|
|
|
|
hal_gpio_init(&pin, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow);
|
|
|
|
hal_gpio_disable_int_callback(&pin);
|
|
|
|
}
|
|
|
|
|
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 15:42:25 +03:00
|
|
|
void platformSetIrqCallback(PlatformIrqCallback callback) {
|
|
|
|
platform_irq_callback = callback;
|
2021-11-11 19:17:50 +03:00
|
|
|
platform_irq_thread_attr.name = "RfalIrqWorker";
|
2021-02-18 15:49:32 +03:00
|
|
|
platform_irq_thread_attr.stack_size = 1024;
|
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 15:42:25 +03:00
|
|
|
platform_irq_thread_attr.priority = osPriorityISR;
|
|
|
|
platform_irq_thread_id = osThreadNew(platformIrqWorker, NULL, &platform_irq_thread_attr);
|
2021-04-29 11:51:48 +03:00
|
|
|
hal_gpio_add_int_callback(&pin, nfc_isr, NULL);
|
|
|
|
// Disable interrupt callback as the pin is shared between 2 apps
|
|
|
|
// It is enabled in rfalLowPowerModeStop()
|
|
|
|
hal_gpio_disable_int_callback(&pin);
|
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 15:42:25 +03:00
|
|
|
}
|
2020-10-19 01:09:48 +03:00
|
|
|
|
|
|
|
HAL_StatusTypeDef platformSpiTxRx(const uint8_t *txBuf, uint8_t *rxBuf, uint16_t len) {
|
2021-04-04 13:45:55 +03:00
|
|
|
furi_assert(platform_st25r3916);
|
2021-03-31 20:52:26 +03:00
|
|
|
bool ret = false;
|
2020-10-19 01:09:48 +03:00
|
|
|
if (txBuf && rxBuf) {
|
2021-08-08 21:03:25 +03:00
|
|
|
ret = furi_hal_spi_bus_trx(platform_st25r3916->bus, (uint8_t*)txBuf, rxBuf, len, 1000);
|
2020-10-19 01:09:48 +03:00
|
|
|
} else if (txBuf) {
|
2021-08-08 21:03:25 +03:00
|
|
|
ret = furi_hal_spi_bus_tx(platform_st25r3916->bus, (uint8_t*)txBuf, len, 1000);
|
2020-10-19 01:09:48 +03:00
|
|
|
} else if (rxBuf) {
|
2021-08-08 21:03:25 +03:00
|
|
|
ret = furi_hal_spi_bus_rx(platform_st25r3916->bus, (uint8_t*)rxBuf, len, 1000);
|
2020-10-19 01:09:48 +03:00
|
|
|
}
|
2021-03-31 20:52:26 +03:00
|
|
|
|
|
|
|
if(!ret) {
|
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 15:42:25 +03:00
|
|
|
asm("bkpt 1");
|
2021-03-31 20:52:26 +03:00
|
|
|
return HAL_ERROR;
|
|
|
|
} else {
|
|
|
|
return HAL_OK;
|
2020-10-19 01:09:48 +03: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 15:42:25 +03:00
|
|
|
void platformProtectST25RComm() {
|
2021-08-13 16:12:10 +03:00
|
|
|
// Don't check platform_st25r3916 since spi device is used simultaneously from nfc worker
|
|
|
|
// thread and platformIrqWorker thread with the highest priority
|
|
|
|
|
|
|
|
// furi_assert(platform_st25r3916 == NULL);
|
2021-08-08 21:03:25 +03:00
|
|
|
platform_st25r3916 = (FuriHalSpiDevice*)furi_hal_spi_device_get(FuriHalSpiDeviceIdNfc);
|
2020-10-19 01:09:48 +03: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 15:42:25 +03:00
|
|
|
void platformUnprotectST25RComm() {
|
2021-08-13 16:12:10 +03:00
|
|
|
// furi_assert(platform_st25r3916);
|
2021-08-08 21:03:25 +03:00
|
|
|
furi_hal_spi_device_return(platform_st25r3916);
|
2021-08-13 16:12:10 +03:00
|
|
|
// platform_st25r3916 = NULL;
|
2020-10-19 01:09:48 +03:00
|
|
|
}
|