Skip to content

Commit

Permalink
New NFC API
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippeBonnaz committed Dec 20, 2023
1 parent 4dd29b6 commit 4a497ad
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 59 deletions.
12 changes: 1 addition & 11 deletions include/os_io_seproxyhal.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@
#include "os_print.h"
#include "os_types.h"

#ifdef HAVE_NFC
#ifdef HAVE_NDEF_SUPPORT
#include "nfc_ndef.h"
#endif
#endif

#ifdef HAVE_SERIALIZED_NBGL
#include "nbgl_serialize.h"
#endif
Expand Down Expand Up @@ -141,11 +135,7 @@ void io_seproxyhal_send_nbgl_serialized(nbgl_serialized_event_type_e event, nbgl
void io_set_timeout(unsigned int timeout);

#ifdef HAVE_NFC
#ifdef HAVE_NDEF_SUPPORT
void io_seproxyhal_nfc_init(ndef_struct_t *ndef_message, bool async, bool forceInit);
#else // ! HAVE_NDEF_SUPPORT
void io_seproxyhal_nfc_init(bool forceInit);
#endif // HAVE_NDEF_SUPPORT
void io_seproxyhal_nfc_power(bool forceInit);
#endif

#ifdef HAVE_SE_TOUCH
Expand Down
2 changes: 1 addition & 1 deletion include/seproxyhal_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@

#ifdef HAVE_NFC
#define SEPROXYHAL_TAG_NFC_RAPDU 0x4A
#define SEPROXYHAL_TAG_NFC_INIT 0x34
#define SEPROXYHAL_TAG_NFC_POWER 0x34
#endif

#define SEPROXYHAL_TAG_DEVICE_OFF 0x4B
Expand Down
51 changes: 4 additions & 47 deletions src/os_io_seproxyhal.c
Original file line number Diff line number Diff line change
Expand Up @@ -495,62 +495,19 @@ void io_seproxyhal_play_tune(tune_index_e tune_index)
#endif // HAVE_PIEZO_SOUND

#ifdef HAVE_NFC
#ifdef HAVE_NDEF_SUPPORT
#include "nfc_ndef.h"
#endif

#ifdef HAVE_NDEF_SUPPORT
/**
* @brief Send a SEPH message to MCU to init NFC
*
* @param ndef_message NDEF message to program into tag, can be NULL (ie no message in tag)
* @param async set to true, if nfc_init is performed while an NFC transfer is ongoing, set to false
* otherwise
* @param forceInit set to true, to force NFC init even if NFC is de-activated in settings, false
* otherwise
*/
void io_seproxyhal_nfc_init(ndef_struct_t *ndef_message, bool async, bool forceInit)
{
uint8_t buffer[5];
uint16_t total_length = 0;
uint8_t is_nfc_enabled
= forceInit
? 1
: (os_setting_get(OS_SETTING_FEATURES, NULL, 0) & OS_SETTING_FEATURES_NFC_ENABLED);
buffer[0] = SEPROXYHAL_TAG_NFC_INIT;
// Fill length offsets 1 and 2 later when text length is known
buffer[3] = is_nfc_enabled;
buffer[4] = (uint8_t) async;
total_length += 2;
if (ndef_message != NULL) {
total_length += sizeof(ndef_struct_t);
memcpy(G_io_seproxyhal_spi_buffer, ndef_message, sizeof(ndef_struct_t));
}
else {
total_length += os_setting_get(OS_SETTING_NFC_TAG_CONTENT,
(uint8_t *) G_io_seproxyhal_spi_buffer,
sizeof(ndef_struct_t));
}
buffer[1] = (total_length & 0xFF00) >> 8;
buffer[2] = total_length & 0x00FF;
io_seproxyhal_spi_send(buffer, 5);
io_seproxyhal_spi_send(G_io_seproxyhal_spi_buffer, total_length - 2);
}
#else // ! HAVE_NDEF_SUPPORT
void io_seproxyhal_nfc_init(bool forceInit)
void io_seproxyhal_nfc_power(bool forceInit)
{
uint8_t buffer[4];
uint8_t is_nfc_enabled
uint8_t power
= forceInit
? 1
: (os_setting_get(OS_SETTING_FEATURES, NULL, 0) & OS_SETTING_FEATURES_NFC_ENABLED);
buffer[0] = SEPROXYHAL_TAG_NFC_INIT;
buffer[0] = SEPROXYHAL_TAG_NFC_POWER;
buffer[1] = 0;
buffer[2] = 1;
buffer[3] = is_nfc_enabled;
buffer[3] = power;
io_seproxyhal_spi_send(buffer, 4);
}
#endif // HAVE_NDEF_SUPPORT
#endif // HAVE_NFC

#ifdef HAVE_SE_TOUCH
Expand Down

0 comments on commit 4a497ad

Please sign in to comment.