esp8266/modmachine: Use common machine_time_pulse_us implementation.

Testing shows that for frequencies which the esp8266 can handle -- up to
about 1kHz -- `machine.time_pulse_us()` now gives more accurate results.

Prior to this commit it would measure on average about 1us lower, but now
the average is much closer to the true value.  For example a pulse that is
1000us long, it would measure between 998 and 1000us.  Now it measures
between 999us and 1001us.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2025-05-23 12:57:20 +10:00
parent ef21ade602
commit 398da22492
3 changed files with 10 additions and 31 deletions

View File

@@ -30,7 +30,7 @@
#if MICROPY_PY_MACHINE_PULSE
MP_WEAK mp_uint_t machine_time_pulse_us(mp_hal_pin_obj_t pin, int pulse_level, mp_uint_t timeout_us) {
mp_uint_t machine_time_pulse_us(mp_hal_pin_obj_t pin, int pulse_level, mp_uint_t timeout_us) {
mp_uint_t nchanges = 2;
mp_uint_t start = mp_hal_ticks_us();
for (;;) {