Skip to content

Commit

Permalink
[FL-3603] Support for external NFC field detection on the new NFC sta…
Browse files Browse the repository at this point in the history
…ck (#3095)

* Add support for detecting the external NFC field

* Update F18 API version

* firmware: fix api version

---------

Co-authored-by: gornekich <[email protected]>
  • Loading branch information
Astrrra and gornekich authored Sep 19, 2023
1 parent 9e374a4 commit a8fa187
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
5 changes: 4 additions & 1 deletion firmware/targets/f7/api_symbols.csv
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,9 @@ Function,+,furi_hal_mpu_protect_read_only,void,"FuriHalMpuRegion, uint32_t, Furi
Function,+,furi_hal_nfc_abort,FuriHalNfcError,
Function,+,furi_hal_nfc_acquire,FuriHalNfcError,
Function,+,furi_hal_nfc_event_start,FuriHalNfcError,
Function,+,furi_hal_nfc_field_detect_start,FuriHalNfcError,
Function,+,furi_hal_nfc_field_detect_stop,FuriHalNfcError,
Function,+,furi_hal_nfc_field_is_present,_Bool,
Function,+,furi_hal_nfc_init,FuriHalNfcError,
Function,+,furi_hal_nfc_is_hal_ready,FuriHalNfcError,
Function,+,furi_hal_nfc_iso14443a_listener_set_col_res_data,FuriHalNfcError,"uint8_t*, uint8_t, uint8_t*, uint8_t"
Expand Down Expand Up @@ -2226,7 +2229,6 @@ Function,+,nfc_data_generator_fill_data,void,"NfcDataGeneratorType, NfcDevice*"
Function,+,nfc_data_generator_get_name,const char*,NfcDataGeneratorType
Function,+,nfc_device_alloc,NfcDevice*,
Function,+,nfc_device_clear,void,NfcDevice*
Function,+,nfc_device_is_equal_data,_Bool,"const NfcDevice*, NfcProtocol, const NfcDeviceData*"
Function,+,nfc_device_copy_data,void,"const NfcDevice*, NfcProtocol, NfcDeviceData*"
Function,+,nfc_device_free,void,NfcDevice*
Function,+,nfc_device_get_data,const NfcDeviceData*,"const NfcDevice*, NfcProtocol"
Expand All @@ -2235,6 +2237,7 @@ Function,+,nfc_device_get_protocol,NfcProtocol,const NfcDevice*
Function,+,nfc_device_get_protocol_name,const char*,NfcProtocol
Function,+,nfc_device_get_uid,const uint8_t*,"const NfcDevice*, size_t*"
Function,+,nfc_device_is_equal,_Bool,"const NfcDevice*, const NfcDevice*"
Function,+,nfc_device_is_equal_data,_Bool,"const NfcDevice*, NfcProtocol, const NfcDeviceData*"
Function,+,nfc_device_load,_Bool,"NfcDevice*, const char*"
Function,+,nfc_device_reset,void,NfcDevice*
Function,+,nfc_device_save,_Bool,"NfcDevice*, const char*"
Expand Down
41 changes: 41 additions & 0 deletions firmware/targets/f7/furi_hal/furi_hal_nfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,47 @@ FuriHalNfcError furi_hal_nfc_reset_mode() {
return error;
}

FuriHalNfcError furi_hal_nfc_field_detect_start() {
FuriHalNfcError error = FuriHalNfcErrorNone;
FuriHalSpiBusHandle* handle = &furi_hal_spi_bus_handle_nfc;

st25r3916_write_reg(
handle,
ST25R3916_REG_OP_CONTROL,
ST25R3916_REG_OP_CONTROL_en | ST25R3916_REG_OP_CONTROL_en_fd_mask);
st25r3916_write_reg(
handle, ST25R3916_REG_MODE, ST25R3916_REG_MODE_targ | ST25R3916_REG_MODE_om0);

return error;
}

FuriHalNfcError furi_hal_nfc_field_detect_stop() {
FuriHalNfcError error = FuriHalNfcErrorNone;
FuriHalSpiBusHandle* handle = &furi_hal_spi_bus_handle_nfc;

st25r3916_clear_reg_bits(
handle,
ST25R3916_REG_OP_CONTROL,
(ST25R3916_REG_OP_CONTROL_en | ST25R3916_REG_OP_CONTROL_en_fd_mask));

return error;
}

bool furi_hal_nfc_field_is_present() {
bool is_present = false;
FuriHalSpiBusHandle* handle = &furi_hal_spi_bus_handle_nfc;

if(st25r3916_check_reg(
handle,
ST25R3916_REG_AUX_DISPLAY,
ST25R3916_REG_AUX_DISPLAY_efd_o,
ST25R3916_REG_AUX_DISPLAY_efd_o)) {
is_present = true;
}

return is_present;
}

FuriHalNfcError furi_hal_nfc_poller_field_on() {
FuriHalNfcError error = FuriHalNfcErrorNone;
FuriHalSpiBusHandle* handle = &furi_hal_spi_bus_handle_nfc;
Expand Down
18 changes: 18 additions & 0 deletions firmware/targets/furi_hal_include/furi_hal_nfc.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,24 @@ FuriHalNfcError furi_hal_nfc_set_mode(FuriHalNfcMode mode, FuriHalNfcTech tech);
*/
FuriHalNfcError furi_hal_nfc_reset_mode();

/** Start field detection
*
* @return FuriHalNfcError
*/
FuriHalNfcError furi_hal_nfc_field_detect_start();

/** Stop field detection
*
* @return FuriHalNfcError
*/
FuriHalNfcError furi_hal_nfc_field_detect_stop();

/** Check if external NFC field is present
*
* @return FuriHalNfcError
*/
bool furi_hal_nfc_field_is_present();

/** Turn on field
*
* @return FuriHalNfcError
Expand Down

0 comments on commit a8fa187

Please sign in to comment.