Skip to content

BLE streamlining #13365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion .astyleignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
^BUILD
^cmsis
^connectivity/drivers/ble
^connectivity/FEATURE_BLE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this PR - no need to fix it here:
We'd better only ignore external components (e.g. Cordio) while keeping checks on our code. If any styles don't match, the CI generates a diff we can apply without manual fixes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the old check was for features/FEATURE_BLE so I figured I'd better move it as is since I don't want to get bogged down with astyle right now, we can fix this in a later PR

Copy link
Contributor

@LDong-Arm LDong-Arm Aug 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
^connectivity/FEATURE_BLE
^connectivity/FEATURE_BLE/libraries/TARGET_CORDIO/stack
^connectivity/FEATURE_BLE/libraries/TARGET_CORDIO_LL/stack

This is what I mean - external code only. See my discussion with Paul earlier. @adbridge

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or can we do another PR to fix this, since this one is already pretty big?

^connectivity/libraries/mbed-coap
^connectivity/libraries/ppp
^features/cryptocell
^features/FEATURE_BLE
^features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_MBED_PSA_SRV
^features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM
^features/frameworks
Expand Down
18 changes: 9 additions & 9 deletions components/BLE/COMPONENT_BlueNRG_MS/BlueNrgMsHCIDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "platform/mbed_wait_api.h"

