Fixed unused variables warnings and indentation

This commit is contained in:
Cristian Maglie 2015-05-29 20:01:31 +02:00
parent 94a182e841
commit 2cbdc121e9
2 changed files with 12 additions and 15 deletions

View File

@ -40,16 +40,14 @@ unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout)
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
uint8_t stateMask = (state ? bit : 0);
unsigned long width = 0; // keep initialization out of time critical area
// convert the timeout from microseconds to a number of times through
// the initial loop; it takes approximately 16 clock cycles per iteration
unsigned long numloops = 0;
unsigned long maxloops = microsecondsToClockCycles(timeout)/16;
width = countPulseASM(portInputRegister(port), bit, stateMask, maxloops);
unsigned long width = countPulseASM(portInputRegister(port), bit, stateMask, maxloops);
//prevent clockCyclesToMicroseconds to return bogus values if countPulseASM timed out
// prevent clockCyclesToMicroseconds to return bogus values if countPulseASM timed out
if (width)
return clockCyclesToMicroseconds(width * 16 + 16);
else
@ -72,7 +70,6 @@ unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout)
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
uint8_t stateMask = (state ? bit : 0);
unsigned long width = 0; // keep initialization out of time critical area
// convert the timeout from microseconds to a number of times through
// 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)
if (numloops++ == maxloops)
return 0;
unsigned long start = micros();
// wait for the pulse to stop
while ((*portInputRegister(port) & bit) == stateMask) {
if (numloops++ == maxloops)
return 0;
}
return micros() - start;
unsigned long start = micros();
// wait for the pulse to stop
while ((*portInputRegister(port) & bit) == stateMask) {
if (numloops++ == maxloops)
return 0;
}
return micros() - start;
}

View File

@ -73,8 +73,8 @@ uint32_t pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout)
// the initial loop; it takes 18 clock cycles per iteration.
unsigned long maxloops = microsecondsToClockCycles(timeout) / 10;
// wait for any previous pulse to end
while ((p.pPort->PIO_PDSR & bit) == stateMask)
// wait for any previous pulse to end
while ((p.pPort->PIO_PDSR & bit) == stateMask)
if (--maxloops == 0)
return 0;
@ -90,4 +90,4 @@ uint32_t pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout)
return 0;
}
return micros() - start;
}
}