shared-bindings/atmel-samd: Fix and improve trigger duration timing on PulseIn.resume.
This commit is contained in:
parent
37c72adc0f
commit
42156484ae
@ -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.
|
||||
|
@ -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)];
|
||||
|
Loading…
x
Reference in New Issue
Block a user