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.
63 lines
1.4 KiB
63 lines
1.4 KiB
2 years ago
|
#ifndef API_UART_H
|
||
|
#define API_UART_H
|
||
|
|
||
|
#include "CH58x_common.h"
|
||
|
#include "api-gpio.h"
|
||
|
#include "fifo.h"
|
||
|
|
||
|
#define RxSize (127)
|
||
|
#define UART_NUMBER (2)
|
||
|
typedef struct {
|
||
|
__IO uint8_t MCR;
|
||
|
__IO uint8_t IER;
|
||
|
__IO uint8_t FCR;
|
||
|
__IO uint8_t LCR;
|
||
|
__IO uint8_t IIR;
|
||
|
__IO uint8_t LSR;
|
||
|
__IO uint8_t MSR;
|
||
|
__IO uint8_t RBR;
|
||
|
__IO uint8_t THR;
|
||
|
__IO uint8_t RFC;
|
||
|
__IO uint8_t TFC;
|
||
|
__IO uint16_t DL;
|
||
|
__IO uint8_t DIV;
|
||
|
__IO uint8_t ADR;
|
||
|
} UART_TypeDef;
|
||
|
#define UARTDIS (0x400)
|
||
|
#define Uart(x) ((UART_TypeDef *)(0x40003000 + (x) * UARTDIS))
|
||
|
|
||
|
|
||
|
typedef enum {
|
||
|
DataBit_5 = 0,
|
||
|
DataBit_6,
|
||
|
DataBit_7,
|
||
|
DataBit_8,
|
||
|
} DataBits_t;
|
||
|
typedef enum {
|
||
|
StopBit_1 = 0,
|
||
|
StopBit_2,
|
||
|
} StopBits_t;
|
||
|
typedef enum {
|
||
|
Parity_None = 0,
|
||
|
Parity_Odd,//奇校验
|
||
|
Parity_Even,
|
||
|
} Parity_t;
|
||
|
typedef struct {
|
||
|
uint8_t Len;
|
||
|
uint8_t RxBuff[RxSize];//串口接受缓存区
|
||
|
Fifo_t RxFifo;
|
||
|
} Uart_t;
|
||
|
|
||
|
#define println(fmt, ...) printf(fmt "\r\n", ##__VA_ARGS__)
|
||
|
#define printHex(buf, size) do{for(int p__i=0;p__i<size,p__i++){printf("%02x",(buf)[i]);}printf("\r\n");}while(0)
|
||
|
|
||
|
void Uart_Init(uint8_t uartId, GpioPin_t Tx, GpioPin_t Rx, uint32_t baudRate, DataBits_t dataBits,
|
||
|
StopBits_t stopBits, Parity_t parity);
|
||
|
|
||
|
void Uart_INCfg(uint8_t uartId, FunctionalState s, uint8_t i);
|
||
|
|
||
|
bool Api_GetUartData(uint8_t id, uint8_t *cmd);
|
||
|
|
||
|
|
||
|
#endif
|