Skip to content

Commit a65613b

Browse files
committed
VSC white space changes
1 parent 9e6ac9c commit a65613b

File tree

1 file changed

+110
-93
lines changed

1 file changed

+110
-93
lines changed

src/SparkFunSX1509.cpp

Lines changed: 110 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -113,20 +113,24 @@ void SX1509::pinDir(byte pin, byte inOut, byte initialLevel)
113113
// 0: IO is configured as an output
114114
// 1: IO is configured as an input
115115
byte modeBit;
116-
if ((inOut == OUTPUT) || (inOut == ANALOG_OUTPUT)) {
116+
if ((inOut == OUTPUT) || (inOut == ANALOG_OUTPUT))
117+
{
117118
uint16_t tempRegData = readWord(REG_DATA_B);
118-
if (initialLevel == LOW) {
119-
tempRegData &= ~(1<<pin);
120-
writeWord(REG_DATA_B, tempRegData);
121-
}
122-
modeBit = 0;
123-
} else {
119+
if (initialLevel == LOW)
120+
{
121+
tempRegData &= ~(1 << pin);
122+
writeWord(REG_DATA_B, tempRegData);
123+
}
124+
modeBit = 0;
125+
}
126+
else
127+
{
124128
modeBit = 1;
125-
}
126-
129+
}
130+
127131
uint16_t tempRegDir = readWord(REG_DIR_B);
128-
if (modeBit)
129-
tempRegDir |= (1<<pin);
132+
if (modeBit)
133+
tempRegDir |= (1 << pin);
130134
else
131135
tempRegDir &= ~(1 << pin);
132136

@@ -149,31 +153,33 @@ void SX1509::pinMode(byte pin, byte inOut, byte initialLevel)
149153

150154
bool SX1509::writePin(byte pin, byte highLow)
151155
{
152-
156+
153157
uint16_t tempRegDir = readWord(REG_DIR_B);
154-
155-
if ((0xFFFF ^ tempRegDir) & (1 << pin)) // If the pin is an output, write high/low
158+
159+
if ((0xFFFF ^ tempRegDir) & (1 << pin)) // If the pin is an output, write high/low
156160
{
157161
uint16_t tempRegData = readWord(REG_DATA_B);
158-
if (highLow) tempRegData |= (1 << pin);
159-
else tempRegData &= ~(1 << pin);
162+
if (highLow)
163+
tempRegData |= (1 << pin);
164+
else
165+
tempRegData &= ~(1 << pin);
160166
return writeWord(REG_DATA_B, tempRegData);
161167
}
162168
else // Otherwise the pin is an input, pull-up/down
163169
{
164170
uint16_t tempPullUp = readWord(REG_PULL_UP_B);
165171
uint16_t tempPullDown = readWord(REG_PULL_DOWN_B);
166-
167-
if (highLow) // if HIGH, do pull-up, disable pull-down
172+
173+
if (highLow) // if HIGH, do pull-up, disable pull-down
168174
{
169-
tempPullUp |= (1<<pin);
170-
tempPullDown &= ~(1<<pin);
175+
tempPullUp |= (1 << pin);
176+
tempPullDown &= ~(1 << pin);
171177
return writeWord(REG_PULL_UP_B, tempPullUp) && writeWord(REG_PULL_DOWN_B, tempPullDown);
172178
}
173179
else // If LOW do pull-down, disable pull-up
174180
{
175-
tempPullDown |= (1<<pin);
176-
tempPullUp &= ~(1<<pin);
181+
tempPullDown |= (1 << pin);
182+
tempPullUp &= ~(1 << pin);
177183
return writeWord(REG_PULL_UP_B, tempPullUp) && writeWord(REG_PULL_DOWN_B, tempPullDown);
178184
}
179185
}
@@ -187,43 +193,50 @@ bool SX1509::digitalWrite(byte pin, byte highLow)
187193
byte SX1509::readPin(byte pin)
188194
{
189195
uint16_t tempRegDir = readWord(REG_DIR_B);
190-
191-
if (tempRegDir & (1<<pin)) // If the pin is an input
196+
197+
if (tempRegDir & (1 << pin)) // If the pin is an input
192198
{
193199
uint16_t tempRegData = readWord(REG_DATA_B);
194-
if (tempRegData & (1<<pin))
200+
if (tempRegData & (1 << pin))
195201
return 1;
196-
} else {
197-
// log_d("Pin %d not INPUT, REG_DIR_B: %d", pin, tempRegDir);
198-
}
199-
202+
}
203+
else
204+
{
205+
// log_d("Pin %d not INPUT, REG_DIR_B: %d", pin, tempRegDir);
206+
}
207+
200208
return 0;
201209
}
202210

