Official Sheffield ARMBand micro:bit program

Committer:
MrBedfordVan
Date:
Mon Oct 17 12:41:20 2016 +0000
Revision:
0:b9164b348919
Official Sheffield ARMBand Micro:bit program

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MrBedfordVan 0:b9164b348919 1 /* mbed Microcontroller Library
MrBedfordVan 0:b9164b348919 2 * Copyright (c) 2006-2013 ARM Limited
MrBedfordVan 0:b9164b348919 3 *
MrBedfordVan 0:b9164b348919 4 * Licensed under the Apache License, Version 2.0 (the "License");
MrBedfordVan 0:b9164b348919 5 * you may not use this file except in compliance with the License.
MrBedfordVan 0:b9164b348919 6 * You may obtain a copy of the License at
MrBedfordVan 0:b9164b348919 7 *
MrBedfordVan 0:b9164b348919 8 * http://www.apache.org/licenses/LICENSE-2.0
MrBedfordVan 0:b9164b348919 9 *
MrBedfordVan 0:b9164b348919 10 * Unless required by applicable law or agreed to in writing, software
MrBedfordVan 0:b9164b348919 11 * distributed under the License is distributed on an "AS IS" BASIS,
MrBedfordVan 0:b9164b348919 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
MrBedfordVan 0:b9164b348919 13 * See the License for the specific language governing permissions and
MrBedfordVan 0:b9164b348919 14 * limitations under the License.
MrBedfordVan 0:b9164b348919 15 */
MrBedfordVan 0:b9164b348919 16
MrBedfordVan 0:b9164b348919 17 #ifndef __NRF51822_H__
MrBedfordVan 0:b9164b348919 18 #define __NRF51822_H__
MrBedfordVan 0:b9164b348919 19
MrBedfordVan 0:b9164b348919 20 #include "ble/BLE.h"
MrBedfordVan 0:b9164b348919 21 #include "ble/blecommon.h"
MrBedfordVan 0:b9164b348919 22 #include "ble/BLEInstanceBase.h"
MrBedfordVan 0:b9164b348919 23
MrBedfordVan 0:b9164b348919 24 #include "nRF5xGap.h"
MrBedfordVan 0:b9164b348919 25 #include "nRF5xGattServer.h"
MrBedfordVan 0:b9164b348919 26 #include "nRF5xGattClient.h"
MrBedfordVan 0:b9164b348919 27 #include "nRF5xSecurityManager.h"
MrBedfordVan 0:b9164b348919 28
MrBedfordVan 0:b9164b348919 29 #include "btle.h"
MrBedfordVan 0:b9164b348919 30
MrBedfordVan 0:b9164b348919 31 class nRF5xn : public BLEInstanceBase
MrBedfordVan 0:b9164b348919 32 {
MrBedfordVan 0:b9164b348919 33 public:
MrBedfordVan 0:b9164b348919 34 nRF5xn(void);
MrBedfordVan 0:b9164b348919 35 virtual ~nRF5xn(void);
MrBedfordVan 0:b9164b348919 36
MrBedfordVan 0:b9164b348919 37 virtual ble_error_t init(BLE::InstanceID_t instanceID, FunctionPointerWithContext<BLE::InitializationCompleteCallbackContext *> callback);
MrBedfordVan 0:b9164b348919 38 virtual bool hasInitialized(void) const {
MrBedfordVan 0:b9164b348919 39 return initialized;
MrBedfordVan 0:b9164b348919 40 }
MrBedfordVan 0:b9164b348919 41 virtual ble_error_t shutdown(void);
MrBedfordVan 0:b9164b348919 42 virtual const char *getVersion(void);
MrBedfordVan 0:b9164b348919 43
MrBedfordVan 0:b9164b348919 44 /**
MrBedfordVan 0:b9164b348919 45 * Accessors to GAP. This function checks whether gapInstance points to an
MrBedfordVan 0:b9164b348919 46 * object. If if does not, then the gapInstance is updated to
MrBedfordVan 0:b9164b348919 47 * &_getInstance before returning.
MrBedfordVan 0:b9164b348919 48 *
MrBedfordVan 0:b9164b348919 49 * @return A reference to GattServer.
MrBedfordVan 0:b9164b348919 50 *
MrBedfordVan 0:b9164b348919 51 * @note Unlike the GattClient, GattServer and SecurityManager, Gap is
MrBedfordVan 0:b9164b348919 52 * always needed in a BLE application. Therefore it is allocated
MrBedfordVan 0:b9164b348919 53 * statically.
MrBedfordVan 0:b9164b348919 54 */
MrBedfordVan 0:b9164b348919 55 virtual Gap &getGap() {
MrBedfordVan 0:b9164b348919 56 return gapInstance;
MrBedfordVan 0:b9164b348919 57 };
MrBedfordVan 0:b9164b348919 58
MrBedfordVan 0:b9164b348919 59 /**
MrBedfordVan 0:b9164b348919 60 * Accessors to GATT Server. This function checks whether a GattServer
MrBedfordVan 0:b9164b348919 61 * object was previously instantiated. If such object does not exist, then
MrBedfordVan 0:b9164b348919 62 * it is created before returning.
MrBedfordVan 0:b9164b348919 63 *
MrBedfordVan 0:b9164b348919 64 * @return A reference to GattServer.
MrBedfordVan 0:b9164b348919 65 */
MrBedfordVan 0:b9164b348919 66 virtual GattServer &getGattServer() {
MrBedfordVan 0:b9164b348919 67 if (gattServerInstance == NULL) {
MrBedfordVan 0:b9164b348919 68 gattServerInstance = new nRF5xGattServer();
MrBedfordVan 0:b9164b348919 69 }
MrBedfordVan 0:b9164b348919 70 return *gattServerInstance;
MrBedfordVan 0:b9164b348919 71 };
MrBedfordVan 0:b9164b348919 72
MrBedfordVan 0:b9164b348919 73 /**
MrBedfordVan 0:b9164b348919 74 * Accessors to GATT Client. This function checks whether a GattClient
MrBedfordVan 0:b9164b348919 75 * object was previously instantiated. If such object does not exist, then
MrBedfordVan 0:b9164b348919 76 * it is created before returning.
MrBedfordVan 0:b9164b348919 77 *
MrBedfordVan 0:b9164b348919 78 * @return A reference to GattClient.
MrBedfordVan 0:b9164b348919 79 */
MrBedfordVan 0:b9164b348919 80 virtual nRF5xGattClient &getGattClient() {
MrBedfordVan 0:b9164b348919 81 if (gattClientInstance == NULL) {
MrBedfordVan 0:b9164b348919 82 gattClientInstance = new nRF5xGattClient();
MrBedfordVan 0:b9164b348919 83 }
MrBedfordVan 0:b9164b348919 84 return *gattClientInstance;
MrBedfordVan 0:b9164b348919 85 }
MrBedfordVan 0:b9164b348919 86
MrBedfordVan 0:b9164b348919 87 /**
MrBedfordVan 0:b9164b348919 88 * Accessors to Security Manager. This function checks whether a SecurityManager
MrBedfordVan 0:b9164b348919 89 * object was previously instantiated. If such object does not exist, then
MrBedfordVan 0:b9164b348919 90 * it is created before returning.
MrBedfordVan 0:b9164b348919 91 *
MrBedfordVan 0:b9164b348919 92 * @return A reference to GattServer.
MrBedfordVan 0:b9164b348919 93 */
MrBedfordVan 0:b9164b348919 94 virtual nRF5xSecurityManager &getSecurityManager() {
MrBedfordVan 0:b9164b348919 95 if (securityManagerInstance == NULL) {
MrBedfordVan 0:b9164b348919 96 securityManagerInstance = new nRF5xSecurityManager();
MrBedfordVan 0:b9164b348919 97 }
MrBedfordVan 0:b9164b348919 98 return *securityManagerInstance;
MrBedfordVan 0:b9164b348919 99 }
MrBedfordVan 0:b9164b348919 100
MrBedfordVan 0:b9164b348919 101 /**
MrBedfordVan 0:b9164b348919 102 * Accessors to GAP. This function checks whether gapInstance points to an
MrBedfordVan 0:b9164b348919 103 * object. If if does not, then the gapInstance is updated to
MrBedfordVan 0:b9164b348919 104 * &_getInstance before returning.
MrBedfordVan 0:b9164b348919 105 *
MrBedfordVan 0:b9164b348919 106 * @return A const reference to GattServer.
MrBedfordVan 0:b9164b348919 107 *
MrBedfordVan 0:b9164b348919 108 * @note Unlike the GattClient, GattServer and SecurityManager, Gap is
MrBedfordVan 0:b9164b348919 109 * always needed in a BLE application. Therefore it is allocated
MrBedfordVan 0:b9164b348919 110 * statically.
MrBedfordVan 0:b9164b348919 111 *
MrBedfordVan 0:b9164b348919 112 * @note The accessor is able to modify the object's state because the
MrBedfordVan 0:b9164b348919 113 * internal pointer has been declared mutable.
MrBedfordVan 0:b9164b348919 114 */
MrBedfordVan 0:b9164b348919 115 virtual const nRF5xGap &getGap() const {
MrBedfordVan 0:b9164b348919 116 return gapInstance;
MrBedfordVan 0:b9164b348919 117 };
MrBedfordVan 0:b9164b348919 118
MrBedfordVan 0:b9164b348919 119 /**
MrBedfordVan 0:b9164b348919 120 * Accessors to GATT Server. This function checks whether a GattServer
MrBedfordVan 0:b9164b348919 121 * object was previously instantiated. If such object does not exist, then
MrBedfordVan 0:b9164b348919 122 * it is created before returning.
MrBedfordVan 0:b9164b348919 123 *
MrBedfordVan 0:b9164b348919 124 * @return A const reference to GattServer.
MrBedfordVan 0:b9164b348919 125 *
MrBedfordVan 0:b9164b348919 126 * @note The accessor is able to modify the object's state because the
MrBedfordVan 0:b9164b348919 127 * internal pointer has been declared mutable.
MrBedfordVan 0:b9164b348919 128 */
MrBedfordVan 0:b9164b348919 129 virtual const nRF5xGattServer &getGattServer() const {
MrBedfordVan 0:b9164b348919 130 if (gattServerInstance == NULL) {
MrBedfordVan 0:b9164b348919 131 gattServerInstance = new nRF5xGattServer();
MrBedfordVan 0:b9164b348919 132 }
MrBedfordVan 0:b9164b348919 133 return *gattServerInstance;
MrBedfordVan 0:b9164b348919 134 };
MrBedfordVan 0:b9164b348919 135
MrBedfordVan 0:b9164b348919 136 /**
MrBedfordVan 0:b9164b348919 137 * Accessors to Security Manager. This function checks whether a SecurityManager
MrBedfordVan 0:b9164b348919 138 * object was previously instantiated. If such object does not exist, then
MrBedfordVan 0:b9164b348919 139 * it is created before returning.
MrBedfordVan 0:b9164b348919 140 *
MrBedfordVan 0:b9164b348919 141 * @return A const reference to GattServer.
MrBedfordVan 0:b9164b348919 142 *
MrBedfordVan 0:b9164b348919 143 * @note The accessor is able to modify the object's state because the
MrBedfordVan 0:b9164b348919 144 * internal pointer has been declared mutable.
MrBedfordVan 0:b9164b348919 145 */
MrBedfordVan 0:b9164b348919 146 virtual const nRF5xSecurityManager &getSecurityManager() const {
MrBedfordVan 0:b9164b348919 147 if (securityManagerInstance == NULL) {
MrBedfordVan 0:b9164b348919 148 securityManagerInstance = new nRF5xSecurityManager();
MrBedfordVan 0:b9164b348919 149 }
MrBedfordVan 0:b9164b348919 150 return *securityManagerInstance;
MrBedfordVan 0:b9164b348919 151 }
MrBedfordVan 0:b9164b348919 152
MrBedfordVan 0:b9164b348919 153 virtual void waitForEvent(void);
MrBedfordVan 0:b9164b348919 154
MrBedfordVan 0:b9164b348919 155 public:
MrBedfordVan 0:b9164b348919 156 static nRF5xn& Instance(BLE::InstanceID_t instanceId);
MrBedfordVan 0:b9164b348919 157
MrBedfordVan 0:b9164b348919 158 private:
MrBedfordVan 0:b9164b348919 159 bool initialized;
MrBedfordVan 0:b9164b348919 160 BLE::InstanceID_t instanceID;
MrBedfordVan 0:b9164b348919 161
MrBedfordVan 0:b9164b348919 162 private:
MrBedfordVan 0:b9164b348919 163 mutable nRF5xGap gapInstance; /**< Gap instance whose reference is returned from a call to
MrBedfordVan 0:b9164b348919 164 * getGap(). Unlike the GattClient, GattServer and
MrBedfordVan 0:b9164b348919 165 * SecurityManager, Gap is always needed in a BLE application. */
MrBedfordVan 0:b9164b348919 166
MrBedfordVan 0:b9164b348919 167 private:
MrBedfordVan 0:b9164b348919 168 mutable nRF5xGattServer *gattServerInstance; /**< Pointer to the GattServer object instance.
MrBedfordVan 0:b9164b348919 169 * If NULL, then GattServer has not been initialized.
MrBedfordVan 0:b9164b348919 170 * The pointer has been declared as 'mutable' so that
MrBedfordVan 0:b9164b348919 171 * it can be assigned inside a 'const' function. */
MrBedfordVan 0:b9164b348919 172 mutable nRF5xGattClient *gattClientInstance; /**< Pointer to the GattClient object instance.
MrBedfordVan 0:b9164b348919 173 * If NULL, then GattClient has not been initialized.
MrBedfordVan 0:b9164b348919 174 * The pointer has been declared as 'mutable' so that
MrBedfordVan 0:b9164b348919 175 * it can be assigned inside a 'const' function. */
MrBedfordVan 0:b9164b348919 176 mutable nRF5xSecurityManager *securityManagerInstance; /**< Pointer to the SecurityManager object instance.
MrBedfordVan 0:b9164b348919 177 * If NULL, then SecurityManager has not been initialized.
MrBedfordVan 0:b9164b348919 178 * The pointer has been declared as 'mutable' so that
MrBedfordVan 0:b9164b348919 179 * it can be assigned inside a 'const' function. */
MrBedfordVan 0:b9164b348919 180 };
MrBedfordVan 0:b9164b348919 181
MrBedfordVan 0:b9164b348919 182 #endif