Prvni ulozeni z chegewara githubu

This commit is contained in:
2023-02-25 16:13:53 +01:00
commit 01eb80dfe2
3279 changed files with 638407 additions and 0 deletions

View File

@ -0,0 +1,272 @@
// Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include <stdio.h>
/* HID Report Map Values */
#define HID_RM_INPUT 0x80
#define HID_RM_OUTPUT 0x90
#define HID_RM_FEATURE 0xb0
#define HID_RM_COLLECTION 0xa0
#define HID_RM_END_COLLECTION 0xc0
#define HID_RM_USAGE_PAGE 0x04
#define HID_RM_LOGICAL_MINIMUM 0x14
#define HID_RM_LOGICAL_MAXIMUM 0x24
#define HID_RM_PHYSICAL_MINIMUM 0x34
#define HID_RM_PHYSICAL_MAXIMUM 0x44
#define HID_RM_UNIT_EXPONENT 0x54
#define HID_RM_UNIT 0x64
#define HID_RM_REPORT_SIZE 0x74
#define HID_RM_REPORT_ID 0x84
#define HID_RM_REPORT_COUNT 0x94
#define HID_RM_PUSH 0xa4
#define HID_RM_POP 0xb4
#define HID_RM_USAGE 0x08
#define HID_RM_USAGE_MINIMUM 0x18
#define HID_RM_USAGE_MAXIMUM 0x28
#define HID_RM_DESIGNATOR_INDEX 0x38
#define HID_RM_DESIGNATOR_MINIMUM 0x48
#define HID_RM_DESIGNATOR_MAXIMUM 0x58
#define HID_RM_STRING_INDEX 0x78
#define HID_RM_STRING_MINIMUM 0x88
#define HID_RM_STRING_MAXIMUM 0x98
#define HID_RM_DELIMITER 0xa8
/* HID Usage Pages and Usages */
#define HID_USAGE_PAGE_GENERIC_DESKTOP 0x01
#define HID_USAGE_KEYBOARD 0x06
#define HID_USAGE_MOUSE 0x02
#define HID_USAGE_JOYSTICK 0x04
#define HID_USAGE_GAMEPAD 0x05
#define HID_USAGE_PAGE_CONSUMER_DEVICE 0x0C
#define HID_USAGE_CONSUMER_CONTROL 0x01
/* HID BT COD Peripheral Min Values Main Role */
#define ESP_HID_COD_MIN_KEYBOARD 0x10
#define ESP_HID_COD_MIN_MOUSE 0x20
/* HID BLE Appearances */
#define ESP_HID_APPEARANCE_GENERIC 0x03C0
#define ESP_HID_APPEARANCE_KEYBOARD 0x03C1
#define ESP_HID_APPEARANCE_MOUSE 0x03C2
#define ESP_HID_APPEARANCE_JOYSTICK 0x03C3
#define ESP_HID_APPEARANCE_GAMEPAD 0x03C4
/* HID Report Types */
#define ESP_HID_REPORT_TYPE_INPUT 1
#define ESP_HID_REPORT_TYPE_OUTPUT 2
#define ESP_HID_REPORT_TYPE_FEATURE 3
/* HID Protocol Modes */
#define ESP_HID_PROTOCOL_MODE_BOOT 0x00 // Boot Protocol Mode
#define ESP_HID_PROTOCOL_MODE_REPORT 0x01 // Report Protocol Mode
/* HID information flags */
#define ESP_HID_FLAGS_REMOTE_WAKE 0x01 // RemoteWake
#define ESP_HID_FLAGS_NORMALLY_CONNECTABLE 0x02 // NormallyConnectable
/* Control point commands */
#define ESP_HID_CONTROL_SUSPEND 0x00 // Suspend
#define ESP_HID_CONTROL_EXIT_SUSPEND 0x01 // Exit Suspend
/* Client Characteristic Configuration values */
#define ESP_HID_CCC_NOTIFICATIONS_ENABLED 0x01 // Notifications enabled
#define ESP_HID_CCC_INDICATIONS_ENABLED 0x02 // Indications enabled
/* HID Transports */
typedef enum {
ESP_HID_TRANSPORT_BT,
ESP_HID_TRANSPORT_BLE,
ESP_HID_TRANSPORT_USB,
ESP_HID_TRANSPORT_MAX
} esp_hid_transport_t;
/* HID Usage Types */
typedef enum {
ESP_HID_USAGE_GENERIC = 0,
ESP_HID_USAGE_KEYBOARD = 1,
ESP_HID_USAGE_MOUSE = 2,
ESP_HID_USAGE_JOYSTICK = 4,
ESP_HID_USAGE_GAMEPAD = 8,
ESP_HID_USAGE_TABLET = 16,
ESP_HID_USAGE_CCONTROL = 32,
ESP_HID_USAGE_VENDOR = 64
} esp_hid_usage_t;
/* HID BT COD Peripheral Min Values. Mask of (keyboard|mouse|ESP_HIDH_COD_*) */
typedef enum {
ESP_HID_COD_MIN_GENERIC,
ESP_HID_COD_MIN_JOYSTICK,
ESP_HID_COD_MIN_GAMEPAD,
ESP_HID_COD_MIN_REMOTE,
ESP_HID_COD_MIN_SENSOR,
ESP_HID_COD_MIN_TABLET,
ESP_HID_COD_MIN_CARD_READER,
ESP_HID_COD_MIN_MAX
} esp_hid_cod_min_t;
/* HID transaction Types */
typedef enum {
ESP_HID_TRANS_HANDSHAKE = 0,
ESP_HID_TRANS_CONTROL = 1,
ESP_HID_TRANS_GET_REPORT = 4,
ESP_HID_TRANS_SET_REPORT = 5,
ESP_HID_TRANS_GET_PROTOCOL = 6,
ESP_HID_TRANS_SET_PROTOCOL = 7,
ESP_HID_TRANS_GET_IDLE = 8,
ESP_HID_TRANS_SET_IDLE = 9,
ESP_HID_TRANS_DATA = 10,
ESP_HID_TRANS_DATAC = 11,
ESP_HID_TRANS_MAX
} esp_hid_trans_type_t;
/**
* @brief HID report item structure
*/
typedef struct {
uint8_t map_index; /*!< HID report map index */
uint8_t report_id; /*!< HID report id */
uint8_t report_type; /*!< HID report type */
uint8_t protocol_mode; /*!< HID protocol mode */
esp_hid_usage_t usage; /*!< HID usage type */
uint16_t value_len; /*!< HID report length in bytes */
} esp_hid_report_item_t;
/**
* @brief HID parsed report map structure
*/
typedef struct {
esp_hid_usage_t usage; /*!< Dominant HID usage. (keyboard > mouse > joystick > gamepad > generic) */
uint16_t appearance; /*!< Calculated HID Appearance based on the dominant usage */
uint8_t reports_len; /*!< Number of reports discovered in the report map */
esp_hid_report_item_t *reports; /*!< Reports discovered in the report map */
} esp_hid_report_map_t;
/**
* @brief HID raw report map structure
*/
typedef struct {
const uint8_t *data; /*!< Pointer to the HID report map data */
uint16_t len; /*!< HID report map data length */
} esp_hid_raw_report_map_t;
/**
* @brief HID device config structure
*/
typedef struct {
uint16_t vendor_id; /*!< HID Vendor ID */
uint16_t product_id; /*!< HID Product ID */
uint16_t version; /*!< HID Product Version */
const char *device_name; /*!< HID Device Name */
const char *manufacturer_name; /*!< HID Manufacturer */
const char *serial_number; /*!< HID Serial Number */
esp_hid_raw_report_map_t *report_maps; /*!< Array of the raw HID report maps */
uint8_t report_maps_len; /*!< number of raw report maps in the array */
} esp_hid_device_config_t;
/*
* @brief Parse RAW HID report map
* It is a responsibility of the user to free the parsed report map,
* when it's no longer needed. Use esp_hid_free_report_map
* @param hid_rm : pointer to the hid report map data
* @param hid_rm_len : length to the hid report map data
*
* @return: pointer to the parsed report map
*/
esp_hid_report_map_t *esp_hid_parse_report_map(const uint8_t *hid_rm, size_t hid_rm_len);
/*
* @brief Free parsed HID report map
* @param map : pointer to the parsed hid report map
*/
void esp_hid_free_report_map(esp_hid_report_map_t *map);
/**
* @brief Calculate the HID Device usage type from the BLE Apperance
* @param appearance : BLE Apperance value
*
* @return: the hid usage type
*/
esp_hid_usage_t esp_hid_usage_from_appearance(uint16_t appearance);
/**
* @brief Calculate the HID Device usage type from the BT CoD
* @param cod : BT CoD value
*
* @return: the hid usage type
*/
esp_hid_usage_t esp_hid_usage_from_cod(uint32_t cod);
/**
* @brief Convert device usage type to string
* @param usage : The HID usage type to convert
*
* @return: a pointer to the string or NULL
*/
const char *esp_hid_usage_str(esp_hid_usage_t usage);
/**
* @brief Convert HID protocol mode to string
* @param protocol_mode : The HID protocol mode to convert
* BOOT/REPORT
*
* @return: a pointer to the string or NULL
*/
const char *esp_hid_protocol_mode_str(uint8_t protocol_mode);
/**
* @brief Convert HID report type to string
* @param report_type : The HID report type to convert
* INPUT/OUTPUT/FEATURE
*
* @return: a pointer to the string or NULL
*/
const char *esp_hid_report_type_str(uint8_t report_type);
/**
* @brief Convert BT CoD major to string
* @param cod_major : The CoD major value to convert
*
* @return: a pointer to the string or NULL
*/
const char *esp_hid_cod_major_str(uint8_t cod_major);
/**
* @brief Print BT CoD minor value
* @param cod_min : The CoD minor value to print
* @param fp : pointer to the output file
*/
void esp_hid_cod_minor_print(uint8_t cod_min, FILE *fp);
/**
* @brief Convert BLE disconnect reason to string
* @param reason : The value of the reason
*
* @return: a pointer to the string or NULL
*/
const char *esp_hid_disconnect_reason_str(esp_hid_transport_t transport, int reason);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,226 @@
// Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include "sdkconfig.h"
#include "esp_err.h"
#include "esp_event.h"
#include "esp_hid_common.h"
#ifdef __cplusplus
extern "C" {
#endif
#include "esp_hidd_transport.h"
ESP_EVENT_DECLARE_BASE(ESP_HIDD_EVENTS); // Declare the event base for HID device
/**
* @brief HIDD callback events enum
*/
typedef enum {
ESP_HIDD_ANY_EVENT = ESP_EVENT_ANY_ID, /*!< HID device any event */
ESP_HIDD_START_EVENT = 0, /*!< HID device stack started */
ESP_HIDD_CONNECT_EVENT, /*!< HID device connected */
ESP_HIDD_PROTOCOL_MODE_EVENT, /*!< HID device protocol mode change */
ESP_HIDD_CONTROL_EVENT, /*!< HID device control request */
ESP_HIDD_OUTPUT_EVENT, /*!< HID device output report event */
ESP_HIDD_FEATURE_EVENT, /*!< HID device feature report event */
ESP_HIDD_DISCONNECT_EVENT, /*!< HID device disconnected */
ESP_HIDD_STOP_EVENT, /*!< HID device stack stopped */
ESP_HIDD_MAX_EVENT, /*!< HID events end marker */
} esp_hidd_event_t;
/**
* @brief HIDD structure forward declaration
*/
struct esp_hidd_dev_s;
typedef struct esp_hidd_dev_s esp_hidd_dev_t;
/**
* @brief HIDD callback parameters union
*/
typedef union {
/**
* @brief ESP_HIDD_START_EVENT
* @note Used only for Classic Bluetooth.
*/
struct {
esp_err_t status; /*!< HID device operation status */
} start; /*!< HID callback param of ESP_HIDD_START_EVENT */
/**
* @brief ESP_HIDD_STOP_EVENT
* @note Used only for Classic Bluetooth.
*/
struct {
esp_err_t status; /*!< HID device operation status */
} stop; /*!< HID callback param of ESP_HIDD_STOP_EVENT */
/**
* @brief ESP_HIDD_CONNECT_EVENT
*/
struct {
esp_hidd_dev_t *dev; /*!< HID device structure */
esp_err_t status; /*!< HID device operation status, used only for Classic Bluetooth */
} connect; /*!< HID callback param of ESP_HIDD_CONNECT_EVENT */
/**
* @brief ESP_HIDD_DISCONNECT_EVENT
*/
struct {
esp_hidd_dev_t *dev; /*!< HID device structure */
int reason; /*!< Indicate the reason of disconnection */
esp_err_t status; /*!< HID device operation status, used only for Classic Bluetooth */
} disconnect; /*!< HID callback param of ESP_HIDD_DISCONNECT_EVENT */
/**
* @brief ESP_HIDD_OUTPUT_EVENT
*/
struct {
esp_hidd_dev_t *dev; /*!< HID device structure */
esp_hid_usage_t usage; /*!< HID report usage */
uint16_t report_id; /*!< HID report index */
uint16_t length; /*!< data length */
uint8_t *data; /*!< The pointer to the data */
uint8_t map_index; /*!< HID config report map index */
} output; /*!< HID callback param of ESP_HIDD_OUTPUT_EVENT */
/**
* @brief ESP_HIDD_FEATURE_EVENT
*/
struct {
esp_hidd_dev_t *dev; /*!< HID device structure */
esp_hid_usage_t usage; /*!< HID report usage */
uint16_t report_id; /*!< HID report index */
uint16_t length; /*!< data length */
uint8_t *data; /*!< The pointer to the data */
uint8_t map_index; /*!< HID config report map index */
uint8_t trans_type; /*!< HID device feature transaction type, used only for Classic Bluetooth */
uint8_t report_type; /*!< HID device feature report type, used only for Classic Bluetooth */
} feature; /*!< HID callback param of ESP_HIDD_FEATURE_EVENT */
/**
* @brief ESP_HIDD_PROTOCOL_MODE_EVENT
*/
struct {
esp_hidd_dev_t *dev; /*!< HID device structure */
uint8_t protocol_mode; /*!< HID Protocol Mode */
uint8_t map_index; /*!< HID config report map index */
} protocol_mode; /*!< HID callback param of ESP_HIDD_PROTOCOL_MODE_EVENT */
/**
* @brief ESP_HIDD_CONTROL_EVENT
*/
struct {
esp_hidd_dev_t *dev; /*!< HID device structure */
uint8_t control; /*!< HID Control Point */
uint8_t map_index; /*!< HID config report map index */
} control; /*!< HID callback param of ESP_HIDD_CONTROL_EVENT */
} esp_hidd_event_data_t;
/**
* @brief Init HID Device
* @param config : configuration for the device
* @param transport: protocol that the device will use (ESP_HID_TRANSPORT_BLE/BT/USB)
* @param callback : function to call when events for this device are generated.
* Can be NULL, but will miss the START event.
* @param[out] dev : location to return the pointer to the device structure
*
* @return: ESP_OK on success
*/
esp_err_t esp_hidd_dev_init(const esp_hid_device_config_t *config, esp_hid_transport_t transport, esp_event_handler_t callback, esp_hidd_dev_t **dev);
/**
* @brief Deinit HID Device
* @param dev : pointer to the device to deinit
*
* @return: ESP_OK on success
*/
esp_err_t esp_hidd_dev_deinit(esp_hidd_dev_t *dev);
/**
* @brief Get the HID Device Transport
* @param dev : pointer to the HID Device
*
* @return: the transport of the connected device or ESP_HID_TRANSPORT_MAX
*/
esp_hid_transport_t esp_hidd_dev_transport_get(esp_hidd_dev_t *dev);
/**
* @brief Check if HID Device is connected
* @param dev : pointer to the device
*
* @return: true if the device is connected
*/
bool esp_hidd_dev_connected(esp_hidd_dev_t *dev);
/**
* @brief Set the battery level reported by the HID Device
* @param dev : pointer to the device
* @param level : battery level (0-100)
*
* @return: ESP_OK on success
*/
esp_err_t esp_hidd_dev_battery_set(esp_hidd_dev_t *dev, uint8_t level);
/**
* @brief Send an INPUT report to the host
* @param dev : pointer to the device
* @param map_index : index of the device report map in the init config
* @param report_id : id of the HID INPUT report
* @param data : pointer to the data to send
* @param length : length of the data to send
*
* @return: ESP_OK on success
*/
esp_err_t esp_hidd_dev_input_set(esp_hidd_dev_t *dev, size_t map_index, size_t report_id, uint8_t *data, size_t length);
/**
* @brief Send a FEATURE report to the host
* @param dev : pointer to the device
* @param map_index : index of the device report map in the init config
* @param report_id : id of the HID FEATURE report
* @param data : pointer to the data to send
* @param length : length of the data to send
*
* @return: ESP_OK on success
*/
esp_err_t esp_hidd_dev_feature_set(esp_hidd_dev_t *dev, size_t map_index, size_t report_id, uint8_t *data, size_t length);
/**
* @brief Register function to listen for device events
* @param dev : pointer to the device
* @param callback : event handler function
* @param event : event to listen for (ESP_HIDD_ANY_EVENT for all)
*
* @return: ESP_OK on success
*/
esp_err_t esp_hidd_dev_event_handler_register(esp_hidd_dev_t *dev, esp_event_handler_t callback, esp_hidd_event_t event);
/**
* @brief Unregister function that is listening for device events
* @param dev : pointer to the device
* @param callback : event handler function
* @param event : event that is listening for (ESP_HIDD_ANY_EVENT for all)
*
* @return: ESP_OK on success
*/
esp_err_t esp_hidd_dev_event_handler_unregister(esp_hidd_dev_t *dev, esp_event_handler_t callback, esp_hidd_event_t event);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,40 @@
// Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "sdkconfig.h"
#if CONFIG_GATTS_ENABLE
#include "esp_gatts_api.h" //for the callback
/**
* @brief HID BLE GATTS System Callback. Attach it in your code
* or call it from your gatts event handler to allow the HID stack to function
* @param event : Event type
* @param gatts_if : GATTS Interface ID
* @param param : Point to callback parameter, currently is union type
*/
void esp_hidd_gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param);
#endif /* CONFIG_GATTS_ENABLE */
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,31 @@
// Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "sdkconfig.h"
#if CONFIG_GATTS_ENABLE
#include "esp_hidd_gatts.h"
#else
typedef int esp_gatt_conn_reason_t;
#endif /* CONFIG_GATTS_ENABLE */
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,400 @@
// Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include "sdkconfig.h"
#include "esp_err.h"
#include "esp_log.h"
#include "esp_event.h"
#include "esp_hid_common.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief HIDH structure forward declaration
*/
struct esp_hidh_dev_s;
typedef struct esp_hidh_dev_s esp_hidh_dev_t;
ESP_EVENT_DECLARE_BASE(ESP_HIDH_EVENTS);
/**
* @brief HIDH callback events enum
*/
typedef enum {
ESP_HIDH_ANY_EVENT = ESP_EVENT_ANY_ID, /*!< HID device any event */
ESP_HIDH_OPEN_EVENT = 0, /*!< HID device opened */
ESP_HIDH_BATTERY_EVENT, /*!< HID device battery level changed */
ESP_HIDH_INPUT_EVENT, /*!< Received HID device INPUT report */
ESP_HIDH_FEATURE_EVENT, /*!< Received HID device FEATURE report */
ESP_HIDH_CLOSE_EVENT, /*!< HID device closed */
ESP_HIDH_START_EVENT, /*!< HID host stack started, used only for Classic Bluetooth */
ESP_HIDH_STOP_EVENT, /*!< HID host stack stopped, used only for Classic Bluetooth */
ESP_HIDH_MAX_EVENT, /*!< HID events end marker */
} esp_hidh_event_t;
/**
* @brief HIDH callback parameters union
*/
typedef union {
/**
* @brief ESP_HIDH_START_EVENT
* @note Used only for Classic Bluetooth.
*/
struct {
esp_err_t status; /*!< HID host operation status */
} start; /*!< HID callback param of ESP_HIDH_START_EVENT */
/**
* @brief ESP_HIDH_STOP_EVENT
* @note Used only for Classic Bluetooth.
*/
struct {
esp_err_t status; /*!< HID host operation status */
} stop; /*!< HID callback param of ESP_HIDH_STOP_EVENT */
/**
* @brief ESP_HIDH_OPEN_EVENT
*/
struct {
esp_hidh_dev_t *dev; /*!< HID Remote bluetooth device */
esp_err_t status; /*!< HID host operation status, used only for Classic Bluetooth */
} open; /*!< HID callback param of ESP_HIDH_OPEN_EVENT */
/**
* @brief ESP_HIDH_CLOSE_EVENT
*/
struct {
esp_hidh_dev_t *dev; /*!< HID Remote bluetooth device. */
int reason; /*!< Reason why the connection was closed. BLE Only */
esp_err_t status; /*!< HID host operation status, used only for Classic Bluetooth */
} close; /*!< HID callback param of ESP_HIDH_CLOSE_EVENT */
/**
* @brief ESP_HIDH_BATTERY_EVENT
*/
struct {
esp_hidh_dev_t *dev; /*!< HID Remote bluetooth device */
uint8_t level; /*!< Battery Level (0-100%) */
esp_err_t status; /*!< HID host operation status */
} battery; /*!< HID callback param of ESP_HIDH_BATTERY_EVENT */
/**
* @brief ESP_HIDH_INPUT_EVENT
*/
struct {
esp_hidh_dev_t *dev; /*!< HID Remote bluetooth device */
esp_hid_usage_t usage; /*!< HID report usage */
uint16_t report_id; /*!< HID report index */
uint16_t length; /*!< HID data length */
uint8_t *data; /*!< The pointer to the HID data */
uint8_t map_index; /*!< HID report map index */
} input; /*!< HID callback param of ESP_HIDH_INPUT_EVENT */
/**
* @brief ESP_HIDH_FEATURE_EVENT
*/
struct {
esp_hidh_dev_t *dev; /*!< HID Remote bluetooth device */
esp_hid_usage_t usage; /*!< HID report usage */
uint16_t report_id; /*!< HID report index */
uint16_t length; /*!< HID data length */
uint8_t *data; /*!< The pointer to the HID data */
uint8_t map_index; /*!< HID report map index */
esp_err_t status; /*!< HID host operation status, used only for Classic Bluetooth */
esp_hid_trans_type_t trans_type; /*!< HID host feature transaction type, used only for Classic Bluetooth */
} feature; /*!< HID callback param of ESP_HIDH_FEATURE_EVENT */
} esp_hidh_event_data_t;
typedef struct {
esp_event_handler_t callback;
uint16_t event_stack_size;
void *callback_arg;
} esp_hidh_config_t;
/**
* @brief Initialize the HID Host component
* @param config : pointer to esp_hidh_config_t structure
*
* @return: ESP_OK on success
*/
esp_err_t esp_hidh_init(const esp_hidh_config_t *config);
/**
* @brief De-initialize the HID Host component
*
* @return: ESP_OK on success
*/
esp_err_t esp_hidh_deinit(void);
/**
* @brief Close HID Device
* @param dev : pointer to the device
*
* @return: ESP_OK on success
*/
esp_err_t esp_hidh_dev_close(esp_hidh_dev_t *dev);
/**
* @brief Free HID Device Memory
* This function MUST be called when handling ESP_HIDH_CLOSE_EVENT
* Only then all memory used for the device will be freed.
* @param dev : pointer to the device
*
* @return: ESP_OK on success
*/
esp_err_t esp_hidh_dev_free(esp_hidh_dev_t *dev);
/**
* @brief Check if the device still exists.
* @param dev : pointer to the device
*
* @return: true if exists
*/
bool esp_hidh_dev_exists(esp_hidh_dev_t *dev);
/**
* @brief Send an OUTPUT report to the device
* @param dev : pointer to the device
* @param map_index : index of the device report map
* @param report_id : id of the HID OUTPUT report
* @param data : pointer to the data to send
* @param length : length of the data to send
*
* @return: ESP_OK on success
*/
esp_err_t esp_hidh_dev_output_set(esp_hidh_dev_t *dev, size_t map_index, size_t report_id, uint8_t *data, size_t length);
/**
* @brief Send a FEATURE report to the device
* @param dev : pointer to the device
* @param map_index : index of the device report map
* @param report_id : id of the HID FEATURE report
* @param data : pointer to the data to send
* @param length : length of the data to send
*
* @return: ESP_OK on success
*/
esp_err_t esp_hidh_dev_feature_set(esp_hidh_dev_t *dev, size_t map_index, size_t report_id, uint8_t *data, size_t length);
/**
* @brief Get the value a FEATURE report from the device
* @param dev : pointer to the device
* @param map_index : index of the device report map
* @param report_id : id of the HID FEATURE report
* @param max_len : size of the buffer that will hold the data
* @param data : pointer to the data buffer
* @param length : pointer to the value that will be set to the number of bytes received
*
* @return: ESP_OK on success
*/
esp_err_t esp_hidh_dev_feature_get(esp_hidh_dev_t *dev, size_t map_index, size_t report_id, size_t max_len, uint8_t *data, size_t *length);
/**
* @brief Set_Report command.
* @note For now, this function used only for Classic Bluetooth.
*
* @param dev : pointer to the device
* @param map_index : index of the device report map
* @param report_id : id of the HID FEATURE report
* @param report_type : report type, defines in `esp_hid_common.h`
* @param data : pointer to the data to send
* @param length : length of the data to send
*
* @return: ESP_OK on success
*/
esp_err_t esp_hidh_dev_set_report(esp_hidh_dev_t *dev, size_t map_index, size_t report_id, int report_type,
uint8_t *data, size_t length);
/**
* @brief Get_Report command.
* @note For now, this function used only for Classic Bluetooth.
*
* @param dev : pointer to the device
* @param map_index : index of the device report map
* @param report_id : id of the HID FEATURE report
* @param report_type : report type, defines in `esp_hid_common.h`
* @param max_len : size of the buffer that will hold the data
*
* @return: ESP_OK on success
*/
esp_err_t esp_hidh_dev_get_report(esp_hidh_dev_t *dev, size_t map_index, size_t report_id, int report_type,
size_t max_len);
/**
* @brief Get_Idle Command.
* @note For now, this function used only for Classic Bluetooth.
*
* @param dev : pointer to the device
*
* @return: ESP_OK on success
*/
esp_err_t esp_hidh_dev_get_idle(esp_hidh_dev_t *dev);
/**
* @brief Set_Idle Command.
* @note For now, this function used only for Classic Bluetooth.
*
* @param dev : pointer to the device
* @param idle_time : idle_time
*
* @return: ESP_OK on success
*/
esp_err_t esp_hidh_dev_set_idle(esp_hidh_dev_t *dev, uint8_t idle_time);
/**
* @brief Get_Protocol Command.
* @note For now, this function used only for Classic Bluetooth.
*
* @param dev : pointer to the device
*
* @return: ESP_OK on success
*/
esp_err_t esp_hidh_dev_get_protocol(esp_hidh_dev_t *dev);
/**
* @brief Set_Protocol Command.
* @note For now, this function used only for Classic Bluetooth.
*
* @param dev : pointer to the device
* @param protocol_mode : protocol_mode
*
* @return: ESP_OK on success
*/
esp_err_t esp_hidh_dev_set_protocol(esp_hidh_dev_t *dev, uint8_t protocol_mode);
/**
* @brief Dump the properties of HID Device to UART
* @param dev : pointer to the HID Device
* @param fp : pointer to the output file
*/
void esp_hidh_dev_dump(esp_hidh_dev_t *dev, FILE *fp);
/**
* @brief Get the BT Device Address of a HID Device
* @param dev : pointer to the HID Device
*
* @return: pointer to the BDA byte array or NULL
*/
const uint8_t *esp_hidh_dev_bda_get(esp_hidh_dev_t *dev);
/**
* @brief Get the HID Device Transport
* @param dev : pointer to the HID Device
*
* @return: the transport of the connected device or ESP_HID_TRANSPORT_MAX
*/
esp_hid_transport_t esp_hidh_dev_transport_get(esp_hidh_dev_t *dev);
/**
* @brief Get the HID Device Cofiguration
* @param dev : pointer to the HID Device
*
* @return: pointer to the config structure or NULL
*/
const esp_hid_device_config_t *esp_hidh_dev_config_get(esp_hidh_dev_t *dev);
/**
* @brief Get the name of a HID Device
* @param dev : pointer to the HID Device
*
* @return: pointer to the character array or NULL
*/
const char *esp_hidh_dev_name_get(esp_hidh_dev_t *dev);
/**
* @brief Get the manufacturer of a HID Device
* @param dev : pointer to the HID Device
*
* @return: pointer to the character array
*/
const char *esp_hidh_dev_manufacturer_get(esp_hidh_dev_t *dev);
/**
* @brief Get the serial number of a HID Device
* @param dev : pointer to the HID Device
*
* @return: pointer to the character array or NULL
*/
const char *esp_hidh_dev_serial_get(esp_hidh_dev_t *dev);
/**
* @brief Get the VID of a HID Device
* @param dev : pointer to the HID Device
*
* @return: the VID value
*/
uint16_t esp_hidh_dev_vendor_id_get(esp_hidh_dev_t *dev);
/**
* @brief Get the PID of a HID Device
* @param dev : pointer to the HID Device
*
* @return: the PID value
*/
uint16_t esp_hidh_dev_product_id_get(esp_hidh_dev_t *dev);
/**
* @brief Get the version HID Device
* @param dev : pointer to the HID Device
*
* @return: the version value
*/
uint16_t esp_hidh_dev_version_get(esp_hidh_dev_t *dev);
/**
* @brief Get the appearance of BLE HID Device
* @param dev : pointer to the BLE HID Device
*
* @return: the appearance value
*/
uint16_t esp_hidh_dev_appearance_get(esp_hidh_dev_t *dev); //BLE Only
/**
* @brief Get the calculated HID Device usage type
* @param dev : pointer to the HID Device
*
* @return: the hid usage type
*/
esp_hid_usage_t esp_hidh_dev_usage_get(esp_hidh_dev_t *dev);
/**
* @brief Get an array of all reports found on a device
* @param dev : pointer to the device
* @param num_reports : pointer to the value that will be set to the number of reports
* @param reports : location to set to the pointer of the reports array
*
* @return: ESP_OK on success
*/
esp_err_t esp_hidh_dev_reports_get(esp_hidh_dev_t *dev, size_t *num_reports, esp_hid_report_item_t **reports);
/**
* @brief Get an array of the report maps found on a device
* @param dev : pointer to the device
* @param num_maps : pointer to the value that will be set to the number of report maps found
* @param maps : location to set to the pointer of the report maps array
*
* @return: ESP_OK on success
*/
esp_err_t esp_hidh_dev_report_maps_get(esp_hidh_dev_t *dev, size_t *num_maps, esp_hid_raw_report_map_t **maps);
#include "esp_hidh_transport.h"
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,41 @@
// Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "sdkconfig.h"
#if CONFIG_BLUEDROID_ENABLED
#include "esp_bt_defs.h"
/**
* @brief Open BlueTooth HID Device using BlueDroid
* @param bda : BT Device Address
* @param transport : BT Device Protocol (Classic/HID)
* @param remote_addr_type : BLE Remote address type
*
* @return: ESP_OK on success
*/
esp_hidh_dev_t *esp_hidh_dev_open(esp_bd_addr_t bda, esp_hid_transport_t transport, uint8_t remote_addr_type);
#endif /* CONFIG_BLUEDROID_ENABLED */
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,40 @@
// Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "sdkconfig.h"
#if CONFIG_GATTC_ENABLE
#include "esp_gattc_api.h" //for the callback
/**
* @brief HID BLE GATTC System Callback. Attach it in your code
* or call it from your gattc event handler to allow the HID stack to function
* @param event : Event type
* @param gattc_if : GATTC Interface ID
* @param param : Point to callback parameter, currently is union type
*/
void esp_hidh_gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param);
#endif /* CONFIG_GATTC_ENABLE */
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,33 @@
// Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "sdkconfig.h"
#if CONFIG_GATTC_ENABLE
#include "esp_hidh_gattc.h"
#endif
#if CONFIG_BLUEDROID_ENABLED
#include "esp_hidh_bluedroid.h"
#endif
#ifdef __cplusplus
}
#endif