hal_ble_uart0.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #ifndef __hal_ble_uart0__
  2. #define __hal_ble_uart0__
  3. #include <stdbool.h>
  4. #include <stdint.h>
  5. #include <string.h>
  6. #include "sdk_common.h"
  7. #include "SEGGER_RTT.h"
  8. #include "usr_config.h"
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. #ifdef __cplusplus
  13. }
  14. #endif
  15. #define UART0_INVALID_PIN PIN_UART0_UNUSED_PIN //该引脚不能使用0XFF,否则程序崩溃。
  16. /*************** 发送命令 ********************/
  17. typedef enum {
  18. UART0_T_HEART = 0,
  19. UART0_T_CONFIG_ASK, //配对申请
  20. UART0_T_CONFIG_ACK, //配对成功
  21. UART0_T_CHAR_VOL, //充电电量
  22. UART0_T_SELF_CHECK_RDY, //自检准备
  23. UART0_T_SELF_CHECK_ASK, //自检开始
  24. UART0_T_SELF_CHECK_ACK, //自检结果
  25. UART0_T_LINE_CHECK_ASK, //自检串口线ASK
  26. UART0_T_LINE_CHECK_ACK, //自检串口线ACK
  27. UART0_NUM_OF_T, //命令连续用此值
  28. }UART0_T_n;
  29. //#define UART0_NUM_OF_T 9 //注意:::此值根据命令的数量改变
  30. /*************** 发送子命令 ********************/
  31. //enum { //UART0_T_UPDATE
  32. // UART0_T_UPDATE_BASEINFO = 0, //设备基本信息
  33. // UART0_T_UPDATE_DATA , //设备数据
  34. // UART0_T_UPDATE_STEPNUM , //回复存储步数
  35. // UART0_T_UPDATE_STEPNUM_CLERA, //删除存储步数
  36. //};
  37. //enum { //UART0_T_CHARGE
  38. // UART0_T_CHARGE_NONE = 0,
  39. // UART0_T_CHARGE_PULLOUT,
  40. // UART0_T_CHARGE_INSERT,
  41. // UART0_T_CHARGE_DONE,
  42. // UART0_T_CHARGE_ERROR,
  43. //};
  44. /*************** 接收命令 ********************/
  45. typedef enum {
  46. UART0_R_HEART = 0,
  47. UART0_R_CONFIG_ASK, //配对申请
  48. UART0_R_CONFIG_ACK, //配对成功
  49. UART0_R_CHAR_VOL, //充电电量
  50. UART0_R_SELF_CHECK_RDY, //自检准备
  51. UART0_R_SELF_CHECK_ASK, //自检开始
  52. UART0_R_SELF_CHECK_ACK, //自检结果
  53. UART0_R_LINE_CHECK_ASK, //自检串口线ASK
  54. UART0_R_LINE_CHECK_ACK, //自检串口线ACK
  55. UART0_NUM_OF_R, //命令连续用此值
  56. }UART0_R_n;
  57. //#define UART0_NUM_OF_R 11 //注意:::此值根据命令的数量改变
  58. /*************** 接收子命令 ********************/
  59. //enum { //UART0_R_UPDATE
  60. // UART0_R_UPDATE_BASEINFO = 0,
  61. // UART0_R_UPDATE_DATA ,
  62. // UART0_R_UPDATE_STEPNUM,
  63. // UART0_R_UPDATE_STEPNUM_CLERA,
  64. //};
  65. typedef void (*UART0_Callback)(void*);
  66. typedef struct _UART0_Rx{
  67. uint8_t cmd;
  68. uint8_t* pDat;
  69. uint8_t datLen;
  70. UART0_Callback cb;
  71. }UART0_Rx_t;
  72. typedef struct _UART0_Tx{
  73. uint8_t n;
  74. uint32_t t;
  75. uint8_t ncnt;
  76. uint32_t tcnt;
  77. uint8_t cmd;
  78. uint8_t* pDat;
  79. uint8_t datLen;
  80. uint8_t holdon;
  81. UART0_Callback cb;
  82. struct _UART0_Tx *next; //单向链表
  83. }UART0_Tx_t;
  84. void UART0_Initialize(uint32_t txd, uint32_t rxd, uint32_t baud);
  85. void UART0_unInit(uint32_t txd, uint32_t rxd);
  86. void UART0_Send(unsigned char cmd,unsigned char *pDat,unsigned char datLen);
  87. int UART0_Rx_Regist(unsigned char cmd,UART0_Callback cb);
  88. void UART0_Tx_Send(UART0_Tx_t* handle,unsigned char cmd,unsigned char *pDat,unsigned char datLen);
  89. void UART0_Tx_Clear(UART0_Tx_t* handle);
  90. void UART0_Push(unsigned char* p,int len);
  91. void UART0_GetPinConfig(uint32_t *txd, uint32_t *rxd);
  92. #endif