#ifndef __hal_ble_uart0__ #define __hal_ble_uart0__ #include #include #include #include "sdk_common.h" #include "SEGGER_RTT.h" #include "usr_config.h" #ifdef __cplusplus extern "C" { #endif #ifdef __cplusplus } #endif #define UART0_INVALID_PIN PIN_UART0_UNUSED_PIN //该引脚不能使用0XFF,否则程序崩溃。 /*************** 发送命令 ********************/ typedef enum { UART0_T_HEART = 0, UART0_T_CONFIG_ASK, //配对申请 UART0_T_CONFIG_ACK, //配对成功 UART0_T_CHAR_VOL, //充电电量 UART0_T_SELF_CHECK_RDY, //自检准备 UART0_T_SELF_CHECK_ASK, //自检开始 UART0_T_SELF_CHECK_ACK, //自检结果 UART0_T_LINE_CHECK_ASK, //自检串口线ASK UART0_T_LINE_CHECK_ACK, //自检串口线ACK UART0_NUM_OF_T, //命令连续用此值 }UART0_T_n; //#define UART0_NUM_OF_T 9 //注意:::此值根据命令的数量改变 /*************** 发送子命令 ********************/ //enum { //UART0_T_UPDATE // UART0_T_UPDATE_BASEINFO = 0, //设备基本信息 // UART0_T_UPDATE_DATA , //设备数据 // UART0_T_UPDATE_STEPNUM , //回复存储步数 // UART0_T_UPDATE_STEPNUM_CLERA, //删除存储步数 //}; //enum { //UART0_T_CHARGE // UART0_T_CHARGE_NONE = 0, // UART0_T_CHARGE_PULLOUT, // UART0_T_CHARGE_INSERT, // UART0_T_CHARGE_DONE, // UART0_T_CHARGE_ERROR, //}; /*************** 接收命令 ********************/ typedef enum { UART0_R_HEART = 0, UART0_R_CONFIG_ASK, //配对申请 UART0_R_CONFIG_ACK, //配对成功 UART0_R_CHAR_VOL, //充电电量 UART0_R_SELF_CHECK_RDY, //自检准备 UART0_R_SELF_CHECK_ASK, //自检开始 UART0_R_SELF_CHECK_ACK, //自检结果 UART0_R_LINE_CHECK_ASK, //自检串口线ASK UART0_R_LINE_CHECK_ACK, //自检串口线ACK UART0_NUM_OF_R, //命令连续用此值 }UART0_R_n; //#define UART0_NUM_OF_R 11 //注意:::此值根据命令的数量改变 /*************** 接收子命令 ********************/ //enum { //UART0_R_UPDATE // UART0_R_UPDATE_BASEINFO = 0, // UART0_R_UPDATE_DATA , // UART0_R_UPDATE_STEPNUM, // UART0_R_UPDATE_STEPNUM_CLERA, //}; typedef void (*UART0_Callback)(void*); typedef struct _UART0_Rx{ uint8_t cmd; uint8_t* pDat; uint8_t datLen; UART0_Callback cb; }UART0_Rx_t; typedef struct _UART0_Tx{ uint8_t n; uint32_t t; uint8_t ncnt; uint32_t tcnt; uint8_t cmd; uint8_t* pDat; uint8_t datLen; uint8_t holdon; UART0_Callback cb; struct _UART0_Tx *next; //单向链表 }UART0_Tx_t; void UART0_Initialize(uint32_t txd, uint32_t rxd, uint32_t baud); void UART0_unInit(uint32_t txd, uint32_t rxd); void UART0_Send(unsigned char cmd,unsigned char *pDat,unsigned char datLen); int UART0_Rx_Regist(unsigned char cmd,UART0_Callback cb); void UART0_Tx_Send(UART0_Tx_t* handle,unsigned char cmd,unsigned char *pDat,unsigned char datLen); void UART0_Tx_Clear(UART0_Tx_t* handle); void UART0_Push(unsigned char* p,int len); void UART0_GetPinConfig(uint32_t *txd, uint32_t *rxd); #endif