Skip to content

Commit 502bdf5

Browse files
pan-adbridge
authored andcommitted
BLE: Enable Generic client on Nordic targets.
1 parent f5ac72f commit 502bdf5

File tree

4 files changed

+26
-43
lines changed

4 files changed

+26
-43
lines changed

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5/source/btle/btle.cpp

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,9 @@ extern "C" {
5151
}
5252

5353
#include "nrf_ble_hci.h"
54-
#include "btle_discovery.h"
5554

56-
#include "nRF5xGattClient.h"
57-
#include "nRF5xServiceDiscovery.h"
58-
#include "nRF5xCharacteristicDescriptorDiscoverer.h"
55+
#include "nRF5XPalGattClient.h"
56+
5957

6058

6159
bool isEventsSignaled = false;
@@ -67,23 +65,6 @@ extern "C" void SD_EVT_IRQHandler(void); // export the softdevice event handler
6765

6866
static void btle_handler(ble_evt_t *p_ble_evt);
6967

70-
#if 0
71-
#define CENTRAL_LINK_COUNT (YOTTA_CFG_NORDIC_BLE_CENTRAL_LINKS) /**<number of central links used by the application. When changing this number remember to adjust the RAM settings */
72-
/** If value for YOTTA_CFG_NORDIC_BLE_PERIPHERAL_LINKS was used, ram settings are adjusted by the yotta target module. */
73-
#define PERIPHERAL_LINK_COUNT (YOTTA_CFG_NORDIC_BLE_PERIPHERAL_LINKS) /**<number of peripheral links used by the application. When changing this number remember to adjust the RAM settings*/
74-
/** If value for YOTTA_CFG_NORDIC_BLE_CENTRAL_LINKS was used, ram settings are adjusted by the yotta target module. */
75-
#define GATTS_ATTR_TAB_SIZE (YOTTA_CFG_NORDIC_BLE_GATTS_ATTR_TAB_SIZE) /**< GATTS attribite table size. */
76-
/** If value for YOTTA_CFG_NORDIC_BLE_GATTS_ATTR_TAB_SIZE was used, ram settings are adjusted by the yotta target module. */
77-
#else
78-
#define CENTRAL_LINK_COUNT 3 /**<number of central links used by the application. When changing this number remember to adjust the RAM settings */
79-
/** If value for YOTTA_CFG_NORDIC_BLE_PERIPHERAL_LINKS was used, ram settings are adjusted by the yotta target module. */
80-
#define PERIPHERAL_LINK_COUNT 1 /**<number of peripheral links used by the application. When changing this number remember to adjust the RAM settings*/
81-
/** If value for YOTTA_CFG_NORDIC_BLE_CENTRAL_LINKS was used, ram settings are adjusted by the yotta target module. */
82-
#define GATTS_ATTR_TAB_SIZE 0x600 /**< GATTS attribite table size. */
83-
/** If value for YOTTA_CFG_NORDIC_BLE_GATTS_ATTR_TAB_SIZE was used, ram settings are adjusted by the yotta target module. */
84-
85-
#endif
86-
8768
static void sys_evt_dispatch(uint32_t sys_evt)
8869
{
8970
#if (IS_LEGACY_DEVICE_MANAGER_ENABLED)
@@ -121,7 +102,7 @@ error_t btle_init(void)
121102

122103
// register softdevice handler vector
123104
NVIC_SetVector(SD_EVT_IRQn, (uint32_t) SD_EVT_IRQHandler);
124-
105+
125106
// Configure the LF clock according to values provided by btle_clock.h.
126107
// It is input from the chain of the yotta configuration system.
127108
clockConfiguration.source = LFCLK_CONF_SOURCE;
@@ -189,6 +170,8 @@ error_t btle_init(void)
189170

190171
static void btle_handler(ble_evt_t *p_ble_evt)
191172
{
173+
using ble::pal::vendor::nordic::nRF5XGattClient;
174+
192175
/* Library service handlers */
193176
#if SDK_CONN_PARAMS_MODULE_ENABLE
194177
ble_conn_params_on_ble_evt(p_ble_evt);
@@ -206,7 +189,7 @@ static void btle_handler(ble_evt_t *p_ble_evt)
206189
#endif
207190

208191
#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
209-
bleGattcEventHandler(p_ble_evt);
192+
nRF5XGattClient::handle_events(p_ble_evt);
210193
#endif
211194

212195
nRF5xn &ble = nRF5xn::Instance(BLE::DEFAULT_INSTANCE);
@@ -229,7 +212,7 @@ static void btle_handler(ble_evt_t *p_ble_evt)
229212
const ble_gap_addr_t *peer = &p_ble_evt->evt.gap_evt.params.connected.peer_addr;
230213
#if (NRF_SD_BLE_API_VERSION <= 2)
231214
const ble_gap_addr_t *own = &p_ble_evt->evt.gap_evt.params.connected.own_addr;
232-
215+
233216
gap.processConnectionEvent(handle,
234217
role,
235218
static_cast<BLEProtocol::AddressType_t>(peer->addr_type), peer->addr,
@@ -275,9 +258,7 @@ static void btle_handler(ble_evt_t *p_ble_evt)
275258

276259
#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
277260
// Close all pending discoveries for this connection
278-
nRF5xGattClient& gattClient = ble.getGattClient();
279-
gattClient.characteristicDescriptorDiscoverer().terminate(handle, BLE_ERROR_INVALID_STATE);
280-
gattClient.discovery().terminate(handle);
261+
nRF5XGattClient::handle_connection_termination(handle);
281262
#endif
282263

283264
gap.processDisconnectionEvent(handle, reason);

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5/source/btle/btle.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ extern "C" {
2626
#include "ble_srv_common.h"
2727
#include "headers/nrf_ble.h"
2828

29+
#define CENTRAL_LINK_COUNT 3 /**<number of central links used by the application. When changing this number remember to adjust the RAM settings */
30+
/** If value for YOTTA_CFG_NORDIC_BLE_PERIPHERAL_LINKS was used, ram settings are adjusted by the yotta target module. */
31+
#define PERIPHERAL_LINK_COUNT 1 /**<number of peripheral links used by the application. When changing this number remember to adjust the RAM settings*/
32+
/** If value for YOTTA_CFG_NORDIC_BLE_CENTRAL_LINKS was used, ram settings are adjusted by the yotta target module. */
33+
#define GATTS_ATTR_TAB_SIZE 0x600 /**< GATTS attribite table size. */
34+
/** If value for YOTTA_CFG_NORDIC_BLE_GATTS_ATTR_TAB_SIZE was used, ram settings are adjusted by the yotta target module. */
35+
2936
error_t btle_init(void);
3037

3138
// flag indicating if events have been signaled or not

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5/source/nRF5xn.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ extern "C" {
3131
#include "softdevice_handler.h"
3232
}
3333

34+
#include "nRF5XPalGattClient.h"
35+
3436
/**
3537
* The singleton which represents the nRF51822 transport for the BLE.
3638
*/
@@ -60,7 +62,7 @@ nRF5xn::nRF5xn(void) :
6062
instanceID(BLE::DEFAULT_INSTANCE),
6163
gapInstance(),
6264
gattServerInstance(NULL),
63-
gattClientInstance(NULL),
65+
gattClient(&(ble::pal::vendor::nordic::nRF5XGattClient::get_client())),
6466
securityManagerInstance(NULL)
6567
{
6668
}
@@ -189,11 +191,9 @@ ble_error_t nRF5xn::shutdown(void)
189191

190192
/* S110 does not support BLE client features, nothing to reset. */
191193
#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
192-
if (gattClientInstance != NULL) {
193-
error = gattClientInstance->reset();
194-
if (error != BLE_ERROR_NONE) {
195-
return error;
196-
}
194+
error = getGattClient().reset();
195+
if (error != BLE_ERROR_NONE) {
196+
return error;
197197
}
198198
#endif
199199

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5/source/nRF5xn.h

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
#include "ble/BLE.h"
2121
#include "ble/blecommon.h"
2222
#include "ble/BLEInstanceBase.h"
23+
#include "ble/generic/GenericGattClient.h"
2324

2425
#include "nRF5xGap.h"
2526
#include "nRF5xGattServer.h"
26-
#include "nRF5xGattClient.h"
2727
#include "nRF5xSecurityManager.h"
2828

2929
#include "btle.h"
@@ -77,11 +77,8 @@ class nRF5xn : public BLEInstanceBase
7777
*
7878
* @return A reference to GattClient.
7979
*/
80-
virtual nRF5xGattClient &getGattClient() {
81-
if (gattClientInstance == NULL) {
82-
gattClientInstance = new nRF5xGattClient();
83-
}
84-
return *gattClientInstance;
80+
virtual GattClient &getGattClient() {
81+
return gattClient;
8582
}
8683

8784
/**
@@ -171,10 +168,8 @@ class nRF5xn : public BLEInstanceBase
171168
* If NULL, then GattServer has not been initialized.
172169
* The pointer has been declared as 'mutable' so that
173170
* it can be assigned inside a 'const' function. */
174-
mutable nRF5xGattClient *gattClientInstance; /**< Pointer to the GattClient object instance.
175-
* If NULL, then GattClient has not been initialized.
176-
* The pointer has been declared as 'mutable' so that
177-
* it can be assigned inside a 'const' function. */
171+
ble::generic::GenericGattClient gattClient;
172+
178173
mutable nRF5xSecurityManager *securityManagerInstance; /**< Pointer to the SecurityManager object instance.
179174
* If NULL, then SecurityManager has not been initialized.
180175
* The pointer has been declared as 'mutable' so that

0 commit comments

Comments
 (0)