ble.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #ifndef __BLE_H
  2. #define __BLE_H
  3. #include "ble_core.h"
  4. #include <stdint.h>
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. #ifdef __BLE_H_GLOBAL
  9. #define __BLE_H_EXTERN
  10. #else
  11. #define __BLE_H_EXTERN extern
  12. #endif
  13. /************************************************************************************************
  14. * Version *
  15. ************************************************************************************************/
  16. /************************************************************************************************
  17. * How to use *
  18. ************************************************************************************************/
  19. /************************************************************************************************
  20. * Enable config *
  21. ************************************************************************************************/
  22. /************************************************************************************************
  23. * Includes *
  24. ************************************************************************************************/
  25. /************************************************************************************************
  26. * Defines *
  27. ************************************************************************************************/
  28. #define BT_BUSY_IND_PORT GPIOB
  29. #define BT_BUSY_IND_PIN GPIO_Pin_12
  30. #define BT_CONN_IND_PORT GPIOB
  31. #define BT_CONN_IND_PIN GPIO_Pin_13
  32. #define BT_RST_PORT GPIOC
  33. #define BT_RST_PIN GPIO_Pin_2
  34. #define BLE_NAME "ALIENTEK"
  35. #define BLE_CODE 0
  36. #define BLE_CFG_DELAY_MS 1020
  37. #define BLE_START_DELAY_MS 500
  38. #define BLE_QRY_DELAY_MS 500
  39. #define BLE_RESTORE_DELAY_MS 1000
  40. #define MAC_LEN 6
  41. #define SN_LEN 10
  42. #define MODEL_LEN 6
  43. /************************************************************************************************
  44. * Typedefs *
  45. ************************************************************************************************/
  46. #pragma pack(1)
  47. typedef enum
  48. {
  49. BLE_INIT_CMD_NAME_QRY = 0,
  50. BLE_INIT_CMD_NAME_CFG,
  51. BLE_INIT_CMD_CODE_CFG,
  52. BLE_INIT_CMD_TXWPR_CFG,
  53. BLE_INIT_CMD_MAX,
  54. } EN_BLE_INIT_CMD;
  55. typedef enum
  56. {
  57. BLE_QRY_CMD_ADV_QRY = 0,
  58. BLE_QRY_CMD_MAC_QRY,
  59. BLE_QRY_CMD_ADV_CFG,
  60. BLE_QRY_CMD_MAX,
  61. } EN_BLE_QRY_CMD;
  62. #define BLE_MTU 100
  63. typedef struct
  64. {
  65. uint8_t is_used;
  66. uint8_t cmd;
  67. uint8_t len;
  68. uint8_t data[BLE_MTU];
  69. int32_t (*p_func)(uint8_t cmd, uint8_t status, uint8_t *data, uint8_t len);
  70. uint32_t tick;
  71. } BLE_CMD_CACHE;
  72. #pragma pack(0)
  73. /************************************************************************************************
  74. * Interfaces *
  75. ************************************************************************************************/
  76. void ble_init(void);
  77. int32_t ble_loop(void);
  78. int32_t ble_send_data(uint8_t data[], int32_t length);
  79. int32_t ble_data_recv(uint8_t data[], uint8_t length, int32_t ms);
  80. #ifdef __cplusplus
  81. };
  82. #endif
  83. #endif // __BLE_H