Skip to content

Commit

Permalink
Modify member variable names.
Browse files Browse the repository at this point in the history
  • Loading branch information
JChristensen committed Feb 8, 2022
1 parent e156f8f commit bc0c6b9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=JC_EEPROM
version=1.0.5
version=1.0.6
author=Jack Christensen <[email protected]>
maintainer=Jack Christensen <[email protected]>
sentence=Arduino library to support external I2C EEPROMs.
Expand Down
52 changes: 26 additions & 26 deletions src/JC_EEPROM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@
// - eepromAddr is the EEPROM's I2C address and defaults to 0x50 which is common.
JC_EEPROM::JC_EEPROM(eeprom_size_t deviceCapacity, uint8_t nDevice, uint16_t pageSize, uint8_t eepromAddr)
{
_dvcCapacity = deviceCapacity;
_nDevice = nDevice;
_pageSize = pageSize;
_eepromAddr = eepromAddr;
_totalCapacity = _nDevice * _dvcCapacity * 1024UL / 8;
_nAddrBytes = deviceCapacity > kbits_16 ? 2 : 1; // two address bytes needed for eeproms > 16kbits
m_dvcCapacity = deviceCapacity;
m_nDevice = nDevice;
m_pageSize = pageSize;
m_eepromAddr = eepromAddr;
m_totalCapacity = m_nDevice * m_dvcCapacity * 1024UL / 8;
m_nAddrBytes = deviceCapacity > kbits_16 ? 2 : 1; // two address bytes needed for eeproms > 16kbits

// determine the bitshift needed to isolate the chip select bits from
// the address to put into the control byte
uint16_t kb = _dvcCapacity;
if ( kb <= kbits_16 ) _csShift = 8;
else if ( kb >= kbits_512 ) _csShift = 16;
uint16_t kb = m_dvcCapacity;
if ( kb <= kbits_16 ) m_csShift = 8;
else if ( kb >= kbits_512 ) m_csShift = 16;
else {
kb >>= 6;
_csShift = 12;
m_csShift = 12;
while ( kb >= 1 ) {
++_csShift;
++m_csShift;
kb >>= 1;
}
}
Expand All @@ -50,8 +50,8 @@ uint8_t JC_EEPROM::begin(twiClockFreq_t twiFreq)
{
Wire.begin();
Wire.setClock(twiFreq);
Wire.beginTransmission(_eepromAddr);
if (_nAddrBytes == 2) Wire.write(0); // high addr byte
Wire.beginTransmission(m_eepromAddr);
if (m_nAddrBytes == 2) Wire.write(0); // high addr byte
Wire.write(0); // low addr byte
return Wire.endTransmission();
}
Expand All @@ -63,23 +63,23 @@ uint8_t JC_EEPROM::begin(twiClockFreq_t twiFreq)
uint8_t JC_EEPROM::write(uint32_t addr, uint8_t* values, uint16_t nBytes)
{
uint8_t ctrlByte; // control byte (I2C device address & chip/block select bits)
uint8_t txStatus = 0; // transmit status
uint8_t txStatus {0}; // transmit status
uint16_t nWrite; // number of bytes to write
uint16_t nPage; // number of bytes remaining on current page, starting at addr

if (addr + nBytes > _totalCapacity) { // will this write go past the top of the EEPROM?
if (addr + nBytes > m_totalCapacity) { // will this write go past the top of the EEPROM?
return EEPROM_ADDR_ERR; // yes, tell the caller
}

while (nBytes > 0) {
nPage = _pageSize - ( addr & (_pageSize - 1) );
nPage = m_pageSize - ( addr & (m_pageSize - 1) );
// find min(nBytes, nPage, BUFFER_LENGTH) -- BUFFER_LENGTH is defined in the Wire library.
nWrite = nBytes < nPage ? nBytes : nPage;
nWrite = BUFFER_LENGTH - _nAddrBytes < nWrite ? BUFFER_LENGTH - _nAddrBytes : nWrite;
ctrlByte = _eepromAddr | (byte) (addr >> _csShift);
nWrite = BUFFER_LENGTH - m_nAddrBytes < nWrite ? BUFFER_LENGTH - m_nAddrBytes : nWrite;
ctrlByte = m_eepromAddr | (byte) (addr >> m_csShift);
Wire.beginTransmission(ctrlByte);
if (_nAddrBytes == 2) Wire.write( (byte) (addr >> 8) ); // high addr byte
Wire.write( (byte) addr ); //low addr byte
if (m_nAddrBytes == 2) Wire.write( (byte) (addr >> 8) ); // high addr byte
Wire.write( (byte) addr ); // low addr byte
Wire.write(values, nWrite);
txStatus = Wire.endTransmission();
if (txStatus != 0) return txStatus;
Expand All @@ -88,7 +88,7 @@ uint8_t JC_EEPROM::write(uint32_t addr, uint8_t* values, uint16_t nBytes)
for (uint8_t i=100; i; --i) {
delayMicroseconds(500); // no point in waiting too fast
Wire.beginTransmission(ctrlByte);
if (_nAddrBytes == 2) Wire.write(0); // high addr byte
if (m_nAddrBytes == 2) Wire.write(0); // high addr byte
Wire.write(0); // low addr byte
txStatus = Wire.endTransmission();
if (txStatus == 0) break;
Expand All @@ -113,18 +113,18 @@ uint8_t JC_EEPROM::read(uint32_t addr, uint8_t* values, uint16_t nBytes)
uint16_t nRead; // number of bytes to read
uint16_t nPage; // number of bytes remaining on current page, starting at addr

if (addr + nBytes > _totalCapacity) { // will this read take us past the top of the EEPROM?
if (addr + nBytes > m_totalCapacity) { // will this read take us past the top of the EEPROM?
return EEPROM_ADDR_ERR; // yes, tell the caller
}

while (nBytes > 0) {
nPage = _pageSize - ( addr & (_pageSize - 1) );
nPage = m_pageSize - ( addr & (m_pageSize - 1) );
nRead = nBytes < nPage ? nBytes : nPage;
nRead = BUFFER_LENGTH < nRead ? BUFFER_LENGTH : nRead;
ctrlByte = _eepromAddr | (byte) (addr >> _csShift);
ctrlByte = m_eepromAddr | (byte) (addr >> m_csShift);
Wire.beginTransmission(ctrlByte);
if (_nAddrBytes == 2) Wire.write( (byte) (addr >> 8) ); // high addr byte
Wire.write( (byte) addr ); // low addr byte
if (m_nAddrBytes == 2) Wire.write( (byte) (addr >> 8) ); // high addr byte
Wire.write( (byte) addr ); // low addr byte
rxStatus = Wire.endTransmission();
if (rxStatus != 0) return rxStatus; // read error

Expand Down
14 changes: 7 additions & 7 deletions src/JC_EEPROM.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ class JC_EEPROM
{return (read(addr) == value) ? 0 : write(addr, &value, 1); }

private:
uint8_t _eepromAddr; // eeprom i2c address
uint16_t _dvcCapacity; // capacity of one EEPROM device, in kbits
uint8_t _nDevice; // number of devices on the bus
uint16_t _pageSize; // page size in bytes
uint8_t _csShift; // number of bits to shift address for chip select bits in control byte
uint16_t _nAddrBytes; // number of address bytes (1 or 2)
uint32_t _totalCapacity; // capacity of all EEPROM devices on the bus, in bytes
uint8_t m_eepromAddr; // eeprom i2c address
uint16_t m_dvcCapacity; // capacity of one EEPROM device, in kbits
uint8_t m_nDevice; // number of devices on the bus
uint16_t m_pageSize; // page size in bytes
uint8_t m_csShift; // number of bits to shift address for chip select bits in control byte
uint16_t m_nAddrBytes; // number of address bytes (1 or 2)
uint32_t m_totalCapacity; // capacity of all EEPROM devices on the bus, in bytes
};

#endif

0 comments on commit bc0c6b9

Please sign in to comment.