Skip to content

Commit ebfd9ff

Browse files
jimmodpgeorge
authored andcommitted
extmod/modbluetooth: Fix sign compare and unused variable warnings.
1 parent c37fd78 commit ebfd9ff

File tree

4 files changed

+48
-23
lines changed

4 files changed

+48
-23
lines changed

extmod/btstack/btstack.mk

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,11 @@ endif
4444

4545
LIB_SRC_C += $(SRC_BTSTACK)
4646

47-
#$(BUILD)/lib/btstack/src/classic/btstack_link_key_db_static.o: CFLAGS += -Wno-error=pointer-arith
48-
49-
# Incorrect %u, should be %lu.
50-
$(BUILD)/lib/btstack/src/classic/a2dp_source.o: CFLAGS += -Wno-error=format=
51-
$(BUILD)/lib/btstack/src/classic/btstack_sbc_decoder_bluedroid.o: CFLAGS += -Wno-error=format=
52-
$(BUILD)/lib/btstack/src/classic/btstack_link_key_db_tlv.o: CFLAGS += -Wno-error=format=
53-
$(BUILD)/lib/btstack/src/classic/goep_client.o: CFLAGS += -Wno-error=format=
54-
$(BUILD)/lib/btstack/src/ble/le_device_db_tlv.o: CFLAGS += -Wno-error=format=
47+
# Suppress some warnings.
48+
BTSTACK_WARNING_CFLAGS = -Wno-old-style-definition -Wno-unused-variable -Wno-unused-parameter
49+
ifneq ($(CC),clang)
50+
BTSTACK_WARNING_CFLAGS += -Wno-format
51+
endif
52+
$(BUILD)/lib/btstack/src/%.o: CFLAGS += $(BTSTACK_WARNING_CFLAGS)
5553

5654
endif

extmod/btstack/modbluetooth_btstack.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ STATIC mp_obj_bluetooth_uuid_t create_mp_uuid(uint16_t uuid16, const uint8_t *uu
6969
}
7070

