diff options
| author | hathach <thach@tinyusb.org> | 2019-01-09 15:15:30 +0700 |
|---|---|---|
| committer | hathach <thach@tinyusb.org> | 2019-01-09 15:15:30 +0700 |
| commit | db82160eefa620d889d4e9df9b04bb476b103951 (patch) | |
| tree | a443f29534443f21ade6861d787e2c75cf358eed | |
| parent | 215008f78cbd30739b7899f3aa8f56940fa471ad (diff) | |
fix pulsein incorrect compute
| -rw-r--r-- | ports/nrf/common-hal/pulseio/PulseIn.c | 4 | ||||
| -rw-r--r-- | ports/nrf/common-hal/pulseio/PulseIn.h | 8 |
2 files changed, 8 insertions, 4 deletions
diff --git a/ports/nrf/common-hal/pulseio/PulseIn.c b/ports/nrf/common-hal/pulseio/PulseIn.c index fa05de148..6e5825af6 100644 --- a/ports/nrf/common-hal/pulseio/PulseIn.c +++ b/ports/nrf/common-hal/pulseio/PulseIn.c @@ -59,6 +59,9 @@ static void _pulsein_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action uint64_t current_ms; current_tick(¤t_ms, ¤t_us); + // current_tick gives us the remaining us until the next tick but we want the number since the last ms. + current_us = 1000 - current_us; + pulseio_pulsein_obj_t* self = NULL; for(int i = 0; i < NRFX_ARRAY_SIZE(_objs); i++ ) { if ( _objs[i] && _objs[i]->pin == pin ) { @@ -66,7 +69,6 @@ static void _pulsein_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action break; } } - if ( !self ) return; if (self->first_edge) { diff --git a/ports/nrf/common-hal/pulseio/PulseIn.h b/ports/nrf/common-hal/pulseio/PulseIn.h index a029129ac..432506418 100644 --- a/ports/nrf/common-hal/pulseio/PulseIn.h +++ b/ports/nrf/common-hal/pulseio/PulseIn.h @@ -35,15 +35,17 @@ typedef struct { mp_obj_base_t base; uint8_t pin; + bool idle_state; + bool paused; + uint16_t* buffer; uint16_t maxlen; - bool idle_state; + volatile uint16_t start; volatile uint16_t len; volatile bool first_edge; - bool paused; - volatile uint64_t last_ms; volatile uint16_t last_us; + volatile uint64_t last_ms; } pulseio_pulsein_obj_t; void pulsein_reset(void); |
