You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
153 lines
4.0 KiB
153 lines
4.0 KiB
#ifndef __UART_INTERFACE_H
|
|
#define __UART_INTERFACE_H
|
|
/**
|
|
* 封装不同使用类型串口 232 485 max3160
|
|
* 封装对应的 GPIO操作
|
|
*/
|
|
/* 485 3160 启用一个, 两个接口都有 MAX3160_ENABLE */
|
|
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include <stdlib.h>
|
|
#include "main.h"
|
|
|
|
#define MAX485_ENABLE 0
|
|
#define MAX3160_ENABLE 1
|
|
|
|
typedef enum
|
|
{
|
|
Uart_Status_Ready = 0x00U,
|
|
Uart_Status_Sending = 0x01U,
|
|
Uart_Status_Send_Cplt = 0x02U,
|
|
Uart_Status_Timeout = 0x10U,
|
|
Uart_Status_Error = 0x11U,
|
|
} Uart_Status_TypeDef;
|
|
|
|
typedef enum
|
|
{
|
|
Uart_Interface_Default = 0x00U,
|
|
Uart_Interface_485 = 0x01U,
|
|
Uart_Interface_Max3160 = 0x02U,
|
|
} Uart_Interface_Type_Typedef;
|
|
|
|
|
|
typedef enum
|
|
{
|
|
Uart_Trans_Polling = 0x00U,
|
|
Uart_Trans_IT = 0x01U,
|
|
Uart_Trans_DMA = 0x02U,
|
|
} Uart_Transmode_TypeDef;
|
|
|
|
|
|
typedef enum
|
|
{
|
|
Uart_RSMODE_232 = 0x00U,
|
|
Uart_RSMODE_485 = 0x01U,
|
|
} Uart_RS_Mode_TypeDef;
|
|
|
|
|
|
typedef enum
|
|
{
|
|
Uart_IDLE_IT_DISABLE = 0x00U,
|
|
Uart_IDLE_IT_ENABLE = 0x01U,
|
|
} Uart_IDLE_Enable_TypeDef;
|
|
|
|
|
|
|
|
#if MAX3160_ENABLE
|
|
|
|
typedef enum{
|
|
SEL_232 = 0,
|
|
SEL_485 = 1,
|
|
}Max3160_Sel_TypeDef;
|
|
|
|
typedef enum{
|
|
DUPLEX_FULL = 0,
|
|
DUPLEX_HALF = 1,
|
|
}Max3160_Duplex_TypeDef; /* 发送时切换全双工(拉低),否则回显, 接收为半双工(拉高 默认)*/
|
|
|
|
typedef enum{
|
|
DISABLE_485_SEND = 0,
|
|
ENABLE_485_SEND = 1,
|
|
}Max3160_DE_TypeDef;
|
|
|
|
# endif
|
|
|
|
#if MAX485_ENABLE
|
|
typedef enum{
|
|
DISABLE_485_SEND = 0,
|
|
ENABLE_485_SEND = 1,
|
|
}Max_DE_TypeDef;
|
|
# endif
|
|
|
|
|
|
|
|
typedef struct
|
|
{
|
|
// UART_HandleTypeDef *huart;
|
|
uint8_t interface_type; /* 0: common, 1: 485 ,2:3160*/
|
|
uint8_t mode_232_485; /* 0: common, 1: 485 */
|
|
|
|
#if MAX485_ENABLE
|
|
GPIO_TypeDef *de485_gpio;
|
|
uint16_t de485_pin;
|
|
uint8_t de485;
|
|
#endif
|
|
|
|
#if MAX3160_ENABLE
|
|
GPIO_TypeDef *de485_gpio;
|
|
uint16_t de485_pin;
|
|
GPIO_TypeDef *sel_gpio;
|
|
GPIO_TypeDef *dplx_gpio;
|
|
uint16_t sel_pin;
|
|
uint16_t dplx_pin;
|
|
uint8_t sel;
|
|
uint8_t dplx;
|
|
#endif
|
|
uint8_t trans_mode; /* 0 :polling, 1: IT 2: DMA*/
|
|
|
|
|
|
}UartInterface_TypeDef;
|
|
|
|
// extern UartInterface_TypeDef *uart_helper;
|
|
|
|
UartInterface_TypeDef * UartInterface_Init( );
|
|
|
|
int UartInterface_Setup_Mode_232_485( UartInterface_TypeDef * interface, Uart_RS_Mode_TypeDef mode_232_485 );
|
|
int UartInterface_Setup_Transmod( UartInterface_TypeDef * interface, Uart_Transmode_TypeDef trans_mode );
|
|
int UartInterface_Setup_Interface_type( UartInterface_TypeDef * interface, Uart_Interface_Type_Typedef interface_type );
|
|
// int UartInterface_Setup_Woek_Mode( UartInterface_TypeDef * interface, uint8_t rs_232_485 );
|
|
|
|
void UartInterface_Set_Sel_GPIO_Pin(UartInterface_TypeDef * interface, GPIO_TypeDef *gpio, uint16_t pin);
|
|
void UartInterface_Set_Dplx_GPIO_Pin(UartInterface_TypeDef * interface, GPIO_TypeDef *gpio, uint16_t pin);
|
|
void UartInterface_Set_DE485_GPIO_Pin(UartInterface_TypeDef * interface, GPIO_TypeDef *gpio, uint16_t pin);
|
|
|
|
void UartInterface_Set_232(UartInterface_TypeDef * interface);
|
|
void UartInterface_Set_485(UartInterface_TypeDef * interface);
|
|
|
|
int UartInterface_Set_GPIO_For_Transmit( UartInterface_TypeDef * interface );
|
|
int UartInterface_Set_GPIO_For_Trans_Cplt( UartInterface_TypeDef * interface );
|
|
|
|
/* 接收方式 也有三种类型 */
|
|
// int UartInterface_Start_Rcv(UartInterface_TypeDef * interface, uint8_t *buf, uint16_t size);
|
|
// void UartInterface_Set_Huart(UartInterface_TypeDef * interface, UART_HandleTypeDef *huart);
|
|
// int UartInterface_Send(UartInterface_TypeDef * interface, uint8_t *buf, uint16_t size);
|
|
// int __UartInterface_Send(UartInterface_TypeDef * interface , uint8_t *buf, uint16_t size);
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|
|
|
|
/**
|
|
// int UartInterface_Send(UartInterface_TypeDef * interface, uint8_t *buf, uint16_t size);
|
|
// int __UartInterface_Send(UartInterface_TypeDef * interface , uint8_t *buf, uint16_t size);
|
|
|
|
// int UartInterface_Send_TxCplt_Callback( UartInterface_TypeDef * interface );
|
|
|
|
// int UartInterface_Send_Cplt(UartInterface_TypeDef * interface);
|
|
// void UartInterface_Set_tc_flag(UartInterface_TypeDef * interface);
|
|
*/ |