@@ -130,6 +130,23 @@ uint8_t TwoWire::requestFrom(int address, int quantity, int sendStop) | |||
return requestFrom((uint8_t)address, (uint8_t)quantity, (uint8_t)sendStop); | |||
} | |||
uint8_t TwoWire::requestFrom(uint8_t addr, uint8_t qty, uint32_t iaddr, uint8_t n, uint8_t stop) | |||
{ | |||
if (n > 0) { | |||
union { uint32_t ul; uint8_t b[4]; } iaddress; | |||
iaddress.ul = iaddr; | |||
beginTransmission(addr); | |||
if (n > 3) n = 3; | |||
do { | |||
n = n - 1; | |||
write(iaddress.b[n]); | |||
} while (n > 0); | |||
endTransmission(false); | |||
} | |||
if (qty > BUFFER_LENGTH) qty = BUFFER_LENGTH; | |||
return requestFrom(addr, qty, stop); | |||
} | |||
void TwoWire::beginTransmission(uint8_t address) | |||
{ | |||
// indicate that we are transmitting |
@@ -71,6 +71,7 @@ class TwoWire : public Stream | |||
uint8_t requestFrom(uint8_t, uint8_t, uint8_t); | |||
uint8_t requestFrom(int, int); | |||
uint8_t requestFrom(int, int, int); | |||
uint8_t requestFrom(uint8_t, uint8_t, uint32_t, uint8_t, uint8_t); | |||
virtual size_t write(uint8_t); | |||
virtual size_t write(const uint8_t *, size_t); | |||
virtual int available(void); |
@@ -227,7 +227,22 @@ uint8_t TwoWire::requestFrom(uint8_t address, uint8_t length, uint8_t sendStop) | |||
return rxBufferLength; | |||
} | |||
uint8_t TwoWire::requestFrom(uint8_t addr, uint8_t qty, uint32_t iaddr, uint8_t n, uint8_t stop) | |||
{ | |||
if (n > 0) { | |||
union { uint32_t ul; uint8_t b[4]; } iaddress; | |||
iaddress.ul = iaddr; | |||
beginTransmission(addr); | |||
if (n > 3) n = 3; | |||
do { | |||
n = n - 1; | |||
write(iaddress.b[n]); | |||
} while (n > 0); | |||
endTransmission(false); | |||
} | |||
if (qty > BUFFER_LENGTH) qty = BUFFER_LENGTH; | |||
return requestFrom(addr, qty, stop); | |||
} | |||
@@ -96,6 +96,7 @@ public: | |||
uint8_t requestFrom(int address, int quantity) { | |||
return requestFrom((uint8_t)address, (uint8_t)quantity, (uint8_t)1); | |||
} | |||
uint8_t requestFrom(uint8_t addr, uint8_t qty, uint32_t iaddr, uint8_t n, uint8_t stop); | |||
virtual size_t write(uint8_t data); | |||
virtual size_t write(const uint8_t *data, size_t quantity); | |||
virtual int available(void) { |
@@ -804,6 +804,23 @@ uint8_t TwoWire::requestFrom(uint8_t address, uint8_t length, uint8_t sendStop) | |||
return count; | |||
} | |||
uint8_t TwoWire::requestFrom(uint8_t addr, uint8_t qty, uint32_t iaddr, uint8_t n, uint8_t stop) | |||
{ | |||
if (n > 0) { | |||
union { uint32_t ul; uint8_t b[4]; } iaddress; | |||
iaddress.ul = iaddr; | |||
beginTransmission(addr); | |||
if (n > 3) n = 3; | |||
do { | |||
n = n - 1; | |||
write(iaddress.b[n]); | |||
} while (n > 0); | |||
endTransmission(false); | |||
} | |||
if (qty > BUFFER_LENGTH) qty = BUFFER_LENGTH; | |||
return requestFrom(addr, qty, stop); | |||
} | |||
// for compatibility with examples that directly call this AVR-specific function | |||
// https://learn.adafruit.com/adafruit-tca9548a-1-to-8-i2c-multiplexer-breakout/wiring-and-test | |||
// https://forum.pjrc.com/threads/44922-Undefined-reference-to-twi_writeTo |
@@ -126,6 +126,7 @@ public: | |||
uint8_t requestFrom(int address, int quantity) { | |||
return requestFrom((uint8_t)address, (uint8_t)quantity, (uint8_t)1); | |||
} | |||
uint8_t requestFrom(uint8_t addr, uint8_t qty, uint32_t iaddr, uint8_t n, uint8_t stop); | |||
virtual size_t write(uint8_t data); | |||
virtual size_t write(const uint8_t *data, size_t quantity); | |||
virtual int available(void) { |