New high-performance SX1509 pin read/write support that

doesn't send any i2c traffic until the calling code asks
it to.
pull/18/head
Jesse Vincent 10 years ago
parent db7f0993a1
commit 047f14d877

@ -152,6 +152,34 @@ byte sx1509Class::rawReadPin(byte pin)
return (readWord(REG_DATA_B) & (1<<pin));
}
void sx1509Class::fetchPinStates() {
pinData = readWord(REG_DATA_B);
}
void sx1509Class::sendPinStates() {
writeWord(REG_DATA_B,pinData);
}
byte sx1509Class::readPrefetchedPin(byte pin) {
return (pinData & (1 << pin));
}
void sx1509Class::updatePinState(byte pin, byte highLow)
{
if (highLow)
pinData = pinData | (1 <<pin);
else
pinData = pinData & ~(1<<pin);
}
byte sx1509Class::readPin(byte pin)
{

@ -44,6 +44,9 @@ private: // These private functions are not available to Arduino sketches.
// If you need to read or write directly to registers, consider
// putting the writeByte, readByte functions in the public section
uint8_t deviceAddress; // I2C Address of SX1509
unsigned int pinData; // used for the keyboardio hacks to do fewer i2c calls
// Pin definitions:
byte pinInterrupt;
byte pinOscillator;
@ -134,7 +137,11 @@ public:
// -----------------------------------------------------------------------------
byte readPin(byte pin);
byte rawReadPin(byte pin);
void fetchPinStates(void);
void sendPinStates(void);
byte readPrefetchedPin(byte pin);
void updatePinState(byte pin, byte highLow);
// -----------------------------------------------------------------------------
// ledDriverInit(byte pin, byte freq, bool log): This function initializes LED
// driving on a pin. It must be called if you want to use the pwm or blink

Loading…
Cancel
Save