Add subclass support to displayio.
Also, swap make_news to accept a kwarg map and refine param checking. Fixes #1237
This commit is contained in:
parent
72d993d60c
commit
747f2cfe26
|
@ -51,8 +51,8 @@
|
|||
//| it shouldn't be used on its own.
|
||||
//|
|
||||
STATIC mp_obj_t layer_make_new(const mp_obj_type_t *type, size_t n_args,
|
||||
size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 4, 5, false);
|
||||
const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
mp_arg_check_num(n_args, kw_args, 4, 5, false);
|
||||
|
||||
layer_obj_t *self = m_new_obj(layer_obj_t);
|
||||
self->base.type = type;
|
||||
|
|
|
@ -51,8 +51,8 @@
|
|||
//| it shouldn't be used on its own.
|
||||
//|
|
||||
STATIC mp_obj_t text_make_new(const mp_obj_type_t *type, size_t n_args,
|
||||
size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 5, 5, false);
|
||||
const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
mp_arg_check_num(n_args, kw_args, 5, 5, false);
|
||||
|
||||
text_obj_t *self = m_new_obj(text_obj_t);
|
||||
self->base.type = type;
|
||||
|
|
|
@ -58,9 +58,9 @@
|
|||
//| :param ~microcontroller.Pin pin: the pin to read from
|
||||
//|
|
||||
STATIC mp_obj_t analogio_analogin_make_new(const mp_obj_type_t *type,
|
||||
mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
// check number of arguments
|
||||
mp_arg_check_num(n_args, n_kw, 1, 1, false);
|
||||
mp_arg_check_num(n_args, kw_args, 1, 1, false);
|
||||
|
||||
// 1st argument is the pin
|
||||
mp_obj_t pin_obj = args[0];
|
||||
|
|
|
@ -58,9 +58,9 @@
|
|||
//|
|
||||
//| :param ~microcontroller.Pin pin: the pin to output to
|
||||
//|
|
||||
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) {
|
||||
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) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
mp_arg_check_num(n_args, kw_args, 1, 1, false);
|
||||
|
||||
assert_pin(args[0], false);
|
||||
const mcu_pin_obj_t *pin = MP_OBJ_TO_PTR(args[0]);
|
||||
|
|
|
@ -93,10 +93,7 @@
|
|||
//| pass
|
||||
//| print("stopped")
|
||||
//|
|
||||
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) {
|
||||
mp_arg_check_num(n_args, n_kw, 3, 4, true);
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
|
||||
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) {
|
||||
enum { ARG_bit_clock, ARG_word_select, ARG_data, ARG_left_justified };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ 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
|
|||
{ MP_QSTR_left_justified, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_bool = false} },
|
||||
};
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
mp_obj_t bit_clock_obj = args[ARG_bit_clock].u_obj;
|
||||
assert_pin(bit_clock_obj, false);
|
||||
|
|
|
@ -87,12 +87,12 @@
|
|||
//| with audiobusio.PDMIn(board.MICROPHONE_CLOCK, board.MICROPHONE_DATA, sample_rate=16000, bit_depth=16) as mic:
|
||||
//| mic.record(b, len(b))
|
||||
//|
|
||||
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) {
|
||||
enum { ARG_sample_rate, ARG_bit_depth, ARG_mono, ARG_oversample, ARG_startup_delay };
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
|
||||
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) {
|
||||
enum { ARG_clock_pin, ARG_data_pin, ARG_sample_rate, ARG_bit_depth, ARG_mono, ARG_oversample, ARG_startup_delay };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_sample_rate, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 16000} },
|
||||
{ MP_QSTR_clock_pin, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_data_pin, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_sample_rate, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 16000} },
|
||||
{ MP_QSTR_bit_depth, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 8} },
|
||||
{ MP_QSTR_mono, MP_ARG_KW_ONLY | MP_ARG_BOOL,{.u_bool = true} },
|
||||
{ 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
|
|||
static const float STARTUP_DELAY_DEFAULT = 0.110F;
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args - 2, pos_args + 2, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
mp_obj_t clock_pin_obj = pos_args[0];
|
||||
mp_obj_t clock_pin_obj = args[ARG_clock_pin].u_obj;
|
||||
assert_pin(clock_pin_obj, false);
|
||||
const mcu_pin_obj_t *clock_pin = MP_OBJ_TO_PTR(clock_pin_obj);
|
||||
assert_pin_free(clock_pin);
|
||||
|
||||
mp_obj_t data_pin_obj = pos_args[1];
|
||||
mp_obj_t data_pin_obj = args[ARG_data_pin].u_obj;
|
||||
assert_pin(data_pin_obj, false);
|
||||
const mcu_pin_obj_t *data_pin = MP_OBJ_TO_PTR(data_pin_obj);
|
||||
assert_pin_free(data_pin);
|
||||
|
|
|
@ -93,10 +93,7 @@
|
|||
//| pass
|
||||
//| print("stopped")
|
||||
//|
|
||||
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) {
|
||||
mp_arg_check_num(n_args, n_kw, 1, 2, true);
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
|
||||
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) {
|
||||
enum { ARG_left_channel, ARG_right_channel, ARG_quiescent_value };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_left_channel, MP_ARG_OBJ | MP_ARG_REQUIRED },
|
||||
|
@ -104,7 +101,7 @@ STATIC mp_obj_t audioio_audioout_make_new(const mp_obj_type_t *type, size_t n_ar
|
|||
{ MP_QSTR_quiescent_value, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x8000} },
|
||||
};
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
mp_obj_t left_channel_obj = args[ARG_left_channel].u_obj;
|
||||
assert_pin(left_channel_obj, false);
|
||||
|
|
|
@ -73,10 +73,7 @@
|
|||
//| time.sleep(1)
|
||||
//| print("stopped")
|
||||
//|
|
||||
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) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, 2, true);
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
|
||||
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) {
|
||||
enum { ARG_voice_count, ARG_buffer_size, ARG_channel_count, ARG_bits_per_sample, ARG_samples_signed, ARG_sample_rate };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ 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,
|
|||
{ MP_QSTR_sample_rate, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 8000} },
|
||||
};
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
mp_int_t voice_count = args[ARG_voice_count].u_int;
|
||||
if (voice_count < 1 || voice_count > 255) {
|
||||
|
|
|
@ -73,10 +73,7 @@
|
|||
//| time.sleep(1)
|
||||
//| dac.stop()
|
||||
//|
|
||||
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) {
|
||||
mp_arg_check_num(n_args, n_kw, 1, 2, true);
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
|
||||
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) {
|
||||
enum { ARG_buffer, ARG_channel_count, ARG_sample_rate };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_buffer, MP_ARG_OBJ | MP_ARG_REQUIRED },
|
||||
|
@ -84,7 +81,7 @@ STATIC mp_obj_t audioio_rawsample_make_new(const mp_obj_type_t *type, size_t n_a
|
|||
{ MP_QSTR_sample_rate, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 8000} },
|
||||
};
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
audioio_rawsample_obj_t *self = m_new_obj(audioio_rawsample_obj_t);
|
||||
self->base.type = &audioio_rawsample_type;
|
||||
|
|
|
@ -67,8 +67,8 @@
|
|||
//| pass
|
||||
//| print("stopped")
|
||||
//|
|
||||
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) {
|
||||
mp_arg_check_num(n_args, n_kw, 1, 1, true);
|
||||
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) {
|
||||
mp_arg_check_num(n_args, kw_args, 1, 1, false);
|
||||
|
||||
audioio_wavefile_obj_t *self = m_new_obj(audioio_wavefile_obj_t);
|
||||
self->base.type = &audioio_wavefile_type;
|
||||
|
|
|
@ -53,13 +53,7 @@
|
|||
//| :param int frequency: The clock frequency of the bus
|
||||
//| :param int timeout: The maximum clock stretching timeout in microseconds
|
||||
//|
|
||||
STATIC mp_obj_t bitbangio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
bitbangio_i2c_obj_t *self = m_new_obj(bitbangio_i2c_obj_t);
|
||||
raise_error_if_deinited(shared_module_bitbangio_i2c_deinited(self));
|
||||
self->base.type = &bitbangio_i2c_type;
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
|
||||
STATIC mp_obj_t bitbangio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_scl, ARG_sda, ARG_frequency, ARG_timeout };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_scl, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
|
@ -68,11 +62,15 @@ STATIC mp_obj_t bitbangio_i2c_make_new(const mp_obj_type_t *type, size_t n_args,
|
|||
{ MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 255} },
|
||||
};
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
assert_pin(args[ARG_scl].u_obj, false);
|
||||
assert_pin(args[ARG_sda].u_obj, false);
|
||||
const mcu_pin_obj_t* scl = MP_OBJ_TO_PTR(args[ARG_scl].u_obj);
|
||||
const mcu_pin_obj_t* sda = MP_OBJ_TO_PTR(args[ARG_sda].u_obj);
|
||||
|
||||
bitbangio_i2c_obj_t *self = m_new_obj(bitbangio_i2c_obj_t);
|
||||
raise_error_if_deinited(shared_module_bitbangio_i2c_deinited(self));
|
||||
self->base.type = &bitbangio_i2c_type;
|
||||
shared_module_bitbangio_i2c_construct(self, scl, sda, args[ARG_frequency].u_int, args[ARG_timeout].u_int);
|
||||
return (mp_obj_t)self;
|
||||
}
|
||||
|
|
|
@ -62,16 +62,13 @@
|
|||
//| onewire.write_bit(False)
|
||||
//| print(onewire.read_bit())
|
||||
//|
|
||||
STATIC mp_obj_t bitbangio_onewire_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
|
||||
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
|
||||
STATIC mp_obj_t bitbangio_onewire_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_pin };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_pin, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
};
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
assert_pin(args[ARG_pin].u_obj, false);
|
||||
const mcu_pin_obj_t* pin = MP_OBJ_TO_PTR(args[ARG_pin].u_obj);
|
||||
assert_pin_free(pin);
|
||||
|
|
|
@ -62,12 +62,7 @@
|
|||
//|
|
||||
|
||||
// TODO(tannewt): Support LSB SPI.
|
||||
STATIC mp_obj_t bitbangio_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
bitbangio_spi_obj_t *self = m_new_obj(bitbangio_spi_obj_t);
|
||||
self->base.type = &bitbangio_spi_type;
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
|
||||
STATIC mp_obj_t bitbangio_spi_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_clock, ARG_MOSI, ARG_MISO, ARG_baudrate, ARG_polarity, ARG_phase, ARG_bits, ARG_firstbit };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_clock, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
|
@ -75,13 +70,16 @@ STATIC mp_obj_t bitbangio_spi_make_new(const mp_obj_type_t *type, size_t n_args,
|
|||
{ MP_QSTR_MISO, MP_ARG_OBJ, {.u_obj = mp_const_none} },
|
||||
};
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
assert_pin(args[ARG_clock].u_obj, false);
|
||||
assert_pin(args[ARG_MOSI].u_obj, true);
|
||||
assert_pin(args[ARG_MISO].u_obj, true);
|
||||
const mcu_pin_obj_t* clock = MP_OBJ_TO_PTR(args[ARG_clock].u_obj);
|
||||
const mcu_pin_obj_t* mosi = MP_OBJ_TO_PTR(args[ARG_MOSI].u_obj);
|
||||
const mcu_pin_obj_t* miso = MP_OBJ_TO_PTR(args[ARG_MISO].u_obj);
|
||||
|
||||
bitbangio_spi_obj_t *self = m_new_obj(bitbangio_spi_obj_t);
|
||||
self->base.type = &bitbangio_spi_type;
|
||||
shared_module_bitbangio_spi_construct(self, clock, mosi, miso);
|
||||
return (mp_obj_t)self;
|
||||
}
|
||||
|
|
|
@ -60,12 +60,9 @@
|
|||
//| :param int frequency: The clock frequency in Hertz
|
||||
//| :param int timeout: The maximum clock stretching timeut - (used only for bitbangio.I2C; ignored for busio.I2C)
|
||||
//|
|
||||
STATIC mp_obj_t busio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
STATIC mp_obj_t busio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
busio_i2c_obj_t *self = m_new_obj(busio_i2c_obj_t);
|
||||
self->base.type = &busio_i2c_type;
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
|
||||
enum { ARG_scl, ARG_sda, ARG_frequency, ARG_timeout };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_scl, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
|
@ -74,7 +71,7 @@ STATIC mp_obj_t busio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, siz
|
|||
{ MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 255} },
|
||||
};
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
assert_pin(args[ARG_scl].u_obj, false);
|
||||
assert_pin(args[ARG_sda].u_obj, false);
|
||||
const mcu_pin_obj_t* scl = MP_OBJ_TO_PTR(args[ARG_scl].u_obj);
|
||||
|
|
|
@ -62,16 +62,13 @@
|
|||
//| onewire.write_bit(False)
|
||||
//| print(onewire.read_bit())
|
||||
//|
|
||||
STATIC mp_obj_t busio_onewire_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
|
||||
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
|
||||
STATIC mp_obj_t busio_onewire_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_pin };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_pin, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
};
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
assert_pin(args[ARG_pin].u_obj, false);
|
||||
const mcu_pin_obj_t* pin = MP_OBJ_TO_PTR(args[ARG_pin].u_obj);
|
||||
assert_pin_free(pin);
|
||||
|
|
|
@ -71,12 +71,9 @@
|
|||
//|
|
||||
|
||||
// TODO(tannewt): Support LSB SPI.
|
||||
STATIC mp_obj_t busio_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
STATIC mp_obj_t busio_spi_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
busio_spi_obj_t *self = m_new_obj(busio_spi_obj_t);
|
||||
self->base.type = &busio_spi_type;
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
|
||||
enum { ARG_clock, ARG_MOSI, ARG_MISO };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_clock, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
|
@ -84,7 +81,7 @@ STATIC mp_obj_t busio_spi_make_new(const mp_obj_type_t *type, size_t n_args, siz
|
|||
{ MP_QSTR_MISO, MP_ARG_OBJ, {.u_obj = mp_const_none} },
|
||||
};
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
assert_pin(args[ARG_clock].u_obj, false);
|
||||
assert_pin(args[ARG_MOSI].u_obj, true);
|
||||
assert_pin(args[ARG_MISO].u_obj, true);
|
||||
|
|
|
@ -69,16 +69,13 @@ typedef struct {
|
|||
extern const busio_uart_parity_obj_t busio_uart_parity_even_obj;
|
||||
extern const busio_uart_parity_obj_t busio_uart_parity_odd_obj;
|
||||
|
||||
STATIC mp_obj_t busio_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
STATIC mp_obj_t busio_uart_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
// Always initially allocate the UART object within the long-lived heap.
|
||||
// This is needed to avoid crashes with certain UART implementations which
|
||||
// cannot accomodate being moved after creation. (See
|
||||
// https://github.com/adafruit/circuitpython/issues/1056)
|
||||
busio_uart_obj_t *self = m_new_ll_obj(busio_uart_obj_t);
|
||||
self->base.type = &busio_uart_type;
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
|
||||
enum { ARG_tx, ARG_rx, ARG_baudrate, ARG_bits, ARG_parity, ARG_stop, ARG_timeout, ARG_receiver_buffer_size};
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_tx, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
|
@ -91,7 +88,7 @@ STATIC mp_obj_t busio_uart_make_new(const mp_obj_type_t *type, size_t n_args, si
|
|||
{ MP_QSTR_receiver_buffer_size, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 64} },
|
||||
};
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
assert_pin(args[ARG_rx].u_obj, true);
|
||||
const mcu_pin_obj_t* rx = MP_OBJ_TO_PTR(args[ARG_rx].u_obj);
|
||||
|
|
|
@ -62,8 +62,8 @@
|
|||
//| :param ~microcontroller.Pin pin: The pin to control
|
||||
//|
|
||||
STATIC mp_obj_t digitalio_digitalinout_make_new(const mp_obj_type_t *type,
|
||||
mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 1, 1, true);
|
||||
mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
mp_arg_check_num(n_args, kw_args, 1, 1, false);
|
||||
|
||||
digitalio_digitalinout_obj_t *self = m_new_obj(digitalio_digitalinout_obj_t);
|
||||
self->base.type = &digitalio_digitalinout_type;
|
||||
|
|
|
@ -55,8 +55,8 @@
|
|||
//| :param int height: The number of values high
|
||||
//| :param int value_count: The number of possible pixel values.
|
||||
//|
|
||||
STATIC mp_obj_t displayio_bitmap_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
|
||||
mp_arg_check_num(n_args, n_kw, 3, 3, false);
|
||||
STATIC mp_obj_t displayio_bitmap_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
mp_arg_check_num(n_args, kw_args, 3, 3, false);
|
||||
uint32_t width = mp_obj_get_int(pos_args[0]);
|
||||
uint32_t height = mp_obj_get_int(pos_args[1]);
|
||||
uint32_t value_count = mp_obj_get_int(pos_args[2]);
|
||||
|
|
|
@ -52,8 +52,8 @@
|
|||
//|
|
||||
// TODO(tannewt): Add support for other color formats.
|
||||
//|
|
||||
STATIC mp_obj_t displayio_colorconverter_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, 0, true);
|
||||
STATIC mp_obj_t displayio_colorconverter_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
mp_arg_check_num(n_args, kw_args, 0, 0, false);
|
||||
|
||||
displayio_colorconverter_t *self = m_new_obj(displayio_colorconverter_t);
|
||||
self->base.type = &displayio_colorconverter_type;
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include "py/binary.h"
|
||||
#include "py/objproperty.h"
|
||||
#include "py/runtime.h"
|
||||
#include "shared-bindings/displayio/Group.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "shared-bindings/util.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
@ -51,7 +52,7 @@
|
|||
//|
|
||||
//| Create a FourWire object associated with the given pins.
|
||||
//|
|
||||
STATIC mp_obj_t displayio_fourwire_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
|
||||
STATIC mp_obj_t displayio_fourwire_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
mp_raise_NotImplementedError(translate("displayio is a work in progress"));
|
||||
return mp_const_none;
|
||||
}
|
||||
|
@ -73,7 +74,11 @@ MP_DEFINE_CONST_FUN_OBJ_KW(displayio_fourwire_send_obj, 1, displayio_fourwire_ob
|
|||
//|
|
||||
STATIC mp_obj_t displayio_fourwire_obj_show(mp_obj_t self_in, mp_obj_t group_in) {
|
||||
displayio_fourwire_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
displayio_group_t* group = MP_OBJ_TO_PTR(group_in);
|
||||
mp_obj_t native_layer = mp_instance_cast_to_native_base(group_in, &displayio_group_type);
|
||||
if (native_layer == MP_OBJ_NULL) {
|
||||
mp_raise_ValueError(translate("Must be a Group subclass."));
|
||||
}
|
||||
displayio_group_t* group = MP_OBJ_TO_PTR(native_layer);
|
||||
common_hal_displayio_fourwire_show(self, group);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
|
|
@ -49,16 +49,13 @@
|
|||
//|
|
||||
//| :param int max_size: The maximum group size.
|
||||
//|
|
||||
STATIC mp_obj_t displayio_group_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, 0, true);
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
|
||||
STATIC mp_obj_t displayio_group_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_max_size };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_max_size, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 4} },
|
||||
};
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
mp_int_t max_size = args[ARG_max_size].u_int;
|
||||
if (max_size < 1) {
|
||||
|
|
|
@ -78,8 +78,8 @@
|
|||
//|
|
||||
//| :param file file: The open bitmap file
|
||||
//|
|
||||
STATIC mp_obj_t displayio_ondiskbitmap_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
|
||||
mp_arg_check_num(n_args, n_kw, 1, 1, false);
|
||||
STATIC mp_obj_t displayio_ondiskbitmap_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
mp_arg_check_num(n_args, kw_args, 1, 1, false);
|
||||
|
||||
if (!MP_OBJ_IS_TYPE(pos_args[0], &mp_type_fileio)) {
|
||||
mp_raise_TypeError(translate("file must be a file opened in byte mode"));
|
||||
|
|
|
@ -54,16 +54,13 @@
|
|||
// TODO(tannewt): Add support for other color formats.
|
||||
// TODO(tannewt): Add support for 8-bit alpha blending.
|
||||
//|
|
||||
STATIC mp_obj_t displayio_palette_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
|
||||
mp_arg_check_num(n_args, n_kw, 1, 1, true);
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
|
||||
STATIC mp_obj_t displayio_palette_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_color_count };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_color_count, MP_ARG_INT | MP_ARG_REQUIRED },
|
||||
{ MP_QSTR_color_count, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
};
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
displayio_palette_t *self = m_new_obj(displayio_palette_t);
|
||||
self->base.type = &displayio_palette_type;
|
||||
|
|
|
@ -53,19 +53,16 @@
|
|||
//| :param bool mirror_x: When true the left boundary is mirrored to the right.
|
||||
//| :param bool mirror_y: When true the top boundary is mirrored to the bottom.
|
||||
//|
|
||||
STATIC mp_obj_t displayio_shape_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
|
||||
mp_arg_check_num(n_args, n_kw, 2, 4, true);
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
|
||||
STATIC mp_obj_t displayio_shape_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_width, ARG_height, ARG_mirror_x, ARG_mirror_y };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_width, MP_ARG_INT | MP_ARG_REQUIRED },
|
||||
{ MP_QSTR_height, MP_ARG_INT | MP_ARG_REQUIRED },
|
||||
{ MP_QSTR_width, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_height, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_mirror_x, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
|
||||
{ MP_QSTR_mirror_y, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
|
||||
};
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
displayio_shape_t *self = m_new_obj(displayio_shape_t);
|
||||
self->base.type = &displayio_shape_type;
|
||||
|
|
|
@ -67,20 +67,17 @@ void unpack_position(mp_obj_t position_obj, int16_t* x, int16_t* y) {
|
|||
//| palette lookup, a gradient, a pattern or a color transformer.
|
||||
//|
|
||||
//|
|
||||
STATIC mp_obj_t displayio_sprite_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
|
||||
mp_arg_check_num(n_args, n_kw, 1, 4, true);
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
|
||||
STATIC mp_obj_t displayio_sprite_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_bitmap, ARG_pixel_shader, ARG_position, ARG_width, ARG_height };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_bitmap, MP_ARG_OBJ | MP_ARG_REQUIRED },
|
||||
{ MP_QSTR_bitmap, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_pixel_shader, MP_ARG_OBJ | MP_ARG_KW_ONLY },
|
||||
{ MP_QSTR_position, MP_ARG_OBJ | MP_ARG_KW_ONLY },
|
||||
{ MP_QSTR_width, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1} },
|
||||
{ MP_QSTR_height, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1} },
|
||||
};
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
mp_obj_t bitmap = args[ARG_bitmap].u_obj;
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@
|
|||
//| button presses start to be recorded.
|
||||
//|
|
||||
STATIC mp_obj_t gamepad_make_new(const mp_obj_type_t *type, size_t n_args,
|
||||
size_t n_kw, const mp_obj_t *args) {
|
||||
const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
if (n_args > 8) {
|
||||
mp_raise_TypeError(translate("too many arguments"));
|
||||
}
|
||||
|
|
|
@ -64,12 +64,9 @@ STATIC mp_obj_t mp_obj_new_i2cslave_i2c_slave_request(i2cslave_i2c_slave_obj_t *
|
|||
//| :param tuple addresses: The I2C addresses to respond to (how many is hw dependent).
|
||||
//| :param bool smbus: Use SMBUS timings if the hardware supports it
|
||||
//|
|
||||
STATIC mp_obj_t i2cslave_i2c_slave_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
STATIC mp_obj_t i2cslave_i2c_slave_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
i2cslave_i2c_slave_obj_t *self = m_new_obj(i2cslave_i2c_slave_obj_t);
|
||||
self->base.type = &i2cslave_i2c_slave_type;
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
|
||||
enum { ARG_scl, ARG_sda, ARG_addresses, ARG_smbus };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_scl, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
|
@ -78,7 +75,7 @@ STATIC mp_obj_t i2cslave_i2c_slave_make_new(const mp_obj_type_t *type, size_t n_
|
|||
{ MP_QSTR_smbus, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
|
||||
};
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
assert_pin(args[ARG_scl].u_obj, false);
|
||||
assert_pin(args[ARG_sda].u_obj, false);
|
||||
|
@ -247,8 +244,8 @@ const mp_obj_type_t i2cslave_i2c_slave_type = {
|
|||
//| :param bool is_read: I2C Master read request
|
||||
//| :param bool is_restart: Repeated Start Condition
|
||||
//|
|
||||
STATIC mp_obj_t i2cslave_i2c_slave_request_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 4, 4, false);
|
||||
STATIC mp_obj_t i2cslave_i2c_slave_request_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
mp_arg_check_num(n_args, kw_args, 4, 4, false);
|
||||
return mp_obj_new_i2cslave_i2c_slave_request(args[0], mp_obj_get_int(args[1]), mp_obj_is_true(args[2]), mp_obj_is_true(args[3]));
|
||||
}
|
||||
|
||||
|
|
|
@ -85,31 +85,29 @@
|
|||
//| pwm.frequency = 880
|
||||
//| time.sleep(0.1)
|
||||
//|
|
||||
STATIC mp_obj_t pulseio_pwmout_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
mp_obj_t pin_obj = args[0];
|
||||
assert_pin(pin_obj, false);
|
||||
const mcu_pin_obj_t *pin = MP_OBJ_TO_PTR(pin_obj);
|
||||
assert_pin_free(pin);
|
||||
|
||||
// create PWM object from the given pin
|
||||
pulseio_pwmout_obj_t *self = m_new_obj(pulseio_pwmout_obj_t);
|
||||
self->base.type = &pulseio_pwmout_type;
|
||||
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, args + n_args);
|
||||
enum { ARG_duty_cycle, ARG_frequency, ARG_variable_frequency };
|
||||
STATIC mp_obj_t pulseio_pwmout_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
enum { ARG_pin, ARG_duty_cycle, ARG_frequency, ARG_variable_frequency };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_pin, MP_ARG_REQUIRED | MP_ARG_OBJ, },
|
||||
{ MP_QSTR_duty_cycle, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
|
||||
{ MP_QSTR_frequency, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 500} },
|
||||
{ MP_QSTR_variable_frequency, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
|
||||
};
|
||||
mp_arg_val_t parsed_args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args - 1, args + 1, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, parsed_args);
|
||||
mp_arg_parse_all(n_args, args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, parsed_args);
|
||||
|
||||
mp_obj_t pin_obj = parsed_args[ARG_pin].u_obj;
|
||||
assert_pin(pin_obj, false);
|
||||
const mcu_pin_obj_t *pin = MP_OBJ_TO_PTR(pin_obj);
|
||||
assert_pin_free(pin);
|
||||
|
||||
uint16_t duty_cycle = parsed_args[ARG_duty_cycle].u_int;
|
||||
uint32_t frequency = parsed_args[ARG_frequency].u_int;
|
||||
bool variable_frequency = parsed_args[ARG_variable_frequency].u_int;
|
||||
|
||||
// create PWM object from the given pin
|
||||
pulseio_pwmout_obj_t *self = m_new_obj(pulseio_pwmout_obj_t);
|
||||
self->base.type = &pulseio_pwmout_type;
|
||||
common_hal_pulseio_pwmout_construct(self, pin, duty_cycle, frequency, variable_frequency);
|
||||
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
|
|
|
@ -81,10 +81,7 @@
|
|||
//| # Resume with an 80 microsecond active pulse
|
||||
//| pulses.resume(80)
|
||||
//|
|
||||
STATIC mp_obj_t pulseio_pulsein_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
|
||||
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
|
||||
STATIC mp_obj_t pulseio_pulsein_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_pin, ARG_maxlen, ARG_idle_state };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_pin, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
|
@ -92,7 +89,7 @@ STATIC mp_obj_t pulseio_pulsein_make_new(const mp_obj_type_t *type, size_t n_arg
|
|||
{ MP_QSTR_idle_state, MP_ARG_BOOL, {.u_bool = false} },
|
||||
};
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
assert_pin(args[ARG_pin].u_obj, false);
|
||||
const mcu_pin_obj_t* pin = MP_OBJ_TO_PTR(args[ARG_pin].u_obj);
|
||||
assert_pin_free(pin);
|
||||
|
|
|
@ -68,8 +68,8 @@
|
|||
//| pulses[0] = 200
|
||||
//| pulse.send(pulses)
|
||||
//|
|
||||
STATIC mp_obj_t pulseio_pulseout_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 1, 1, true);
|
||||
STATIC mp_obj_t pulseio_pulseout_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
mp_arg_check_num(n_args, kw_args, 1, 1, false);
|
||||
mp_obj_t carrier_obj = args[0];
|
||||
|
||||
if (!MP_OBJ_IS_TYPE(carrier_obj, &pulseio_pwmout_type)) {
|
||||
|
|
|
@ -64,17 +64,14 @@
|
|||
//| print(position)
|
||||
//| last_position = position
|
||||
//|
|
||||
STATIC mp_obj_t rotaryio_incrementalencoder_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
|
||||
mp_arg_check_num(n_args, n_kw, 2, 2, true);
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
|
||||
STATIC mp_obj_t rotaryio_incrementalencoder_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_pin_a, ARG_pin_b };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_pin_a, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_pin_b, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
};
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
assert_pin(args[ARG_pin_a].u_obj, false);
|
||||
const mcu_pin_obj_t* pin_a = MP_OBJ_TO_PTR(args[ARG_pin_a].u_obj);
|
||||
|
|
|
@ -63,9 +63,9 @@ const rtc_rtc_obj_t rtc_rtc_obj = {{&rtc_rtc_type}};
|
|||
//|
|
||||
//| This class represents the onboard Real Time Clock. It is a singleton and will always return the same instance.
|
||||
//|
|
||||
STATIC mp_obj_t rtc_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t rtc_rtc_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
// No arguments
|
||||
mp_arg_check_num(n_args, n_kw, 0, 0, false);
|
||||
mp_arg_check_num(n_args, kw_args, 0, 0, false);
|
||||
|
||||
// return constant object
|
||||
return (mp_obj_t)&rtc_rtc_obj;
|
||||
|
|
|
@ -83,8 +83,8 @@ STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) {
|
|||
MP_DEFINE_CONST_FUN_OBJ_1(time_sleep_obj, time_sleep);
|
||||
|
||||
#if MICROPY_PY_COLLECTIONS
|
||||
mp_obj_t struct_time_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
if (n_args != 1) {
|
||||
mp_obj_t struct_time_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
if (n_args != 1 || kw_args != NULL || kw_args->used > 0) {
|
||||
mp_raise_TypeError(translate("time.struct_time() takes exactly 1 argument"));
|
||||
}
|
||||
if (!MP_OBJ_IS_TYPE(args[0], &mp_type_tuple) || ((mp_obj_tuple_t*) MP_OBJ_TO_PTR(args[0]))->len != 9) {
|
||||
|
@ -92,7 +92,7 @@ mp_obj_t struct_time_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
|
|||
}
|
||||
|
||||
mp_obj_tuple_t* tuple = MP_OBJ_TO_PTR(args[0]);
|
||||
return namedtuple_make_new(type, 9, 0, tuple->items);
|
||||
return namedtuple_make_new(type, 9, tuple->items, NULL);
|
||||
}
|
||||
|
||||
//| .. class:: struct_time((tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec, tm_wday, tm_yday, tm_isdst))
|
||||
|
@ -158,7 +158,7 @@ mp_obj_t struct_time_from_tm(timeutils_struct_time_t *tm) {
|
|||
mp_obj_new_int(-1), // tm_isdst is not supported
|
||||
};
|
||||
|
||||
return namedtuple_make_new((const mp_obj_type_t*)&struct_time_type_obj, 9, 0, elems);
|
||||
return namedtuple_make_new((const mp_obj_type_t*)&struct_time_type_obj, 9, elems, NULL);
|
||||
};
|
||||
|
||||
void struct_time_to_tm(mp_obj_t t, timeutils_struct_time_t *tm) {
|
||||
|
|
|
@ -61,9 +61,9 @@
|
|||
//| :param ~microcontroller.Pin pin: the pin to read from
|
||||
//|
|
||||
STATIC mp_obj_t touchio_touchin_make_new(const mp_obj_type_t *type,
|
||||
mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
// check number of arguments
|
||||
mp_arg_check_num(n_args, n_kw, 1, 1, false);
|
||||
mp_arg_check_num(n_args, kw_args, 1, 1, false);
|
||||
|
||||
// 1st argument is the pin
|
||||
mp_obj_t pin_obj = args[0];
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
//| Not currently dynamically supported.
|
||||
//|
|
||||
STATIC mp_obj_t usb_hid_device_make_new(const mp_obj_type_t *type,
|
||||
mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
//| to the ``usb_midi.ports`` tuple.
|
||||
//|
|
||||
|
||||
STATIC mp_obj_t usb_midi_portin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
|
||||
STATIC mp_obj_t usb_midi_portin_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
//| to the ``usb_midi.ports`` tuple.
|
||||
//|
|
||||
|
||||
STATIC mp_obj_t usb_midi_portout_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
|
||||
STATIC mp_obj_t usb_midi_portout_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,13 @@ void common_hal_displayio_group_append(displayio_group_t* self, mp_obj_t layer)
|
|||
if (self->size == self->max_size) {
|
||||
mp_raise_RuntimeError(translate("Group full"));
|
||||
}
|
||||
mp_obj_t native_layer = mp_instance_cast_to_native_base(layer, &displayio_group_type);
|
||||
if (native_layer == MP_OBJ_NULL) {
|
||||
native_layer = mp_instance_cast_to_native_base(layer, &displayio_sprite_type);
|
||||
}
|
||||
if (native_layer == MP_OBJ_NULL) {
|
||||
mp_raise_ValueError(translate("Layer must be a Group or Sprite subclass."));
|
||||
}
|
||||
self->children[self->size] = layer;
|
||||
self->size++;
|
||||
self->needs_refresh = true;
|
||||
|
|
|
@ -39,6 +39,8 @@ void displayio_refresh_display(void) {
|
|||
return;
|
||||
}
|
||||
if (refresh_queued(display)) {
|
||||
PORT->Group[1].DIRSET.reg = 1 << 22;
|
||||
|
||||
// We compute the pixels
|
||||
uint16_t x0 = 0;
|
||||
uint16_t y0 = 0;
|
||||
|
@ -53,10 +55,19 @@ void displayio_refresh_display(void) {
|
|||
for (uint16_t x = x0; x < x1; ++x) {
|
||||
uint16_t* pixel = &(((uint16_t*)buffer)[index]);
|
||||
*pixel = 0;
|
||||
if (display->current_group != NULL) {
|
||||
displayio_group_get_pixel(display->current_group, x, y, pixel);
|
||||
}
|
||||
|
||||
PORT->Group[1].OUTTGL.reg = 1 << 22;
|
||||
|
||||
//if (index == 0) {
|
||||
if (display->current_group != NULL) {
|
||||
displayio_group_get_pixel(display->current_group, x, y, pixel);
|
||||
}
|
||||
// } else {
|
||||
// *pixel = (((uint16_t*)buffer)[0]);
|
||||
// }
|
||||
|
||||
|
||||
PORT->Group[1].OUTTGL.reg = 1 << 22;
|
||||
|
||||
index += 1;
|
||||
// The buffer is full, send it.
|
||||
|
|
|
@ -57,9 +57,9 @@ void supervisor_flash_set_usb_writable(bool usb_writable) {
|
|||
const mp_obj_type_t supervisor_flash_type;
|
||||
STATIC const mp_obj_base_t supervisor_flash_obj = {&supervisor_flash_type};
|
||||
|
||||
STATIC mp_obj_t supervisor_flash_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t supervisor_flash_obj_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 0, 0, false);
|
||||
mp_arg_check_num(n_args, kw_args, 0, 0, false);
|
||||
|
||||
// return singleton object
|
||||
return (mp_obj_t)&supervisor_flash_obj;
|
||||
|
|
Loading…
Reference in New Issue