Merge pull request #4668 from DavePutz/issue_4659

Increased possible pulsein length to ~65 ms.
This commit is contained in:
Scott Shawcroft 2021-04-27 11:01:51 -07:00 committed by GitHub
commit f99deeda68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 7 deletions

View File

@ -39,9 +39,11 @@
pulseio_pulsein_obj_t *save_self; pulseio_pulsein_obj_t *save_self;
#define NO_PIN 0xff #define NO_PIN 0xff
#define MAX_PULSE 65535
#define MIN_PULSE 10
volatile bool last_level; volatile bool last_level;
volatile uint16_t level_count = 0; volatile uint32_t level_count = 0;
volatile uint16_t result = 0; volatile uint32_t result = 0;
volatile uint16_t buf_index = 0; volatile uint16_t buf_index = 0;
uint16_t pulsein_program[] = { uint16_t pulsein_program[] = {
@ -133,16 +135,21 @@ void common_hal_pulseio_pulsein_interrupt() {
result = level_count; result = level_count;
last_level = level; last_level = level;
level_count = 1; level_count = 1;
// ignore pulses that are too long and too short // Pulses that are londger than MAX_PULSE will return MAX_PULSE
if (result < 4000 && result > 10) { if (result > MAX_PULSE ) {
self->buffer[buf_index] = result; result = MAX_PULSE;
}
// ignore pulses that are too short
if (result <= MAX_PULSE && result > MIN_PULSE) {
self->buffer[buf_index] = (uint16_t) result;
buf_index++; buf_index++;
self->len++; self->len++;
} }
} }
} }
// check for a pulse thats too long (4000 us) or maxlen reached, and reset
if ((level_count > 4000) || (buf_index >= self->maxlen)) { // check for a pulse thats too long (MAX_PULSE us) or maxlen reached, and reset
if ((level_count > MAX_PULSE) || (buf_index >= self->maxlen)) {
pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, false); pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, false);
pio_sm_init(self->state_machine.pio, self->state_machine.state_machine, self->state_machine.offset, &self->state_machine.sm_config); pio_sm_init(self->state_machine.pio, self->state_machine.state_machine, self->state_machine.offset, &self->state_machine.sm_config);
pio_sm_restart(self->state_machine.pio,self->state_machine.state_machine); pio_sm_restart(self->state_machine.pio,self->state_machine.state_machine);