MS5611 - Remove profanity. Replace comment with code. Improve code

size.  Improve code readability.
This commit is contained in:
Dominic Clifton 2014-10-03 14:38:20 +01:00
parent 98f5bdd986
commit 043577b8af
1 changed files with 5 additions and 9 deletions

View File

@ -106,19 +106,15 @@ static int8_t ms5611_crc(uint16_t *prom)
{
int32_t i, j;
uint32_t res = 0;
uint8_t zero = 1;
uint8_t crc = prom[7] & 0xF;
prom[7] &= 0xFF00;
// if eeprom is all zeros, we're probably fucked - BUT this will return valid CRC lol
for (i = 0; i < 8; i++) {
if (prom[i] != 0)
zero = 0;
}
if (zero)
return -1;
bool blankEeprom = true;
for (i = 0; i < 16; i++) {
if (prom[i >> 1]) {
blankEeprom = false;
}
if (i & 1)
res ^= ((prom[i >> 1]) & 0x00FF);
else
@ -130,7 +126,7 @@ static int8_t ms5611_crc(uint16_t *prom)
}
}
prom[7] |= crc;
if (crc == ((res >> 12) & 0xF))
if (!blankEeprom && crc == ((res >> 12) & 0xF))
return 0;
return -1;