diff options
| author | Lucian Copeland <hierophect@gmail.com> | 2020-08-04 10:59:05 -0400 |
|---|---|---|
| committer | Lucian Copeland <hierophect@gmail.com> | 2020-08-14 12:21:41 -0400 |
| commit | f9512983ff0c63a719d7708496e1a827a2ca8a64 (patch) | |
| tree | ad4348994c8ff40faa4ea733940fc75195d78af5 /shared-bindings | |
| parent | 98469322b7d35748f0f2cb03cc5bd4d470ea6339 (diff) | |
Add PulseOut
Diffstat (limited to 'shared-bindings')
| -rw-r--r-- | shared-bindings/pulseio/PulseOut.c | 26 | ||||
| -rw-r--r-- | shared-bindings/pulseio/PulseOut.h | 6 |
2 files changed, 26 insertions, 6 deletions
diff --git a/shared-bindings/pulseio/PulseOut.c b/shared-bindings/pulseio/PulseOut.c index 3d35f0544..10524f51b 100644 --- a/shared-bindings/pulseio/PulseOut.c +++ b/shared-bindings/pulseio/PulseOut.c @@ -64,19 +64,33 @@ //| pulse.send(pulses)""" //| ... //| -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) { +STATIC mp_obj_t pulseio_pulseout_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + + pulseio_pulseout_obj_t *self = m_new_obj(pulseio_pulseout_obj_t); + self->base.type = &pulseio_pulseout_type; + + #ifndef CPY_PULSEOUT_USES_DIGITALIO + // Most ports pass a PWMOut 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)) { mp_raise_TypeError_varg(translate("Expected a %q"), pulseio_pwmout_type.name); } + common_hal_pulseio_pulseout_construct(self, (pulseio_pwmout_obj_t *)MP_OBJ_TO_PTR(carrier_obj)); + #else + // ESP32-S2 Special Case + enum { ARG_pin, ARG_frequency}; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_pin, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_frequency, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 38000} }, + }; + 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); - // create Pulse object from the given pin - pulseio_pulseout_obj_t *self = m_new_obj(pulseio_pulseout_obj_t); - self->base.type = &pulseio_pulseout_type; + const mcu_pin_obj_t* pin = validate_obj_is_free_pin(args[ARG_pin].u_obj); - common_hal_pulseio_pulseout_construct(self, (pulseio_pwmout_obj_t *)MP_OBJ_TO_PTR(carrier_obj)); + common_hal_pulseio_pulseout_construct(self, pin, args[ARG_frequency].u_int); + #endif return MP_OBJ_FROM_PTR(self); } diff --git a/shared-bindings/pulseio/PulseOut.h b/shared-bindings/pulseio/PulseOut.h index 390910ff6..090f6d15c 100644 --- a/shared-bindings/pulseio/PulseOut.h +++ b/shared-bindings/pulseio/PulseOut.h @@ -33,8 +33,14 @@ extern const mp_obj_type_t pulseio_pulseout_type; +#ifndef CPY_PULSEOUT_USES_DIGITALIO extern void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self, const pulseio_pwmout_obj_t* carrier); +#else +extern void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self, + const mcu_pin_obj_t* pin, uint32_t frequency); +#endif + extern void common_hal_pulseio_pulseout_deinit(pulseio_pulseout_obj_t* self); extern bool common_hal_pulseio_pulseout_deinited(pulseio_pulseout_obj_t* self); extern void common_hal_pulseio_pulseout_send(pulseio_pulseout_obj_t* self, |
