Skip to content

Commit fd2a3d3

Browse files
committed
drv/bluetooth_stm32_cc2640: use actual adv tx power
This reads the advertisement tx power from the bluetooth chip instead of hard-coding it. The hard-coded value was correct, so the value doesn't actually change.
1 parent 5046a36 commit fd2a3d3

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

lib/ble5stack/central/hci.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@ HCI_StatusCodes_t HCI_readLocalVersionInfo(void)
1010
{
1111
return HCI_sendHCICommand(HCI_READ_LOCAL_VERSION_INFO, NULL, 0);
1212
}
13+
14+
HCI_StatusCodes_t HCI_LE_readAdvertisingChannelTxPower(void)
15+
{
16+
return HCI_sendHCICommand(HCI_LE_READ_ADVERTISING_CHANNEL_TX_POWER, NULL, 0);
17+
}

lib/ble5stack/central/hci.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55

66
HCI_StatusCodes_t HCI_readBdaddr(void);
77
HCI_StatusCodes_t HCI_readLocalVersionInfo(void);
8+
HCI_StatusCodes_t HCI_LE_readAdvertisingChannelTxPower(void);
89

910
#endif // HCI_H

lib/ble5stack/central/hci_tl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@
9696
// Status Parameters
9797
#define HCI_READ_RSSI 0x1405 //!< opcode of @ref HCI_ReadRssiCmd
9898

99+
// Low energy commands
100+
#define HCI_LE_READ_ADVERTISING_CHANNEL_TX_POWER 0x2007 //!< opcode of @ref HCI_LE_readAdvertisingChannelTxPower
101+
99102
/* HCI Status return types */
100103
typedef enum
101104
{

lib/pbio/drv/bluetooth/bluetooth_stm32_cc2640.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,18 @@ static PT_THREAD(set_discoverable(struct pt *pt, pbio_task_t *task)) {
270270

271271
PT_BEGIN(pt);
272272

273+
static int8_t tx_power;
274+
PT_WAIT_WHILE(pt, write_xfer_size);
275+
HCI_LE_readAdvertisingChannelTxPower();
276+
PT_WAIT_UNTIL(pt, hci_command_complete);
277+
278+
{
279+
HCI_StatusCodes_t status = read_buf[9];
280+
if (status == bleSUCCESS) {
281+
tx_power = read_buf[10];
282+
}
283+
}
284+
273285
// Set advertising data
274286

275287
PT_WAIT_WHILE(pt, write_xfer_size);
@@ -281,7 +293,7 @@ static PT_THREAD(set_discoverable(struct pt *pt, pbio_task_t *task)) {
281293
pbio_uuid128_reverse_copy(&data[5], pbio_pybricks_service_uuid);
282294
data[21] = 2; // length
283295
data[22] = GAP_ADTYPE_POWER_LEVEL;
284-
data[23] = 0;
296+
data[23] = tx_power;
285297
GAP_updateAdvertistigData(GAP_AD_TYPE_ADVERTISEMNT_DATA, 24, data);
286298
PT_WAIT_UNTIL(pt, hci_command_complete);
287299
// ignoring response data

0 commit comments

Comments
 (0)