Add support for SpiNorFlash and FS (#30)
The external SPI flash is implemented as a 4MB on the local filesystem. This allows the FS (littleFS) and settings to work properly. Remove the simulated `FS.h` and `FS.cpp`, because we can now use the files from InfiniTime directly as the heavy lifting is done in the simulated `SpiNorFlash.h` and cpp files. `SpiNorFlash.h` provides read and write functions with `uint8_t` buffer, but `fs::fstream` expects `char` buffer. Use `reinterpret_cast` and check if by any chance the `char` type on a platform is implemented with more than one byte. Then the `reinterpret_cast<char *>(buffer)` would change the meaning of the `size` parameter, which could lead to garbage data. Co-authored-by: Reinhold Gschweicher <pyro4hell@gmail.com>
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
#pragma once
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Drivers {
|
||||
class Spi;
|
||||
class SpiNorFlash {
|
||||
public:
|
||||
explicit SpiNorFlash(Spi& spi);
|
||||
explicit SpiNorFlash(const std::string& memoryFilePath);
|
||||
~SpiNorFlash();
|
||||
SpiNorFlash(const SpiNorFlash&) = delete;
|
||||
SpiNorFlash& operator=(const SpiNorFlash&) = delete;
|
||||
SpiNorFlash(SpiNorFlash&&) = delete;
|
||||
@@ -53,8 +55,12 @@ namespace Pinetime {
|
||||
};
|
||||
static constexpr uint16_t pageSize = 256;
|
||||
|
||||
Spi& spi;
|
||||
static constexpr size_t memorySize {0x400000};
|
||||
const std::string& memoryFilePath;
|
||||
|
||||
|
||||
Identification device_id;
|
||||
std::fstream memoryFile;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user