Sfoglia il codice sorgente

fix simple pull request comments. Implement descriptor index hack.

Zachery Littell 5 anni fa
parent
commit
081af79009

+ 3 - 5
examples/device/hid_multipleinterface/src/main.c

@@ -30,8 +30,6 @@
 #include "bsp/board.h"
 #include "tusb.h"
 
-#include "usb_descriptors.h"
-
 //--------------------------------------------------------------------+
 // MACRO CONSTANT TYPEDEF PROTYPES
 //--------------------------------------------------------------------+
@@ -138,13 +136,13 @@ void hid_task(void)
       uint8_t keycode[6] = { 0 };
       keycode[0] = HID_KEY_A;
 
-      tud_hid_n_keyboard_report(keyboard_interface, REPORT_ID_KEYBOARD, 0, keycode);
+      tud_hid_n_keyboard_report(keyboard_interface, 0, 0, keycode);
 
       has_key = true;
     }else
     {
       // send empty key report if previously has key pressed
-      if (has_key) tud_hid_n_keyboard_report(keyboard_interface, REPORT_ID_KEYBOARD, 0, NULL);
+      if (has_key) tud_hid_n_keyboard_report(keyboard_interface, 0, 0, NULL);
       has_key = false;
     }
   }
@@ -157,7 +155,7 @@ void hid_task(void)
       int8_t const delta = 5;
 
       // no button, right + down, no scroll pan
-      tud_hid_n_mouse_report(mouse_interface, REPORT_ID_MOUSE, 0x00, delta, delta, 0, 0);
+      tud_hid_n_mouse_report(mouse_interface, 0, 0x00, delta, delta, 0, 0);
 
       // delay a bit before attempt to send keyboard report
       board_delay(10);

+ 2 - 3
examples/device/hid_multipleinterface/src/usb_descriptors.c

@@ -24,7 +24,6 @@
  */
 
 #include "tusb.h"
-#include "usb_descriptors.h"
 
 /* A combination of interfaces must have a unique product id, since PC will save device driver after the first plug.
  * Same VID/PID with different interface e.g MSC (first), then CDC (later) will possibly cause system error on PC.
@@ -73,12 +72,12 @@ uint8_t const * tud_descriptor_device_cb(void)
 
 uint8_t const desc_hid_report1[] =
 {
-  TUD_HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(REPORT_ID_KEYBOARD) )
+  TUD_HID_REPORT_DESC_KEYBOARD()
 };
 
 uint8_t desc_hid_report2[] =
 {
-  TUD_HID_REPORT_DESC_MOUSE   ( HID_REPORT_ID(REPORT_ID_MOUSE) )
+  TUD_HID_REPORT_DESC_MOUSE()
 };
 
 // Invoked when received GET HID REPORT DESCRIPTOR

+ 0 - 34
examples/device/hid_multipleinterface/src/usb_descriptors.h

@@ -1,34 +0,0 @@
-/* 
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#ifndef USB_DESCRIPTORS_H_
-#define USB_DESCRIPTORS_H_
-
-enum
-{
-  REPORT_ID_KEYBOARD = 1,
-  REPORT_ID_MOUSE
-};
-
-#endif /* USB_DESCRIPTORS_H_ */

+ 16 - 4
src/class/hid/hid_device.c

@@ -67,12 +67,21 @@ static inline hidd_interface_t* get_interface_by_itfnum(uint8_t itf_num)
   return NULL;
 }
 
+static inline uint8_t get_descindex_by_itfnum(uint8_t itf_num)
+{
+	for (uint8_t i=0; i < CFG_TUD_HID; i++ )
+	{
+		if ( itf_num == _hidd_itf[i].itf_num ) return i;
+	}
+
+	return 0;
+}
+
 //--------------------------------------------------------------------+
 // APPLICATION API
 //--------------------------------------------------------------------+
 bool tud_hid_n_ready(uint8_t itf)
 {
-  //uint8_t const itf = 0;
   uint8_t const ep_in = _hidd_itf[itf].ep_in;
   return tud_ready() && (ep_in != 0) && !usbd_edpt_busy(TUD_OPT_RHPORT, ep_in);
 }
@@ -80,7 +89,6 @@ bool tud_hid_n_ready(uint8_t itf)
 bool tud_hid_n_report(uint8_t itf, uint8_t report_id, void const* report, uint8_t len)
 {
   uint8_t const rhport = 0;
-  //uint8_t const itf = 0;
   hidd_interface_t * p_hid = &_hidd_itf[itf];
 
   // claim endpoint
@@ -106,7 +114,6 @@ bool tud_hid_n_report(uint8_t itf, uint8_t report_id, void const* report, uint8_
 
 bool tud_hid_n_boot_mode(uint8_t itf)
 {
-  //uint8_t itf = 0;
   return _hidd_itf[itf].boot_mode;
 }
 
@@ -237,7 +244,12 @@ bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * request
     }
     else if (request->bRequest == TUSB_REQ_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_REPORT)
     {
-      uint8_t const * desc_report = tud_hid_descriptor_report_cb((uint8_t) request->wIndex);
+      #if CFG_TUD_HID>1
+      uint8_t const calculated_desc_index = get_descindex_by_itfnum((uint8_t) request->wIndex);
+      uint8_t const * desc_report = tud_hid_descriptor_report_cb(calculated_desc_index);
+      #else
+      uint8_t const * desc_report = tud_hid_descriptor_report_cb();
+      #endif
       tud_control_xfer(rhport, request, (void*) desc_report, p_hid->report_desc_len);
     }
     else

+ 4 - 1
src/class/hid/hid_device.h

@@ -86,8 +86,11 @@ static inline bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8
 
 // Invoked when received GET HID REPORT DESCRIPTOR request
 // Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
-// TODO Talk about this change... because it is breaking. Might be better way to handle.
+#if CFG_TUD_HID>1
 uint8_t const * tud_hid_descriptor_report_cb(uint8_t desc_index);
+#else
+uint8_t const * tud_hid_descriptor_report_cb(void);
+#endif
 
 // Invoked when received GET_REPORT control request
 // Application must fill buffer report's content and return its length.