Merge pull request #31 from adafruit/cachedval
add some basic caching support for chips with write-only registers
This commit is contained in:
commit
f2a192c10b
|
|
@ -131,6 +131,9 @@ bool Adafruit_BusIO_Register::write(uint32_t value, uint8_t numbytes) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// store a copy
|
||||||
|
_cached = value;
|
||||||
|
|
||||||
for (int i = 0; i < numbytes; i++) {
|
for (int i = 0; i < numbytes; i++) {
|
||||||
if (_byteorder == LSBFIRST) {
|
if (_byteorder == LSBFIRST) {
|
||||||
_buffer[i] = value & 0xFF;
|
_buffer[i] = value & 0xFF;
|
||||||
|
|
@ -166,6 +169,12 @@ uint32_t Adafruit_BusIO_Register::read(void) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Read cached data from last time we wrote to this register
|
||||||
|
* @return Returns 0xFFFFFFFF on failure, value otherwise
|
||||||
|
*/
|
||||||
|
uint32_t Adafruit_BusIO_Register::readCached(void) { return _cached; }
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Read a buffer of data from the register location
|
* @brief Read a buffer of data from the register location
|
||||||
* @param buffer Pointer to data to read into
|
* @param buffer Pointer to data to read into
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ public:
|
||||||
bool read(uint8_t *value);
|
bool read(uint8_t *value);
|
||||||
bool read(uint16_t *value);
|
bool read(uint16_t *value);
|
||||||
uint32_t read(void);
|
uint32_t read(void);
|
||||||
|
uint32_t readCached(void);
|
||||||
bool write(uint8_t *buffer, uint8_t len);
|
bool write(uint8_t *buffer, uint8_t len);
|
||||||
bool write(uint32_t value, uint8_t numbytes = 0);
|
bool write(uint32_t value, uint8_t numbytes = 0);
|
||||||
|
|
||||||
|
|
@ -51,6 +52,7 @@ private:
|
||||||
uint8_t _width, _addrwidth, _byteorder;
|
uint8_t _width, _addrwidth, _byteorder;
|
||||||
uint8_t _buffer[4]; // we wont support anything larger than uint32 for
|
uint8_t _buffer[4]; // we wont support anything larger than uint32 for
|
||||||
// non-buffered read
|
// non-buffered read
|
||||||
|
uint32_t _cached = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue