8000 extmod/modbluetooth: Make modbluetooth event not a bitfield. · larsks/micropython@e6881f0 · GitHub
[go: up one dir, main page]

Skip to content

Commit e6881f0

Browse files
jimmodpgeorge
authored andcommitted
extmod/modbluetooth: Make modbluetooth event not a bitfield.
There doesn't appear to be any use for only triggering on specific events, so it's just easier to number them sequentially. This makes them smaller values so they take up only 1 byte in the ringbuf, only 1 byte for the opcode in the bytecode, and makes room for more events. Also add a couple of new event types that need to be implemented (to avoid re-numbering later). And rename _COMPLETE and _STATUS to _DONE for consistency. In the future the "trigger" keyword argument can be reinstated by requiring the user to compute the bitmask, eg: ble.irq(handler, 1 << _IRQ_SCAN_RESULT | 1 << _IRQ_SCAN_DONE)
1 parent 02cc446 commit e6881f0

File tree

7 files changed

+92
-83
lines changed

7 files changed

+92
-83
lines changed

examples/bluetooth/ble_temperature.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
from micropython import const
1313

14-
_IRQ_CENTRAL_CONNECT = const(1 << 0)
15-
_IRQ_CENTRAL_DISCONNECT = const(1 << 1)
14+
_IRQ_CENTRAL_CONNECT = const(1)
15+
_IRQ_CENTRAL_DISCONNECT = const(2)
1616

1717
# org.bluetooth.service.environmental_sensing
1818
_ENV_SENSE_UUID = bluetooth.UUID(0x181A)

examples/bluetooth/ble_temperature_central.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,25 @@
1010

1111
from micropython import const
1212

13-
_IRQ_CENTRAL_CONNECT = const(1 << 0)
14-
_IRQ_CENTRAL_DISCONNECT = const(1 << 1)
15-
_IRQ_GATTS_WRITE = const(1 << 2)
16-
_IRQ_GATTS_READ_REQUEST = const(1 << 3)
17-
_IRQ_SCAN_RESULT = const(1 << 4)
18-
_IRQ_SCAN_COMPLETE = const(1 << 5)
19-
_IRQ_PERIPHERAL_CONNECT = const(1 << 6)
20-
_IRQ_PERIPHERAL_DISCONNECT = const(1 << 7)
21-
_IRQ_GATTC_SERVICE_RESULT = const(1 << 8)
22-
_IRQ_GATTC_CHARACTERISTIC_RESULT = const(1 << 9)
23-
_IRQ_GATTC_DESCRIPTOR_RESULT = const(1 << 10)
24-
_IRQ_GATTC_READ_RESULT = const(1 << 11)
25-
_IRQ_GATTC_WRITE_STATUS = const(1 << 12)
26-
_IRQ_GATTC_NOTIFY = const(1 << 13)
27-
_IRQ_GATTC_INDICATE = const(1 << 14)
28-
_IRQ_ALL = const(0xFFFF)
13+
_IRQ_CENTRAL_CONNECT = const(1)
14+
_IRQ_CENTRAL_DISCONNECT = const(2)
15+
_IRQ_GATTS_WRITE = const(3)
16+
_IRQ_GATTS_READ_REQUEST = const(4)
17+
_IRQ_SCAN_RESULT = const(5)
18+
_IRQ_SCAN_DONE = const(6)
19+
_IRQ_PERIPHERAL_CONNECT = const(7)
20+
_IRQ_PERIPHERAL_DISCONNECT = const(8)
21+
_IRQ_GATTC_SERVICE_RESULT = const(9)
22+
_IRQ_GATTC_SERVICE_DONE = const(10)
23+
_IRQ_GATTC_CHARACTERISTIC_RESULT = const(11)
24+
_IRQ_GATTC_CHARACTERISTIC_DONE = const(12)
25+
_IRQ_GATTC_DESCRIPTOR_RESULT = const(13)
26+
_IRQ_GATTC_DESCRIPTOR_DONE = const(14)
27+
_IRQ_GATTC_READ_RESULT = const(15)
28+
_IRQ_GATTC_READ_DONE = const(16)
29+
_IRQ_GATTC_WRITE_DONE = const(17)
30+
_IRQ_GATTC_NOTIFY = const(18)
31+
_IRQ_GATTC_INDICATE = const(19)
2932

3033
_ADV_IND = const(0x00)
3134
_ADV_DIRECT_IND = const(0x01)
@@ -93,7 +96,7 @@ def _irq(self, event, data):
9396
self._name = decode_name(adv_data) or "?"
9497
self._ble.gap_scan(None)
9598

96-
elif event == _IRQ_SCAN_COMPLETE:
99+
elif event == _IRQ_SCAN_DONE:
97100
if self._scan_callback:
98101
if self._addr:
99102
# Found a device during the scan (and the scan was explicitly stopped).

examples/bluetooth/ble_uart_peripheral.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
from micropython import const
77

8-
_IRQ_CENTRAL_CONNECT = const(1 << 0)
9-
_IRQ_CENTRAL_DISCONNECT = const(1 << 1)
10-
_IRQ_GATTS_WRITE = const(1 << 2)
8+
_IRQ_CENTRAL_CONNECT = const(1)
9+
_IRQ_CENTRAL_DISCONNECT = const(2)
10+
_IRQ_GATTS_WRITE = const(3)
1111

1212
_UART_UUID = bluetooth.UUID("6E400001-B5A3-F393-E0A9-E50E24DCCA9E")
1313
_UART_TX = (

extmod/modbluetooth.c

Lines changed: 17 additions & 20 deletions
10000
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* The MIT License (MIT)
55
*
66
* Copyright (c) 2018 Ayke van Laethem
7-
* Copyright (c) 2019 Jim Mussared
7+
* Copyright (c) 2019-2020 Jim Mussared
88
*
99
* Permission is hereby granted, free of charge, to any person obtaining a copy
1010
* of this software and associated documentation files (the "Software"), to deal
@@ -57,7 +57,6 @@ STATIC const mp_obj_type_t bluetooth_uuid_type;
5757
typedef struct {
5858
mp_obj_base_t base;
5959
mp_obj_t irq_handler;
60-
uint16_t irq_trigger;
6160
bool irq_scheduled;
6261
mp_obj_t irq_data_tuple;
6362
uint8_t irq_data_addr_bytes[6];
@@ -249,7 +248,6 @@ STATIC mp_obj_t bluetooth_ble_make_new(const mp_obj_type_t *type, size_t n_args,
249248
o->base.type = &bluetooth_ble_type;
250249

251250
o->irq_handler = mp_const_none;
252-
o->irq_trigger = 0;
253251

254252
// Pre-allocate the event data tuple to prevent needing to allocate in the IRQ handler.
255253
o->irq_data_tuple = mp_obj_new_tuple(MICROPY_PY_BLUETOOTH_MAX_EVENT_DATA_TUPLE_LEN, NULL);
@@ -372,10 +370,9 @@ STATIC mp_obj_t bluetooth_ble_config(size_t n_args, const mp_obj_t *args, mp_map
372370
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bluetooth_ble_config_obj, 1, bluetooth_ble_config);
373371

374372
STATIC mp_obj_t bluetooth_ble_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
375-
enum { ARG_handler, ARG_trigger };
373+
enum { ARG_handler };
376374
static const mp_arg_t allowed_args[] = {
377375
{ MP_QSTR_handler, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_rom_obj = MP_ROM_NONE} },
378-
{ MP_QSTR_trigger, MP_ARG_INT, {.u_int = MP_BLUETOOTH_IRQ_ALL} },
379376
};
380377
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
381378
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
@@ -388,7 +385,6 @@ STATIC mp_obj_t bluetooth_ble_irq(size_t n_args, const mp_obj_t *pos_args, mp_ma
388385
MICROPY_PY_BLUETOOTH_ENTER
389386
mp_obj_bluetooth_ble_t *o = MP_OBJ_TO_PTR(MP_STATE_VM(bluetooth));
390387
o->irq_handler = callback;
391-
o->irq_trigger = args[ARG_trigger].u_int;
392388
MICROPY_PY_BLUETOOTH_EXIT
393389

394390
return mp_const_none;
@@ -854,7 +850,7 @@ STATIC mp_obj_t bluetooth_ble_invoke_irq(mp_obj_t none_in) {
854850
for (;;) {
855851
MICROPY_PY_BLUETOOTH_ENTER
856852

857-
mp_int_t event = event = ringbuf_get16(&o->ringbuf);
853+
mp_int_t event = ringbuf_get(&o->ringbuf);
858854
if (event < 0) {
859855
// Nothing available in ringbuf.
860856
MICROPY_PY_BLUETOOTH_EXIT
@@ -878,7 +874,7 @@ STATIC mp_obj_t bluetooth_ble_invoke_irq(mp_obj_t none_in) {
878874
} else if (event == MP_BLUETOOTH_IRQ_SCAN_RESULT) {
879875
// addr_type, addr, adv_type, rssi, adv_data
880876
ringbuf_extract(&o->ringbuf, data_tuple, 0, 1, &o->irq_data_addr, 2, NULL, &o->irq_data_data);
881-
} else if (event == MP_BLUETOOTH_IRQ_SCAN_COMPLETE) {
877+
} else if (event == MP_BLUETOOTH_IRQ_SCAN_DONE) {
882878
// No params required.
883879
data_tuple->len = 0;
884880
} else if (event == MP_BLUETOOTH_IRQ_GATTC_SERVICE_RESULT) {
@@ -893,7 +889,7 @@ STATIC mp_obj_t bluetooth_ble_invoke_irq(mp_obj_t none_in) {
893889
} else if (event == MP_BLUETOOTH_IRQ_GATTC_READ_RESULT || event == MP_BLUETOOTH_IRQ_GATTC_NOTIFY || event == MP_BLUETOOTH_IRQ_GATTC_INDICATE) {
894890
// conn_handle, value_handle, data
895891
ringbuf_extract(&o->ringbuf, data_tuple, 2, 0, NULL, 0, NULL, &o->irq_data_data);
896-
} else if (event == MP_BLUETOOTH_IRQ_GATTC_WRITE_STATUS) {
892+
} else if (event == MP_BLUETOOTH_IRQ_GATTC_WRITE_DONE) {
897893
// conn_handle, value_handle, status
898894
ringbuf_extract(&o->ringbuf, data_tuple, 3, 0, NULL, 0, NULL, NULL);
899895
#endif // MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE
@@ -915,23 +911,24 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(bluetooth_ble_invoke_irq_obj, bluetooth_ble_inv
915911
// Callbacks are called in interrupt context (i.e. can't allocate), so we need to push the data
916912
// into the ringbuf and schedule the callback via mp_sched_schedule.
917913

918-
STATIC bool enqueue_irq(mp_obj_bluetooth_ble_t *o, size_t len, uint16_t event) {
919-
if (!o || !(o->irq_trigger & event) || o->irq_handler == mp_const_none) {
914+
STATIC bool enqueue_irq(mp_obj_bluetooth_ble_t *o, size_t len, uint8_t event) {
915+
if (!o || o->irq_handler == mp_const_none) {
920916
return false;
921917
}
922918

923-
if (ringbuf_free(&o->ringbuf) < len + 2) {
919+
// Check if there is enough room for <event-type><payload>.
920+
if (ringbuf_free(&o->ringbuf) < len + 1) {
924921
// Ringbuffer doesn't have room (and is therefore non-empty).
925922

926923
// If this is another scan result, or the front of the ringbuffer isn't a scan result, then nothing to do.
927-
if (event == MP_BLUETOOTH_IRQ_SCAN_RESULT || ringbuf_peek16(&o->ringbuf) != MP_BLUETOOTH_IRQ_SCAN_RESULT) {
924+
if (event == MP_BLUETOOTH_IRQ_SCAN_RESULT || ringbuf_peek(&o->ringbuf) != MP_BLUETOOTH_IRQ_SCAN_RESULT) {
928925
return false;
929926
}
930927

931928
// Front of the queue is a scan result, remove it.
932929

933930
// event, addr_type, addr, adv_type, rssi
934-
int n = 2 + 1 + 6 + 1 + 1;
931+
int n = 1 + 1 + 6 + 1 + 1;
935932
for (int i = 0; i < n; ++i) {
936933
ringbuf_get(&o->ringbuf);
937934
}
@@ -943,7 +940,7 @@ STATIC bool enqueue_irq(mp_obj_bluetooth_ble_t *o, size_t len, uint16_t event) {
943940
}
944941

945942
// Append this event, the caller will then append the arguments.
946-
ringbuf_put16(&o->ringbuf, event);
943+
ringbuf_put(&o->ringbuf, event);
947944
return true;
948945
}
949946

@@ -959,7 +956,7 @@ STATIC void schedule_ringbuf(mp_uint_t atomic_state) {
959956
}
960957
}
961958

962-
void mp_bluetooth_gap_on_connected_disconnected(uint16_t event, uint16_t conn_handle, uint8_t addr_type, const uint8_t *addr) {
959+
void mp_bluetooth_gap_on_connected_disconnected(uint8_t event, uint16_t conn_handle, uint8_t addr_type, const uint8_t *addr) {
963960
MICROPY_PY_BLUETOOTH_ENTER
964961
mp_obj_bluetooth_ble_t *o = MP_OBJ_TO_PTR(MP_STATE_VM(bluetooth));
965962
if (enqueue_irq(o, 2 + 1 + 6, event)) {
@@ -986,7 +983,7 @@ void mp_bluetooth_gatts_on_write(uint16_t conn_handle, uint16_t value_handle) {
986983
void mp_bluetooth_gap_on_scan_complete(void) {
987984
MICROPY_PY_BLUETOOTH_ENTER
988985
mp_obj_bluetooth_ble_t *o = MP_OBJ_TO_PTR(MP_STATE_VM(bluetooth));
989-
if (enqueue_irq(o, 0, MP_BLUETOOTH_IRQ_SCAN_COMPLETE)) {
986+
if (enqueue_irq(o, 0, MP_BLUETOOTH_IRQ_SCAN_DONE)) {
990987
}
991988
schedule_ringbuf(atomic_state);
992989
}
@@ -1048,7 +1045,7 @@ void mp_bluetooth_gattc_on_descriptor_result(uint16_t conn_handle, uint16_t hand
10481045
schedule_ringbuf(atomic_state);
10491046
}
10501047

1051-
size_t mp_bluetooth_gattc_on_data_available_start(uint16_t event, uint16_t conn_handle, uint16_t value_handle, size_t data_len, mp_uint_t *atomic_state_out) {
1048+
size_t mp_bluetooth_gattc_on_data_available_start(uint8_t event, uint16_t conn_handle, uint16_t value_handle, size_t data_len, mp_uint_t *atomic_state_out) {
10521049
MICROPY_PY_BLUETOOTH_ENTER
10531050
*atomic_state_out = atomic_state;
10541051
mp_obj_bluetooth_ble_t *o = MP_OBJ_TO_PTR(MP_STATE_VM(bluetooth));
@@ -1077,7 +1074,7 @@ void mp_bluetooth_gattc_on_data_available_end(mp_uint_t atomic_state) {
10771074
void mp_bluetooth_gattc_on_write_status(uint16_t conn_handle, uint16_t value_handle, uint16_t status) {
10781075
MICROPY_PY_BLUETOOTH_ENTER
10791076
mp_obj_bluetooth_ble_t *o = MP_OBJ_TO_PTR(MP_STATE_VM(bluetooth));
1080-
if (enqueue_irq(o, 2 + 2 + 2, MP_BLUETOOTH_IRQ_GATTC_WRITE_STATUS)) {
1077+
if (enqueue_irq(o, 2 + 2 + 2, MP_BLUETOOTH_IRQ_GATTC_WRITE_DONE)) {
10811078
ringbuf_put16(&o->ringbuf, conn_handle);
10821079
ringbuf_put16(&o->ringbuf, value_handle);
10831080
ringbuf_put16(&o->ringbuf, status);
@@ -1092,7 +1089,7 @@ void mp_bluetooth_gattc_on_write_status(uint16_t conn_handle, uint16_t value_han
10921089
// On ESP32, for example, this is not the case.
10931090
bool mp_bluetooth_gatts_on_read_request(uint16_t conn_handle, uint16_t value_handle) {
10941091
mp_obj_bluetooth_ble_t *o = MP_OBJ_TO_PTR(MP_STATE_VM(bluetooth));
1095-
if ((o->irq_trigger & MP_BLUETOOTH_IRQ_GATTS_READ_REQUEST) && o->irq_handler != mp_const_none) {
1092+
if (o->irq_handler != mp_const_none) {
10961093
// Use pre-allocated tuple because this is a hard IRQ.
10971094
mp_obj_tuple_t *data = MP_OBJ_TO_PTR(o->irq_data_tuple);
10981095
data->items[0] = MP_OBJ_NEW_SMALL_INT(conn_handle);

extmod/modbluetooth.h

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* The MIT License (MIT)
55
*
66
* Copyright (c) 2018 Ayke van Laethem
7-
* Copyright (c) 2019 Jim Mussared
7+
* Copyright (c) 2019-2020 Jim Mussared
88
*
99
* Permission is hereby granted, free of charge, to any person obtaining a copy
1010
* of this software and associated documentation files (the "Software"), to deal
@@ -88,48 +88,50 @@
8888
#define MP_BLUETOOTH_ADDR_RANDOM_PRIVATE_NON_RESOLVABLE (0x13) // Random private non-resolvable address. (NRF SD 0x03)
8989

9090
// Event codes for the IRQ handler.
91-
// Can also be combined to pass to the trigger param to select which events you
92-
// are interested in.
93-
// Note this is currently stored in a uint16_t (in irq_trigger, and the event
94-
// arg to the irq handler), so one spare value remaining.
95-
#define MP_BLUETOOTH_IRQ_CENTRAL_CONNECT (1 << 0)
96-
#define MP_BLUETOOTH_IRQ_CENTRAL_DISCONNECT (1 << 1)
97-
#define MP_BLUETOOTH_IRQ_GATTS_WRITE (1 << 2)
98-
#define MP_BLUETOOTH_IRQ_GATTS_READ_REQUEST (1 << 3)
99-
#define MP_BLUETOOTH_IRQ_SCAN_RESULT (1 << 4)
100-
#define MP_BLUETOOTH_IRQ_SCAN_COMPLETE (1 << 5)
101-
#define MP_BLUETOOTH_IRQ_PERIPHERAL_CONNECT (1 << 6)
102-
#define MP_BLUETOOTH_IRQ_PERIPHERAL_DISCONNECT (1 << 7)
103-
#define MP_BLUETOOTH_IRQ_GATTC_SERVICE_RESULT (1 << 8)
104-
#define MP_BLUETOOTH_IRQ_GATTC_CHARACTERISTIC_RESULT (1 << 9)
105-
#define MP_BLUETOOTH_IRQ_GATTC_DESCRIPTOR_RESULT (1 << 10)
106-
#define MP_BLUETOOTH_IRQ_GATTC_READ_RESULT (1 << 11)
107-
#define MP_BLUETOOTH_IRQ_GATTC_WRITE_STATUS 10000 (1 << 12)
108-
#define MP_BLUETOOTH_IRQ_GATTC_NOTIFY (1 << 13)
109-
#define MP_BLUETOOTH_IRQ_GATTC_INDICATE (1 << 14)
110-
#define MP_BLUETOOTH_IRQ_ALL (0xffff)
91+
#define MP_BLUETOOTH_IRQ_CENTRAL_CONNECT (1)
92+
#define MP_BLUETOOTH_IRQ_CENTRAL_DISCONNECT (2)
93+
#define MP_BLUETOOTH_IRQ_GATTS_WRITE (3)
94+
#define MP_BLUETOOTH_IRQ_GATTS_READ_REQUEST (4)
95+
#define MP_BLUETOOTH_IRQ_SCAN_RESULT (5)
96+
#define MP_BLUETOOTH_IRQ_SCAN_DONE (6)
97+
#define MP_BLUETOOTH_IRQ_PERIPHERAL_CONNECT (7)
98+
#define MP_BLUETOOTH_IRQ_PERIPHERAL_DISCONNECT (8)
99+
#define MP_BLUETOOTH_IRQ_GATTC_SERVICE_RESULT (9)
100+
#define MP_BLUETOOTH_IRQ_GATTC_SERVICE_DONE (10)
101+
#define MP_BLUETOOTH_IRQ_GATTC_CHARACTERISTIC_RESULT (11)
102+
#define MP_BLUETOOTH_IRQ_GATTC_CHARACTERISTIC_DONE (12)
103+
#define MP_BLUETOOTH_IRQ_GATTC_DESCRIPTOR_RESULT (13)
104+
#define MP_BLUETOOTH_IRQ_GATTC_DESCRIPTOR_DONE (14)
105+
#define MP_BLUETOOTH_IRQ_GATTC_READ_RESULT (15)
106+
#define MP_BLUETOOTH_IRQ_GATTC_READ_DONE (16)
107+
#define MP_BLUETOOTH_IRQ_GATTC_WRITE_DONE (17)
108+
#define MP_BLUETOOTH_IRQ_GATTC_NOTIFY (18)
109+
#define MP_BLUETOOTH_IRQ_GATTC_INDICATE (19)
111110

112111
/*
113112
These aren't included in the module for space reasons, but can be used
114113
in your Python code if necessary.
115114
116115
from micropython import const
117-
_IRQ_CENTRAL_CONNECT = const(1 << 0)
118-
_IRQ_CENTRAL_DISCONNECT = const(1 << 1)
119-
_IRQ_GATTS_WRITE = const(1 << 2)
120-
_IRQ_GATTS_READ_REQUEST = const(1 << 3)
121-
_IRQ_SCAN_RESULT = const(1 << 4)
122-
_IRQ_SCAN_COMPLETE = const(1 << 5)
123-
_IRQ_PERIPHERAL_CONNECT = const(1 << 6)
124-
_IRQ_PERIPHERAL_DISCONNECT = const(1 << 7)
125-
_IRQ_GATTC_SERVICE_RESULT = const(1 << 8)
126-
_IRQ_GATTC_CHARACTERISTIC_RESULT = const(1 << 9)
127-
_IRQ_GATTC_DESCRIPTOR_RESULT = const(1 << 10)
128-
_IRQ_GATTC_READ_RESULT = const(1 << 11)
129-
_IRQ_GATTC_WRITE_STATUS = const(1 << 12)
130-
_IRQ_GATTC_NOTIFY = const(1 << 13)
131-
_IRQ_GATTC_INDICATE = const(1 << 14)
132-
_IRQ_ALL = const(0xffff)
116+
_IRQ_CENTRAL_CONNECT = const(1)
117+
_IRQ_CENTRAL_DISCONNECT = const(2)
118+
_IRQ_GATTS_WRITE = const(3)
119+
_IRQ_GATTS_READ_REQUEST = const(4)
120+
_IRQ_SCAN_RESULT = const(5)
121+
_IRQ_SCAN_DONE = const(6)
122+
_IRQ_PERIPHERAL_CONNECT = const(7)
123+
_IRQ_PERIPHERAL_DISCONNECT = const(8)
124+
_IRQ_GATTC_SERVICE_RESULT = const(9)
125+
_IRQ_GATTC_SERVICE_DONE = const(10)
126+
_IRQ_GATTC_CHARACTERISTIC_RESULT = const(11)
127+
_IRQ_GATTC_CHARACTERISTIC_DONE = const(12)
128+
_IRQ_GATTC_DESCRIPTOR_RESULT = const(13)
129+
_IRQ_GATTC_DESCRIPTOR_DONE = const(14)
130+
_IRQ_GATTC_READ_RESULT = const(15)
131+
_IRQ_GATTC_READ_DONE = const(16)
132+
_IRQ_GATTC_WRITE_DONE = const(17)
133+
_IRQ_GATTC_NOTIFY = const(18)
134+
_IRQ_GATTC_INDICATE = const(19)
133135
*/
134136

135137
// Common UUID type.
@@ -238,7 +240,7 @@ int mp_bluetooth_gattc_write(uint16_t conn_handle, uint16_t value_handle, const
238240
// API implemented by modbluetooth (called by port-specific implementations):
239241

240242
// Notify modbluetooth that a connection/disconnection event has occurred.
241-
void mp_bluetooth_gap_on_connected_disconnected(uint16_t event, uint16_t conn_handle, uint8_t addr_type, const uint8_t *addr);
243+
void mp_bluetooth_gap_on_connected_disconnected(uint8_t event, uint16_t conn_handle, uint8_t addr_type, const uint8_t *addr);
242244

243245
// Call this when a characteristic is written to.
244246
void mp_bluetooth_gatts_on_write(uint16_t conn_handle, uint16_t value_handle);
@@ -267,7 +269,7 @@ void mp_bluetooth_gattc_on_descriptor_result(uint16_t conn_handle, uint16_t hand
267269
// Notify modbluetooth that a read has completed with data (or notify/indicate data available, use `event` to disambiguate).
268270
// Note: these functions are to be called in a group protected by MICROPY_PY_BLUETOOTH_ENTER/EXIT.
269271
// _start returns the number of bytes to submit to the calls to _chunk, followed by a call to _end.
270-
size_t mp_bluetooth_gattc_on_data_available_start(uint16_t event, uint16_t conn_handle, uint16_t value_handle, size_t data_len, mp_uint_t *atomic_state_out);
272+
size_t mp_bluetooth_gattc_on_data_available_start(uint8_t event, uint16_t conn_handle, uint16_t value_handle, size_t data_len, mp_uint_t *atomic_state_out);
271273
void mp_bluetooth_gattc_on_data_available_chunk(const uint8_t *data, size_t data_len);
272274
void mp_bluetooth_gattc_on_data_available_end(mp_uint_t atomic_state);
273275

extmod/nimble/modbluetooth_nimble.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* The MIT License (MIT)
55
*
66
* Copyright (c) 2019 Damien P. George
7-
* Copyright (c) 2019 Jim Mussared
7+
* Copyright (c) 2019-2020 Jim Mussared
88
*
99
* Permission is hereby granted, free of charge, to any person obtaining a copy
1010
* of this software and associated documentation files (the "Software"), to deal
@@ -612,7 +612,7 @@ int mp_bluetooth_gatts_set_buffer(uint16_t value_handle, size_t len, bool append
612612

613613
#if MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE
614614

615-
STATIC void gattc_on_data_available(uint16_t event, uint16_t conn_handle, uint16_t value_handle, const struct os_mbuf *om) {
615+
STATIC void gattc_on_data_available(uint8_t event, uint16_t conn_handle, uint16_t value_handle, const struct os_mbuf *om) {
616616
size_t len = OS_MBUF_PKTLEN(om);
617617
mp_uint_t atomic_state;
618618
len = mp_bluetooth_gattc_on_data_available_start(event, conn_handle, value_handle, len, &atomic_state);

py/ringbuf.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ static inline int ringbuf_get(ringbuf_t *r) {
6363
return v;
6464
}
6565

66+
static inline int ringbuf_peek(ringbuf_t *r) {
67+
if (r->iget == r->iput) {
68+
return -1;
69+
}
70+
return r->buf[r->iget];
71+
}
72+
6673
static inline int ringbuf_put(ringbuf_t *r, uint8_t v) {
6774
uint32_t iput_new = r->iput + 1;
6875
if (iput_new >= r->size) {

0 commit comments

Comments
 (0)
0