Skip to content

Commit 747f2cf

Browse files
committed
Add subclass support to displayio.
Also, swap make_news to accept a kwarg map and refine param checking. Fixes adafruit#1237
1 parent 72d993d commit 747f2cf

41 files changed

Lines changed: 132 additions & 163 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

shared-bindings/_stage/Layer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
//| it shouldn't be used on its own.
5252
//|
5353
STATIC mp_obj_t layer_make_new(const mp_obj_type_t *type, size_t n_args,
54-
size_t n_kw, const mp_obj_t *args) {
55-
mp_arg_check_num(n_args, n_kw, 4, 5, false);
54+
const mp_obj_t *args, mp_map_t *kw_args) {
55+
mp_arg_check_num(n_args, kw_args, 4, 5, false);
5656

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

shared-bindings/_stage/Text.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
//| it shouldn't be used on its own.
5252
//|
5353
STATIC mp_obj_t text_make_new(const mp_obj_type_t *type, size_t n_args,
54-
size_t n_kw, const mp_obj_t *args) {
55-
mp_arg_check_num(n_args, n_kw, 5, 5, false);
54+
const mp_obj_t *args, mp_map_t *kw_args) {
55+
mp_arg_check_num(n_args, kw_args, 5, 5, false);
5656

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

shared-bindings/analogio/AnalogIn.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@
5858
//| :param ~microcontroller.Pin pin: the pin to read from
5959
//|
6060
STATIC mp_obj_t analogio_analogin_make_new(const mp_obj_type_t *type,
61-
mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
61+
mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
6262
// check number of arguments
63-
mp_arg_check_num(n_args, n_kw, 1, 1, false);
63+
mp_arg_check_num(n_args, kw_args, 1, 1, false);
6464

6565
// 1st argument is the pin
6666
mp_obj_t pin_obj = args[0];

shared-bindings/analogio/AnalogOut.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@
5858
//|
5959
//| :param ~microcontroller.Pin pin: the pin to output to
6060
//|
61-
STATIC mp_obj_t analogio_analogout_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
61+
STATIC mp_obj_t analogio_analogout_make_new(const mp_obj_type_t *type, mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
6262
// check arguments
63-
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
63+
mp_arg_check_num(n_args, kw_args, 1, 1, false);
6464

6565
assert_pin(args[0], false);
6666
const mcu_pin_obj_t *pin = MP_OBJ_TO_PTR(args[0]);

shared-bindings/audiobusio/I2SOut.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,7 @@
9393
//| pass
9494
//| print("stopped")
9595
//|
96-
STATIC mp_obj_t audiobusio_i2sout_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
97-
mp_arg_check_num(n_args, n_kw, 3, 4, true);
98-
mp_map_t kw_args;
99-
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
96+
STATIC mp_obj_t audiobusio_i2sout_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
10097
enum { ARG_bit_clock, ARG_word_select, ARG_data, ARG_left_justified };
10198
static const mp_arg_t allowed_args[] = {
10299
{ MP_QSTR_bit_clock, MP_ARG_OBJ | MP_ARG_REQUIRED },
@@ -105,7 +102,7 @@ STATIC mp_obj_t audiobusio_i2sout_make_new(const mp_obj_type_t *type, size_t n_a
105102
{ MP_QSTR_left_justified, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_bool = false} },
106103
};
107104
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
108-
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
105+
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
109106

110107
mp_obj_t bit_clock_obj = args[ARG_bit_clock].u_obj;
111108
assert_pin(bit_clock_obj, false);

shared-bindings/audiobusio/PDMIn.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@
8787
//| with audiobusio.PDMIn(board.MICROPHONE_CLOCK, board.MICROPHONE_DATA, sample_rate=16000, bit_depth=16) as mic:
8888
//| mic.record(b, len(b))
8989
//|
90-
STATIC mp_obj_t audiobusio_pdmin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
91-
enum { ARG_sample_rate, ARG_bit_depth, ARG_mono, ARG_oversample, ARG_startup_delay };
92-
mp_map_t kw_args;
93-
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
90+
STATIC mp_obj_t audiobusio_pdmin_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
91+
enum { ARG_clock_pin, ARG_data_pin, ARG_sample_rate, ARG_bit_depth, ARG_mono, ARG_oversample, ARG_startup_delay };
9492
static const mp_arg_t allowed_args[] = {
95-
{ MP_QSTR_sample_rate, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 16000} },
93+
{ MP_QSTR_clock_pin, MP_ARG_REQUIRED | MP_ARG_OBJ },
94+
{ MP_QSTR_data_pin, MP_ARG_REQUIRED | MP_ARG_OBJ },
95+
{ MP_QSTR_sample_rate, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 16000} },
9696
{ MP_QSTR_bit_depth, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 8} },
9797
{ MP_QSTR_mono, MP_ARG_KW_ONLY | MP_ARG_BOOL,{.u_bool = true} },
9898
{ MP_QSTR_oversample, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 64} },
@@ -102,14 +102,14 @@ STATIC mp_obj_t audiobusio_pdmin_make_new(const mp_obj_type_t *type, size_t n_ar
102102
static const float STARTUP_DELAY_DEFAULT = 0.110F;
103103

104104
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
105-
mp_arg_parse_all(n_args - 2, pos_args + 2, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
105+
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
106106

107-
mp_obj_t clock_pin_obj = pos_args[0];
107+
mp_obj_t clock_pin_obj = args[ARG_clock_pin].u_obj;
108108
assert_pin(clock_pin_obj, false);
109109
const mcu_pin_obj_t *clock_pin = MP_OBJ_TO_PTR(clock_pin_obj);
110110
assert_pin_free(clock_pin);
111111

112-
mp_obj_t data_pin_obj = pos_args[1];
112+
mp_obj_t data_pin_obj = args[ARG_data_pin].u_obj;
113113
assert_pin(data_pin_obj, false);
114114
const mcu_pin_obj_t *data_pin = MP_OBJ_TO_PTR(data_pin_obj);
115115
assert_pin_free(data_pin);

shared-bindings/audioio/AudioOut.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,15 @@
9393
//| pass
9494
//| print("stopped")
9595
//|
96-
STATIC mp_obj_t audioio_audioout_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
97-
mp_arg_check_num(n_args, n_kw, 1, 2, true);
98-
mp_map_t kw_args;
99-
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
96+
STATIC mp_obj_t audioio_audioout_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
10097
enum { ARG_left_channel, ARG_right_channel, ARG_quiescent_value };
10198
static const mp_arg_t allowed_args[] = {
10299
{ MP_QSTR_left_channel, MP_ARG_OBJ | MP_ARG_REQUIRED },
103100
{ MP_QSTR_right_channel, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = mp_const_none} },
104101
{ MP_QSTR_quiescent_value, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x8000} },
105102
};
106103
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
107-
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
104+
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
108105

109106
mp_obj_t left_channel_obj = args[ARG_left_channel].u_obj;
110107
assert_pin(left_channel_obj, false);

shared-bindings/audioio/Mixer.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,7 @@
7373
//| time.sleep(1)
7474
//| print("stopped")
7575
//|
76-
STATIC mp_obj_t audioio_mixer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
77-
mp_arg_check_num(n_args, n_kw, 0, 2, true);
78-
mp_map_t kw_args;
79-
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
76+
STATIC mp_obj_t audioio_mixer_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
8077
enum { ARG_voice_count, ARG_buffer_size, ARG_channel_count, ARG_bits_per_sample, ARG_samples_signed, ARG_sample_rate };
8178
static const mp_arg_t allowed_args[] = {
8279
{ MP_QSTR_voice_count, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 2} },
@@ -87,7 +84,7 @@ STATIC mp_obj_t audioio_mixer_make_new(const mp_obj_type_t *type, size_t n_args,
8784
{ MP_QSTR_sample_rate, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 8000} },
8885
};
8986
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
90-
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
87+
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
9188

