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

//#include "../../com/svc/svc_com.h"

#include  "sr_stddef.h"

/*FLASH芯片id*/
#define FLASH_ID 0X8512
/*FLASH块大小*/
#define FLASH_SECTOR_SIZE       ((uint32_t)4096)
#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_SPI                       SPI1
#define FLASH_SPI_CLK                   CLK_Peripheral_SPI1

#define FLASH_EN_GPIO_PORT              GPIOA                       /* GPIOA */
#define FLASH_EN_PIN                    GPIO_PIN_4                  /* PA.01 */

#define FLASH_SPI_SCK_GPIO_PORT         GPIOA                       /* GPIOF */
#define FLASH_SPI_SCK_PIN               GPIO_PIN_5                  /* PF.07 */

#define FLASH_SPI_MISO_GPIO_PORT        GPIOA                       /* GPIOF */
#define FLASH_SPI_MISO_PIN              GPIO_PIN_6                  /* PF.01 */

#define FLASH_SPI_MOSI_GPIO_PORT        GPIOA                       /* GPIOC */
#define FLASH_SPI_MOSI_PIN              GPIO_PIN_7                  /* PC.07 */

#define FLASH_CS_GPIO_PORT              GPIOB                       /* GPIOC */
#define FLASH_CS_PIN                    GPIO_PIN_0                  /* PC.00 */


/*flash电源打开*/
#define Bsp_Flash_Power_On()          GPIO_ResetBits(FLASH_EN_GPIO_PORT, FLASH_EN_PIN)

/*flash电源关闭*/
#define Bsp_Flash_Power_Off()         GPIO_SetBits(FLASH_EN_GPIO_PORT, FLASH_EN_PIN)
  


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