File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed
ports/raspberrypi/common-hal/pulseio Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change 39
39
pulseio_pulsein_obj_t * save_self ;
40
40
41
41
#define NO_PIN 0xff
42
- #define MAX_PULSE 32678
42
+ #define MAX_PULSE 65535
43
43
#define MIN_PULSE 10
44
44
volatile bool last_level ;
45
- volatile uint16_t level_count = 0 ;
46
- volatile uint16_t result = 0 ;
45
+ volatile uint32_t level_count = 0 ;
46
+ volatile uint32_t result = 0 ;
47
47
volatile uint16_t buf_index = 0 ;
48
48
49
49
uint16_t pulsein_program [] = {
@@ -140,14 +140,19 @@ void common_hal_pulseio_pulsein_interrupt() {
140
140
result = level_count ;
141
141
last_level = level ;
142
142
level_count = 1 ;
143
- // ignore pulses that are too long and too short
144
- if (result < MAX_PULSE && result > MIN_PULSE ) {
145
- self -> buffer [buf_index ] = result ;
143
+ // Pulses that are londger than MAX_PULSE will return MAX_PULSE
144
+ if (result > MAX_PULSE ) {
145
+ result = MAX_PULSE ;
146
+ }
147
+ // ignore pulses that are too short
148
+ if (result <= MAX_PULSE && result > MIN_PULSE ) {
149
+ self -> buffer [buf_index ] = (uint16_t ) result ;
146
150
buf_index ++ ;
147
151
self -> len ++ ;
148
152
}
149
153
}
150
154
}
155
+
151
156
// check for a pulse thats too long (MAX_PULSE us) or maxlen reached, and reset
152
157
if ((level_count > MAX_PULSE ) || (buf_index >= self -> maxlen )) {
153
158
pio_sm_set_enabled (self -> state_machine .pio , self -> state_machine .state_machine , false);
You can’t perform that action at this time.
0 commit comments