Previous version which works for my stm32f401 Nucleo board

Fork of X_NUCLEO_IDB0XA1 by ST

Committer:
Wolfgang Betz
Date:
Tue Oct 06 12:12:37 2015 +0200
Revision:
128:46ae62a90136
Parent:
109:9e152b2453bc
Merge branch 'master' of hg::http://wobetz@developer.mbed.org/teams/ST/code/X_NUCLEO_IDB0XA1 into idb0xa1-split

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wolfgang Betz 90:26c0c9807ab4 1 /* mbed Microcontroller Library
Wolfgang Betz 90:26c0c9807ab4 2 * Copyright (c) 2006-2013 ARM Limited
Wolfgang Betz 90:26c0c9807ab4 3 *
Wolfgang Betz 90:26c0c9807ab4 4 * Licensed under the Apache License, Version 2.0 (the "License");
Wolfgang Betz 90:26c0c9807ab4 5 * you may not use this file except in compliance with the License.
Wolfgang Betz 90:26c0c9807ab4 6 * You may obtain a copy of the License at
Wolfgang Betz 90:26c0c9807ab4 7 *
Wolfgang Betz 90:26c0c9807ab4 8 * http://www.apache.org/licenses/LICENSE-2.0
Wolfgang Betz 90:26c0c9807ab4 9 *
Wolfgang Betz 90:26c0c9807ab4 10 * Unless required by applicable law or agreed to in writing, software
Wolfgang Betz 90:26c0c9807ab4 11 * distributed under the License is distributed on an "AS IS" BASIS,
Wolfgang Betz 90:26c0c9807ab4 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Wolfgang Betz 90:26c0c9807ab4 13 * See the License for the specific language governing permissions and
Wolfgang Betz 90:26c0c9807ab4 14 * limitations under the License.
Wolfgang Betz 90:26c0c9807ab4 15 */
Wolfgang Betz 90:26c0c9807ab4 16
Wolfgang Betz 90:26c0c9807ab4 17 /**
Wolfgang Betz 90:26c0c9807ab4 18 ******************************************************************************
Wolfgang Betz 90:26c0c9807ab4 19 * @file BlueNRGGap.h
Wolfgang Betz 90:26c0c9807ab4 20 * @author STMicroelectronics
Wolfgang Betz 90:26c0c9807ab4 21 * @brief Header file for BlueNRG BLE_API Gap Class
Wolfgang Betz 90:26c0c9807ab4 22 ******************************************************************************
Wolfgang Betz 90:26c0c9807ab4 23 * @copy
Wolfgang Betz 90:26c0c9807ab4 24 *
Wolfgang Betz 90:26c0c9807ab4 25 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
Wolfgang Betz 90:26c0c9807ab4 26 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
Wolfgang Betz 90:26c0c9807ab4 27 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
Wolfgang Betz 90:26c0c9807ab4 28 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
Wolfgang Betz 90:26c0c9807ab4 29 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
Wolfgang Betz 90:26c0c9807ab4 30 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
Wolfgang Betz 90:26c0c9807ab4 31 *
Wolfgang Betz 90:26c0c9807ab4 32 * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
Wolfgang Betz 90:26c0c9807ab4 33 */
Wolfgang Betz 90:26c0c9807ab4 34
Wolfgang Betz 90:26c0c9807ab4 35 #ifndef __BLUENRG_GAP_H__
Wolfgang Betz 90:26c0c9807ab4 36 #define __BLUENRG_GAP_H__
Wolfgang Betz 90:26c0c9807ab4 37
Wolfgang Betz 90:26c0c9807ab4 38 #include "mbed.h"
Wolfgang Betz 90:26c0c9807ab4 39 #include "blecommon.h"
Wolfgang Betz 90:26c0c9807ab4 40 #include "btle.h"
Wolfgang Betz 90:26c0c9807ab4 41 #include "GapAdvertisingParams.h"
Wolfgang Betz 90:26c0c9807ab4 42 #include "GapAdvertisingData.h"
Wolfgang Betz 90:26c0c9807ab4 43 #include <ble/Gap.h>
Wolfgang Betz 90:26c0c9807ab4 44
Wolfgang Betz 90:26c0c9807ab4 45 #define BLE_CONN_HANDLE_INVALID 0x0
Wolfgang Betz 90:26c0c9807ab4 46 #define BDADDR_SIZE 6
Wolfgang Betz 90:26c0c9807ab4 47
Wolfgang Betz 90:26c0c9807ab4 48 #define BLUENRG_GAP_ADV_INTERVAL_MIN (0)
Wolfgang Betz 90:26c0c9807ab4 49 #define BLUENRG_GAP_ADV_INTERVAL_MAX (0)
Wolfgang Betz 90:26c0c9807ab4 50 #define BLE_GAP_ADV_NONCON_INTERVAL_MIN (0)
Wolfgang Betz 90:26c0c9807ab4 51
apalmieri 94:2993df23d1ac 52 #define UUID_BUFFER_SIZE 13 //6*2(16-bit UUIDs)+1
apalmieri 94:2993df23d1ac 53 #define ADV_DATA_MAX_SIZE 31
Wolfgang Betz 90:26c0c9807ab4 54
Wolfgang Betz 90:26c0c9807ab4 55 /**************************************************************************/
Wolfgang Betz 90:26c0c9807ab4 56 /*!
Wolfgang Betz 90:26c0c9807ab4 57 \brief
Wolfgang Betz 90:26c0c9807ab4 58
Wolfgang Betz 90:26c0c9807ab4 59 */
Wolfgang Betz 90:26c0c9807ab4 60 /**************************************************************************/
Wolfgang Betz 90:26c0c9807ab4 61 class BlueNRGGap : public Gap
Wolfgang Betz 90:26c0c9807ab4 62 {
Wolfgang Betz 90:26c0c9807ab4 63 public:
Wolfgang Betz 90:26c0c9807ab4 64 static BlueNRGGap &getInstance() {
Wolfgang Betz 90:26c0c9807ab4 65 static BlueNRGGap m_instance;
Wolfgang Betz 90:26c0c9807ab4 66 return m_instance;
Wolfgang Betz 90:26c0c9807ab4 67 }
Wolfgang Betz 90:26c0c9807ab4 68
Wolfgang Betz 90:26c0c9807ab4 69 // <<<ANDREA>>>
Wolfgang Betz 90:26c0c9807ab4 70 enum AdvType_t {
Wolfgang Betz 90:26c0c9807ab4 71 ADV_IND = GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED,//Gap::ADV_IND,
Wolfgang Betz 90:26c0c9807ab4 72 ADV_DIRECT_IND = GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED,//Gap::ADV_DIRECT_IND,
Wolfgang Betz 90:26c0c9807ab4 73 ADV_SCAN_IND = GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED,//Gap::ADV_SCAN_IND,
Wolfgang Betz 90:26c0c9807ab4 74 ADV_NONCONN_IND = GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED//Gap::ADV_NONCONN_IND
Wolfgang Betz 90:26c0c9807ab4 75 };
Wolfgang Betz 90:26c0c9807ab4 76
Wolfgang Betz 90:26c0c9807ab4 77 /* Functions that must be implemented from Gap */
Wolfgang Betz 90:26c0c9807ab4 78 virtual ble_error_t setAddress(addr_type_t type, const Address_t address);
Wolfgang Betz 90:26c0c9807ab4 79 virtual ble_error_t getAddress(addr_type_t *typeP, Address_t address);
Wolfgang Betz 90:26c0c9807ab4 80 virtual ble_error_t setAdvertisingData(const GapAdvertisingData &, const GapAdvertisingData &);
Wolfgang Betz 90:26c0c9807ab4 81 virtual ble_error_t startAdvertising(const GapAdvertisingParams &);
Wolfgang Betz 90:26c0c9807ab4 82 virtual ble_error_t stopAdvertising(void);
Wolfgang Betz 90:26c0c9807ab4 83 virtual ble_error_t stopScan();
Wolfgang Betz 90:26c0c9807ab4 84 virtual uint16_t getMinAdvertisingInterval(void) const;
Wolfgang Betz 90:26c0c9807ab4 85 virtual uint16_t getMinNonConnectableAdvertisingInterval(void) const;
Wolfgang Betz 90:26c0c9807ab4 86 virtual uint16_t getMaxAdvertisingInterval(void) const;
Wolfgang Betz 90:26c0c9807ab4 87 virtual ble_error_t disconnect(DisconnectionReason_t reason);
Wolfgang Betz 90:26c0c9807ab4 88 virtual ble_error_t disconnect(Handle_t connectionHandle, DisconnectionReason_t reason);
Wolfgang Betz 90:26c0c9807ab4 89 virtual ble_error_t getPreferredConnectionParams(ConnectionParams_t *params);
Wolfgang Betz 90:26c0c9807ab4 90 virtual ble_error_t setPreferredConnectionParams(const ConnectionParams_t *params);
Wolfgang Betz 90:26c0c9807ab4 91 virtual ble_error_t updateConnectionParams(Handle_t handle, const ConnectionParams_t *params);
Wolfgang Betz 90:26c0c9807ab4 92
Wolfgang Betz 90:26c0c9807ab4 93 virtual ble_error_t setDeviceName(const uint8_t *deviceName);
Wolfgang Betz 90:26c0c9807ab4 94 virtual ble_error_t getDeviceName(uint8_t *deviceName, unsigned *lengthP);
Wolfgang Betz 90:26c0c9807ab4 95 virtual ble_error_t setAppearance(GapAdvertisingData::Appearance appearance);
Wolfgang Betz 90:26c0c9807ab4 96 virtual ble_error_t getAppearance(GapAdvertisingData::Appearance *appearanceP);
Wolfgang Betz 90:26c0c9807ab4 97
Wolfgang Betz 90:26c0c9807ab4 98 virtual ble_error_t setTxPower(int8_t txPower);
Wolfgang Betz 90:26c0c9807ab4 99 virtual void getPermittedTxPowerValues(const int8_t **, size_t *);
Wolfgang Betz 90:26c0c9807ab4 100 // <<<ANDREA>>>
Wolfgang Betz 90:26c0c9807ab4 101
Wolfgang Betz 90:26c0c9807ab4 102
Wolfgang Betz 90:26c0c9807ab4 103 void setConnectionHandle(uint16_t con_handle);
Wolfgang Betz 90:26c0c9807ab4 104 uint16_t getConnectionHandle(void);
Wolfgang Betz 90:26c0c9807ab4 105
Wolfgang Betz 90:26c0c9807ab4 106 //tHalUint8* getAddress();
Wolfgang Betz 90:26c0c9807ab4 107 bool getIsSetAddress();
apalmieri 109:9e152b2453bc 108
apalmieri 109:9e152b2453bc 109 Timeout getAdvTimeout(void) const {
apalmieri 109:9e152b2453bc 110 return advTimeout;
apalmieri 109:9e152b2453bc 111 }
apalmieri 109:9e152b2453bc 112 uint8_t getAdvToFlag(void) {
apalmieri 109:9e152b2453bc 113 return AdvToFlag;
apalmieri 109:9e152b2453bc 114 }
apalmieri 109:9e152b2453bc 115 void setAdvToFlag(void);
apalmieri 109:9e152b2453bc 116
apalmieri 109:9e152b2453bc 117 void Process(void);
Wolfgang Betz 90:26c0c9807ab4 118
Wolfgang Betz 90:26c0c9807ab4 119 protected:
Wolfgang Betz 90:26c0c9807ab4 120 virtual ble_error_t startRadioScan(const GapScanningParams &scanningParams);
Wolfgang Betz 90:26c0c9807ab4 121
Wolfgang Betz 90:26c0c9807ab4 122 private:
Wolfgang Betz 90:26c0c9807ab4 123 uint16_t m_connectionHandle;
Wolfgang Betz 90:26c0c9807ab4 124 uint8_t bdaddr[BDADDR_SIZE];
Wolfgang Betz 90:26c0c9807ab4 125 bool isSetAddress;
apalmieri 94:2993df23d1ac 126 tBleStatus ret; // FIXME: delete this
Wolfgang Betz 90:26c0c9807ab4 127 uint8_t *DeviceName;
Wolfgang Betz 90:26c0c9807ab4 128 uint8_t deviceAppearance[2];
Wolfgang Betz 90:26c0c9807ab4 129
apalmieri 94:2993df23d1ac 130 uint8_t *local_name;
apalmieri 94:2993df23d1ac 131 uint8_t local_name_length;
apalmieri 107:5cc5ac5bfbbb 132
apalmieri 107:5cc5ac5bfbbb 133 bool txPowerAdType;
apalmieri 94:2993df23d1ac 134
apalmieri 94:2993df23d1ac 135 uint8_t servUuidlength;
apalmieri 94:2993df23d1ac 136 uint8_t servUuidData[UUID_BUFFER_SIZE];
apalmieri 94:2993df23d1ac 137
apalmieri 94:2993df23d1ac 138 uint8_t AdvLen;
apalmieri 94:2993df23d1ac 139 uint8_t AdvData[ADV_DATA_MAX_SIZE];
apalmieri 94:2993df23d1ac 140
apalmieri 109:9e152b2453bc 141 Timeout advTimeout;
apalmieri 109:9e152b2453bc 142 bool AdvToFlag;
apalmieri 109:9e152b2453bc 143
Wolfgang Betz 90:26c0c9807ab4 144 BlueNRGGap() {
Wolfgang Betz 90:26c0c9807ab4 145 m_connectionHandle = BLE_CONN_HANDLE_INVALID;
Wolfgang Betz 90:26c0c9807ab4 146 isSetAddress = false;
Wolfgang Betz 90:26c0c9807ab4 147 DeviceName = NULL;
Wolfgang Betz 90:26c0c9807ab4 148 }
Wolfgang Betz 90:26c0c9807ab4 149
Wolfgang Betz 90:26c0c9807ab4 150 BlueNRGGap(BlueNRGGap const &);
Wolfgang Betz 90:26c0c9807ab4 151 void operator=(BlueNRGGap const &);
Wolfgang Betz 90:26c0c9807ab4 152 };
Wolfgang Betz 90:26c0c9807ab4 153
Wolfgang Betz 90:26c0c9807ab4 154 #endif // ifndef __BLUENRG_GAP_H__