Skip to content

Commit 8a77886

Browse files
committed
Added consumer control support to HID/hid_composite example
Added Adafruit_USBD_HID send report helper: sendReport8(), sendReport16(), sendReport32()
1 parent cf1925f commit 8a77886

File tree

6 files changed

+86
-52
lines changed

6 files changed

+86
-52
lines changed

.travis.yml.bck

Lines changed: 0 additions & 49 deletions
This file was deleted.

changelog.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,42 @@
11
# Adafruit TinyUSB Arduino Library Changelog
22

3+
## 0.9.0 - 2020.04.23
4+
5+
- Fixed mouseButtonRelease() error
6+
- Supported multiple cables for USB MIDI (requires BSP nRF52 0.20.0 and SAMD 1.5.12 )
7+
- Added consumer control support to HID/hid_composite example
8+
- Added Adafruit_USBD_HID send report helper: sendReport8(), sendReport16(), sendReport32()
9+
10+
**Minor Breaking Changes**
11+
- Removed trailing comma in hid report descriptor, this is required to use with BSP nRF52 0.20.0 and SAMD 1.5.12 e.g
12+
13+
from
14+
15+
```
16+
uint8_t const desc_hid_report[] =
17+
{
18+
TUD_HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(RID_KEYBOARD), ),
19+
TUD_HID_REPORT_DESC_MOUSE ( HID_REPORT_ID(RID_MOUSE ), ),
20+
};
21+
```
22+
to
23+
24+
```
25+
uint8_t const desc_hid_report[] =
26+
{
27+
TUD_HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(RID_KEYBOARD) /*, no more trailing comma */ ),
28+
TUD_HID_REPORT_DESC_MOUSE ( HID_REPORT_ID(RID_MOUSE ) /*, no more trailing comma */ ),
29+
};
30+
```
31+
32+
## 0.8.2 - 2020.04.06
33+
34+
- Removed package-lock.json in hid generic inout example due to security warning from github
35+
36+
## 0.8.1 - 2020.01.08
37+
38+
- More CI migrating work, no function changes
39+
340
## 0.8.0 - 2019.12.30
441

542
- Correct USB BCD version to 2.1 for webUSB

examples/HID/hid_composite/hid_composite.ino

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ uint8_t const desc_hid_report[] =
4444
{
4545
TUD_HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(RID_KEYBOARD) ),
4646
TUD_HID_REPORT_DESC_MOUSE ( HID_REPORT_ID(RID_MOUSE) ),
47-
//TUD_HID_REPORT_DESC_CONSUMER( HID_REPORT_ID(RID_CONSUMER_CONTROL), )
47+
TUD_HID_REPORT_DESC_CONSUMER( HID_REPORT_ID(RID_CONSUMER_CONTROL) )
4848
};
4949

5050
// USB HID object
@@ -97,7 +97,7 @@ void loop()
9797
/*------------- Keyboard -------------*/
9898
if ( usb_hid.ready() )
9999
{
100-
// use to prevent sending multiple consecutive zero report
100+
// use to send key release report
101101
static bool has_key = false;
102102

103103
if ( btn_pressed )
@@ -114,5 +114,31 @@ void loop()
114114
if (has_key) usb_hid.keyboardRelease(RID_KEYBOARD);
115115
has_key = false;
116116
}
117+
118+
// delay a bit before attempt to send consumer report
119+
delay(10);
120+
}
121+
122+
/*------------- Consumer Control -------------*/
123+
if ( usb_hid.ready() )
124+
{
125+
// Consumer Control is used to control Media playback, Volume, Brightness etc ...
126+
// Consumer report is 2-byte containing the control code of the key
127+
// For list of control check out https://github.com/hathach/tinyusb/blob/master/src/class/hid/hid.h#L544
128+
129+
// use to send consumer release report
130+
static bool has_consumer_key = false;
131+
132+
if ( btn_pressed )
133+
{
134+
// send volume down (0x00EA)
135+
usb_hid.sendReport16(RID_CONSUMER_CONTROL, HID_USAGE_CONSUMER_VOLUME_DECREMENT);
136+
has_consumer_key = true;
137+
}else
138+
{
139+
// release the consume key by sending zero (0x0000)
140+
if (has_consumer_key) usb_hid.sendReport16(RID_CONSUMER_CONTROL, 0);
141+
has_consumer_key = false;
142+
}
117143
}
118144
}

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Adafruit TinyUSB Library
2-
version=0.8.2
2+
version=0.9.0
33
author=Adafruit
44
maintainer=Adafruit <info@adafruit.com>
55
sentence=TinyUSB library for Arduino

src/Adafruit_USBD_HID.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,21 @@ bool Adafruit_USBD_HID::sendReport(uint8_t report_id, void const *report,
117117
return tud_hid_report(report_id, report, len);
118118
}
119119

120+
bool Adafruit_USBD_HID::sendReport8 (uint8_t report_id, uint8_t num)
121+
{
122+
return tud_hid_report(report_id, &num, sizeof(num));
123+
}
124+
125+
bool Adafruit_USBD_HID::sendReport16(uint8_t report_id, uint16_t num)
126+
{
127+
return tud_hid_report(report_id, &num, sizeof(num));
128+
}
129+
130+
bool Adafruit_USBD_HID::sendReport32(uint8_t report_id, uint32_t num)
131+
{
132+
return tud_hid_report(report_id, &num, sizeof(num));
133+
}
134+
120135
//------------- TinyUSB callbacks -------------//
121136
extern "C" {
122137

src/Adafruit_USBD_HID.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ class Adafruit_USBD_HID : Adafruit_USBD_Interface {
5151
bool ready(void);
5252
bool sendReport(uint8_t report_id, void const *report, uint8_t len);
5353

54+
// Report helpers
55+
bool sendReport8 (uint8_t report_id, uint8_t num);
56+
bool sendReport16(uint8_t report_id, uint16_t num);
57+
bool sendReport32(uint8_t report_id, uint32_t num);
58+
5459
//------------- Keyboard API -------------//
5560
bool keyboardReport(uint8_t report_id, uint8_t modifier, uint8_t keycode[6]);
5661
bool keyboardPress(uint8_t report_id, char ch);

0 commit comments

Comments
 (0)