203-
bool SX1509::readPin(const byte pin, bool* value)
211+
bool SX1509::readPin(const byte pin, bool *value)
204212
{
205-
uint16_t tempRegDir;
206-
if (readWord(REG_DIR_B, &tempRegDir)) {
207-
if (tempRegDir & (1<<pin)) { // If the pin is an input
208-
uint16_t tempRegData;
209-
if (readWord(REG_DATA_B, &tempRegData)) {
210-
*value = (tempRegData & (1<<pin)) != 0;
211-
return true;
212-
};
213-
} else {
214-
*value = false;
215-
return true;
216-
}
217-
}
218-
return false;
213+
uint16_t tempRegDir;
214+
if (readWord(REG_DIR_B, &tempRegDir))
215+
{
216+
if (tempRegDir & (1 << pin))
217+
{ // If the pin is an input
218+
uint16_t tempRegData;
219+
if (readWord(REG_DATA_B, &tempRegData))
220+
{
221+
*value = (tempRegData & (1 << pin)) != 0;
222+
return true;
223+
};
224+
}
225+
else
226+
{
227+
*value = false;
228+
return true;
229+
}
230+
}
231+
return false;
219232
}
220233

221234
byte SX1509::digitalRead(byte pin)
222235
{
223236
return readPin(pin);
224237
}
225238

226-
bool SX1509::digitalRead(byte pin, bool* value)
239+
bool SX1509::digitalRead(byte pin, bool *value)
227240
{
228241
return readPin(pin, value);
229242
}
@@ -573,7 +586,7 @@ void SX1509::enableInterrupt(byte pin, byte riseFall)
573586
{
574587
// Set REG_INTERRUPT_MASK
575588
uint16_t tempWord = readWord(REG_INTERRUPT_MASK_B);
576-
tempWord &= ~(1<<pin); // 0 = event on IO will trigger interrupt
589+
tempWord &= ~(1 << pin); // 0 = event on IO will trigger interrupt
577590
writeWord(REG_INTERRUPT_MASK_B, tempWord);
578591

579592
byte sensitivity = 0;
@@ -750,9 +763,9 @@ uint16_t SX1509::readWord(byte registerAddress)
750763
return readValue;
751764
}
752765

753-
bool SX1509::readByte(byte registerAddress, byte* value)
766+
bool SX1509::readByte(byte registerAddress, byte *value)
754767
{
755-
return readBytes(registerAddress, value, 1);
768+
return readBytes(registerAddress, value, 1);
756769
}
757770

758771
// readWord(byte registerAddress)
@@ -761,15 +774,16 @@ bool SX1509::readByte(byte registerAddress, byte* value)
761774
// - The msb of the return value will contain the value read from registerAddress
762775
// - The lsb of the return value will contain the value read from registerAddress + 1
763776
// - Return boolean true if succesfull
764-
bool SX1509::readWord(byte registerAddress, uint16_t* value)
777+
bool SX1509::readWord(byte registerAddress, uint16_t *value)
765778
{
766-
byte dest[2];
767-
if (readBytes(registerAddress, dest, 2)) {
768-
value[0] = dest[1];
769-
value[1] = dest[0];
770-
return true;
771-
}
772-
return false;
779+
byte dest[2];
780+
if (readBytes(registerAddress, dest, 2))
781+
{
782+
value[0] = dest[1];
783+
value[1] = dest[0];
784+
return true;
785+
}
786+
return false;
773787
}
774788

