summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/device/hid_composite/src/main.c29
-rw-r--r--examples/device/hid_composite/src/usb_descriptors.c3
-rw-r--r--examples/device/hid_composite/src/usb_descriptors.h1
-rw-r--r--examples/device/hid_multiple_interface/src/usb_descriptors.c10
4 files changed, 37 insertions, 6 deletions
diff --git a/examples/device/hid_composite/src/main.c b/examples/device/hid_composite/src/main.c
index 6a9b6445d..45b8ba674 100644
--- a/examples/device/hid_composite/src/main.c
+++ b/examples/device/hid_composite/src/main.c
@@ -183,6 +183,35 @@ void hid_task(void)
if (has_consumer_key) tud_hid_report(REPORT_ID_CONSUMER_CONTROL, &empty_key, 2);
has_consumer_key = false;
}
+
+ // delay a bit before sending next report
+ board_delay(10);
+ }
+
+ /*------------- Gamepad -------------*/
+ if ( tud_hid_ready() )
+ {
+ // use to avoid send multiple consecutive zero report for keyboard
+ static bool has_gamepad_key = false;
+
+ hid_gamepad_report_t report =
+ {
+ .x = 0, .y = 0, .z = 0, .rz = 0, .rx = 0, .ry = 0,
+ .hat = 0, .buttons = 0
+ };
+
+ if ( btn )
+ {
+ report.hat = GAMEPAD_HAT_UP;
+ tud_hid_report(REPORT_ID_GAMEPAD, &report, sizeof(report));
+
+ has_gamepad_key = true;
+ }else
+ {
+ report.hat = GAMEPAD_HAT_CENTERED;
+ if (has_gamepad_key) tud_hid_report(REPORT_ID_GAMEPAD, &report, sizeof(report));
+ has_gamepad_key = false;
+ }
}
}
diff --git a/examples/device/hid_composite/src/usb_descriptors.c b/examples/device/hid_composite/src/usb_descriptors.c
index 67ea34c08..fbe0e2550 100644
--- a/examples/device/hid_composite/src/usb_descriptors.c
+++ b/examples/device/hid_composite/src/usb_descriptors.c
@@ -75,7 +75,8 @@ uint8_t const desc_hid_report[] =
{
TUD_HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(REPORT_ID_KEYBOARD )),
TUD_HID_REPORT_DESC_MOUSE ( HID_REPORT_ID(REPORT_ID_MOUSE )),
- TUD_HID_REPORT_DESC_CONSUMER( HID_REPORT_ID(REPORT_ID_CONSUMER_CONTROL ))
+ TUD_HID_REPORT_DESC_CONSUMER( HID_REPORT_ID(REPORT_ID_CONSUMER_CONTROL )),
+ TUD_HID_REPORT_DESC_GAMEPAD ( HID_REPORT_ID(REPORT_ID_GAMEPAD ))
};
// Invoked when received GET HID REPORT DESCRIPTOR
diff --git a/examples/device/hid_composite/src/usb_descriptors.h b/examples/device/hid_composite/src/usb_descriptors.h
index feda83dcd..7894719fd 100644
--- a/examples/device/hid_composite/src/usb_descriptors.h
+++ b/examples/device/hid_composite/src/usb_descriptors.h
@@ -30,6 +30,7 @@ enum
REPORT_ID_KEYBOARD = 1,
REPORT_ID_MOUSE,
REPORT_ID_CONSUMER_CONTROL,
+ REPORT_ID_GAMEPAD
};
#endif /* USB_DESCRIPTORS_H_ */
diff --git a/examples/device/hid_multiple_interface/src/usb_descriptors.c b/examples/device/hid_multiple_interface/src/usb_descriptors.c
index 2354e5c1f..a28e57a2b 100644
--- a/examples/device/hid_multiple_interface/src/usb_descriptors.c
+++ b/examples/device/hid_multiple_interface/src/usb_descriptors.c
@@ -140,11 +140,11 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
char const* string_desc_arr [] =
{
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
- "TinyUSB", // 1: Manufacturer
- "TinyUSB Device", // 2: Product
- "123456", // 3: Serials, should use chip ID
- "Keyboard Interface", // 4: Interface 1 String
- "Mouse Interface", // 5: Interface 2 String
+ "TinyUSB", // 1: Manufacturer
+ "TinyUSB Device", // 2: Product
+ "123456", // 3: Serials, should use chip ID
+ "Keyboard Interface", // 4: Interface 1 String
+ "Mouse Interface", // 5: Interface 2 String
};
static uint16_t _desc_str[32];