@@ -45,7 +45,7 @@ I2C_eeprom::I2C_eeprom(const uint8_t deviceAddress, const uint32_t deviceSize, T
4545{
4646 _deviceAddress = deviceAddress;
4747 _deviceSize = setDeviceSize (deviceSize);
48- _pageSize = getPageSize (_deviceSize);
48+ _pageSize = calculatePageSize (_deviceSize);
4949 _wire = wire;
5050
5151 // Chips 16 Kbit (2048 Bytes) or smaller only have one-word addresses.
@@ -296,7 +296,7 @@ bool I2C_eeprom::updateBlockVerify(const uint16_t memoryAddress, const uint8_t *
296296// 24LC01 128 B YES
297297uint32_t I2C_eeprom::determineSize (const bool debug)
298298{
299- // try to read a byte to see if connected
299+ // try to read a byte to see if connected
300300 if (! isConnected ()) return 0 ;
301301
302302 uint8_t patAA = 0xAA ;
@@ -308,7 +308,7 @@ uint32_t I2C_eeprom::determineSize(const bool debug)
308308
309309 // store old values
310310 bool addressSize = _isAddressSizeTwoWords;
311- _isAddressSizeTwoWords = size > I2C_DEVICESIZE_24LC16; // 2048
311+ _isAddressSizeTwoWords = size > I2C_DEVICESIZE_24LC16; // 2048
312312 uint8_t buf = readByte (size);
313313
314314 // test folding
@@ -338,7 +338,7 @@ uint32_t I2C_eeprom::determineSize(const bool debug)
338338// new 1.8.1 #61
339339// updated 1.8.2 #63
340340//
341- // Returns:
341+ // Returns:
342342// 0 if device size cannot be determined or device is not online
343343// 1 if device has default bytes in first dataFirstBytes bytes [0-BUFSIZE]
344344// Write some dataFirstBytes to the first bytes and retry or use the determineSize method
@@ -402,14 +402,14 @@ uint32_t I2C_eeprom::determineSizeNoWrite()
402402 _isAddressSizeTwoWords = (size >= I2C_DEVICESIZE_24LC16); // == 2048
403403
404404 // Try to read last byte of the block, should return length of 0 when fails for single byte devices
405- // Will return the same dataFirstBytes as initially read on other devices
405+ // Will return the same dataFirstBytes as initially read on other devices
406406 // as the data pointer could not be moved to the requested position
407407 delay (2 );
408408 uint16_t bSize = readBlock (size, dataMatch, BUFSIZE);
409409
410410 if (bSize == BUFSIZE && memcmp (dataFirstBytes, dataMatch, BUFSIZE) != 0 )
411411 {
412- // Read is performed just over size (size + BUFSIZE),
412+ // Read is performed just over size (size + BUFSIZE),
413413 // this will only work for devices with mem > size;
414414 // therefore return size * 2
415415 _isAddressSizeTwoWords = addressSize;
@@ -433,16 +433,23 @@ uint8_t I2C_eeprom::getPageSize()
433433}
434434
435435
436- uint8_t I2C_eeprom::getPageSize (uint32_t deviceSize)
436+ uint8_t I2C_eeprom::calculatePageSize (uint32_t deviceSize)
437437{
438438 // determine page size from device size
439439 // based on Microchip 24LCXX data sheets.
440440 if (deviceSize <= I2C_DEVICESIZE_24LC02) return 8 ;
441441 if (deviceSize <= I2C_DEVICESIZE_24LC16) return 16 ;
442442 if (deviceSize <= I2C_DEVICESIZE_24LC64) return 32 ;
443443 if (deviceSize <= I2C_DEVICESIZE_24LC256) return 64 ;
444- // I2C_DEVICESIZE_24LC512
445- return 128 ;
444+ if (deviceSize <= I2C_DEVICESIZE_24LC512) return 128 ;
445+ // Error.
446+ return 0 ;
447+ }
448+
449+
450+ uint8_t I2C_eeprom::getPageSize (uint32_t deviceSize)
451+ {
452+ return calculatePageSize (deviceSize);
446453}
447454
448455
@@ -469,7 +476,7 @@ uint32_t I2C_eeprom::setDeviceSize(uint32_t deviceSize)
469476
470477uint8_t I2C_eeprom::setPageSize (uint8_t pageSize)
471478{
472- // force power of 2.
479+ // force power of 2.
473480 if (pageSize >= 128 ) {
474481 _pageSize = 128 ;
475482 }
@@ -616,7 +623,7 @@ int I2C_eeprom::_WriteBlock(const uint16_t memoryAddress, const uint8_t * buffer
616623
617624 _lastWrite = micros ();
618625
619- yield (); // For OS scheduling
626+ yield (); // For OS scheduling
620627
621628// if (rv != 0)
622629// {
@@ -627,7 +634,7 @@ int I2C_eeprom::_WriteBlock(const uint16_t memoryAddress, const uint8_t * buffer
627634// SPRN("\t");
628635// SPRNL(rv);
629636// }
630- // return -(abs(rv)); // error
637+ // return -(abs(rv)); // error
631638// }
632639 return rv;
633640}
@@ -728,9 +735,9 @@ void I2C_eeprom::_waitEEReady()
728735 {
729736 if (isConnected ()) return ;
730737 // TODO remove pre 1.7.4 code
731- // _wire->beginTransmission(_deviceAddress);
732- // int x = _wire->endTransmission();
733- // if (x == 0) return;
738+ // _wire->beginTransmission(_deviceAddress);
739+ // int x = _wire->endTransmission();
740+ // if (x == 0) return;
734741 yield (); // For OS scheduling
735742 }
736743 return ;
0 commit comments