Skip to content

Commit 0323d91

Browse files
committed
BLE - Devirtualization of the Maxim port .
1 parent 536443b commit 0323d91

File tree

8 files changed

+188
-59
lines changed

8 files changed

+188
-59
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2019 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "ble/GattServer.h"
18+
#include "source/GattServer.tpp"
19+
#include "MaximGattServer.h"
20+
21+
#include "ble/GattClient.h"
22+
#include "source/GattClient.tpp"
23+
#include "MaximGattClient.h"
24+
25+
#include "ble/gap/Gap.h"
26+
#include "ble/Gap.h"
27+
#include "source/gap/Gap.tpp"
28+
#include "source/LegacyGap.tpp"
29+
#include "MaximGap.h"
30+
31+
#include "ble/SecurityManager.h"
32+
#include "source/SecurityManager.tpp"
33+
#include "MaximSecurityManager.h"
34+
35+
template class ble::interface::GattServer<MaximGattServer>;
36+
37+
template class ble::interface::GattClient<MaximGattClient>;
38+
39+
template class ble::interface::LegacyGap<MaximGap>;
40+
template class ble::interface::Gap<MaximGap>;
41+
42+
template class ble::interface::SecurityManager<MaximSecurityManager>;
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2019 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef BLE_IMPLEMENTATION_FORWARD_H_
18+
#define BLE_IMPLEMENTATION_FORWARD_H_
19+
20+
////////////////////////////////////////////////////////////////////////////////
21+
// Forward declarations of the implementation types
22+
//
23+
namespace ble {
24+
25+
namespace interface {
26+
27+
template<class Impl>
28+
class LegacyGap;
29+
30+
template<class Impl>
31+
class Gap;
32+
33+
template<class Impl>
34+
class GattClient;
35+
36+
template<class Impl>
37+
class SecurityManager;
38+
39+
template<class Impl>
40+
class GattServer;
41+
42+
} // namespace interface
43+
} // ble
44+
45+
class MaximGap;
46+
class MaximGattClient;
47+
class MaximGattServer;
48+
class MaximSecurityManager;
49+
50+
// implementation assembly
51+
namespace ble {
52+
namespace impl {
53+
// SECURITY MANAGER
54+
typedef interface::SecurityManager<MaximSecurityManager> SecurityManager;
55+
56+
// GAP
57+
typedef interface::LegacyGap<MaximGap> LegacyGap;
58+
59+
typedef interface::Gap<MaximGap> Gap;
60+
61+
// GATT CLIENT
62+
typedef interface::GattClient<MaximGattClient> GattClient;
63+
64+
// GATT SERVER
65+
typedef ble::interface::GattServer<MaximGattServer> GattServer;
66+
} // impl
67+
} // ble
68+
69+
70+
#endif //BLE_IMPLEMENTATION_FORWARD_H_

features/FEATURE_BLE/targets/TARGET_Maxim/MaximGap.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ MaximGap &MaximGap::getInstance() {
4040
return m_instance;
4141
}
4242

