Merge pull request #31 from adafruit/cachedval

add some basic caching support for chips with write-only registers
This commit is contained in:
siddacious 2020-06-30 11:45:55 -07:00 committed by GitHub
commit f2a192c10b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -131,6 +131,9 @@ bool Adafruit_BusIO_Register::write(uint32_t value, uint8_t numbytes) {
return false;
}
// store a copy
_cached = value;
for (int i = 0; i < numbytes; i++) {
if (_byteorder == LSBFIRST) {
_buffer[i] = value & 0xFF;
@ -166,6 +169,12 @@ uint32_t Adafruit_BusIO_Register::read(void) {
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
* @param buffer Pointer to data to read into

View File

@ -35,6 +35,7 @@ public:
bool read(uint8_t *value);
bool read(uint16_t *value);
uint32_t read(void);
uint32_t readCached(void);
bool write(uint8_t *buffer, uint8_t len);
bool write(uint32_t value, uint8_t numbytes = 0);
@ -51,6 +52,7 @@ private:
uint8_t _width, _addrwidth, _byteorder;
uint8_t _buffer[4]; // we wont support anything larger than uint32 for
// non-buffered read
uint32_t _cached = 0;
};
/*!