Skip to content

NFC

Near-field communication (NFC) is a set of communication protocols that enable two electronic devices, one of which is usually a portable device such as a smartphone, to establish communication by bringing them within close proximity of each other.

MiraOS support NFC-tag emulation.

Note: When using NFC on the nrf52840 platform TIMER4 is unavailable.

Defines

MIRA_NFC_NDEF_FILE_ID

#define MIRA_NFC_NDEF_FILE_ID

File id of the NDEF file.

This file must contain an NDEF message.

Types

mira_nfc_file_id_t

typedef uint16_t mira_nfc_file_id_t;

Type of file identifier.

Used to identify files. The word length might change depending on backend implementation requirements. Only comparisons with other values of same type, or constants in this file.

Structs

mira_nfc_config_t

Configuration of NFC tag interface.

All callbacks are synchronized to the threading, and will not interrupt a running thread, except during normal process switching.

Name Type Description
callback_field_on void(*)(void *storage) Called when entering an NFC field.
callback_field_off void(*)(void *storage) Called when leaving an NFC field.
callback_file_open uint8_t *(*)(mira_nfc_file_id_t file_id, mira_size_t *size, void *storage) Called when a file is selected/opened.
callback_file_save mira_bool_t(*)(mira_nfc_file_id_t file_id, mira_size_t size, void *storage) Called when a write is successful.
storage void * Local storage for user data.
max_file_size uint16_t Maximum file size.

The buffer returned by callback_file_open must be of at least this size to enable writing.

proprietary_file_count uint16_t Number of proprietary files.

Number of proprietary files beside the ndef file. Each proprietary file will enumerated starting from MIRA_NFC_PRORIETARY_FILE_ID_BASE.

Functions

mira_nfc_init

mira_status_t mira_nfc_init(const mira_nfc_config_t *config);

Initialize the NRF module.

The custom config is passed as a parameter (NULL for platform default).

Parameters

Name Description
config Configuration of the nfc reader. This must be valid until mira_nfc_uninit() is called, and must not change during that time.

Return value

Name Description
MIRA_SUCCESS NFC successfully initialized.
MIRA_ERROR_UNKNOWN An unknown error occurred.

mira_nfc_uninit

mira_status_t mira_nfc_uninit(void);

Close the nfc interface.

Free all references to the NFC interface, and close the hardware, until next call of mira_nfc_init.

Return value

Name Description
MIRA_SUCCESS NFC successfully uninitialized.
MIRA_ERROR_UNKNOWN An unknown error occurred.