summaryrefslogtreecommitdiff
path: root/extmod/modbluetooth_nimble.c
diff options
context:
space:
mode:
Diffstat (limited to 'extmod/modbluetooth_nimble.c')
-rw-r--r--extmod/modbluetooth_nimble.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/extmod/modbluetooth_nimble.c b/extmod/modbluetooth_nimble.c
index 131b73574..c09f1cd2d 100644
--- a/extmod/modbluetooth_nimble.c
+++ b/extmod/modbluetooth_nimble.c
@@ -87,21 +87,22 @@ STATIC int ble_hs_err_to_errno(int err) {
}
}
+// Note: modbluetooth UUIDs store their data in LE.
STATIC ble_uuid_t* create_nimble_uuid(const mp_obj_bluetooth_uuid_t *uuid) {
if (uuid->type == MP_BLUETOOTH_UUID_TYPE_16) {
ble_uuid16_t *result = m_new(ble_uuid16_t, 1);
result->u.type = BLE_UUID_TYPE_16;
- result->value = uuid->uuid._16;
+ result->value = (uuid->data[1] << 8) | uuid->data[0];
return (ble_uuid_t*)result;
} else if (uuid->type == MP_BLUETOOTH_UUID_TYPE_32) {
ble_uuid32_t *result = m_new(ble_uuid32_t, 1);
result->u.type = BLE_UUID_TYPE_32;
- result->value = uuid->uuid._32;
+ result->value = (uuid->data[1] << 24) | (uuid->data[1] << 16) | (uuid->data[1] << 8) | uuid->data[0];
return (ble_uuid_t*)result;
} else if (uuid->type == MP_BLUETOOTH_UUID_TYPE_128) {
ble_uuid128_t *result = m_new(ble_uuid128_t, 1);
result->u.type = BLE_UUID_TYPE_128;
- memcpy(result->value, uuid->uuid._128, 16);
+ memcpy(result->value, uuid->data, 16);
return (ble_uuid_t*)result;
} else {
return NULL;
@@ -115,15 +116,19 @@ STATIC mp_obj_bluetooth_uuid_t create_mp_uuid(const ble_uuid_any_t *uuid) {
switch (uuid->u.type) {
case BLE_UUID_TYPE_16:
result.type = MP_BLUETOOTH_UUID_TYPE_16;
- result.uuid._16 = uuid->u16.value;
+ result.data[0] = uuid->u16.value & 0xff;
+ result.data[1] = (uuid->u16.value << 8) & 0xff;
break;
case BLE_UUID_TYPE_32:
result.type = MP_BLUETOOTH_UUID_TYPE_32;
- result.uuid._32 = uuid->u32.value;
+ result.data[0] = uuid->u32.value & 0xff;
+ result.data[1] = (uuid->u32.value << 8) & 0xff;
+ result.data[2] = (uuid->u32.value << 16) & 0xff;
+ result.data[3] = (uuid->u32.value << 24) & 0xff;
break;
case BLE_UUID_TYPE_128:
result.type = MP_BLUETOOTH_UUID_TYPE_128;
- memcpy(result.uuid._128, uuid->u128.value, 16);
+ memcpy(result.data, uuid->u128.value, 16);
break;
default:
assert(false);
@@ -131,7 +136,7 @@ STATIC mp_obj_bluetooth_uuid_t create_mp_uuid(const ble_uuid_any_t *uuid) {
return result;
}
-// modbluetooth (and the layers above it) work in BE addresses, Nimble works in LE.
+// modbluetooth (and the layers above it) work in BE for addresses, Nimble works in LE.
STATIC void reverse_addr_byte_order(uint8_t *addr_out, const uint8_t *addr_in) {
for (int i = 0; i < 6; ++i) {
addr_out[i] = addr_in[5-i];