Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FL-3603] Support for external NFC field detection on the new NFC stack #3095

Merged
merged 4 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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