aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Shawcroft <scott@chickadee.tech>2017-08-10 11:55:34 -0700
committerScott Shawcroft <scott@chickadee.tech>2017-08-10 11:55:34 -0700
commit42156484ae0ebb709e5543fb69505fe88148edf0 (patch)
tree5ac78277e4b83c5f1609a77c535c737d6fc1acf5
parent37c72adc0fd1a9937910cee7f201078f531c6a54 (diff)
shared-bindings/atmel-samd: Fix and improve trigger duration timing on PulseIn.resume.
-rw-r--r--atmel-samd/common-hal/pulseio/PulseIn.c12
-rw-r--r--shared-bindings/pulseio/PulseIn.c2
2 files changed, 12 insertions, 2 deletions
diff --git a/atmel-samd/common-hal/pulseio/PulseIn.c b/atmel-samd/common-hal/pulseio/PulseIn.c
index f48045cf4..09cad1404 100644
--- a/atmel-samd/common-hal/pulseio/PulseIn.c
+++ b/atmel-samd/common-hal/pulseio/PulseIn.c
@@ -172,9 +172,19 @@ void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t* self,
pin_conf.direction = PORT_PIN_DIR_OUTPUT;
pin_conf.input_pull = PORT_PIN_PULL_NONE;
port_pin_set_config(self->pin, &pin_conf);
+
+ // TODO(tannewt): delay_us isn't exactly correct so we adjust the value
+ // here before calling it. Find out why its not exact and fix it instead
+ // of hacking around it here.
+ uint32_t adjusted_duration = trigger_duration;
+ adjusted_duration *= 4;
+ adjusted_duration /= 5;
+
+ common_hal_mcu_disable_interrupts();
port_pin_set_output_level(self->pin, !self->idle_state);
- delay_us(trigger_duration);
+ common_hal_mcu_delay_us(adjusted_duration);
port_pin_set_output_level(self->pin, self->idle_state);
+ common_hal_mcu_enable_interrupts();
}
// Reconfigure the pin and make sure its set to detect the first edge.
diff --git a/shared-bindings/pulseio/PulseIn.c b/shared-bindings/pulseio/PulseIn.c
index 5cdaa4cf3..0abc06680 100644
--- a/shared-bindings/pulseio/PulseIn.c
+++ b/shared-bindings/pulseio/PulseIn.c
@@ -159,7 +159,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(pulseio_pulsein_pause_obj, pulseio_pulsein_obj_pause);
STATIC mp_obj_t pulseio_pulsein_obj_resume(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_trigger_duration };
static const mp_arg_t allowed_args[] = {
- { MP_QSTR_trigger_duration, MP_ARG_OBJ, {.u_int = 0} },
+ { MP_QSTR_trigger_duration, MP_ARG_INT, {.u_int = 0} },
};
pulseio_pulsein_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];