2019-10-05 19:00:10 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2019 Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef SPIFLASH_HPP
|
|
|
|
|
#define SPIFLASH_HPP
|
|
|
|
|
|
2020-04-21 09:00:57 +02:00
|
|
|
#include "spiInterface.hpp"
|
2019-10-05 19:00:10 +02:00
|
|
|
|
|
|
|
|
class SPIFlash {
|
|
|
|
|
public:
|
2021-01-30 07:57:49 +01:00
|
|
|
SPIFlash(SPIInterface *spi, int8_t verbose);
|
2019-10-05 19:00:10 +02:00
|
|
|
/* power */
|
|
|
|
|
void power_up();
|
|
|
|
|
void power_down();
|
|
|
|
|
void reset();
|
|
|
|
|
/* protection */
|
2019-11-21 09:19:48 +01:00
|
|
|
int write_enable();
|
2019-10-05 19:00:10 +02:00
|
|
|
int write_disable();
|
|
|
|
|
int disable_protection();
|
2021-05-05 06:59:02 +02:00
|
|
|
/*!
|
|
|
|
|
* \brief unlock all sectors: specific to
|
|
|
|
|
* Microchip SST26VF032B / SST26VF032BA
|
|
|
|
|
* \return false if unlock fail
|
|
|
|
|
*/
|
|
|
|
|
bool global_unlock();
|
2019-10-05 19:00:10 +02:00
|
|
|
/* erase */
|
|
|
|
|
int bulk_erase();
|
|
|
|
|
int sector_erase(int addr);
|
|
|
|
|
int sectors_erase(int base_addr, int len);
|
|
|
|
|
/* write */
|
|
|
|
|
int write_page(int addr, uint8_t *data, int len);
|
2020-08-23 17:14:21 +02:00
|
|
|
/* read */
|
|
|
|
|
int read(int base_addr, uint8_t *data, int len);
|
2019-10-05 19:00:10 +02:00
|
|
|
/* combo flash + erase */
|
|
|
|
|
int erase_and_prog(int base_addr, uint8_t *data, int len);
|
|
|
|
|
/* display/info */
|
2019-11-21 09:19:48 +01:00
|
|
|
uint8_t read_status_reg();
|
2019-10-05 19:00:10 +02:00
|
|
|
void read_id();
|
2020-08-23 17:14:21 +02:00
|
|
|
uint16_t readNonVolatileCfgReg();
|
|
|
|
|
uint16_t readVolatileCfgReg();
|
2019-10-05 19:00:10 +02:00
|
|
|
private:
|
2020-04-21 09:00:57 +02:00
|
|
|
SPIInterface *_spi;
|
2021-01-30 07:57:49 +01:00
|
|
|
int8_t _verbose;
|
2021-05-05 06:25:00 +02:00
|
|
|
uint32_t _jedec_id; /**< CHIP ID */
|
2019-10-05 19:00:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|