mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-03-21 02:26:10 +00:00
chore(core): Redo NFC driver to event based structure
This commit is contained in:
parent
f9f3d1a3cb
commit
d962d63e2d
@ -46,6 +46,7 @@ typedef enum {
|
||||
|
||||
typedef enum {
|
||||
NFC_NO_EVENT,
|
||||
NFC_EVENT_DEACTIVATED,
|
||||
NFC_EVENT_ACTIVATED,
|
||||
} nfc_event_t;
|
||||
|
||||
|
@ -51,16 +51,20 @@
|
||||
// NFC-F PAD0
|
||||
#define LM_PAD0 0x00U
|
||||
|
||||
typedef enum{
|
||||
NFC_STATE_ACTIVE,
|
||||
NFC_STATE_NOT_ACTIVE
|
||||
} nfc_state_t;
|
||||
|
||||
typedef struct {
|
||||
bool initialized;
|
||||
// SPI driver
|
||||
SPI_HandleTypeDef hspi;
|
||||
// NFC IRQ pin callback
|
||||
void (*nfc_irq_callback)(void);
|
||||
|
||||
EXTI_HandleTypeDef hEXTI;
|
||||
|
||||
rfalNfcDiscoverParam disc_params;
|
||||
nfc_state_t last_nfc_state;
|
||||
} st25r3916b_driver_t;
|
||||
|
||||
static st25r3916b_driver_t g_st25r3916b_driver = {
|
||||
@ -211,6 +215,7 @@ nfc_status_t nfc_init() {
|
||||
}
|
||||
|
||||
drv->initialized = true;
|
||||
drv->last_nfc_state = NFC_STATE_NOT_ACTIVE;
|
||||
|
||||
return NFC_OK;
|
||||
}
|
||||
@ -375,14 +380,40 @@ nfc_status_t nfc_get_event(nfc_event_t *event) {
|
||||
return NFC_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
static rfalNfcDevice *nfcDevice;
|
||||
rfalNfcDevice *nfcDevice;
|
||||
|
||||
// Run RFAL worker periodically
|
||||
rfalNfcWorker();
|
||||
|
||||
if(rfalNfcIsDevActivated(rfalNfcGetState())) {
|
||||
rfalNfcState rfal_state = rfalNfcGetState();
|
||||
|
||||
*event = NFC_EVENT_ACTIVATED;
|
||||
nfc_state_t cur_nfc_state = NFC_STATE_NOT_ACTIVE;
|
||||
|
||||
if(rfalNfcIsDevActivated(rfal_state)) {
|
||||
cur_nfc_state = NFC_STATE_ACTIVE;
|
||||
}
|
||||
|
||||
if(cur_nfc_state != drv->last_nfc_state){
|
||||
|
||||
switch(cur_nfc_state){
|
||||
|
||||
case NFC_STATE_ACTIVE:
|
||||
*event = NFC_EVENT_ACTIVATED;
|
||||
break;
|
||||
|
||||
case NFC_STATE_NOT_ACTIVE:
|
||||
*event = NFC_EVENT_DEACTIVATED;
|
||||
break;
|
||||
|
||||
default:
|
||||
*event = NFC_NO_EVENT;
|
||||
}
|
||||
|
||||
drv->last_nfc_state = cur_nfc_state;
|
||||
|
||||
}
|
||||
|
||||
if(cur_nfc_state == NFC_STATE_ACTIVE) {
|
||||
|
||||
rfalNfcGetActiveDevice(&nfcDevice);
|
||||
|
||||
@ -434,6 +465,7 @@ nfc_status_t nfc_get_event(nfc_event_t *event) {
|
||||
rfalNfcDeactivate(RFAL_NFC_DEACTIVATE_DISCOVERY); // Automatically deactivate
|
||||
}
|
||||
|
||||
// No event in CE mode, activation/deactivation handled automatically
|
||||
*event = NFC_NO_EVENT;
|
||||
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user