Skip to content

Commit 4d317b0

Browse files
authored
Merge pull request arduino#107 from hathach/adafruit-tinyusb
add bi-directional HID
2 parents 7a2e3e1 + c21b601 commit 4d317b0

File tree

13 files changed

+283
-266
lines changed

13 files changed

+283
-266
lines changed

cores/arduino/Adafruit_TinyUSB_Core/tinyusb/src/class/cdc/cdc_device.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ typedef struct
7171
//--------------------------------------------------------------------+
7272
// INTERNAL OBJECT & FUNCTION DECLARATION
7373
//--------------------------------------------------------------------+
74-
CFG_TUSB_MEM_SECTION static cdcd_interface_t _cdcd_itf[CFG_TUD_CDC] = { { 0 } };
74+
CFG_TUSB_MEM_SECTION static cdcd_interface_t _cdcd_itf[CFG_TUD_CDC];
7575

7676
// TODO will be replaced by dcd_edpt_busy()
7777
bool pending_read_from_host;
@@ -289,14 +289,12 @@ bool cdcd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t
289289
(TUSB_CLASS_CDC_DATA == ((tusb_desc_interface_t const *) p_desc)->bInterfaceClass) )
290290
{
291291
// next to endpoint descriptor
292-
(*p_length) += tu_desc_len(p_desc);
293292
p_desc = tu_desc_next(p_desc);
294293

295-
// Open endpoint pair with usbd helper
296-
tusb_desc_endpoint_t const *p_desc_ep = (tusb_desc_endpoint_t const *) p_desc;
297-
TU_ASSERT( usbd_open_edpt_pair(rhport, p_desc_ep, TUSB_XFER_BULK, &p_cdc->ep_out, &p_cdc->ep_in) );
294+
// Open endpoint pair
295+
TU_ASSERT( usbd_open_edpt_pair(rhport, p_desc, 2, TUSB_XFER_BULK, &p_cdc->ep_out, &p_cdc->ep_in) );
298296

299-
(*p_length) += 2*sizeof(tusb_desc_endpoint_t);
297+
(*p_length) += sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t);
300298
}
301299

302300
// Prepare for incoming data

cores/arduino/Adafruit_TinyUSB_Core/tinyusb/src/class/cdc/cdc_device.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,17 @@ static inline bool tud_cdc_write_flush (void)
8989
//--------------------------------------------------------------------+
9090
// APPLICATION CALLBACK API (WEAK is optional)
9191
//--------------------------------------------------------------------+
92+
93+
// Invoked when received new data
9294
ATTR_WEAK void tud_cdc_rx_cb(uint8_t itf);
95+
96+
// Invoked when received `wanted_char`
9397
ATTR_WEAK void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char);
98+
99+
// Invoked when line state DTR & RTS are changed via SET_CONTROL_LINE_STATE
94100
ATTR_WEAK void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts);
101+
102+
// Invoked when line coding is change via SET_LINE_CODING
95103
ATTR_WEAK void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const* p_line_coding);
96104

97105
/** @} */

cores/arduino/Adafruit_TinyUSB_Core/tinyusb/src/class/hid/hid.h

Lines changed: 56 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,20 @@
4343
/** \defgroup ClassDriver_HID_Common Common Definitions
4444
* @{ */
4545

46+
/// USB HID Descriptor
47+
typedef struct ATTR_PACKED
48+
{
49+
uint8_t bLength; /**< Numeric expression that is the total size of the HID descriptor */
50+
uint8_t bDescriptorType; /**< Constant name specifying type of HID descriptor. */
51+
52+
uint16_t bcdHID; /**< Numeric expression identifying the HID Class Specification release */
53+
uint8_t bCountryCode; /**< Numeric expression identifying country code of the localized hardware. */
54+
uint8_t bNumDescriptors; /**< Numeric expression specifying the number of class descriptors */
55+
56+
uint8_t bReportType; /**< Type of HID class report. */
57+
uint16_t wReportLength; /**< the total size of the Report descriptor. */
58+
} tusb_hid_descriptor_hid_t;
59+
4660
/// HID Subclass
4761
typedef enum
4862
{
@@ -69,9 +83,10 @@ typedef enum
6983
/// HID Request Report Type
7084
typedef enum
7185
{
72-
HID_REPORT_TYPE_INPUT = 1, ///< Input
73-
HID_REPORT_TYPE_OUTPUT, ///< Output
74-
HID_REPORT_TYPE_FEATURE ///< Feature
86+
HID_REPORT_TYPE_INVALID = 0,
87+
HID_REPORT_TYPE_INPUT, ///< Input
88+
HID_REPORT_TYPE_OUTPUT, ///< Output
89+
HID_REPORT_TYPE_FEATURE ///< Feature
7590
}hid_report_type_t;
7691

7792
/// HID Class Specific Control Request
@@ -85,59 +100,45 @@ typedef enum
85100
HID_REQ_CONTROL_SET_PROTOCOL = 0x0b ///< Set Protocol
86101
}hid_request_type_t;
87102

88-
/// USB HID Descriptor
89-
typedef struct ATTR_PACKED
90-
{
91-
uint8_t bLength; /**< Numeric expression that is the total size of the HID descriptor */
92-
uint8_t bDescriptorType; /**< Constant name specifying type of HID descriptor. */
93-
94-
uint16_t bcdHID; /**< Numeric expression identifying the HID Class Specification release */
95-
uint8_t bCountryCode; /**< Numeric expression identifying country code of the localized hardware. */
96-
uint8_t bNumDescriptors; /**< Numeric expression specifying the number of class descriptors */
97-
98-
uint8_t bReportType; /**< Type of HID class report. */
99-
uint16_t wReportLength; /**< the total size of the Report descriptor. */
100-
} tusb_hid_descriptor_hid_t;
101-
102103
/// HID Country Code
103104
typedef enum
104105
{
105-
HID_Local_NotSupported = 0 , ///< NotSupported
106-
HID_Local_Arabic , ///< Arabic
107-
HID_Local_Belgian , ///< Belgian
108-
HID_Local_Canadian_Bilingual , ///< Canadian_Bilingual
109-
HID_Local_Canadian_French , ///< Canadian_French
110-
HID_Local_Czech_Republic , ///< Czech_Republic
111-
HID_Local_Danish , ///< Danish
112-
HID_Local_Finnish , ///< Finnish
113-
HID_Local_French , ///< French
114-
HID_Local_German , ///< German
115-
HID_Local_Greek , ///< Greek
116-
HID_Local_Hebrew , ///< Hebrew
117-
HID_Local_Hungary , ///< Hungary
118-
HID_Local_International , ///< International
119-
HID_Local_Italian , ///< Italian
120-
HID_Local_Japan_Katakana , ///< Japan_Katakana
121-
HID_Local_Korean , ///< Korean
122-
HID_Local_Latin_American , ///< Latin_American
123-
HID_Local_Netherlands_Dutch , ///< Netherlands/Dutch
124-
HID_Local_Norwegian , ///< Norwegian
125-
HID_Local_Persian_Farsi , ///< Persian (Farsi)
126-
HID_Local_Poland , ///< Poland
127-
HID_Local_Portuguese , ///< Portuguese
128-
HID_Local_Russia , ///< Russia
129-
HID_Local_Slovakia , ///< Slovakia
130-
HID_Local_Spanish , ///< Spanish
131-
HID_Local_Swedish , ///< Swedish
132-
HID_Local_Swiss_French , ///< Swiss/French
133-
HID_Local_Swiss_German , ///< Swiss/German
134-
HID_Local_Switzerland , ///< Switzerland
135-
HID_Local_Taiwan , ///< Taiwan
136-
HID_Local_Turkish_Q , ///< Turkish-Q
137-
HID_Local_UK , ///< UK
138-
HID_Local_US , ///< US
139-
HID_Local_Yugoslavia , ///< Yugoslavia
140-
HID_Local_Turkish_F ///< Turkish-F
106+
HID_LOCAL_NotSupported = 0 , ///< NotSupported
107+
HID_LOCAL_Arabic , ///< Arabic
108+
HID_LOCAL_Belgian , ///< Belgian
109+
HID_LOCAL_Canadian_Bilingual , ///< Canadian_Bilingual
110+
HID_LOCAL_Canadian_French , ///< Canadian_French
111+
HID_LOCAL_Czech_Republic , ///< Czech_Republic
112+
HID_LOCAL_Danish , ///< Danish
113+
HID_LOCAL_Finnish , ///< Finnish
114+
HID_LOCAL_French , ///< French
115+
HID_LOCAL_German , ///< German
116+
HID_LOCAL_Greek , ///< Greek
117+
HID_LOCAL_Hebrew , ///< Hebrew
118+
HID_LOCAL_Hungary , ///< Hungary
119+
HID_LOCAL_International , ///< International
120+
HID_LOCAL_Italian , ///< Italian
121+
HID_LOCAL_Japan_Katakana , ///< Japan_Katakana
122+
HID_LOCAL_Korean , ///< Korean
123+
HID_LOCAL_Latin_American , ///< Latin_American
124+
HID_LOCAL_Netherlands_Dutch , ///< Netherlands/Dutch
125+
HID_LOCAL_Norwegian , ///< Norwegian
126+
HID_LOCAL_Persian_Farsi , ///< Persian (Farsi)
127+
HID_LOCAL_Poland , ///< Poland
128+
HID_LOCAL_Portuguese , ///< Portuguese
129+
HID_LOCAL_Russia , ///< Russia
130+
HID_LOCAL_Slovakia , ///< Slovakia
131+
HID_LOCAL_Spanish , ///< Spanish
132+
HID_LOCAL_Swedish , ///< Swedish
133+
HID_LOCAL_Swiss_French , ///< Swiss/French
134+
HID_LOCAL_Swiss_German , ///< Swiss/German
135+
HID_LOCAL_Switzerland , ///< Switzerland
136+
HID_LOCAL_Taiwan , ///< Taiwan
137+
HID_LOCAL_Turkish_Q , ///< Turkish-Q
138+
HID_LOCAL_UK , ///< UK
139+
HID_LOCAL_US , ///< US
140+
HID_LOCAL_Yugoslavia , ///< Yugoslavia
141+
HID_LOCAL_Turkish_F ///< Turkish-F
141142
} hid_country_code_t;
142143

143144
/** @} */
@@ -155,7 +156,7 @@ typedef struct ATTR_PACKED
155156
int8_t x; /**< Current delta x movement of the mouse. */
156157
int8_t y; /**< Current delta y movement on the mouse. */
157158
int8_t wheel; /**< Current delta wheel movement on the mouse. */
158-
// int8_t pan;
159+
int8_t pan; // using AC Pan
159160
} hid_mouse_report_t;
160161

161162
/// Standard Mouse Buttons Bitmap
@@ -461,7 +462,7 @@ enum {
461462
HID_USAGE_PAGE_MSR = 0x8e,
462463
HID_USAGE_PAGE_CAMERA = 0x90,
463464
HID_USAGE_PAGE_ARCADE = 0x91,
464-
HID_USAGE_PAGE_VENDOR = 0xFFFF // 0xFF00 - 0xFFFF
465+
HID_USAGE_PAGE_VENDOR = 0xFF00 // 0xFF00 - 0xFFFF
465466
};
466467

467468
/// HID Usage Table - Table 6: Generic Desktop Page

0 commit comments

Comments
 (0)