Skip to content

Commit 4215648

Browse files
committed
shared-bindings/atmel-samd: Fix and improve trigger duration timing on PulseIn.resume.
1 parent 37c72ad commit 4215648

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

atmel-samd/common-hal/pulseio/PulseIn.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,19 @@ void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t* self,
172172
pin_conf.direction = PORT_PIN_DIR_OUTPUT;
173173
pin_conf.input_pull = PORT_PIN_PULL_NONE;
174174
port_pin_set_config(self->pin, &pin_conf);
175+
176+
// TODO(tannewt): delay_us isn't exactly correct so we adjust the value
177+
// here before calling it. Find out why its not exact and fix it instead
178+
// of hacking around it here.
179+
uint32_t adjusted_duration = trigger_duration;
180+
adjusted_duration *= 4;
181+
adjusted_duration /= 5;
182+
183+
common_hal_mcu_disable_interrupts();
175184
port_pin_set_output_level(self->pin, !self->idle_state);
176-
delay_us(trigger_duration);
185+
common_hal_mcu_delay_us(adjusted_duration);
177186
port_pin_set_output_level(self->pin, self->idle_state);
187+
common_hal_mcu_enable_interrupts();
178188
}
179189

180190
// Reconfigure the pin and make sure its set to detect the first edge.

shared-bindings/pulseio/PulseIn.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(pulseio_pulsein_pause_obj, pulseio_pulsein_obj_pause);
159159
STATIC mp_obj_t pulseio_pulsein_obj_resume(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
160160
enum { ARG_trigger_duration };
161161
static const mp_arg_t allowed_args[] = {
162-
{ MP_QSTR_trigger_duration, MP_ARG_OBJ, {.u_int = 0} },
162+
{ MP_QSTR_trigger_duration, MP_ARG_INT, {.u_int = 0} },
163163
};
164164
pulseio_pulsein_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
165165
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy