Browse Source

Add Wire.requestFrom() with 5 params

main
PaulStoffregen 5 years ago
parent
commit
760fcb7197
6 changed files with 53 additions and 1 deletions
  1. +17
    -0
      Wire.cpp
  2. +1
    -0
      Wire.h
  3. +16
    -1
      WireIMXRT.cpp
  4. +1
    -0
      WireIMXRT.h
  5. +17
    -0
      WireKinetis.cpp
  6. +1
    -0
      WireKinetis.h

+ 17
- 0
Wire.cpp View File

@@ -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

+ 1
- 0
Wire.h View File

@@ -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);

+ 16
- 1
WireIMXRT.cpp View File

@@ -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);
}




+ 1
- 0
WireIMXRT.h View File

@@ -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) {

+ 17
- 0
WireKinetis.cpp View File

@@ -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

+ 1
- 0
WireKinetis.h View File

@@ -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) {

Loading…
Cancel
Save