esp_hidh_private.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef _ESP_HIDH_PRIVATE_H_
  14. #define _ESP_HIDH_PRIVATE_H_
  15. #include "esp_hidh.h"
  16. #if CONFIG_BLUEDROID_ENABLED
  17. #include "esp_gap_bt_api.h"
  18. #endif /* CONFIG_BLUEDROID_ENABLED */
  19. #include "freertos/FreeRTOS.h"
  20. #include "freertos/task.h"
  21. #include "freertos/semphr.h"
  22. #include "esp_event.h"
  23. #include "sys/queue.h"
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. /**
  28. * @brief HIDH device report data
  29. */
  30. typedef struct esp_hidh_dev_report_s {
  31. struct esp_hidh_dev_report_s *next;
  32. uint8_t map_index; //the index of the report map
  33. uint8_t report_id; //the id of the report
  34. uint8_t report_type; //input, output or feature
  35. uint8_t protocol_mode; //boot or report
  36. size_t value_len; //maximum len of value by report map
  37. esp_hid_usage_t usage; //generic, keyboard or mouse
  38. //BLE properties
  39. uint16_t handle; //handle to the value
  40. uint16_t ccc_handle; //handle to client config
  41. uint8_t permissions; //report permissions
  42. } esp_hidh_dev_report_t;
  43. /**
  44. * @brief HIDH device data
  45. */
  46. struct esp_hidh_dev_s {
  47. struct esp_hidh_dev_s *next;
  48. esp_hid_device_config_t config;
  49. esp_hid_usage_t usage;
  50. esp_hid_transport_t transport; //BT, BLE or USB
  51. bool connected; //we have all required data to communicate
  52. bool opened; //we opened the device manually, else the device connected to us
  53. int status; //status of the last command
  54. size_t reports_len;
  55. esp_hidh_dev_report_t *reports;
  56. void *tmp;
  57. size_t tmp_len;
  58. xSemaphoreHandle semaphore;
  59. esp_err_t (*close) (esp_hidh_dev_t *dev);
  60. esp_err_t (*report_write) (esp_hidh_dev_t *dev, size_t map_index, size_t report_id, int report_type, uint8_t *data, size_t len);
  61. esp_err_t (*report_read) (esp_hidh_dev_t *dev, size_t map_index, size_t report_id, int report_type, size_t max_length, uint8_t *value, size_t *value_len);
  62. void (*dump) (esp_hidh_dev_t *dev, FILE *fp);
  63. #if CONFIG_BLUEDROID_ENABLED
  64. esp_bd_addr_t bda;
  65. #endif /* CONFIG_BLUEDROID_ENABLED */
  66. union {
  67. #if CONFIG_BT_HID_HOST_ENABLED
  68. struct {
  69. esp_bt_cod_t cod;
  70. int handle;
  71. uint8_t sub_class;
  72. uint8_t app_id;
  73. uint16_t attr_mask;
  74. } bt;
  75. #endif /* CONFIG_BT_HID_HOST_ENABLED */
  76. #if CONFIG_GATTC_ENABLE
  77. struct {
  78. esp_ble_addr_type_t address_type;
  79. int conn_id;
  80. uint16_t appearance;
  81. uint16_t battery_handle;
  82. uint16_t battery_ccc_handle;
  83. } ble;
  84. #endif /* CONFIG_GATTC_ENABLE */
  85. };
  86. TAILQ_ENTRY(esp_hidh_dev_s) devices;
  87. };
  88. typedef TAILQ_HEAD(esp_hidh_dev_head_s, esp_hidh_dev_s) esp_hidh_dev_head_t;
  89. esp_hidh_dev_t *esp_hidh_dev_malloc(void);
  90. #if CONFIG_BLUEDROID_ENABLED
  91. esp_hidh_dev_t *esp_hidh_dev_get_by_bda(esp_bd_addr_t bda); //BT/BLE
  92. esp_hidh_dev_t *esp_hidh_dev_get_by_handle(int handle); //BT Only
  93. esp_hidh_dev_t *esp_hidh_dev_get_by_conn_id(uint16_t conn_id); //BLE Only
  94. #endif /* CONFIG_BLUEDROID_ENABLED */
  95. esp_hidh_dev_report_t *esp_hidh_dev_get_report_by_id_and_type(esp_hidh_dev_t *dev, size_t map_index, size_t report_id, int report_type);
  96. esp_hidh_dev_report_t *esp_hidh_dev_get_input_report_by_id_and_proto(esp_hidh_dev_t *dev, size_t report_id, int protocol_mode);
  97. esp_hidh_dev_report_t *esp_hidh_dev_get_report_by_handle(esp_hidh_dev_t *dev, uint16_t handle); //BLE Only
  98. #ifdef __cplusplus
  99. }
  100. #endif
  101. #endif /* _ESP_HIDH_PRIVATE_H_ */