40 lines
1.4 KiB
C++
40 lines
1.4 KiB
C++
#ifndef NORFLASH_H
|
|
#define NORFLASH_H
|
|
#include <stdint.h>
|
|
#include "spiblocked.h"
|
|
/// Enumerace povelů pro SPI FLASH.
|
|
enum FLASH_COMMANDS : uint8_t {
|
|
/* single byte commands */
|
|
FLASH_WRDI = 0x04, // nepoužito
|
|
FLASH_WREN = 0x06,
|
|
FLASH_RDID = 0x9F,
|
|
FLASHRSTEN = 0x66, // nepoužito
|
|
FLASH__RST = 0x99, // nepoužito
|
|
FLASH__RES = 0xAB, // release from power down, nepoužito
|
|
FLASH__DPD = 0xB9, // power down, nepoužito
|
|
// multi - byte
|
|
FLASH_RDSR1 = 0x05,
|
|
// dále se mohou povely lišit
|
|
FLASH_RDSR2 = 0x35, // nepoužito
|
|
FLASH_4READ = 0x03,
|
|
FLASH_4PP = 0x02,
|
|
FLASH_4SE = 0x20,
|
|
};
|
|
|
|
class NorFlash {
|
|
SpiBlocked spi;
|
|
public:
|
|
explicit NorFlash () noexcept;
|
|
unsigned ReadBlock (const unsigned addr, uint8_t * data, const unsigned len);
|
|
unsigned WriteBlock (const unsigned addr, const uint8_t * data, const unsigned len);
|
|
bool EraseSector (const unsigned addr);
|
|
protected:
|
|
/// Jednoduchý příkaz
|
|
bool SingleCommand (const FLASH_COMMANDS cmd) const;
|
|
/// Načtení registru STATUS1 nebo STATUS2 pomocí FLASH_RDSRx
|
|
uint8_t ReadStatus (const FLASH_COMMANDS cmd) const;
|
|
/// Čekání na dokončení operace zápisu / mazání
|
|
bool WaitForReady (const unsigned ms = 5u) const;
|
|
};
|
|
|
|
#endif // NORFLASH_H
|