mirror of
https://github.com/micropython/micropython.git
synced 2026-01-06 12:10:13 +01:00
all: Reformat C and Python source code with tools/codeformat.py.
This is run with uncrustify 0.70.1, and black 19.10b0.
This commit is contained in:
@@ -107,7 +107,7 @@ STATIC mp_obj_t bluetooth_uuid_make_new(const mp_obj_type_t *type, size_t n_args
|
||||
self->type = MP_BLUETOOTH_UUID_TYPE_128;
|
||||
int uuid_i = 32;
|
||||
for (int i = 0; i < uuid_bufinfo.len; i++) {
|
||||
char c = ((char*)uuid_bufinfo.buf)[i];
|
||||
char c = ((char *)uuid_bufinfo.buf)[i];
|
||||
if (c == '-') {
|
||||
continue;
|
||||
}
|
||||
@@ -121,10 +121,10 @@ STATIC mp_obj_t bluetooth_uuid_make_new(const mp_obj_type_t *type, size_t n_args
|
||||
}
|
||||
if (uuid_i % 2 == 0) {
|
||||
// lower nibble
|
||||
self->data[uuid_i/2] |= c;
|
||||
self->data[uuid_i / 2] |= c;
|
||||
} else {
|
||||
// upper nibble
|
||||
self->data[uuid_i/2] = c << 4;
|
||||
self->data[uuid_i / 2] = c << 4;
|
||||
}
|
||||
}
|
||||
if (uuid_i > 0) {
|
||||
@@ -143,7 +143,8 @@ STATIC mp_obj_t bluetooth_uuid_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
|
||||
// Use the QSTR hash function.
|
||||
return MP_OBJ_NEW_SMALL_INT(qstr_compute_hash(self->data, self->type));
|
||||
}
|
||||
default: return MP_OBJ_NULL; // op not supported
|
||||
default:
|
||||
return MP_OBJ_NULL; // op not supported
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,7 +324,7 @@ STATIC mp_obj_t bluetooth_ble_config(size_t n_args, const mp_obj_t *args, mp_map
|
||||
// Get old buffer sizes and pointers
|
||||
uint8_t *old_ringbuf_buf = self->ringbuf.buf;
|
||||
size_t old_ringbuf_alloc = self->ringbuf.size;
|
||||
uint8_t *old_irq_data_buf = (uint8_t*)self->irq_data_data.data;
|
||||
uint8_t *old_irq_data_buf = (uint8_t *)self->irq_data_data.data;
|
||||
size_t old_irq_data_alloc = self->irq_data_data_alloc;
|
||||
|
||||
// Atomically update the ringbuf and irq data
|
||||
@@ -355,7 +356,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bluetooth_ble_config_obj, 1, bluetooth_ble_con
|
||||
STATIC mp_obj_t bluetooth_ble_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_handler, ARG_trigger };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_handler, MP_ARG_OBJ|MP_ARG_REQUIRED, {.u_rom_obj = MP_ROM_NONE} },
|
||||
{ MP_QSTR_handler, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_rom_obj = MP_ROM_NONE} },
|
||||
{ MP_QSTR_trigger, MP_ARG_INT, {.u_int = MP_BLUETOOTH_IRQ_ALL} },
|
||||
};
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
@@ -367,7 +368,7 @@ STATIC mp_obj_t bluetooth_ble_irq(size_t n_args, const mp_obj_t *pos_args, mp_ma
|
||||
|
||||
// Update the callback.
|
||||
MICROPY_PY_BLUETOOTH_ENTER
|
||||
mp_obj_bluetooth_ble_t* o = MP_OBJ_TO_PTR(MP_STATE_VM(bluetooth));
|
||||
mp_obj_bluetooth_ble_t *o = MP_OBJ_TO_PTR(MP_STATE_VM(bluetooth));
|
||||
o->irq_handler = callback;
|
||||
o->irq_trigger = args[ARG_trigger].u_int;
|
||||
MICROPY_PY_BLUETOOTH_EXIT
|
||||
@@ -426,7 +427,7 @@ STATIC int bluetooth_gatts_register_service(mp_obj_t uuid_in, mp_obj_t character
|
||||
mp_obj_t characteristic_obj;
|
||||
|
||||
// Lists of characteristic uuids and flags.
|
||||
mp_obj_bluetooth_uuid_t **characteristic_uuids = m_new(mp_obj_bluetooth_uuid_t*, len);
|
||||
mp_obj_bluetooth_uuid_t **characteristic_uuids = m_new(mp_obj_bluetooth_uuid_t *, len);
|
||||
uint8_t *characteristic_flags = m_new(uint8_t, len);
|
||||
|
||||
// Flattened list of descriptor uuids and flags. Grows (realloc) as more descriptors are encountered.
|
||||
@@ -471,7 +472,7 @@ STATIC int bluetooth_gatts_register_service(mp_obj_t uuid_in, mp_obj_t character
|
||||
}
|
||||
|
||||
// Grow the flattened uuids and flags arrays with this many more descriptors.
|
||||
descriptor_uuids = m_renew(mp_obj_bluetooth_uuid_t*, descriptor_uuids, descriptor_index, descriptor_index + num_descriptors[characteristic_index]);
|
||||
descriptor_uuids = m_renew(mp_obj_bluetooth_uuid_t *, descriptor_uuids, descriptor_index, descriptor_index + num_descriptors[characteristic_index]);
|
||||
descriptor_flags = m_renew(uint8_t, descriptor_flags, descriptor_index, descriptor_index + num_descriptors[characteristic_index]);
|
||||
|
||||
// Also grow the handles array.
|
||||
@@ -520,7 +521,7 @@ STATIC mp_obj_t bluetooth_ble_gatts_register_services(mp_obj_t self_in, mp_obj_t
|
||||
|
||||
mp_obj_tuple_t *result = MP_OBJ_TO_PTR(mp_obj_new_tuple(len, NULL));
|
||||
|
||||
uint16_t **handles = m_new0(uint16_t*, len);
|
||||
uint16_t **handles = m_new0(uint16_t *, len);
|
||||
size_t *num_handles = m_new0(size_t, len);
|
||||
|
||||
// TODO: Add a `append` kwarg (defaulting to False) to make this behavior optional.
|
||||
@@ -622,7 +623,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(bluetooth_ble_gap_disconnect_obj, bluetooth_ble
|
||||
|
||||
STATIC mp_obj_t bluetooth_ble_gatts_read(mp_obj_t self_in, mp_obj_t value_handle_in) {
|
||||
size_t len = 0;
|
||||
uint8_t* buf;
|
||||
uint8_t *buf;
|
||||
mp_bluetooth_gatts_read(mp_obj_get_int(value_handle_in), &buf, &len);
|
||||
return mp_obj_new_bytes(buf, len);
|
||||
}
|
||||
@@ -756,7 +757,7 @@ STATIC const mp_obj_type_t bluetooth_ble_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_BLE,
|
||||
.make_new = bluetooth_ble_make_new,
|
||||
.locals_dict = (void*)&bluetooth_ble_locals_dict,
|
||||
.locals_dict = (void *)&bluetooth_ble_locals_dict,
|
||||
};
|
||||
|
||||
STATIC const mp_rom_map_elem_t mp_module_bluetooth_globals_table[] = {
|
||||
@@ -772,14 +773,14 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_bluetooth_globals, mp_module_bluetooth_glo
|
||||
|
||||
const mp_obj_module_t mp_module_ubluetooth = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&mp_module_bluetooth_globals,
|
||||
.globals = (mp_obj_dict_t *)&mp_module_bluetooth_globals,
|
||||
};
|
||||
|
||||
// Helpers
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
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_b, size_t n_i8, mp_obj_bluetooth_uuid_t *uuid, mp_obj_str_t *bytes_data) {
|
||||
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_b, size_t n_i8, mp_obj_bluetooth_uuid_t *uuid, mp_obj_str_t *bytes_data) {
|
||||
assert(ringbuf_avail(ringbuf) >= n_u16 * 2 + n_u8 + (bytes_addr ? 6 : 0) + n_b + n_i8 + (uuid ? 1 : 0) + (bytes_data ? 1 : 0));
|
||||
int j = 0;
|
||||
|
||||
@@ -793,7 +794,7 @@ STATIC void ringbuf_extract(ringbuf_t* ringbuf, mp_obj_tuple_t *data_tuple, size
|
||||
bytes_addr->len = 6;
|
||||
for (int i = 0; i < bytes_addr->len; ++i) {
|
||||
// cast away const, this is actually bt->irq_addr_bytes.
|
||||
((uint8_t*)bytes_addr->data)[i] = ringbuf_get(ringbuf);
|
||||
((uint8_t *)bytes_addr->data)[i] = ringbuf_get(ringbuf);
|
||||
}
|
||||
data_tuple->items[j++] = MP_OBJ_FROM_PTR(bytes_addr);
|
||||
}
|
||||
@@ -815,7 +816,7 @@ STATIC void ringbuf_extract(ringbuf_t* ringbuf, mp_obj_tuple_t *data_tuple, size
|
||||
bytes_data->len = ringbuf_get(ringbuf);
|
||||
for (int i = 0; i < bytes_data->len; ++i) {
|
||||
// cast away const, this is actually bt->irq_data_bytes.
|
||||
((uint8_t*)bytes_data->data)[i] = ringbuf_get(ringbuf);
|
||||
((uint8_t *)bytes_data->data)[i] = ringbuf_get(ringbuf);
|
||||
}
|
||||
data_tuple->items[j++] = MP_OBJ_FROM_PTR(bytes_data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user