X_NUCLEO_IDB05A1
Dependencies: mbed-os-example-ble-Advertising
Revision 278:a5209d8cfd61, committed 2016-09-15
- Comitter:
- Vincent Coubard
- Date:
- Thu Sep 15 10:51:43 2016 +0100
- Branch:
- 117ed4c55629877d7cb3d79c4bcb24e7da5bcab0
- Parent:
- 277:8da7a954664d
- Child:
- 279:30a6a8ad2623
- Commit message:
- Sync with 117ed4c55629877d7cb3d79c4bcb24e7da5bcab0
2016-07-26 10:10:57+01:00: Vincent Coubard
Fix include path for mbed classic.
Changed in this revision
--- a/source/BlueNRGDevice.cpp Thu Sep 15 10:51:41 2016 +0100
+++ b/source/BlueNRGDevice.cpp Thu Sep 15 10:51:43 2016 +0100
@@ -16,7 +16,7 @@
/**
******************************************************************************
- * @file BlueNRGDevice.cpp
+ * @file BlueNRGDevice.cpp
* @author STMicroelectronics
* @brief Implementation of BLEDeviceInstanceBase
******************************************************************************
@@ -30,14 +30,18 @@
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2>
- */
-
+ */
+
/** @defgroup BlueNRGDevice
* @brief BlueNRG BLE_API Device Adaptation
* @{
*/
-#include "mbed-drivers/mbed.h"
+#ifdef YOTTA_CFG_MBED_OS
+ #include "mbed-drivers/mbed.h"
+#else
+ #include "mbed.h"
+#endif
#include "BlueNRGDevice.h"
#include "BlueNRGGap.h"
#include "BlueNRGGattServer.h"
@@ -97,14 +101,14 @@
PinName sck,
PinName cs,
PinName rst,
- PinName irq) :
+ PinName irq) :
isInitialized(false), spi_(mosi, miso, sck), nCS_(cs), rst_(rst), irq_(irq)
{
// Setup the spi for 8 bit data, low clock polarity,
// 1-edge phase, with an 8MHz clock rate
spi_.format(8, 0);
spi_.frequency(8000000);
-
+
// Deselect the BlueNRG chip by keeping its nCS signal high
nCS_ = 1;
@@ -154,7 +158,7 @@
int BlueNRGDevice::updateFirmware(const uint8_t *fw_image, uint32_t fw_size)
{
int status = program_device(fw_image, fw_size);
-
+
return (status);
}
@@ -184,14 +188,14 @@
// Init the BlueNRG/BlueNRG-MS stack
btleInit();
-
+
isInitialized = true;
BLE::InitializationCompleteCallbackContext context = {
BLE::Instance(instanceID),
BLE_ERROR_NONE
};
callback.call(&context);
-
+
return BLE_ERROR_NONE;
}
@@ -218,9 +222,9 @@
}
/*!
- @brief Wait for any BLE Event like BLE Connection, Read Request etc.
+ @brief Wait for any BLE Event like BLE Connection, Read Request etc.
@param[in] void
- @returns char *
+ @returns char *
*/
void BlueNRGDevice::waitForEvent(void)
{
@@ -228,7 +232,7 @@
do {
bluenrgDeviceInstance.processEvents();
-
+
if(must_return) return;
__WFE(); /* it is recommended that SEVONPEND in the
@@ -237,8 +241,8 @@
that conrol is given back to main loop before next WFE */
} while(true);
-}
-
+}
+
/*!
@brief get GAP version
@brief Get the BLE stack version information
@@ -255,15 +259,15 @@
/*!
@brief get reference to GAP object
@param[in] void
- @returns Gap&
+ @returns Gap&
*/
/**************************************************************************/
-Gap &BlueNRGDevice::getGap()
+Gap &BlueNRGDevice::getGap()
{
return BlueNRGGap::getInstance();
}
-const Gap &BlueNRGDevice::getGap() const
+const Gap &BlueNRGDevice::getGap() const
{
return BlueNRGGap::getInstance();
}
@@ -272,10 +276,10 @@
/*!
@brief get reference to GATT server object
@param[in] void
- @returns GattServer&
+ @returns GattServer&
*/
/**************************************************************************/
-GattServer &BlueNRGDevice::getGattServer()
+GattServer &BlueNRGDevice::getGattServer()
{
return BlueNRGGattServer::getInstance();
}
@@ -284,7 +288,7 @@
{
return BlueNRGGattServer::getInstance();
}
-
+
/**************************************************************************/
/*!
@brief shut down the BLE device
@@ -325,7 +329,7 @@
return BLE_ERROR_NONE;
}
-
+
/**
* @brief Reads from BlueNRG SPI buffer and store data into local buffer.
* @param buffer : Buffer where data from SPI are stored
@@ -338,7 +342,7 @@
uint8_t len = 0;
uint8_t char_ff = 0xff;
volatile uint8_t read_char;
-
+
uint8_t i = 0;
volatile uint8_t tmpreg;
@@ -347,38 +351,38 @@
/* Select the chip */
nCS_ = 0;
-
- /* Read the header */
+
+ /* Read the header */
for (i = 0; i < 5; i++)
- {
+ {
tmpreg = spi_.write(header_master[i]);
header_slave[i] = (uint8_t)(tmpreg);
- }
-
+ }
+
if (header_slave[0] == 0x02) {
/* device is ready */
byte_count = (header_slave[4]<<8)|header_slave[3];
-
+
if (byte_count > 0) {
-
+
/* avoid to read more data that size of the buffer */
if (byte_count > buff_size){
byte_count = buff_size;
}
-
+
for (len = 0; len < byte_count; len++){
read_char = spi_.write(char_ff);
buffer[len] = read_char;
}
- }
+ }
}
/* Release CS line to deselect the chip */
nCS_ = 1;
-
+
// Add a small delay to give time to the BlueNRG to set the IRQ pin low
// to avoid a useless SPI read at the end of the transaction
for(volatile int i = 0; i < 2; i++)__NOP();
-
+
#ifdef PRINT_CSV_FORMAT
if (len > 0) {
print_csv_time();
@@ -388,8 +392,8 @@
PRINT_CSV("\n");
}
#endif
-
- return len;
+
+ return len;
}
/**
@@ -402,11 +406,11 @@
*/
int32_t BlueNRGDevice::spiWrite(uint8_t* data1,
uint8_t* data2, uint8_t Nb_bytes1, uint8_t Nb_bytes2)
-{
+{
int32_t result = 0;
uint32_t i;
volatile uint8_t tmpreg;
-
+
unsigned char header_master[HEADER_SIZE] = {0x0a, 0x00, 0x00, 0x00, 0x00};
unsigned char header_slave[HEADER_SIZE] = {0xaa, 0x00, 0x00, 0x00, 0x00};
@@ -415,24 +419,24 @@
/* CS reset */
nCS_ = 0;
- /* Exchange header */
+ /* Exchange header */
for (i = 0; i < 5; i++)
- {
+ {
tmpreg = spi_.write(header_master[i]);
header_slave[i] = tmpreg;
- }
-
+ }
+
if (header_slave[0] == 0x02) {
/* SPI is ready */
if (header_slave[1] >= (Nb_bytes1+Nb_bytes2)) {
-
+
/* Buffer is big enough */
for (i = 0; i < Nb_bytes1; i++) {
spi_.write(*(data1 + i));
}
for (i = 0; i < Nb_bytes2; i++) {
spi_.write(*(data2 + i));
- }
+ }
} else {
/* Buffer is too small */
result = -2;
@@ -441,13 +445,13 @@
/* SPI is not ready */
result = -1;
}
-
+
/* Release CS line */
//HAL_GPIO_WritePin(BNRG_SPI_CS_PORT, BNRG_SPI_CS_PIN, GPIO_PIN_SET);
nCS_ = 1;
-
+
enable_irq();
-
+
return result;
}
--- a/source/BlueNRGGap.cpp Thu Sep 15 10:51:41 2016 +0100 +++ b/source/BlueNRGGap.cpp Thu Sep 15 10:51:43 2016 +0100 @@ -39,7 +39,11 @@ */ #include "BlueNRGDevice.h" -#include "mbed-drivers/mbed.h" +#ifdef YOTTA_CFG_MBED_OS + #include "mbed-drivers/mbed.h" +#else + #include "mbed.h" +#endif #include "Payload.h" #include "Utils.h" #include "debug.h"
--- a/source/BlueNRGGattClient.cpp Thu Sep 15 10:51:41 2016 +0100 +++ b/source/BlueNRGGattClient.cpp Thu Sep 15 10:51:43 2016 +0100 @@ -37,7 +37,11 @@ */ #include "BlueNRGGattClient.h" -#include "mbed-drivers/mbed.h" +#ifdef YOTTA_CFG_MBED_OS + #include "mbed-drivers/mbed.h" +#else + #include "mbed.h" +#endif #include "BlueNRGGap.h" #include "Utils.h" #include "debug.h"
--- a/source/BlueNRGGattServer.cpp Thu Sep 15 10:51:41 2016 +0100 +++ b/source/BlueNRGGattServer.cpp Thu Sep 15 10:51:43 2016 +0100 @@ -37,7 +37,11 @@ */ #include "BlueNRGGattServer.h" -#include "mbed-drivers/mbed.h" +#ifdef YOTTA_CFG_MBED_OS + #include "mbed-drivers/mbed.h" +#else + #include "mbed.h" +#endif #include "BlueNRGGap.h" #include "Utils.h" #include "debug.h"
--- a/x-nucleo-idb0xa1/BlueNRGDevice.h Thu Sep 15 10:51:41 2016 +0100 +++ b/x-nucleo-idb0xa1/BlueNRGDevice.h Thu Sep 15 10:51:43 2016 +0100 @@ -40,7 +40,11 @@ #include "btle.h" -#include "mbed-drivers/mbed.h" +#ifdef YOTTA_CFG_MBED_OS + #include "mbed-drivers/mbed.h" +#else + #include "mbed.h" +#endif #include "ble/blecommon.h" #include "ble/BLEInstanceBase.h" #include "ble/BLE.h"
--- a/x-nucleo-idb0xa1/BlueNRGGap.h Thu Sep 15 10:51:41 2016 +0100 +++ b/x-nucleo-idb0xa1/BlueNRGGap.h Thu Sep 15 10:51:43 2016 +0100 @@ -35,7 +35,11 @@ #ifndef __BLUENRG_GAP_H__ #define __BLUENRG_GAP_H__ -#include "mbed-drivers/mbed.h" +#ifdef YOTTA_CFG_MBED_OS + #include "mbed-drivers/mbed.h" +#else + #include "mbed.h" +#endif #include "ble/blecommon.h" #include "btle.h" #include "ble/GapAdvertisingParams.h"
--- a/x-nucleo-idb0xa1/BlueNRGGattClient.h Thu Sep 15 10:51:41 2016 +0100 +++ b/x-nucleo-idb0xa1/BlueNRGGattClient.h Thu Sep 15 10:51:43 2016 +0100 @@ -34,7 +34,11 @@ #ifndef __BLUENRG_GATT_CLIENT_H__ #define __BLUENRG_GATT_CLIENT_H__ -#include "mbed-drivers/mbed.h" +#ifdef YOTTA_CFG_MBED_OS + #include "mbed-drivers/mbed.h" +#else + #include "mbed.h" +#endif #include "ble/blecommon.h" #include "btle.h" #include "ble/GattClient.h" @@ -178,5 +182,4 @@ }; -#endif /* __BLUENRG_GATT_CLIENT_H__ */ - +#endif /* __BLUENRG_GATT_CLIENT_H__ */ \ No newline at end of file
--- a/x-nucleo-idb0xa1/BlueNRGGattServer.h Thu Sep 15 10:51:41 2016 +0100 +++ b/x-nucleo-idb0xa1/BlueNRGGattServer.h Thu Sep 15 10:51:43 2016 +0100 @@ -34,7 +34,11 @@ #ifndef __BLUENRG_GATT_SERVER_H__ #define __BLUENRG_GATT_SERVER_H__ -#include "mbed-drivers/mbed.h" +#ifdef YOTTA_CFG_MBED_OS + #include "mbed-drivers/mbed.h" +#else + #include "mbed.h" +#endif #include "ble/blecommon.h" #include "btle.h" #include "ble/GattService.h"
--- a/x-nucleo-idb0xa1/utils/Payload.h Thu Sep 15 10:51:41 2016 +0100
+++ b/x-nucleo-idb0xa1/utils/Payload.h Thu Sep 15 10:51:43 2016 +0100
@@ -14,7 +14,11 @@
* limitations under the License.
*/
-#include "mbed-drivers/mbed.h"
+#ifdef YOTTA_CFG_MBED_OS
+ #include "mbed-drivers/mbed.h"
+#else
+ #include "mbed.h"
+#endif
#include "debug.h"
#ifndef __PAYLOAD_H__
@@ -188,4 +192,4 @@
}
};
-#endif // __PAYLOAD_H__
+#endif // __PAYLOAD_H__
\ No newline at end of file
--- a/x-nucleo-idb0xa1/utils/Utils.h Thu Sep 15 10:51:41 2016 +0100
+++ b/x-nucleo-idb0xa1/utils/Utils.h Thu Sep 15 10:51:43 2016 +0100
@@ -22,7 +22,11 @@
#include "ble_status.h"
#include "hal_types.h"
-#include "mbed-drivers/mbed.h"
+#ifdef YOTTA_CFG_MBED_OS
+ #include "mbed-drivers/mbed.h"
+#else
+ #include "mbed.h"
+#endif
#define STORE_LE_16(buf, val) ( ((buf)[0] = (uint8_t) (val) ) , \
((buf)[1] = (uint8_t) (val>>8) ) )
@@ -44,4 +48,4 @@
tBleStatus getHighPowerAndPALevelValue(int8_t dBMLevel, int8_t& EN_HIGH_POWER, int8_t& PA_LEVEL);
#endif // __UTIL_H__
-
+
\ No newline at end of file