|
39 | 39 | pulseio_pulsein_obj_t *save_self;
|
40 | 40 |
|
41 | 41 | #define NO_PIN 0xff
|
| 42 | +#define MAX_PULSE 65535 |
| 43 | +#define MIN_PULSE 10 |
42 | 44 | volatile bool last_level;
|
43 |
| -volatile uint16_t level_count = 0; |
44 |
| -volatile uint16_t result = 0; |
| 45 | +volatile uint32_t level_count = 0; |
| 46 | +volatile uint32_t result = 0; |
45 | 47 | volatile uint16_t buf_index = 0;
|
46 | 48 |
|
47 | 49 | uint16_t pulsein_program[] = {
|
@@ -133,16 +135,21 @@ void common_hal_pulseio_pulsein_interrupt() {
|
133 | 135 | result = level_count;
|
134 | 136 | last_level = level;
|
135 | 137 | level_count = 1;
|
136 |
| - // ignore pulses that are too long and too short |
137 |
| - if (result < 4000 && result > 10) { |
138 |
| - self->buffer[buf_index] = result; |
| 138 | + // Pulses that are londger than MAX_PULSE will return MAX_PULSE |
| 139 | + if (result > MAX_PULSE ) { |
| 140 | + result = MAX_PULSE; |
| 141 | + } |
| 142 | + // ignore pulses that are too short |
| 143 | + if (result <= MAX_PULSE && result > MIN_PULSE) { |
| 144 | + self->buffer[buf_index] = (uint16_t) result; |
139 | 145 | buf_index++;
|
140 | 146 | self->len++;
|
141 | 147 | }
|
142 | 148 | }
|
143 | 149 | }
|
144 |
| -// check for a pulse thats too long (4000 us) or maxlen reached, and reset |
145 |
| - if ((level_count > 4000) || (buf_index >= self->maxlen)) { |
| 150 | + |
| 151 | +// check for a pulse thats too long (MAX_PULSE us) or maxlen reached, and reset |
| 152 | + if ((level_count > MAX_PULSE) || (buf_index >= self->maxlen)) { |
146 | 153 | pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, false);
|
147 | 154 | pio_sm_init(self->state_machine.pio, self->state_machine.state_machine, self->state_machine.offset, &self->state_machine.sm_config);
|
148 | 155 | pio_sm_restart(self->state_machine.pio,self->state_machine.state_machine);
|
|
0 commit comments