Skip to content
This repository was archived by the owner on Sep 23, 2021. It is now read-only.

Commit 8f9a84c

Browse files
authored
Merge pull request #119 from ojousima/v1-backports
Add NFC fixes to eddystone
2 parents 4235e6d + 9ef1732 commit 8f9a84c

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

ruuvi_examples/eddystone/bluetooth_application_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#define APPLICATION_ADV_INTERVAL 500 /**< ms **/
99
#define APP_TX_POWER 4 /**< dBm **/
1010

11-
#define INIT_FWREV "Eddystone 1.3.4" /**< Github tag **/
11+
#define INIT_FWREV "Eddystone 1.3.5" /**< Github tag **/
1212
#define INIT_SWREV INIT_FWREV /**< Practicially same thing, as there is no separate SW **/
1313

1414
#endif

ruuvi_examples/eddystone/main.c

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
#include "init.h"
4545
#include "bluetooth_core.h"
4646
#include "pin_interrupt.h"
47-
#include "nrf_nfc_handler.h"
47+
#include "nfc.h"
48+
#include "nfc_t2t_lib.h"
4849

4950
#include "ruuvi_endpoints.h"
5051

@@ -132,10 +133,41 @@ ret_code_t button_press_handler(const ruuvi_standard_message_t message)
132133
/**
133134
* Callback for NFC event
134135
*/
135-
ret_code_t nfc_detected_handler(const ruuvi_standard_message_t message)
136+
static void nfc_detected_handler(void* data, uint16_t length)
136137
{
137138
nrf_ble_es_on_start_connectable_advertising();
138-
return NRF_SUCCESS;
139+
}
140+
141+
/**
142+
* Work around NFC data corruption bug by reinitializing NFC data after field has been lost.
143+
* Call this function outside of interrupt context.
144+
*/
145+
static void reinit_nfc(void* data, uint16_t length)
146+
{
147+
init_nfc();
148+
}
149+
150+
/**@brief Function for handling NFC events.
151+
* Schedulers call to handler.
152+
*/
153+
void app_nfc_callback(void* p_context, nfc_t2t_event_t event, const uint8_t* p_data, size_t data_length)
154+
{
155+
NRF_LOG_INFO("NFC\r\n");
156+
switch (event)
157+
{
158+
case NFC_T2T_EVENT_FIELD_ON:
159+
NRF_LOG_INFO("NFC Field detected \r\n");
160+
app_sched_event_put (NULL, 0, nfc_detected_handler);
161+
break;
162+
case NFC_T2T_EVENT_FIELD_OFF:
163+
NRF_LOG_INFO("NFC Field lost \r\n");
164+
app_sched_event_put (NULL, 0, reinit_nfc);
165+
break;
166+
case NFC_T2T_EVENT_DATA_READ:
167+
NRF_LOG_INFO("Data read\r\n");
168+
default:
169+
break;
170+
}
139171
}
140172

141173
/**
@@ -155,9 +187,8 @@ int main(void)
155187

156188
NRF_LOG_DEBUG("BLE init status: %d\r\n", err_code);
157189

158-
//init_handler must be called before init_nfc, as init_nfc passes function pointer set by init_handler to NFC stack
159-
nfc_init_handler();
160-
nfc_connected_handler_set(nfc_detected_handler);
190+
//setup callback before initializing NFC.
191+
set_nfc_callback(app_nfc_callback);
161192
err_code |= init_nfc();
162193

163194

0 commit comments

Comments
 (0)