Test cases for I2C_eeprom initialization (#15)

Added test cases for I2C_eeprom initialization to verify that the page size is chosen correctly and that it sets the address size properly.

Fixed a bug with the larger eeprom sizes having incorrect intervals.
This commit is contained in:
Tomas Hübner
2021-01-08 14:46:57 +01:00
committed by GitHub
parent 5bfc57b1d2
commit e0eba70c85
4 changed files with 194 additions and 11 deletions
+7 -10
View File
@@ -46,30 +46,27 @@ I2C_eeprom::I2C_eeprom(const uint8_t deviceAddress, const unsigned int deviceSiz
_deviceAddress = deviceAddress;
// Chips 16Kbit (2048 Bytes) or smaller only have one-word addresses.
// Also try to guess page size from device size (going by Microchip 24LCXX datasheets here).
if (deviceSize <= 256)
this->_isAddressSizeTwoWords = deviceSize <= 2048 ? false : true;
// Try to guess page size from device size (going by Microchip 24LCXX datasheets here).
if (deviceSize <= 256) // 2Kbit
{
this->_isAddressSizeTwoWords = false;
this->_pageSize = 8;
}
else if (deviceSize <= 256 * 8)
else if (deviceSize <= 2048) // 16Kbit
{
this->_isAddressSizeTwoWords = false;
this->_pageSize = 16;
}
else if(deviceSize <= 8192 * 8)
else if(deviceSize <= 8192) // 64Kbit
{
this->_isAddressSizeTwoWords = true;
this->_pageSize = 32;
}
else if(deviceSize <= 65536 * 8)
else if(deviceSize <= 32768) // 256Kbit
{
this->_isAddressSizeTwoWords = true;
this->_pageSize = 64;
}
else
{
this->_isAddressSizeTwoWords = true;
this->_pageSize = 128;
}
}