Skip to content

Commit 6494bbd

Browse files
committed
snapshot
1 parent b08b026 commit 6494bbd

8 files changed

Lines changed: 131 additions & 128 deletions

File tree

devices/ble_hci/common-hal/_bleio/Adapter.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,12 @@ void common_hal_bleio_adapter_stop_advertising(bleio_adapter_obj_t *self) {
633633
self->now_advertising = false;
634634
self->extended_advertising = false;
635635
self->circuitpython_advertising = false;
636-
check_hci_error(hci_le_set_advertising_enable(BT_HCI_LE_ADV_DISABLE));
636+
int result = hci_le_set_advertising_enable(BT_HCI_LE_ADV_DISABLE);
637+
// OK if we're already stopped.
638+
if (result != BT_HCI_ERR_CMD_DISALLOWED) {
639+
check_hci_error(result);
640+
}
641+
637642
//TODO startup CircuitPython advertising again.
638643
}
639644

@@ -704,4 +709,6 @@ void bleio_adapter_background(bleio_adapter_obj_t* adapter) {
704709
adapter->advertising_timeout_msecs = 0;
705710
common_hal_bleio_adapter_stop_advertising(adapter);
706711
}
712+
713+
hci_poll_for_incoming_pkt();
707714
}

devices/ble_hci/common-hal/_bleio/Characteristic.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,10 @@ void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self,
9191
self->write_perm = write_perm;
9292
self->descriptor_list = NULL;
9393

94-
//FIX
95-
// const mp_int_t max_length_max = fixed_length ? BLE_GATTS_FIX_ATTR_LEN_MAX : BLE_GATTS_VAR_ATTR_LEN_MAX;
96-
// if (max_length < 0 || max_length > max_length_max) {
97-
// mp_raise_ValueError_varg(translate("max_length must be 0-%d when fixed_length is %s"),
98-
// max_length_max, fixed_length ? "True" : "False");
99-
// }
94+
const mp_int_t max_length_max = 512;
95+
if (max_length < 0 || max_length > max_length_max) {
96+
mp_raise_ValueError(translate("max_length must be <= 512"));
97+
}
10098
self->max_length = max_length;
10199
self->fixed_length = fixed_length;
102100

