#line 1 "c:\\Users\\32244\\Documents\\Arduino\\generated_examples\\w25q128_spi\\src\\w25q128\\w25q128_spi.h"
#ifndef _w25q128_spi_h__
  #define _w25q128_spi_h__
#endif
#include <Arduino.h>
/* https://blog.csdn.net/ShenZhen_zixian/article/details/123202118 */
//////////////////////////////////////////////////////////////////////////
// #define NORFLASH_DEBUG_ENABLE  // uart debug
#define HARDWARE_SPI           // use hardware spi
// #define SOFTWARE_SPI           // use software spi
#define FLASH_TEST_ENABLE       //enable test
//////////////////////////////////////////////////////////////////////////
#define NORFLASH_CS_PIN         5
#define NORFLASH_CLK_PIN        18        
#define NORFLASH_MOSI_PIN       23       
#define NORFLASH_MISO_PIN       19        
// #define NORFLASH_HOLD_PIN       9   // hold pin no connect 3.3V 
// #define NORFLASH_WP_PIN         14  // hold pin no connect 3.3V  
#define NORFLASH_HOLD_PIN       -1     // hold pin connect 3.3V
#define NORFLASH_WP_PIN         -1     // wp pin connect 3.3V

#define ManufactDeviceID_CMD	  0x90   
#define READ_JEDEC_ID_CMD       0x9F
#define WRITE_STATUS            0x01    
#define READ_STATU_REGISTER_1   0x05    
#define READ_STATU_REGISTER_2   0x35
#define READ_DATA_CMD	          0x03
#define WRITE_ENABLE_CMD	      0x06
#define WRITE_DISABLE_CMD	      0x04
#define SECTOR_ERASE_CMD	      0x20
#define CHIP_ERASE_CMD	        0xC7
#define PAGE_PROGRAM_CMD        0x02

#define ONE_PAGE_SIZE           256     
#define SPI_FREQUENCY_4M        40*1000000



void norflash_spi_init(void);
void write_byte(uint8_t data);
uint8_t read_byte(uint8_t tx_data);
void write_enable(void);
void write_disable(void);
uint8_t read_status(void);
void check_busy(char *str);
void write_one_block_data(uint32_t addr, uint8_t * pbuf, uint16_t len);
void write_one_sector_data(uint32_t addr, uint8_t * pbuf, uint16_t len);
void write_arbitrary_data(uint32_t addr, uint8_t* pbuf, uint32_t len);
void read_data(uint32_t addr24, uint8_t *pbuf, uint32_t len);
void sector_erase(uint32_t addr24);
uint16_t read_norflash_id(void);

