add some basic caching support for chips with write-only registers
This commit is contained in:
parent
22ea3a921c
commit
780626ce54
|
|
@ -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,15 @@ 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
|
||||
|
|
@ -195,6 +207,7 @@ bool Adafruit_BusIO_Register::read(uint8_t *buffer, uint8_t len) {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* @brief Read 2 bytes of data from the register location
|
||||
* @param value Pointer to uint16_t variable to read into
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
||||
/*!
|
||||
|
|
|
|||
Loading…
Reference in New Issue