diff options
| author | JF <jf@codingfield.com> | 2020-05-11 16:50:37 (GMT) |
|---|---|---|
| committer | JF <jf@codingfield.com> | 2020-05-11 16:50:37 (GMT) |
| commit | ee05577dd62c64d0e6a2e497b75710c7a1351557 (patch) | |
| tree | 36d36462bd1c3aaa06df46b0bf6086111c83df2b /src/drivers/SpiNorFlash.h | |
| parent | 0b8e6c3fa20457bce931b1d289f187e46fc68307 (diff) | |
Fix race conditions on SPI and integrate the SPI NOR Flash driver into DFUService (WIP)
Diffstat (limited to 'src/drivers/SpiNorFlash.h')
| -rw-r--r-- | src/drivers/SpiNorFlash.h | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/drivers/SpiNorFlash.h b/src/drivers/SpiNorFlash.h index 839a1c2..b5f1920 100644 --- a/src/drivers/SpiNorFlash.h +++ b/src/drivers/SpiNorFlash.h @@ -12,6 +12,26 @@ namespace Pinetime { SpiNorFlash(SpiNorFlash&&) = delete; SpiNorFlash& operator=(SpiNorFlash&&) = delete; + typedef struct __attribute__((packed)) { + uint8_t manufacturer = 0; + uint8_t type = 0; + uint8_t density = 0; + } Identification; + + Identification ReadIdentificaion(); + uint8_t ReadStatusRegister(); + bool WriteInProgress(); + bool WriteEnabled(); + uint8_t ReadConfigurationRegister(); + void Read(uint32_t address, uint8_t* buffer, size_t size); + void Write(uint32_t address, uint8_t *buffer, size_t size); + void WriteEnable(); + void SectorErase(uint32_t sectorAddress); + uint8_t ReadSecurityRegister(); + bool ProgramFailed(); + bool EraseFailed(); + + void Init(); void Uninit(); @@ -19,6 +39,18 @@ namespace Pinetime { void Sleep(); void Wakeup(); private: + enum class Commands : uint8_t { + PageProgram = 0x02, + Read = 0x03, + ReadStatusRegister = 0x05, + WriteEnable = 0x06, + ReadConfigurationRegister = 0x15, + SectorErase = 0x20, + ReadSecurityRegister = 0x2B, + ReadIdentification = 0x9F, + }; + static constexpr uint16_t pageSize = 256; + Spi& spi; }; |
