rename subfolder source to src
This commit is contained in:
595
src/class/hid/hid.h
Normal file
595
src/class/hid/hid.h
Normal file
@@ -0,0 +1,595 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file hid.h
|
||||
@author hathach (tinyusb.org)
|
||||
|
||||
@section LICENSE
|
||||
|
||||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2013, hathach (tinyusb.org)
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holders nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This file is part of the tinyusb stack.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
|
||||
/** \ingroup group_class
|
||||
* \defgroup ClassDriver_HID Human Interface Device (HID)
|
||||
* @{ */
|
||||
|
||||
#ifndef _TUSB_HID_H_
|
||||
#define _TUSB_HID_H_
|
||||
|
||||
#include "common/tusb_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Common Definitions
|
||||
//--------------------------------------------------------------------+
|
||||
/** \defgroup ClassDriver_HID_Common Common Definitions
|
||||
* @{ */
|
||||
|
||||
/// HID Subclass
|
||||
typedef enum
|
||||
{
|
||||
HID_SUBCLASS_NONE = 0, ///< No Subclass
|
||||
HID_SUBCLASS_BOOT = 1 ///< Boot Interface Subclass
|
||||
}hid_subclass_type_t;
|
||||
|
||||
/// HID Protocol
|
||||
typedef enum
|
||||
{
|
||||
HID_PROTOCOL_NONE = 0, ///< None
|
||||
HID_PROTOCOL_KEYBOARD = 1, ///< Keyboard
|
||||
HID_PROTOCOL_MOUSE = 2 ///< Mouse
|
||||
}hid_protocol_type_t;
|
||||
|
||||
/// HID Descriptor Type
|
||||
typedef enum
|
||||
{
|
||||
HID_DESC_TYPE_HID = 0x21, ///< HID Descriptor
|
||||
HID_DESC_TYPE_REPORT = 0x22, ///< Report Descriptor
|
||||
HID_DESC_TYPE_PHYSICAL = 0x23 ///< Physical Descriptor
|
||||
}hid_descriptor_type_t;
|
||||
|
||||
/// HID Request Report Type
|
||||
typedef enum
|
||||
{
|
||||
HID_REQUEST_REPORT_INPUT = 1, ///< Input
|
||||
HID_REQUEST_REPORT_OUTPUT, ///< Output
|
||||
HID_REQUEST_REPORT_FEATURE ///< Feature
|
||||
}hid_request_report_type_t;
|
||||
|
||||
/// HID Class Specific Control Request
|
||||
typedef enum
|
||||
{
|
||||
HID_REQUEST_CONTROL_GET_REPORT = 0x01, ///< Get Report
|
||||
HID_REQUEST_CONTROL_GET_IDLE = 0x02, ///< Get Idle
|
||||
HID_REQUEST_CONTROL_GET_PROTOCOL = 0x03, ///< Get Protocol
|
||||
HID_REQUEST_CONTROL_SET_REPORT = 0x09, ///< Set Report
|
||||
HID_REQUEST_CONTROL_SET_IDLE = 0x0a, ///< Set Idle
|
||||
HID_REQUEST_CONTROL_SET_PROTOCOL = 0x0b ///< Set Protocol
|
||||
}hid_request_type_t;
|
||||
|
||||
/// USB HID Descriptor
|
||||
typedef struct ATTR_PACKED
|
||||
{
|
||||
uint8_t bLength; /**< Numeric expression that is the total size of the HID descriptor */
|
||||
uint8_t bDescriptorType; /**< Constant name specifying type of HID descriptor. */
|
||||
|
||||
uint16_t bcdHID; /**< Numeric expression identifying the HID Class Specification release */
|
||||
uint8_t bCountryCode; /**< Numeric expression identifying country code of the localized hardware. */
|
||||
uint8_t bNumDescriptors; /**< Numeric expression specifying the number of class descriptors */
|
||||
|
||||
uint8_t bReportType; /**< Type of HID class report. */
|
||||
uint16_t wReportLength; /**< the total size of the Report descriptor. */
|
||||
} tusb_hid_descriptor_hid_t;
|
||||
|
||||
/// HID Country Code
|
||||
typedef enum
|
||||
{
|
||||
HID_Local_NotSupported = 0 , ///< NotSupported
|
||||
HID_Local_Arabic , ///< Arabic
|
||||
HID_Local_Belgian , ///< Belgian
|
||||
HID_Local_Canadian_Bilingual , ///< Canadian_Bilingual
|
||||
HID_Local_Canadian_French , ///< Canadian_French
|
||||
HID_Local_Czech_Republic , ///< Czech_Republic
|
||||
HID_Local_Danish , ///< Danish
|
||||
HID_Local_Finnish , ///< Finnish
|
||||
HID_Local_French , ///< French
|
||||
HID_Local_German , ///< German
|
||||
HID_Local_Greek , ///< Greek
|
||||
HID_Local_Hebrew , ///< Hebrew
|
||||
HID_Local_Hungary , ///< Hungary
|
||||
HID_Local_International , ///< International
|
||||
HID_Local_Italian , ///< Italian
|
||||
HID_Local_Japan_Katakana , ///< Japan_Katakana
|
||||
HID_Local_Korean , ///< Korean
|
||||
HID_Local_Latin_American , ///< Latin_American
|
||||
HID_Local_Netherlands_Dutch , ///< Netherlands/Dutch
|
||||
HID_Local_Norwegian , ///< Norwegian
|
||||
HID_Local_Persian_Farsi , ///< Persian (Farsi)
|
||||
HID_Local_Poland , ///< Poland
|
||||
HID_Local_Portuguese , ///< Portuguese
|
||||
HID_Local_Russia , ///< Russia
|
||||
HID_Local_Slovakia , ///< Slovakia
|
||||
HID_Local_Spanish , ///< Spanish
|
||||
HID_Local_Swedish , ///< Swedish
|
||||
HID_Local_Swiss_French , ///< Swiss/French
|
||||
HID_Local_Swiss_German , ///< Swiss/German
|
||||
HID_Local_Switzerland , ///< Switzerland
|
||||
HID_Local_Taiwan , ///< Taiwan
|
||||
HID_Local_Turkish_Q , ///< Turkish-Q
|
||||
HID_Local_UK , ///< UK
|
||||
HID_Local_US , ///< US
|
||||
HID_Local_Yugoslavia , ///< Yugoslavia
|
||||
HID_Local_Turkish_F ///< Turkish-F
|
||||
} hid_country_code_t;
|
||||
|
||||
/** @} */
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MOUSE
|
||||
//--------------------------------------------------------------------+
|
||||
/** \addtogroup ClassDriver_HID_Mouse Mouse
|
||||
* @{ */
|
||||
|
||||
/// Standard HID Boot Protocol Mouse Report.
|
||||
typedef struct ATTR_PACKED
|
||||
{
|
||||
uint8_t buttons; /**< buttons mask for currently pressed buttons in the mouse. */
|
||||
int8_t x; /**< Current delta x movement of the mouse. */
|
||||
int8_t y; /**< Current delta y movement on the mouse. */
|
||||
int8_t wheel; /**< Current delta wheel movement on the mouse. */
|
||||
} hid_mouse_report_t;
|
||||
|
||||
/// Standard Mouse Buttons Bitmap
|
||||
typedef enum
|
||||
{
|
||||
MOUSE_BUTTON_LEFT = BIT_(0), ///< Left button
|
||||
MOUSE_BUTTON_RIGHT = BIT_(1), ///< Right button
|
||||
MOUSE_BUTTON_MIDDLE = BIT_(2) ///< Middle button
|
||||
}hid_mouse_button_bm_t;
|
||||
|
||||
/// @}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Keyboard
|
||||
//--------------------------------------------------------------------+
|
||||
/** \addtogroup ClassDriver_HID_Keyboard Keyboard
|
||||
* @{ */
|
||||
|
||||
/// Standard HID Boot Protocol Keyboard Report.
|
||||
typedef struct ATTR_PACKED
|
||||
{
|
||||
uint8_t modifier; /**< Keyboard modifier byte, indicating pressed modifier keys (a combination of HID_KEYBOARD_MODIFER_* masks). */
|
||||
uint8_t reserved; /**< Reserved for OEM use, always set to 0. */
|
||||
uint8_t keycode[6]; /**< Key codes of the currently pressed keys. */
|
||||
} hid_keyboard_report_t;
|
||||
|
||||
/// Keyboard modifier codes bitmap
|
||||
typedef enum
|
||||
{
|
||||
KEYBOARD_MODIFIER_LEFTCTRL = BIT_(0), ///< Left Control
|
||||
KEYBOARD_MODIFIER_LEFTSHIFT = BIT_(1), ///< Left Shift
|
||||
KEYBOARD_MODIFIER_LEFTALT = BIT_(2), ///< Left Alt
|
||||
KEYBOARD_MODIFIER_LEFTGUI = BIT_(3), ///< Left Window
|
||||
KEYBOARD_MODIFIER_RIGHTCTRL = BIT_(4), ///< Right Control
|
||||
KEYBOARD_MODIFIER_RIGHTSHIFT = BIT_(5), ///< Right Shift
|
||||
KEYBOARD_MODIFIER_RIGHTALT = BIT_(6), ///< Right Alt
|
||||
KEYBOARD_MODIFIER_RIGHTGUI = BIT_(7) ///< Right Window
|
||||
}hid_keyboard_modifier_bm_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
KEYBOARD_LED_NUMLOCK = BIT_(0), ///< Num Lock LED
|
||||
KEYBOARD_LED_CAPSLOCK = BIT_(1), ///< Caps Lock LED
|
||||
KEYBOARD_LED_SCROLLLOCK = BIT_(2), ///< Scroll Lock LED
|
||||
KEYBOARD_LED_COMPOSE = BIT_(3), ///< Composition Mode
|
||||
KEYBOARD_LED_KANA = BIT_(4) ///< Kana mode
|
||||
}hid_keyboard_led_bm_t;
|
||||
|
||||
/// @}
|
||||
|
||||
#define HID_KEYCODE_TABLE(ENTRY) \
|
||||
ENTRY( 0x04, 'a' , 'A' )\
|
||||
ENTRY( 0x05, 'b' , 'B' )\
|
||||
ENTRY( 0x06, 'c' , 'C' )\
|
||||
ENTRY( 0x07, 'd' , 'D' )\
|
||||
ENTRY( 0x08, 'e' , 'E' )\
|
||||
ENTRY( 0x09, 'f' , 'F' )\
|
||||
ENTRY( 0x0a, 'g' , 'G' )\
|
||||
ENTRY( 0x0b, 'h' , 'H' )\
|
||||
ENTRY( 0x0c, 'i' , 'I' )\
|
||||
ENTRY( 0x0d, 'j' , 'J' )\
|
||||
ENTRY( 0x0e, 'k' , 'K' )\
|
||||
ENTRY( 0x0f, 'l' , 'L' )\
|
||||
ENTRY( 0x10, 'm' , 'M' )\
|
||||
ENTRY( 0x11, 'n' , 'N' )\
|
||||
ENTRY( 0x12, 'o' , 'O' )\
|
||||
ENTRY( 0x13, 'p' , 'P' )\
|
||||
ENTRY( 0x14, 'q' , 'Q' )\
|
||||
ENTRY( 0x15, 'r' , 'R' )\
|
||||
ENTRY( 0x16, 's' , 'S' )\
|
||||
ENTRY( 0x17, 't' , 'T' )\
|
||||
ENTRY( 0x18, 'u' , 'U' )\
|
||||
ENTRY( 0x19, 'v' , 'V' )\
|
||||
ENTRY( 0x1a, 'w' , 'W' )\
|
||||
ENTRY( 0x1b, 'x' , 'X' )\
|
||||
ENTRY( 0x1c, 'y' , 'Y' )\
|
||||
ENTRY( 0x1d, 'z' , 'Z' )\
|
||||
\
|
||||
ENTRY( 0x1e, '1' , '!' )\
|
||||
ENTRY( 0x1f, '2' , '@' )\
|
||||
ENTRY( 0x20, '3' , '#' )\
|
||||
ENTRY( 0x21, '4' , '$' )\
|
||||
ENTRY( 0x22, '5' , '%' )\
|
||||
ENTRY( 0x23, '6' , '^' )\
|
||||
ENTRY( 0x24, '7' , '&' )\
|
||||
ENTRY( 0x25, '8' , '*' )\
|
||||
ENTRY( 0x26, '9' , '(' )\
|
||||
ENTRY( 0x27, '0' , ')' )\
|
||||
\
|
||||
ENTRY( 0x28, '\r' , '\r' )\
|
||||
ENTRY( 0x29, '\x1b', '\x1b' )\
|
||||
ENTRY( 0x2a, '\b' , '\b' )\
|
||||
ENTRY( 0x2b, '\t' , '\t' )\
|
||||
ENTRY( 0x2c, ' ' , ' ' )\
|
||||
ENTRY( 0x2d, '-' , '_' )\
|
||||
ENTRY( 0x2e, '=' , '+' )\
|
||||
ENTRY( 0x2f, '[' , '{' )\
|
||||
ENTRY( 0x30, ']' , '}' )\
|
||||
ENTRY( 0x31, '\\' , '|' )\
|
||||
ENTRY( 0x32, '#' , '~' ) /* TODO non-US keyboard */ \
|
||||
ENTRY( 0x33, ';' , ':' )\
|
||||
ENTRY( 0x34, '\'' , '\"' )\
|
||||
ENTRY( 0x35, 0 , 0 )\
|
||||
ENTRY( 0x36, ',' , '<' )\
|
||||
ENTRY( 0x37, '.' , '>' )\
|
||||
ENTRY( 0x38, '/' , '?' )\
|
||||
ENTRY( 0x39, 0 , 0 ) /* TODO CapsLock, non-locking key implementation*/ \
|
||||
\
|
||||
ENTRY( 0x54, '/' , '/' )\
|
||||
ENTRY( 0x55, '*' , '*' )\
|
||||
ENTRY( 0x56, '-' , '-' )\
|
||||
ENTRY( 0x57, '+' , '+' )\
|
||||
ENTRY( 0x58, '\r' , '\r' )\
|
||||
ENTRY( 0x59, '1' , 0 ) /* numpad1 & end */ \
|
||||
ENTRY( 0x5a, '2' , 0 )\
|
||||
ENTRY( 0x5b, '3' , 0 )\
|
||||
ENTRY( 0x5c, '4' , 0 )\
|
||||
ENTRY( 0x5d, '5' , '5' )\
|
||||
ENTRY( 0x5e, '6' , 0 )\
|
||||
ENTRY( 0x5f, '7' , 0 )\
|
||||
ENTRY( 0x60, '8' , 0 )\
|
||||
ENTRY( 0x61, '9' , 0 )\
|
||||
ENTRY( 0x62, '0' , 0 )\
|
||||
ENTRY( 0x63, '0' , 0 )\
|
||||
ENTRY( 0x67, '=' , '=' )\
|
||||
|
||||
|
||||
|
||||
// TODO HID complete keycode table
|
||||
|
||||
//enum
|
||||
//{
|
||||
// KEYBOARD_KEYCODE_A = 0x04,
|
||||
// KEYBOARD_KEYCODE_Z = 0x1d,
|
||||
//
|
||||
// KEYBOARD_KEYCODE_1 = 0x1e,
|
||||
// KEYBOARD_KEYCODE_0 = 0x27,
|
||||
//
|
||||
// KEYBOARD_KEYCODE_ENTER = 0x28,
|
||||
// KEYBOARD_KEYCODE_ESCAPE = 0x29,
|
||||
// KEYBOARD_KEYCODE_BACKSPACE = 0x2a,
|
||||
// KEYBOARD_KEYCODE_TAB = 0x2b,
|
||||
// KEYBOARD_KEYCODE_SPACEBAR = 0x2c,
|
||||
//
|
||||
//};
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// REPORT DESCRIPTOR
|
||||
//--------------------------------------------------------------------+
|
||||
//------------- ITEM & TAG -------------//
|
||||
#define HID_REPORT_DATA_0(data)
|
||||
#define HID_REPORT_DATA_1(data) , data
|
||||
#define HID_REPORT_DATA_2(data) , U16_TO_U8S_LE(data)
|
||||
#define HID_REPORT_DATA_3(data) , U32_TO_U8S_LE(data)
|
||||
|
||||
#define HID_REPORT_ITEM(data, tag, type, size) \
|
||||
(((tag) << 4) | ((type) << 2) | (size)) HID_REPORT_DATA_##size(data)
|
||||
|
||||
#define RI_TYPE_MAIN 0
|
||||
#define RI_TYPE_GLOBAL 1
|
||||
#define RI_TYPE_LOCAL 2
|
||||
|
||||
//------------- MAIN ITEMS 6.2.2.4 -------------//
|
||||
#define HID_INPUT(x) HID_REPORT_ITEM(x, 8, RI_TYPE_MAIN, 1)
|
||||
#define HID_OUTPUT(x) HID_REPORT_ITEM(x, 9, RI_TYPE_MAIN, 1)
|
||||
#define HID_COLLECTION(x) HID_REPORT_ITEM(x, 10, RI_TYPE_MAIN, 1)
|
||||
#define HID_FEATURE(x) HID_REPORT_ITEM(x, 11, RI_TYPE_MAIN, 1)
|
||||
#define HID_COLLECTION_END HID_REPORT_ITEM(x, 12, RI_TYPE_MAIN, 0)
|
||||
|
||||
//------------- INPUT, OUTPUT, FEATURE 6.2.2.5 -------------//
|
||||
#define HID_DATA (0<<0)
|
||||
#define HID_CONSTANT (1<<0)
|
||||
|
||||
#define HID_ARRAY (0<<1)
|
||||
#define HID_VARIABLE (1<<1)
|
||||
|
||||
#define HID_ABSOLUTE (0<<2)
|
||||
#define HID_RELATIVE (1<<2)
|
||||
|
||||
#define HID_WRAP_NO (0<<3)
|
||||
#define HID_WRAP (1<<3)
|
||||
|
||||
#define HID_LINEAR (0<<4)
|
||||
#define HID_NONLINEAR (1<<4)
|
||||
|
||||
#define HID_PREFERRED_STATE (0<<5)
|
||||
#define HID_PREFERRED_NO (1<<5)
|
||||
|
||||
#define HID_NO_NULL_POSITION (0<<6)
|
||||
#define HID_NULL_STATE (1<<6)
|
||||
|
||||
#define HID_NON_VOLATILE (0<<7)
|
||||
#define HID_VOLATILE (1<<7)
|
||||
|
||||
#define HID_BITFIELD (0<<8)
|
||||
#define HID_BUFFERED_BYTES (1<<8)
|
||||
|
||||
//------------- COLLECTION ITEM 6.2.2.6 -------------//
|
||||
enum {
|
||||
HID_COLLECTION_PHYSICAL = 0,
|
||||
HID_COLLECTION_APPLICATION,
|
||||
HID_COLLECTION_LOGICAL,
|
||||
HID_COLLECTION_REPORT,
|
||||
HID_COLLECTION_NAMED_ARRAY,
|
||||
HID_COLLECTION_USAGE_SWITCH,
|
||||
HID_COLLECTION_USAGE_MODIFIER
|
||||
};
|
||||
|
||||
//------------- GLOBAL ITEMS 6.2.2.7 -------------//
|
||||
#define HID_USAGE_PAGE(x) HID_REPORT_ITEM(x, 0, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_USAGE_PAGE_N(x, n) HID_REPORT_ITEM(x, 0, RI_TYPE_GLOBAL, n)
|
||||
|
||||
#define HID_LOGICAL_MIN(x) HID_REPORT_ITEM(x, 1, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_LOGICAL_MIN_N(x, n) HID_REPORT_ITEM(x, 1, RI_TYPE_GLOBAL, n)
|
||||
|
||||
#define HID_LOGICAL_MAX(x) HID_REPORT_ITEM(x, 2, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_LOGICAL_MAX_N(x, n) HID_REPORT_ITEM(x, 2, RI_TYPE_GLOBAL, n)
|
||||
|
||||
#define HID_PHYSICAL_MIN(x) HID_REPORT_ITEM(x, 3, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_PHYSICAL_MIN_N(x, n) HID_REPORT_ITEM(x, 3, RI_TYPE_GLOBAL, n)
|
||||
|
||||
#define HID_PHYSICAL_MAX(x) HID_REPORT_ITEM(x, 4, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_PHYSICAL_MAX_N(x, n) HID_REPORT_ITEM(x, 4, RI_TYPE_GLOBAL, n)
|
||||
|
||||
#define HID_UNIT_EXPONENT(x) HID_REPORT_ITEM(x, 5, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_UNIT_EXPONENT_N(x, n) HID_REPORT_ITEM(x, 5, RI_TYPE_GLOBAL, n)
|
||||
|
||||
#define HID_UNIT(x) HID_REPORT_ITEM(x, 6, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_UNIT_N(x, n) HID_REPORT_ITEM(x, 6, RI_TYPE_GLOBAL, n)
|
||||
|
||||
#define HID_REPORT_SIZE(x) HID_REPORT_ITEM(x, 7, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_REPORT_SIZE_N(x, n) HID_REPORT_ITEM(x, 7, RI_TYPE_GLOBAL, n)
|
||||
|
||||
#define HID_REPORT_ID(x) HID_REPORT_ITEM(x, 8, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_REPORT_ID_N(x) HID_REPORT_ITEM(x, 8, RI_TYPE_GLOBAL, n)
|
||||
|
||||
#define HID_REPORT_COUNT(x) HID_REPORT_ITEM(x, 9, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_REPORT_COUNT_N(x, n) HID_REPORT_ITEM(x, 9, RI_TYPE_GLOBAL, n)
|
||||
|
||||
#define HID_PUSH HID_REPORT_ITEM(x, 10, RI_TYPE_GLOBAL, 0)
|
||||
#define HID_POP HID_REPORT_ITEM(x, 11, RI_TYPE_GLOBAL, 0)
|
||||
|
||||
//------------- LOCAL ITEMS 6.2.2.8 -------------//
|
||||
#define HID_USAGE(x) HID_REPORT_ITEM(x, 0, RI_TYPE_LOCAL, 1)
|
||||
#define HID_USAGE_N(x, n) HID_REPORT_ITEM(x, 0, RI_TYPE_LOCAL, n)
|
||||
|
||||
#define HID_USAGE_MIN(x) HID_REPORT_ITEM(x, 1, RI_TYPE_LOCAL, 1)
|
||||
#define HID_USAGE_MIN_N(x, n) HID_REPORT_ITEM(x, 1, RI_TYPE_LOCAL, n)
|
||||
|
||||
#define HID_USAGE_MAX(x) HID_REPORT_ITEM(x, 2, RI_TYPE_LOCAL, 1)
|
||||
#define HID_USAGE_MAX_N(x, n) HID_REPORT_ITEM(x, 2, RI_TYPE_LOCAL, n)
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Usage Table
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
/// HID Usage Table - Table 1: Usage Page Summary
|
||||
enum {
|
||||
HID_USAGE_PAGE_DESKTOP = 0x01,
|
||||
HID_USAGE_PAGE_SIMULATE = 0x02,
|
||||
HID_USAGE_PAGE_VIRTUAL_REALITY = 0x03,
|
||||
HID_USAGE_PAGE_SPORT = 0x04,
|
||||
HID_USAGE_PAGE_GAME = 0x05,
|
||||
HID_USAGE_PAGE_GENERIC_DEVICE = 0x06,
|
||||
HID_USAGE_PAGE_KEYBOARD = 0x07,
|
||||
HID_USAGE_PAGE_LED = 0x08,
|
||||
HID_USAGE_PAGE_BUTTON = 0x09,
|
||||
HID_USAGE_PAGE_ORDINAL = 0x0a,
|
||||
HID_USAGE_PAGE_TELEPHONY = 0x0b,
|
||||
HID_USAGE_PAGE_CONSUMER = 0x0c,
|
||||
HID_USAGE_PAGE_DIGITIZER = 0x0d,
|
||||
HID_USAGE_PAGE_PID = 0x0f,
|
||||
HID_USAGE_PAGE_UNICODE = 0x10,
|
||||
HID_USAGE_PAGE_ALPHA_DISPLAY = 0x14,
|
||||
HID_USAGE_PAGE_MEDICAL = 0x40,
|
||||
HID_USAGE_PAGE_MONITOR = 0x80, //0x80 - 0x83
|
||||
HID_USAGE_PAGE_POWER = 0x84, // 0x084 - 0x87
|
||||
HID_USAGE_PAGE_BARCODE_SCANNER = 0x8c,
|
||||
HID_USAGE_PAGE_SCALE = 0x8d,
|
||||
HID_USAGE_PAGE_MSR = 0x8e,
|
||||
HID_USAGE_PAGE_CAMERA = 0x90,
|
||||
HID_USAGE_PAGE_ARCADE = 0x91,
|
||||
HID_USAGE_PAGE_VENDOR = 0xFFFF // 0xFF00 - 0xFFFF
|
||||
};
|
||||
|
||||
/// HID Usage Table - Table 6: Generic Desktop Page
|
||||
enum {
|
||||
HID_USAGE_DESKTOP_POINTER = 0x01,
|
||||
HID_USAGE_DESKTOP_MOUSE = 0x02,
|
||||
HID_USAGE_DESKTOP_JOYSTICK = 0x04,
|
||||
HID_USAGE_DESKTOP_GAMEPAD = 0x05,
|
||||
HID_USAGE_DESKTOP_KEYBOARD = 0x06,
|
||||
HID_USAGE_DESKTOP_KEYPAD = 0x07,
|
||||
HID_USAGE_DESKTOP_MULTI_AXIS_CONTROLLER = 0x08,
|
||||
HID_USAGE_DESKTOP_TABLET_PC_SYSTEM = 0x09,
|
||||
HID_USAGE_DESKTOP_X = 0x30,
|
||||
HID_USAGE_DESKTOP_Y = 0x31,
|
||||
HID_USAGE_DESKTOP_Z = 0x32,
|
||||
HID_USAGE_DESKTOP_RX = 0x33,
|
||||
HID_USAGE_DESKTOP_RY = 0x34,
|
||||
HID_USAGE_DESKTOP_RZ = 0x35,
|
||||
HID_USAGE_DESKTOP_SLIDER = 0x36,
|
||||
HID_USAGE_DESKTOP_DIAL = 0x37,
|
||||
HID_USAGE_DESKTOP_WHEEL = 0x38,
|
||||
HID_USAGE_DESKTOP_HAT_SWITCH = 0x39,
|
||||
HID_USAGE_DESKTOP_COUNTED_BUFFER = 0x3a,
|
||||
HID_USAGE_DESKTOP_BYTE_COUNT = 0x3b,
|
||||
HID_USAGE_DESKTOP_MOTION_WAKEUP = 0x3c,
|
||||
HID_USAGE_DESKTOP_START = 0x3d,
|
||||
HID_USAGE_DESKTOP_SELECT = 0x3e,
|
||||
HID_USAGE_DESKTOP_VX = 0x40,
|
||||
HID_USAGE_DESKTOP_VY = 0x41,
|
||||
HID_USAGE_DESKTOP_VZ = 0x42,
|
||||
HID_USAGE_DESKTOP_VBRX = 0x43,
|
||||
HID_USAGE_DESKTOP_VBRY = 0x44,
|
||||
HID_USAGE_DESKTOP_VBRZ = 0x45,
|
||||
HID_USAGE_DESKTOP_VNO = 0x46,
|
||||
HID_USAGE_DESKTOP_FEATURE_NOTIFICATION = 0x47,
|
||||
HID_USAGE_DESKTOP_RESOLUTION_MULTIPLIER = 0x48,
|
||||
HID_USAGE_DESKTOP_SYSTEM_CONTROL = 0x80,
|
||||
HID_USAGE_DESKTOP_SYSTEM_POWER_DOWN = 0x81,
|
||||
HID_USAGE_DESKTOP_SYSTEM_SLEEP = 0x82,
|
||||
HID_USAGE_DESKTOP_SYSTEM_WAKE_UP = 0x83,
|
||||
HID_USAGE_DESKTOP_SYSTEM_CONTEXT_MENU = 0x84,
|
||||
HID_USAGE_DESKTOP_SYSTEM_MAIN_MENU = 0x85,
|
||||
HID_USAGE_DESKTOP_SYSTEM_APP_MENU = 0x86,
|
||||
HID_USAGE_DESKTOP_SYSTEM_MENU_HELP = 0x87,
|
||||
HID_USAGE_DESKTOP_SYSTEM_MENU_EXIT = 0x88,
|
||||
HID_USAGE_DESKTOP_SYSTEM_MENU_SELECT = 0x89,
|
||||
HID_USAGE_DESKTOP_SYSTEM_MENU_RIGHT = 0x8A,
|
||||
HID_USAGE_DESKTOP_SYSTEM_MENU_LEFT = 0x8B,
|
||||
HID_USAGE_DESKTOP_SYSTEM_MENU_UP = 0x8C,
|
||||
HID_USAGE_DESKTOP_SYSTEM_MENU_DOWN = 0x8D,
|
||||
HID_USAGE_DESKTOP_SYSTEM_COLD_RESTART = 0x8E,
|
||||
HID_USAGE_DESKTOP_SYSTEM_WARM_RESTART = 0x8F,
|
||||
HID_USAGE_DESKTOP_DPAD_UP = 0x90,
|
||||
HID_USAGE_DESKTOP_DPAD_DOWN = 0x91,
|
||||
HID_USAGE_DESKTOP_DPAD_RIGHT = 0x92,
|
||||
HID_USAGE_DESKTOP_DPAD_LEFT = 0x93,
|
||||
HID_USAGE_DESKTOP_SYSTEM_DOCK = 0xA0,
|
||||
HID_USAGE_DESKTOP_SYSTEM_UNDOCK = 0xA1,
|
||||
HID_USAGE_DESKTOP_SYSTEM_SETUP = 0xA2,
|
||||
HID_USAGE_DESKTOP_SYSTEM_BREAK = 0xA3,
|
||||
HID_USAGE_DESKTOP_SYSTEM_DEBUGGER_BREAK = 0xA4,
|
||||
HID_USAGE_DESKTOP_APPLICATION_BREAK = 0xA5,
|
||||
HID_USAGE_DESKTOP_APPLICATION_DEBUGGER_BREAK = 0xA6,
|
||||
HID_USAGE_DESKTOP_SYSTEM_SPEAKER_MUTE = 0xA7,
|
||||
HID_USAGE_DESKTOP_SYSTEM_HIBERNATE = 0xA8,
|
||||
HID_USAGE_DESKTOP_SYSTEM_DISPLAY_INVERT = 0xB0,
|
||||
HID_USAGE_DESKTOP_SYSTEM_DISPLAY_INTERNAL = 0xB1,
|
||||
HID_USAGE_DESKTOP_SYSTEM_DISPLAY_EXTERNAL = 0xB2,
|
||||
HID_USAGE_DESKTOP_SYSTEM_DISPLAY_BOTH = 0xB3,
|
||||
HID_USAGE_DESKTOP_SYSTEM_DISPLAY_DUAL = 0xB4,
|
||||
HID_USAGE_DESKTOP_SYSTEM_DISPLAY_TOGGLE_INT_EXT = 0xB5,
|
||||
HID_USAGE_DESKTOP_SYSTEM_DISPLAY_SWAP_PRIMARY_SECONDARY = 0xB6,
|
||||
HID_USAGE_DESKTOP_SYSTEM_DISPLAY_LCD_AUTOSCALE = 0xB7
|
||||
};
|
||||
|
||||
|
||||
/// HID Usage Table: Consumer Page (0x0C)
|
||||
/// Only contains controls that supported by Windows (whole list is too long)
|
||||
enum
|
||||
{
|
||||
// Generic Control
|
||||
HID_USAGE_CONSUMER_CONTROL = 0x0001,
|
||||
|
||||
// Power Control
|
||||
HID_USAGE_CONSUMER_POWER = 0x0030,
|
||||
HID_USAGE_CONSUMER_RESET = 0x0031,
|
||||
HID_USAGE_CONSUMER_SLEEP = 0x0032,
|
||||
|
||||
// Screen Brightness
|
||||
HID_USAGE_CONSUMER_BRIGHTNESS_INCREMENT = 0x006F,
|
||||
HID_USAGE_CONSUMER_BRIGHTNESS_DECREMENT = 0x0070,
|
||||
|
||||
// These HID usages operate only on mobile systems (battery powered) and
|
||||
// require Windows 8 (build 8302 or greater).
|
||||
HID_USAGE_CONSUMER_WIRELESS_RADIO_CONTROLS = 0x000C,
|
||||
HID_USAGE_CONSUMER_WIRELESS_RADIO_BUTTONS = 0x00C6,
|
||||
HID_USAGE_CONSUMER_WIRELESS_RADIO_LED = 0x00C7,
|
||||
HID_USAGE_CONSUMER_WIRELESS_RADIO_SLIDER_SWITCH = 0x00C8,
|
||||
|
||||
// Media Control
|
||||
HID_USAGE_CONSUMER_PLAY_PAUSE = 0x00CD,
|
||||
HID_USAGE_CONSUMER_SCAN_NEXT = 0x00B5,
|
||||
HID_USAGE_CONSUMER_SCAN_PREVIOUS = 0x00B6,
|
||||
HID_USAGE_CONSUMER_STOP = 0x00B7,
|
||||
HID_USAGE_CONSUMER_VOLUME = 0x00E0,
|
||||
HID_USAGE_CONSUMER_MUTE = 0x00E2,
|
||||
HID_USAGE_CONSUMER_BASS = 0x00E3,
|
||||
HID_USAGE_CONSUMER_TREBLE = 0x00E4,
|
||||
HID_USAGE_CONSUMER_BASS_BOOST = 0x00E5,
|
||||
HID_USAGE_CONSUMER_VOLUME_INCREMENT = 0x00E9,
|
||||
HID_USAGE_CONSUMER_VOLUME_DECREMENT = 0x00EA,
|
||||
HID_USAGE_CONSUMER_BASS_INCREMENT = 0x0152,
|
||||
HID_USAGE_CONSUMER_BASS_DECREMENT = 0x0153,
|
||||
HID_USAGE_CONSUMER_TREBLE_INCREMENT = 0x0154,
|
||||
HID_USAGE_CONSUMER_TREBLE_DECREMENT = 0x0155,
|
||||
|
||||
// Application Launcher
|
||||
HID_USAGE_CONSUMER_AL_CONSUMER_CONTROL_CONFIGURATION = 0x0183,
|
||||
HID_USAGE_CONSUMER_AL_EMAIL_READER = 0x018A,
|
||||
HID_USAGE_CONSUMER_AL_CALCULATOR = 0x0192,
|
||||
HID_USAGE_CONSUMER_AL_LOCAL_BROWSER = 0x0194,
|
||||
|
||||
// Browser/Explorer Specific
|
||||
HID_USAGE_CONSUMER_AC_SEARCH = 0x0221,
|
||||
HID_USAGE_CONSUMER_AC_HOME = 0x0223,
|
||||
HID_USAGE_CONSUMER_AC_BACK = 0x0224,
|
||||
HID_USAGE_CONSUMER_AC_FORWARD = 0x0225,
|
||||
HID_USAGE_CONSUMER_AC_STOP = 0x0226,
|
||||
HID_USAGE_CONSUMER_AC_REFRESH = 0x0227,
|
||||
HID_USAGE_CONSUMER_AC_BOOKMARKS = 0x022A,
|
||||
|
||||
// Mouse Horizontal scroll
|
||||
HID_USAGE_CONSUMER_AC_PAN = 0x0238,
|
||||
};
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TUSB_HID_H__ */
|
||||
|
||||
/// @}
|
||||
322
src/class/hid/hid_device.c
Normal file
322
src/class/hid/hid_device.c
Normal file
@@ -0,0 +1,322 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file hid_device.c
|
||||
@author hathach (tinyusb.org)
|
||||
|
||||
@section LICENSE
|
||||
|
||||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2013, hathach (tinyusb.org)
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holders nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This file is part of the tinyusb stack.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
|
||||
#include "tusb_option.h"
|
||||
|
||||
#if (MODE_DEVICE_SUPPORTED && DEVICE_CLASS_HID)
|
||||
|
||||
#define _TINY_USB_SOURCE_FILE_
|
||||
//--------------------------------------------------------------------+
|
||||
// INCLUDE
|
||||
//--------------------------------------------------------------------+
|
||||
#include "common/tusb_common.h"
|
||||
#include "hid_device.h"
|
||||
#include "device/usbd_pvt.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO CONSTANT TYPEDEF
|
||||
//--------------------------------------------------------------------+
|
||||
enum {
|
||||
HIDD_NUMBER_OF_SUBCLASS = 3,
|
||||
HIDD_BUFFER_SIZE = 128
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint8_t const * p_report_desc;
|
||||
uint16_t report_length;
|
||||
|
||||
uint8_t edpt_addr;
|
||||
uint8_t interface_number;
|
||||
}hidd_interface_t;
|
||||
|
||||
typedef struct {
|
||||
hidd_interface_t * const p_interface;
|
||||
void (* const xfer_cb) (uint8_t, tusb_event_t, uint32_t);
|
||||
uint16_t (* const get_report_cb) (uint8_t, hid_request_report_type_t, void**, uint16_t );
|
||||
void (* const set_report_cb) (uint8_t, hid_request_report_type_t, uint8_t[], uint16_t);
|
||||
}hidd_class_driver_t;
|
||||
|
||||
extern ATTR_WEAK hidd_interface_t keyboardd_data;
|
||||
extern ATTR_WEAK hidd_interface_t moused_data;
|
||||
|
||||
static hidd_class_driver_t const hidd_class_driver[HIDD_NUMBER_OF_SUBCLASS] =
|
||||
{
|
||||
// [HID_PROTOCOL_NONE] = for HID Generic
|
||||
|
||||
#if CFG_TUD_HID_KEYBOARD
|
||||
[HID_PROTOCOL_KEYBOARD] =
|
||||
{
|
||||
.p_interface = &keyboardd_data,
|
||||
.xfer_cb = tud_hid_keyboard_cb,
|
||||
.get_report_cb = tud_hid_keyboard_get_report_cb,
|
||||
.set_report_cb = tud_hid_keyboard_set_report_cb
|
||||
},
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_HID_MOUSE
|
||||
[HID_PROTOCOL_MOUSE] =
|
||||
{
|
||||
.p_interface = &moused_data,
|
||||
.xfer_cb = tud_hid_mouse_cb,
|
||||
.get_report_cb = tud_hid_mouse_get_report_cb,
|
||||
.set_report_cb = tud_hid_mouse_set_report_cb
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
// internal buffer for transferring data
|
||||
CFG_TUSB_ATTR_USBRAM STATIC_VAR uint8_t m_hid_buffer[ HIDD_BUFFER_SIZE ];
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// KEYBOARD APPLICATION API
|
||||
//--------------------------------------------------------------------+
|
||||
#if CFG_TUD_HID_KEYBOARD
|
||||
STATIC_VAR hidd_interface_t keyboardd_data;
|
||||
|
||||
bool tud_hid_keyboard_busy(uint8_t rhport)
|
||||
{
|
||||
return dcd_edpt_busy(rhport, keyboardd_data.edpt_addr);
|
||||
}
|
||||
|
||||
tusb_error_t tud_hid_keyboard_send(uint8_t rhport, hid_keyboard_report_t const *p_report)
|
||||
{
|
||||
VERIFY(tud_mounted(), TUSB_ERROR_USBD_DEVICE_NOT_CONFIGURED);
|
||||
|
||||
hidd_interface_t * p_kbd = &keyboardd_data; // TODO &keyboardd_data[rhport];
|
||||
|
||||
TU_ASSERT( dcd_edpt_xfer(rhport, p_kbd->edpt_addr, (void*) p_report, sizeof(hid_keyboard_report_t)), TUSB_ERROR_DCD_EDPT_XFER ) ;
|
||||
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MOUSE APPLICATION API
|
||||
//--------------------------------------------------------------------+
|
||||
#if CFG_TUD_HID_MOUSE
|
||||
STATIC_VAR hidd_interface_t moused_data;
|
||||
|
||||
bool tud_hid_mouse_is_busy(uint8_t rhport)
|
||||
{
|
||||
return dcd_edpt_busy(rhport, moused_data.edpt_addr);
|
||||
}
|
||||
|
||||
tusb_error_t tud_hid_mouse_send(uint8_t rhport, hid_mouse_report_t const *p_report)
|
||||
{
|
||||
VERIFY(tud_mounted(), TUSB_ERROR_USBD_DEVICE_NOT_CONFIGURED);
|
||||
|
||||
hidd_interface_t * p_mouse = &moused_data; // TODO &keyboardd_data[rhport];
|
||||
|
||||
TU_ASSERT( dcd_edpt_xfer(rhport, p_mouse->edpt_addr, (void*) p_report, sizeof(hid_mouse_report_t)), TUSB_ERROR_DCD_EDPT_XFER ) ;
|
||||
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// USBD-CLASS API
|
||||
//--------------------------------------------------------------------+
|
||||
static void interface_clear(hidd_interface_t * p_interface)
|
||||
{
|
||||
if ( p_interface != NULL )
|
||||
{
|
||||
memclr_(p_interface, sizeof(hidd_interface_t));
|
||||
p_interface->interface_number = INTERFACE_INVALID_NUMBER;
|
||||
}
|
||||
}
|
||||
|
||||
void hidd_init(void)
|
||||
{
|
||||
for(uint8_t i=0; i<HIDD_NUMBER_OF_SUBCLASS; i++)
|
||||
{
|
||||
interface_clear( hidd_class_driver[i].p_interface );
|
||||
}
|
||||
}
|
||||
|
||||
void hidd_close(uint8_t rhport)
|
||||
{
|
||||
for(uint8_t i=0; i<HIDD_NUMBER_OF_SUBCLASS; i++)
|
||||
{
|
||||
interface_clear(hidd_class_driver[i].p_interface);
|
||||
}
|
||||
}
|
||||
|
||||
tusb_error_t hidd_control_request_st(uint8_t rhport, tusb_control_request_t const * p_request)
|
||||
{
|
||||
uint8_t subclass_idx;
|
||||
for(subclass_idx=0; subclass_idx<HIDD_NUMBER_OF_SUBCLASS; subclass_idx++)
|
||||
{
|
||||
hidd_interface_t * const p_interface = hidd_class_driver[subclass_idx].p_interface;
|
||||
if ( (p_interface != NULL) && (p_request->wIndex == p_interface->interface_number) ) break;
|
||||
}
|
||||
|
||||
TU_ASSERT(subclass_idx < HIDD_NUMBER_OF_SUBCLASS, TUSB_ERROR_FAILED);
|
||||
|
||||
hidd_class_driver_t const * const p_driver = &hidd_class_driver[subclass_idx];
|
||||
hidd_interface_t* const p_hid = p_driver->p_interface;
|
||||
|
||||
OSAL_SUBTASK_BEGIN
|
||||
|
||||
//------------- STD Request -------------//
|
||||
if (p_request->bmRequestType_bit.type == TUSB_REQ_TYPE_STANDARD)
|
||||
{
|
||||
uint8_t const desc_type = u16_high_u8(p_request->wValue);
|
||||
uint8_t const desc_index = u16_low_u8 (p_request->wValue);
|
||||
|
||||
(void) desc_index;
|
||||
|
||||
if (p_request->bRequest == TUSB_REQ_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_REPORT)
|
||||
{
|
||||
STASK_ASSERT ( p_hid->report_length <= HIDD_BUFFER_SIZE );
|
||||
|
||||
// copy to allow report descriptor not to be in USBRAM
|
||||
memcpy(m_hid_buffer, p_hid->p_report_desc, p_hid->report_length);
|
||||
|
||||
usbd_control_xfer_st(rhport, p_request->bmRequestType_bit.direction, m_hid_buffer, p_hid->report_length);
|
||||
}else
|
||||
{
|
||||
dcd_control_stall(rhport);
|
||||
}
|
||||
}
|
||||
//------------- Class Specific Request -------------//
|
||||
else if (p_request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS)
|
||||
{
|
||||
if( (HID_REQUEST_CONTROL_GET_REPORT == p_request->bRequest) && (p_driver->get_report_cb != NULL) )
|
||||
{
|
||||
// wValue = Report Type | Report ID
|
||||
void* p_buffer = NULL;
|
||||
|
||||
uint16_t actual_length = p_driver->get_report_cb(rhport, (hid_request_report_type_t) u16_high_u8(p_request->wValue),
|
||||
&p_buffer, p_request->wLength);
|
||||
STASK_ASSERT( p_buffer != NULL && actual_length > 0 );
|
||||
|
||||
usbd_control_xfer_st(rhport, p_request->bmRequestType_bit.direction, p_buffer, actual_length);
|
||||
}
|
||||
else if ( (HID_REQUEST_CONTROL_SET_REPORT == p_request->bRequest) && (p_driver->set_report_cb != NULL) )
|
||||
{
|
||||
// return TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT; // TODO test STALL control out endpoint (with mouse+keyboard)
|
||||
// wValue = Report Type | Report ID
|
||||
usbd_control_xfer_st(rhport, p_request->bmRequestType_bit.direction, m_hid_buffer, p_request->wLength);
|
||||
|
||||
p_driver->set_report_cb(rhport, u16_high_u8(p_request->wValue), m_hid_buffer, p_request->wLength);
|
||||
}
|
||||
else if (HID_REQUEST_CONTROL_SET_IDLE == p_request->bRequest)
|
||||
{
|
||||
// uint8_t idle_rate = u16_high_u8(p_request->wValue);
|
||||
dcd_control_status(rhport, p_request->bmRequestType_bit.direction);
|
||||
}else
|
||||
{
|
||||
// HID_REQUEST_CONTROL_GET_IDLE:
|
||||
// HID_REQUEST_CONTROL_GET_PROTOCOL:
|
||||
// HID_REQUEST_CONTROL_SET_PROTOCOL:
|
||||
dcd_control_stall(rhport);
|
||||
}
|
||||
}else
|
||||
{
|
||||
dcd_control_stall(rhport);
|
||||
}
|
||||
|
||||
OSAL_SUBTASK_END
|
||||
}
|
||||
|
||||
tusb_error_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length)
|
||||
{
|
||||
uint8_t const *p_desc = (uint8_t const *) p_interface_desc;
|
||||
|
||||
//------------- HID descriptor -------------//
|
||||
p_desc += p_desc[DESCRIPTOR_OFFSET_LENGTH];
|
||||
tusb_hid_descriptor_hid_t const *p_desc_hid = (tusb_hid_descriptor_hid_t const *) p_desc;
|
||||
TU_ASSERT(HID_DESC_TYPE_HID == p_desc_hid->bDescriptorType, TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE);
|
||||
|
||||
//------------- Endpoint Descriptor -------------//
|
||||
p_desc += p_desc[DESCRIPTOR_OFFSET_LENGTH];
|
||||
tusb_desc_endpoint_t const *p_desc_endpoint = (tusb_desc_endpoint_t const *) p_desc;
|
||||
TU_ASSERT(TUSB_DESC_ENDPOINT == p_desc_endpoint->bDescriptorType, TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE);
|
||||
|
||||
if (p_interface_desc->bInterfaceSubClass == HID_SUBCLASS_BOOT)
|
||||
{
|
||||
switch(p_interface_desc->bInterfaceProtocol)
|
||||
{
|
||||
case HID_PROTOCOL_KEYBOARD:
|
||||
case HID_PROTOCOL_MOUSE:
|
||||
{
|
||||
hidd_class_driver_t const * const p_driver = &hidd_class_driver[p_interface_desc->bInterfaceProtocol];
|
||||
hidd_interface_t * const p_hid = p_driver->p_interface;
|
||||
|
||||
VERIFY(p_hid, TUSB_ERROR_FAILED);
|
||||
|
||||
VERIFY( dcd_edpt_open(rhport, p_desc_endpoint), TUSB_ERROR_DCD_FAILED );
|
||||
|
||||
p_hid->edpt_addr = p_desc_endpoint->bEndpointAddress;
|
||||
|
||||
p_hid->interface_number = p_interface_desc->bInterfaceNumber;
|
||||
p_hid->p_report_desc = (p_interface_desc->bInterfaceProtocol == HID_PROTOCOL_KEYBOARD) ? tusbd_descriptor_pointers.p_hid_keyboard_report : tusbd_descriptor_pointers.p_hid_mouse_report;
|
||||
p_hid->report_length = p_desc_hid->wReportLength;
|
||||
|
||||
VERIFY(p_hid->p_report_desc, TUSB_ERROR_DESCRIPTOR_CORRUPTED);
|
||||
}
|
||||
break;
|
||||
|
||||
default: // TODO unknown, unsupported protocol --> skip this interface
|
||||
return TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE;
|
||||
}
|
||||
*p_length = sizeof(tusb_desc_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_desc_endpoint_t);
|
||||
}else
|
||||
{
|
||||
// open generic
|
||||
*p_length = 0;
|
||||
return TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE;
|
||||
}
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
|
||||
tusb_error_t hidd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, tusb_event_t event, uint32_t xferred_bytes)
|
||||
{
|
||||
for(uint8_t i=0; i<HIDD_NUMBER_OF_SUBCLASS; i++)
|
||||
{
|
||||
hidd_interface_t * const p_interface = hidd_class_driver[i].p_interface;
|
||||
if ( (p_interface != NULL) && (edpt_addr == p_interface->edpt_addr) )
|
||||
{
|
||||
hidd_class_driver[i].xfer_cb(rhport, event, xferred_bytes);
|
||||
}
|
||||
}
|
||||
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
|
||||
#endif
|
||||
217
src/class/hid/hid_device.h
Normal file
217
src/class/hid/hid_device.h
Normal file
@@ -0,0 +1,217 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file hid_device.h
|
||||
@author hathach (tinyusb.org)
|
||||
|
||||
@section LICENSE
|
||||
|
||||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2013, hathach (tinyusb.org)
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holders nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This file is part of the tinyusb stack.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef _TUSB_HID_DEVICE_H_
|
||||
#define _TUSB_HID_DEVICE_H_
|
||||
|
||||
#include "common/tusb_common.h"
|
||||
#include "device/usbd.h"
|
||||
#include "hid.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// KEYBOARD APPLICATION API
|
||||
//--------------------------------------------------------------------+
|
||||
/** \addtogroup ClassDriver_HID_Keyboard Keyboard
|
||||
* @{ */
|
||||
/** \defgroup Keyboard_Device Device
|
||||
* @{ */
|
||||
|
||||
/** \brief Check if the interface is currently busy or not
|
||||
* \param[in] rhport USB Controller ID
|
||||
* \retval true if the interface is busy meaning the stack is still transferring/waiting data from/to host
|
||||
* \retval false if the interface is not busy meaning the stack successfully transferred data from/to host
|
||||
* \note This function is primarily used for polling/waiting result after \ref tusbd_hid_keyboard_send.
|
||||
*/
|
||||
bool tud_hid_keyboard_busy(uint8_t rhport);
|
||||
|
||||
/** \brief Submit USB transfer
|
||||
* \param[in] rhport USB Controller ID
|
||||
* \param[in,out] p_report address that is used to store data from device. Must be accessible by usb controller (see \ref CFG_TUSB_ATTR_USBRAM)
|
||||
* \returns \ref tusb_error_t type to indicate success or error condition.
|
||||
* \retval TUSB_ERROR_NONE on success
|
||||
* \retval TUSB_ERROR_INTERFACE_IS_BUSY if the interface is already transferring data with device
|
||||
* \retval TUSB_ERROR_DEVICE_NOT_READY if device is not yet configured (by SET CONFIGURED request)
|
||||
* \retval TUSB_ERROR_INVALID_PARA if input parameters are not correct
|
||||
* \note This function is non-blocking and returns immediately. Data will be transferred when USB Host work with this interface.
|
||||
* The result of usb transfer will be reported by the interface's callback function
|
||||
*/
|
||||
tusb_error_t tud_hid_keyboard_send(uint8_t rhport, hid_keyboard_report_t const *p_report);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// APPLICATION CALLBACK API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
/** \brief Callback function that is invoked when an transferring event occurred
|
||||
* after invoking \ref tusbd_hid_keyboard_send
|
||||
* \param[in] rhport USB Controller ID
|
||||
* \param[in] event an value from \ref tusb_event_t
|
||||
* \note event can be one of following
|
||||
* - TUSB_EVENT_XFER_COMPLETE : previously scheduled transfer completes successfully.
|
||||
* - TUSB_EVENT_XFER_ERROR : previously scheduled transfer encountered a transaction error.
|
||||
* - TUSB_EVENT_XFER_STALLED : previously scheduled transfer is stalled by device.
|
||||
*/
|
||||
void tud_hid_keyboard_cb(uint8_t rhport, tusb_event_t event, uint32_t xferred_bytes);
|
||||
|
||||
/** \brief Callback function that is invoked when USB host request \ref HID_REQUEST_CONTROL_GET_REPORT
|
||||
* via control endpoint.
|
||||
* \param[in] rhport USB Controller ID
|
||||
* \param[in] report_type specify which report (INPUT, OUTPUT, FEATURE) that host requests
|
||||
* \param[out] pp_report pointer to buffer that application need to update, value must be accessible by USB controller (see \ref CFG_TUSB_ATTR_USBRAM)
|
||||
* \param[in] requested_length number of bytes that host requested
|
||||
* \retval non-zero Actual number of bytes in the response's buffer.
|
||||
* \retval zero indicates the current request is not supported. Tinyusb device stack will reject the request by
|
||||
* sending STALL in the data phase.
|
||||
* \note After this callback, the request is silently executed by the tinyusb stack, thus
|
||||
* the completion of this control request will not be reported to application.
|
||||
* For Keyboard, USB host often uses this to turn on/off the LED for CAPLOCKS, NUMLOCK (\ref hid_keyboard_led_bm_t)
|
||||
*/
|
||||
uint16_t tud_hid_keyboard_get_report_cb(uint8_t rhport, hid_request_report_type_t report_type, void** pp_report, uint16_t requested_length);
|
||||
|
||||
/** \brief Callback function that is invoked when USB host request \ref HID_REQUEST_CONTROL_SET_REPORT
|
||||
* via control endpoint.
|
||||
* \param[in] rhport USB Controller ID
|
||||
* \param[in] report_type specify which report (INPUT, OUTPUT, FEATURE) that host requests
|
||||
* \param[in] p_report_data buffer containing the report's data
|
||||
* \param[in] length number of bytes in the \a p_report_data
|
||||
* \note By the time this callback is invoked, the USB control transfer is already completed in the hardware side.
|
||||
* Application are free to handle data at its own will.
|
||||
*/
|
||||
void tud_hid_keyboard_set_report_cb(uint8_t rhport, hid_request_report_type_t report_type, uint8_t p_report_data[], uint16_t length);
|
||||
|
||||
/** @} */
|
||||
/** @} */
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MOUSE APPLICATION API
|
||||
//--------------------------------------------------------------------+
|
||||
/** \addtogroup ClassDriver_HID_Mouse Mouse
|
||||
* @{ */
|
||||
/** \defgroup Mouse_Device Device
|
||||
* @{ */
|
||||
|
||||
/** \brief Check if the interface is currently busy or not
|
||||
* \param[in] rhport USB Controller ID
|
||||
* \retval true if the interface is busy meaning the stack is still transferring/waiting data from/to host
|
||||
* \retval false if the interface is not busy meaning the stack successfully transferred data from/to host
|
||||
* \note This function is primarily used for polling/waiting result after \ref tusbd_hid_mouse_send.
|
||||
*/
|
||||
bool tud_hid_mouse_is_busy(uint8_t rhport);
|
||||
|
||||
/** \brief Perform transfer queuing
|
||||
* \param[in] rhport USB Controller ID
|
||||
* \param[in,out] p_report address that is used to store data from device. Must be accessible by usb controller (see \ref CFG_TUSB_ATTR_USBRAM)
|
||||
* \returns \ref tusb_error_t type to indicate success or error condition.
|
||||
* \retval TUSB_ERROR_NONE on success
|
||||
* \retval TUSB_ERROR_INTERFACE_IS_BUSY if the interface is already transferring data with device
|
||||
* \retval TUSB_ERROR_DEVICE_NOT_READY if device is not yet configured (by SET CONFIGURED request)
|
||||
* \retval TUSB_ERROR_INVALID_PARA if input parameters are not correct
|
||||
* \note This function is non-blocking and returns immediately. Data will be transferred when USB Host work with this interface.
|
||||
* The result of usb transfer will be reported by the interface's callback function
|
||||
*/
|
||||
tusb_error_t tud_hid_mouse_send(uint8_t rhport, hid_mouse_report_t const *p_report);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// APPLICATION CALLBACK API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
/** \brief Callback function that is invoked when an transferring event occurred
|
||||
* after invoking \ref tusbd_hid_mouse_send
|
||||
* \param[in] rhport USB Controller ID
|
||||
* \param[in] event an value from \ref tusb_event_t
|
||||
* \note event can be one of following
|
||||
* - TUSB_EVENT_XFER_COMPLETE : previously scheduled transfer completes successfully.
|
||||
* - TUSB_EVENT_XFER_ERROR : previously scheduled transfer encountered a transaction error.
|
||||
* - TUSB_EVENT_XFER_STALLED : previously scheduled transfer is stalled by device.
|
||||
*/
|
||||
void tud_hid_mouse_cb(uint8_t rhport, tusb_event_t event, uint32_t xferred_bytes);
|
||||
|
||||
/** \brief Callback function that is invoked when USB host request \ref HID_REQUEST_CONTROL_GET_REPORT
|
||||
* via control endpoint.
|
||||
* \param[in] rhport USB Controller ID
|
||||
* \param[in] report_type specify which report (INPUT, OUTPUT, FEATURE) that host requests
|
||||
* \param[out] pp_report pointer to buffer that application need to update, value must be accessible by USB controller (see \ref CFG_TUSB_ATTR_USBRAM)
|
||||
* \param[in] requested_length number of bytes that host requested
|
||||
* \retval non-zero Actual number of bytes in the response's buffer.
|
||||
* \retval zero indicates the current request is not supported. Tinyusb device stack will reject the request by
|
||||
* sending STALL in the data phase.
|
||||
* \note After this callback, the request is silently executed by the tinyusb stack, thus
|
||||
* the completion of this control request will not be reported to application
|
||||
*/
|
||||
uint16_t tud_hid_mouse_get_report_cb(uint8_t rhport, hid_request_report_type_t report_type, void** pp_report, uint16_t requested_length);
|
||||
|
||||
/** \brief Callback function that is invoked when USB host request \ref HID_REQUEST_CONTROL_SET_REPORT
|
||||
* via control endpoint.
|
||||
* \param[in] rhport USB Controller ID
|
||||
* \param[in] report_type specify which report (INPUT, OUTPUT, FEATURE) that host requests
|
||||
* \param[in] p_report_data buffer containing the report's data
|
||||
* \param[in] length number of bytes in the \a p_report_data
|
||||
* \note By the time this callback is invoked, the USB control transfer is already completed in the hardware side.
|
||||
* Application are free to handle data at its own will.
|
||||
*/
|
||||
void tud_hid_mouse_set_report_cb(uint8_t rhport, hid_request_report_type_t report_type, uint8_t p_report_data[], uint16_t length);
|
||||
|
||||
/** @} */
|
||||
/** @} */
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// USBD-CLASS DRIVER API
|
||||
//--------------------------------------------------------------------+
|
||||
#ifdef _TINY_USB_SOURCE_FILE_
|
||||
|
||||
void hidd_init(void);
|
||||
tusb_error_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length);
|
||||
tusb_error_t hidd_control_request_st(uint8_t rhport, tusb_control_request_t const * p_request);
|
||||
tusb_error_t hidd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, tusb_event_t event, uint32_t xferred_bytes);
|
||||
void hidd_close(uint8_t rhport);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TUSB_HID_DEVICE_H_ */
|
||||
|
||||
|
||||
304
src/class/hid/hid_host.c
Normal file
304
src/class/hid/hid_host.c
Normal file
@@ -0,0 +1,304 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file hid_host.c
|
||||
@author hathach (tinyusb.org)
|
||||
|
||||
@section LICENSE
|
||||
|
||||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2013, hathach (tinyusb.org)
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holders nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This file is part of the tinyusb stack.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
|
||||
#include "tusb_option.h"
|
||||
|
||||
#if (MODE_HOST_SUPPORTED && HOST_CLASS_HID)
|
||||
|
||||
#define _TINY_USB_SOURCE_FILE_
|
||||
//--------------------------------------------------------------------+
|
||||
// INCLUDE
|
||||
//--------------------------------------------------------------------+
|
||||
#include "common/tusb_common.h"
|
||||
#include "hid_host.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO CONSTANT TYPEDEF
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// HID Interface common functions
|
||||
//--------------------------------------------------------------------+
|
||||
static inline tusb_error_t hidh_interface_open(uint8_t dev_addr, uint8_t interface_number, tusb_desc_endpoint_t const *p_endpoint_desc, hidh_interface_info_t *p_hid)
|
||||
{
|
||||
p_hid->pipe_hdl = hcd_pipe_open(dev_addr, p_endpoint_desc, TUSB_CLASS_HID);
|
||||
p_hid->report_size = p_endpoint_desc->wMaxPacketSize.size; // TODO get size from report descriptor
|
||||
p_hid->interface_number = interface_number;
|
||||
|
||||
TU_ASSERT (pipehandle_is_valid(p_hid->pipe_hdl), TUSB_ERROR_HCD_FAILED);
|
||||
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
|
||||
static inline void hidh_interface_close(hidh_interface_info_t *p_hid)
|
||||
{
|
||||
(void) hcd_pipe_close(p_hid->pipe_hdl);
|
||||
memclr_(p_hid, sizeof(hidh_interface_info_t));
|
||||
}
|
||||
|
||||
// called from public API need to validate parameters
|
||||
tusb_error_t hidh_interface_get_report(uint8_t dev_addr, void * report, hidh_interface_info_t *p_hid)
|
||||
{
|
||||
//------------- parameters validation -------------//
|
||||
// TODO change to use is configured function
|
||||
TU_ASSERT (TUSB_DEVICE_STATE_CONFIGURED == tuh_device_get_state(dev_addr), TUSB_ERROR_DEVICE_NOT_READY);
|
||||
VERIFY (report, TUSB_ERROR_INVALID_PARA);
|
||||
TU_ASSSERT (!hcd_pipe_is_busy(p_hid->pipe_hdl), TUSB_ERROR_INTERFACE_IS_BUSY);
|
||||
|
||||
TU_ASSERT_ERR( hcd_pipe_xfer(p_hid->pipe_hdl, report, p_hid->report_size, true) ) ;
|
||||
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// KEYBOARD
|
||||
//--------------------------------------------------------------------+
|
||||
#if CFG_TUSB_HOST_HID_KEYBOARD
|
||||
|
||||
#define EXPAND_KEYCODE_TO_ASCII(keycode, ascii, shift_modified) \
|
||||
[0][keycode] = ascii,\
|
||||
[1][keycode] = shift_modified,\
|
||||
|
||||
// TODO size of table should be a macro for application to check boundary
|
||||
uint8_t const hid_keycode_to_ascii_tbl[2][128] =
|
||||
{
|
||||
HID_KEYCODE_TABLE(EXPAND_KEYCODE_TO_ASCII)
|
||||
};
|
||||
|
||||
STATIC_VAR hidh_interface_info_t keyboardh_data[CFG_TUSB_HOST_DEVICE_MAX]; // does not have addr0, index = dev_address-1
|
||||
|
||||
//------------- KEYBOARD PUBLIC API (parameter validation required) -------------//
|
||||
bool tuh_hid_keyboard_is_mounted(uint8_t dev_addr)
|
||||
{
|
||||
return tuh_device_is_configured(dev_addr) && pipehandle_is_valid(keyboardh_data[dev_addr-1].pipe_hdl);
|
||||
}
|
||||
|
||||
tusb_error_t tuh_hid_keyboard_get_report(uint8_t dev_addr, void* p_report)
|
||||
{
|
||||
return hidh_interface_get_report(dev_addr, p_report, &keyboardh_data[dev_addr-1]);
|
||||
}
|
||||
|
||||
bool tuh_hid_keyboard_is_busy(uint8_t dev_addr)
|
||||
{
|
||||
return tuh_hid_keyboard_is_mounted(dev_addr) &&
|
||||
hcd_pipe_is_busy( keyboardh_data[dev_addr-1].pipe_hdl );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MOUSE
|
||||
//--------------------------------------------------------------------+
|
||||
#if CFG_TUSB_HOST_HID_MOUSE
|
||||
|
||||
STATIC_VAR hidh_interface_info_t mouseh_data[CFG_TUSB_HOST_DEVICE_MAX]; // does not have addr0, index = dev_address-1
|
||||
|
||||
//------------- Public API -------------//
|
||||
bool tuh_hid_mouse_is_mounted(uint8_t dev_addr)
|
||||
{
|
||||
return tuh_device_is_configured(dev_addr) && pipehandle_is_valid(mouseh_data[dev_addr-1].pipe_hdl);
|
||||
}
|
||||
|
||||
bool tuh_hid_mouse_is_busy(uint8_t dev_addr)
|
||||
{
|
||||
return tuh_hid_mouse_is_mounted(dev_addr) &&
|
||||
hcd_pipe_is_busy( mouseh_data[dev_addr-1].pipe_hdl );
|
||||
}
|
||||
|
||||
tusb_error_t tuh_hid_mouse_get_report(uint8_t dev_addr, void * report)
|
||||
{
|
||||
return hidh_interface_get_report(dev_addr, report, &mouseh_data[dev_addr-1]);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// GENERIC
|
||||
//--------------------------------------------------------------------+
|
||||
#if CFG_TUSB_HOST_HID_GENERIC
|
||||
|
||||
//STATIC_ struct {
|
||||
// hidh_interface_info_t
|
||||
//} generic_data[CFG_TUSB_HOST_DEVICE_MAX];
|
||||
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// CLASS-USBH API (don't require to verify parameters)
|
||||
//--------------------------------------------------------------------+
|
||||
void hidh_init(void)
|
||||
{
|
||||
#if CFG_TUSB_HOST_HID_KEYBOARD
|
||||
memclr_(&keyboardh_data, sizeof(hidh_interface_info_t)*CFG_TUSB_HOST_DEVICE_MAX);
|
||||
#endif
|
||||
|
||||
#if CFG_TUSB_HOST_HID_MOUSE
|
||||
memclr_(&mouseh_data, sizeof(hidh_interface_info_t)*CFG_TUSB_HOST_DEVICE_MAX);
|
||||
#endif
|
||||
|
||||
#if CFG_TUSB_HOST_HID_GENERIC
|
||||
hidh_generic_init();
|
||||
#endif
|
||||
}
|
||||
|
||||
#if 0
|
||||
CFG_TUSB_ATTR_USBRAM uint8_t report_descriptor[256];
|
||||
#endif
|
||||
|
||||
tusb_error_t hidh_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length)
|
||||
{
|
||||
tusb_error_t error;
|
||||
uint8_t const *p_desc = (uint8_t const *) p_interface_desc;
|
||||
|
||||
//------------- HID descriptor -------------//
|
||||
p_desc += p_desc[DESCRIPTOR_OFFSET_LENGTH];
|
||||
tusb_hid_descriptor_hid_t const *p_desc_hid = (tusb_hid_descriptor_hid_t const *) p_desc;
|
||||
TU_ASSERT(HID_DESC_TYPE_HID == p_desc_hid->bDescriptorType, TUSB_ERROR_INVALID_PARA);
|
||||
|
||||
//------------- Endpoint Descriptor -------------//
|
||||
p_desc += p_desc[DESCRIPTOR_OFFSET_LENGTH];
|
||||
tusb_desc_endpoint_t const * p_endpoint_desc = (tusb_desc_endpoint_t const *) p_desc;
|
||||
TU_ASSERT(TUSB_DESC_ENDPOINT == p_endpoint_desc->bDescriptorType, TUSB_ERROR_INVALID_PARA);
|
||||
|
||||
OSAL_SUBTASK_BEGIN
|
||||
|
||||
//------------- SET IDLE (0) request -------------//
|
||||
STASK_INVOKE(
|
||||
usbh_control_xfer_subtask( dev_addr, bm_request_type(TUSB_DIR_OUT, TUSB_REQ_TYPE_CLASS, TUSB_REQ_RCPT_INTERFACE),
|
||||
HID_REQUEST_CONTROL_SET_IDLE, 0, p_interface_desc->bInterfaceNumber,
|
||||
0, NULL ),
|
||||
error
|
||||
);
|
||||
(void) error; // skip if set idle is failed
|
||||
|
||||
#if 0
|
||||
//------------- Get Report Descriptor TODO HID parser -------------//
|
||||
if ( p_desc_hid->bNumDescriptors )
|
||||
{
|
||||
STASK_INVOKE(
|
||||
usbh_control_xfer_subtask( dev_addr, bm_request_type(TUSB_DIR_IN, TUSB_REQ_TYPE_STANDARD, TUSB_REQ_RCPT_INTERFACE),
|
||||
TUSB_REQ_GET_DESCRIPTOR, (p_desc_hid->bReportType << 8), 0,
|
||||
p_desc_hid->wReportLength, report_descriptor ),
|
||||
error
|
||||
);
|
||||
(void) error; // if error in getting report descriptor --> treating like there is none
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( HID_SUBCLASS_BOOT == p_interface_desc->bInterfaceSubClass )
|
||||
{
|
||||
#if CFG_TUSB_HOST_HID_KEYBOARD
|
||||
if ( HID_PROTOCOL_KEYBOARD == p_interface_desc->bInterfaceProtocol)
|
||||
{
|
||||
STASK_ASSERT_ERR ( hidh_interface_open(dev_addr, p_interface_desc->bInterfaceNumber, p_endpoint_desc, &keyboardh_data[dev_addr-1]) );
|
||||
tuh_hid_keyboard_mounted_cb(dev_addr);
|
||||
} else
|
||||
#endif
|
||||
|
||||
#if CFG_TUSB_HOST_HID_MOUSE
|
||||
if ( HID_PROTOCOL_MOUSE == p_interface_desc->bInterfaceProtocol)
|
||||
{
|
||||
STASK_ASSERT_ERR ( hidh_interface_open(dev_addr, p_interface_desc->bInterfaceNumber, p_endpoint_desc, &mouseh_data[dev_addr-1]) );
|
||||
tuh_hid_mouse_mounted_cb(dev_addr);
|
||||
} else
|
||||
#endif
|
||||
|
||||
{
|
||||
STASK_RETURN(TUSB_ERROR_HIDH_NOT_SUPPORTED_PROTOCOL); // exit & restart task
|
||||
}
|
||||
}else
|
||||
{
|
||||
STASK_RETURN(TUSB_ERROR_HIDH_NOT_SUPPORTED_SUBCLASS); // exit & restart task
|
||||
}
|
||||
|
||||
*p_length = sizeof(tusb_desc_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_desc_endpoint_t);
|
||||
|
||||
OSAL_SUBTASK_END
|
||||
}
|
||||
|
||||
void hidh_isr(pipe_handle_t pipe_hdl, tusb_event_t event, uint32_t xferred_bytes)
|
||||
{
|
||||
(void) xferred_bytes; // TODO may need to use this para later
|
||||
|
||||
#if CFG_TUSB_HOST_HID_KEYBOARD
|
||||
if ( pipehandle_is_equal(pipe_hdl, keyboardh_data[pipe_hdl.dev_addr-1].pipe_hdl) )
|
||||
{
|
||||
tuh_hid_keyboard_isr(pipe_hdl.dev_addr, event);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CFG_TUSB_HOST_HID_MOUSE
|
||||
if ( pipehandle_is_equal(pipe_hdl, mouseh_data[pipe_hdl.dev_addr-1].pipe_hdl) )
|
||||
{
|
||||
tuh_hid_mouse_isr(pipe_hdl.dev_addr, event);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CFG_TUSB_HOST_HID_GENERIC
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void hidh_close(uint8_t dev_addr)
|
||||
{
|
||||
#if CFG_TUSB_HOST_HID_KEYBOARD
|
||||
if ( pipehandle_is_valid( keyboardh_data[dev_addr-1].pipe_hdl ) )
|
||||
{
|
||||
hidh_interface_close(&keyboardh_data[dev_addr-1]);
|
||||
tuh_hid_keyboard_unmounted_cb(dev_addr);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CFG_TUSB_HOST_HID_MOUSE
|
||||
if( pipehandle_is_valid( mouseh_data[dev_addr-1].pipe_hdl ) )
|
||||
{
|
||||
hidh_interface_close(&mouseh_data[dev_addr-1]);
|
||||
tuh_hid_mouse_unmounted_cb( dev_addr );
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CFG_TUSB_HOST_HID_GENERIC
|
||||
hidh_generic_close(dev_addr);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
231
src/class/hid/hid_host.h
Normal file
231
src/class/hid/hid_host.h
Normal file
@@ -0,0 +1,231 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file hid_host.h
|
||||
@author hathach (tinyusb.org)
|
||||
|
||||
@section LICENSE
|
||||
|
||||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2013, hathach (tinyusb.org)
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holders nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This file is part of the tinyusb stack.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
|
||||
/** \addtogroup ClassDriver_HID
|
||||
* @{ */
|
||||
|
||||
#ifndef _TUSB_HID_HOST_H_
|
||||
#define _TUSB_HID_HOST_H_
|
||||
|
||||
#include "common/tusb_common.h"
|
||||
#include "host/usbh.h"
|
||||
#include "hid.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// KEYBOARD Application API
|
||||
//--------------------------------------------------------------------+
|
||||
/** \addtogroup ClassDriver_HID_Keyboard Keyboard
|
||||
* @{ */
|
||||
|
||||
/** \defgroup Keyboard_Host Host
|
||||
* The interface API includes status checking function, data transferring function and callback functions
|
||||
* @{ */
|
||||
|
||||
extern uint8_t const hid_keycode_to_ascii_tbl[2][128]; // TODO used weak attr if build failed without KEYBOARD enabled
|
||||
|
||||
/** \brief Check if device supports Keyboard interface or not
|
||||
* \param[in] dev_addr device address
|
||||
* \retval true if device supports Keyboard interface
|
||||
* \retval false if device does not support Keyboard interface or is not mounted
|
||||
*/
|
||||
bool tuh_hid_keyboard_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT;
|
||||
|
||||
/** \brief Check if the interface is currently busy or not
|
||||
* \param[in] dev_addr device address
|
||||
* \retval true if the interface is busy meaning the stack is still transferring/waiting data from/to device
|
||||
* \retval false if the interface is not busy meaning the stack successfully transferred data from/to device
|
||||
* \note This function is primarily used for polling/waiting result after \ref tuh_hid_keyboard_get_report.
|
||||
* Alternatively, asynchronous event API can be used
|
||||
*/
|
||||
bool tuh_hid_keyboard_is_busy(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT;
|
||||
|
||||
/** \brief Perform a get report from Keyboard interface
|
||||
* \param[in] dev_addr device address
|
||||
* \param[in,out] p_report address that is used to store data from device. Must be accessible by usb controller (see \ref CFG_TUSB_ATTR_USBRAM)
|
||||
* \returns \ref tusb_error_t type to indicate success or error condition.
|
||||
* \retval TUSB_ERROR_NONE on success
|
||||
* \retval TUSB_ERROR_INTERFACE_IS_BUSY if the interface is already transferring data with device
|
||||
* \retval TUSB_ERROR_DEVICE_NOT_READY if device is not yet configured (by SET CONFIGURED request)
|
||||
* \retval TUSB_ERROR_INVALID_PARA if input parameters are not correct
|
||||
* \note This function is non-blocking and returns immediately. The result of usb transfer will be reported by the interface's callback function
|
||||
*/
|
||||
tusb_error_t tuh_hid_keyboard_get_report(uint8_t dev_addr, void * p_report) /*ATTR_WARN_UNUSED_RESULT*/;
|
||||
|
||||
//------------- Application Callback -------------//
|
||||
/** \brief Callback function that is invoked when an transferring event occurred
|
||||
* \param[in] dev_addr Address of device
|
||||
* \param[in] event an value from \ref tusb_event_t
|
||||
* \note event can be one of following
|
||||
* - TUSB_EVENT_XFER_COMPLETE : previously scheduled transfer completes successfully.
|
||||
* - TUSB_EVENT_XFER_ERROR : previously scheduled transfer encountered a transaction error.
|
||||
* - TUSB_EVENT_XFER_STALLED : previously scheduled transfer is stalled by device.
|
||||
* \note Application should schedule the next report by calling \ref tuh_hid_keyboard_get_report within this callback
|
||||
*/
|
||||
void tuh_hid_keyboard_isr(uint8_t dev_addr, tusb_event_t event);
|
||||
|
||||
/** \brief Callback function that will be invoked when a device with Keyboard interface is mounted
|
||||
* \param[in] dev_addr Address of newly mounted device
|
||||
* \note This callback should be used by Application to set-up interface-related data
|
||||
*/
|
||||
void tuh_hid_keyboard_mounted_cb(uint8_t dev_addr);
|
||||
|
||||
/** \brief Callback function that will be invoked when a device with Keyboard interface is unmounted
|
||||
* \param[in] dev_addr Address of newly unmounted device
|
||||
* \note This callback should be used by Application to tear-down interface-related data
|
||||
*/
|
||||
void tuh_hid_keyboard_unmounted_cb(uint8_t dev_addr);
|
||||
|
||||
/** @} */ // Keyboard_Host
|
||||
/** @} */ // ClassDriver_HID_Keyboard
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MOUSE Application API
|
||||
//--------------------------------------------------------------------+
|
||||
/** \addtogroup ClassDriver_HID_Mouse Mouse
|
||||
* @{ */
|
||||
|
||||
/** \defgroup Mouse_Host Host
|
||||
* The interface API includes status checking function, data transferring function and callback functions
|
||||
* @{ */
|
||||
|
||||
/** \brief Check if device supports Mouse interface or not
|
||||
* \param[in] dev_addr device address
|
||||
* \retval true if device supports Mouse interface
|
||||
* \retval false if device does not support Mouse interface or is not mounted
|
||||
*/
|
||||
bool tuh_hid_mouse_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT;
|
||||
|
||||
/** \brief Check if the interface is currently busy or not
|
||||
* \param[in] dev_addr device address
|
||||
* \retval true if the interface is busy meaning the stack is still transferring/waiting data from/to device
|
||||
* \retval false if the interface is not busy meaning the stack successfully transferred data from/to device
|
||||
* \note This function is primarily used for polling/waiting result after \ref tuh_hid_mouse_get_report.
|
||||
* Alternatively, asynchronous event API can be used
|
||||
*/
|
||||
bool tuh_hid_mouse_is_busy(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT;
|
||||
|
||||
/** \brief Perform a get report from Mouse interface
|
||||
* \param[in] dev_addr device address
|
||||
* \param[in,out] p_report address that is used to store data from device. Must be accessible by usb controller (see \ref CFG_TUSB_ATTR_USBRAM)
|
||||
* \returns \ref tusb_error_t type to indicate success or error condition.
|
||||
* \retval TUSB_ERROR_NONE on success
|
||||
* \retval TUSB_ERROR_INTERFACE_IS_BUSY if the interface is already transferring data with device
|
||||
* \retval TUSB_ERROR_DEVICE_NOT_READY if device is not yet configured (by SET CONFIGURED request)
|
||||
* \retval TUSB_ERROR_INVALID_PARA if input parameters are not correct
|
||||
* \note This function is non-blocking and returns immediately. The result of usb transfer will be reported by the interface's callback function
|
||||
*/
|
||||
tusb_error_t tuh_hid_mouse_get_report(uint8_t dev_addr, void* p_report) /*ATTR_WARN_UNUSED_RESULT*/;
|
||||
|
||||
//------------- Application Callback -------------//
|
||||
/** \brief Callback function that is invoked when an transferring event occurred
|
||||
* \param[in] dev_addr Address of device
|
||||
* \param[in] event an value from \ref tusb_event_t
|
||||
* \note event can be one of following
|
||||
* - TUSB_EVENT_XFER_COMPLETE : previously scheduled transfer completes successfully.
|
||||
* - TUSB_EVENT_XFER_ERROR : previously scheduled transfer encountered a transaction error.
|
||||
* - TUSB_EVENT_XFER_STALLED : previously scheduled transfer is stalled by device.
|
||||
* \note Application should schedule the next report by calling \ref tuh_hid_mouse_get_report within this callback
|
||||
*/
|
||||
void tuh_hid_mouse_isr(uint8_t dev_addr, tusb_event_t event);
|
||||
|
||||
/** \brief Callback function that will be invoked when a device with Mouse interface is mounted
|
||||
* \param[in] dev_addr Address of newly mounted device
|
||||
* \note This callback should be used by Application to set-up interface-related data
|
||||
*/
|
||||
void tuh_hid_mouse_mounted_cb(uint8_t dev_addr);
|
||||
|
||||
/** \brief Callback function that will be invoked when a device with Mouse interface is unmounted
|
||||
* \param[in] dev_addr Address of newly unmounted device
|
||||
* \note This callback should be used by Application to tear-down interface-related data
|
||||
*/
|
||||
void tuh_hid_mouse_unmounted_cb(uint8_t dev_addr);
|
||||
|
||||
/** @} */ // Mouse_Host
|
||||
/** @} */ // ClassDriver_HID_Mouse
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// GENERIC Application API
|
||||
//--------------------------------------------------------------------+
|
||||
/** \addtogroup ClassDriver_HID_Generic Generic (not supported yet)
|
||||
* @{ */
|
||||
|
||||
/** \defgroup Generic_Host Host
|
||||
* The interface API includes status checking function, data transferring function and callback functions
|
||||
* @{ */
|
||||
|
||||
bool tuh_hid_generic_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT;
|
||||
tusb_error_t tuh_hid_generic_get_report(uint8_t dev_addr, void* p_report, bool int_on_complete) ATTR_WARN_UNUSED_RESULT;
|
||||
tusb_error_t tuh_hid_generic_set_report(uint8_t dev_addr, void* p_report, bool int_on_complete) ATTR_WARN_UNUSED_RESULT;
|
||||
tusb_interface_status_t tuh_hid_generic_get_status(uint8_t dev_addr) ATTR_WARN_UNUSED_RESULT;
|
||||
tusb_interface_status_t tuh_hid_generic_set_status(uint8_t dev_addr) ATTR_WARN_UNUSED_RESULT;
|
||||
|
||||
//------------- Application Callback -------------//
|
||||
void tuh_hid_generic_isr(uint8_t dev_addr, tusb_event_t event);
|
||||
|
||||
/** @} */ // Generic_Host
|
||||
/** @} */ // ClassDriver_HID_Generic
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// USBH-CLASS DRIVER API
|
||||
//--------------------------------------------------------------------+
|
||||
#ifdef _TINY_USB_SOURCE_FILE_
|
||||
|
||||
typedef struct {
|
||||
pipe_handle_t pipe_hdl;
|
||||
uint16_t report_size;
|
||||
uint8_t interface_number;
|
||||
}hidh_interface_info_t;
|
||||
|
||||
void hidh_init(void);
|
||||
tusb_error_t hidh_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) ATTR_WARN_UNUSED_RESULT;
|
||||
void hidh_isr(pipe_handle_t pipe_hdl, tusb_event_t event, uint32_t xferred_bytes);
|
||||
void hidh_close(uint8_t dev_addr);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TUSB_HID_HOST_H_ */
|
||||
|
||||
/** @} */ // ClassDriver_HID
|
||||
Reference in New Issue
Block a user