Nordic stack and drivers for the mbed BLE API. Version to work around build bug.

Dependents:   microbit_rubber_ducky microbit_mouse_BLE microbit_mouse_BLE_daybreak_version microbit_presenter

Fork of nRF51822 by Nordic Semiconductor

Committer:
vcoubard
Date:
Mon Jan 11 10:19:02 2016 +0000
Revision:
541:884f95bf5351
Parent:
526:ec7b14ac1522
Child:
546:1e147322b2b5
Synchronized with git rev 60a7c0c0
Author: Rohit Grover
bring in the latest changes for BLE::init() where we allow <object, member> tuples for init callback.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vcoubard 541:884f95bf5351 1 /* mbed Microcontroller Library
vcoubard 541:884f95bf5351 2 * Copyright (c) 2006-2013 ARM Limited
vcoubard 541:884f95bf5351 3 *
vcoubard 541:884f95bf5351 4 * Licensed under the Apache License, Version 2.0 (the "License");
vcoubard 541:884f95bf5351 5 * you may not use this file except in compliance with the License.
vcoubard 541:884f95bf5351 6 * You may obtain a copy of the License at
vcoubard 541:884f95bf5351 7 *
vcoubard 541:884f95bf5351 8 * http://www.apache.org/licenses/LICENSE-2.0
vcoubard 541:884f95bf5351 9 *
vcoubard 541:884f95bf5351 10 * Unless required by applicable law or agreed to in writing, software
vcoubard 541:884f95bf5351 11 * distributed under the License is distributed on an "AS IS" BASIS,
vcoubard 541:884f95bf5351 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
vcoubard 541:884f95bf5351 13 * See the License for the specific language governing permissions and
vcoubard 541:884f95bf5351 14 * limitations under the License.
vcoubard 541:884f95bf5351 15 */
vcoubard 541:884f95bf5351 16
vcoubard 541:884f95bf5351 17 #ifndef __NRF5x_GAP_H__
vcoubard 541:884f95bf5351 18 #define __NRF5x_GAP_H__
vcoubard 541:884f95bf5351 19
vcoubard 541:884f95bf5351 20 #include "mbed.h"
vcoubard 541:884f95bf5351 21 #include "ble/blecommon.h"
vcoubard 541:884f95bf5351 22 #include "ble.h"
vcoubard 541:884f95bf5351 23 #include "ble/GapAdvertisingParams.h"
vcoubard 541:884f95bf5351 24 #include "ble/GapAdvertisingData.h"
vcoubard 541:884f95bf5351 25 #include "ble/Gap.h"
vcoubard 541:884f95bf5351 26 #include "ble/GapScanningParams.h"
vcoubard 541:884f95bf5351 27
vcoubard 541:884f95bf5351 28 #include "nrf_soc.h"
vcoubard 541:884f95bf5351 29 #include "ble_radio_notification.h"
vcoubard 541:884f95bf5351 30 #include "btle_security.h"
vcoubard 541:884f95bf5351 31
vcoubard 541:884f95bf5351 32 void radioNotificationStaticCallback(bool param);
vcoubard 541:884f95bf5351 33
vcoubard 541:884f95bf5351 34 /**************************************************************************/
vcoubard 541:884f95bf5351 35 /*!
vcoubard 541:884f95bf5351 36 \brief
vcoubard 541:884f95bf5351 37
vcoubard 541:884f95bf5351 38 */
vcoubard 541:884f95bf5351 39 /**************************************************************************/
vcoubard 541:884f95bf5351 40 class nRF5xGap : public Gap
vcoubard 541:884f95bf5351 41 {
vcoubard 541:884f95bf5351 42 public:
vcoubard 541:884f95bf5351 43 static nRF5xGap &getInstance();
vcoubard 541:884f95bf5351 44
vcoubard 541:884f95bf5351 45 /* Functions that must be implemented from Gap */
vcoubard 541:884f95bf5351 46 virtual ble_error_t setAddress(AddressType_t type, const Address_t address);
vcoubard 541:884f95bf5351 47 virtual ble_error_t getAddress(AddressType_t *typeP, Address_t address);
vcoubard 541:884f95bf5351 48 virtual ble_error_t setAdvertisingData(const GapAdvertisingData &, const GapAdvertisingData &);
vcoubard 541:884f95bf5351 49
vcoubard 541:884f95bf5351 50 virtual uint16_t getMinAdvertisingInterval(void) const {return GapAdvertisingParams::ADVERTISEMENT_DURATION_UNITS_TO_MS(BLE_GAP_ADV_INTERVAL_MIN);}
vcoubard 541:884f95bf5351 51 virtual uint16_t getMinNonConnectableAdvertisingInterval(void) const {return GapAdvertisingParams::ADVERTISEMENT_DURATION_UNITS_TO_MS(BLE_GAP_ADV_NONCON_INTERVAL_MIN);}
vcoubard 541:884f95bf5351 52 virtual uint16_t getMaxAdvertisingInterval(void) const {return GapAdvertisingParams::ADVERTISEMENT_DURATION_UNITS_TO_MS(BLE_GAP_ADV_INTERVAL_MAX);}
vcoubard 541:884f95bf5351 53
vcoubard 541:884f95bf5351 54 virtual ble_error_t startAdvertising(const GapAdvertisingParams &);
vcoubard 541:884f95bf5351 55 virtual ble_error_t stopAdvertising(void);
vcoubard 541:884f95bf5351 56 virtual ble_error_t connect(const Address_t, Gap::AddressType_t peerAddrType, const ConnectionParams_t *connectionParams, const GapScanningParams *scanParams);
vcoubard 541:884f95bf5351 57 virtual ble_error_t disconnect(Handle_t connectionHandle, DisconnectionReason_t reason);
vcoubard 541:884f95bf5351 58 virtual ble_error_t disconnect(DisconnectionReason_t reason);
vcoubard 541:884f95bf5351 59
vcoubard 541:884f95bf5351 60 virtual ble_error_t setDeviceName(const uint8_t *deviceName);
vcoubard 541:884f95bf5351 61 virtual ble_error_t getDeviceName(uint8_t *deviceName, unsigned *lengthP);
vcoubard 541:884f95bf5351 62 virtual ble_error_t setAppearance(GapAdvertisingData::Appearance appearance);
vcoubard 541:884f95bf5351 63 virtual ble_error_t getAppearance(GapAdvertisingData::Appearance *appearanceP);
vcoubard 541:884f95bf5351 64
vcoubard 541:884f95bf5351 65 virtual ble_error_t setTxPower(int8_t txPower);
vcoubard 541:884f95bf5351 66 virtual void getPermittedTxPowerValues(const int8_t **valueArrayPP, size_t *countP);
vcoubard 541:884f95bf5351 67
vcoubard 541:884f95bf5351 68 void setConnectionHandle(uint16_t con_handle);
vcoubard 541:884f95bf5351 69 uint16_t getConnectionHandle(void);
vcoubard 541:884f95bf5351 70
vcoubard 541:884f95bf5351 71 virtual ble_error_t getPreferredConnectionParams(ConnectionParams_t *params);
vcoubard 541:884f95bf5351 72 virtual ble_error_t setPreferredConnectionParams(const ConnectionParams_t *params);
vcoubard 541:884f95bf5351 73 virtual ble_error_t updateConnectionParams(Handle_t handle, const ConnectionParams_t *params);
vcoubard 541:884f95bf5351 74
vcoubard 541:884f95bf5351 75 virtual ble_error_t initRadioNotification(void) {
vcoubard 541:884f95bf5351 76 if (ble_radio_notification_init(NRF_APP_PRIORITY_HIGH, NRF_RADIO_NOTIFICATION_DISTANCE_800US, radioNotificationStaticCallback) == NRF_SUCCESS) {
vcoubard 541:884f95bf5351 77 return BLE_ERROR_NONE;
vcoubard 541:884f95bf5351 78 }
vcoubard 541:884f95bf5351 79
vcoubard 541:884f95bf5351 80 return BLE_ERROR_UNSPECIFIED;
vcoubard 541:884f95bf5351 81 }
vcoubard 541:884f95bf5351 82
vcoubard 541:884f95bf5351 83 /* Observer role is not supported by S110, return BLE_ERROR_NOT_IMPLEMENTED */
vcoubard 541:884f95bf5351 84 #if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
vcoubard 541:884f95bf5351 85 virtual ble_error_t startRadioScan(const GapScanningParams &scanningParams) {
vcoubard 541:884f95bf5351 86 ble_gap_scan_params_t scanParams = {
vcoubard 541:884f95bf5351 87 .active = scanningParams.getActiveScanning(), /**< If 1, perform active scanning (scan requests). */
vcoubard 541:884f95bf5351 88 .selective = 0, /**< If 1, ignore unknown devices (non whitelisted). */
vcoubard 541:884f95bf5351 89 .p_whitelist = NULL, /**< Pointer to whitelist, NULL if none is given. */
vcoubard 541:884f95bf5351 90 .interval = scanningParams.getInterval(), /**< Scan interval between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
vcoubard 541:884f95bf5351 91 .window = scanningParams.getWindow(), /**< Scan window between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
vcoubard 541:884f95bf5351 92 .timeout = scanningParams.getTimeout(), /**< Scan timeout between 0x0001 and 0xFFFF in seconds, 0x0000 disables timeout. */
vcoubard 541:884f95bf5351 93 };
vcoubard 541:884f95bf5351 94
vcoubard 541:884f95bf5351 95 if (sd_ble_gap_scan_start(&scanParams) != NRF_SUCCESS) {
vcoubard 541:884f95bf5351 96 return BLE_ERROR_PARAM_OUT_OF_RANGE;
vcoubard 541:884f95bf5351 97 }
vcoubard 541:884f95bf5351 98
vcoubard 541:884f95bf5351 99 return BLE_ERROR_NONE;
vcoubard 541:884f95bf5351 100 }
vcoubard 541:884f95bf5351 101
vcoubard 541:884f95bf5351 102 virtual ble_error_t stopScan(void) {
vcoubard 541:884f95bf5351 103 if (sd_ble_gap_scan_stop() == NRF_SUCCESS) {
vcoubard 541:884f95bf5351 104 return BLE_ERROR_NONE;
vcoubard 541:884f95bf5351 105 }
vcoubard 541:884f95bf5351 106
vcoubard 541:884f95bf5351 107 return BLE_STACK_BUSY;
vcoubard 541:884f95bf5351 108 }
vcoubard 541:884f95bf5351 109 #endif
vcoubard 541:884f95bf5351 110
vcoubard 541:884f95bf5351 111 private:
vcoubard 541:884f95bf5351 112 /**
vcoubard 541:884f95bf5351 113 * A helper function to process radio-notification events; to be called internally.
vcoubard 541:884f95bf5351 114 * @param param [description]
vcoubard 541:884f95bf5351 115 */
vcoubard 541:884f95bf5351 116 void processRadioNotificationEvent(bool param) {
vcoubard 541:884f95bf5351 117 radioNotificationCallback.call(param);
vcoubard 541:884f95bf5351 118 }
vcoubard 541:884f95bf5351 119 friend void radioNotificationStaticCallback(bool param); /* allow invocations of processRadioNotificationEvent() */
vcoubard 541:884f95bf5351 120
vcoubard 541:884f95bf5351 121 private:
vcoubard 541:884f95bf5351 122 uint16_t m_connectionHandle;
vcoubard 541:884f95bf5351 123 nRF5xGap() {
vcoubard 541:884f95bf5351 124 m_connectionHandle = BLE_CONN_HANDLE_INVALID;
vcoubard 541:884f95bf5351 125 }
vcoubard 541:884f95bf5351 126
vcoubard 541:884f95bf5351 127 nRF5xGap(nRF5xGap const &);
vcoubard 541:884f95bf5351 128 void operator=(nRF5xGap const &);
vcoubard 541:884f95bf5351 129 };
vcoubard 541:884f95bf5351 130
rgrover1 388:db85a09c27ef 131 #endif // ifndef __NRF5x_GAP_H__