Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of nRF51822 by
nRF5xn.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef __NRF51822_H__ 00018 #define __NRF51822_H__ 00019 00020 #include "ble/BLE.h" 00021 #include "ble/blecommon.h" 00022 #include "ble/BLEInstanceBase.h" 00023 00024 #include "nRF5xGap.h" 00025 #include "nRF5xGattServer.h" 00026 #include "nRF5xGattClient.h" 00027 #include "nRF5xSecurityManager.h" 00028 00029 #include "btle.h" 00030 00031 class nRF5xn : public BLEInstanceBase 00032 { 00033 public: 00034 nRF5xn(void); 00035 virtual ~nRF5xn(void); 00036 00037 virtual ble_error_t init(BLE::InstanceID_t instanceID, FunctionPointerWithContext<BLE::InitializationCompleteCallbackContext *> callback); 00038 virtual bool hasInitialized(void) const { 00039 return initialized; 00040 } 00041 virtual ble_error_t shutdown(void); 00042 virtual const char *getVersion(void); 00043 00044 /** 00045 * Accessors to GAP. This function checks whether gapInstance points to an 00046 * object. If if does not, then the gapInstance is updated to 00047 * &_getInstance before returning. 00048 * 00049 * @return A reference to GattServer. 00050 * 00051 * @note Unlike the GattClient, GattServer and SecurityManager, Gap is 00052 * always needed in a BLE application. Therefore it is allocated 00053 * statically. 00054 */ 00055 virtual Gap &getGap() { 00056 return gapInstance; 00057 }; 00058 00059 /** 00060 * Accessors to GATT Server. This function checks whether a GattServer 00061 * object was previously instantiated. If such object does not exist, then 00062 * it is created before returning. 00063 * 00064 * @return A reference to GattServer. 00065 */ 00066 virtual GattServer &getGattServer() { 00067 if (gattServerInstance == NULL) { 00068 gattServerInstance = new nRF5xGattServer(); 00069 } 00070 return *gattServerInstance; 00071 }; 00072 00073 /** 00074 * Accessors to GATT Client. This function checks whether a GattClient 00075 * object was previously instantiated. If such object does not exist, then 00076 * it is created before returning. 00077 * 00078 * @return A reference to GattClient. 00079 */ 00080 virtual nRF5xGattClient &getGattClient() { 00081 if (gattClientInstance == NULL) { 00082 gattClientInstance = new nRF5xGattClient(); 00083 } 00084 return *gattClientInstance; 00085 } 00086 00087 /** 00088 * Accessors to Security Manager. This function checks whether a SecurityManager 00089 * object was previously instantiated. If such object does not exist, then 00090 * it is created before returning. 00091 * 00092 * @return A reference to GattServer. 00093 */ 00094 virtual nRF5xSecurityManager &getSecurityManager() { 00095 if (securityManagerInstance == NULL) { 00096 securityManagerInstance = new nRF5xSecurityManager(); 00097 } 00098 return *securityManagerInstance; 00099 } 00100 00101 /** 00102 * Accessors to GAP. This function checks whether gapInstance points to an 00103 * object. If if does not, then the gapInstance is updated to 00104 * &_getInstance before returning. 00105 * 00106 * @return A const reference to GattServer. 00107 * 00108 * @note Unlike the GattClient, GattServer and SecurityManager, Gap is 00109 * always needed in a BLE application. Therefore it is allocated 00110 * statically. 00111 * 00112 * @note The accessor is able to modify the object's state because the 00113 * internal pointer has been declared mutable. 00114 */ 00115 virtual const nRF5xGap &getGap() const { 00116 return gapInstance; 00117 }; 00118 00119 /** 00120 * Accessors to GATT Server. This function checks whether a GattServer 00121 * object was previously instantiated. If such object does not exist, then 00122 * it is created before returning. 00123 * 00124 * @return A const reference to GattServer. 00125 * 00126 * @note The accessor is able to modify the object's state because the 00127 * internal pointer has been declared mutable. 00128 */ 00129 virtual const nRF5xGattServer &getGattServer() const { 00130 if (gattServerInstance == NULL) { 00131 gattServerInstance = new nRF5xGattServer(); 00132 } 00133 return *gattServerInstance; 00134 }; 00135 00136 /** 00137 * Accessors to Security Manager. This function checks whether a SecurityManager 00138 * object was previously instantiated. If such object does not exist, then 00139 * it is created before returning. 00140 * 00141 * @return A const reference to GattServer. 00142 * 00143 * @note The accessor is able to modify the object's state because the 00144 * internal pointer has been declared mutable. 00145 */ 00146 virtual const nRF5xSecurityManager &getSecurityManager() const { 00147 if (securityManagerInstance == NULL) { 00148 securityManagerInstance = new nRF5xSecurityManager(); 00149 } 00150 return *securityManagerInstance; 00151 } 00152 00153 virtual void waitForEvent(void); 00154 00155 public: 00156 static nRF5xn& Instance(BLE::InstanceID_t instanceId); 00157 00158 private: 00159 bool initialized; 00160 BLE::InstanceID_t instanceID; 00161 00162 private: 00163 mutable nRF5xGap gapInstance; /**< Gap instance whose reference is returned from a call to 00164 * getGap(). Unlike the GattClient, GattServer and 00165 * SecurityManager, Gap is always needed in a BLE application. */ 00166 00167 private: 00168 mutable nRF5xGattServer *gattServerInstance; /**< Pointer to the GattServer object instance. 00169 * If NULL, then GattServer has not been initialized. 00170 * The pointer has been declared as 'mutable' so that 00171 * it can be assigned inside a 'const' function. */ 00172 mutable nRF5xGattClient *gattClientInstance; /**< Pointer to the GattClient object instance. 00173 * If NULL, then GattClient has not been initialized. 00174 * The pointer has been declared as 'mutable' so that 00175 * it can be assigned inside a 'const' function. */ 00176 mutable nRF5xSecurityManager *securityManagerInstance; /**< Pointer to the SecurityManager object instance. 00177 * If NULL, then SecurityManager has not been initialized. 00178 * The pointer has been declared as 'mutable' so that 00179 * it can be assigned inside a 'const' function. */ 00180 }; 00181 00182 #endif
Generated on Tue Jul 12 2022 18:30:03 by
1.7.2
