43 #if NRFX_CHECK(NRFX_NFCT_ENABLED)
45 #include <nrfx_nfct.h>
47 #define NRFX_LOG_MODULE NFCT
50 #if defined(NRF52832_XXAA) || defined(NRF52832_XXAB) || \
51 defined(NRF52833_XXAA) || defined(NRF52840_XXAA)
52 #define USE_TIMER_WORKAROUND
55 #if defined(USE_TIMER_WORKAROUND)
56 #include <nrfx_timer.h>
60 const nrfx_timer_t timer;
61 #if defined(NRF52833_XXAA) || defined(NRF52840_XXAA)
62 bool fieldevents_filter_active;
66 uint32_t field_state_cnt;
68 } nrfx_nfct_timer_workaround_t;
70 #if defined(NRF52833_XXAA) || defined(NRF52840_XXAA)
71 #define NRFX_NFCT_ACTIVATE_DELAY 1000
72 #define NRFX_NFCT_TIMER_PERIOD NRFX_NFCT_ACTIVATE_DELAY
74 #define NRFX_NFCT_FIELDLOST_THR 7
75 #define NRFX_NFCT_FIELD_TIMER_PERIOD 100
76 #define NRFX_NFCT_TIMER_PERIOD NRFX_NFCT_FIELD_TIMER_PERIOD
78 #define NRFX_NFCT_TIMER_INSTANCE 4
80 static nrfx_nfct_timer_workaround_t m_timer_workaround =
82 .timer = NRFX_TIMER_INSTANCE(NRFX_NFCT_TIMER_INSTANCE),
86 #define NRFX_NFCT_FWT_MAX_DIFF 1u
87 #define NFCT_FRAMEDELAYMAX_DEFAULT (0x00001000UL)
90 #define NRFX_NFCT_RX_INT_MASK (NRF_NFCT_INT_RXFRAMESTART_MASK | \
91 NRF_NFCT_INT_RXFRAMEEND_MASK | \
92 NRF_NFCT_INT_RXERROR_MASK)
95 #define NRFX_NFCT_TX_INT_MASK (NRF_NFCT_INT_TXFRAMESTART_MASK | \
96 NRF_NFCT_INT_TXFRAMEEND_MASK)
100 #define NRFX_NFCT_FRAME_STATUS_RX_ALL_MASK (NRF_NFCT_RX_FRAME_STATUS_CRC_MASK | \
101 NRF_NFCT_RX_FRAME_STATUS_PARITY_MASK | \
102 NRF_NFCT_RX_FRAME_STATUS_OVERRUN_MASK)
105 #if defined (NRF52832_XXAA) || defined(NRF52832_XXAB)
106 #define NRFX_NFCT_ERROR_STATUS_ALL_MASK (NRF_NFCT_ERROR_FRAMEDELAYTIMEOUT_MASK | \
107 NRF_NFCT_ERROR_NFCFIELDTOOSTRONG_MASK | \
108 NRF_NFCT_ERROR_NFCFIELDTOOWEAK_MASK)
110 #define NRFX_NFCT_ERROR_STATUS_ALL_MASK (NRF_NFCT_ERROR_FRAMEDELAYTIMEOUT_MASK)
114 #define NRFX_NFCT_BYTES_TO_BITS(_bytes) ((_bytes) << 3)
115 #define NRFX_NFCT_BITS_TO_BYTES(_bits) ((_bits) >> 3)
118 #define NRFX_NFCT_EVT_ACTIVE(_name) (nrf_nfct_event_check(NRFX_CONCAT_2(NRF_NFCT_EVENT_, _name)) && \
119 nrf_nfct_int_enable_check(NRFX_CONCAT_3(NRF_NFCT_INT_, _name, _MASK)))
122 #define NRFX_NFCT_CB_HANDLE(_cb, _evt) \
130 NRFX_NFC_FIELD_STATE_NONE,
131 NRFX_NFC_FIELD_STATE_OFF,
132 NRFX_NFC_FIELD_STATE_ON,
133 NRFX_NFC_FIELD_STATE_UNKNOWN
134 } nrfx_nfct_field_state_t;
139 nrfx_nfct_config_t config;
140 nrfx_drv_state_t state;
141 volatile bool field_on;
142 uint32_t frame_delay_max;
143 } nrfx_nfct_control_block_t;
145 static nrfx_nfct_control_block_t m_nfct_cb;
150 static void nrfx_nfct_hw_init_setup(
void)
153 nrf_nfct_frame_delay_mode_set(NRF_NFCT_FRAME_DELAY_MODE_WINDOWGRID);
158 nrf_nfct_sensres_bit_frame_sdd_set(NRF_NFCT_SENSRES_BIT_FRAME_SDD_00100);
162 static void nrfx_nfct_frame_delay_max_set(
bool default_delay)
166 nrf_nfct_frame_delay_max_set(NFCT_FRAMEDELAYMAX_DEFAULT);
170 nrf_nfct_frame_delay_max_set(m_nfct_cb.frame_delay_max);
178 static void nrfx_nfct_field_event_handler(
volatile nrfx_nfct_field_state_t field_state)
180 nrfx_nfct_evt_t nfct_evt;
182 #if defined(NRF52833_XXAA) || defined(NRF52840_XXAA)
183 if(m_timer_workaround.fieldevents_filter_active)
189 if (field_state == NRFX_NFC_FIELD_STATE_UNKNOWN)
192 field_state = (nrfx_nfct_field_check()) ? NRFX_NFC_FIELD_STATE_ON : NRFX_NFC_FIELD_STATE_OFF;
200 case NRFX_NFC_FIELD_STATE_ON:
201 if (!m_nfct_cb.field_on)
203 #if defined(NRF52833_XXAA) || defined(NRF52840_XXAA)
205 m_timer_workaround.is_hfclk_on =
false;
206 m_timer_workaround.is_delayed =
false;
207 m_timer_workaround.fieldevents_filter_active =
true;
209 nrfx_timer_clear(&m_timer_workaround.timer);
210 nrfx_timer_enable(&m_timer_workaround.timer);
212 #elif defined(NRF52832_XXAA) || defined(NRF52832_XXAB)
213 nrfx_timer_clear(&m_timer_workaround.timer);
214 nrfx_timer_enable(&m_timer_workaround.timer);
215 m_timer_workaround.field_state_cnt = 0;
218 m_nfct_cb.field_on =
true;
219 nfct_evt.evt_id = NRFX_NFCT_EVT_FIELD_DETECTED;
220 NRFX_NFCT_CB_HANDLE(m_nfct_cb.config.cb, nfct_evt);
224 case NRFX_NFC_FIELD_STATE_OFF:
225 if (m_nfct_cb.field_on)
227 nrf_nfct_task_trigger(NRF_NFCT_TASK_SENSE);
228 nrf_nfct_int_disable(NRFX_NFCT_RX_INT_MASK | NRFX_NFCT_TX_INT_MASK);
229 m_nfct_cb.field_on =
false;
230 nfct_evt.evt_id = NRFX_NFCT_EVT_FIELD_LOST;
233 nrfx_nfct_frame_delay_max_set(
true);
236 NRFX_NFCT_CB_HANDLE(m_nfct_cb.config.cb, nfct_evt);
246 #if defined(USE_TIMER_WORKAROUND)
248 #if defined(NRF52833_XXAA) || defined(NRF52840_XXAA)
249 static void nrfx_nfct_activate_check(
void)
251 static bool is_field_validation_pending =
false;
253 if (is_field_validation_pending)
255 is_field_validation_pending =
false;
256 m_timer_workaround.fieldevents_filter_active =
false;
259 nrfx_nfct_field_event_handler(NRFX_NFC_FIELD_STATE_UNKNOWN);
263 if ((m_timer_workaround.is_hfclk_on) && (m_timer_workaround.is_delayed))
265 nrf_nfct_task_trigger(NRF_NFCT_TASK_ACTIVATE);
266 is_field_validation_pending =
true;
269 nrfx_timer_clear(&m_timer_workaround.timer);
270 nrfx_timer_enable(&m_timer_workaround.timer);
275 #if defined(NRF52832_XXAA) || defined(NRF52832_XXAB)
277 static inline void nrfx_nfct_reset(
void)
280 uint32_t int_enabled;
281 uint8_t nfcid1[NRF_NFCT_SENSRES_NFCID1_SIZE_TRIPLE];
282 nrf_nfct_sensres_nfcid1_size_t nfcid1_size;
283 nrf_nfct_selres_protocol_t protocol;
286 fdm = nrf_nfct_frame_delay_max_get();
287 nfcid1_size = nrf_nfct_nfcid1_get(nfcid1);
288 protocol = nrf_nfct_selsres_protocol_get();
289 int_enabled = nrf_nfct_int_enable_get();
292 *(
volatile uint32_t *)0x40005FFC = 0;
293 *(
volatile uint32_t *)0x40005FFC;
294 *(
volatile uint32_t *)0x40005FFC = 1;
297 nrf_nfct_frame_delay_max_set(fdm);
298 nrf_nfct_nfcid1_set(nfcid1, nfcid1_size);
299 nrf_nfct_selres_protocol_set(protocol);
302 nrfx_nfct_hw_init_setup();
305 nrf_nfct_int_enable(int_enabled);
308 nrf_nfct_int_disable(NRFX_NFCT_RX_INT_MASK | NRFX_NFCT_TX_INT_MASK);
310 NRFX_LOG_INFO(
"Reinitialize");
314 static void nrfx_nfct_field_poll(
void)
316 if (!nrfx_nfct_field_check())
318 if (++m_timer_workaround.field_state_cnt > NRFX_NFCT_FIELDLOST_THR)
320 nrfx_nfct_evt_t nfct_evt =
322 .evt_id = NRFX_NFCT_EVT_FIELD_LOST,
325 nrfx_timer_disable(&m_timer_workaround.timer);
326 m_nfct_cb.field_on =
false;
329 nrfx_nfct_frame_delay_max_set(
true);
337 NRFX_NFCT_CB_HANDLE(m_nfct_cb.config.cb, nfct_evt);
342 m_timer_workaround.field_state_cnt = 0;
346 static void nrfx_nfct_field_timer_handler(nrf_timer_event_t event_type,
void * p_context)
350 if (event_type != NRF_TIMER_EVENT_COMPARE0)
355 #if defined(NRF52833_XXAA) || defined(NRF52840_XXAA)
356 m_timer_workaround.is_delayed =
true;
358 nrfx_timer_disable(&m_timer_workaround.timer);
359 nrfx_nfct_activate_check();
361 nrfx_nfct_field_poll();
365 static inline nrfx_err_t nrfx_nfct_field_timer_config(
void)
368 nrfx_timer_config_t timer_cfg =
370 .frequency = NRF_TIMER_FREQ_1MHz,
371 .mode = NRF_TIMER_MODE_TIMER,
372 .bit_width = NRF_TIMER_BIT_WIDTH_16,
376 err_code = nrfx_timer_init(&m_timer_workaround.timer, &timer_cfg, nrfx_nfct_field_timer_handler);
377 if (err_code != NRFX_SUCCESS)
382 nrfx_timer_extended_compare(&m_timer_workaround.timer,
383 NRF_TIMER_CC_CHANNEL0,
384 nrfx_timer_us_to_ticks(&m_timer_workaround.timer, NRFX_NFCT_TIMER_PERIOD),
385 NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK,
391 static inline nrf_nfct_sensres_nfcid1_size_t nrf_nfct_nfcid1_size_to_sensres_size(uint8_t nfcid1_size)
395 case NRFX_NFCT_NFCID1_SINGLE_SIZE:
396 return NRF_NFCT_SENSRES_NFCID1_SIZE_SINGLE;
398 case NRFX_NFCT_NFCID1_DOUBLE_SIZE:
399 return NRF_NFCT_SENSRES_NFCID1_SIZE_DOUBLE;
401 case NRFX_NFCT_NFCID1_TRIPLE_SIZE:
402 return NRF_NFCT_SENSRES_NFCID1_SIZE_TRIPLE;
405 return NRF_NFCT_SENSRES_NFCID1_SIZE_DOUBLE;
409 static inline void nrfx_nfct_rxtx_int_enable(uint32_t rxtx_int_mask)
411 nrf_nfct_int_enable(rxtx_int_mask & m_nfct_cb.config.rxtx_int_mask);
414 nrfx_err_t nrfx_nfct_init(nrfx_nfct_config_t
const * p_config)
416 NRFX_ASSERT(p_config);
418 nrfx_err_t err_code = NRFX_SUCCESS;
420 if (m_nfct_cb.state != NRFX_DRV_STATE_UNINITIALIZED)
422 return NRFX_ERROR_INVALID_STATE;
425 m_nfct_cb.config = *p_config;
426 nrfx_nfct_hw_init_setup();
428 NRFX_IRQ_PENDING_CLEAR(NFCT_IRQn);
430 NRFX_IRQ_ENABLE(NFCT_IRQn);
432 #if defined(USE_TIMER_WORKAROUND)
434 err_code = nrfx_nfct_field_timer_config();
437 if (err_code == NRFX_SUCCESS)
439 uint8_t default_nfcid1[NRFX_NFCT_NFCID1_DEFAULT_LEN];
440 err_code = nrfx_nfct_nfcid1_default_bytes_get(default_nfcid1,
sizeof(default_nfcid1));
441 NRFX_ASSERT(err_code == NRFX_SUCCESS);
442 nrf_nfct_nfcid1_set(default_nfcid1, NRF_NFCT_SENSRES_NFCID1_SIZE_DEFAULT);
449 m_nfct_cb.state = NRFX_DRV_STATE_INITIALIZED;
450 m_nfct_cb.frame_delay_max = NFCT_FRAMEDELAYMAX_DEFAULT;
452 NRFX_LOG_INFO(
"Initialized");
456 void nrfx_nfct_uninit(
void)
460 NRFX_IRQ_DISABLE(NFCT_IRQn);
461 NRFX_IRQ_PENDING_CLEAR(NFCT_IRQn);
463 #if defined(USE_TIMER_WORKAROUND)
465 nrfx_timer_uninit(&m_timer_workaround.timer);
468 m_nfct_cb.state = NRFX_DRV_STATE_UNINITIALIZED;
471 void nrfx_nfct_enable(
void)
473 nrf_nfct_error_status_clear(NRFX_NFCT_ERROR_STATUS_ALL_MASK);
474 nrf_nfct_task_trigger(NRF_NFCT_TASK_SENSE);
476 nrf_nfct_int_enable(NRF_NFCT_INT_FIELDDETECTED_MASK | NRF_NFCT_INT_ERROR_MASK |
477 NRF_NFCT_INT_SELECTED_MASK);
478 #if !defined(NRF52832_XXAA) && !defined(NRF52832_XXAB)
479 nrf_nfct_int_enable(NRF_NFCT_INT_FIELDLOST_MASK);
482 NRFX_LOG_INFO(
"Start");
485 void nrfx_nfct_disable(
void)
487 nrf_nfct_int_disable(NRF_NFCT_DISABLE_ALL_INT);
488 nrf_nfct_task_trigger(NRF_NFCT_TASK_DISABLE);
490 NRFX_LOG_INFO(
"Stop");
493 bool nrfx_nfct_field_check(
void)
495 uint32_t
const field_state = nrf_nfct_field_status_get();
497 if (((field_state & NRF_NFCT_FIELD_STATE_PRESENT_MASK) == 0) &&
498 ((field_state & NRF_NFCT_FIELD_STATE_LOCK_MASK) == 0))
507 void nrfx_nfct_rx(nrfx_nfct_data_desc_t
const * p_tx_data)
509 NRFX_ASSERT(p_tx_data);
511 nrf_nfct_rxtx_buffer_set((uint8_t *) p_tx_data->p_data, p_tx_data->data_size);
513 nrfx_nfct_rxtx_int_enable(NRFX_NFCT_RX_INT_MASK);
514 nrf_nfct_task_trigger(NRF_NFCT_TASK_ENABLERXDATA);
517 nrfx_err_t nrfx_nfct_tx(nrfx_nfct_data_desc_t
const * p_tx_data,
518 nrf_nfct_frame_delay_mode_t delay_mode)
520 NRFX_ASSERT(p_tx_data);
521 NRFX_ASSERT(p_tx_data->p_data);
523 if (p_tx_data->data_size == 0)
525 return NRFX_ERROR_INVALID_LENGTH;
528 nrf_nfct_rxtx_buffer_set((uint8_t *) p_tx_data->p_data, p_tx_data->data_size);
529 nrf_nfct_tx_bits_set(NRFX_NFCT_BYTES_TO_BITS(p_tx_data->data_size));
530 nrf_nfct_frame_delay_mode_set((nrf_nfct_frame_delay_mode_t) delay_mode);
532 nrfx_nfct_rxtx_int_enable(NRFX_NFCT_TX_INT_MASK);
533 nrf_nfct_task_trigger(NRF_NFCT_TASK_STARTTX);
535 NRFX_LOG_INFO(
"Tx start");
539 void nrfx_nfct_state_force(nrfx_nfct_state_t state)
541 #if defined(NRF52833_XXAA) || defined(NRF52840_XXAA)
542 if (state == NRFX_NFCT_STATE_ACTIVATED)
544 m_timer_workaround.is_hfclk_on =
true;
546 nrfx_nfct_activate_check();
550 nrf_nfct_task_trigger((nrf_nfct_task_t) state);
553 void nrfx_nfct_init_substate_force(nrfx_nfct_active_state_t sub_state)
555 if (sub_state == NRFX_NFCT_ACTIVE_STATE_DEFAULT)
557 #if defined(NRF52832_XXAA) || defined(NRF52832_XXAB)
558 if (((*(uint32_t
volatile *)(0x40005420)) & 0x1UL) == (1UL))
560 if (nrf_nfct_sleep_state_get() == NRF_NFCT_SLEEP_STATE_SLEEP_A)
564 nrf_nfct_task_trigger(NRF_NFCT_TASK_GOSLEEP);
569 nrf_nfct_task_trigger(NRF_NFCT_TASK_GOIDLE);
574 nrf_nfct_task_trigger((nrf_nfct_task_t) sub_state);
578 nrfx_nfct_frame_delay_max_set(
true);
582 nrf_nfct_int_disable(NRFX_NFCT_RX_INT_MASK | NRFX_NFCT_TX_INT_MASK);
585 nrfx_err_t nrfx_nfct_parameter_set(nrfx_nfct_param_t
const * p_param)
587 NRFX_ASSERT(p_param);
591 case NRFX_NFCT_PARAM_ID_FDT:
593 uint32_t delay = p_param->data.fdt;
594 uint32_t delay_thr = NFCT_FRAMEDELAYMAX_FRAMEDELAYMAX_Msk;
597 if (delay > (delay_thr + NRFX_NFCT_FWT_MAX_DIFF))
599 return NRFX_ERROR_INVALID_PARAM;
602 delay = (delay > delay_thr) ? delay_thr : delay;
603 m_nfct_cb.frame_delay_max = delay;
607 case NRFX_NFCT_PARAM_ID_SEL_RES:
608 if (p_param->data.sel_res_protocol > NRF_NFCT_SELRES_PROTOCOL_NFCDEP_T4AT)
610 return NRFX_ERROR_INVALID_PARAM;
613 nrf_nfct_selres_protocol_set((nrf_nfct_selres_protocol_t) p_param->data.sel_res_protocol);
616 case NRFX_NFCT_PARAM_ID_NFCID1:
618 nrf_nfct_sensres_nfcid1_size_t id_size_mask;
620 id_size_mask = nrf_nfct_nfcid1_size_to_sensres_size(p_param->data.nfcid1.id_size);
621 nrf_nfct_nfcid1_set(p_param->data.nfcid1.p_id, id_size_mask);
632 nrfx_err_t nrfx_nfct_nfcid1_default_bytes_get(uint8_t *
const p_nfcid1_buff,
633 uint32_t nfcid1_buff_len)
635 if ((nfcid1_buff_len != NRFX_NFCT_NFCID1_SINGLE_SIZE) &&
636 (nfcid1_buff_len != NRFX_NFCT_NFCID1_DOUBLE_SIZE) &&
637 (nfcid1_buff_len != NRFX_NFCT_NFCID1_TRIPLE_SIZE))
639 return NRFX_ERROR_INVALID_LENGTH;
642 uint32_t nfc_tag_header0 = NRF_FICR->NFC.TAGHEADER0;
643 uint32_t nfc_tag_header1 = NRF_FICR->NFC.TAGHEADER1;
644 uint32_t nfc_tag_header2 = NRF_FICR->NFC.TAGHEADER2;
646 p_nfcid1_buff[0] = (uint8_t) (nfc_tag_header0 >> 0);
647 p_nfcid1_buff[1] = (uint8_t) (nfc_tag_header0 >> 8);
648 p_nfcid1_buff[2] = (uint8_t) (nfc_tag_header0 >> 16);
649 p_nfcid1_buff[3] = (uint8_t) (nfc_tag_header1 >> 0);
651 if (nfcid1_buff_len != NRFX_NFCT_NFCID1_SINGLE_SIZE)
653 p_nfcid1_buff[4] = (uint8_t) (nfc_tag_header1 >> 8);
654 p_nfcid1_buff[5] = (uint8_t) (nfc_tag_header1 >> 16);
655 p_nfcid1_buff[6] = (uint8_t) (nfc_tag_header1 >> 24);
657 if (nfcid1_buff_len == NRFX_NFCT_NFCID1_TRIPLE_SIZE)
659 p_nfcid1_buff[7] = (uint8_t) (nfc_tag_header2 >> 0);
660 p_nfcid1_buff[8] = (uint8_t) (nfc_tag_header2 >> 8);
661 p_nfcid1_buff[9] = (uint8_t) (nfc_tag_header2 >> 16);
666 else if (p_nfcid1_buff[3] == 0x88)
668 p_nfcid1_buff[3] |= 0x11;
676 void nrfx_nfct_autocolres_enable(
void)
678 #if defined(NRF52832_XXAA) || defined(NRF52832_XXAB)
679 (*(uint32_t *)(0x4000559C)) &= (~(0x1UL));
681 nrf_nfct_autocolres_enable();
685 void nrfx_nfct_autocolres_disable(
void)
687 #if defined(NRF52832_XXAA) || defined(NRF52832_XXAB)
688 (*(uint32_t *)(0x4000559C)) |= (0x1UL);
690 nrf_nfct_autocolres_disable();
694 void nrfx_nfct_irq_handler(
void)
696 nrfx_nfct_field_state_t current_field = NRFX_NFC_FIELD_STATE_NONE;
698 if (NRFX_NFCT_EVT_ACTIVE(FIELDDETECTED))
700 nrf_nfct_event_clear(NRF_NFCT_EVENT_FIELDDETECTED);
701 current_field = NRFX_NFC_FIELD_STATE_ON;
703 NRFX_LOG_DEBUG(
"Field detected");
706 #if !defined(NRF52832_XXAA) && !defined(NRF52832_XXAB)
707 if (NRFX_NFCT_EVT_ACTIVE(FIELDLOST))
709 nrf_nfct_event_clear(NRF_NFCT_EVENT_FIELDLOST);
710 current_field = (current_field == NRFX_NFC_FIELD_STATE_NONE) ?
711 NRFX_NFC_FIELD_STATE_OFF : NRFX_NFC_FIELD_STATE_UNKNOWN;
713 NRFX_LOG_DEBUG(
"Field lost");
718 if (current_field != NRFX_NFC_FIELD_STATE_NONE)
720 nrfx_nfct_field_event_handler(current_field);
723 if (NRFX_NFCT_EVT_ACTIVE(RXFRAMEEND))
725 nrf_nfct_event_clear(NRF_NFCT_EVENT_RXFRAMEEND);
727 nrfx_nfct_evt_t nfct_evt =
729 .evt_id = NRFX_NFCT_EVT_RX_FRAMEEND
733 nfct_evt.params.rx_frameend.rx_status = 0;
734 nfct_evt.params.rx_frameend.rx_data.p_data = nrf_nfct_rxtx_buffer_get();
735 nfct_evt.params.rx_frameend.rx_data.data_size = NRFX_NFCT_BITS_TO_BYTES(nrf_nfct_rx_bits_get(
true));
737 if (NRFX_NFCT_EVT_ACTIVE(RXERROR))
739 nfct_evt.params.rx_frameend.rx_status =
740 (nrf_nfct_rx_frame_status_get() & NRFX_NFCT_FRAME_STATUS_RX_ALL_MASK);
741 nrf_nfct_event_clear(NRF_NFCT_EVENT_RXERROR);
743 NRFX_LOG_DEBUG(
"Rx error (0x%x)", (
unsigned int) nfct_evt.params.rx_frameend.rx_status);
746 nrf_nfct_rx_frame_status_clear(NRFX_NFCT_FRAME_STATUS_RX_ALL_MASK);
749 NRFX_NFCT_CB_HANDLE(m_nfct_cb.config.cb, nfct_evt);
752 nrf_nfct_event_clear(NRF_NFCT_EVENT_TXFRAMESTART);
754 NRFX_LOG_DEBUG(
"Rx fend");
757 if (NRFX_NFCT_EVT_ACTIVE(TXFRAMEEND))
759 nrf_nfct_event_clear(NRF_NFCT_EVENT_TXFRAMEEND);
761 nrfx_nfct_evt_t nfct_evt =
763 .evt_id = NRFX_NFCT_EVT_TX_FRAMEEND
767 nrf_nfct_int_disable(NRFX_NFCT_TX_INT_MASK);
769 NRFX_NFCT_CB_HANDLE(m_nfct_cb.config.cb, nfct_evt);
771 NRFX_LOG_DEBUG(
"Tx fend");
774 if (NRFX_NFCT_EVT_ACTIVE(SELECTED))
776 nrf_nfct_event_clear(NRF_NFCT_EVENT_SELECTED);
779 nrf_nfct_event_clear(NRF_NFCT_EVENT_RXFRAMEEND);
780 nrf_nfct_event_clear(NRF_NFCT_EVENT_RXERROR);
781 nrf_nfct_event_clear(NRF_NFCT_EVENT_TXFRAMESTART);
782 nrf_nfct_event_clear(NRF_NFCT_EVENT_TXFRAMEEND);
785 nrfx_nfct_frame_delay_max_set(
false);
789 nrf_nfct_rx_frame_status_clear(NRFX_NFCT_FRAME_STATUS_RX_ALL_MASK);
790 nrf_nfct_error_status_clear(NRFX_NFCT_ERROR_STATUS_ALL_MASK);
792 nrfx_nfct_evt_t nfct_evt =
794 .evt_id = NRFX_NFCT_EVT_SELECTED
796 NRFX_NFCT_CB_HANDLE(m_nfct_cb.config.cb, nfct_evt);
798 NRFX_LOG_DEBUG(
"Selected");
801 if (NRFX_NFCT_EVT_ACTIVE(ERROR))
803 uint32_t err_status = nrf_nfct_error_status_get();
804 nrf_nfct_event_clear(NRF_NFCT_EVENT_ERROR);
806 nrfx_nfct_evt_t nfct_evt =
808 .evt_id = NRFX_NFCT_EVT_ERROR
812 if (err_status & NRF_NFCT_ERROR_FRAMEDELAYTIMEOUT_MASK)
814 nrf_nfct_error_status_clear(NRF_NFCT_ERROR_FRAMEDELAYTIMEOUT_MASK);
816 nfct_evt.params.error.reason = NRFX_NFCT_ERROR_FRAMEDELAYTIMEOUT;
817 NRFX_NFCT_CB_HANDLE(m_nfct_cb.config.cb, nfct_evt);
821 err_status &= ~NRF_NFCT_ERROR_FRAMEDELAYTIMEOUT_MASK;
824 NRFX_LOG_DEBUG(
"Error (0x%x)", (
unsigned int) err_status);
828 nrf_nfct_error_status_clear(NRFX_NFCT_ERROR_STATUS_ALL_MASK);
831 if (NRFX_NFCT_EVT_ACTIVE(TXFRAMESTART))
833 nrf_nfct_event_clear(NRF_NFCT_EVENT_TXFRAMESTART);
835 if (m_nfct_cb.config.cb != NULL)
837 nrfx_nfct_evt_t nfct_evt;
839 nfct_evt.evt_id = NRFX_NFCT_EVT_TX_FRAMESTART;
840 nfct_evt.params.tx_framestart.tx_data.p_data = nrf_nfct_rxtx_buffer_get();
841 nfct_evt.params.tx_framestart.tx_data.data_size = NRFX_NFCT_BITS_TO_BYTES(nrf_nfct_tx_bits_get());
843 m_nfct_cb.config.cb(&nfct_evt);
#define NRFX_NFCT_CONFIG_IRQ_PRIORITY