lvgl-v7/Origin__V0.3_LVGL7/UART/SimplUART/APP/SPI_Flash.c

110 lines
2.3 KiB
C
Raw Permalink Normal View History

2022-11-19 17:03:00 +00:00
#include <SWM320.h>
#include "type.h"
#include "BoardCfg.h"
#include "debug.h"
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
#if(SPI_FLASH)
/**********************************************************
HAL
**********************************************************/
#define SPI0_CS_Low() GPIO_ClrBit(GPIOP, PIN22)
#define SPI0_CS_High() GPIO_SetBit(GPIOP, PIN22)
/**
* @brief SPI0初始化
*
*/
static void This_SPI_Init(void) {
GPIO_Init(GPIOP, PIN22, 1, 0, 0);
PORT_Init(PORTP, PIN23, FUNMUX1_SPI0_SCLK, 0);
PORT_Init(PORTP, PIN18, FUNMUX0_SPI0_MOSI, 0);
PORT_Init(PORTP, PIN19, FUNMUX1_SPI0_MISO, 1);
SPI_InitStructure SPI_initStruct;
SPI_initStruct.clkDiv = SPI_CLKDIV_32;
SPI_initStruct.FrameFormat = SPI_FORMAT_SPI;
SPI_initStruct.SampleEdge = SPI_SECOND_EDGE;
SPI_initStruct.IdleLevel = SPI_HIGH_LEVEL;
SPI_initStruct.WordSize = 8;
SPI_initStruct.Master = 1;
SPI_initStruct.RXHFullIEn = 0;
SPI_initStruct.TXEmptyIEn = 0;
SPI_initStruct.TXCompleteIEn = 0;
SPI_Init(SPI0, &SPI_initStruct);
SPI_Open(SPI0);
}
/**
* @brief SPI_Flash初始化
*
*/
void SPI_FlashInit(void){
This_SPI_Init();
}
/**
* @brief SPI数据
*
* @param data
* @param len
*/
static void ThisSend(u8 * data,u32 len){
for (u32 i = 0; i < len; i++)
{
SPI_ReadWrite(SPI0, data[i]);
}
}
/**
* @brief
*
* @param data
* @return u8
*/
static u8 ThisReadWrite(u8 data){
return SPI_ReadWrite(SPI0, data);
}
/**
* @brief
*
*/
static void ThisCSLow(){
SPI0_CS_Low();
}
/**
* @brief
*
*/
static void ThisCSHigh(){
SPI0_CS_High();
}
/**********************************************************
**********************************************************/
// const u8 chipID_List[][2]={
// {0xef,}
// }
/**
* @brief Flash的ID
*
*/
void Flash_Read_ID(){
ThisCSLow();
ThisReadWrite(FLASH_CMD_READ_ID);
ThisReadWrite(0x00);
ThisReadWrite(0x00);
ThisReadWrite(0x00);
u8 factory = ThisReadWrite(0xff);
u8 device = ThisReadWrite(0xff);
Printf("factory:%d,device:%d\n", factory, device);
ThisCSHigh();
}
#endif