// FEATURE_BLE/targets/TARGET_CORDIO
#include "CordioBLE.h"
#include "BLEInstanceBase.h"
#include "CordioHCIDriver.h"
#include "CordioHCITransportDriver.h"
#include "hci_api.h"
Expand Down Expand Up @@ -64,17 +64,17 @@ namespace bluenrg_ms {

/**
* BlueNRG_MS HCI driver implementation.
* @see cordio::CordioHCIDriver
* @see CordioHCIDriver
*/
class HCIDriver : public cordio::CordioHCIDriver {
class HCIDriver : public CordioHCIDriver {
public:
/**
* Construction of the BlueNRG_MS HCIDriver.
* @param transport: Transport of the HCI commands.
* @param rst: Name of the reset pin
*/
HCIDriver(cordio::CordioHCITransportDriver &transport_driver, PinName rst) :
cordio::CordioHCIDriver(transport_driver), rst(rst) { }
HCIDriver(CordioHCITransportDriver &transport_driver, PinName rst) :
CordioHCIDriver(transport_driver), rst(rst) { }

/**
* @see CordioHCIDriver::do_initialize
Expand All @@ -87,10 +87,10 @@ class HCIDriver : public cordio::CordioHCIDriver {
/**
* @see CordioHCIDriver::get_buffer_pool_description
*/
ble::vendor::cordio::buf_pool_desc_t get_buffer_pool_description()
ble::buf_pool_desc_t get_buffer_pool_description()
{
// Use default buffer pool
return ble::vendor::cordio::CordioHCIDriver::get_default_buffer_pool_description();
return ble::CordioHCIDriver::get_default_buffer_pool_description();
}

/**
Expand Down Expand Up @@ -435,7 +435,7 @@ class HCIDriver : public cordio::CordioHCIDriver {
* event from the stack. This might not be the best solution for all BLE chip;
* especially this one.
*/
class TransportDriver : public cordio::CordioHCITransportDriver {
class TransportDriver : public CordioHCITransportDriver {
public:
/**
* Construct the transport driver required by a BlueNRG_MS module.
Expand Down Expand Up @@ -607,7 +607,7 @@ class TransportDriver : public cordio::CordioHCITransportDriver {
/**
* Cordio HCI driver factory
*/
ble::vendor::cordio::CordioHCIDriver &ble_cordio_get_hci_driver()
ble::CordioHCIDriver &ble_cordio_get_hci_driver()
{
static ble::vendor::bluenrg_ms::TransportDriver transport_driver(
MBED_CONF_BLUENRG_MS_SPI_MOSI,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
* Copyright (c) 2006-2020 ARM Limited
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,27 +19,23 @@
#ifndef MBED_BLE_H__
#define MBED_BLE_H__

#include "BLERoles.h"
#include "FunctionPointerWithContext.h"
#include "platform/mbed_error.h"
#include "platform/mbed_assert.h"
#include "platform/mbed_toolchain.h"

#include "ble/common/ble/BLERoles.h"
#include "ble/common/ble/BLETypes.h"
#include "ble/common/ble/blecommon.h"

#include "blecommon.h"
#include "ble/Gap.h"
#include "ble/GattServer.h"
#include "ble/GattClient.h"
#include "ble/GattServer.h"
#include "ble/SecurityManager.h"

#include "ble/FunctionPointerWithContext.h"

#ifdef YOTTA_CFG_MBED_OS
#include "mbed-drivers/mbed_error.h"
#else

#include "platform/mbed_error.h"

#endif

#include "platform/mbed_toolchain.h"

/* Forward declaration for the implementation class */

namespace ble {
class BLEInstanceBase;

/**
Expand Down Expand Up @@ -140,25 +138,41 @@ class BLE {
public:
/**
* Opaque type used to store the ID of a BLE instance.
* @deprecated BLE singleton supports one instance. You may create multiple instances by using the constructor.
*/
typedef unsigned InstanceID_t;

/**
* The value of the BLE::InstanceID_t for the default BLE instance.
* @deprecated BLE singleton supports one instance. You may create multiple instances by using the constructor.
*/
static const InstanceID_t DEFAULT_INSTANCE = 0;

#ifndef YOTTA_CFG_BLE_INSTANCES_COUNT
/**
* The number of permitted BLE instances for the application.
* @deprecated BLE singleton supports one instance. You may create multiple instances by using the constructor.
*/
static const InstanceID_t NUM_INSTANCES = 1;
#else

/**
* The number of permitted BLE instances for the application.
* Get a reference to the BLE singleton.
*
* @note Calling Instance() is preferred over constructing a BLE object
* directly because it returns a reference to singleton.
*
* @return A reference to a single object.
*/
static const InstanceID_t NUM_INSTANCES = YOTTA_CFG_BLE_INSTANCES_COUNT;
#endif
static BLE &Instance();

/**
* Constructor for a handle to a BLE instance (the BLE stack). BLE handles
* are thin wrappers around a transport object (that is, ptr. to
* ble::BLEInstanceBase).
*
* @param[in] transport Ble transport used for the BLE instance.
* @note Cordio supports only one instance.
*/
BLE(ble::BLEInstanceBase &transport);

/**
* Get a reference to the BLE singleton corresponding to a given interface.
Expand All @@ -173,17 +187,25 @@ class BLE {
* @return A reference to a single object.
*
* @pre id shall be less than NUM_INSTANCES.
*
*/
static BLE &Instance(InstanceID_t id = DEFAULT_INSTANCE);
MBED_DEPRECATED_SINCE("mbed-os-6.3.0", "BLE singleton supports one instance. You may create multiple"
"instances by using the constructor. Please use BLE::Instance().")
static BLE &Instance(InstanceID_t id)
{
return Instance();
}

/**
* Fetch the ID of a BLE instance.
*
* @return Instance id of this BLE instance.
*/
MBED_DEPRECATED_SINCE("mbed-os-6.3.0", "BLE singleton supports one instance. You may create multiple"
"instances by using the constructor.")
InstanceID_t getInstanceID(void) const
{
return instanceID;
return DEFAULT_INSTANCE;
}

/**
Expand Down Expand Up @@ -348,14 +370,14 @@ class BLE {
*
* @return A reference to a Gap object associated to this BLE instance.
*/
Gap &gap();
ble::Gap &gap();

/**
* A const alternative to gap().
*
* @return A const reference to a Gap object associated to this BLE instance.
*/
const Gap &gap() const;
const ble::Gap &gap() const;

#if BLE_FEATURE_GATT_SERVER
/**
Expand All @@ -364,15 +386,15 @@ class BLE {
*
* @return A reference to a GattServer object associated to this BLE instance.
*/
GattServer &gattServer();
ble::GattServer &gattServer();

/**
* A const alternative to gattServer().
*
* @return A const reference to a GattServer object associated to this BLE
* instance.
*/
const GattServer &gattServer() const;
const ble::GattServer &gattServer() const;
#endif // BLE_FEATURE_GATT_SERVER

#if BLE_FEATURE_GATT_CLIENT
Expand All @@ -382,15 +404,15 @@ class BLE {
*
* @return A reference to a GattClient object associated to this BLE instance.
*/
GattClient &gattClient();
ble::GattClient &gattClient();

/**
* A const alternative to gattClient().
*
* @return A const reference to a GattClient object associated to this BLE
* instance.
*/
const GattClient &gattClient() const;
const ble::GattClient &gattClient() const;
#endif // BLE_FEATURE_GATT_CLIENT

#if BLE_FEATURE_SECURITY
Expand All @@ -401,15 +423,15 @@ class BLE {
* @return A reference to a SecurityManager object associated to this BLE
* instance.
*/
SecurityManager &securityManager();
ble::SecurityManager &securityManager();

/**
* A const alternative to securityManager().
*
* @return A const reference to a SecurityManager object associated to this
* BLE instance.
*/
const SecurityManager &securityManager() const;
const ble::SecurityManager &securityManager() const;
#endif // BLE_FEATURE_SECURITY

/**
Expand All @@ -421,18 +443,6 @@ class BLE {
*/
static const char *errorToString(ble_error_t error);

private:
friend class BLEInstanceBase;

/**
* Constructor for a handle to a BLE instance (the BLE stack). BLE handles
* are thin wrappers around a transport object (that is, ptr. to
* BLEInstanceBase).
*
* @param[in] instanceID BLE Instance ID to get.
*/
BLE(InstanceID_t instanceID = DEFAULT_INSTANCE);

/**
* This function allows the BLE stack to signal that there is work to do and
* event processing should be done (BLE::processEvent()).
Expand All @@ -442,6 +452,9 @@ class BLE {
*/
void signalEventsToProcess();

private:
friend class ble::BLEInstanceBase;

/**
* Implementation of init() [internal to BLE_API].
*
Expand All @@ -455,16 +468,17 @@ class BLE {
private:
// Prevent copy construction and copy assignment of BLE.
BLE(const BLE &);

BLE &operator=(const BLE &);

private:
InstanceID_t instanceID;
BLEInstanceBase *transport; /* The device-specific backend */
ble::BLEInstanceBase &transport; /* The device-specific backend */
OnEventsToProcessCallback_t whenEventsToProcess;
bool event_signaled;
};

}

using ble::BLE;
/**
* @namespace ble Entry namespace for all %BLE API definitions.
*/
Expand Down
Loading