43-
ble_error_t MaximGap::setAdvertisingData(const GapAdvertisingData &advData, const GapAdvertisingData &scanResponse)
43+
ble_error_t MaximGap::setAdvertisingData_(const GapAdvertisingData &advData, const GapAdvertisingData &scanResponse)
4444
{
4545
/* Make sure we don't exceed the advertising payload length */
4646
if (advData.getPayloadLen() > GAP_ADVERTISING_DATA_MAX_PAYLOAD) {
@@ -61,7 +61,7 @@ ble_error_t MaximGap::setAdvertisingData(const GapAdvertisingData &advData, cons
6161
return BLE_ERROR_NONE;
6262
}
6363

64-
ble_error_t MaximGap::startAdvertising(const GapAdvertisingParams &params)
64+
ble_error_t MaximGap::startAdvertising_(const GapAdvertisingParams &params)
6565
{
6666
/* Make sure we support the advertising type */
6767
if (params.getAdvertisingType() == GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED) {
@@ -108,7 +108,7 @@ ble_error_t MaximGap::startAdvertising(const GapAdvertisingParams &params)
108108
return BLE_ERROR_NONE;
109109
}
110110

111-
ble_error_t MaximGap::stopAdvertising(void)
111+
ble_error_t MaximGap::stopAdvertising_(void)
112112
{
113113
DmAdvStop();
114114

@@ -123,11 +123,11 @@ void MaximGap::advertisingStopped(void)
123123
* be '0.' Otherwise, advertising must have stopped due to a timeout
124124
*/
125125
if (state.advertising) {
126-
processTimeoutEvent(Gap::TIMEOUT_SRC_ADVERTISING);
126+
processTimeoutEvent(TIMEOUT_SRC_ADVERTISING);
127127
}
128128
}
129129

130-
ble_error_t MaximGap::disconnect(DisconnectionReason_t reason)
130+
ble_error_t MaximGap::disconnect_(DisconnectionReason_t reason)
131131
{
132132
DmConnClose(DM_CLIENT_ID_APP, m_connectionHandle, reason);
133133

@@ -137,7 +137,7 @@ ble_error_t MaximGap::disconnect(DisconnectionReason_t reason)
137137
return BLE_ERROR_NONE;
138138
}
139139

140-
ble_error_t MaximGap::disconnect(Handle_t connectionHandle, DisconnectionReason_t reason)
140+
ble_error_t MaximGap::disconnect_(Handle_t connectionHandle, DisconnectionReason_t reason)
141141
{
142142
DmConnClose(DM_CLIENT_ID_APP, connectionHandle, reason);
143143

@@ -147,17 +147,17 @@ ble_error_t MaximGap::disconnect(Handle_t connectionHandle, DisconnectionReason_
147147
return BLE_ERROR_NONE;
148148
}
149149

150-
ble_error_t MaximGap::getPreferredConnectionParams(ConnectionParams_t *params)
150+
ble_error_t MaximGap::getPreferredConnectionParams_(ConnectionParams_t *params)
151151
{
152152
return BLE_ERROR_NOT_IMPLEMENTED;
153153
}
154154

155-
ble_error_t MaximGap::setPreferredConnectionParams(const ConnectionParams_t *params)
155+
ble_error_t MaximGap::setPreferredConnectionParams_(const ConnectionParams_t *params)
156156
{
157157
return BLE_ERROR_NOT_IMPLEMENTED;
158158
}
159159

160-
ble_error_t MaximGap::updateConnectionParams(Handle_t handle, const ConnectionParams_t *newParams)
160+
ble_error_t MaximGap::updateConnectionParams_(Handle_t handle, const ConnectionParams_t *newParams)
161161
{
162162
if (DmConnCheckIdle(handle) != 0) {
163163
return BLE_STACK_BUSY;
@@ -173,7 +173,7 @@ ble_error_t MaximGap::updateConnectionParams(Handle_t handle, const ConnectionPa
173173
return BLE_ERROR_NONE;
174174
}
175175

176-
ble_error_t MaximGap::startRadioScan(const GapScanningParams &scanningParams)
176+
ble_error_t MaximGap::startRadioScan_(const GapScanningParams &scanningParams)
177177
{
178178
DmScanSetInterval(scanningParams.getInterval(), scanningParams.getWindow());
179179

@@ -189,7 +189,7 @@ ble_error_t MaximGap::startRadioScan(const GapScanningParams &scanningParams)
189189
return BLE_ERROR_NONE;
190190
}
191191

192-
ble_error_t MaximGap::stopScan(void)
192+
ble_error_t MaximGap::stopScan_(void)
193193
{
194194
DmScanStop();
195195
return BLE_ERROR_NONE;
@@ -205,7 +205,7 @@ uint16_t MaximGap::getConnectionHandle(void)
205205
return m_connectionHandle;
206206
}
207207

208-
ble_error_t MaximGap::setAddress(AddressType_t type, const Address_t address)
208+
ble_error_t MaximGap::setAddress_(AddressType_t type, const Address_t address)
209209
{
210210
if ((type != BLEProtocol::AddressType::PUBLIC) && (type != BLEProtocol::AddressType::RANDOM_STATIC)) {
211211
return BLE_ERROR_PARAM_OUT_OF_RANGE;
@@ -217,40 +217,40 @@ ble_error_t MaximGap::setAddress(AddressType_t type, const Address_t address)
217217
return BLE_ERROR_NONE;
218218
}
219219

220-
ble_error_t MaximGap::getAddress(AddressType_t *typeP, Address_t address)
220+
ble_error_t MaximGap::getAddress_(AddressType_t *typeP, Address_t address)
221221
{
222222
*typeP = m_type;
223223
BdaCpy(address, HciGetBdAddr());
224224
return BLE_ERROR_NONE;
225225
}
226226

227-
ble_error_t MaximGap::setDeviceName(const uint8_t *deviceName)
227+
ble_error_t MaximGap::setDeviceName_(const uint8_t *deviceName)
228228
{
229229
return BLE_ERROR_NOT_IMPLEMENTED;
230230
}
231231

232-
ble_error_t MaximGap::getDeviceName(uint8_t *deviceName, unsigned *lengthP)
232+
ble_error_t MaximGap::getDeviceName_(uint8_t *deviceName, unsigned *lengthP)
233233
{
234234
return BLE_ERROR_NOT_IMPLEMENTED;
235235
}
236236

237-
ble_error_t MaximGap::setAppearance(GapAdvertisingData::Appearance appearance)
237+
ble_error_t MaximGap::setAppearance_(GapAdvertisingData::Appearance appearance)
238238
{
239239
return BLE_ERROR_NOT_IMPLEMENTED;
240240
}
241241

242-
ble_error_t MaximGap::getAppearance(GapAdvertisingData::Appearance *appearanceP)
242+
ble_error_t MaximGap::getAppearance_(GapAdvertisingData::Appearance *appearanceP)
243243
{
244244
return BLE_ERROR_NOT_IMPLEMENTED;
245245
}
246246

247-
ble_error_t MaximGap::setTxPower(int8_t txPower)
247+
ble_error_t MaximGap::setTxPower_(int8_t txPower)
248248
{
249249
HciVsSetTxPower(txPower);
250250
return BLE_ERROR_NONE;
251251
}
252252

253-
void MaximGap::getPermittedTxPowerValues(const int8_t **valueArrayPP, size_t *countP)
253+
void MaximGap::getPermittedTxPowerValues_(const int8_t **valueArrayPP, size_t *countP)
254254
{
255255
static const int8_t permittedTxValues[] = {
256256
-18, -15, -12, -9, -6, -3, 0, 3

features/FEATURE_BLE/targets/TARGET_Maxim/MaximGap.h

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,49 +49,66 @@
4949
5050
*/
5151
/**************************************************************************/
52-
class MaximGap : public Gap
52+
class MaximGap : public ble::interface::LegacyGap<MaximGap>
5353
{
5454
public:
5555
static MaximGap &getInstance();
5656

5757
/* Functions that must be implemented from Gap */
58-
virtual ble_error_t setAddress(AddressType_t type, const Address_t address);
59-
virtual ble_error_t getAddress(AddressType_t *typeP, Address_t address);
60-
virtual ble_error_t setAdvertisingData(const GapAdvertisingData &, const GapAdvertisingData &);
58+
ble_error_t setAddress_(AddressType_t type, const Address_t address);
59+
ble_error_t getAddress_(AddressType_t *typeP, Address_t address);
60+
ble_error_t setAdvertisingData_(const GapAdvertisingData &, const GapAdvertisingData &);
6161

6262
#define BLE_GAP_ADV_INTERVAL_MIN 0x0020 /**< Minimum Advertising interval in 625 us units, i.e. 20 ms. */
6363
#define BLE_GAP_ADV_NONCON_INTERVAL_MIN 0x00A0 /**< Minimum Advertising interval in 625 us units for non connectable mode, i.e. 100 ms. */
6464
#define BLE_GAP_ADV_INTERVAL_MAX 0x4000 /**< Maximum Advertising interval in 625 us units, i.e. 10.24 s. */
6565

66-
virtual uint16_t getMinAdvertisingInterval(void) const { return BLE_GAP_ADV_INTERVAL_MIN; }
67-
virtual uint16_t getMinNonConnectableAdvertisingInterval(void) const { return BLE_GAP_ADV_NONCON_INTERVAL_MIN; }
68-
virtual uint16_t getMaxAdvertisingInterval(void) const { return BLE_GAP_ADV_INTERVAL_MAX; }
66+
uint16_t getMinAdvertisingInterval_(void) const { return BLE_GAP_ADV_INTERVAL_MIN; }
67+
uint16_t getMinNonConnectableAdvertisingInterval_(void) const { return BLE_GAP_ADV_NONCON_INTERVAL_MIN; }
68+
uint16_t getMaxAdvertisingInterval_(void) const { return BLE_GAP_ADV_INTERVAL_MAX; }
6969

70-
virtual ble_error_t startAdvertising(const GapAdvertisingParams &);
71-
virtual ble_error_t stopAdvertising(void);
72-
virtual ble_error_t disconnect(Handle_t connectionHandle, DisconnectionReason_t reason);
73-
virtual ble_error_t disconnect(DisconnectionReason_t reason);
70+
ble_error_t startAdvertising_(const GapAdvertisingParams &);
71+
ble_error_t stopAdvertising_(void);
72+
ble_error_t disconnect_(Handle_t connectionHandle, DisconnectionReason_t reason);
73+
ble_error_t disconnect_(DisconnectionReason_t reason);
7474

75-
virtual ble_error_t setDeviceName(const uint8_t *deviceName);
76-
virtual ble_error_t getDeviceName(uint8_t *deviceName, unsigned *lengthP);
77-
virtual ble_error_t setAppearance(GapAdvertisingData::Appearance appearance);
78-
virtual ble_error_t getAppearance(GapAdvertisingData::Appearance *appearanceP);
75+
ble_error_t setDeviceName_(const uint8_t *deviceName);
76+
ble_error_t getDeviceName_(uint8_t *deviceName, unsigned *lengthP);
77+
ble_error_t setAppearance_(GapAdvertisingData::Appearance appearance);
78+
ble_error_t getAppearance_(GapAdvertisingData::Appearance *appearanceP);
7979

80-
virtual ble_error_t setTxPower(int8_t txPower);
81-
virtual void getPermittedTxPowerValues(const int8_t **valueArrayPP, size_t *countP);
80+
ble_error_t setTxPower_(int8_t txPower);
81+
void getPermittedTxPowerValues_(const int8_t **valueArrayPP, size_t *countP);
8282

8383
void setConnectionHandle(uint16_t m_connectionHandle);
8484
uint16_t getConnectionHandle(void);
8585

86-
virtual ble_error_t getPreferredConnectionParams(ConnectionParams_t *params);
87-
virtual ble_error_t setPreferredConnectionParams(const ConnectionParams_t *params);
88-
virtual ble_error_t updateConnectionParams(Handle_t handle, const ConnectionParams_t *params);
86+
ble_error_t getPreferredConnectionParams_(ConnectionParams_t *params);
87+
ble_error_t setPreferredConnectionParams_(const ConnectionParams_t *params);
88+
ble_error_t updateConnectionParams_(Handle_t handle, const ConnectionParams_t *params);
8989

90-
virtual ble_error_t startRadioScan(const GapScanningParams &scanningParams);
91-
virtual ble_error_t stopScan(void);
90+
ble_error_t startRadioScan_(const GapScanningParams &scanningParams);
91+
ble_error_t stopScan_(void);
9292

9393
void advertisingStopped(void);
9494

95+
protected:
96+
// import from Gap
97+
friend ble::interface::Gap<MaximGap>;
98+
99+
using ble::interface::Gap<MaximGap>::startAdvertising_;
100+
using ble::interface::Gap<MaximGap>::stopAdvertising_;
101+
using ble::interface::Gap<MaximGap>::connect_;
102+
using ble::interface::Gap<MaximGap>::disconnect_;
103+
104+
// import from LegacyGap
105+
friend ble::interface::LegacyGap<MaximGap>;
106+
107+
using ble::interface::LegacyGap<MaximGap>::startAdvertising_;
108+
using ble::interface::LegacyGap<MaximGap>::stopAdvertising_;
109+
using ble::interface::LegacyGap<MaximGap>::connect_;
110+
using ble::interface::LegacyGap<MaximGap>::disconnect_;
111+
95112
private:
96113
uint16_t m_connectionHandle;
97114
addr_type_t m_type;

features/FEATURE_BLE/targets/TARGET_Maxim/MaximGattClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
#include "ble/GattClient.h"
4040

41-
class MaximGattClient : public GattClient
41+
class MaximGattClient : public ble::interface::GattClient<MaximGattClient>
4242
{
4343
public:
4444
static MaximGattClient &getInstance() {

0 commit comments

Comments
 (0)