2020-05-07 17:53:51 +00:00
|
|
|
#pragma once
|
|
|
|
#include <cstddef>
|
|
|
|
|
|
|
|
namespace Pinetime {
|
|
|
|
namespace Drivers {
|
|
|
|
class Spi;
|
|
|
|
class SpiNorFlash {
|
|
|
|
public:
|
|
|
|
explicit SpiNorFlash(Spi& spi);
|
|
|
|
SpiNorFlash(const SpiNorFlash&) = delete;
|
|
|
|
SpiNorFlash& operator=(const SpiNorFlash&) = delete;
|
|
|
|
SpiNorFlash(SpiNorFlash&&) = delete;
|
|
|
|
SpiNorFlash& operator=(SpiNorFlash&&) = delete;
|
|
|
|
|
2020-05-11 16:50:37 +00:00
|
|
|
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);
|
2020-06-01 16:32:46 +00:00
|
|
|
void Write(uint32_t address, const uint8_t *buffer, size_t size);
|
2020-05-11 16:50:37 +00:00
|
|
|
void WriteEnable();
|
|
|
|
void SectorErase(uint32_t sectorAddress);
|
|
|
|
uint8_t ReadSecurityRegister();
|
|
|
|
bool ProgramFailed();
|
|
|
|
bool EraseFailed();
|
|
|
|
|
|
|
|
|
2020-05-07 17:53:51 +00:00
|
|
|
void Init();
|
|
|
|
void Uninit();
|
|
|
|
|
|
|
|
|
|
|
|
void Sleep();
|
|
|
|
void Wakeup();
|
|
|
|
private:
|
2020-05-11 16:50:37 +00:00
|
|
|
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;
|
|
|
|
|
2020-05-07 17:53:51 +00:00
|
|
|
Spi& spi;
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|