| #pragma once |
| |
| #include <Arduino.h> |
| #include <stdint.h> |
| |
| #include "pw_result/result.h" |
| #include "pw_span/span.h" |
| #include "pw_status/status.h" |
| |
| using pw::span; |
| using pw::Status; |
| |
| namespace gonk::spi_flash { |
| |
| class SpiFlash { |
| public: |
| struct DeviceId { |
| uint8_t manufacturer_id; |
| uint8_t family_code; |
| uint8_t product_version; |
| }; |
| |
| SpiFlash(uint16_t flash_cs, uint32_t baudrate, SPIClass &flash_spi); |
| |
| Status WriteEnable(); |
| Status WriteDisable(); |
| pw::Result<DeviceId> GetDeviceIds(); |
| std::bitset<8> StatusRegister(); |
| bool IsBusy(); |
| bool WritingIsEnabled(); |
| Status Erase(); |
| void StartFlashSpi(); |
| void StopFlashSpi(); |
| void ResumeFromPowerDown(); |
| |
| private: |
| uint16_t flash_cs_; |
| SPISettings spi_settings_; |
| SPIClass &flash_spi_; |
| }; |
| |
| } // namespace gonk::spi_flash |