/*
 * @Description: 存储模块-bsp层-型号w25x
 * @Author: yangsw
 * @Date: 2021-05-20 18:35:04
 * @LastEditTime: 2023-05-25 11:50:57
 * @LastEditors: Lida
 * @Reference: 
 */
#ifndef _SR_BSP_W25X_H
#define _SR_BSP_W25X_H


#include  "sr_stddef.h"
#include  "sr_gpio.h"


/*FLASH芯片id*/
#define FLASH_ID 0X8512
/*FLASH块大小*/
#define FLASH_SECTOR_SIZE       ((uint32_t)4096)


/*FLASH寄存器地址*/
#define W25X_WriteEnable        0x06
#define W25X_WriteDisable       0x04
#define W25X_ReadStatusReg      0x05
#define W25X_WriteStatusReg     0x01
#define W25X_ReadData           0x03
#define W25X_FastReadData       0x0B
#define W25X_FastReadDual       0x3B
#define W25X_PageProgram        0x02
#define W25X_BlockErase         0xD8
#define W25X_SectorErase        0x20
#define W25X_ChipErase          0xC7
#define W25X_PowerDown          0xB9
#define W25X_ReleasePowerDown   0xAB
#define W25X_DeviceID           0xAB
#define W25X_ManufactDeviceID   0x90
#define W25X_JedecDeviceID      0x9F


#define FLASH_PWR_EN_ID      SR_GPIO4    //PA4
#define FLASH_SPI_SCK_ID     SR_GPIO5    //PA5
#define FLASH_SPI_MISO_ID    SR_GPIO6    //PA6
#define FLASH_SPI_MOSI_ID    SR_GPIO7    //PA7
#define FLASH_SPI_CS_ID      SR_GPIO20   //PB0

/*flash电源打开*/
#define Bsp_Flash_Power_On()          SR_HalGpioWrite(FLASH_PWR_EN_ID, SR_GPIO_LOW)

/*flash电源关闭*/
#define Bsp_Flash_Power_Off()         SR_HalGpioWrite(FLASH_PWR_EN_ID, SR_GPIO_HIGH)
  


int Bsp_Flash_Init();

uint16_t Bsp_Flash_Read_Id(void);
void Bsp_Flash_Powerdown(void);
void Bsp_Flash_Release_Powerdown(void);

void Bsp_Flash_Erase_Sector(uint16_t sector_addr);
void Bsp_Flash_Read(uint8_t *out_buff,uint32_t read_addr,uint16_t read_num);
void Bsp_Flash_Write(uint8_t* data,uint32_t write_addr,uint16_t write_num);


#endif