Skip to content

Commit

Permalink
drv/bluetooth_stm32_cc2640: add GAP_UpdateLinkParamReq()
Browse files Browse the repository at this point in the history
This calls GAP_UpdateLinkParamReq() when a central connects to a
Pybricks hub. This is needed to make using a Handset work with Pybricks
while the hub is connected to a 2019 or newer MacBook.

Fixes: pybricks/support#397
  • Loading branch information
dlech committed Nov 17, 2021
1 parent b053d58 commit dcc9fa5
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/pbio/drv/bluetooth/bluetooth_stm32_cc2640.c
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,26 @@ static void handle_event(uint8_t *packet) {
// we currently only allow connection from one central
conn_handle = (data[11] << 8) | data[10];
DBG("link: %04x", conn_handle);

// On 2019 and newer MacBooks, the default interval was
// measured to be 15 ms. This caused advertisement to
// not be received by the local Bluetooth chip when
// scanning for devices. Calling the command below
// effectively sends the L2CAP Connection Parameter
// Update Request suggested by Apple[1] to reduce the
// interval to presumably make more room for receiving
// advertising data. There are a number of requirements
// in the Apple spec, such as the interval must be a
// multiple of 15 ms.
// [1]: https://developer.apple.com/accessories/Accessory-Design-Guidelines.pdf
gapUpdateLinkParamReq_t req = {
.connectionHandle = conn_handle,
.intervalMin = 24, // 24 * 1.25 ms = 30 ms
.intervalMax = 48, // 48 * 1.25 ms = 60 ms
.connLatency = 0,
.connTimeout = 500, // 500 * 10 ms = 5 s
};
GAP_UpdateLinkParamReq(&req);
} else if (data[12] == GAP_PROFILE_CENTRAL) {
// we currently only allow connection to one LEGO Powered Up remote peripheral
remote_handle = (data[11] << 8) | data[10];
Expand Down

0 comments on commit dcc9fa5

Please sign in to comment.