Skip to content

Commit bc12d76

Browse files
author
Stefan Jones
committed
Introduced support for Consumer Control devices on Leonardo and Micro
1 parent 5615e20 commit bc12d76

File tree

2 files changed

+205
-3
lines changed

2 files changed

+205
-3
lines changed

Diff for: hardware/arduino/cores/arduino/HID.cpp

+161-3
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@
2525

2626
//#define RAWHID_ENABLED
2727

28-
// Singletons for mouse and keyboard
29-
28+
// Singletons for mouse, keyboard and remote
29+
3030
Mouse_ Mouse;
3131
Keyboard_ Keyboard;
32+
Remote_ Remote;
3233

3334
//================================================================================
3435
//================================================================================
@@ -124,8 +125,61 @@ const u8 _hidReportDescriptor[] = {
124125
0x95, 64, // report count RX
125126
0x09, 0x02, // usage
126127
0x91, 0x02, // Output (array)
127-
0xC0 // end collection
128+
0xC0, // end collection
128129
#endif
130+
131+
//-----------------------------------------------------------------------------
132+
133+
/* Cross-platform support for controls found on IR Remotes */
134+
135+
0x05, 0x0c, // Usage Page (Consumer Devices)
136+
0x09, 0x01, // Usage (Consumer Control)
137+
0xa1, 0x01, // Collection (Application)
138+
0x85, 0x04, // REPORT_ID (4)
139+
0x15, 0x00, // Logical Minimum (0)
140+
0x25, 0x01, // Logical Maximum (1)
141+
0x09, 0xe9, // Usage (Volume Up)
142+
0x09, 0xea, // Usage (Volume Down)
143+
0x75, 0x01, // Report Size (1)
144+
0x95, 0x02, // Report Count (2)
145+
0x81, 0x06, // Input (Data, Variable, Relative)
146+
147+
0x09, 0xe2, // Usage (Mute)
148+
0x95, 0x01, // Report Count (1)
149+
0x81, 0x06, // Input (Data, Variable, Relative)
150+
151+
0x09, 0xb0, // Usage (Play)
152+
0x95, 0x01, // Report Count (1)
153+
0x81, 0x06, // Input (Data, Variable, Relative)
154+
155+
0x09, 0xb1, // Usage (Pause)
156+
0x95, 0x01, // Report Count (1)
157+
0x81, 0x06, // Input (Data, Variable, Relative)
158+
159+
0x09, 0xb7, // Usage (Stop)
160+
0x95, 0x01, // Report Count (1)
161+
0x81, 0x06, // Input (Data, Variable, Relative)
162+
163+
0x09, 0xb5, // Usage (Next)
164+
0x95, 0x01, // Report Count (1)
165+
0x81, 0x06, // Input (Data, Variable, Relative)
166+
167+
0x09, 0xb6, // Usage (Previous)
168+
0x95, 0x01, // Report Count (1)
169+
0x81, 0x06, // Input (Data, Variable, Relative)
170+
171+
0x09, 0xb3, // Usage (Fast Forward)
172+
0x95, 0x01, // Report Count (1)
173+
0x81, 0x06, // Input (Data, Variable, Relative)
174+
175+
0x09, 0xb4, // Usage (Rewind)
176+
0x95, 0x01, // Report Count (1)
177+
0x81, 0x06, // Input (Data, Variable, Relative)
178+
179+
0x95, 0x06, // Report Count (6) Number of bits remaining in byte
180+
0x81, 0x07, // Input (Constant, Variable, Relative)
181+
0xc0 //End Collection
182+
129183
};
130184

131185
extern const HIDDescriptor _hidInterface PROGMEM;
@@ -515,6 +569,110 @@ size_t Keyboard_::write(uint8_t c)
515569
return (p); // just return the result of press() since release() almost always returns 1
516570
}
517571

572+
//================================================================================
573+
//================================================================================
574+
// Remote
575+
576+
Remote_::Remote_(void)
577+
{
578+
}
579+
580+
void Remote_::begin(void)
581+
{
582+
}
583+
584+
void Remote_::end(void)
585+
{
586+
}
587+
588+
void Remote_::increase(void)
589+
{
590+
u8 m[2];
591+
m[0] = VOLUME_UP;
592+
m[1] = 0;
593+
HID_SendReport(4,m,2);
594+
}
595+
596+
void Remote_::decrease(void)
597+
{
598+
u8 m[2];
599+
m[0] = VOLUME_DOWN;
600+
m[1] = 0;
601+
HID_SendReport(4,m,2);
602+
}
603+
604+
void Remote_::mute(void)
605+
{
606+
u8 m[2];
607+
m[0] = VOLUME_MUTE;
608+
m[1] = 0;
609+
HID_SendReport(4,m,2);
610+
}
611+
612+
void Remote_::play(void)
613+
{
614+
u8 m[2];
615+
m[0] = REMOTE_PLAY;
616+
m[1] = 0;
617+
HID_SendReport(4,m,2);
618+
}
619+
620+
void Remote_::pause(void)
621+
{
622+
u8 m[2];
623+
m[0] = REMOTE_PAUSE;
624+
m[1] = 0;
625+
HID_SendReport(4,m,2);
626+
}
627+
628+
void Remote_::stop(void)
629+
{
630+
u8 m[2];
631+
m[0] = REMOTE_STOP;
632+
m[1] = 0;
633+
HID_SendReport(4,m,2);
634+
}
635+
636+
void Remote_::next(void)
637+
{
638+
u8 m[2];
639+
m[0] = REMOTE_NEXT;
640+
m[1] = 0;
641+
HID_SendReport(4,m,2);
642+
}
643+
644+
void Remote_::previous(void)
645+
{
646+
u8 m[2];
647+
m[0] = REMOTE_PREVIOUS;
648+
m[1] = 0;
649+
HID_SendReport(4,m,2);
650+
}
651+
652+
void Remote_::forward(void)
653+
{
654+
u8 m[2];
655+
m[0] = 0;
656+
m[1] = REMOTE_FAST_FORWARD >> 8;
657+
HID_SendReport(4,m,2);
658+
}
659+
660+
void Remote_::rewind(void)
661+
{
662+
u8 m[2];
663+
m[0] = 0;
664+
m[1] = REMOTE_REWIND >> 8;
665+
HID_SendReport(4,m,2);
666+
}
667+
668+
void Remote_::clear(void)
669+
{
670+
u8 m[2];
671+
m[0] = 0;
672+
m[1] = 0;
673+
HID_SendReport(4,m,2);
674+
}
675+
518676
#endif
519677

520678
#endif /* if defined(USBCON) */

Diff for: hardware/arduino/cores/arduino/USBAPI.h

+44
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,50 @@ class Keyboard_ : public Print
135135
};
136136
extern Keyboard_ Keyboard;
137137

138+
//================================================================================
139+
//================================================================================
140+
// Remote
141+
142+
#define REMOTE_CLEAR 0
143+
#define VOLUME_UP 1
144+
#define VOLUME_DOWN 2
145+
#define VOLUME_MUTE 4
146+
#define REMOTE_PLAY 8
147+
#define REMOTE_PAUSE 16
148+
#define REMOTE_STOP 32
149+
#define REMOTE_NEXT 64
150+
#define REMOTE_PREVIOUS 128
151+
#define REMOTE_FAST_FORWARD 256
152+
#define REMOTE_REWIND 512
153+
154+
class Remote_
155+
{
156+
private:
157+
public:
158+
Remote_(void);
159+
void begin(void);
160+
void end(void);
161+
162+
// Volume
163+
void increase(void);
164+
void decrease(void);
165+
void mute(void);
166+
167+
// Playback
168+
void play(void);
169+
void pause(void);
170+
void stop(void);
171+
172+
// Track Controls
173+
void next(void);
174+
void previous(void);
175+
void forward(void);
176+
void rewind(void);
177+
178+
// Send an empty report to prevent repeated actions
179+
void clear(void);
180+
};
181+
extern Remote_ Remote;
138182
//================================================================================
139183
//================================================================================
140184
// Low level API

0 commit comments

Comments
 (0)