9289
mp_int_t voice_count = args[ARG_voice_count].u_int;
9390
if (voice_count < 1 || voice_count > 255) {

shared-bindings/audioio/RawSample.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,15 @@
7373
//| time.sleep(1)
7474
//| dac.stop()
7575
//|
76-
STATIC mp_obj_t audioio_rawsample_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
77-
mp_arg_check_num(n_args, n_kw, 1, 2, true);
78-
mp_map_t kw_args;
79-
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
76+
STATIC mp_obj_t audioio_rawsample_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
8077
enum { ARG_buffer, ARG_channel_count, ARG_sample_rate };
8178
static const mp_arg_t allowed_args[] = {
8279
{ MP_QSTR_buffer, MP_ARG_OBJ | MP_ARG_REQUIRED },
8380
{ MP_QSTR_channel_count, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 1 } },
8481
{ MP_QSTR_sample_rate, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 8000} },
8582
};
8683
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);
84+
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
8885

8986
audioio_rawsample_obj_t *self = m_new_obj(audioio_rawsample_obj_t);
9087
self->base.type = &audioio_rawsample_type;

shared-bindings/audioio/WaveFile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@
6767
//| pass
6868
//| print("stopped")
6969
//|
70-
STATIC mp_obj_t audioio_wavefile_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
71-
mp_arg_check_num(n_args, n_kw, 1, 1, true);
70+
STATIC mp_obj_t audioio_wavefile_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
71+
mp_arg_check_num(n_args, kw_args, 1, 1, false);
7272

7373
audioio_wavefile_obj_t *self = m_new_obj(audioio_wavefile_obj_t);
7474
self->base.type = &audioio_wavefile_type;

0 commit comments

Comments
 (0)