summaryrefslogtreecommitdiff
path: root/shared-bindings
diff options
context:
space:
mode:
authorScott Shawcroft <scott@adafruit.com>2020-08-20 11:24:08 -0700
committerGitHub <noreply@github.com>2020-08-20 11:24:08 -0700
commit400701004b6e4e47e58db08c87c46609056d645f (patch)
tree07179fdb71a67f43a74cbf2c212fbd5313aaad03 /shared-bindings
parente47447ba592676c2ab57a4ae7c2aed4f7bd10004 (diff)
parentdd425ee6c54deee72d0fa7cd42282b8157a54da6 (diff)
Merge pull request #3279 from hierophect/esp32-pulseinout
ESP32-S2: Add PulseOut and PulseIn
Diffstat (limited to 'shared-bindings')
-rw-r--r--shared-bindings/pulseio/PulseOut.c29
-rw-r--r--shared-bindings/pulseio/PulseOut.h6
2 files changed, 24 insertions, 11 deletions
diff --git a/shared-bindings/pulseio/PulseOut.c b/shared-bindings/pulseio/PulseOut.c
index 3d35f0544..3fd722558 100644
--- a/shared-bindings/pulseio/PulseOut.c
+++ b/shared-bindings/pulseio/PulseOut.c
@@ -64,20 +64,29 @@
//| 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) {
- mp_arg_check_num(n_args, kw_args, 1, 1, false);
- mp_obj_t carrier_obj = args[0];
+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) {
- if (!MP_OBJ_IS_TYPE(carrier_obj, &pulseio_pwmout_type)) {
- mp_raise_TypeError_varg(translate("Expected a %q"), pulseio_pwmout_type.name);
- }
-
- // 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;
- common_hal_pulseio_pulseout_construct(self, (pulseio_pwmout_obj_t *)MP_OBJ_TO_PTR(carrier_obj));
-
+ mp_obj_t carrier_obj = pos_args[0];
+ if (MP_OBJ_IS_TYPE(carrier_obj, &pulseio_pwmout_type)) {
+ // Use a PWMOut Carrier
+ mp_arg_check_num(n_args, kw_args, 1, 1, false);
+ common_hal_pulseio_pulseout_construct(self, (pulseio_pwmout_obj_t *)MP_OBJ_TO_PTR(carrier_obj), NULL, 0, 0);
+ } else {
+ // Use a Pin, frequency, and duty cycle
+ 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_QSTR_duty_cycle, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1<<15} },
+ };
+ 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);
+ const mcu_pin_obj_t* pin = validate_obj_is_free_pin(args[ARG_pin].u_obj);
+ common_hal_pulseio_pulseout_construct(self, NULL, pin, args[ARG_frequency].u_int, args[ARG_frequency].u_int);
+ }
return MP_OBJ_FROM_PTR(self);
}
diff --git a/shared-bindings/pulseio/PulseOut.h b/shared-bindings/pulseio/PulseOut.h
index 390910ff6..9d4778e93 100644
--- a/shared-bindings/pulseio/PulseOut.h
+++ b/shared-bindings/pulseio/PulseOut.h
@@ -34,7 +34,11 @@
extern const mp_obj_type_t pulseio_pulseout_type;
extern void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self,
- const pulseio_pwmout_obj_t* carrier);
+ const pulseio_pwmout_obj_t* carrier,
+ const mcu_pin_obj_t* pin,
+ uint32_t frequency,
+ uint16_t duty_cycle);
+
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,