Prusa3d Marlin fork
xflash.h
1 //xflash.h
2 #ifndef _XFLASH_H
3 #define _XFLASH_H
4 
5 #include <inttypes.h>
6 #include "config.h"
7 #include "spi.h"
8 
9 
10 
11 #define XFLASH_STATUS_BUSY 0x01
12 #define XFLASH_STATUS_WEL 0x02
13 #define XFLASH_STATUS_BP0 0x04
14 #define XFLASH_STATUS_BP1 0x08
15 #define XFLASH_STATUS_TB 0x20
16 #define XFLASH_STATUS_SRP 0x80
17 
18 #define XFLASH_SPI_RATE 0 // fosc/4 = 4MHz
19 #define XFLASH_SPCR SPI_SPCR(XFLASH_SPI_RATE, 1, 1, 1, 0)
20 #define XFLASH_SPSR SPI_SPSR(XFLASH_SPI_RATE)
21 
22 #define XFLASH_SPI_ENTER() spi_setup(XFLASH_SPCR, XFLASH_SPSR)
23 
24 #if defined(__cplusplus)
25 extern "C" {
26 #endif //defined(__cplusplus)
27 
28 
29 extern int8_t xflash_init(void);
30 extern void xflash_enable_wr(void);
31 extern void xflash_disable_wr(void);
32 extern uint8_t xflash_rd_status_reg(void);
33 #if 0
34 extern void w25x20cl_wr_status_reg(uint8_t val);
35 #endif
36 extern void xflash_rd_data(uint32_t addr, uint8_t* data, uint16_t cnt);
37 
38 extern void xflash_sector_erase(uint32_t addr);
39 extern void xflash_block32_erase(uint32_t addr);
40 extern void xflash_block64_erase(uint32_t addr);
41 extern void xflash_chip_erase(void);
42 extern void xflash_rd_uid(uint8_t* uid);
43 extern void xflash_wait_busy(void);
44 
45 // write up to a single page of data (256bytes)
46 extern void xflash_page_program(uint32_t addr, uint8_t* data, uint16_t cnt);
47 
48 // write up to a single page of data from program memory
49 extern void xflash_page_program_P(uint32_t addr, uint8_t* data, uint16_t cnt);
50 
51 // xflash_multipage_program: high-level interface for multi-page writes.
52 // Write any amount of data, chunking writes to page boundaries as needed.
53 // Automatically enables writes and waits for completion.
54 extern void xflash_multipage_program(uint32_t addr, uint8_t* data, uint16_t cnt);
55 
56 #if defined(__cplusplus)
57 }
58 #endif //defined(__cplusplus)
59 #endif //_XFLASH_H