Skip to content

Commit 74034d6

Browse files
committed
characteristic/cccd r/w; not tested
1 parent 0f4b969 commit 74034d6

File tree

7 files changed

+196
-243
lines changed

7 files changed

+196
-243
lines changed

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,6 @@
3030
#include "shared-module/_bleio/Attribute.h"
3131
#include "shared-bindings/_bleio/UUID.h"
3232

33-
// Types returned by attribute table lookups. These are UUIDs.
34-
typedef enum {
35-
BLE_TYPE_UNKNOWN = 0x0000,
36-
BLE_TYPE_SERVICE_PRIMARY = 0x2800,
37-
BLE_TYPE_SERVICE_SECONDARY = 0x2801,
38-
BLE_TYPE_SERVICE_INCLUDE = 0x2802, // not yet implemented by us
39-
BLE_TYPE_CHARACTERISTIC = 0x2803,
40-
BLE_TYPE_CHAR_EXTENDED_PROPS = 0x2900, // not yet implemented by us
41-
BLE_TYPE_CHAR_USER_DESC = 0x2901, // not yet implemented by us
42-
BLE_TYPE_CCCD = 0x2902,
43-
BLE_TYPE_SCCD = 0x2903, // not yet implemented by us
44-
BLE_TYPE_CHAR_PRESENTATION_FMT = 0x2904, // not yet implemented by us
45-
BLE_TYPE_CHAR_AGGREGATE_FMT = 0x2905, // not yet implemented by us
46-
} ble_attribute_type_uuid;
47-
4833
bleio_uuid_obj_t *bleio_attribute_get_uuid(mp_obj_t *attribute);
4934

5035
#endif // MICROPY_INCLUDED_BLE_HCI_COMMON_HAL_ATTRIBUTE_H

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void common_hal_bleio_service_add_characteristic(bleio_service_obj_t *self,
104104
cccd->base.type = &bleio_descriptor_type;
105105

106106
uint16_t zero = 0;
107-
mp_buffer_info_t zero_cccd = {
107+
mp_buffer_info_t zero_cccd_value = {
108108
.buf = &zero,
109109
.len = sizeof(zero),
110110
};
@@ -117,7 +117,7 @@ void common_hal_bleio_service_add_characteristic(bleio_service_obj_t *self,
117117
characteristic->read_perm, // Make CCCD write perm match characteristic read perm.
118118
2, // 2 bytes
119119
true, // fixed length
120-
&zero_cccd // Initial value is 0.
120+
&zero_cccd_value // Initial value is 0.
121121
);
122122

123123
// Adds CCCD to attribute table, and also extends self->end_handle to include the CCCD.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,8 @@ void common_hal_bleio_uuid_pack_into(bleio_uuid_obj_t *self, uint8_t* buf) {
6868
common_hal_bleio_uuid_get_uuid128(self, buf);
6969
}
7070
}
71+
72+
// Return a uui16 only if this is a standard uuid. Otherwise return BLE_UUID_UNKNOWN.
73+
uint16_t bleio_uuid_get_uuid16_or_unknown(bleio_uuid_obj_t *uuid) {
74+
return uuid->size == 16 ? uuid->uuid16 : BLE_UUID_UNKNOWN;
75+
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,28 @@
3131

3232
#include "py/obj.h"
3333

34+
// Types returned by attribute table lookups. These are UUIDs.
35+
typedef enum {
36+
BLE_UUID_UNKNOWN = 0x0000,
37+
BLE_UUID_SERVICE_PRIMARY = 0x2800,
38+
BLE_UUID_SERVICE_SECONDARY = 0x2801,
39+
BLE_UUID_SERVICE_INCLUDE = 0x2802, // not yet implemented by us
40+
BLE_UUID_CHARACTERISTIC = 0x2803,
41+
BLE_UUID_CHAR_EXTENDED_PROPS = 0x2900, // not yet implemented by us
42+
BLE_UUID_CHAR_USER_DESC = 0x2901, // not yet implemented by us
43+
BLE_UUID_CCCD = 0x2902,
44+
BLE_UUID_SCCD = 0x2903, // not yet implemented by us
45+
BLE_UUID_CHAR_PRESENTATION_FMT = 0x2904, // not yet implemented by us
46+
BLE_UUID_CHAR_AGGREGATE_FMT = 0x2905, // not yet implemented by us
47+
} ble_standard_uuid;
48+
3449
typedef struct {
3550
mp_obj_base_t base;
3651
uint8_t size;
3752
uint16_t uuid16;
3853
uint8_t uuid128[16];
3954
} bleio_uuid_obj_t;
4055

56+
uint16_t bleio_uuid_get_uuid16_or_unknown(bleio_uuid_obj_t *uuid);
57+
4158
#endif // MICROPY_INCLUDED_BLE_HCI_COMMON_HAL_UUID_H

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void check_hci_error(hci_result_t result) {
117117
void bleio_reset() {
118118
// Create a UUID object for all CCCD's.
119119
cccd_uuid.base.type = &bleio_uuid_type;
120-
common_hal_bleio_uuid_construct(&cccd_uuid, BLE_TYPE_CCCD, NULL);
120+
common_hal_bleio_uuid_construct(&cccd_uuid, BLE_UUID_CCCD, NULL);
121121

122122
bleio_hci_reset();
123123

0 commit comments

Comments
 (0)