Skip to content

Commit bd3c36c

Browse files
committed
fixup m0 and nrf
1 parent 12c8b00 commit bd3c36c

12 files changed

Lines changed: 58 additions & 90 deletions

File tree

shared-bindings/bleio/Address.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,18 @@ STATIC uint8_t xdigit_8b_value(byte nibble1, byte nibble2) {
6969
//| - `bleio.AddressType.RANDOM_PRIVATE_RESOLVABLE`
7070
//| - `bleio.AddressType.RANDOM_PRIVATE_NON_RESOLVABLE`
7171
//|
72-
STATIC mp_obj_t bleio_address_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
73-
mp_arg_check_num(n_args, n_kw, 1, 1, true);
74-
bleio_address_obj_t *self = m_new_obj(bleio_address_obj_t);
75-
self->base.type = &bleio_address_type;
76-
self->type = ADDRESS_PUBLIC;
77-
78-
mp_map_t kw_args;
79-
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
80-
72+
STATIC mp_obj_t bleio_address_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
8173
enum { ARG_address };
8274
static const mp_arg_t allowed_args[] = {
8375
{ MP_QSTR_address, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
8476
};
8577

8678
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
87-
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
79+
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
80+
81+
bleio_address_obj_t *self = m_new_obj(bleio_address_obj_t);
82+
self->base.type = &bleio_address_type;
83+
self->type = ADDRESS_PUBLIC;
8884

8985
const mp_obj_t address = args[ARG_address].u_obj;
9086

shared-bindings/bleio/Broadcaster.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,19 @@
5959
//| :param float interval: how often to broadcast
6060
//|
6161

62-
STATIC mp_obj_t bleio_broadcaster_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
63-
mp_arg_check_num(n_args, n_kw, 0, 1, true);
64-
bleio_broadcaster_obj_t *self = m_new_obj(bleio_broadcaster_obj_t);
65-
self->base.type = &bleio_broadcaster_type;
66-
67-
mp_map_t kw_args;
68-
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
69-
62+
STATIC mp_obj_t bleio_broadcaster_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
7063
enum { ARG_interval };
7164
static const mp_arg_t allowed_args[] = {
7265
{ MP_QSTR_interval, MP_ARG_OBJ, {.u_obj = MP_OBJ_NEW_SMALL_INT(1)} },
7366
};
7467

7568
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
76-
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
69+
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
7770

7871
mp_float_t interval = mp_obj_get_float(args[ARG_interval].u_obj);
7972

73+
bleio_broadcaster_obj_t *self = m_new_obj(bleio_broadcaster_obj_t);
74+
self->base.type = &bleio_broadcaster_type;
8075
// Do port-specific initialization. interval will be validated.
8176
common_hal_bleio_broadcaster_construct(self, interval);
8277

shared-bindings/bleio/Characteristic.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,7 @@
5151
//| :param bool write: Clients may write this characteristic; a response will be sent back
5252
//| :param bool write_no_response: Clients may write this characteristic; no response will be sent back
5353
//|
54-
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) {
55-
mp_arg_check_num(n_args, n_kw, 1, 1, true);
56-
bleio_characteristic_obj_t *self = m_new_obj(bleio_characteristic_obj_t);
57-
self->base.type = &bleio_characteristic_type;
58-
59-
mp_map_t kw_args;
60-
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
61-
54+
STATIC mp_obj_t bleio_characteristic_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
6255
enum {
6356
ARG_uuid, ARG_broadcast, ARG_indicate, ARG_notify, ARG_read, ARG_write, ARG_write_no_response,
6457
};
@@ -73,14 +66,16 @@ STATIC mp_obj_t bleio_characteristic_make_new(const mp_obj_type_t *type, size_t
7366
};
7467

7568
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
76-
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
69+
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
7770

7871
const mp_obj_t uuid = args[ARG_uuid].u_obj;
7972

8073
if (!MP_OBJ_IS_TYPE(uuid, &bleio_uuid_type)) {
8174
mp_raise_ValueError(translate("Expected a UUID"));
8275
}
8376

77+
bleio_characteristic_obj_t *self = m_new_obj(bleio_characteristic_obj_t);
78+
self->base.type = &bleio_characteristic_type;
8479
self->uuid = MP_OBJ_TO_PTR(uuid);
8580

8681
bleio_characteristic_properties_t properties;

shared-bindings/bleio/CharacteristicBuffer.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,15 @@
4444
//| :param int buffer_size: Size of ring buffer that stores incoming data coming from client.
4545
//| Must be >= 1.
4646
//|
47-
STATIC mp_obj_t bleio_characteristic_buffer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
48-
mp_arg_check_num(n_args, n_kw, 1, 2, true);
49-
bleio_characteristic_buffer_obj_t *self = m_new_obj(bleio_characteristic_buffer_obj_t);
50-
self->base.type = &bleio_characteristic_buffer_type;
51-
52-
mp_map_t kw_args;
53-
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
54-
47+
STATIC mp_obj_t bleio_characteristic_buffer_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
5548
enum { ARG_characteristic, ARG_buffer_size, };
5649
static const mp_arg_t allowed_args[] = {
5750
{ MP_QSTR_characteristic, MP_ARG_REQUIRED | MP_ARG_OBJ },
5851
{ MP_QSTR_buffer_size, MP_ARG_REQUIRED | MP_ARG_INT },
5952
};
6053

6154
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
62-
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
55+
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
6356

6457
const mp_obj_t characteristic = args[ARG_characteristic].u_obj;
6558
const int buffer_size = args[ARG_buffer_size].u_int;
@@ -72,6 +65,8 @@ STATIC mp_obj_t bleio_characteristic_buffer_make_new(const mp_obj_type_t *type,
7265
mp_raise_ValueError(translate("Expected a Characteristic"));
7366
}
7467

68+
bleio_characteristic_buffer_obj_t *self = m_new_obj(bleio_characteristic_buffer_obj_t);
69+
self->base.type = &bleio_characteristic_buffer_type;
7570
self->characteristic = MP_OBJ_TO_PTR(characteristic);
7671

7772
common_hal_bleio_characteristic_buffer_construct(self, self->characteristic, buffer_size);

shared-bindings/bleio/Descriptor.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,28 +71,23 @@ enum {
7171
//|
7272
//| The descriptor uuid. (read-only)
7373
//|
74-
STATIC mp_obj_t bleio_descriptor_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
75-
mp_arg_check_num(n_args, n_kw, 0, 1, true);
76-
bleio_descriptor_obj_t *self = m_new_obj(bleio_descriptor_obj_t);
77-
self->base.type = type;
78-
79-
mp_map_t kw_args;
80-
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
81-
74+
STATIC mp_obj_t bleio_descriptor_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
8275
enum { ARG_uuid };
8376
static const mp_arg_t allowed_args[] = {
8477
{ MP_QSTR_uuid, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
8578
};
8679

8780
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
88-
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
81+
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
8982

9083
const mp_obj_t uuid_arg = args[ARG_uuid].u_obj;
9184

9285
if (!MP_OBJ_IS_TYPE(uuid_arg, &bleio_uuid_type)) {
9386
mp_raise_ValueError(translate("Expected a UUID"));
9487
}
9588

89+
bleio_descriptor_obj_t *self = m_new_obj(bleio_descriptor_obj_t);
90+
self->base.type = type;
9691
bleio_uuid_obj_t *uuid = MP_OBJ_TO_PTR(uuid_arg);
9792
common_hal_bleio_descriptor_construct(self, uuid);
9893

shared-bindings/bleio/Peripheral.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,30 +82,25 @@ static const char default_name[] = "CIRCUITPY";
8282
//| :param str name: The name used when advertising this peripheral
8383
//|
8484

85-
STATIC mp_obj_t bleio_peripheral_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
86-
mp_arg_check_num(n_args, n_kw, 0, 1, true);
87-
bleio_peripheral_obj_t *self = m_new_obj(bleio_peripheral_obj_t);
88-
self->base.type = &bleio_peripheral_type;
89-
self->service_list = mp_obj_new_list(0, NULL);
90-
self->notif_handler = mp_const_none;
91-
92-
mp_map_t kw_args;
93-
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
94-
85+
STATIC mp_obj_t bleio_peripheral_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
9586
enum { ARG_services, ARG_name };
9687
static const mp_arg_t allowed_args[] = {
9788
{ MP_QSTR_services, MP_ARG_OBJ, {.u_obj = mp_const_none} },
9889
{ MP_QSTR_name, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
9990
};
10091

10192
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
102-
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
93+
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
10394

10495
// If services is not an iterable, an exception will be thrown.
10596
mp_obj_iter_buf_t iter_buf;
10697
mp_obj_t iterable = mp_getiter(args[ARG_services].u_obj, &iter_buf);
10798
mp_obj_t service;
10899

100+
bleio_peripheral_obj_t *self = m_new_obj(bleio_peripheral_obj_t);
101+
self->base.type = &bleio_peripheral_type;
102+
self->service_list = mp_obj_new_list(0, NULL);
103+
self->notif_handler = mp_const_none;
109104
while ((service = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) {
110105
if (!MP_OBJ_IS_TYPE(service, &bleio_service_type)) {
111106
mp_raise_ValueError(translate("services includes an object that is not a Service"));

shared-bindings/bleio/ScanEntry.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ STATIC mp_obj_t scanentry_get_service_uuids(mp_obj_t self_in) {
248248
mp_obj_t entries = mp_obj_new_list(0, NULL);
249249
for (size_t i = 0; i < uuids_len / sizeof(uint16_t); ++i) {
250250
const mp_obj_t uuid_int = mp_obj_new_int(uuids[sizeof(uint16_t) * i] | (uuids[sizeof(uint16_t) * i + 1] << 8));
251-
const mp_obj_t uuid_obj = bleio_uuid_type.make_new(&bleio_uuid_type, 1, 0, &uuid_int);
251+
const mp_obj_t uuid_obj = bleio_uuid_type.make_new(&bleio_uuid_type, 1, &uuid_int, NULL);
252252

253253
mp_obj_list_append(entries, uuid_obj);
254254
}

shared-bindings/bleio/Scanner.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*/
2626

2727
#include "py/objproperty.h"
28+
#include "py/runtime.h"
2829
#include "shared-bindings/bleio/ScanEntry.h"
2930
#include "shared-bindings/bleio/Scanner.h"
3031

@@ -77,7 +78,9 @@ STATIC void bleio_scanner_print(const mp_print_t *print, mp_obj_t self_in, mp_pr
7778
mp_printf(print, "Scanner(interval: %d window: %d)", self->interval, self->window);
7879
}
7980

80-
STATIC mp_obj_t bleio_scanner_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
81+
STATIC mp_obj_t bleio_scanner_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *all_args, mp_map_t *kw_args) {
82+
mp_arg_check_num(n_args, kw_args, 0, 0, false);
83+
8184
bleio_scanner_obj_t *self = m_new_obj(bleio_scanner_obj_t);
8285
self->base.type = type;
8386

shared-bindings/bleio/Service.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,7 @@
4949
//| :param bool secondary: If the service is a secondary one
5050
//|
5151

52-
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) {
53-
mp_arg_check_num(n_args, n_kw, 2, 3, true);
54-
bleio_service_obj_t *self = m_new_obj(bleio_service_obj_t);
55-
self->char_list = mp_obj_new_list(0, NULL);
56-
self->base.type = &bleio_service_type;
57-
self->device = mp_const_none;
58-
self->handle = 0xFFFF;
59-
60-
mp_map_t kw_args;
61-
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
62-
52+
STATIC mp_obj_t bleio_service_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
6353
enum { ARG_uuid, ARG_characteristics, ARG_secondary };
6454
static const mp_arg_t allowed_args[] = {
6555
{ MP_QSTR_uuid, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = mp_const_none} },
@@ -68,16 +58,20 @@ STATIC mp_obj_t bleio_service_make_new(const mp_obj_type_t *type, size_t n_args,
6858
};
6959

7060
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
71-
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
72-
73-
self->is_secondary = args[ARG_secondary].u_bool;
61+
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
7462

7563
const mp_obj_t uuid = args[ARG_uuid].u_obj;
7664

7765
if (!MP_OBJ_IS_TYPE(uuid, &bleio_uuid_type)) {
7866
mp_raise_ValueError(translate("Expected a UUID"));
7967
}
8068

69+
bleio_service_obj_t *self = m_new_obj(bleio_service_obj_t);
70+
self->char_list = mp_obj_new_list(0, NULL);
71+
self->base.type = &bleio_service_type;
72+
self->device = mp_const_none;
73+
self->handle = 0xFFFF;
74+
self->is_secondary = args[ARG_secondary].u_bool;
8175
self->uuid = MP_OBJ_TO_PTR(uuid);
8276

8377
// If characteristics is not an iterable, an exception will be thrown.

shared-bindings/bleio/UUID.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
//|
5252
//| :param int/buffer value: The uuid value to encapsulate
5353
//|
54-
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) {
55-
mp_arg_check_num(n_args, n_kw, 1, 1, false);
54+
STATIC mp_obj_t bleio_uuid_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
55+
mp_arg_check_num(n_args, kw_args, 1, 1, false);
5656

5757
bleio_uuid_obj_t *self = m_new_obj(bleio_uuid_obj_t);
5858
self->base.type = type;

0 commit comments

Comments
 (0)