BLE_API wrapper library for STMicroelectronics' BlueNRG Bluetooth Low Energy expansion board shield (Component)

Dependents:   Nucleo_Zumo_BLE_IDB04A1 contest_IOT5 contest_IOT6 contest_IOT_10 ... more

Fork of X_NUCLEO_IDB0XA1 by ST Expansion SW Team

Arduino Connector Compatibility Warning

X-NUCLEO-IDB04A1 and X-NUCLEO-IDB05A1 are Arduino compatible with an exception: instead of using pin D13 for the SPI clock, they use pin D3. The default configuration for this library is having the SPI clock on pin D3.

To be fully Arduino compatible, X-NUCLEO-IDB04A1 and X-NUCLEO-IDB05A1 need a small HW patch.

For X-NUCLEO-IDB04A1 this patch consists in removing zero resistor R10 and instead soldering zero resistor R11. For X-NUCLEO-IDB05A1 this patch consists in removing zero resistor R4 and instead soldering zero resistor R6.

In case you patch your board, then you also have to configure this library to use pin D13 to drive the SPI clock (see macro IDB0XA1_D13_PATCH in file x_nucleo_idb0xa1_targets.h).

If you use pin D13 for the SPI clock, please be aware that on STM32 Nucleo boards you may not drive the LED, otherwise you will get a conflict: the LED on STM32 Nucleo boards is connected to pin D13.

Referring to the current list of tested platforms (see X-NUCLEO-IDB04A1 and X-NUCLEO-IDB05A1 pages), the patch is required by ST-Nucleo-F103RB; ST-Nucleo-F302R8; ST-Nucleo-F411RE; and ST-Nucleo-F446RE.

Committer:
Andrea Palmieri
Date:
Fri Sep 16 12:03:25 2016 +0200
Revision:
307:fa98703ece8e
Parent:
278:a5209d8cfd61
Sync with 21bfd161ace255bb6214d6b74cae1fd30b3e24c9

