#ifndef _SPI1_FLASH_H
#define _SPI1_FLASH_H

#include "include.h"
/*!                SPI_MODE
 * SPI_2WIRE_MODE:      CLK,DI/DO   (240Ω resistors between DI and DO) ;
 *
 * SPI_3WIRE_MODE:      CLK,DI,DO
 *
 * SPI_2BIT_BID_MODE:   CLK,2-DI/DO
 *
 * SPI_4BIT_BID_MODE:   CLK,4-DI/DO
 */

#define SPI_MODE                SPI_3WIRE_MODE  //SPI_2WIRE_MODE
#define SPIFALSH_BAUD           (12000000)      //SPI baud rate 500K
#define SPIFLASH_ID             0x40170000      //Determine whether FLASH is online by reading the ID, and change it to the ID corresponding to SPIFLASH

/**一般不需要改**/
void spi1_cs_en(void);
void spi1_cs_dis(void);
void spi1_cs_init(void);
#define TRACE(...)              printf(__VA_ARGS__) //调试信息输出
#define SPI1_CS_INIT()          spi1_cs_init()
#define SPI1_CS_EN()            spi1_cs_en()
#define SPI1_CS_DIS()           spi1_cs_dis()

#define SF_PROGRAM              0x02                //SPIFlash programming
#define SF_READ                 0x03                //SPIFlash Read
#define SF_READSSR              0x05                //SPIFlash Read Status Register
#define SF_WRITE_EN             0x06                //SPIFlash write enable
#define SF_ERASE                0x20                //SPIFlash erase//sector erase (4K erase)
/****************/

void spi1_init(u8 mode,u32 baud);
void spiflash1_read(void *buf, u32 addr, u32 len);
void spiflash1_write(void *buf, u32 addr, u32 len);
u32 spiflash1_id_read(void);
void spiflash1_erase(u32 addr);
void spiflash1_erase_block(u32 addr);
bool is_exspiflash_online(void);

void spiflash_run(void);

#endif
