2024-02-07 23:50:06 +01:00

76 lines
2.1 KiB
C++

#ifndef STA_SENSORS_W25Q128_HPP
#define STA_SENSORS_W25Q128_HPP
#include <sta/bus/spi/device.hpp>
#include <sta/sensors/w25qxx_defs.hpp>
namespace sta
{
class W25Qxx
{
public:
W25Qxx(SPIDevice * device);
uint8_t init();
public:
/*
* Status registers.
*/
/**
* @brief Read one of the flash's status registers.
*
* @param regID The ID of the status register. Can only be 1, 2 or 3.
* @param status_byte A pointer to the variable to write the state into.
* @return uint8_t Returns 1 if successful, 0 otherwise.
*/
uint8_t readStatusRegister(uint8_t regID, uint8_t * status_byte);
/**
* @brief Write into one of the chip's status registers.
*
* @param regID The ID of the status register. Can only be 1, 2 or 3.
* @param status_byte The byte to write into the status register.
* @param nonvolatile If set to true, this setting will be restored after power off.
* @return uint8_t Returns 1 if successful, 0 otherwise.
*/
uint8_t writeStatusRegister(uint8_t regID, uint8_t * status_byte, bool nonvolatile = false);
/**
* @brief Checks if the flash is busy writing or erasing.
*
* @return bool Returns true if the flash is busy, false otherwise.
*/
bool isBusy();
/**
* @brief Checks if the flash is write enabled.
*
* @return bool Returns true if the flash is write enabled, false otherwise.
*/
bool isWriteEnabled();
public:
uint8_t readData(const uint8_t * addr, uint8_t * buffer, size_t length);
uint8_t pageProgram(const uint8_t * addr, uint8_t * buffer, size_t length);
private:
uint8_t busWrite(uint8_t instruction, const uint8_t * data = nullptr, size_t length = 0);
uint8_t busRead(uint8_t instruction, uint8_t * data, size_t length);
uint8_t writeEnable();
uint8_t writeVolatileEnable();
uint8_t writeDisable();
SPIDevice * device_;
};
} // namespace sta
#endif // STA_SENSORS_W25Q128_HPP