summaryrefslogtreecommitdiff
path: root/extmod/modbluetooth_nimble.c
diff options
context:
space:
mode:
authorJim Mussared <jim.mussared@gmail.com>2019-10-11 13:12:59 +1100
committerJim Mussared <jim.mussared@gmail.com>2019-10-11 13:51:07 +1100
commit76f474129e571f1de7a5e66298866675f9f2c8f1 (patch)
tree6d3177ede79782501b027dcc005e8b32e80c762c /extmod/modbluetooth_nimble.c
parentb65cc387cd0819ab97a4a8f7ebbc1f6345f65379 (diff)
extmod/modbluetooth: Use us instead of ms for advertising interval.
This is to more accurately match the BLE spec, where intervals are configured in units of channel hop time (625us). When it was specified in ms, not all "valid" intervals were able to be specified. Now that we're also allowing configuration of scan interval, this commit updates advertising to match.
Diffstat (limited to 'extmod/modbluetooth_nimble.c')
-rw-r--r--extmod/modbluetooth_nimble.c14
1 files changed, 4 insertions, 10 deletions
diff --git a/extmod/modbluetooth_nimble.c b/extmod/modbluetooth_nimble.c
index 727894f86..8805d4100 100644
--- a/extmod/modbluetooth_nimble.c
+++ b/extmod/modbluetooth_nimble.c
@@ -341,7 +341,7 @@ void mp_bluetooth_get_device_addr(uint8_t *addr) {
#endif
}
-int mp_bluetooth_gap_advertise_start(bool connectable, uint16_t interval_ms, const uint8_t *adv_data, size_t adv_data_len, const uint8_t *sr_data, size_t sr_data_len) {
+int mp_bluetooth_gap_advertise_start(bool connectable, int32_t interval_us, const uint8_t *adv_data, size_t adv_data_len, const uint8_t *sr_data, size_t sr_data_len) {
int ret;
mp_bluetooth_gap_advertise_stop();
@@ -360,18 +360,12 @@ int mp_bluetooth_gap_advertise_start(bool connectable, uint16_t interval_ms, con
}
}
- // Convert from 1ms to 0.625ms units.
- interval_ms = interval_ms * 8 / 5;
- if (interval_ms < 0x20 || interval_ms > 0x4000) {
- return MP_EINVAL;
- }
-
struct ble_gap_adv_params adv_params = {
.conn_mode = connectable ? BLE_GAP_CONN_MODE_UND : BLE_GAP_CONN_MODE_NON,
.disc_mode = BLE_GAP_DISC_MODE_GEN,
- .itvl_min = interval_ms,
- .itvl_max = interval_ms,
- .channel_map = 7, // all 3 channels
+ .itvl_min = interval_us / BLE_HCI_ADV_ITVL, // convert to 625us units.
+ .itvl_max = interval_us / BLE_HCI_ADV_ITVL,
+ .channel_map = 7, // all 3 channels.
};
ret = ble_gap_adv_start(BLE_OWN_ADDR_PUBLIC, NULL, BLE_HS_FOREVER, &adv_params, gap_event_cb, NULL);