Skip to content

Commit

Permalink
Merge pull request #174 from attermann/inheritance
Browse files Browse the repository at this point in the history
Make Adafruit_FlashCache generic
  • Loading branch information
hathach authored Aug 28, 2024
2 parents 160b5ff + 0404b97 commit d8353ba
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
9 changes: 5 additions & 4 deletions src/Adafruit_FlashCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* THE SOFTWARE.
*/

#include "Adafruit_SPIFlash.h"
#include "Adafruit_FlashCache.h"
#include "Adafruit_SPIFlashBase.h"

#if SPIFLASH_DEBUG
#define SPICACHE_LOG(_new_addr) \
Expand All @@ -49,7 +50,7 @@ static inline uint32_t offset_of(uint32_t addr) {

Adafruit_FlashCache::Adafruit_FlashCache(void) { _addr = INVALID_ADDR; }

bool Adafruit_FlashCache::sync(Adafruit_SPIFlash *fl) {
bool Adafruit_FlashCache::sync(Adafruit_SPIFlashBase *fl) {
if (_addr == INVALID_ADDR) {
return true;
}
Expand All @@ -62,7 +63,7 @@ bool Adafruit_FlashCache::sync(Adafruit_SPIFlash *fl) {
return true;
}

bool Adafruit_FlashCache::write(Adafruit_SPIFlash *fl, uint32_t address,
bool Adafruit_FlashCache::write(Adafruit_SPIFlashBase *fl, uint32_t address,
void const *src, uint32_t len) {
uint8_t const *src8 = (uint8_t const *)src;
uint32_t remain = len;
Expand Down Expand Up @@ -96,7 +97,7 @@ bool Adafruit_FlashCache::write(Adafruit_SPIFlash *fl, uint32_t address,
return true;
}

bool Adafruit_FlashCache::read(Adafruit_SPIFlash *fl, uint32_t address,
bool Adafruit_FlashCache::read(Adafruit_SPIFlashBase *fl, uint32_t address,
uint8_t *buffer, uint32_t count) {
// overwrite with cache value if available
if ((_addr != INVALID_ADDR) &&
Expand Down
9 changes: 5 additions & 4 deletions src/Adafruit_FlashCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <stdint.h>

// forward declaration
class Adafruit_SPIFlash;
class Adafruit_SPIFlashBase;

class Adafruit_FlashCache {
private:
Expand All @@ -39,10 +39,11 @@ class Adafruit_FlashCache {
public:
Adafruit_FlashCache(void);

bool sync(Adafruit_SPIFlash *fl);
bool write(Adafruit_SPIFlash *fl, uint32_t dst, void const *src,
bool sync(Adafruit_SPIFlashBase *fl);
bool write(Adafruit_SPIFlashBase *fl, uint32_t dst, void const *src,
uint32_t len);
bool read(Adafruit_SPIFlash *fl, uint32_t addr, uint8_t *dst, uint32_t count);
bool read(Adafruit_SPIFlashBase *fl, uint32_t addr, uint8_t *dst,
uint32_t count);
};

#endif /* ADAFRUIT_FLASHCACHE_H_ */
2 changes: 1 addition & 1 deletion src/Adafruit_SPIFlash.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class Adafruit_SPIFlash : public FsBlockDeviceInterface,
return writeSectors(block, src, nb);
}

private:
protected:
bool _cache_en;
Adafruit_FlashCache *_cache;
};
Expand Down

0 comments on commit d8353ba

Please sign in to comment.