fix pulsein incorrect compute

This commit is contained in:
hathach 2019-01-09 15:15:30 +07:00
parent 215008f78c
commit db82160eef
No known key found for this signature in database
GPG Key ID: 2FA891220FBFD581
2 changed files with 8 additions and 4 deletions

View File

@ -59,6 +59,9 @@ static void _pulsein_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action
uint64_t current_ms;
current_tick(&current_ms, &current_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) {

View File

@ -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);