button_pro.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #include "prf_defs.h"
  2. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #if (BUT_PROFILE_CFG)
  15. #include "common/bt_target.h"
  16. #include "stack/gatt_api.h"
  17. #include "stack/gattdefs.h"
  18. #include "esp_gatt_api.h"
  19. #define KEY_SUCCESS GATT_SUCCESS
  20. #define KEY_ILLEGAL_PARAM GATT_ILLEGAL_PARAMETER
  21. #define KEY_NO_RESOURCES GATT_NO_RESOURCES
  22. //define the key serivce uuid
  23. #define ATT_SVC_BUTTON 0xFFFF
  24. //define the key Char uuid
  25. #define ATT_CHAR_BUTTON_WIT 0xFF01
  26. #define ATT_CHAR_BUTTON_NTF 0xFF02
  27. #define BUTTON_PRESS_NTF_CFG 0x01
  28. #define BUTTON_VAL_MAX_LEN (10)
  29. #define BUTT_MAX_APPS GATT_CL_MAX_LCB
  30. #define BUT_MAX_STRING_DATA 7
  31. typedef void (*but_prf_cb_t)(uint8_t app_id, uint8_t event, uint16_t len, uint8_t *value);
  32. #ifndef BUT_MAX_INT_NUM
  33. #define BUT_MAX_INT_NUM 4
  34. #endif
  35. enum {
  36. RECEIVE_NET_PASSWD_EVT,
  37. RECEIVE_NET_SSD_EVT,
  38. RECEIVE_EVT_MAX
  39. };
  40. /// button Service Attributes Indexes
  41. enum {
  42. KEY_IDX_SVC,
  43. KEY_IDX_BUTTON_WIT_CHAR,
  44. KEY_IDX_BUTTON_WIT_VAL,
  45. KEY_IDX_BUTTON_NTF_CHAR,
  46. KEY_IDX_BUTTON_NTF_VAL,
  47. KEY_IDX_BUTTON_NTF_CFG,
  48. KEY_IDX_NB,
  49. };
  50. typedef struct {
  51. BD_ADDR remote_bda;
  52. BOOLEAN need_rsp;
  53. uint16_t clt_cfg;
  54. } but_write_data_t;
  55. typedef struct {
  56. BOOLEAN in_use;
  57. BOOLEAN congest;
  58. uint16_t conn_id;
  59. BOOLEAN connected;
  60. BD_ADDR remote_bda;
  61. uint32_t trans_id;
  62. uint8_t cur_srvc_id;
  63. } but_clcb_t;
  64. typedef struct {
  65. uint8_t app_id;
  66. uint16_t but_wirt_hdl;
  67. uint16_t but_ntf_hdl;
  68. uint16_t but_cfg_hdl;
  69. but_prf_cb_t p_cback;
  70. } but_inst_t;
  71. /* service engine control block */
  72. typedef struct {
  73. but_clcb_t clcb; /* connection link*/
  74. esp_gatt_if_t gatt_if;
  75. BOOLEAN enabled;
  76. BOOLEAN is_primery;
  77. but_inst_t button_inst;
  78. uint8_t inst_id;
  79. } button_env_cb_t;
  80. void Button_CreateService(void);
  81. but_clcb_t *button_env_clcb_alloc(uint16_t conn_id, BD_ADDR bda);
  82. uint16_t button_env_find_conn_id_by_bd_adddr(BD_ADDR bda);
  83. BOOLEAN button_env_clcb_dealloc(uint16_t conn_id);
  84. esp_gatt_status_t button_init(but_prf_cb_t call_back);
  85. void button_disable(uint16_t connid);
  86. void button_msg_notify(uint16_t len, uint8_t *button_msg);
  87. extern button_env_cb_t button_cb_env;
  88. #endif ///BUT_PROFILE_CFG