devices/ble_hci/common-hal/_bleio/UUID.c

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -36,55 +36,35 @@
3636
// If uuid128 is NULL, this is a Bluetooth SIG 16-bit UUID.
3737
// If uuid128 is not NULL, it's a 128-bit (16-byte) UUID, with bytes 12 and 13 zero'd out, where
3838
// the 16-bit part goes. Those 16 bits are passed in uuid16.
39-
void common_hal_bleio_uuid_construct(bleio_uuid_obj_t *self, uint32_t uuid16, const uint8_t uuid128[]) {
40-
//FIX self->nrf_ble_uuid.uuid = uuid16;
41-
// if (uuid128 == NULL) {
42-
// self->nrf_ble_uuid.type = BLE_UUID_TYPE_BLE;
43-
// } else {
44-
// ble_uuid128_t vs_uuid;
45-
// memcpy(vs_uuid.uuid128, uuid128, sizeof(vs_uuid.uuid128));
46-
47-
// // Register this vendor-specific UUID. Bytes 12 and 13 will be zero.
48-
// check_nrf_error(sd_ble_uuid_vs_add(&vs_uuid, &self->nrf_ble_uuid.type));
49-
// vm_used_ble = true;
50-
// }
39+
void common_hal_bleio_uuid_construct(bleio_uuid_obj_t *self, uint32_t uuid16, const uint8_t uuid128[16]) {
40+
self->size = uuid128 == NULL ? 16 : 128;
41+
self->uuid16 = uuid16;
42+
if (uuid128) {
43+
memcpy(self->uuid128, uuid128, 16);
44+
self->uuid128[12] = uuid16 & 0xff;
45+
self->uuid128[13] = uuid16 >> 8;
46+
} else {
47+
memset(self->uuid128, 0, 16);
48+
}
5149
}
5250

5351
uint32_t common_hal_bleio_uuid_get_size(bleio_uuid_obj_t *self) {
54-
//FIX return self->nrf_ble_uuid.type == BLE_UUID_TYPE_BLE ? 16 : 128;
55-
return 0;
52+
return self->size;
5653
}
5754

5855
uint32_t common_hal_bleio_uuid_get_uuid16(bleio_uuid_obj_t *self) {
59-
//FIX return self->nrf_ble_uuid.uuid;
60-
return 0;
56+
return self->uuid16;
6157
}
6258

6359
void common_hal_bleio_uuid_get_uuid128(bleio_uuid_obj_t *self, uint8_t uuid128[16]) {
64-
//FIX uint8_t length;
65-
//FIX check_nrf_error(sd_ble_uuid_encode(&self->nrf_ble_uuid, &length, uuid128));
60+
memcpy(uuid128, self->uuid128, 16);
6661
}
6762

6863
void common_hal_bleio_uuid_pack_into(bleio_uuid_obj_t *self, uint8_t* buf) {
69-
//FIX if (self->nrf_ble_uuid.type == BLE_UUID_TYPE_BLE) {
70-
// buf[0] = self->nrf_ble_uuid.uuid & 0xff;
71-
// buf[1] = self->nrf_ble_uuid.uuid >> 8;
72-
// } else {
73-
// common_hal_bleio_uuid_get_uuid128(self, buf);
74-
// }
64+
if (self->size == 16) {
65+
buf[0] = self->uuid16 & 0xff;
66+
buf[1] = self->uuid16 >> 8;
67+
} else {
68+
common_hal_bleio_uuid_get_uuid128(self, buf);
69+
}
7570
}
76-
77-
//FIX
78-
// void bleio_uuid_construct_from_nrf_ble_uuid(bleio_uuid_obj_t *self, ble_uuid_t *nrf_ble_uuid) {
79-
// if (nrf_ble_uuid->type == BLE_UUID_TYPE_UNKNOWN) {
80-
// mp_raise_bleio_BluetoothError(translate("Unexpected nrfx uuid type"));
81-
// }
82-
// self->nrf_ble_uuid.uuid = nrf_ble_uuid->uuid;
83-
// self->nrf_ble_uuid.type = nrf_ble_uuid->type;
84-
// }
85-
86-
// // Fill in a ble_uuid_t from my values.
87-
// void bleio_uuid_convert_to_nrf_ble_uuid(bleio_uuid_obj_t *self, ble_uuid_t *nrf_ble_uuid) {
88-
// nrf_ble_uuid->uuid = self->nrf_ble_uuid.uuid;
89-
// nrf_ble_uuid->type = self->nrf_ble_uuid.type;
90-
// }

devices/ble_hci/common-hal/_bleio/UUID.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,9 @@
3333

3434
typedef struct {
3535
mp_obj_base_t base;
36-
//FIX Use the native way of storing UUID's:
37-
// - ble_uuid_t.uuid is a 16-bit uuid.
38-
// - ble_uuid_t.type is BLE_UUID_TYPE_BLE if it's a 16-bit Bluetooth SIG UUID.
39-
// or is BLE_UUID_TYPE_VENDOR_BEGIN and higher, which indexes into a table of registered
40-
// 128-bit UUIDs.
41-
// ble_uuid_t nrf_ble_uuid;
36+
uint8_t size;
37+
uint16_t uuid16;
38+
uint8_t uuid128[16];
4239
} bleio_uuid_obj_t;
4340

44-
// void bleio_uuid_construct_from_nrf_ble_uuid(bleio_uuid_obj_t *self, ble_uuid_t *nrf_uuid);
45-
// void bleio_uuid_convert_to_nrf_ble_uuid(bleio_uuid_obj_t *self, ble_uuid_t *nrf_uuid);
46-
4741
#endif // MICROPY_INCLUDED_BLE_HCI_COMMON_HAL_UUID_H

0 commit comments

Comments
 (0)