移除多余文件
This commit is contained in:
parent
c2b3cdd592
commit
5ab3868114
@ -1,20 +0,0 @@
|
||||
//HC12 库
|
||||
|
||||
#include "string.h"
|
||||
|
||||
#include "systick.h"
|
||||
|
||||
#include "hc25.h"
|
||||
|
||||
/**************************************** 私有变量 ****************************************/
|
||||
|
||||
/*****************************************************************************************/
|
||||
|
||||
/**************************************** 私有函数 ****************************************/
|
||||
|
||||
/*****************************************************************************************/
|
||||
|
||||
void HC12_Init(void)
|
||||
{
|
||||
|
||||
}
|
||||
@ -1,19 +0,0 @@
|
||||
//HC12 ¿â
|
||||
|
||||
#ifndef __HC12_H
|
||||
#define __HC12_H
|
||||
|
||||
#include "uart.h"
|
||||
|
||||
#define HC12_COM COM3
|
||||
|
||||
#define HC12_SendBuff(__pdata__, __data_len__) Uart_SendBuf(HC12_COM, __pdata__, __data_len__)
|
||||
#define HC12_Receive(__pdata__) Uart_GetChar(HC12_COM, __pdata__)
|
||||
#define HC12_ReceiveBuffUntil(__pdata__, __end_byte__, __timeout__) Uart_GetBuffUntil(HC12_COM, __pdata__, __end_byte__, __timeout__)
|
||||
#define HC12_ClearSend Uart_ClearTxFifo(HC12_COM)
|
||||
#define HC12_ClearReceive Uart_ClearRxFifo(HC12_COM)
|
||||
#define HC12_BindReceiveHandle(__receive__) Uart_BindReceiveHandle(HC12_COM, __receive__)
|
||||
|
||||
void HC12_Init(void);
|
||||
|
||||
#endif
|
||||
@ -1,32 +0,0 @@
|
||||
//HC25 库
|
||||
|
||||
#include "string.h"
|
||||
|
||||
#include "systick.h"
|
||||
|
||||
#include "led.h"
|
||||
|
||||
#include "hc25.h"
|
||||
|
||||
/**************************************** 私有变量 ****************************************/
|
||||
|
||||
uint8_t is_at_mode = 1; //开机时默认 AT 模式打开,防止出错
|
||||
uint8_t at_cmd[30];
|
||||
|
||||
/*****************************************************************************************/
|
||||
|
||||
/**************************************** 私有函数 ****************************************/
|
||||
|
||||
/*****************************************************************************************/
|
||||
|
||||
void HC25_Init(void)
|
||||
{
|
||||
HC25_ExitATMode;
|
||||
}
|
||||
|
||||
void HC25_SendATCmd(uint8_t *cmd)
|
||||
{
|
||||
strcpy(at_cmd, "AT+");
|
||||
strcat(at_cmd, cmd);
|
||||
HC25_SendBuff(at_cmd, strlen(at_cmd) + 1);
|
||||
}
|
||||
@ -1,39 +0,0 @@
|
||||
//HC25 ¿â
|
||||
|
||||
#ifndef __HC25_H
|
||||
#define __HC25_H
|
||||
|
||||
#include "sys.h"
|
||||
#include "uart.h"
|
||||
|
||||
#define HC25_COM COM2
|
||||
|
||||
#define HC25_SendBuff(__pdata__, __data_len__) \
|
||||
Uart_SendBuf(HC25_COM, __pdata__, __data_len__); \
|
||||
Delay_ms(50)
|
||||
#define HC25_Receive(__pdata__) Uart_GetChar(HC25_COM, __pdata__)
|
||||
#define HC25_ReceiveBuffUntil(__pdata__, __end_byte__, __timeout__) Uart_GetBuffUntil(HC25_COM, __pdata__, __end_byte__, __timeout__)
|
||||
#define HC25_ClearSend Uart_ClearTxFifo(HC25_COM)
|
||||
#define HC25_ClearReceive Uart_ClearRxFifo(HC25_COM)
|
||||
#define HC25_EnterATMode \
|
||||
if (is_at_mode == 0) \
|
||||
{ \
|
||||
HC25_SendBuff("+++", 4); \
|
||||
Delay_ms(200); \
|
||||
is_at_mode = 1; \
|
||||
HC25_ClearReceive; \
|
||||
}
|
||||
#define HC25_ExitATMode \
|
||||
if (is_at_mode == 1) \
|
||||
{ \
|
||||
HC25_SendATCmd("ENTM"); \
|
||||
Delay_ms(200); \
|
||||
is_at_mode = 0; \
|
||||
HC25_ClearReceive; \
|
||||
}
|
||||
|
||||
void HC25_Init(void);
|
||||
|
||||
void HC25_SendATCmd(uint8_t *cmd);
|
||||
|
||||
#endif
|
||||
@ -1,348 +0,0 @@
|
||||
//按键 FIFO 库
|
||||
|
||||
#include "adc.h"
|
||||
|
||||
#include "key.h"
|
||||
|
||||
#define DIGITAL_KEY_NUM 3 //数字信号按键个数
|
||||
#define ADC_KEY_NUM 4 //模拟信号按键个数
|
||||
#define KEY_COUNT (DIGITAL_KEY_NUM + ADC_KEY_NUM)
|
||||
|
||||
//使能 GPIO 时钟
|
||||
#define ALL_KEY_GPIO_CLK_ENABLE() \
|
||||
{ \
|
||||
__HAL_RCC_GPIOE_CLK_ENABLE(); \
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE(); \
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE(); \
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GPIO_TypeDef *gpio;
|
||||
uint16_t pin;
|
||||
} X_GPIO_T;
|
||||
|
||||
static const X_GPIO_T s_gpio_list[DIGITAL_KEY_NUM] = {
|
||||
{GPIOE, GPIO_PIN_3}, //KEY1
|
||||
{GPIOC, GPIO_PIN_5}, //KEY2
|
||||
{GPIOD, GPIO_PIN_10} //JOY_OK
|
||||
};
|
||||
|
||||
static volatile KEY_T s_tBtn[KEY_COUNT] = {0};
|
||||
static volatile KEY_FIFO_T s_tKey; //按键 FIFO 变量
|
||||
static volatile is_key_clear = 1;
|
||||
|
||||
static void InitKeyVar(void);
|
||||
static void InitKeyDigital(void);
|
||||
static void DetectKey(uint8_t i);
|
||||
|
||||
static uint8_t KeyPinActive(uint8_t _id)
|
||||
{
|
||||
if (_id < DIGITAL_KEY_NUM)
|
||||
{
|
||||
uint8_t level;
|
||||
|
||||
if ((s_gpio_list[_id].gpio->IDR & s_gpio_list[_id].pin) == 0)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
else if (_id < DIGITAL_KEY_NUM + ADC_KEY_NUM)
|
||||
{
|
||||
switch (_id)
|
||||
{
|
||||
case JOY_U:
|
||||
{
|
||||
if (ADC_Get_PC0() < 0.01)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case JOY_D:
|
||||
{
|
||||
if (ADC_Get_PC0() > 3.20)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case JOY_L:
|
||||
{
|
||||
if (ADC_Get_PC1() < 0.01)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case JOY_R:
|
||||
{
|
||||
if (ADC_Get_PC1() > 3.20)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t IsKeyDownFunc(uint8_t _id)
|
||||
{
|
||||
uint8_t count = 0;
|
||||
uint8_t save = UINT8_MAX;
|
||||
|
||||
//判断有几个键按下
|
||||
for (uint8_t i = 0; i < KEY_COUNT; i++)
|
||||
{
|
||||
if (KeyPinActive(i))
|
||||
{
|
||||
count++;
|
||||
save = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (count == 1 && save == _id)
|
||||
return 1; //只有单个键按下时才有效
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 初始化按键
|
||||
*/
|
||||
void KEY_Init(void)
|
||||
{
|
||||
InitKeyVar(); //初始化按键变量
|
||||
InitKeyDigital(); //初始化数字按键
|
||||
}
|
||||
|
||||
static void InitKeyDigital(void)
|
||||
{
|
||||
GPIO_InitTypeDef gpio_init;
|
||||
|
||||
ALL_KEY_GPIO_CLK_ENABLE();
|
||||
|
||||
gpio_init.Mode = GPIO_MODE_INPUT;
|
||||
gpio_init.Pull = GPIO_PULLUP;
|
||||
gpio_init.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
|
||||
for (uint8_t i = 0; i < DIGITAL_KEY_NUM; i++)
|
||||
{
|
||||
gpio_init.Pin = s_gpio_list[i].pin;
|
||||
HAL_GPIO_Init(s_gpio_list[i].gpio, &gpio_init);
|
||||
}
|
||||
}
|
||||
|
||||
static void InitKeyVar(void)
|
||||
{
|
||||
s_tKey.Read = 0;
|
||||
s_tKey.Write = 0;
|
||||
|
||||
//缺省值
|
||||
for (uint8_t i = 0; i < KEY_COUNT; i++)
|
||||
{
|
||||
s_tBtn[i].LongTime = KEY_LONG_TIME; //若设置为 0 表示不检测长按键事件
|
||||
s_tBtn[i].Count = KEY_FILTER_TIME / 2; //计数器设置为滤波时间的一半
|
||||
s_tBtn[i].State = 0; //按键缺省状态,0 为未按下
|
||||
s_tBtn[i].RepeatSpeed = 0; //按键连发的速度,0 表示不支持连发
|
||||
s_tBtn[i].RepeatCount = 0; //连发计数器
|
||||
}
|
||||
|
||||
//摇杆上下左右,支持长按 1 秒后,自动连发
|
||||
KEY_SetKeyParam(JOY_U, 50, 6);
|
||||
KEY_SetKeyParam(JOY_D, 50, 6);
|
||||
KEY_SetKeyParam(JOY_L, 50, 6);
|
||||
KEY_SetKeyParam(JOY_R, 50, 6);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 将键值压入按键 FIFO。可用于模拟一个按键事件
|
||||
* @param _KeyCode: 键值
|
||||
*/
|
||||
void KEY_PutKey(uint8_t _KeyCode)
|
||||
{
|
||||
s_tKey.Buf[s_tKey.Write] = _KeyCode;
|
||||
|
||||
if (++s_tKey.Write >= KEY_FIFO_SIZE)
|
||||
{
|
||||
s_tKey.Write = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 从按键 FIFO 读取一个键值
|
||||
* @retval 键值
|
||||
*/
|
||||
uint8_t KEY_GetKey(void)
|
||||
{
|
||||
if (s_tKey.Read == s_tKey.Write)
|
||||
{
|
||||
return KEY_NONE;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t ret = s_tKey.Buf[s_tKey.Read];
|
||||
|
||||
if (++s_tKey.Read >= KEY_FIFO_SIZE)
|
||||
s_tKey.Read = 0;
|
||||
|
||||
if (
|
||||
ret == KEY1_UP ||
|
||||
ret == KEY2_UP ||
|
||||
ret == JOY_OK_UP ||
|
||||
ret == JOY_U_UP ||
|
||||
ret == JOY_D_UP ||
|
||||
ret == JOY_L_UP ||
|
||||
ret == JOY_R_UP)
|
||||
{
|
||||
if (is_key_clear)
|
||||
{
|
||||
is_key_clear = 0;
|
||||
return KEY_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
is_key_clear = 0;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 从按键 FIFO 读取一个键值,空值时阻塞
|
||||
* @retval 键值
|
||||
*/
|
||||
uint8_t KEY_GetKeyWait(void)
|
||||
{
|
||||
uint8_t key = KEY_NONE;
|
||||
|
||||
while (key == KEY_NONE)
|
||||
key = KEY_GetKey();
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 读取某键状态
|
||||
* @param _ucKeyID: 按键 ID
|
||||
* @retval 1 表示按下,0 表示未按下
|
||||
*/
|
||||
uint8_t KEY_GetKeyState(KEY_ID_E _ucKeyID)
|
||||
{
|
||||
return s_tBtn[_ucKeyID].State;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 等待特定键按下
|
||||
* @param _ucKeyID: 按键 ID
|
||||
*/
|
||||
void KEY_WaitKey(KEY_ID_E _ucKeyID)
|
||||
{
|
||||
while (KEY_GetKeyState(_ucKeyID) != 1)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置按键参数
|
||||
* @param _ucKeyID: 按键 ID
|
||||
* @param _LongTime: 长按事件时间
|
||||
* @param _RepeatSpeed: 连发速度
|
||||
*/
|
||||
void KEY_SetKeyParam(uint8_t _ucKeyID, uint16_t _LongTime, uint8_t _RepeatSpeed)
|
||||
{
|
||||
s_tBtn[_ucKeyID].LongTime = _LongTime; //长按时间 0 表示不检测长按键事件
|
||||
s_tBtn[_ucKeyID].RepeatSpeed = _RepeatSpeed; //按键连发的速度,0 表示不支持连发
|
||||
s_tBtn[_ucKeyID].RepeatCount = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 清空按键 FIFO
|
||||
*/
|
||||
void KEY_ClearKey(void)
|
||||
{
|
||||
s_tKey.Read = s_tKey.Write;
|
||||
is_key_clear = 1;
|
||||
}
|
||||
|
||||
static void DetectKey(uint8_t i)
|
||||
{
|
||||
KEY_T *pBtn;
|
||||
|
||||
pBtn = &s_tBtn[i];
|
||||
if (IsKeyDownFunc(i))
|
||||
{
|
||||
if (pBtn->Count < KEY_FILTER_TIME)
|
||||
{
|
||||
pBtn->Count = KEY_FILTER_TIME;
|
||||
}
|
||||
else if (pBtn->Count < 2 * KEY_FILTER_TIME)
|
||||
{
|
||||
pBtn->Count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pBtn->State == 0)
|
||||
{
|
||||
pBtn->State = 1;
|
||||
|
||||
KEY_PutKey((uint8_t)(3 * i + 1));
|
||||
}
|
||||
|
||||
if (pBtn->LongTime > 0)
|
||||
{
|
||||
if (pBtn->LongCount < pBtn->LongTime)
|
||||
{
|
||||
if (++pBtn->LongCount == pBtn->LongTime)
|
||||
{
|
||||
KEY_PutKey((uint8_t)(3 * i + 3));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pBtn->RepeatSpeed > 0)
|
||||
{
|
||||
if (++pBtn->RepeatCount >= pBtn->RepeatSpeed)
|
||||
{
|
||||
pBtn->RepeatCount = 0;
|
||||
KEY_PutKey((uint8_t)(3 * i + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pBtn->Count > KEY_FILTER_TIME)
|
||||
{
|
||||
pBtn->Count = KEY_FILTER_TIME;
|
||||
}
|
||||
else if (pBtn->Count != 0)
|
||||
{
|
||||
pBtn->Count--;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pBtn->State == 1)
|
||||
{
|
||||
pBtn->State = 0;
|
||||
|
||||
KEY_PutKey((uint8_t)(3 * i + 2));
|
||||
}
|
||||
}
|
||||
|
||||
pBtn->LongCount = 0;
|
||||
pBtn->RepeatCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 扫描所有按键。非阻塞,应被 SysTick 中断周期性的调用,10ms 一次
|
||||
*/
|
||||
void KEY_Scan10ms(void)
|
||||
{
|
||||
for (uint8_t i = 0; i < KEY_COUNT; i++)
|
||||
DetectKey(i);
|
||||
}
|
||||
@ -1,117 +0,0 @@
|
||||
//按键 FIFO 库
|
||||
|
||||
#ifndef __KEY_H
|
||||
#define __KEY_H
|
||||
|
||||
#include "sys.h"
|
||||
|
||||
//按键事件别名
|
||||
|
||||
#define KEY1_DOWN KEY_1_DOWN
|
||||
#define KEY1_UP KEY_1_UP
|
||||
#define KEY1_LONG KEY_1_LONG
|
||||
|
||||
#define KEY2_DOWN KEY_2_DOWN
|
||||
#define KEY2_UP KEY_2_UP
|
||||
#define KEY2_LONG KEY_2_LONG
|
||||
|
||||
#define JOY_OK_DOWN KEY_3_DOWN //OK
|
||||
#define JOY_OK_UP KEY_3_UP
|
||||
#define JOY_OK_LONG KEY_3_LONG
|
||||
|
||||
#define JOY_U_DOWN KEY_4_DOWN //上
|
||||
#define JOY_U_UP KEY_4_UP
|
||||
#define JOY_U_LONG KEY_4_LONG
|
||||
|
||||
#define JOY_D_DOWN KEY_5_DOWN //下
|
||||
#define JOY_D_UP KEY_5_UP
|
||||
#define JOY_D_LONG KEY_5_LONG
|
||||
|
||||
#define JOY_L_DOWN KEY_6_DOWN //左
|
||||
#define JOY_L_UP KEY_6_UP
|
||||
#define JOY_L_LONG KEY_6_LONG
|
||||
|
||||
#define JOY_R_DOWN KEY_7_DOWN //右
|
||||
#define JOY_R_UP KEY_7_UP
|
||||
#define JOY_R_LONG KEY_7_LONG
|
||||
|
||||
//按键 ID
|
||||
typedef enum
|
||||
{
|
||||
KEY1 = 0,
|
||||
KEY2,
|
||||
JOY_OK,
|
||||
JOY_U,
|
||||
JOY_D,
|
||||
JOY_L,
|
||||
JOY_R
|
||||
} KEY_ID_E;
|
||||
|
||||
#define KEY_FILTER_TIME 5 //按键滤波时间 50ms,单位 10ms
|
||||
#define KEY_LONG_TIME 100 //持续 1 秒,长按事件
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t (*IsKeyDownFunc)(void); //按键按下的判断函数,1 表示按下
|
||||
|
||||
uint8_t Count; //滤波器计数器
|
||||
uint16_t LongCount; //长按计数器
|
||||
uint16_t LongTime; //按键按下持续时间,0 表示不检测长按
|
||||
uint8_t State; //按键当前状态(按下还是弹起)
|
||||
uint8_t RepeatSpeed; //连续按键周期
|
||||
uint8_t RepeatCount; //连续按键计数器
|
||||
} KEY_T;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
KEY_NONE = 0,
|
||||
|
||||
KEY_1_DOWN, //1 键按下
|
||||
KEY_1_UP, //1 键弹起
|
||||
KEY_1_LONG, //1 键长按
|
||||
|
||||
KEY_2_DOWN, //2 键按下
|
||||
KEY_2_UP, //2 键弹起
|
||||
KEY_2_LONG, //2 键长按
|
||||
|
||||
KEY_3_DOWN, //3 键按下
|
||||
KEY_3_UP, //3 键弹起
|
||||
KEY_3_LONG, //3 键长按
|
||||
|
||||
KEY_4_DOWN, //4 键按下
|
||||
KEY_4_UP, //4 键弹起
|
||||
KEY_4_LONG, //4 键长按
|
||||
|
||||
KEY_5_DOWN, //5 键按下
|
||||
KEY_5_UP, //5 键弹起
|
||||
KEY_5_LONG, //5 键长按
|
||||
|
||||
KEY_6_DOWN, //6 键按下
|
||||
KEY_6_UP, //6 键弹起
|
||||
KEY_6_LONG, //6 键长按
|
||||
|
||||
KEY_7_DOWN, //7 键按下
|
||||
KEY_7_UP, //7 键弹起
|
||||
KEY_7_LONG, //7 键长按
|
||||
} KEY_ENUM;
|
||||
|
||||
//按键 FIFO 变量
|
||||
#define KEY_FIFO_SIZE 10
|
||||
typedef struct
|
||||
{
|
||||
uint8_t Buf[KEY_FIFO_SIZE]; //键值缓冲区
|
||||
uint8_t Read; //缓冲区读指针
|
||||
uint8_t Write; //缓冲区写指针
|
||||
} KEY_FIFO_T;
|
||||
|
||||
void KEY_Init(void);
|
||||
void KEY_Scan10ms(void);
|
||||
void KEY_PutKey(uint8_t _KeyCode);
|
||||
uint8_t KEY_GetKey(void);
|
||||
uint8_t KEY_GetKeyWait(void);
|
||||
uint8_t KEY_GetKeyState(KEY_ID_E _ucKeyID);
|
||||
void KEY_WaitKey(KEY_ID_E _ucKeyID);
|
||||
void KEY_SetKeyParam(uint8_t _ucKeyID, uint16_t _LongTime, uint8_t _RepeatSpeed);
|
||||
void KEY_ClearKey(void);
|
||||
|
||||
#endif
|
||||
@ -1,228 +0,0 @@
|
||||
//LCD 库(ILI9431 及字库)
|
||||
|
||||
#include "systick.h"
|
||||
#include "spi.h"
|
||||
|
||||
#include "lcd.h"
|
||||
|
||||
/**************************************** 私有函数 ****************************************/
|
||||
|
||||
/*****************************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief LCD 发送 8 位命令
|
||||
* @param cmd: 8 位命令
|
||||
*/
|
||||
void LCD_SendCmd(uint8_t cmd)
|
||||
{
|
||||
LCD_Cmd_Mode_On;
|
||||
|
||||
SPI2_Write8Bits(cmd);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LCD 发送 8 位数据
|
||||
* @param data: 8 位数据
|
||||
*/
|
||||
void LCD_SendData8Bits(uint8_t data)
|
||||
{
|
||||
LCD_Data_Mode_On;
|
||||
|
||||
SPI2_Write8Bits(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LCD 发送 16 位数据
|
||||
* @param data: 16 位数据
|
||||
*/
|
||||
void LCD_SendData16Bits(uint16_t data)
|
||||
{
|
||||
LCD_Data_Mode_On;
|
||||
|
||||
SPI2_Write16Bits(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LCD 发送 32 位数据
|
||||
* @param data: 32 位数据
|
||||
*/
|
||||
void LCD_SendData32Bits(uint32_t data)
|
||||
{
|
||||
LCD_Data_Mode_On;
|
||||
|
||||
SPI2_Write32Bits(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LCD 发送连续数据
|
||||
* @param pData: 指向写入数据的指针
|
||||
* @param Count: 字节数
|
||||
*/
|
||||
void LCD_SendDataBytes(uint8_t *pData, uint32_t Count)
|
||||
{
|
||||
LCD_Data_Mode_On;
|
||||
|
||||
SPI2_WriteBytes(pData, Count);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LCD 发送 8 位命令并发送 8 位数据
|
||||
* @param cmd: 8 位命令
|
||||
* @param data: 8 位数据
|
||||
*/
|
||||
void LCD_SendCmdData8Bits(uint8_t cmd, uint8_t data)
|
||||
{
|
||||
LCD_SendCmd(cmd);
|
||||
LCD_SendData8Bits(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LCD 发送 8 位命令并发送 16 位数据
|
||||
* @param cmd: 8 位命令
|
||||
* @param data: 16 位数据
|
||||
*/
|
||||
void LCD_SendCmdData16Bits(uint8_t cmd, uint16_t data)
|
||||
{
|
||||
LCD_SendCmd(cmd);
|
||||
LCD_SendData16Bits(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LCD 发送 8 位命令并发送 32 位数据
|
||||
* @param cmd: 8 位命令
|
||||
* @param data: 32 位数据
|
||||
*/
|
||||
void LCD_SendCmdData32Bits(uint8_t cmd, uint32_t data)
|
||||
{
|
||||
LCD_SendCmd(cmd);
|
||||
LCD_SendData32Bits(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LCD 发送 8 位命令并发送连续数据数据
|
||||
* @param cmd: 8 位命令
|
||||
* @param pData: 指向写入数据的指针
|
||||
* @param Count: 字节数
|
||||
*/
|
||||
void LCD_SendCmdDataBytes(uint8_t cmd, uint8_t *pData, uint32_t Count)
|
||||
{
|
||||
LCD_SendCmd(cmd);
|
||||
LCD_SendDataBytes(pData, Count);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LCD 及字库初始化
|
||||
*/
|
||||
void LCD_Init(void)
|
||||
{
|
||||
//初始化 ILI9431
|
||||
//初始化 PB0 PB1 PB12
|
||||
GPIO_InitTypeDef GPIO_Initure;
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE(); //开启 PB 时钟
|
||||
|
||||
GPIO_Initure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_12; //PB0 PB1 PB12
|
||||
GPIO_Initure.Mode = GPIO_MODE_OUTPUT_PP; //推挽输出
|
||||
GPIO_Initure.Pull = GPIO_PULLUP; //上拉
|
||||
GPIO_Initure.Speed = GPIO_SPEED_FREQ_VERY_HIGH; //高速
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_Initure); //初始化 PB0 PB1 PB12
|
||||
|
||||
LCD_Stop_Send;
|
||||
LCD_Data_Mode_On;
|
||||
LCD_BLK_On; //点亮背光
|
||||
|
||||
SPI2_Init(); //初始化 SPI2
|
||||
SPI2_SetSpeed(SPI_BAUDRATEPRESCALER_4); //设置 SPI2 速度
|
||||
|
||||
LCD_Start_Send; //片选 CS 位置 0,开始传输
|
||||
|
||||
LCD_SendCmd(LCD_CMD_SWRESET); //软复位,进入睡眠模式
|
||||
Delay_ms(50);
|
||||
|
||||
//功耗控制 B
|
||||
uint8_t pwctrlb_param[3] = {0x00, 0xd9, 0x30};
|
||||
LCD_SendCmdDataBytes(LCD_CMD_PWCTRLB, pwctrlb_param, 3);
|
||||
|
||||
LCD_SendCmdData32Bits(LCD_CMD_PWOSCTRL, 0x64031281); //电源序列控制
|
||||
|
||||
//驱动时序控制 A
|
||||
uint8_t dtctrla_param[3] = {0x85, 0x10, 0x78};
|
||||
LCD_SendCmdDataBytes(LCD_CMD_DTCTRLA, dtctrla_param, 3);
|
||||
|
||||
//功耗控制 A
|
||||
uint8_t pwctrla_param[5] = {0x39, 0x2c, 0x00, 0x34, 0x02};
|
||||
LCD_SendCmdDataBytes(LCD_CMD_PWCTRLA, pwctrla_param, 5);
|
||||
|
||||
LCD_SendCmdData8Bits(LCD_CMD_PRCRTL, 0x20); //泵比控制
|
||||
|
||||
LCD_SendCmdData16Bits(LCD_CMD_DTCTRLB, 0x0000); //驱动时序控制 B
|
||||
|
||||
LCD_SendCmdData8Bits(LCD_CMD_PWCTRL1, 0x21); //功耗控制 1
|
||||
|
||||
LCD_SendCmdData8Bits(LCD_CMD_PWCTRL2, 0x12); //功耗控制 2
|
||||
|
||||
LCD_SendCmdData16Bits(LCD_CMD_VMCTRL1, 0x323c); //VCOM 控制 1
|
||||
|
||||
LCD_SendCmdData8Bits(LCD_CMD_VMCTRL2, 0xc1); //VCOM 控制 2
|
||||
|
||||
LCD_SendCmdData8Bits(LCD_CMD_MADCTL, LCD_CMD_MADCTL_PARAM); //储存器访问控制,设定为横屏
|
||||
|
||||
LCD_SendCmdData8Bits(LCD_CMD_PIXSET, 0x55); //像素格式设置
|
||||
|
||||
LCD_SendCmdData16Bits(LCD_CMD_FRMCTR1, 0x0018); //帧速率控制
|
||||
|
||||
LCD_SendCmdData16Bits(LCD_CMD_DISCTRL, 0x0aa2); //显示功能控制
|
||||
|
||||
LCD_SendCmdData8Bits(LCD_CMD_EN3G, 0x00); //使能 3G
|
||||
|
||||
LCD_SendCmdData8Bits(LCD_CMD_GAMSET, 0x01); //伽马设置
|
||||
|
||||
//正极伽马校准
|
||||
uint8_t pgamctrl_param[15] = {0x0f, 0x20, 0x1e, 0x09, 0x12, 0x0b, 0x50, 0xba, 0x44, 0x09, 0x14, 0x05, 0x23, 0x21, 0x00};
|
||||
LCD_SendCmdDataBytes(LCD_CMD_PGAMCTRL, pgamctrl_param, 15);
|
||||
|
||||
//负极伽马校准
|
||||
uint8_t ngamctrl_param[15] = {0x00, 0x19, 0x19, 0x00, 0x12, 0x07, 0x2d, 0x28, 0x3f, 0x02, 0x0a, 0x08, 0x25, 0x2d, 0x0f};
|
||||
LCD_SendCmdDataBytes(LCD_CMD_NGAMCTRL, ngamctrl_param, 15);
|
||||
|
||||
LCD_SendCmd(LCD_CMD_SLPOUT); //退出睡眠模式
|
||||
|
||||
//利用退出睡眠模式后的等待时间初始化字库
|
||||
uint8_t font_temp[8];
|
||||
LCD_Font_ReadAddr(font_temp, 0x00000000, 8); //试读 8 字节数据
|
||||
|
||||
//根据 ILI9431 手册,发送 LCD_CMD_SLPOUT 后需等待 120ms。实测去除延时仍能工作
|
||||
// Delay_ms(120);
|
||||
|
||||
LCD_Disp_On; //开显示
|
||||
|
||||
LCD_SetWin(0, 0, LCD_WIDTH, LCD_HEIGHT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LCD 设置显示窗口
|
||||
* @param x: 0~319
|
||||
* @param y: 0~239。x y 为窗口左上角坐标
|
||||
* @param width: 窗口宽度。需大于 0
|
||||
* @param height: 窗口高度。需大于 0
|
||||
*/
|
||||
void LCD_SetWin(uint16_t x, uint16_t y, uint16_t width, uint16_t height)
|
||||
{
|
||||
LCD_SendCmdData32Bits(LCD_CMD_CASET, (x << 16) | (x + width - 1));
|
||||
LCD_SendCmdData32Bits(LCD_CMD_PASET, (y << 16) | (y + height - 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LCD 字库读地址
|
||||
* @param pData: 读出内容指针
|
||||
* @param addr: 16 位地址
|
||||
* @param Count: 字节数
|
||||
*/
|
||||
void LCD_Font_ReadAddr(uint8_t *pData, uint32_t addr, uint16_t Count)
|
||||
{
|
||||
LCD_Font_Start_Send; //CS 置 1,此时在控制字库而非 ILI9431
|
||||
|
||||
SPI2_Write32Bits(LCD_FONT_CMD_RDADDR << 24 | addr);
|
||||
SPI2_ReadBytes(pData, Count);
|
||||
|
||||
LCD_Font_Stop_Send;
|
||||
}
|
||||
@ -1,183 +0,0 @@
|
||||
//LCD 库(ILI9431 及字库)
|
||||
|
||||
#ifndef __LCD_H
|
||||
#define __LCD_H
|
||||
|
||||
#include "sys.h"
|
||||
|
||||
/**************************************** 屏幕参数 ****************************************/
|
||||
//采用横屏
|
||||
#define LCD_WIDTH 320
|
||||
#define LCD_HEIGHT 240
|
||||
#define LCD_CMD_MADCTL_PARAM 0x68 //储存器访问控制命令参数。若更改为竖屏需要修改此参数
|
||||
|
||||
/*****************************************************************************************/
|
||||
|
||||
/**************************************** 字库位置 ****************************************/
|
||||
#define ADDR_ASCII12 0x00080000
|
||||
#define ADDR_ASCII16 0x00080800
|
||||
#define ADDR_ASCII24 0x00081200
|
||||
#define ADDR_ASCII32 0x00082600
|
||||
#define ADDR_ASCII48 0x00084800
|
||||
#define ADDR_ASCII64 0x00089200
|
||||
|
||||
#define ADDR_GBK12 0x00091400
|
||||
#define ADDR_GBK16 0x0011dd00
|
||||
#define ADDR_GBK24 0x001da000
|
||||
#define ADDR_GBK32 0x00380000
|
||||
|
||||
/***************************************** 位控制 *****************************************/
|
||||
//CS 位控制
|
||||
#define LCD_CS_Set HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET)
|
||||
#define LCD_CS_Clr HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET)
|
||||
|
||||
//RS 位控制(D/C)
|
||||
#define LCD_RS_Set HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_SET)
|
||||
#define LCD_RS_Clr HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_RESET)
|
||||
|
||||
//BLK 位控制
|
||||
#define LCD_BLK_Set HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET)
|
||||
#define LCD_BLK_Clr HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET)
|
||||
|
||||
/*****************************************************************************************/
|
||||
|
||||
/****************************************** 命令 ******************************************/
|
||||
//LCD 命令,即 ILI9341 命令
|
||||
#define LCD_CMD_NOP 0x00
|
||||
#define LCD_CMD_SWRESET 0x01
|
||||
#define LCD_CMD_RDDIDIF 0x04
|
||||
#define LCD_CMD_RDDST 0x09
|
||||
#define LCD_CMD_RDDPM 0x0a
|
||||
#define LCD_CMD_RDDMADCTL 0x0b
|
||||
#define LCD_CMD_RDDCOLMOD 0x0c
|
||||
#define LCD_CMD_RDDIM 0x0d
|
||||
#define LCD_CMD_RDDSM 0x0e
|
||||
#define LCD_CMD_RDDSDR 0x0f
|
||||
#define LCD_CMD_SPLIN 0x10
|
||||
#define LCD_CMD_SLPOUT 0x11
|
||||
#define LCD_CMD_PTLON 0x12
|
||||
#define LCD_CMD_NORON 0x13
|
||||
#define LCD_CMD_DINVOFF 0x20
|
||||
#define LCD_CMD_DINVON 0x21
|
||||
#define LCD_CMD_GAMSET 0x26
|
||||
#define LCD_CMD_DISPOFF 0x28
|
||||
#define LCD_CMD_DISPON 0x29
|
||||
#define LCD_CMD_CASET 0x2a
|
||||
#define LCD_CMD_PASET 0x2b
|
||||
#define LCD_CMD_RAMWR 0x2c
|
||||
#define LCD_CMD_RGBSET 0x2d
|
||||
#define LCD_CMD_RAMRD 0x2e
|
||||
#define LCD_CMD_PLTAR 0x30
|
||||
#define LCD_CMD_VSCRDEF 0x33
|
||||
#define LCD_CMD_TEOFF 0x34
|
||||
#define LCD_CMD_TEON 0x35
|
||||
#define LCD_CMD_MADCTL 0x36
|
||||
#define LCD_CMD_VSCRSADD 0x37
|
||||
#define LCD_CMD_IDMOFF 0x38
|
||||
#define LCD_CMD_IDMON 0x39
|
||||
#define LCD_CMD_PIXSET 0x3a
|
||||
#define LCD_CMD_WRITE_MEMORY_CONTINUE 0x3c
|
||||
#define LCD_CMD_READ_MEMORY_CONTINUE 0x3e
|
||||
#define LCD_CMD_SET_TEAR_SCANLINE 0x44
|
||||
#define LCD_CMD_GET_SCANLINE 0x45
|
||||
#define LCD_CMD_WRDISBV 0x51
|
||||
#define LCD_CMD_RDDISBV 0x52
|
||||
#define LCD_CMD_WRCTRLD 0x53
|
||||
#define LCD_CMD_RDCTRLD 0x54
|
||||
#define LCD_CMD_WRCABC 0x55
|
||||
#define LCD_CMD_RDCABC 0x56
|
||||
#define LCD_CMD_WRCABCMB 0x5e
|
||||
#define LCD_CMD_RDCABCMB 0x5f
|
||||
#define LCD_CMD_RDID1 0xda
|
||||
#define LCD_CMD_RDID2 0xdb
|
||||
#define LCD_CMD_RDID3 0xdc
|
||||
#define LCD_CMD_IFMODE 0xb0
|
||||
#define LCD_CMD_FRMCTR1 0xb1
|
||||
#define LCD_CMD_FRMCTR2 0xb2
|
||||
#define LCD_CMD_FRMCTR3 0xb3
|
||||
#define LCD_CMD_INVTR 0xb4
|
||||
#define LCD_CMD_PRCTR 0xb5
|
||||
#define LCD_CMD_DISCTRL 0xb6
|
||||
#define LCD_CMD_ETMOD 0xb7
|
||||
#define LCD_CMD_BACKLIGHTCTRL1 0xb8
|
||||
#define LCD_CMD_BACKLIGHTCTRL2 0xb9
|
||||
#define LCD_CMD_BACKLIGHTCTRL3 0xba
|
||||
#define LCD_CMD_BACKLIGHTCTRL4 0xbb
|
||||
#define LCD_CMD_BACKLIGHTCTRL5 0xbc
|
||||
#define LCD_CMD_BACKLIGHTCTRL7 0xbe
|
||||
#define LCD_CMD_BACKLIGHTCTRL8 0xbf
|
||||
#define LCD_CMD_PWCTRL1 0xc0
|
||||
#define LCD_CMD_PWCTRL2 0xc1
|
||||
#define LCD_CMD_VMCTRL1 0xc5
|
||||
#define LCD_CMD_VMCTRL2 0xc7
|
||||
#define LCD_CMD_NVMWR 0xd0
|
||||
#define LCD_CMD_NVMPKEY 0xd1
|
||||
#define LCD_CMD_RDNVM 0xd2
|
||||
#define LCD_CMD_RDID4 0xd3
|
||||
#define LCD_CMD_PGAMCTRL 0xe0
|
||||
#define LCD_CMD_NGAMCTRL 0xe1
|
||||
#define LCD_CMD_DGAMCTRL1 0xe2
|
||||
#define LCD_CMD_DGAMCTRL2 0xe3
|
||||
#define LCD_CMD_IFCTL 0xf6
|
||||
#define LCD_CMD_PWCTRLA 0xcb
|
||||
#define LCD_CMD_PWCTRLB 0xcf
|
||||
#define LCD_CMD_DTCTRLA 0xe8
|
||||
#define LCD_CMD_DTCTRLB 0xea
|
||||
#define LCD_CMD_PWOSCTRL 0xed
|
||||
#define LCD_CMD_EN3G 0xf2
|
||||
#define LCD_CMD_PRCRTL 0xf7
|
||||
|
||||
//字库命令
|
||||
#define LCD_FONT_CMD_RDADDR 0x03
|
||||
|
||||
/*****************************************************************************************/
|
||||
|
||||
/***************************************** 位切换宏 ***************************************/
|
||||
//ILI9431
|
||||
#define LCD_Start_Send LCD_CS_Clr //进入 LCD 发送模式(CS 置 0,此时操作 ILI9431)
|
||||
#define LCD_Stop_Send LCD_CS_Set //退出 LCD 发送模式(CS 置 1)
|
||||
|
||||
#define LCD_Cmd_Mode_On LCD_RS_Clr //进入命令模式(RS 置 0)
|
||||
#define LCD_Data_Mode_On LCD_RS_Set //进入数据模式(RS 置 1)
|
||||
|
||||
#define LCD_BLK_On LCD_BLK_Set //开背光
|
||||
#define LCD_BLK_Off LCD_BLK_Clr //关背光
|
||||
|
||||
//字库
|
||||
#define LCD_Font_Start_Send LCD_CS_Set //进入 LCD Font 发送模式(CS 置 1,此时操作字库)
|
||||
#define LCD_Font_Stop_Send LCD_CS_Clr //退出 LCD Font 发送模式(CS 置 0)
|
||||
|
||||
/*****************************************************************************************/
|
||||
|
||||
/***************************************** 命令宏 ****************************************/
|
||||
#define LCD_Disp_On LCD_SendCmd(LCD_CMD_DISPON) //开显示
|
||||
#define LCD_Disp_Off LCD_SendCmd(LCD_CMD_DISPOFF) //冻结显示。可用于关闭从显存到屏幕的刷新,防止因刷屏速度慢导致波纹出现
|
||||
|
||||
#define LCD_Reverse_On LCD_SendCmd(LCD_CMD_DINVON) //开全局反色模式
|
||||
#define LCD_Reverse_Off LCD_SendCmd(LCD_CMD_DINVOFF) //关全局反色模式
|
||||
|
||||
#define LCD_RAM_Wr LCD_SendCmd(LCD_CMD_RAMWR) //开始写显存
|
||||
#define LCD_RAM_Rd LCD_SendCmd(LCD_CMD_RAMRD) //开始读显存
|
||||
|
||||
/**************************************** 通讯函数 ****************************************/
|
||||
|
||||
void LCD_SendCmd(uint8_t cmd);
|
||||
void LCD_SendData8Bits(uint8_t data);
|
||||
void LCD_SendData16Bits(uint16_t data);
|
||||
void LCD_SendData32Bits(uint32_t data);
|
||||
void LCD_SendDataBytes(uint8_t *pData, uint32_t Count);
|
||||
void LCD_SendCmdData8Bits(uint8_t cmd, uint8_t data);
|
||||
void LCD_SendCmdData16Bits(uint8_t cmd, uint16_t data);
|
||||
void LCD_SendCmdData32Bits(uint8_t cmd, uint32_t data);
|
||||
void LCD_SendCmdDataBytes(uint8_t cmd, uint8_t *pData, uint32_t Count);
|
||||
|
||||
/*****************************************************************************************/
|
||||
|
||||
/**************************************** 操作函数 ****************************************/
|
||||
|
||||
void LCD_Init(void);
|
||||
void LCD_SetWin(uint16_t x, uint16_t y, uint16_t width, uint16_t height);
|
||||
|
||||
void LCD_Font_ReadAddr(uint8_t *pData, uint32_t addr, uint16_t Count);
|
||||
|
||||
#endif
|
||||
@ -1,42 +0,0 @@
|
||||
//LED 库
|
||||
|
||||
#include "sys.h"
|
||||
|
||||
#include "led.h"
|
||||
|
||||
/**
|
||||
* @brief LED 初始化,用于 LED2
|
||||
*/
|
||||
void LED_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_Initure;
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE(); //开启 PA 时钟
|
||||
|
||||
GPIO_Initure.Pin = GPIO_PIN_1; //PA1
|
||||
GPIO_Initure.Mode = GPIO_MODE_OUTPUT_PP; //推挽输出
|
||||
GPIO_Initure.Pull = GPIO_PULLUP; //上拉
|
||||
GPIO_Initure.Speed = GPIO_SPEED_FREQ_VERY_HIGH; //高速
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_Initure); //初始化 PA1
|
||||
|
||||
LED2_Off;
|
||||
SysTick_StartTimer(LED2_SYSTICK_TIMER_ID, 50);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LED2 慢速翻转,无阻塞,防止因调用过快导致无法观察
|
||||
* @param led_num: 序号
|
||||
*/
|
||||
void LED_Slow_Toggle(uint8_t led_num)
|
||||
{
|
||||
switch (led_num)
|
||||
{
|
||||
case 2:
|
||||
{
|
||||
if (SysTick_CheckTimer(LED2_SYSTICK_TIMER_ID))
|
||||
{
|
||||
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_1);
|
||||
SysTick_StartTimer(LED2_SYSTICK_TIMER_ID, 50);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
//LED 库
|
||||
|
||||
#ifndef _LED_H
|
||||
#define _LED_H
|
||||
|
||||
#include "sys.h"
|
||||
|
||||
#define LED2(n) (n ? HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_SET) : HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_RESET))
|
||||
#define LED2_On LED2(0)
|
||||
#define LED2_Off LED2(1)
|
||||
#define LED2_Toggle HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_1) //LED2 翻转
|
||||
#define LED2_SYSTICK_TIMER_ID 0
|
||||
#define LED2_Slow_Toggle LED_Slow_Toggle(2) //LED2 慢速翻转,无阻塞,防止因调用过快导致无法观察
|
||||
|
||||
void LED_Init(void);
|
||||
void LED_Slow_Toggle(uint8_t led_num);
|
||||
|
||||
#endif
|
||||
@ -1,516 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h743i_eval_sd.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @brief This file includes the uSD card driver mounted on STM32H743I-EVAL
|
||||
* evaluation boards.
|
||||
@verbatim
|
||||
How To use this driver:
|
||||
-----------------------
|
||||
- This driver is used to drive the micro SD external cards mounted on STM32H743I-EVAL
|
||||
evaluation board.
|
||||
- This driver does not need a specific component driver for the micro SD device
|
||||
to be included with.
|
||||
|
||||
Driver description:
|
||||
------------------
|
||||
+ Initialization steps:
|
||||
o Initialize the micro SD card using the BSP_SD_Init() function. This
|
||||
function includes the MSP layer hardware resources initialization and the
|
||||
SDIO interface configuration to interface with the external micro SD. It
|
||||
also includes the micro SD initialization sequence for SDCard1.
|
||||
o To check the SD card presence you can use the function BSP_SD_IsDetected() which
|
||||
returns the detection status for SDCard1. The function BSP_SD_IsDetected() returns
|
||||
the detection status for SDCard1.
|
||||
o If SD presence detection interrupt mode is desired, you must configure the
|
||||
SD detection interrupt mode by calling the functions BSP_SD_ITConfig() for
|
||||
SDCard1. The interrupt is generated as an external interrupt whenever the
|
||||
micro SD card is plugged/unplugged in/from the evaluation board. The SD detection
|
||||
is managed by MFX, so the SD detection interrupt has to be treated by MFX_IRQOUT
|
||||
gpio pin IRQ handler.
|
||||
o The function BSP_SD_GetCardInfo() are used to get the micro SD card information
|
||||
which is stored in the structure "HAL_SD_CardInfoTypedef".
|
||||
|
||||
+ Micro SD card operations
|
||||
o The micro SD card can be accessed with read/write block(s) operations once
|
||||
it is ready for access. The access, by default to SDCard1, can be performed whether
|
||||
using the polling mode by calling the functions BSP_SD_ReadBlocks()/BSP_SD_WriteBlocks(),
|
||||
or by DMA transfer using the functions BSP_SD_ReadBlocks_DMA()/BSP_SD_WriteBlocks_DMA().
|
||||
o The DMA transfer complete is used with interrupt mode. Once the SD transfer
|
||||
is complete, the SD interrupt is handled using the function BSP_SDMMC1_IRQHandler()
|
||||
when SDCard1 is used.
|
||||
o The SD erase block(s) is performed using the functions BSP_SD_Erase() with specifying
|
||||
the number of blocks to erase.
|
||||
o The SD runtime status is returned when calling the function BSP_SD_GetStatus().
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
#include "sdio.h"
|
||||
|
||||
//#define SD_DETECT_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
|
||||
|
||||
//#define SD_DETECT_GPIO_PORT GPIOG
|
||||
//#define SD_DETECT_PIN GPIO_PIN_9
|
||||
|
||||
//#define SD_IS_INSERTED() ((SD_DETECT_GPIO_PORT->IDR & SD_DETECT_PIN) == 0)
|
||||
|
||||
#define SD_IS_INSERTED() 1
|
||||
|
||||
SD_HandleTypeDef uSdHandle;
|
||||
//static uint8_t UseExtiModeDetection = 0;
|
||||
|
||||
/**
|
||||
* @brief Initializes the SD card device.
|
||||
* @retval SD status
|
||||
*/
|
||||
uint8_t BSP_SD_Init(void)
|
||||
{
|
||||
uint8_t sd_state = MSD_OK;
|
||||
|
||||
/* uSD device interface configuration */
|
||||
uSdHandle.Instance = SDMMC1;
|
||||
|
||||
uSdHandle.Init.ClockDiv = 2; /* 高速卡可以用1,低速卡用2(用1不稳定) */
|
||||
uSdHandle.Init.ClockPowerSave = SDMMC_CLOCK_POWER_SAVE_DISABLE;
|
||||
uSdHandle.Init.ClockEdge = SDMMC_CLOCK_EDGE_RISING;
|
||||
uSdHandle.Init.HardwareFlowControl = SDMMC_HARDWARE_FLOW_CONTROL_DISABLE;
|
||||
uSdHandle.Init.BusWide = SDMMC_BUS_WIDE_4B;
|
||||
|
||||
/* Check if the SD card is plugged in the slot */
|
||||
#ifdef SD_DETECT_GPIO_PORT
|
||||
{
|
||||
GPIO_InitTypeDef gpio_init;
|
||||
|
||||
SD_DETECT_GPIO_CLK_ENABLE(); /* 打开GPIO时钟 */
|
||||
|
||||
gpio_init.Mode = GPIO_MODE_INPUT; /* 设置输入 */
|
||||
gpio_init.Pull = GPIO_NOPULL; /* 上下拉电阻不使能 */
|
||||
gpio_init.Speed = GPIO_SPEED_FREQ_VERY_HIGH; /* GPIO速度等级 */
|
||||
gpio_init.Pin = SD_DETECT_PIN;
|
||||
HAL_GPIO_Init(SD_DETECT_GPIO_PORT, &gpio_init);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
/* Initialise Transciver MFXPIN to enable 1.8V Switch mode */
|
||||
BSP_IO_ConfigPin(SD_LDO_SEL_PIN, IO_MODE_OUTPUT_PP_PU);
|
||||
#endif
|
||||
|
||||
if (BSP_SD_IsDetected() != SD_PRESENT)
|
||||
{
|
||||
return MSD_ERROR_SD_NOT_PRESENT;
|
||||
}
|
||||
|
||||
/* Msp SD initialization */
|
||||
BSP_SD_MspInit(&uSdHandle, NULL);
|
||||
|
||||
/* HAL SD initialization */
|
||||
if (HAL_SD_Init(&uSdHandle) != HAL_OK)
|
||||
{
|
||||
sd_state = MSD_ERROR;
|
||||
}
|
||||
|
||||
return sd_state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInitializes the SD card device.
|
||||
* @retval SD status
|
||||
*/
|
||||
uint8_t BSP_SD_DeInit(void)
|
||||
{
|
||||
uint8_t sd_state = MSD_OK;
|
||||
|
||||
uSdHandle.Instance = SDMMC1;
|
||||
|
||||
/* Set back Mfx pin to INPUT mode in case it was in exti */
|
||||
//UseExtiModeDetection = 0;
|
||||
|
||||
/* HAL SD deinitialization */
|
||||
if (HAL_SD_DeInit(&uSdHandle) != HAL_OK)
|
||||
{
|
||||
sd_state = MSD_ERROR;
|
||||
}
|
||||
|
||||
/* Msp SD deinitialization */
|
||||
uSdHandle.Instance = SDMMC1;
|
||||
BSP_SD_MspDeInit(&uSdHandle, NULL);
|
||||
|
||||
return sd_state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures Interrupt mode for SD1 detection pin.
|
||||
* @retval Returns 0
|
||||
*/
|
||||
uint8_t BSP_SD_ITConfig(void)
|
||||
{
|
||||
#if 0 /* 不使用外部EXIT中断检测 */
|
||||
/* Configure Interrupt mode for SD detection pin */
|
||||
/* Note: disabling exti mode can be done calling BSP_SD_DeInit() */
|
||||
UseExtiModeDetection = 1;
|
||||
BSP_SD_IsDetected();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Detects if SD card is correctly plugged in the memory slot or not.
|
||||
* @retval Returns if SD is detected or not
|
||||
*/
|
||||
uint8_t BSP_SD_IsDetected(void)
|
||||
{
|
||||
__IO uint8_t status = SD_PRESENT;
|
||||
|
||||
/* Check SD card detect pin */
|
||||
if (SD_IS_INSERTED())
|
||||
{
|
||||
status = SD_PRESENT;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = SD_NOT_PRESENT;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads block(s) from a specified address in an SD card, in polling mode.
|
||||
* @param pData: Pointer to the buffer that will contain the data to transmit
|
||||
* @param ReadAddr: Address from where data is to be read
|
||||
* @param NumOfBlocks: Number of SD blocks to read
|
||||
* @param Timeout: Timeout for read operation
|
||||
* @retval SD status
|
||||
*/
|
||||
uint8_t BSP_SD_ReadBlocks(uint32_t *pData, uint32_t ReadAddr, uint32_t NumOfBlocks, uint32_t Timeout)
|
||||
{
|
||||
|
||||
if (HAL_SD_ReadBlocks(&uSdHandle, (uint8_t *)pData, ReadAddr, NumOfBlocks, Timeout) == HAL_OK)
|
||||
{
|
||||
return MSD_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return MSD_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes block(s) to a specified address in an SD card, in polling mode.
|
||||
* @param pData: Pointer to the buffer that will contain the data to transmit
|
||||
* @param WriteAddr: Address from where data is to be written
|
||||
* @param NumOfBlocks: Number of SD blocks to write
|
||||
* @param Timeout: Timeout for write operation
|
||||
* @retval SD status
|
||||
*/
|
||||
uint8_t BSP_SD_WriteBlocks(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBlocks, uint32_t Timeout)
|
||||
{
|
||||
|
||||
if (HAL_SD_WriteBlocks(&uSdHandle, (uint8_t *)pData, WriteAddr, NumOfBlocks, Timeout) == HAL_OK)
|
||||
{
|
||||
return MSD_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return MSD_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads block(s) from a specified address in an SD card, in DMA mode.
|
||||
* @param pData: Pointer to the buffer that will contain the data to transmit
|
||||
* @param ReadAddr: Address from where data is to be read
|
||||
* @param NumOfBlocks: Number of SD blocks to read
|
||||
* @retval SD status
|
||||
*/
|
||||
uint8_t BSP_SD_ReadBlocks_DMA(uint32_t *pData, uint32_t ReadAddr, uint32_t NumOfBlocks)
|
||||
{
|
||||
|
||||
if (HAL_SD_ReadBlocks_DMA(&uSdHandle, (uint8_t *)pData, ReadAddr, NumOfBlocks) == HAL_OK)
|
||||
{
|
||||
return MSD_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return MSD_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes block(s) to a specified address in an SD card, in DMA mode.
|
||||
* @param pData: Pointer to the buffer that will contain the data to transmit
|
||||
* @param WriteAddr: Address from where data is to be written
|
||||
* @param NumOfBlocks: Number of SD blocks to write
|
||||
* @retval SD status
|
||||
*/
|
||||
uint8_t BSP_SD_WriteBlocks_DMA(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBlocks)
|
||||
{
|
||||
|
||||
if (HAL_SD_WriteBlocks_DMA(&uSdHandle, (uint8_t *)pData, WriteAddr, NumOfBlocks) == HAL_OK)
|
||||
{
|
||||
return MSD_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return MSD_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Erases the specified memory area of the given SD card.
|
||||
* @param StartAddr: Start byte address
|
||||
* @param EndAddr: End byte address
|
||||
* @retval SD status
|
||||
*/
|
||||
uint8_t BSP_SD_Erase(uint32_t StartAddr, uint32_t EndAddr)
|
||||
{
|
||||
|
||||
if (HAL_SD_Erase(&uSdHandle, StartAddr, EndAddr) == HAL_OK)
|
||||
{
|
||||
return MSD_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return MSD_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initializes the SD MSP.
|
||||
* @param hsd: SD handle
|
||||
* @param Params: Pointer to void
|
||||
* @retval None
|
||||
*/
|
||||
__weak void BSP_SD_MspInit(SD_HandleTypeDef *hsd, void *Params)
|
||||
{
|
||||
|
||||
GPIO_InitTypeDef gpio_init_structure;
|
||||
|
||||
/* Enable SDIO clock */
|
||||
__HAL_RCC_SDMMC1_CLK_ENABLE();
|
||||
|
||||
/* Enable GPIOs clock */
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
|
||||
gpio_init_structure.Mode = GPIO_MODE_AF_PP;
|
||||
gpio_init_structure.Pull = GPIO_NOPULL;
|
||||
gpio_init_structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH; //GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
|
||||
/* D0(PC8), D1(PC9), D2(PC10), D3(PC11), CK(PC12), CMD(PD2) */
|
||||
/* Common GPIO configuration */
|
||||
gpio_init_structure.Alternate = GPIO_AF12_SDIO1;
|
||||
|
||||
/* GPIOC configuration */
|
||||
gpio_init_structure.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12;
|
||||
HAL_GPIO_Init(GPIOC, &gpio_init_structure);
|
||||
|
||||
/* GPIOD configuration */
|
||||
gpio_init_structure.Pin = GPIO_PIN_2;
|
||||
HAL_GPIO_Init(GPIOD, &gpio_init_structure);
|
||||
|
||||
// /* D0DIR(PC6), D123DIR(PC7) */
|
||||
// gpio_init_structure.Alternate = GPIO_AF8_SDIO1;
|
||||
// /* GPIOC configuration */
|
||||
// gpio_init_structure.Pin = GPIO_PIN_6 | GPIO_PIN_7;
|
||||
// HAL_GPIO_Init(GPIOC, &gpio_init_structure);
|
||||
|
||||
// /* CKIN(PB8), CDIR(PB9) */
|
||||
// gpio_init_structure.Alternate = GPIO_AF7_SDIO1;
|
||||
// /* GPIOB configuration */
|
||||
// gpio_init_structure.Pin = GPIO_PIN_8 | GPIO_PIN_9;
|
||||
// HAL_GPIO_Init(GPIOB, &gpio_init_structure);
|
||||
|
||||
__HAL_RCC_SDMMC1_FORCE_RESET();
|
||||
__HAL_RCC_SDMMC1_RELEASE_RESET();
|
||||
|
||||
/* NVIC configuration for SDIO interrupts */
|
||||
HAL_NVIC_SetPriority(SDMMC1_IRQn, 5, 0);
|
||||
HAL_NVIC_EnableIRQ(SDMMC1_IRQn);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInitializes the SD MSP.
|
||||
* @param hsd: SD handle
|
||||
* @param Params: Pointer to void
|
||||
* @retval None
|
||||
*/
|
||||
__weak void BSP_SD_MspDeInit(SD_HandleTypeDef *hsd, void *Params)
|
||||
{
|
||||
/* Disable NVIC for SDIO interrupts */
|
||||
HAL_NVIC_DisableIRQ(SDMMC1_IRQn);
|
||||
|
||||
/* DeInit GPIO pins can be done in the application
|
||||
(by surcharging this __weak function) */
|
||||
|
||||
/* Disable SDMMC1 clock */
|
||||
__HAL_RCC_SDMMC1_CLK_DISABLE();
|
||||
|
||||
/* GPIO pins clock and DMA clocks can be shut down in the application
|
||||
by surcharging this __weak function */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets the current SD card data status.
|
||||
* @retval Data transfer state.
|
||||
* This value can be one of the following values:
|
||||
* @arg SD_TRANSFER_OK: No data transfer is acting
|
||||
* @arg SD_TRANSFER_BUSY: Data transfer is acting
|
||||
*/
|
||||
uint8_t BSP_SD_GetCardState(void)
|
||||
{
|
||||
return ((HAL_SD_GetCardState(&uSdHandle) == HAL_SD_CARD_TRANSFER) ? SD_TRANSFER_OK : SD_TRANSFER_BUSY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get SD information about specific SD card.
|
||||
* @param CardInfo: Pointer to HAL_SD_CardInfoTypedef structure
|
||||
* @retval None
|
||||
*/
|
||||
void BSP_SD_GetCardInfo(BSP_SD_CardInfo *CardInfo)
|
||||
{
|
||||
HAL_SD_GetCardInfo(&uSdHandle, CardInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief BSP SD Abort callbacks
|
||||
* @retval None
|
||||
*/
|
||||
__weak void BSP_SD_AbortCallback(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief BSP Tx Transfer completed callbacks
|
||||
* @retval None
|
||||
*/
|
||||
__weak void BSP_SD_WriteCpltCallback(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief BSP Rx Transfer completed callbacks
|
||||
* @retval None
|
||||
*/
|
||||
__weak void BSP_SD_ReadCpltCallback(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief BSP Error callbacks
|
||||
* @retval None
|
||||
*/
|
||||
__weak void BSP_SD_ErrorCallback(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief BSP SD Transceiver 1.8V Mode Callback.
|
||||
*/
|
||||
__weak void BSP_SD_DriveTransciver_1_8V_Callback(FlagStatus status)
|
||||
{
|
||||
#if 0
|
||||
if(status == SET)
|
||||
{
|
||||
BSP_IO_WritePin(IO_PIN_13, BSP_IO_PIN_SET);
|
||||
}
|
||||
else
|
||||
{
|
||||
BSP_IO_WritePin(IO_PIN_13, BSP_IO_PIN_RESET);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief SD Abort callbacks
|
||||
* @param hsd: SD handle
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SD_AbortCallback(SD_HandleTypeDef *hsd)
|
||||
{
|
||||
BSP_SD_AbortCallback();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tx Transfer completed callbacks
|
||||
* @param hsd: SD handle
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SD_TxCpltCallback(SD_HandleTypeDef *hsd)
|
||||
{
|
||||
BSP_SD_WriteCpltCallback();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Rx Transfer completed callbacks
|
||||
* @param hsd: SD handle
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SD_RxCpltCallback(SD_HandleTypeDef *hsd)
|
||||
{
|
||||
BSP_SD_ReadCpltCallback();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Error callbacks
|
||||
* @param hsd: SD handle
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SD_ErrorCallback(SD_HandleTypeDef *hsd)
|
||||
{
|
||||
BSP_SD_ErrorCallback();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable the SD Transceiver 1.8V Mode Callback.
|
||||
*/
|
||||
void HAL_SD_DriveTransciver_1_8V_Callback(FlagStatus status)
|
||||
{
|
||||
BSP_SD_DriveTransciver_1_8V_Callback(status);
|
||||
}
|
||||
|
||||
void SDMMC1_IRQHandler(void)
|
||||
{
|
||||
HAL_SD_IRQHandler(&uSdHandle);
|
||||
}
|
||||
|
||||
/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
|
||||
@ -1,160 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h743i_eval_sd.h
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 29-December-2017
|
||||
* @brief This file contains the common defines and functions prototypes for
|
||||
* the stm32h743i_eval_sd.c driver.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __STM32H743I_EVAL_SD_H
|
||||
#define __STM32H743I_EVAL_SD_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32H743I_EVAL
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup STM32H743I_EVAL_SD SD
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup STM32H743I_EVAL_SD_Exported_Types SD Exported Types
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief SD Card information structure
|
||||
*/
|
||||
#define BSP_SD_CardInfo HAL_SD_CardInfoTypeDef
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief SD status structure definition
|
||||
*/
|
||||
#define MSD_OK ((uint8_t)0x00)
|
||||
#define MSD_ERROR ((uint8_t)0x01)
|
||||
#define MSD_ERROR_SD_NOT_PRESENT ((uint8_t)0x02)
|
||||
|
||||
/**
|
||||
* @brief SD transfer state definition
|
||||
*/
|
||||
#define SD_TRANSFER_OK ((uint8_t)0x00)
|
||||
#define SD_TRANSFER_BUSY ((uint8_t)0x01)
|
||||
|
||||
/** @defgroup STM32H743I_EVAL_SD_Exported_Constants SD Exported Constants
|
||||
* @{
|
||||
*/
|
||||
#define SD_PRESENT ((uint8_t)0x01)
|
||||
#define SD_NOT_PRESENT ((uint8_t)0x00)
|
||||
|
||||
#define SD_DATATIMEOUT ((uint32_t)100000000)
|
||||
|
||||
|
||||
#define SD_DetectIRQHandler() HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_8)
|
||||
|
||||
#ifndef USE_SD_TRANSCEIVER
|
||||
#define USE_SD_TRANSCEIVER 0
|
||||
#endif /* USE_SD_TRANSCEIVER */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32H743I_EVAL_SD_Exported_Macro SD Exported Macro
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32H743I_EVAL_SD_Exported_Functions SD Exported Functions
|
||||
* @{
|
||||
*/
|
||||
uint8_t BSP_SD_Init(void);
|
||||
uint8_t BSP_SD_DeInit(void);
|
||||
uint8_t BSP_SD_ITConfig(void);
|
||||
|
||||
uint8_t BSP_SD_ReadBlocks(uint32_t *pData, uint32_t ReadAddr, uint32_t NumOfBlocks, uint32_t Timeout);
|
||||
uint8_t BSP_SD_WriteBlocks(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBlocks, uint32_t Timeout);
|
||||
uint8_t BSP_SD_ReadBlocks_DMA(uint32_t *pData, uint32_t ReadAddr, uint32_t NumOfBlocks);
|
||||
uint8_t BSP_SD_WriteBlocks_DMA(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBlocks);
|
||||
uint8_t BSP_SD_Erase(uint32_t StartAddr, uint32_t EndAddr);
|
||||
uint8_t BSP_SD_GetCardState(void);
|
||||
void BSP_SD_GetCardInfo(BSP_SD_CardInfo *CardInfo);
|
||||
uint8_t BSP_SD_IsDetected(void);
|
||||
|
||||
/* These functions can be modified in case the current settings (e.g. DMA stream)
|
||||
need to be changed for specific application needs */
|
||||
void BSP_SD_MspInit(SD_HandleTypeDef *hsd, void *Params);
|
||||
void BSP_SD_MspDeInit(SD_HandleTypeDef *hsd, void *Params);
|
||||
void BSP_SD_AbortCallback(void);
|
||||
void BSP_SD_WriteCpltCallback(void);
|
||||
void BSP_SD_ReadCpltCallback(void);
|
||||
void BSP_SD_ErrorCallback(void);
|
||||
void BSP_SD_DriveTransciver_1_8V_Callback(FlagStatus status);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __STM32H743I_EVAL_SD_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
Loading…
x
Reference in New Issue
Block a user