串口同时支持原来的方式吧
This commit is contained in:
parent
ccb8d1df59
commit
eda680bddf
|
@ -16,7 +16,7 @@ SerialPort::SerialPort(USART_TypeDef* com, int baudRate, int parity, int dataBit
|
|||
assert_param(com);
|
||||
|
||||
USART_TypeDef* g_Uart_Ports[] = UARTS;
|
||||
_index = 0xFF;
|
||||
byte _index = 0xFF;
|
||||
for(int i=0; i<ArrayLength(g_Uart_Ports); i++)
|
||||
{
|
||||
if(g_Uart_Ports[i] == com)
|
||||
|
@ -25,13 +25,21 @@ SerialPort::SerialPort(USART_TypeDef* com, int baudRate, int parity, int dataBit
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Init(_index, baudRate, parity, dataBits, stopBits);
|
||||
}
|
||||
|
||||
void SerialPort::Init(byte index, int baudRate, int parity, int dataBits, int stopBits)
|
||||
{
|
||||
USART_TypeDef* g_Uart_Ports[] = UARTS;
|
||||
_index = index;
|
||||
assert_param(_index < ArrayLength(g_Uart_Ports));
|
||||
|
||||
_port = g_Uart_Ports[_index];
|
||||
_baudRate = baudRate;
|
||||
_parity = parity;
|
||||
_dataBits = dataBits;
|
||||
_stopBits = stopBits;
|
||||
_port = com;
|
||||
|
||||
_tx = NULL;
|
||||
_rx = NULL;
|
||||
|
|
15
SerialPort.h
15
SerialPort.h
|
@ -19,9 +19,24 @@ private:
|
|||
AlternatePort* _tx;
|
||||
InputPort* _rx;
|
||||
|
||||
void Init(byte index,
|
||||
int baudRate = 115200,
|
||||
int parity = USART_Parity_No, //无奇偶校验
|
||||
int dataBits = USART_WordLength_8b, //8位数据长度
|
||||
int stopBits = USART_StopBits_1); //1位停止位
|
||||
|
||||
public:
|
||||
OutputPort* RS485; // RS485使能引脚
|
||||
|
||||
SerialPort(COM_Def index,
|
||||
int baudRate = 115200,
|
||||
int parity = USART_Parity_No, //无奇偶校验
|
||||
int dataBits = USART_WordLength_8b, //8位数据长度
|
||||
int stopBits = USART_StopBits_1) //1位停止位
|
||||
{
|
||||
Init(index, baudRate, parity, dataBits, stopBits);
|
||||
}
|
||||
|
||||
SerialPort(USART_TypeDef* com,
|
||||
int baudRate = 115200,
|
||||
int parity = USART_Parity_No, //无奇偶校验
|
||||
|
|
23
Sys.h
23
Sys.h
|
@ -35,17 +35,20 @@ typedef char* String;
|
|||
#include "Platform\Pin.h"
|
||||
|
||||
/* 串口定义 */
|
||||
#define COM1 0
|
||||
#define COM2 1
|
||||
#define COM3 2
|
||||
#define COM4 3
|
||||
#define COM5 4
|
||||
typedef enum
|
||||
{
|
||||
COM1 = 0,
|
||||
COM2 = 1,
|
||||
COM3 = 2,
|
||||
COM4 = 3,
|
||||
COM5 = 4,
|
||||
#ifdef STM32F4
|
||||
#define COM6 5
|
||||
#define COM7 6
|
||||
#define COM8 7
|
||||
COM6 = 5,
|
||||
COM7 = 6,
|
||||
COM8 = 7,
|
||||
#endif
|
||||
#define COM_NONE 0xFF
|
||||
COM_NONE = 0xFF
|
||||
} COM_Def;
|
||||
|
||||
// 委托
|
||||
#include "Delegate.h"
|
||||
|
@ -61,7 +64,7 @@ public:
|
|||
bool Inited; // 是否已完成初始化
|
||||
uint Clock; // 系统时钟
|
||||
uint CystalClock; // 晶振时钟
|
||||
byte MessagePort; // 消息口,默认0表示USART1
|
||||
COM_Def MessagePort; // 消息口,默认0表示USART1
|
||||
byte ID[12]; // 芯片ID。
|
||||
ushort FlashSize; // 芯片Flash容量。
|
||||
ushort RAMSize; // 芯片RAM容量
|
||||
|
|
Loading…
Reference in New Issue