summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xports/nrf/Makefile3
-rw-r--r--ports/nrf/common-hal/bleio/Service.c5
-rw-r--r--ports/nrf/common-hal/bleio/UUID.c115
-rw-r--r--ports/nrf/common-hal/bleio/UUID.h9
-rw-r--r--shared-bindings/bleio/Characteristic.c12
-rw-r--r--shared-bindings/bleio/Service.c8
-rw-r--r--shared-bindings/bleio/UUID.c151
-rw-r--r--shared-bindings/bleio/UUID.h6
-rw-r--r--shared-bindings/bleio/UUIDType.c75
-rw-r--r--shared-bindings/bleio/UUIDType.h46
-rw-r--r--shared-bindings/bleio/__init__.c3
11 files changed, 149 insertions, 284 deletions
diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile
index 8d0d6d000..a622522a4 100755
--- a/ports/nrf/Makefile
+++ b/ports/nrf/Makefile
@@ -193,8 +193,7 @@ SRC_BINDINGS_ENUMS += \
bleio/Address.c \
bleio/AddressType.c \
bleio/AdvertisementData.c \
- bleio/ScanEntry.c \
- bleio/UUIDType.c
+ bleio/ScanEntry.c
endif
SRC_SHARED_MODULE = \
diff --git a/ports/nrf/common-hal/bleio/Service.c b/ports/nrf/common-hal/bleio/Service.c
index c17c16904..6866837a1 100644
--- a/ports/nrf/common-hal/bleio/Service.c
+++ b/ports/nrf/common-hal/bleio/Service.c
@@ -53,7 +53,7 @@ void common_hal_bleio_service_add_characteristic(bleio_service_obj_t *self, blei
ble_uuid_t uuid = {
.type = BLE_UUID_TYPE_BLE,
- .uuid = characteristic->uuid->value[0] | (characteristic->uuid->value[1] << 8),
+ .uuid = characteristic->uuid->uuid16;
};
if (characteristic->uuid->type == UUID_TYPE_128BIT)
@@ -79,8 +79,7 @@ void common_hal_bleio_service_add_characteristic(bleio_service_obj_t *self, blei
uint32_t err_code;
err_code = sd_ble_gatts_characteristic_add(self->handle, &char_md, &attr_char_value, &handles);
if (err_code != NRF_SUCCESS) {
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
- translate("Failed to add characteristic, status: 0x%08lX"), err_code));
+ mp_raise_OSError(translate("Could not add characteristic"));
}
characteristic->user_desc_handle = handles.user_desc_handle;
diff --git a/ports/nrf/common-hal/bleio/UUID.c b/ports/nrf/common-hal/bleio/UUID.c
index 9a2e101ea..a54de5e31 100644
--- a/ports/nrf/common-hal/bleio/UUID.c
+++ b/ports/nrf/common-hal/bleio/UUID.c
@@ -25,100 +25,47 @@
* THE SOFTWARE.
*/
-#include "ble.h"
-#include "ble_drv.h"
-#include "common-hal/bleio/UUID.h"
-#include "nrf_error.h"
-#include "py/objstr.h"
+#include <string.h>
+
#include "py/runtime.h"
+#include "common-hal/bleio/UUID.h"
#include "shared-bindings/bleio/Adapter.h"
-#include "shared-bindings/bleio/UUID.h"
-
-#define UUID_STR_16BIT_LEN 6
-#define UUID_STR_128BIT_LEN 36
-
-static uint8_t xdigit_8b_value(byte nibble1, byte nibble2) {
- return unichar_xdigit_value(nibble1) |
- (unichar_xdigit_value(nibble2) << 4);
-}
-
-void common_hal_bleio_uuid_construct(bleio_uuid_obj_t *self, const mp_obj_t *uuid) {
- if (MP_OBJ_IS_INT(*uuid)) {
- self->type = UUID_TYPE_16BIT;
-
- self->value[1] = (mp_obj_get_int(*uuid) >> 8) & 0xFF;
- self->value[0] = (mp_obj_get_int(*uuid) >> 0) & 0xFF;
- return;
- }
-
- if (MP_OBJ_IS_STR(*uuid)) {
- GET_STR_DATA_LEN(*uuid, str_data, str_len);
-
- if (str_len == UUID_STR_16BIT_LEN) {
- self->type = UUID_TYPE_16BIT;
-
- self->value[0] = xdigit_8b_value(str_data[5], str_data[4]);
- self->value[1] = xdigit_8b_value(str_data[3], str_data[2]);
- } else if (str_len == UUID_STR_128BIT_LEN) {
- self->type = UUID_TYPE_128BIT;
- ble_uuid128_t vs_uuid;
- vs_uuid.uuid128[0] = xdigit_8b_value(str_data[35], str_data[34]);
- vs_uuid.uuid128[1] = xdigit_8b_value(str_data[33], str_data[32]);
- vs_uuid.uuid128[2] = xdigit_8b_value(str_data[31], str_data[30]);
- vs_uuid.uuid128[3] = xdigit_8b_value(str_data[29], str_data[28]);
- vs_uuid.uuid128[4] = xdigit_8b_value(str_data[27], str_data[26]);
- vs_uuid.uuid128[5] = xdigit_8b_value(str_data[25], str_data[24]);
-
- // 23 '-'
- vs_uuid.uuid128[6] = xdigit_8b_value(str_data[22], str_data[21]);
- vs_uuid.uuid128[7] = xdigit_8b_value(str_data[20], str_data[19]);
-
- // 18 '-'
- vs_uuid.uuid128[8] = xdigit_8b_value(str_data[17], str_data[16]);
- vs_uuid.uuid128[9] = xdigit_8b_value(str_data[15], str_data[14]);
-
- // 13 '-'
- vs_uuid.uuid128[10] = xdigit_8b_value(str_data[12], str_data[11]);
- vs_uuid.uuid128[11] = xdigit_8b_value(str_data[10], str_data[9]);
-
- // 8 '-'
- self->value[0] = xdigit_8b_value(str_data[7], str_data[6]);
- self->value[1] = xdigit_8b_value(str_data[5], str_data[4]);
-
- vs_uuid.uuid128[14] = xdigit_8b_value(str_data[3], str_data[2]);
- vs_uuid.uuid128[15] = xdigit_8b_value(str_data[1], str_data[0]);
-
- common_hal_bleio_adapter_set_enabled(true);
-
- const uint32_t err_code = sd_ble_uuid_vs_add(&vs_uuid, &self->uuid_vs_idx);
- if (err_code != NRF_SUCCESS) {
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
- translate("Failed to add Vendor Specific UUID, status: 0x%08lX"), err_code));
- }
-
- } else {
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
- translate("Invalid UUID string length")));
- }
+#include "ble.h"
+#include "ble_drv.h"
+#include "nrf_error.h"
- return;
+// If uuid128 is NULL, this is a Bluetooth SIG 16-bit UUID.
+// If uuid128 is not NULL, it's a 128-bit (16-byte) UUID, with bytes 12 and 13 zero'd out, where
+// the 16-bit part goes. Those 16 bits are passed in uuid16.
+void common_hal_bleio_uuid_construct(bleio_uuid_obj_t *self, uint32_t uuid16, uint8_t uuid128[]) {
+ self->uuid16 = uuid16;
+ self->uuid_vs_idx = 0;
+ if (uuid128 != NULL) {
+ ble_uuid128_t vs_uuid;
+ memcpy(vs_uuid.uuid128, uuid128, sizeof(vs_uuid.uuid128));
+
+ // Register this vendor-specific UUID. Bytes 12 and 13 will be zero.
+ common_hal_bleio_adapter_set_enabled(true);
+ const uint32_t err_code = sd_ble_uuid_vs_add(&vs_uuid, &self->uuid_vs_idx);
+ if (err_code != NRF_SUCCESS) {
+ mp_raise_OSError(&mp_type_OSError, translate("Could not register Vendor-Specific UUID"));
}
-
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
- translate("Invalid UUID parameter")));
}
void common_hal_bleio_uuid_print(bleio_uuid_obj_t *self, const mp_print_t *print) {
- if (self->type == UUID_TYPE_16BIT) {
- mp_printf(print, "UUID(uuid: 0x" HEX2_FMT HEX2_FMT ")",
- self->value[1], self->value[0]);
+ if (self->uuid_vs_idx != 0) {
+ mp_printf(print, "UUID(uuid16: 0x%04x, Vendor-Specific index: " HEX2_FMT ")",
+ self->uuid16, self->uuid_vs_idx);
} else {
- mp_printf(print, "UUID(uuid: 0x" HEX2_FMT HEX2_FMT ", VS idx: " HEX2_FMT ")",
- self->value[1], self->value[0], self->uuid_vs_idx);
+ mp_printf(print, "UUID16(0x%04x)", self->uuid16);
}
}
-bleio_uuid_type_t common_hal_bleio_uuid_get_type(bleio_uuid_obj_t *self) {
- return self->type;
+bool common_hal_bleio_uuid_get_vendor_specific(bleio_uuid_obj_t *self) {
+ return self->uuid_vs_idx != 0;
+}
+
+uint32_t common_hal_bleio_uuid_get_uuid16(bleio_uuid_obj_t *self) {
+ return self->uuid16;
}
diff --git a/ports/nrf/common-hal/bleio/UUID.h b/ports/nrf/common-hal/bleio/UUID.h
index cb0fddcfd..77f8fc5d1 100644
--- a/ports/nrf/common-hal/bleio/UUID.h
+++ b/ports/nrf/common-hal/bleio/UUID.h
@@ -28,13 +28,16 @@
#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_UUID_H
#define MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_UUID_H
-#include "shared-bindings/bleio/UUIDType.h"
+#include "py/obj.h"
typedef struct {
mp_obj_base_t base;
- bleio_uuid_type_t type;
+ // If non-zero, `uuid_vs_idx` is an index into the SoftDevice's table of registered vendor-specific UUID's.
+ // If zero, `value` is a 16-bit Bluetooth SIG UUID, which would convert to this 128-bit UUID.
+ // 0000xxxx-0000-1000-8000-00805F9B34FB
uint8_t uuid_vs_idx;
- uint8_t value[2];
+ // The 16-bit part of the UUID. This replaces bytes 12 and 13 in the registered 128-bit UUID.
+ uint16_t uuid16;
} bleio_uuid_obj_t;
#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_UUID_H
diff --git a/shared-bindings/bleio/Characteristic.c b/shared-bindings/bleio/Characteristic.c
index 369f3f991..2dd1d4270 100644
--- a/shared-bindings/bleio/Characteristic.c
+++ b/shared-bindings/bleio/Characteristic.c
@@ -80,18 +80,19 @@
//| .. attribute:: write
//|
-//| A `bool` specifying if the characteristic allows writting to its value.
+//| A `bool` specifying if the characteristic allows writing to its value.
//|
//| .. attribute:: write_no_resp
//|
-//| A `bool` specifying if the characteristic allows writting to its value without response.
+//| A `bool` specifying if the characteristic allows writing to its value without response.
//|
STATIC void bleio_characteristic_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in);
- mp_printf(print, "Characteristic(uuid: 0x"HEX2_FMT""HEX2_FMT" handle: 0x" HEX2_FMT ")",
- self->uuid->value[1], self->uuid->value[0], self->handle);
+ mp_printf(print, "Characteristic(");
+ common_hal_bleio_uuid_print(print, self->uuid);
+ mp_printf(print, ")");
}
STATIC mp_obj_t bleio_characteristic_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
@@ -121,8 +122,7 @@ STATIC mp_obj_t bleio_characteristic_make_new(const mp_obj_type_t *type, size_t
if (MP_OBJ_IS_TYPE(uuid, &bleio_uuid_type)) {
self->uuid = MP_OBJ_TO_PTR(uuid);
} else {
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
- translate("Invalid UUID parameter")));
+ mp_raise_ValueError(translate("Expected a UUID"));
}
common_hal_bleio_characteristic_construct(self);
diff --git a/shared-bindings/bleio/Service.c b/shared-bindings/bleio/Service.c
index 2d09cbc3c..727350215 100644
--- a/shared-bindings/bleio/Service.c
+++ b/shared-bindings/bleio/Service.c
@@ -66,8 +66,9 @@
STATIC void bleio_service_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
bleio_service_obj_t *self = MP_OBJ_TO_PTR(self_in);
- mp_printf(print, "Service(uuid: 0x"HEX2_FMT""HEX2_FMT")",
- self->uuid->value[1], self->uuid->value[0]);
+ mp_printf(print, "Service(");
+ common_hal_bleio_uuid_print(print, self->uuid);
+ mp_print(print, ")");
}
STATIC mp_obj_t bleio_service_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
@@ -101,8 +102,7 @@ STATIC mp_obj_t bleio_service_make_new(const mp_obj_type_t *type, size_t n_args,
if (MP_OBJ_IS_TYPE(uuid, &bleio_uuid_type)) {
self->uuid = MP_OBJ_TO_PTR(uuid);
} else {
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
- translate("Invalid UUID parameter")));
+ mp_raise_ValueError(translate("Expected a UUID or None"));
}
return MP_OBJ_FROM_PTR(self);
diff --git a/shared-bindings/bleio/UUID.c b/shared-bindings/bleio/UUID.c
index 7cef9a26f..33d280304 100644
--- a/shared-bindings/bleio/UUID.c
+++ b/shared-bindings/bleio/UUID.c
@@ -5,6 +5,7 @@
*
* Copyright (c) 2017 Glenn Ruben Bakke
* Copyright (c) 2018 Artur Pacholec
+ * Copyright (c) 2018 Dan Halbert for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -29,47 +30,38 @@
#include "py/runtime.h"
#include "shared-bindings/bleio/UUID.h"
+// Including hyphens.
+#define UUID128_STR_LEN 36
+// Number of bytes
+#define UUID128_BYTE_LEN 32
+
+STATIC uint8_t xdigit_8b_value(byte nibble1, byte nibble2) {
+ return unichar_xdigit_value(nibble1) | (unichar_xdigit_value(nibble2) << 4);
+}
+
+
//| .. currentmodule:: bleio
//|
-//| :class:`UUID` -- BLE UUID
+//| :class:`UUID16` -- BLE UUID16
//| =========================================================
//|
-//| Encapsulates both 16-bit and 128-bit UUIDs. Can be used for services,
-//| characteristics, descriptors and more.
+//| A 16-bit or 128-bit UUID. Can be used for services, characteristics, descriptors and more.
//|
//| .. class:: UUID(uuid)
//|
-//| Create a new UUID object encapsulating the uuid value.
-//| The value itself can be one of:
+//| Create a new UUID or UUID object encapsulating the uuid value.
+//| The value can be one of:
//|
-//| - a `int` value in range of 0 to 0xFFFF
-//| - a `str` value in the format of '0xXXXX' for 16-bit or 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX' for 128-bit
+//| - an `int` value in range 0 to 0xFFFF (Bluetooth SIG 16-bit UUID)
+//| - a `str` value in the format 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', where the X's are hex digits.
+//| (128 bit UUID)
//|
//| :param int/str uuid: The uuid to encapsulate
//|
-//| .. method:: __len__()
-//|
-//| Returns the uuid length in bits
-//|
-//| This allows you to:
-//|
-//| uuid = bleio.UUID(0x1801)
-//| print(len(uuid))
-//|
-
-//| .. attribute:: type
-//|
-//| The UUID type. One of:
-//|
-//| - `bleio.UUIDType.TYPE_16BIT`
-//| - `bleio.UUIDType.TYPE_128BIT`
-//|
STATIC mp_obj_t bleio_uuid_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
mp_arg_check_num(n_args, n_kw, 1, 1, true);
- bleio_uuid_obj_t *self = m_new_obj(bleio_uuid_obj_t);
- self->base.type = &bleio_uuid_type;
mp_map_t kw_args;
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
@@ -84,20 +76,55 @@ STATIC mp_obj_t bleio_uuid_make_new(const mp_obj_type_t *type, size_t n_args, si
const mp_obj_t uuid = args[ARG_uuid].u_obj;
- common_hal_bleio_uuid_construct(self, &uuid);
-
- return MP_OBJ_FROM_PTR(self);
-}
-
-STATIC mp_obj_t bleio_uuid_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
- bleio_uuid_obj_t *self = MP_OBJ_TO_PTR(self_in);
-
- const bleio_uuid_type_t type = common_hal_bleio_uuid_get_type(self);
- const uint8_t len = (type == UUID_TYPE_16BIT) ? 16 : 128;
- switch (op) {
- case MP_UNARY_OP_BOOL: return mp_obj_new_bool(len != 0);
- case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(len);
- default: return MP_OBJ_NULL; // op not supported
+ if (MP_OBJ_IS_INT(uuid)) {
+ mp_int_t uuid16 = mp_obj_get_int(uuid);
+ if (uuid16 < 0 || uuid16 > 0xffff) {
+ mp_raise_ValueError(translate("Integer UUID not in range 0 to 0xffff"));
+ }
+
+ // This is a 16-bit Bluetooth SIG UUID. NULL means no 128-bit value.
+ common_hal_bleio_uuid_construct(self, uuid16, NULL);
+
+ } else if (MP_OBJ_IS_STR(uuid)) {
+ uint8_t uuid128[UUID128_BYTE_LEN];
+ GET_STR_DATA_LEN(uuid, str, str_len);
+ if (str_len == UUID128_STR_LEN &&
+ str[8] == '-' && str[13] == '-' && str[18] == '-' && str[23] == '-') {
+ size_t str_index = UUID128_STR_LEN - 1;
+ size_t uuid128_index = 0;
+ bool error = false;
+
+ // Loop until fewer than two characters left.
+ while (str_index >= 1 && uuid128_index < UUID128_BYTE_LEN) {
+ if (str[str_index] == '-') {
+ // Skip hyphen separators.
+ str--;
+ continue;
+ }
+
+ if (!unichar_isxdigit(str[str_index]) ||
+ !unichar_isxdigit(str[str_index-1])) {
+ error = true;
+ break;
+ }
+
+ uuid128[uuid128_index] = xdigit_8b_value(str[str_index],
+ str[str_index-1]);
+ uuid128_index += 1;
+ str_index -= 2;
+ }
+ // Check for correct number of hex digits and no parsing errors.
+ if (!error && uuid128_index == UUID128_BYTE_LEN && str_index == -1) {
+ uint32_t uuid16 = (uuid128[13] << 8) | uuid128[12];
+ uuid128[12] = 0;
+ uuid128[13] = 0;
+ common_hal_bleio_uuid_construct(self, uuid16, uuid128);
+ return MP_OBJ_FROM_PTR(self);
+ }
+ }
+ mp_raise_ValueError(translate("UUID string must be of the form xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"));
+ } else {
+ mp_raise_ValueError(translate("UUID value is not int or string"));
}
}
@@ -107,31 +134,46 @@ STATIC void bleio_uuid_print(const mp_print_t *print, mp_obj_t self_in, mp_print
common_hal_bleio_uuid_print(self, print);
}
-STATIC mp_obj_t bleio_uuid_get_type(mp_obj_t self_in) {
+//| .. attribute:: uuid16
+//|
+//| The 16-bit part of the UUID. (read-only)
+//|
+STATIC void bleio_uuid_get_uuid16(mp_obj_t self_in) {
bleio_uuid_obj_t *self = MP_OBJ_TO_PTR(self_in);
+ return MP_OBJ_NEW_SMALL_INT(common_hal_bleio_uuid_get_uuid16(self));
+}
- const bleio_uuid_type_t type = common_hal_bleio_uuid_get_type(self);
- if (type == UUID_TYPE_16BIT) {
- return (mp_obj_t)&bleio_uuidtype_16bit_obj;
- }
+MP_DEFINE_CONST_FUN_OBJ_1(bleio_uuid_get_uuid16_obj, bleio_uuid_get_uuid16);
- if (type == UUID_TYPE_128BIT) {
- return (mp_obj_t)&bleio_uuidtype_128bit_obj;
- }
+const mp_obj_property_t bleio_uuid16_obj = {
+ .base.type = &mp_type_property,
+ .proxy = {(mp_obj_t)&bleio_uuid_get_uuid16_obj,
+ (mp_obj_t)&mp_const_none_obj,
+ (mp_obj_t)&mp_const_none_obj},
+};
- return (mp_obj_t)&mp_const_none_obj;
+//| .. attribute:: vendor_specific
+//|
+//| True if this UUID represents a 128-bit vendor-specific UUID.
+//| False if this UUID represents a 16-bit Bluetooth SIG assigned UUID. (read-only)
+//|
+STATIC mp_obj_t bleio_uuid_get_vendor_specific(mp_obj_t self_in) {
+ bleio_uuid_obj_t *self = MP_OBJ_TO_PTR(self_in);
+ return mp_obj_new_bool(common_hal_bleio_uuid_get_vendor_specific(self));
}
-MP_DEFINE_CONST_FUN_OBJ_1(bleio_uuid_get_type_obj, bleio_uuid_get_type);
-const mp_obj_property_t bleio_uuid_type_obj = {
+MP_DEFINE_CONST_FUN_OBJ_1(bleio_uuid_get_vendor_specific_obj, bleio_uuid_get_vendor_specific);
+
+const mp_obj_property_t bleio_uuid_vendor_specific_obj = {
.base.type = &mp_type_property,
- .proxy = {(mp_obj_t)&bleio_uuid_get_type_obj,
+ .proxy = {(mp_obj_t)&bleio_uuid_get_vendor_specific_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj},
};
STATIC const mp_rom_map_elem_t bleio_uuid_locals_dict_table[] = {
- { MP_ROM_QSTR(MP_QSTR_type), MP_ROM_PTR(&bleio_uuid_type_obj) },
+ { MP_ROM_QSTR(MP_QSTR_uuid16), MP_ROM_PTR(&bleio_uuid16_obj) },
+ { MP_ROM_QSTR(MP_QSTR_vendor_specific), MP_ROM_PTR(&bleio_uuid_vendor_specific_obj) },
};
STATIC MP_DEFINE_CONST_DICT(bleio_uuid_locals_dict, bleio_uuid_locals_dict_table);
@@ -141,6 +183,5 @@ const mp_obj_type_t bleio_uuid_type = {
.name = MP_QSTR_UUID,
.print = bleio_uuid_print,
.make_new = bleio_uuid_make_new,
- .unary_op = bleio_uuid_unary_op,
- .locals_dict = (mp_obj_dict_t*)&bleio_uuid_locals_dict
+ .locals_dict = (mp_obj_dict_t*)&bleio_uuid_locals_dict,
};
diff --git a/shared-bindings/bleio/UUID.h b/shared-bindings/bleio/UUID.h
index d6fcbac1b..e27058516 100644
--- a/shared-bindings/bleio/UUID.h
+++ b/shared-bindings/bleio/UUID.h
@@ -28,12 +28,12 @@
#define MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_UUID_H
#include "common-hal/bleio/UUID.h"
-#include "shared-bindings/bleio/UUIDType.h"
extern const mp_obj_type_t bleio_uuid_type;
-extern void common_hal_bleio_uuid_construct(bleio_uuid_obj_t *self, const mp_obj_t *uuid);
+extern void common_hal_bleio_uuid_construct(bleio_uuid_obj_t *self, mp_int_t uuid16, uint8_t uuid128[]);
extern void common_hal_bleio_uuid_print(bleio_uuid_obj_t *self, const mp_print_t *print);
-extern bleio_uuid_type_t common_hal_bleio_uuid_get_type(bleio_uuid_obj_t *self);
+extern bool common_hal_bleio_uuid_get_vendor_specific(bleio_uuid_obj_t *self);
+extern uint32_t common_hal_bleio_uuid_get_uuid16(bleio_uuid_obj_t *self);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_UUID_H
diff --git a/shared-bindings/bleio/UUIDType.c b/shared-bindings/bleio/UUIDType.c
deleted file mode 100644
index e36d1f06d..000000000
--- a/shared-bindings/bleio/UUIDType.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * This file is part of the Micro Python project, http://micropython.org/
- *
- * The MIT License (MIT)
- *
- * Copyright (c) 2018 Artur Pacholec
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#include "shared-bindings/bleio/UUIDType.h"
-
-//| .. currentmodule:: bleio
-//|
-//| :class:`UUIDType` -- defines the type of a BLE UUID
-//| =============================================================
-//|
-//| .. class:: bleio.UUIDType
-//|
-//| Enum-like class to define the type of a BLE UUID.
-//|
-//| .. data:: TYPE_16BIT
-//|
-//| The UUID is 16-bit
-//|
-//| .. data:: TYPE_128BIT
-//|
-//| The UUID is 128-bit
-//|
-const mp_obj_type_t bleio_uuidtype_type;
-
-const bleio_uuidtype_obj_t bleio_uuidtype_16bit_obj = {
- { &bleio_uuidtype_type },
-};
-
-const bleio_uuidtype_obj_t bleio_uuidtype_128bit_obj = {
- { &bleio_uuidtype_type },
-};
-
-STATIC const mp_rom_map_elem_t bleio_uuidtype_locals_dict_table[] = {
- { MP_ROM_QSTR(MP_QSTR_TYPE_16BIT), MP_ROM_PTR(&bleio_uuidtype_16bit_obj) },
- { MP_ROM_QSTR(MP_QSTR_TYPE_128BIT), MP_ROM_PTR(&bleio_uuidtype_128bit_obj) },
-};
-STATIC MP_DEFINE_CONST_DICT(bleio_uuidtype_locals_dict, bleio_uuidtype_locals_dict_table);
-
-STATIC void bleio_uuidtype_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
- qstr type = MP_QSTR_TYPE_128BIT;
- if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&bleio_uuidtype_16bit_obj)) {
- type = MP_QSTR_TYPE_16BIT;
- }
- mp_printf(print, "%q.%q.%q", MP_QSTR_bleio, MP_QSTR_UUIDType, type);
-}
-
-const mp_obj_type_t bleio_uuidtype_type = {
- { &mp_type_type },
- .name = MP_QSTR_UUIDType,
- .print = bleio_uuidtype_print,
- .locals_dict = (mp_obj_t)&bleio_uuidtype_locals_dict,
-};
diff --git a/shared-bindings/bleio/UUIDType.h b/shared-bindings/bleio/UUIDType.h
deleted file mode 100644
index 87bbf9b53..000000000
--- a/shared-bindings/bleio/UUIDType.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * This file is part of the Micro Python project, http://micropython.org/
- *
- * The MIT License (MIT)
- *
- * Copyright (c) 2018 Artur Pacholec
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_UUIDTYPE_H
-#define MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_UUIDTYPE_H
-
-#include "py/obj.h"
-
-typedef enum {
- UUID_TYPE_16BIT,
- UUID_TYPE_128BIT
-} bleio_uuid_type_t;
-
-extern const mp_obj_type_t bleio_uuidtype_type;
-
-typedef struct {
- mp_obj_base_t base;
-} bleio_uuidtype_obj_t;
-
-extern const bleio_uuidtype_obj_t bleio_uuidtype_16bit_obj;
-extern const bleio_uuidtype_obj_t bleio_uuidtype_128bit_obj;
-
-#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_UUIDTYPE_H
diff --git a/shared-bindings/bleio/__init__.c b/shared-bindings/bleio/__init__.c
index 98099422c..46822603f 100644
--- a/shared-bindings/bleio/__init__.c
+++ b/shared-bindings/bleio/__init__.c
@@ -36,7 +36,6 @@
#include "shared-bindings/bleio/Scanner.h"
#include "shared-bindings/bleio/Service.h"
#include "shared-bindings/bleio/UUID.h"
-#include "shared-bindings/bleio/UUIDType.h"
//| :mod:`bleio` --- Bluetooth Low Energy functionality
//| ================================================================
@@ -63,7 +62,6 @@
//| Scanner
//| Service
//| UUID
-//| UUIDType
//|
//| .. attribute:: adapter
//|
@@ -89,7 +87,6 @@ STATIC const mp_rom_map_elem_t bleio_module_globals_table[] = {
// Enum-like Classes.
{ MP_ROM_QSTR(MP_QSTR_AddressType), MP_ROM_PTR(&bleio_addresstype_type) },
- { MP_ROM_QSTR(MP_QSTR_UUIDType), MP_ROM_PTR(&bleio_uuidtype_type) },
};
STATIC MP_DEFINE_CONST_DICT(bleio_module_globals, bleio_module_globals_table);