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

110 lines
2.3 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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