2016-09-16 11:53:47+02:00: Andrea Palmieri
Get rid of warnings

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wolfgang Betz 130:770ce14d3d15 1 /* mbed Microcontroller Library
Wolfgang Betz 130:770ce14d3d15 2 * Copyright (c) 2006-2013 ARM Limited
Wolfgang Betz 130:770ce14d3d15 3 *
Wolfgang Betz 130:770ce14d3d15 4 * Licensed under the Apache License, Version 2.0 (the "License");
Wolfgang Betz 130:770ce14d3d15 5 * you may not use this file except in compliance with the License.
Wolfgang Betz 130:770ce14d3d15 6 * You may obtain a copy of the License at
Wolfgang Betz 130:770ce14d3d15 7 *
Wolfgang Betz 130:770ce14d3d15 8 * http://www.apache.org/licenses/LICENSE-2.0
Wolfgang Betz 130:770ce14d3d15 9 *
Wolfgang Betz 130:770ce14d3d15 10 * Unless required by applicable law or agreed to in writing, software
Wolfgang Betz 130:770ce14d3d15 11 * distributed under the License is distributed on an "AS IS" BASIS,
Wolfgang Betz 130:770ce14d3d15 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Wolfgang Betz 130:770ce14d3d15 13 * See the License for the specific language governing permissions and
Wolfgang Betz 130:770ce14d3d15 14 * limitations under the License.
Wolfgang Betz 130:770ce14d3d15 15 */
Wolfgang Betz 130:770ce14d3d15 16 /**
Wolfgang Betz 130:770ce14d3d15 17 ******************************************************************************
Vincent Coubard 259:323f588e5f57 18 * @file BlueNRGGattServer.cpp
Wolfgang Betz 130:770ce14d3d15 19 * @author STMicroelectronics
Wolfgang Betz 130:770ce14d3d15 20 * @brief Header file for BLE_API GattServer Class
Wolfgang Betz 130:770ce14d3d15 21 ******************************************************************************
Wolfgang Betz 130:770ce14d3d15 22 * @copy
Wolfgang Betz 130:770ce14d3d15 23 *
Wolfgang Betz 130:770ce14d3d15 24 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
Wolfgang Betz 130:770ce14d3d15 25 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
Wolfgang Betz 130:770ce14d3d15 26 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
Wolfgang Betz 130:770ce14d3d15 27 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
Wolfgang Betz 130:770ce14d3d15 28 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
Wolfgang Betz 130:770ce14d3d15 29 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
Wolfgang Betz 130:770ce14d3d15 30 *
Wolfgang Betz 130:770ce14d3d15 31 * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
Andrea Palmieri 229:9981f62cdb1a 32 */
Vincent Coubard 259:323f588e5f57 33
Wolfgang Betz 130:770ce14d3d15 34 #ifndef __BLUENRG_GATT_SERVER_H__
Wolfgang Betz 130:770ce14d3d15 35 #define __BLUENRG_GATT_SERVER_H__
Wolfgang Betz 130:770ce14d3d15 36
Vincent Coubard 278:a5209d8cfd61 37 #ifdef YOTTA_CFG_MBED_OS
Vincent Coubard 278:a5209d8cfd61 38 #include "mbed-drivers/mbed.h"
Vincent Coubard 278:a5209d8cfd61 39 #else
Vincent Coubard 278:a5209d8cfd61 40 #include "mbed.h"
Vincent Coubard 278:a5209d8cfd61 41 #endif
Wolfgang Betz 131:e09947216ccb 42 #include "ble/blecommon.h"
Wolfgang Betz 130:770ce14d3d15 43 #include "btle.h"
Wolfgang Betz 131:e09947216ccb 44 #include "ble/GattService.h"
Wolfgang Betz 130:770ce14d3d15 45 #include "ble/GattServer.h"
Wolfgang Betz 130:770ce14d3d15 46 #include <vector>
Wolfgang Betz 130:770ce14d3d15 47 #include <map>
Wolfgang Betz 130:770ce14d3d15 48
Wolfgang Betz 130:770ce14d3d15 49 #define BLE_TOTAL_CHARACTERISTICS 10
Wolfgang Betz 130:770ce14d3d15 50
Wolfgang Betz 130:770ce14d3d15 51 using namespace std;
Wolfgang Betz 130:770ce14d3d15 52
Wolfgang Betz 130:770ce14d3d15 53 class BlueNRGGattServer : public GattServer
Wolfgang Betz 130:770ce14d3d15 54 {
Wolfgang Betz 130:770ce14d3d15 55 public:
Wolfgang Betz 130:770ce14d3d15 56 static BlueNRGGattServer &getInstance() {
Wolfgang Betz 130:770ce14d3d15 57 static BlueNRGGattServer m_instance;
Wolfgang Betz 130:770ce14d3d15 58 return m_instance;
Wolfgang Betz 130:770ce14d3d15 59 }
Vincent Coubard 259:323f588e5f57 60
Wolfgang Betz 130:770ce14d3d15 61 enum HandleEnum_t {
Wolfgang Betz 130:770ce14d3d15 62 CHAR_HANDLE = 0,
Wolfgang Betz 130:770ce14d3d15 63 CHAR_VALUE_HANDLE,
Wolfgang Betz 130:770ce14d3d15 64 CHAR_DESC_HANDLE
Wolfgang Betz 130:770ce14d3d15 65 };
Vincent Coubard 259:323f588e5f57 66
Wolfgang Betz 130:770ce14d3d15 67 /* Functions that must be implemented from GattServer */
Wolfgang Betz 130:770ce14d3d15 68 virtual ble_error_t addService(GattService &);
Andrea Palmieri 204:6a6d2f041905 69 virtual ble_error_t read(GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP);
Andrea Palmieri 204:6a6d2f041905 70 virtual ble_error_t read(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP);
Wolfgang Betz 130:770ce14d3d15 71 virtual ble_error_t write(GattAttribute::Handle_t, const uint8_t[], uint16_t, bool localOnly = false);
Wolfgang Betz 130:770ce14d3d15 72 virtual ble_error_t write(Gap::Handle_t connectionHandle, GattAttribute::Handle_t, const uint8_t[], uint16_t, bool localOnly = false);
Wolfgang Betz 130:770ce14d3d15 73 virtual ble_error_t initializeGATTDatabase(void);
Vincent Coubard 259:323f588e5f57 74
Wolfgang Betz 130:770ce14d3d15 75 virtual bool isOnDataReadAvailable() const {
Wolfgang Betz 130:770ce14d3d15 76 return true;
Wolfgang Betz 130:770ce14d3d15 77 }
Andrea Palmieri 229:9981f62cdb1a 78
Andrea Palmieri 229:9981f62cdb1a 79 virtual ble_error_t reset(void);
Vincent Coubard 259:323f588e5f57 80
Wolfgang Betz 130:770ce14d3d15 81 /* BlueNRG Functions */
Wolfgang Betz 130:770ce14d3d15 82 void eventCallback(void);
Wolfgang Betz 130:770ce14d3d15 83 //void hwCallback(void *pckt);
Andrea Palmieri 229:9981f62cdb1a 84 ble_error_t Read_Request_CB(uint16_t attributeHandle);
Vincent Coubard 267:cd7870e466b3 85 uint8_t Write_Request_CB(
Vincent Coubard 267:cd7870e466b3 86 uint16_t connection_handle, uint16_t attr_handle,
Vincent Coubard 267:cd7870e466b3 87 uint8_t data_length, const uint8_t* data
Vincent Coubard 267:cd7870e466b3 88 );
Wolfgang Betz 130:770ce14d3d15 89 GattCharacteristic* getCharacteristicFromHandle(uint16_t charHandle);
Wolfgang Betz 130:770ce14d3d15 90 void HCIDataWrittenEvent(const GattWriteCallbackParams *params);
Wolfgang Betz 130:770ce14d3d15 91 void HCIDataReadEvent(const GattReadCallbackParams *params);
Wolfgang Betz 130:770ce14d3d15 92 void HCIEvent(GattServerEvents::gattEvent_e type, uint16_t charHandle);
Wolfgang Betz 130:770ce14d3d15 93 void HCIDataSentEvent(unsigned count);
Vincent Coubard 259:323f588e5f57 94
Wolfgang Betz 130:770ce14d3d15 95 private:
Vincent Coubard 259:323f588e5f57 96
Vincent Coubard 259:323f588e5f57 97 // compute the number of attribute record needed by a service
Vincent Coubard 259:323f588e5f57 98 static uint16_t computeAttributesRecord(GattService& service);
Vincent Coubard 259:323f588e5f57 99
Vincent Coubard 259:323f588e5f57 100
Wolfgang Betz 130:770ce14d3d15 101 static const int MAX_SERVICE_COUNT = 10;
Wolfgang Betz 130:770ce14d3d15 102 uint8_t serviceCount;
Wolfgang Betz 130:770ce14d3d15 103 uint8_t characteristicCount;
Wolfgang Betz 130:770ce14d3d15 104 uint16_t servHandle, charHandle;
Wolfgang Betz 130:770ce14d3d15 105
Andrea Palmieri 229:9981f62cdb1a 106 std::map<uint16_t, uint16_t> bleCharHandleMap; // 1st argument is characteristic, 2nd argument is service
Wolfgang Betz 130:770ce14d3d15 107 GattCharacteristic *p_characteristics[BLE_TOTAL_CHARACTERISTICS];
Wolfgang Betz 130:770ce14d3d15 108 uint16_t bleCharacteristicHandles[BLE_TOTAL_CHARACTERISTICS];
Wolfgang Betz 130:770ce14d3d15 109
Wolfgang Betz 130:770ce14d3d15 110 BlueNRGGattServer() {
Wolfgang Betz 130:770ce14d3d15 111 serviceCount = 0;
Wolfgang Betz 130:770ce14d3d15 112 characteristicCount = 0;
Wolfgang Betz 130:770ce14d3d15 113 };
Wolfgang Betz 130:770ce14d3d15 114
Wolfgang Betz 130:770ce14d3d15 115 BlueNRGGattServer(BlueNRGGattServer const &);
Wolfgang Betz 130:770ce14d3d15 116 void operator=(BlueNRGGattServer const &);
Vincent Coubard 259:323f588e5f57 117
Vincent Coubard 259:323f588e5f57 118 static const int CHAR_DESC_TYPE_16_BIT=0x01;
Vincent Coubard 259:323f588e5f57 119 static const int CHAR_DESC_TYPE_128_BIT=0x02;
Wolfgang Betz 130:770ce14d3d15 120 static const int CHAR_DESC_SECURITY_PERMISSION=0x00;
Vincent Coubard 259:323f588e5f57 121 static const int CHAR_DESC_ACCESS_PERMISSION=0x03;
Vincent Coubard 259:323f588e5f57 122 static const int CHAR_ATTRIBUTE_LEN_IS_FIXED=0x00;
Wolfgang Betz 130:770ce14d3d15 123 };
Wolfgang Betz 130:770ce14d3d15 124
Vincent Coubard 259:323f588e5f57 125 #endif