775789
// readBytes(byte firstRegisterAddress, byte * destination, byte length)
@@ -778,28 +792,30 @@ bool SX1509::readWord(byte registerAddress, uint16_t* value)
778792
// - destination is an array of bytes where the read values will be stored into
779793
// - length is the number of bytes to be read
780794
// - Return boolean true if succesfull
781-
bool SX1509::readBytes(byte firstRegisterAddress, byte * destination, byte length)
795+
bool SX1509::readBytes(byte firstRegisterAddress, byte *destination, byte length)
782796
{
783797
_i2cPort->beginTransmission(deviceAddress);
784798
_i2cPort->write(firstRegisterAddress);
785799
uint8_t endResult = _i2cPort->endTransmission();
786800
bool result = (endResult == I2C_ERROR_OK) && (_i2cPort->requestFrom(deviceAddress, length) == length);
787-
788-
if (result) {
789-
unsigned int timeout = RECEIVE_TIMEOUT_VALUE * length;
790-
while ((_i2cPort->available() < length) && (timeout-- != 0))
791-
;
792-
793-
if (timeout == 0) {
794-
return false;
795-
}
796-
797-
for (int i=0; i<length; i++)
798-
{
799-
destination[i] = _i2cPort->read();
800-
}
801-
}
802-
return result;
801+
802+
if (result)
803+
{
804+
unsigned int timeout = RECEIVE_TIMEOUT_VALUE * length;
805+
while ((_i2cPort->available() < length) && (timeout-- != 0))
806+
;
807+
808+
if (timeout == 0)
809+
{
810+
return false;
811+
}
812+
813+
for (int i = 0; i < length; i++)
814+
{
815+
destination[i] = _i2cPort->read();
816+
}
817+
}
818+
return result;
803819
}
804820

805821
// writeByte(byte registerAddress, byte writeValue)
@@ -810,9 +826,9 @@ bool SX1509::readBytes(byte firstRegisterAddress, byte * destination, byte lengt
810826
bool SX1509::writeByte(byte registerAddress, byte writeValue)
811827
{
812828
_i2cPort->beginTransmission(deviceAddress);
813-
bool result = _i2cPort->write(registerAddress) && _i2cPort->write(writeValue);
814-
uint8_t endResult = _i2cPort->endTransmission();
815-
return result && (endResult == I2C_ERROR_OK);
829+
bool result = _i2cPort->write(registerAddress) && _i2cPort->write(writeValue);
830+
uint8_t endResult = _i2cPort->endTransmission();
831+
return result && (endResult == I2C_ERROR_OK);
816832
}
817833

818834
// writeWord(byte registerAddress, ungisnged int writeValue)
@@ -822,13 +838,13 @@ bool SX1509::writeByte(byte registerAddress, byte writeValue)
822838
// - Return value: true if succeeded, false if failed
823839
bool SX1509::writeWord(byte registerAddress, uint16_t writeValue)
824840
{
825-
byte msb, lsb;
826-
msb = ((writeValue & 0xFF00) >> 8);
827-
lsb = (writeValue & 0x00FF);
828-
_i2cPort->beginTransmission(deviceAddress);
829-
bool result = _i2cPort->write(registerAddress) && _i2cPort->write(msb) && _i2cPort->write(lsb);
830-
uint8_t endResult = _i2cPort->endTransmission();
831-
return result && (endResult == I2C_ERROR_OK);
841+
byte msb, lsb;
842+
msb = ((writeValue & 0xFF00) >> 8);
843+
lsb = (writeValue & 0x00FF);
844+
_i2cPort->beginTransmission(deviceAddress);
845+
bool result = _i2cPort->write(registerAddress) && _i2cPort->write(msb) && _i2cPort->write(lsb);
846+
uint8_t endResult = _i2cPort->endTransmission();
847+
return result && (endResult == I2C_ERROR_OK);
832848
}
833849

834850
// writeBytes(byte firstRegisterAddress, byte * writeArray, byte length)
@@ -838,14 +854,15 @@ bool SX1509::writeWord(byte registerAddress, uint16_t writeValue)
838854
// - writeArray should be an array of byte values to be written.
839855
// - length should be the number of bytes to be written.
840856
// - Return value: true if succeeded, false if failed
841-
bool SX1509::writeBytes(byte firstRegisterAddress, byte * writeArray, byte length)
842-
{
843-
_i2cPort->beginTransmission(deviceAddress);
844-
bool result = _i2cPort->write(firstRegisterAddress);
845-
int i = 0;
846-
while (result && i < length) {
847-
result = _i2cPort->write(writeArray[i++]);
848-
}
849-
uint8_t endResult = _i2cPort->endTransmission();
850-
return result && (endResult == I2C_ERROR_OK);
857+
bool SX1509::writeBytes(byte firstRegisterAddress, byte *writeArray, byte length)
858+
{
859+
_i2cPort->beginTransmission(deviceAddress);
860+
bool result = _i2cPort->write(firstRegisterAddress);
861+
int i = 0;
862+
while (result && i < length)
863+
{
864+
result = _i2cPort->write(writeArray[i++]);
865+
}
866+
uint8_t endResult = _i2cPort->endTransmission();
867+
return result && (endResult == I2C_ERROR_OK);
851868
}

0 commit comments

Comments
 (0)