@@ -40,16 +40,14 @@ unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout)
40
40
uint8_t bit = digitalPinToBitMask (pin );
41
41
uint8_t port = digitalPinToPort (pin );
42
42
uint8_t stateMask = (state ? bit : 0 );
43
- unsigned long width = 0 ; // keep initialization out of time critical area
44
43
45
44
// convert the timeout from microseconds to a number of times through
46
45
// the initial loop; it takes approximately 16 clock cycles per iteration
47
- unsigned long numloops = 0 ;
48
46
unsigned long maxloops = microsecondsToClockCycles (timeout )/16 ;
49
47
50
- width = countPulseASM (portInputRegister (port ), bit , stateMask , maxloops );
48
+ unsigned long width = countPulseASM (portInputRegister (port ), bit , stateMask , maxloops );
51
49
52
- //prevent clockCyclesToMicroseconds to return bogus values if countPulseASM timed out
50
+ // prevent clockCyclesToMicroseconds to return bogus values if countPulseASM timed out
53
51
if (width )
54
52
return clockCyclesToMicroseconds (width * 16 + 16 );
55
53
else
@@ -72,7 +70,6 @@ unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout)
72
70
uint8_t bit = digitalPinToBitMask (pin );
73
71
uint8_t port = digitalPinToPort (pin );
74
72
uint8_t stateMask = (state ? bit : 0 );
75
- unsigned long width = 0 ; // keep initialization out of time critical area
76
73
77
74
// convert the timeout from microseconds to a number of times through
78
75
// the initial loop; it takes 16 clock cycles per iteration.
@@ -89,11 +86,11 @@ unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout)
89
86
if (numloops ++ == maxloops )
90
87
return 0 ;
91
88
92
- unsigned long start = micros ();
93
- // wait for the pulse to stop
94
- while ((* portInputRegister (port ) & bit ) == stateMask ) {
95
- if (numloops ++ == maxloops )
96
- return 0 ;
97
- }
98
- return micros () - start ;
89
+ unsigned long start = micros ();
90
+ // wait for the pulse to stop
91
+ while ((* portInputRegister (port ) & bit ) == stateMask ) {
92
+ if (numloops ++ == maxloops )
93
+ return 0 ;
94
+ }
95
+ return micros () - start ;
99
96
}
0 commit comments