Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Adafruit_FlashCache generic #174

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading