Skip to content

Commit 16b018b

Browse files
committed
add hid_composite with joy feather wing
1 parent 9dfe220 commit 16b018b

File tree

4 files changed

+107
-6
lines changed

4 files changed

+107
-6
lines changed

examples/HID/hid_composite/hid_composite.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void loop()
6565
{
6666
// Wake up host if we are in suspend mode
6767
// and REMOTE_WAKEUP feature is enabled by host
68-
tud_remote_wakeup();
68+
USBDevice.remoteWakeup();
6969
}
7070

7171
/*------------- Mouse -------------*/
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*********************************************************************
2+
Adafruit invests time and resources providing this open source code,
3+
please support Adafruit and open-source hardware by purchasing
4+
products from Adafruit!
5+
6+
MIT license, check LICENSE for more information
7+
Copyright (c) 2019 Ha Thach for Adafruit Industries
8+
All text above, and the splash screen below must be included in
9+
any redistribution
10+
*********************************************************************/
11+
12+
/* This sketch demonstrates USB HID mouse using Joystick Feather Wing
13+
* https://www.adafruit.com/product/3632
14+
*
15+
* Following library is required
16+
* - Adafruit_seesaw
17+
*/
18+
19+
#include "Adafruit_TinyUSB.h"
20+
#include "Adafruit_seesaw.h"
21+
22+
#define BUTTON_RIGHT 6
23+
#define BUTTON_DOWN 7
24+
#define BUTTON_LEFT 9
25+
#define BUTTON_UP 10
26+
#define BUTTON_SEL 14
27+
uint32_t button_mask = (1 << BUTTON_RIGHT) | (1 << BUTTON_DOWN) |
28+
(1 << BUTTON_LEFT) | (1 << BUTTON_UP) | (1 << BUTTON_SEL);
29+
30+
Adafruit_seesaw ss;
31+
32+
// HID report descriptor using TinyUSB's template
33+
// Single Report (no ID) descriptor
34+
uint8_t const desc_hid_report[] =
35+
{
36+
TUD_HID_REPORT_DESC_MOUSE()
37+
};
38+
39+
// USB HID object
40+
Adafruit_USBD_HID usb_hid;
41+
42+
int last_x, last_y;
43+
44+
// the setup function runs once when you press reset or power the board
45+
void setup()
46+
{
47+
usb_hid.setPollInterval(2);
48+
usb_hid.setReportDescriptor(desc_hid_report, sizeof(desc_hid_report));
49+
50+
usb_hid.begin();
51+
52+
Serial.begin(115200);
53+
Serial.println("Adafruit TinyUSB HID Mouse with Joy FeatherWing example");
54+
55+
if(!ss.begin(0x49)){
56+
Serial.println("ERROR! seesaw not found");
57+
while(1);
58+
} else {
59+
Serial.println("seesaw started");
60+
Serial.print("version: ");
61+
Serial.println(ss.getVersion(), HEX);
62+
}
63+
ss.pinModeBulk(button_mask, INPUT_PULLUP);
64+
ss.setGPIOInterrupts(button_mask, 1);
65+
66+
last_y = ss.analogRead(2);
67+
last_x = ss.analogRead(3);
68+
}
69+
70+
void loop()
71+
{
72+
// poll gpio once each 10 ms
73+
delay(10);
74+
75+
int y = ss.analogRead(2);
76+
int x = ss.analogRead(3);
77+
78+
int dx = x - last_x;
79+
int dy = y - last_y;
80+
81+
if ( (abs(dx) > 3) || (abs(dy) > 30) )
82+
{
83+
// Remote wakeup if PC is suspended
84+
if ( tud_suspended() )
85+
{
86+
// Wake up host if we are in suspend mode
87+
// and REMOTE_WAKEUP feature is enabled by host
88+
USBDevice.remoteWakeup();
89+
}
90+
91+
/*------------- Mouse -------------*/
92+
if ( usb_hid.ready() )
93+
{
94+
usb_hid.mouseMove(0, dx, dy); // no ID: right + down
95+
96+
last_x = x;
97+
last_y = y;
98+
99+
// delay a bit before attempt to send keyboard report
100+
delay(10);
101+
}
102+
}
103+
}

examples/HID/hid_keyboard/hid_keyboard.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void loop()
6363
// {
6464
// // Wake up host if we are in suspend mode
6565
// // and REMOTE_WAKEUP feature is enabled by host
66-
// tud_remote_wakeup();
66+
// USBDevice.remoteWakeup();
6767
// }
6868

6969
if ( !usb_hid.ready() ) return;

examples/HID/hid_mouse/hid_mouse.ino

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ uint8_t const desc_hid_report[] =
3737
TUD_HID_REPORT_DESC_MOUSE()
3838
};
3939

40+
// USB HID object
4041
Adafruit_USBD_HID usb_hid;
4142

4243
// the setup function runs once when you press reset or power the board
@@ -53,9 +54,6 @@ void setup()
5354
Serial.begin(115200);
5455

5556
Serial.println("Adafruit TinyUSB HID Mouse example");
56-
Serial.print("Wire pin ");
57-
Serial.print(pin);
58-
Serial.println(" to GND to move cursor to bottom right corner.");
5957
}
6058

6159
void loop()
@@ -71,7 +69,7 @@ void loop()
7169
{
7270
// Wake up host if we are in suspend mode
7371
// and REMOTE_WAKEUP feature is enabled by host
74-
tud_remote_wakeup();
72+
USBDevice.remoteWakeup();
7573
}
7674

7775
/*------------- Mouse -------------*/

0 commit comments

Comments
 (0)