You've already forked crosspoint-reader
mirror of
https://github.com/crosspoint-reader/crosspoint-reader.git
synced 2026-02-13 15:13:44 -08:00
## Summary Continue my changes to introduce the HAL infrastructure from https://github.com/crosspoint-reader/crosspoint-reader/pull/522 This PR touches quite a lot of files, but most of them are just name changing. It should not have any impacts to the end behavior. ## Additional Context My plan is to firstly add this small shim layer, which sounds useless at first, but then I'll implement an emulated driver which can be helpful for testing and for development. Currently, on my fork, I'm using a FS driver that allow "mounting" a local directory from my computer to the device, much like the `-v` mount option on docker. This allows me to quickly reset `.crosspoint` directory if anything goes wrong. I plan to upstream this feature when this PR get merged. --- ### AI Usage While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it helps set the right context for reviewers. Did you use AI tools to help write this code? NO
55 lines
2.0 KiB
C++
55 lines
2.0 KiB
C++
#pragma once
|
|
|
|
#include <SDCardManager.h>
|
|
|
|
#include <vector>
|
|
|
|
class HalStorage {
|
|
public:
|
|
HalStorage();
|
|
bool begin();
|
|
bool ready() const;
|
|
std::vector<String> listFiles(const char* path = "/", int maxFiles = 200);
|
|
// Read the entire file at `path` into a String. Returns empty string on failure.
|
|
String readFile(const char* path);
|
|
// Low-memory helpers:
|
|
// Stream the file contents to a `Print` (e.g. `Serial`, or any `Print`-derived object).
|
|
// Returns true on success, false on failure.
|
|
bool readFileToStream(const char* path, Print& out, size_t chunkSize = 256);
|
|
// Read up to `bufferSize-1` bytes into `buffer`, null-terminating it. Returns bytes read.
|
|
size_t readFileToBuffer(const char* path, char* buffer, size_t bufferSize, size_t maxBytes = 0);
|
|
// Write a string to `path` on the SD card. Overwrites existing file.
|
|
// Returns true on success.
|
|
bool writeFile(const char* path, const String& content);
|
|
// Ensure a directory exists, creating it if necessary. Returns true on success.
|
|
bool ensureDirectoryExists(const char* path);
|
|
|
|
FsFile open(const char* path, const oflag_t oflag = O_RDONLY);
|
|
bool mkdir(const char* path, const bool pFlag = true);
|
|
bool exists(const char* path);
|
|
bool remove(const char* path);
|
|
bool rmdir(const char* path);
|
|
|
|
bool openFileForRead(const char* moduleName, const char* path, FsFile& file);
|
|
bool openFileForRead(const char* moduleName, const std::string& path, FsFile& file);
|
|
bool openFileForRead(const char* moduleName, const String& path, FsFile& file);
|
|
bool openFileForWrite(const char* moduleName, const char* path, FsFile& file);
|
|
bool openFileForWrite(const char* moduleName, const std::string& path, FsFile& file);
|
|
bool openFileForWrite(const char* moduleName, const String& path, FsFile& file);
|
|
bool removeDir(const char* path);
|
|
|
|
static HalStorage& getInstance() { return instance; }
|
|
|
|
private:
|
|
static HalStorage instance;
|
|
|
|
bool initialized = false;
|
|
};
|
|
|
|
#define Storage HalStorage::getInstance()
|
|
|
|
// Downstream code must use Storage instead of SdMan
|
|
#ifdef SdMan
|
|
#undef SdMan
|
|
#endif
|