Fork of ble-x-nucleo-idb0xa1 with changes required by BleStarMbed
bluenrg/BlueNRGDevice.h@0:ac0b0725c6fa, 2018-02-20 (annotated)
- Committer:
- lorevee
- Date:
- Tue Feb 20 11:07:16 2018 +0000
- Revision:
- 0:ac0b0725c6fa
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lorevee | 0:ac0b0725c6fa | 1 | /* mbed Microcontroller Library |
lorevee | 0:ac0b0725c6fa | 2 | * Copyright (c) 2006-2013 ARM Limited |
lorevee | 0:ac0b0725c6fa | 3 | * |
lorevee | 0:ac0b0725c6fa | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
lorevee | 0:ac0b0725c6fa | 5 | * you may not use this file except in compliance with the License. |
lorevee | 0:ac0b0725c6fa | 6 | * You may obtain a copy of the License at |
lorevee | 0:ac0b0725c6fa | 7 | * |
lorevee | 0:ac0b0725c6fa | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
lorevee | 0:ac0b0725c6fa | 9 | * |
lorevee | 0:ac0b0725c6fa | 10 | * Unless required by applicable law or agreed to in writing, software |
lorevee | 0:ac0b0725c6fa | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
lorevee | 0:ac0b0725c6fa | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
lorevee | 0:ac0b0725c6fa | 13 | * See the License for the specific language governing permissions and |
lorevee | 0:ac0b0725c6fa | 14 | * limitations under the License. |
lorevee | 0:ac0b0725c6fa | 15 | */ |
lorevee | 0:ac0b0725c6fa | 16 | |
lorevee | 0:ac0b0725c6fa | 17 | /** |
lorevee | 0:ac0b0725c6fa | 18 | ****************************************************************************** |
lorevee | 0:ac0b0725c6fa | 19 | * @file BlueNRGDevice.h |
lorevee | 0:ac0b0725c6fa | 20 | * @author STMicroelectronics |
lorevee | 0:ac0b0725c6fa | 21 | * @brief Header file for BLEDeviceInstanceBase based BlueNRGDevice |
lorevee | 0:ac0b0725c6fa | 22 | ****************************************************************************** |
lorevee | 0:ac0b0725c6fa | 23 | * @copy |
lorevee | 0:ac0b0725c6fa | 24 | * |
lorevee | 0:ac0b0725c6fa | 25 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS |
lorevee | 0:ac0b0725c6fa | 26 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE |
lorevee | 0:ac0b0725c6fa | 27 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY |
lorevee | 0:ac0b0725c6fa | 28 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING |
lorevee | 0:ac0b0725c6fa | 29 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE |
lorevee | 0:ac0b0725c6fa | 30 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
lorevee | 0:ac0b0725c6fa | 31 | * |
lorevee | 0:ac0b0725c6fa | 32 | * <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2> |
lorevee | 0:ac0b0725c6fa | 33 | */ |
lorevee | 0:ac0b0725c6fa | 34 | |
lorevee | 0:ac0b0725c6fa | 35 | #ifndef __BLUENRG_DEVICE_H__ |
lorevee | 0:ac0b0725c6fa | 36 | #define __BLUENRG_DEVICE_H__ |
lorevee | 0:ac0b0725c6fa | 37 | |
lorevee | 0:ac0b0725c6fa | 38 | #define BLUENRG |
lorevee | 0:ac0b0725c6fa | 39 | #define DEBUG_BLUENRG_USER |
lorevee | 0:ac0b0725c6fa | 40 | |
lorevee | 0:ac0b0725c6fa | 41 | #include "btle.h" |
lorevee | 0:ac0b0725c6fa | 42 | |
lorevee | 0:ac0b0725c6fa | 43 | #ifdef YOTTA_CFG_MBED_OS |
lorevee | 0:ac0b0725c6fa | 44 | #include "mbed-drivers/mbed.h" |
lorevee | 0:ac0b0725c6fa | 45 | #else |
lorevee | 0:ac0b0725c6fa | 46 | #include "mbed.h" |
lorevee | 0:ac0b0725c6fa | 47 | #endif |
lorevee | 0:ac0b0725c6fa | 48 | #include "ble/blecommon.h" |
lorevee | 0:ac0b0725c6fa | 49 | #include "ble/BLEInstanceBase.h" |
lorevee | 0:ac0b0725c6fa | 50 | #include "ble/BLE.h" |
lorevee | 0:ac0b0725c6fa | 51 | #include "BlueNRGGap.h" |
lorevee | 0:ac0b0725c6fa | 52 | #include "BlueNRGGattServer.h" |
lorevee | 0:ac0b0725c6fa | 53 | #include "BlueNRGGattClient.h" |
lorevee | 0:ac0b0725c6fa | 54 | |
lorevee | 0:ac0b0725c6fa | 55 | |
lorevee | 0:ac0b0725c6fa | 56 | class BlueNRGDevice : public BLEInstanceBase |
lorevee | 0:ac0b0725c6fa | 57 | { |
lorevee | 0:ac0b0725c6fa | 58 | |
lorevee | 0:ac0b0725c6fa | 59 | public: |
lorevee | 0:ac0b0725c6fa | 60 | BlueNRGDevice(PinName mosi, PinName miso, PinName sck, PinName cs, PinName rst, PinName irq); |
lorevee | 0:ac0b0725c6fa | 61 | virtual ~BlueNRGDevice(void); |
lorevee | 0:ac0b0725c6fa | 62 | |
lorevee | 0:ac0b0725c6fa | 63 | virtual ble_error_t init(BLE::InstanceID_t instanceID, FunctionPointerWithContext<BLE::InitializationCompleteCallbackContext *> callback); |
lorevee | 0:ac0b0725c6fa | 64 | virtual ble_error_t shutdown(void); |
lorevee | 0:ac0b0725c6fa | 65 | virtual const char *getVersion(void); |
lorevee | 0:ac0b0725c6fa | 66 | virtual Gap& getGap(); |
lorevee | 0:ac0b0725c6fa | 67 | virtual const Gap& getGap() const; |
lorevee | 0:ac0b0725c6fa | 68 | virtual GattServer& getGattServer(); |
lorevee | 0:ac0b0725c6fa | 69 | virtual const GattServer& getGattServer() const; |
lorevee | 0:ac0b0725c6fa | 70 | virtual void waitForEvent(void); |
lorevee | 0:ac0b0725c6fa | 71 | |
lorevee | 0:ac0b0725c6fa | 72 | virtual GattClient& getGattClient() { |
lorevee | 0:ac0b0725c6fa | 73 | return BlueNRGGattClient::getInstance(); |
lorevee | 0:ac0b0725c6fa | 74 | } |
lorevee | 0:ac0b0725c6fa | 75 | |
lorevee | 0:ac0b0725c6fa | 76 | virtual SecurityManager& getSecurityManager() { |
lorevee | 0:ac0b0725c6fa | 77 | return *sm; |
lorevee | 0:ac0b0725c6fa | 78 | } |
lorevee | 0:ac0b0725c6fa | 79 | |
lorevee | 0:ac0b0725c6fa | 80 | virtual const SecurityManager& getSecurityManager() const { |
lorevee | 0:ac0b0725c6fa | 81 | return *sm; |
lorevee | 0:ac0b0725c6fa | 82 | } |
lorevee | 0:ac0b0725c6fa | 83 | void reset(void); |
lorevee | 0:ac0b0725c6fa | 84 | virtual bool hasInitialized(void) const { |
lorevee | 0:ac0b0725c6fa | 85 | return isInitialized; |
lorevee | 0:ac0b0725c6fa | 86 | } |
lorevee | 0:ac0b0725c6fa | 87 | |
lorevee | 0:ac0b0725c6fa | 88 | uint8_t getUpdaterHardwareVersion(uint8_t *hw_version); |
lorevee | 0:ac0b0725c6fa | 89 | int updateFirmware(const uint8_t *fw_image, uint32_t fw_size); |
lorevee | 0:ac0b0725c6fa | 90 | bool dataPresent(); |
lorevee | 0:ac0b0725c6fa | 91 | int32_t spiRead(uint8_t *buffer, uint8_t buff_size); |
lorevee | 0:ac0b0725c6fa | 92 | int32_t spiWrite(uint8_t* data1, uint8_t* data2, uint8_t Nb_bytes1, uint8_t Nb_bytes2); |
lorevee | 0:ac0b0725c6fa | 93 | void disable_irq(); |
lorevee | 0:ac0b0725c6fa | 94 | void enable_irq(); |
lorevee | 0:ac0b0725c6fa | 95 | |
lorevee | 0:ac0b0725c6fa | 96 | virtual void processEvents(); |
lorevee | 0:ac0b0725c6fa | 97 | |
lorevee | 0:ac0b0725c6fa | 98 | private: |
lorevee | 0:ac0b0725c6fa | 99 | bool isInitialized; |
lorevee | 0:ac0b0725c6fa | 100 | |
lorevee | 0:ac0b0725c6fa | 101 | SPI spi_; |
lorevee | 0:ac0b0725c6fa | 102 | DigitalOut nCS_; |
lorevee | 0:ac0b0725c6fa | 103 | DigitalOut rst_; |
lorevee | 0:ac0b0725c6fa | 104 | InterruptIn irq_; |
lorevee | 0:ac0b0725c6fa | 105 | |
lorevee | 0:ac0b0725c6fa | 106 | //FIXME: TBI (by now just placeholders to let build |
lorevee | 0:ac0b0725c6fa | 107 | /*** betzw: placeholders ***/ |
lorevee | 0:ac0b0725c6fa | 108 | SecurityManager *sm; |
lorevee | 0:ac0b0725c6fa | 109 | }; |
lorevee | 0:ac0b0725c6fa | 110 | |
lorevee | 0:ac0b0725c6fa | 111 | #endif |