aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2010-11-17 16:06:20 +0900
committertmk <nobody@nowhere>2010-11-17 16:06:20 +0900
commit02d955e9fecda610e9cb7f5317262b907614bf31 (patch)
tree01a32f36bb17574f46c0d1848d87b0f750afdedc
parent8240e606d4571624c7967d6acfa562d70ff3ab97 (diff)
downloadqmk_firmware-02d955e9fecda610e9cb7f5317262b907614bf31.tar.gz
qmk_firmware-02d955e9fecda610e9cb7f5317262b907614bf31.zip
add audio controls from consumer page(HID)
-rw-r--r--Makefile.common1
-rw-r--r--hhkb/keymap.c2
-rw-r--r--key_process.c13
-rw-r--r--usb.c71
-rw-r--r--usb_extra.c33
-rw-r--r--usb_extra.h20
-rw-r--r--usb_keycodes.h4
7 files changed, 134 insertions, 10 deletions
diff --git a/Makefile.common b/Makefile.common
index bec799c08..467f6e777 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -55,6 +55,7 @@ SRC = tmk.c \
55 usb_keyboard.c \ 55 usb_keyboard.c \
56 usb_mouse.c \ 56 usb_mouse.c \
57 usb_debug.c \ 57 usb_debug.c \
58 usb_extra.c \
58 usb.c \ 59 usb.c \
59 jump_bootloader.c \ 60 jump_bootloader.c \
60 print.c \ 61 print.c \
diff --git a/hhkb/keymap.c b/hhkb/keymap.c
index 18e444e2c..ea8e39a93 100644
--- a/hhkb/keymap.c
+++ b/hhkb/keymap.c
@@ -84,7 +84,7 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
84 */ 84 */
85 KEYMAP(KB_PWR, KB_F1, KB_F2, KB_F3, KB_F4, KB_F5, KB_F6, KB_F7, KB_F8, KB_F9, KB_F10, KB_F11, KB_F12, KB_INS, KB_DEL, \ 85 KEYMAP(KB_PWR, KB_F1, KB_F2, KB_F3, KB_F4, KB_F5, KB_F6, KB_F7, KB_F8, KB_F9, KB_F10, KB_F11, KB_F12, KB_INS, KB_DEL, \
86 KB_CAPS,KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_PSCR,KB_SLCK,KB_BRK, KB_UP, KB_NO, KB_BSPC, \ 86 KB_CAPS,KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_PSCR,KB_SLCK,KB_BRK, KB_UP, KB_NO, KB_BSPC, \
87 KB_LCTL,KB_VUP, KB_VDWN,KB_MUTE,KB_NO, KB_NO, KP_ASTR,KP_SLSH,KB_HOME,KB_PGUP,KB_LEFT,KB_RGHT,KB_ENT, \ 87 KB_LCTL,KB_VOLD,KB_VOLU,KB_MUTE,KB_NO, KB_NO, KP_ASTR,KP_SLSH,KB_HOME,KB_PGUP,KB_LEFT,KB_RGHT,KB_ENT, \
88 KB_LSFT,KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KP_PLUS,KP_MINS,KB_END, KB_PGDN,KB_DOWN,KB_RSFT,FN_1, \ 88 KB_LSFT,KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KP_PLUS,KP_MINS,KB_END, KB_PGDN,KB_DOWN,KB_RSFT,FN_1, \
89 KB_LGUI,KB_LALT,KB_SPC, KB_RALT,FN_7), 89 KB_LGUI,KB_LALT,KB_SPC, KB_RALT,FN_7),
90 90
diff --git a/key_process.c b/key_process.c
index f6e16b8ed..243f4aad8 100644
--- a/key_process.c
+++ b/key_process.c
@@ -8,6 +8,7 @@
8#include "jump_bootloader.h" 8#include "jump_bootloader.h"
9#include "usb_keyboard.h" 9#include "usb_keyboard.h"
10#include "usb_mouse.h" 10#include "usb_mouse.h"
11#include "usb_extra.h"
11#include "usb_keycodes.h" 12#include "usb_keycodes.h"
12#include "layer.h" 13#include "layer.h"
13#include "matrix_skel.h" 14#include "matrix_skel.h"
@@ -88,6 +89,18 @@ void proc_matrix(void) {
88 if (code == MS_WH_RIGHT) mouse_hwheel += 1; 89 if (code == MS_WH_RIGHT) mouse_hwheel += 1;
89 } else if (IS_FN(code)) { 90 } else if (IS_FN(code)) {
90 fn_bits |= FN_BIT(code); 91 fn_bits |= FN_BIT(code);
92 } else if (code == KB_MUTE) {
93 usb_extra_send(AUDIO_MUTE);
94 usb_extra_send(0);
95 _delay_ms(500);
96 } else if (code == KB_VOLU) {
97 usb_extra_send(AUDIO_VOL_UP);
98 usb_extra_send(0);
99 _delay_ms(100);
100 } else if (code == KB_VOLD) {
101 usb_extra_send(AUDIO_VOL_DOWN);
102 usb_extra_send(0);
103 _delay_ms(100);
91 } else { 104 } else {
92 // normal keys 105 // normal keys
93 if (key_index < 6) 106 if (key_index < 6)
diff --git a/usb.c b/usb.c
index 3011ecb2a..7add57daa 100644
--- a/usb.c
+++ b/usb.c
@@ -28,6 +28,7 @@
28#include "usb_keyboard.h" 28#include "usb_keyboard.h"
29#include "usb_mouse.h" 29#include "usb_mouse.h"
30#include "usb_debug.h" 30#include "usb_debug.h"
31#include "usb_extra.h"
31#include "print.h" 32#include "print.h"
32#include "util.h" 33#include "util.h"
33 34
@@ -87,7 +88,7 @@ static const uint8_t PROGMEM endpoint_config_table[] = {
87 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(KEYBOARD_SIZE) | KEYBOARD_BUFFER, // 1 88 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(KEYBOARD_SIZE) | KEYBOARD_BUFFER, // 1
88 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(MOUSE_SIZE) | MOUSE_BUFFER, // 2 89 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(MOUSE_SIZE) | MOUSE_BUFFER, // 2
89 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(DEBUG_TX_SIZE) | DEBUG_TX_BUFFER, // 3 90 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(DEBUG_TX_SIZE) | DEBUG_TX_BUFFER, // 3
90 0, // 4 91 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(EXTRA_SIZE) | EXTRA_BUFFER, // 4
91 0, // 5 92 0, // 5
92 0, // 6 93 0, // 6
93}; 94};
@@ -249,17 +250,43 @@ static uint8_t PROGMEM debug_hid_report_desc[] = {
249 0xC0 // end collection 250 0xC0 // end collection
250}; 251};
251 252
252#define CONFIG1_DESC_SIZE (9+(9+9+7)+(9+9+7)+(9+9+7)) 253// audio controls(consumer page)
253#define KEYBOARD_HID_DESC_OFFSET (9+9) 254// http://www.microsoft.com/whdc/archive/w2kbd.mspx
254#define MOUSE_HID_DESC_OFFSET (9+(9+9+7)+9) 255static uint8_t PROGMEM extra_hid_report_desc[] = {
255#define DEBUG_HID_DESC_OFFSET (9+(9+9+7)+(9+9+7)+9) 256 0x05, 0x0c, // USAGE_PAGE (Consumer Devices)
257 0x09, 0x01, // USAGE (Consumer Control)
258 0xa1, 0x01, // COLLECTION (Application)
259 0x85, 0x01, // REPORT_ID (1)
260 0x09, 0xe9, // USAGE (Volume Up)
261 0x09, 0xea, // USAGE (Volume Down)
262 0x15, 0x00, // LOGICAL_MINIMUM (0)
263 0x25, 0x01, // LOGICAL_MAXIMUM (1)
264 0x75, 0x01, // REPORT_SIZE (1)
265 0x95, 0x02, // REPORT_COUNT (2)
266 0x81, 0x02, // INPUT (Data,Var,Abs)
267 0x09, 0xe2, // USAGE (Mute)
268 0x15, 0x00, // LOGICAL_MINIMUM (0)
269 0x25, 0x01, // LOGICAL_MAXIMUM (1)
270 0x75, 0x01, // REPORT_SIZE (1)
271 0x95, 0x01, // REPORT_COUNT (1)
272 0x81, 0x06, // INPUT (Data,Var,Rel)
273 0x95, 0x05, // REPORT_COUNT (5)
274 0x81, 0x07, // INPUT (Cnst,Var,Abs)
275 0xc0 // END_COLLECTION
276};
277
278#define CONFIG1_DESC_SIZE (9+(9+9+7)*4)
279#define KEYBOARD_HID_DESC_OFFSET (9+(9+9+7)*0+9)
280#define MOUSE_HID_DESC_OFFSET (9+(9+9+7)*1+9)
281#define DEBUG_HID_DESC_OFFSET (9+(9+9+7)*2+9)
282#define EXTRA_HID_DESC_OFFSET (9+(9+9+7)*3+9)
256static uint8_t PROGMEM config1_descriptor[CONFIG1_DESC_SIZE] = { 283static uint8_t PROGMEM config1_descriptor[CONFIG1_DESC_SIZE] = {
257 // configuration descriptor, USB spec 9.6.3, page 264-266, Table 9-10 284 // configuration descriptor, USB spec 9.6.3, page 264-266, Table 9-10
258 9, // bLength; 285 9, // bLength;
259 2, // bDescriptorType; 286 2, // bDescriptorType;
260 LSB(CONFIG1_DESC_SIZE), // wTotalLength 287 LSB(CONFIG1_DESC_SIZE), // wTotalLength
261 MSB(CONFIG1_DESC_SIZE), 288 MSB(CONFIG1_DESC_SIZE),
262 3, // bNumInterfaces 289 4, // bNumInterfaces
263 1, // bConfigurationValue 290 1, // bConfigurationValue
264 0, // iConfiguration 291 0, // iConfiguration
265 0xC0, // bmAttributes 292 0xC0, // bmAttributes
@@ -344,7 +371,34 @@ static uint8_t PROGMEM config1_descriptor[CONFIG1_DESC_SIZE] = {
344 DEBUG_TX_ENDPOINT | 0x80, // bEndpointAddress 371 DEBUG_TX_ENDPOINT | 0x80, // bEndpointAddress
345 0x03, // bmAttributes (0x03=intr) 372 0x03, // bmAttributes (0x03=intr)
346 DEBUG_TX_SIZE, 0, // wMaxPacketSize 373 DEBUG_TX_SIZE, 0, // wMaxPacketSize
347 1 // bInterval 374 1, // bInterval
375
376 // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
377 9, // bLength
378 4, // bDescriptorType
379 EXTRA_INTERFACE, // bInterfaceNumber
380 0, // bAlternateSetting
381 1, // bNumEndpoints
382 0x03, // bInterfaceClass (0x03 = HID)
383 0x00, // bInterfaceSubClass
384 0x00, // bInterfaceProtocol
385 0, // iInterface
386 // HID descriptor, HID 1.11 spec, section 6.2.1
387 9, // bLength
388 0x21, // bDescriptorType
389 0x11, 0x01, // bcdHID
390 0, // bCountryCode
391 1, // bNumDescriptors
392 0x22, // bDescriptorType
393 sizeof(extra_hid_report_desc), // wDescriptorLength
394 0,
395 // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
396 7, // bLength
397 5, // bDescriptorType
398 EXTRA_ENDPOINT | 0x80, // bEndpointAddress
399 0x03, // bmAttributes (0x03=intr)
400 EXTRA_SIZE, 0, // wMaxPacketSize
401 10, // bInterval
348}; 402};
349 403
350// If you're desperate for a little extra code memory, these strings 404// If you're desperate for a little extra code memory, these strings
@@ -392,6 +446,9 @@ static struct descriptor_list_struct {
392 // HID REPORT 446 // HID REPORT
393 {0x2200, DEBUG_INTERFACE, debug_hid_report_desc, sizeof(debug_hid_report_desc)}, 447 {0x2200, DEBUG_INTERFACE, debug_hid_report_desc, sizeof(debug_hid_report_desc)},
394 {0x2100, DEBUG_INTERFACE, config1_descriptor+DEBUG_HID_DESC_OFFSET, 9}, 448 {0x2100, DEBUG_INTERFACE, config1_descriptor+DEBUG_HID_DESC_OFFSET, 9},
449 // HID REPORT
450 {0x2200, EXTRA_INTERFACE, extra_hid_report_desc, sizeof(extra_hid_report_desc)},
451 {0x2100, EXTRA_INTERFACE, config1_descriptor+EXTRA_HID_DESC_OFFSET, 9},
395 // STRING descriptor 452 // STRING descriptor
396 {0x0300, 0x0000, (const uint8_t *)&string0, 4}, 453 {0x0300, 0x0000, (const uint8_t *)&string0, 4},
397 {0x0301, 0x0409, (const uint8_t *)&string1, sizeof(STR_MANUFACTURER)}, 454 {0x0301, 0x0409, (const uint8_t *)&string1, sizeof(STR_MANUFACTURER)},
diff --git a/usb_extra.c b/usb_extra.c
new file mode 100644
index 000000000..94c317d98
--- /dev/null
+++ b/usb_extra.c
@@ -0,0 +1,33 @@
1#include <avr/interrupt.h>
2#include "usb_extra.h"
3
4int8_t usb_extra_send(uint8_t bits)
5{
6 uint8_t intr_state, timeout;
7
8 if (!usb_configured()) return -1;
9 intr_state = SREG;
10 cli();
11 UENUM = EXTRA_ENDPOINT;
12 timeout = UDFNUML + 50;
13 while (1) {
14 // are we ready to transmit?
15 if (UEINTX & (1<<RWAL)) break;
16 SREG = intr_state;
17 // has the USB gone offline?
18 if (!usb_configured()) return -1;
19 // have we waited too long?
20 if (UDFNUML == timeout) return -1;
21 // get ready to try checking again
22 intr_state = SREG;
23 cli();
24 UENUM = EXTRA_ENDPOINT;
25 }
26
27 UEDATX = 1; // report id
28 UEDATX = bits;
29
30 UEINTX = 0x3A;
31 SREG = intr_state;
32 return 0;
33}
diff --git a/usb_extra.h b/usb_extra.h
new file mode 100644
index 000000000..499e6b2fb
--- /dev/null
+++ b/usb_extra.h
@@ -0,0 +1,20 @@
1#ifndef USB_EXTRA_H
2#define USB_EXTRA_H 1
3
4#include <stdint.h>
5#include "usb.h"
6
7
8#define EXTRA_INTERFACE 3
9#define EXTRA_ENDPOINT 4
10#define EXTRA_SIZE 2
11#define EXTRA_BUFFER EP_DOUBLE_BUFFER
12
13#define AUDIO_VOL_UP (1<<0)
14#define AUDIO_VOL_DOWN (1<<1)
15#define AUDIO_MUTE (1<<2)
16
17
18int8_t usb_extra_send(uint8_t bits);
19
20#endif
diff --git a/usb_keycodes.h b/usb_keycodes.h
index b49ecd580..87aa31ca8 100644
--- a/usb_keycodes.h
+++ b/usb_keycodes.h
@@ -77,8 +77,8 @@
77#define KB_SCLN KB_SCOLON 77#define KB_SCLN KB_SCOLON
78#define KB_QUOT KB_QUOTE 78#define KB_QUOT KB_QUOTE
79#define KB_PWR KB_POWER 79#define KB_PWR KB_POWER
80#define KB_VUP KB_VOLUP 80#define KB_VOLU KB_VOLUP
81#define KB_VDWN KB_VOLDOWN 81#define KB_VOLD KB_VOLDOWN
82#define KP_SLSH KP_SLASH 82#define KP_SLSH KP_SLASH
83#define KP_ASTR KP_ASTERISK 83#define KP_ASTR KP_ASTERISK
84#define KP_MINS KP_MINUS 84#define KP_MINS KP_MINUS