7171
STATIC void btstack_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) {
72+
(void)channel;
73+
(void)size;
7274
DEBUG_EVENT_printf("btstack_packet_handler(packet_type=%u, channel=%u, packet=%p, size=%u)\n", packet_type, channel, packet, size);
7375
if (packet_type != HCI_EVENT_PACKET) {
7476
return;
@@ -204,6 +206,8 @@ STATIC void btstack_packet_handler(uint8_t packet_type, uint16_t channel, uint8_
204206

205207
#if MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE
206208
STATIC void btstack_packet_handler_write_with_response(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) {
209+
(void)channel;
210+
(void)size;
207211
DEBUG_EVENT_printf("btstack_packet_handler_write_with_response(packet_type=%u, channel=%u, packet=%p, size=%u)\n", packet_type, channel, packet, size);
208212
if (packet_type != HCI_EVENT_PACKET) {
209213
return;
@@ -402,6 +406,7 @@ int mp_bluetooth_gatts_register_service_begin(bool append) {
402406
}
403407

404408
STATIC uint16_t att_read_callback(hci_con_handle_t connection_handle, uint16_t att_handle, uint16_t offset, uint8_t *buffer, uint16_t buffer_size) {
409+
(void)connection_handle;
405410
DEBUG_EVENT_printf("btstack: att_read_callback (handle: %u, offset: %u, buffer: %p, size: %u)\n", att_handle, offset, buffer, buffer_size);
406411
mp_bluetooth_gatts_db_entry_t *entry = mp_bluetooth_gatts_db_lookup(MP_STATE_PORT(bluetooth_btstack_root_pointers)->gatts_db, att_handle);
407412
if (!entry) {
@@ -413,6 +418,8 @@ STATIC uint16_t att_read_callback(hci_con_handle_t connection_handle, uint16_t a
413418
}
414419

415420
STATIC int att_write_callback(hci_con_handle_t connection_handle, uint16_t att_handle, uint16_t transaction_mode, uint16_t offset, uint8_t *buffer, uint16_t buffer_size) {
421+
(void)offset;
422+
(void)transaction_mode;
416423
DEBUG_EVENT_printf("btstack: att_write_callback (handle: %u, mode: %u, offset: %u, buffer: %p, size: %u)\n", att_handle, transaction_mode, offset, buffer, buffer_size);
417424
mp_bluetooth_gatts_db_entry_t *entry = mp_bluetooth_gatts_db_lookup(MP_STATE_PORT(bluetooth_btstack_root_pointers)->gatts_db, att_handle);
418425
if (!entry) {
@@ -483,9 +490,9 @@ int mp_bluetooth_gatts_register_service(mp_obj_bluetooth_uuid_t *service_uuid, m
483490
++handle_index;
484491

485492
for (size_t j = 0; j < num_descriptors[i]; ++j) {
486-
uint16_t props = descriptor_flags[descriptor_index] | ATT_PROPERTY_DYNAMIC;
487-
uint16_t read_permission = ATT_SECURITY_NONE;
488-
uint16_t write_permission = ATT_SECURITY_NONE;
493+
props = descriptor_flags[descriptor_index] | ATT_PROPERTY_DYNAMIC;
494+
read_permission = ATT_SECURITY_NONE;
495+
write_permission = ATT_SECURITY_NONE;
489496

490497
if (descriptor_uuids[descriptor_index]->type == MP_BLUETOOTH_UUID_TYPE_16) {
491498
handles[handle_index] = att_db_util_add_descriptor_uuid16(get_uuid16(descriptor_uuids[descriptor_index]), props, read_permission, write_permission, NULL, 0);
@@ -558,6 +565,7 @@ int mp_bluetooth_gap_disconnect(uint16_t conn_handle) {
558565
STATIC btstack_timer_source_t scan_duration_timeout;
559566

560567
STATIC void hci_initialization_timeout_handler(btstack_timer_source_t *ds) {
568+
(void)ds;
561569
mp_bluetooth_gap_scan_stop();
562570
}
563571

extmod/modbluetooth.c

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ STATIC mp_obj_t bluetooth_handle_errno(int err) {
8282
// ----------------------------------------------------------------------------
8383

8484
STATIC mp_obj_t bluetooth_uuid_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
85+
(void)type;
86+
8587
mp_arg_check_num(n_args, n_kw, 1, 1, false);
8688

8789
mp_obj_bluetooth_uuid_t *self = m_new_obj(mp_obj_bluetooth_uuid_t);
@@ -106,7 +108,7 @@ STATIC mp_obj_t bluetooth_uuid_make_new(const mp_obj_type_t *type, size_t n_args
106108
// Assume UUID string (e.g. '6E400001-B5A3-F393-E0A9-E50E24DCCA9E')
107109
self->type = MP_BLUETOOTH_UUID_TYPE_128;
108110
int uuid_i = 32;
109-
for (int i = 0; i < uuid_bufinfo.len; i++) {
111+
for (size_t i = 0; i < uuid_bufinfo.len; i++) {
110112
char c = ((char *)uuid_bufinfo.buf)[i];
111113
if (c == '-') {
112114
continue;
@@ -173,6 +175,8 @@ STATIC mp_obj_t bluetooth_uuid_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_
173175
}
174176

175177
STATIC void bluetooth_uuid_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
178+
(void)kind;
179+
176180
mp_obj_bluetooth_uuid_t *self = MP_OBJ_TO_PTR(self_in);
177181
mp_printf(print, "UUID%u(%s", self->type * 8, self->type <= 4 ? "0x" : "'");
178182
for (int i = 0; i < self->type; ++i) {
@@ -187,7 +191,7 @@ STATIC void bluetooth_uuid_print(const mp_print_t *print, mp_obj_t self_in, mp_p
187191
mp_printf(print, ")");
188192
}
189193

190-
mp_int_t bluetooth_uuid_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
194+
STATIC mp_int_t bluetooth_uuid_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
191195
mp_obj_bluetooth_uuid_t *self = MP_OBJ_TO_PTR(self_in);
192196

193197
if (flags != MP_BUFFER_READ) {
@@ -203,7 +207,7 @@ mp_int_t bluetooth_uuid_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo,
203207
#if MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE
204208

205209
STATIC void ringbuf_put_uuid(ringbuf_t *ringbuf, mp_obj_bluetooth_uuid_t *uuid) {
206-
assert(ringbuf_free(ringbuf) >= uuid->type + 1);
210+
assert(ringbuf_free(ringbuf) >= (size_t)uuid->type + 1);
207211
ringbuf_put(ringbuf, uuid->type);
208212
for (int i = 0; i < uuid->type; ++i) {
209213
ringbuf_put(ringbuf, uuid->data[i]);
@@ -236,6 +240,10 @@ STATIC const mp_obj_type_t bluetooth_uuid_type = {
236240
// ----------------------------------------------------------------------------
237241

238242
STATIC mp_obj_t bluetooth_ble_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
243+
(void)type;
244+
(void)n_args;
245+
(void)n_kw;
246+
(void)all_args;
239247
if (MP_STATE_VM(bluetooth) == MP_OBJ_NULL) {
240248
mp_obj_bluetooth_ble_t *o = m_new0(mp_obj_bluetooth_ble_t, 1);
241249
o->base.type = &bluetooth_ble_type;
@@ -511,6 +519,7 @@ STATIC int bluetooth_gatts_register_service(mp_obj_t uuid_in, mp_obj_t character
511519
}
512520

513521
STATIC mp_obj_t bluetooth_ble_gatts_register_services(mp_obj_t self_in, mp_obj_t services_in) {
522+
(void)self_in;
514523
mp_obj_t len_in = mp_obj_len(services_in);
515524
size_t len = mp_obj_get_int(len_in);
516525
mp_obj_iter_buf_t iter_buf;
@@ -529,7 +538,7 @@ STATIC mp_obj_t bluetooth_ble_gatts_register_services(mp_obj_t self_in, mp_obj_t
529538
return bluetooth_handle_errno(err);
530539
}
531540

532-
int i = 0;
541+
size_t i = 0;
533542
while ((service_tuple_obj = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) {
534543
// (uuid, chars)
535544
mp_obj_t *service_items;
@@ -552,7 +561,7 @@ STATIC mp_obj_t bluetooth_ble_gatts_register_services(mp_obj_t self_in, mp_obj_t
552561
// TODO: Also the Generic Access service characteristics?
553562
for (i = 0; i < len; ++i) {
554563
mp_obj_tuple_t *service_handles = MP_OBJ_TO_PTR(mp_obj_new_tuple(num_handles[i], NULL));
555-
for (int j = 0; j < num_handles[i]; ++j) {
564+
for (size_t j = 0; j < num_handles[i]; ++j) {
556565
service_handles->items[j] = MP_OBJ_NEW_SMALL_INT(handles[i][j]);
557566
}
558567
result->items[i] = MP_OBJ_FROM_PTR(service_handles);
@@ -603,6 +612,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_gap_scan_obj, 1, 4, blu
603612
#endif // MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE
604613

605614
STATIC mp_obj_t bluetooth_ble_gap_disconnect(mp_obj_t self_in, mp_obj_t conn_handle_in) {
615+
(void)self_in;
606616
uint16_t conn_handle = mp_obj_get_int(conn_handle_in);
607617
int err = mp_bluetooth_gap_disconnect(conn_handle);
608618
if (err == 0) {
@@ -620,6 +630,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(bluetooth_ble_gap_disconnect_obj, bluetooth_ble
620630
// ----------------------------------------------------------------------------
621631

622632
STATIC mp_obj_t bluetooth_ble_gatts_read(mp_obj_t self_in, mp_obj_t value_handle_in) {
633+
(void)self_in;
623634
size_t len = 0;
624635
uint8_t *buf;
625636
mp_bluetooth_gatts_read(mp_obj_get_int(value_handle_in), &buf, &len);
@@ -628,6 +639,7 @@ STATIC mp_obj_t bluetooth_ble_gatts_read(mp_obj_t self_in, mp_obj_t value_handle
628639
STATIC MP_DEFINE_CONST_FUN_OBJ_2(bluetooth_ble_gatts_read_obj, bluetooth_ble_gatts_read);
629640

630641
STATIC mp_obj_t bluetooth_ble_gatts_write(mp_obj_t self_in, mp_obj_t value_handle_in, mp_obj_t data) {
642+
(void)self_in;
631643
mp_buffer_info_t bufinfo = {0};
632644
mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ);
633645
int err = mp_bluetooth_gatts_write(mp_obj_get_int(value_handle_in), bufinfo.buf, bufinfo.len);
@@ -669,12 +681,14 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_gatts_set_buffer_obj, 3
669681
#if MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE
670682

671683
STATIC mp_obj_t bluetooth_ble_gattc_discover_services(mp_obj_t self_in, mp_obj_t conn_handle_in) {
684+
(void)self_in;
672685
mp_int_t conn_handle = mp_obj_get_int(conn_handle_in);
673686
return bluetooth_handle_errno(mp_bluetooth_gattc_discover_primary_services(conn_handle));
674687
}
675688
STATIC MP_DEFINE_CONST_FUN_OBJ_2(bluetooth_ble_gattc_discover_services_obj, bluetooth_ble_gattc_discover_services);
676689

677690
STATIC mp_obj_t bluetooth_ble_gattc_discover_characteristics(size_t n_args, const mp_obj_t *args) {
691+
(void)n_args;
678692
mp_int_t conn_handle = mp_obj_get_int(args[1]);
679693
mp_int_t start_handle = mp_obj_get_int(args[2]);
680694
mp_int_t end_handle = mp_obj_get_int(args[3]);
@@ -683,6 +697,7 @@ STATIC mp_obj_t bluetooth_ble_gattc_discover_characteristics(size_t n_args, cons
683697
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_gattc_discover_characteristics_obj, 4, 4, bluetooth_ble_gattc_discover_characteristics);
684698

685699
STATIC mp_obj_t bluetooth_ble_gattc_discover_descriptors(size_t n_args, const mp_obj_t *args) {
700+
(void)n_args;
686701
mp_int_t conn_handle = mp_obj_get_int(args[1]);
687702
mp_int_t start_handle = mp_obj_get_int(args[2]);
688703
mp_int_t end_handle = mp_obj_get_int(args[3]);
@@ -691,6 +706,7 @@ STATIC mp_obj_t bluetooth_ble_gattc_discover_descriptors(size_t n_args, const mp
691706
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_gattc_discover_descriptors_obj, 4, 4, bluetooth_ble_gattc_discover_descriptors);
692707

693708
STATIC mp_obj_t bluetooth_ble_gattc_read(mp_obj_t self_in, mp_obj_t conn_handle_in, mp_obj_t value_handle_in) {
709+
(void)self_in;
694710
mp_int_t conn_handle = mp_obj_get_int(conn_handle_in);
695711
mp_int_t value_handle = mp_obj_get_int(value_handle_in);
696712
return bluetooth_handle_errno(mp_bluetooth_gattc_read(conn_handle, value_handle));
@@ -777,23 +793,23 @@ const mp_obj_module_t mp_module_ubluetooth = {
777793

778794
STATIC void ringbuf_extract(ringbuf_t *ringbuf, mp_obj_tuple_t *data_tuple, size_t n_u16, size_t n_u8, mp_obj_str_t *bytes_addr, size_t n_i8, mp_obj_bluetooth_uuid_t *uuid, mp_obj_str_t *bytes_data) {
779795
assert(ringbuf_avail(ringbuf) >= n_u16 * 2 + n_u8 + (bytes_addr ? 6 : 0) + n_i8 + (uuid ? 1 : 0) + (bytes_data ? 1 : 0));
780-
int j = 0;
796+
size_t j = 0;
781797

782-
for (int i = 0; i < n_u16; ++i) {
798+
for (size_t i = 0; i < n_u16; ++i) {
783799
data_tuple->items[j++] = MP_OBJ_NEW_SMALL_INT(ringbuf_get16(ringbuf));
784800
}
785801
if (n_u8) {
786802
data_tuple->items[j++] = MP_OBJ_NEW_SMALL_INT(ringbuf_get(ringbuf));
787803
}
788804
if (bytes_addr) {
789805
bytes_addr->len = 6;
790-
for (int i = 0; i < bytes_addr->len; ++i) {
806+
for (size_t i = 0; i < bytes_addr->len; ++i) {
791807
// cast away const, this is actually bt->irq_addr_bytes.
792808
((uint8_t *)bytes_addr->data)[i] = ringbuf_get(ringbuf);
793809
}
794810
data_tuple->items[j++] = MP_OBJ_FROM_PTR(bytes_addr);
795811
}
796-
for (int i = 0; i < n_i8; ++i) {
812+
for (size_t i = 0; i < n_i8; ++i) {
797813
// Note the int8_t got packed into the ringbuf as a uint8_t.
798814
data_tuple->items[j++] = MP_OBJ_NEW_SMALL_INT((int8_t)ringbuf_get(ringbuf));
799815
}
@@ -806,7 +822,7 @@ STATIC void ringbuf_extract(ringbuf_t *ringbuf, mp_obj_tuple_t *data_tuple, size
806822
// that's what's available here in bt->irq_data_bytes.
807823
if (bytes_data) {
808824
bytes_data->len = ringbuf_get(ringbuf);
809-
for (int i = 0; i < bytes_data->len; ++i) {
825+
for (size_t i = 0; i < bytes_data->len; ++i) {
810826
// cast away const, this is actually bt->irq_data_bytes.
811827
((uint8_t *)bytes_data->data)[i] = ringbuf_get(ringbuf);
812828
}
@@ -817,6 +833,7 @@ STATIC void ringbuf_extract(ringbuf_t *ringbuf, mp_obj_tuple_t *data_tuple, size
817833
}
818834

819835
STATIC mp_obj_t bluetooth_ble_invoke_irq(mp_obj_t none_in) {
836+
(void)none_in;
820837
// This is always executing in schedule context.
821838

822839
mp_obj_bluetooth_ble_t *o = MP_OBJ_TO_PTR(MP_STATE_VM(bluetooth));
@@ -976,7 +993,7 @@ void mp_bluetooth_gap_on_scan_result(uint8_t addr_type, const uint8_t *addr, uin
976993
// Note conversion of int8_t rssi to uint8_t. Must un-convert on the way out.
977994
ringbuf_put(&o->ringbuf, (uint8_t)rssi);
978995
ringbuf_put(&o->ringbuf, data_len);
979-
for (int i = 0; i < data_len; ++i) {
996+
for (size_t i = 0; i < data_len; ++i) {
980997
ringbuf_put(&o->ringbuf, data[i]);
981998
}
982999
}
@@ -1036,7 +1053,7 @@ size_t mp_bluetooth_gattc_on_data_available_start(uint16_t event, uint16_t conn_
10361053

10371054
void mp_bluetooth_gattc_on_data_available_chunk(const uint8_t *data, size_t data_len) {
10381055
mp_obj_bluetooth_ble_t *o = MP_OBJ_TO_PTR(MP_STATE_VM(bluetooth));
1039-
for (int i = 0; i < data_len; ++i) {
1056+
for (size_t i = 0; i < data_len; ++i) {
10401057
ringbuf_put(&o->ringbuf, data[i]);
10411058
}
10421059
}

ports/unix/btstack_usb.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
#include "lib/btstack/src/btstack.h"
3737
#include "lib/btstack/platform/embedded/btstack_run_loop_embedded.h"
38+
#include "lib/btstack/platform/embedded/hal_cpu.h"
39+
#include "lib/btstack/platform/embedded/hal_time_ms.h"
3840

3941
#include "extmod/btstack/modbluetooth_btstack.h"
4042

0 commit comments

Comments
 (0)