-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathSST25VF.h
67 lines (49 loc) · 1.82 KB
/
SST25VF.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/************************************************************************************
*
* Name : SST25VF.h
* Author : Noah Shibley
* Contributors: Ubi de Feo [SPI Transactions implementation]
* Date : Aug 17th, 2013
* Version : 0.1
* Notes : Nor Serial Flash 16Mbit (2Mbytes) - S71295 (SST) 2097152 bytes.
* Based on SST code from: www.Beat707.com design. (Rugged Circuits and Wusik)
* Should work for SST25VF004, SST25VF016, SST25VF064, etc.
*
*
*
***********************************************************************************/
//include guard
#ifndef SST25VF_H
#define SST25VF_H
#include <SPI.h>
#define FLASH_MAX_BYTES 2097152 //this chip contains this much storage
#define FLASH_MAX_SECTOR 512 //each sector is 4096 bytes
#define SST25VF_SPI_MODE SPI_MODE0
#define SST25VF_SPI_CLOCK F_CPU
#define SST25VF_SPI_BIT_ORDER MSBFIRST
class SST25VF {
public:
SST25VF();
void begin(int chipSelect,int writeProtect,int hold);
void update();
void readID();
void totalErase();
void sectorErase(uint8_t sectorAddress);
void readInit(uint32_t address);
uint8_t readNext();
void readFinish();
void readArray(uint32_t address,uint8_t dataBuffer[],uint16_t dataLength);
void writeByte(uint32_t address, uint8_t data);
uint32_t writeArray(uint32_t address,const uint8_t dataBuffer[],uint16_t dataLength);
private:
void init();
char buf[16];
uint8_t FLASH_SSn; //chip select pin
uint8_t FLASH_Wp; //Write protection pin
uint8_t FLASH_Hold; //read/write hold pin (pause)
void waitUntilDone();
void setAddress(uint32_t addr);
inline void volatile nop(void) { asm __volatile__ ("nop"); }
SPISettings sstSPISettings;
};
#endif