ble.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #include "include.h"
  2. #if LE_EN || BT_ATT_EN
  3. static ble_gatt_characteristic_cb_info_t *characteristic_cb_info[LE_ATT_NUM] AT(.ble_cache.att);
  4. static uint8_t gatts_profile_table[LE_ATT_NUM * 10] AT(.ble_cache.att);
  5. void priv_ble_gatts_service_init(void);
  6. #if LE_EN
  7. const bool cfg_ble_security_en = LE_PAIR_EN;
  8. bool cfg_ble_sm_sc_en = LE_SM_SC_EN;
  9. bool cfg_bt_ble_adv = LE_ADV_POWERON_EN;
  10. //可重定义该函数修改ble地址
  11. #if LE_SM_SC_EN
  12. void ble_get_local_bd_addr(u8 *addr)
  13. {
  14. bt_get_local_bd_addr(addr);
  15. }
  16. #endif
  17. //可重定义该函数修改ble地址类型
  18. u8 ble_get_local_addr_mode(void)
  19. {
  20. return LE_ADDRESS_TYPE;
  21. }
  22. void ble_disconnect_callback(void)
  23. {
  24. printf("--->ble_disconnect_callback\n");
  25. #if GFPS_EN
  26. gfps_ble_disconnected_callback();
  27. #endif
  28. app_ble_disconnect_callback();
  29. }
  30. void ble_connect_callback(void)
  31. {
  32. printf("--->ble_connect_callback\n");
  33. #if GFPS_EN
  34. gfps_ble_connected_callback();
  35. #endif
  36. app_ble_connect_callback();
  37. }
  38. //主从切换时获取需要同步给新主机的数据,返回数据长度
  39. uint16_t role_switch_get_user_ble_data(uint8_t *data_ptr)
  40. {
  41. printf("role_switch_get_user_ble_data\n");
  42. uint16_t len = app_ble_role_switch_get_data(data_ptr);
  43. return len;
  44. }
  45. //主从切换时接收到旧主机传递的数据
  46. uint16_t role_switch_set_user_ble_data(uint8_t *data_ptr, uint16_t len)
  47. {
  48. printf("role_switch_set_user_ble_data data\n");
  49. app_ble_role_switch_set_data(data_ptr,len);
  50. return len;
  51. }
  52. uint ble_get_bat_level(void)
  53. {
  54. return bsp_get_bat_level();
  55. }
  56. #if LE_SM_SC_EN
  57. void ble_get_link_info(void *buf, u16 addr, u16 size)
  58. {
  59. //printf("bt_read: %04x,%04x, %08lx\n", addr, size, BLE_CM_PAGE(addr));
  60. cm_read(buf, BLE_CM_PAGE(addr), size);
  61. //print_r(buf, size);
  62. }
  63. void ble_put_link_info(void *buf, u16 addr, u16 size)
  64. {
  65. //printf("bt_write: %04x,%04x, %08lx\n", addr, size, BLE_CM_PAGE(addr));
  66. //print_r(buf, size);
  67. cm_write(buf, BLE_CM_PAGE(addr), size);
  68. }
  69. void ble_sync_link_info(void)
  70. {
  71. cm_sync();
  72. }
  73. #endif
  74. #endif // LE_EN
  75. void ble_init_att(void)
  76. {
  77. ble_gatts_init(gatts_profile_table, sizeof(gatts_profile_table),
  78. characteristic_cb_info,
  79. LE_ATT_NUM);
  80. app_ble_init();
  81. priv_ble_gatts_service_init();
  82. }
  83. #endif // LE_EN || BT_ATT_EN