summaryrefslogtreecommitdiff
path: root/src/drivers/SpiNorFlash.h
diff options
context:
space:
mode:
authorJF <jf@codingfield.com>2020-06-07 14:17:45 +0200
committerGitea <gitea@fake.local>2020-06-07 14:17:45 +0200
commita0e73f5c1a1e652aa6270b7e42a73aee3d12ded6 (patch)
tree6205dfb543bb22245d39a2f6e44d2c26cb381c10 /src/drivers/SpiNorFlash.h
parent8a94750e30399bfb204cbec59a769d9d1b6b5baa (diff)
parentdbdb26ae1fa45cec88f1b9ea0353b3d0a3c39f56 (diff)
Merge branch 'develop' of JF/PineTime into master
Diffstat (limited to 'src/drivers/SpiNorFlash.h')
-rw-r--r--src/drivers/SpiNorFlash.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/drivers/SpiNorFlash.h b/src/drivers/SpiNorFlash.h
new file mode 100644
index 00000000..98267c09
--- /dev/null
+++ b/src/drivers/SpiNorFlash.h
@@ -0,0 +1,60 @@
+#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;
+
+ 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, const uint8_t *buffer, size_t size);
+ void WriteEnable();
+ void SectorErase(uint32_t sectorAddress);
+ uint8_t ReadSecurityRegister();
+ bool ProgramFailed();
+ bool EraseFailed();
+
+
+ void Init();
+ void Uninit();
+
+
+ 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;
+
+ };
+ }
+}
+
+