[FL-3122] Re-init NFC when starting the worker (#2399)

* Re-init NFC when starting the worker
* FuriHal: cleanup nfc init/deinit sequence
* FuriHal: a little bit more defensive nfc init

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
Astra 2023-02-20 16:44:03 +02:00 committed by GitHub
parent 738e0df4f4
commit b15c4afea1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 3 deletions

View File

@ -1,5 +1,5 @@
entry,status,name,type,params entry,status,name,type,params
Version,+,14.0,, Version,+,14.1,,
Header,+,applications/services/bt/bt_service/bt.h,, Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/cli/cli.h,, Header,+,applications/services/cli/cli.h,,
Header,+,applications/services/cli/cli_vcp.h,, Header,+,applications/services/cli/cli_vcp.h,,
@ -1171,6 +1171,7 @@ Function,+,furi_hal_mpu_protect_disable,void,FuriHalMpuRegion
Function,+,furi_hal_mpu_protect_no_access,void,"FuriHalMpuRegion, uint32_t, FuriHalMPURegionSize" Function,+,furi_hal_mpu_protect_no_access,void,"FuriHalMpuRegion, uint32_t, FuriHalMPURegionSize"
Function,+,furi_hal_mpu_protect_read_only,void,"FuriHalMpuRegion, uint32_t, FuriHalMPURegionSize" Function,+,furi_hal_mpu_protect_read_only,void,"FuriHalMpuRegion, uint32_t, FuriHalMPURegionSize"
Function,+,furi_hal_nfc_activate_nfca,_Bool,"uint32_t, uint32_t*" Function,+,furi_hal_nfc_activate_nfca,_Bool,"uint32_t, uint32_t*"
Function,-,furi_hal_nfc_deinit,void,
Function,+,furi_hal_nfc_detect,_Bool,"FuriHalNfcDevData*, uint32_t" Function,+,furi_hal_nfc_detect,_Bool,"FuriHalNfcDevData*, uint32_t"
Function,+,furi_hal_nfc_emulate_nfca,_Bool,"uint8_t*, uint8_t, uint8_t*, uint8_t, FuriHalNfcEmulateCallback, void*, uint32_t" Function,+,furi_hal_nfc_emulate_nfca,_Bool,"uint8_t*, uint8_t, uint8_t*, uint8_t, FuriHalNfcEmulateCallback, void*, uint32_t"
Function,+,furi_hal_nfc_exit_sleep,void, Function,+,furi_hal_nfc_exit_sleep,void,

1 entry status name type params
2 Version + 14.0 14.1
3 Header + applications/services/bt/bt_service/bt.h
4 Header + applications/services/cli/cli.h
5 Header + applications/services/cli/cli_vcp.h
1171 Function + furi_hal_mpu_protect_no_access void FuriHalMpuRegion, uint32_t, FuriHalMPURegionSize
1172 Function + furi_hal_mpu_protect_read_only void FuriHalMpuRegion, uint32_t, FuriHalMPURegionSize
1173 Function + furi_hal_nfc_activate_nfca _Bool uint32_t, uint32_t*
1174 Function - furi_hal_nfc_deinit void
1175 Function + furi_hal_nfc_detect _Bool FuriHalNfcDevData*, uint32_t
1176 Function + furi_hal_nfc_emulate_nfca _Bool uint8_t*, uint8_t, uint8_t*, uint8_t, FuriHalNfcEmulateCallback, void*, uint32_t
1177 Function + furi_hal_nfc_exit_sleep void

View File

@ -24,13 +24,29 @@ FuriEventFlag* event = NULL;
#define FURI_HAL_NFC_UID_INCOMPLETE (0x04) #define FURI_HAL_NFC_UID_INCOMPLETE (0x04)
void furi_hal_nfc_init() { void furi_hal_nfc_init() {
furi_assert(!event);
event = furi_event_flag_alloc();
ReturnCode ret = rfalNfcInitialize(); ReturnCode ret = rfalNfcInitialize();
if(ret == ERR_NONE) { if(ret == ERR_NONE) {
furi_hal_nfc_start_sleep(); furi_hal_nfc_start_sleep();
event = furi_event_flag_alloc();
FURI_LOG_I(TAG, "Init OK"); FURI_LOG_I(TAG, "Init OK");
} else { } else {
FURI_LOG_W(TAG, "Initialization failed, RFAL returned: %d", ret); FURI_LOG_W(TAG, "Init Failed, RFAL returned: %d", ret);
}
}
void furi_hal_nfc_deinit() {
ReturnCode ret = rfalDeinitialize();
if(ret == ERR_NONE) {
FURI_LOG_I(TAG, "Deinit OK");
} else {
FURI_LOG_W(TAG, "Deinit Failed, RFAL returned: %d", ret);
}
if(event) {
furi_event_flag_free(event);
event = NULL;
} }
} }

View File

@ -101,6 +101,10 @@ typedef struct {
*/ */
void furi_hal_nfc_init(); void furi_hal_nfc_init();
/** Deinit nfc
*/
void furi_hal_nfc_deinit();
/** Check if nfc worker is busy /** Check if nfc worker is busy
* *
* @return true if busy * @return true if busy

View File

@ -56,6 +56,8 @@ void nfc_worker_start(
while(furi_hal_nfc_is_busy()) { while(furi_hal_nfc_is_busy()) {
furi_delay_ms(10); furi_delay_ms(10);
} }
furi_hal_nfc_deinit();
furi_hal_nfc_init();
nfc_worker->callback = callback; nfc_worker->callback = callback;
nfc_worker->context = context; nfc_worker->context = context;