aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/command.c1
-rw-r--r--common/host.c5
-rw-r--r--keyboard/macway/keymap.c2
-rw-r--r--protocol/lufa/descriptor.h7
-rw-r--r--protocol/lufa/lufa.c122
-rw-r--r--protocol/lufa/lufa.h15
6 files changed, 91 insertions, 61 deletions
diff --git a/common/command.c b/common/command.c
index e325a5d84..13d37242d 100644
--- a/common/command.c
+++ b/common/command.c
@@ -138,6 +138,7 @@ static uint8_t command_common(void)
138 } 138 }
139 break; 139 break;
140 case KB_S: 140 case KB_S:
141 print("host_keyboard_leds:"); phex(host_keyboard_leds()); print("\n");
141#ifdef HOST_PJRC 142#ifdef HOST_PJRC
142 print("UDCON: "); phex(UDCON); print("\n"); 143 print("UDCON: "); phex(UDCON); print("\n");
143 print("UDIEN: "); phex(UDIEN); print("\n"); 144 print("UDIEN: "); phex(UDIEN); print("\n");
diff --git a/common/host.c b/common/host.c
index cc26d55c2..8dd2abbee 100644
--- a/common/host.c
+++ b/common/host.c
@@ -168,13 +168,16 @@ void host_mouse_send(report_mouse_t *report)
168 168
169void host_system_send(uint16_t data) 169void host_system_send(uint16_t data)
170{ 170{
171 static uint16_t last_data = 0;
172 if (data == last_data) return;
173 last_data = data;
174
171 if (!driver) return; 175 if (!driver) return;
172 (*driver->send_system)(data); 176 (*driver->send_system)(data);
173} 177}
174 178
175void host_consumer_send(uint16_t data) 179void host_consumer_send(uint16_t data)
176{ 180{
177 // TODO: this is needed?
178 static uint16_t last_data = 0; 181 static uint16_t last_data = 0;
179 if (data == last_data) return; 182 if (data == last_data) return;
180 last_data = data; 183 last_data = data;
diff --git a/keyboard/macway/keymap.c b/keyboard/macway/keymap.c
index 5ecea2569..76c0d8b72 100644
--- a/keyboard/macway/keymap.c
+++ b/keyboard/macway/keymap.c
@@ -111,7 +111,7 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
111 * `-----------------------------------------------------------' 111 * `-----------------------------------------------------------'
112 */ 112 */
113 KEYMAP(PWR, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, \ 113 KEYMAP(PWR, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, \
114 CAPS,NO, NO, NO, NO, NO, NO, NO, PSCR,SLCK,BRK, UP, NO, NO, \ 114 CAPS,NO, NO, NO, NO, NO, NO, NO, PSCR,SLCK,BRK, UP, NO, NLCK,\
115 LCTL,VOLD,VOLU,MUTE,NO, NO, PAST,PSLS,HOME,PGUP,LEFT,RGHT,ENT, \ 115 LCTL,VOLD,VOLU,MUTE,NO, NO, PAST,PSLS,HOME,PGUP,LEFT,RGHT,ENT, \
116 LSFT,NO, NO, NO, NO, NO, PPLS,PMNS,END, PGDN,DOWN,RSFT,FN1, \ 116 LSFT,NO, NO, NO, NO, NO, PPLS,PMNS,END, PGDN,DOWN,RSFT,FN1, \
117 NO, LGUI,LALT,SPC, RALT,NO, NO, NO, RCTL), 117 NO, LGUI,LALT,SPC, RALT,NO, NO, NO, RCTL),
diff --git a/protocol/lufa/descriptor.h b/protocol/lufa/descriptor.h
index 19bce999f..001e072e6 100644
--- a/protocol/lufa/descriptor.h
+++ b/protocol/lufa/descriptor.h
@@ -1,3 +1,10 @@
1/*
2 * Copyright 2012 Jun Wako <wakojun@gmail.com>
3 * This file is based on:
4 * LUFA-120219/Demos/Device/Lowlevel/KeyboardMouse
5 * LUFA-120219/Demos/Device/Lowlevel/GenericHID
6 */
7
1/* 8/*
2 LUFA Library 9 LUFA Library
3 Copyright (C) Dean Camera, 2012. 10 Copyright (C) Dean Camera, 2012.
diff --git a/protocol/lufa/lufa.c b/protocol/lufa/lufa.c
index f485e24bf..8fa719bc9 100644
--- a/protocol/lufa/lufa.c
+++ b/protocol/lufa/lufa.c
@@ -46,13 +46,12 @@
46#include "descriptor.h" 46#include "descriptor.h"
47#include "lufa.h" 47#include "lufa.h"
48 48
49static uint8_t idle_duration = 0;
50static uint8_t protocol_report = 1;
49static uint8_t keyboard_led_stats = 0; 51static uint8_t keyboard_led_stats = 0;
50 52
51// TODO: impl Control Request GET_REPORT
52static report_keyboard_t keyboard_report_sent; 53static report_keyboard_t keyboard_report_sent;
53#ifdef MOUSE_ENABLE 54
54static report_mouse_t mouse_report_sent;
55#endif
56 55
57/* Host driver */ 56/* Host driver */
58static uint8_t keyboard_leds(void); 57static uint8_t keyboard_leds(void);
@@ -83,12 +82,8 @@ int main(void)
83 debug_keyboard = true; 82 debug_keyboard = true;
84 debug_mouse = true; 83 debug_mouse = true;
85 84
86/* TODO: can't print here 85 // TODO: can't print here
87 _delay_ms(5000); 86 debug("LUFA init\n");
88 USB_USBTask();
89 print("abcdefg\n");
90 USB_USBTask();
91*/
92 87
93 keyboard_init(); 88 keyboard_init();
94 host_set_driver(&lufa_driver); 89 host_set_driver(&lufa_driver);
@@ -228,19 +223,6 @@ void EVENT_USB_Device_ControlRequest(void)
228 ReportData = (uint8_t*)&keyboard_report_sent; 223 ReportData = (uint8_t*)&keyboard_report_sent;
229 ReportSize = sizeof(keyboard_report_sent); 224 ReportSize = sizeof(keyboard_report_sent);
230 break; 225 break;
231#ifdef MOUSE_ENABLE
232 case MOUSE_INTERFACE:
233 // TODO: test/check
234 ReportData = (uint8_t*)&mouse_report_sent;
235 ReportSize = sizeof(mouse_report_sent);
236 break;
237#endif
238#ifdef EXTRAKEY_ENABLE
239 case EXTRA_INTERFACE:
240 break;
241#endif
242 case CONSOLE_INTERFACE:
243 break;
244 } 226 }
245 227
246 /* Write the report data to the control endpoint */ 228 /* Write the report data to the control endpoint */
@@ -252,35 +234,65 @@ void EVENT_USB_Device_ControlRequest(void)
252 case HID_REQ_SetReport: 234 case HID_REQ_SetReport:
253 if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) 235 if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
254 { 236 {
255 Endpoint_ClearSETUP();
256
257 /* Wait until the LED report has been sent by the host */
258 while (!(Endpoint_IsOUTReceived()))
259 {
260 if (USB_DeviceState == DEVICE_STATE_Unattached)
261 return;
262 }
263 237
264 // Interface 238 // Interface
265 switch (USB_ControlRequest.wIndex) { 239 switch (USB_ControlRequest.wIndex) {
266 case KEYBOARD_INTERFACE: 240 case KEYBOARD_INTERFACE:
267 // TODO: test/check 241 Endpoint_ClearSETUP();
268 /* Read in the LED report from the host */ 242
243 while (!(Endpoint_IsOUTReceived())) {
244 if (USB_DeviceState == DEVICE_STATE_Unattached)
245 return;
246 }
269 keyboard_led_stats = Endpoint_Read_8(); 247 keyboard_led_stats = Endpoint_Read_8();
270 break; 248
271#ifdef MOUSE_ENABLE 249 Endpoint_ClearOUT();
272 case MOUSE_INTERFACE: 250 Endpoint_ClearStatusStage();
273 break;
274#endif
275#ifdef EXTRAKEY_ENABLE
276 case EXTRA_INTERFACE:
277 break;
278#endif
279 case CONSOLE_INTERFACE:
280 break; 251 break;
281 } 252 }
282 253
283 Endpoint_ClearOUT(); 254 }
255
256 break;
257
258 case HID_REQ_GetProtocol:
259 if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
260 {
261 Endpoint_ClearSETUP();
262 while (!(Endpoint_IsINReady()));
263 Endpoint_Write_8(protocol_report);
264 Endpoint_ClearIN();
265 Endpoint_ClearStatusStage();
266 }
267
268 break;
269 case HID_REQ_SetProtocol:
270 if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
271 {
272 Endpoint_ClearSETUP();
273 Endpoint_ClearStatusStage();
274
275 protocol_report = ((USB_ControlRequest.wValue & 0xFF) != 0x00);
276 }
277
278 break;
279 case HID_REQ_SetIdle:
280 if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
281 {
282 Endpoint_ClearSETUP();
283 Endpoint_ClearStatusStage();
284
285 idle_duration = ((USB_ControlRequest.wValue & 0xFF00) >> 8);
286 }
287
288 break;
289 case HID_REQ_GetIdle:
290 if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
291 {
292 Endpoint_ClearSETUP();
293 while (!(Endpoint_IsINReady()));
294 Endpoint_Write_8(idle_duration);
295 Endpoint_ClearIN();
284 Endpoint_ClearStatusStage(); 296 Endpoint_ClearStatusStage();
285 } 297 }
286 298
@@ -329,23 +341,17 @@ static void send_mouse(report_mouse_t *report)
329 /* Finalize the stream transfer to send the last packet */ 341 /* Finalize the stream transfer to send the last packet */
330 Endpoint_ClearIN(); 342 Endpoint_ClearIN();
331 } 343 }
332 mouse_report_sent = *report;
333#endif 344#endif
334} 345}
335 346
336typedef struct {
337 uint8_t report_id;
338 uint16_t usage;
339} __attribute__ ((packed)) report_extra_t;
340
341static void send_system(uint16_t data) 347static void send_system(uint16_t data)
342{ 348{
349 report_extra_t r = {
350 .report_id = REPORT_ID_SYSTEM,
351 .usage = data
352 };
343 Endpoint_SelectEndpoint(EXTRA_IN_EPNUM); 353 Endpoint_SelectEndpoint(EXTRA_IN_EPNUM);
344 if (Endpoint_IsReadWriteAllowed()) { 354 if (Endpoint_IsReadWriteAllowed()) {
345 report_extra_t r = {
346 .report_id = REPORT_ID_SYSTEM,
347 .usage = data
348 };
349 Endpoint_Write_Stream_LE(&r, sizeof(report_extra_t), NULL); 355 Endpoint_Write_Stream_LE(&r, sizeof(report_extra_t), NULL);
350 Endpoint_ClearIN(); 356 Endpoint_ClearIN();
351 } 357 }
@@ -353,12 +359,12 @@ static void send_system(uint16_t data)
353 359
354static void send_consumer(uint16_t data) 360static void send_consumer(uint16_t data)
355{ 361{
362 report_extra_t r = {
363 .report_id = REPORT_ID_CONSUMER,
364 .usage = data
365 };
356 Endpoint_SelectEndpoint(EXTRA_IN_EPNUM); 366 Endpoint_SelectEndpoint(EXTRA_IN_EPNUM);
357 if (Endpoint_IsReadWriteAllowed()) { 367 if (Endpoint_IsReadWriteAllowed()) {
358 report_extra_t r = {
359 .report_id = REPORT_ID_CONSUMER,
360 .usage = data
361 };
362 Endpoint_Write_Stream_LE(&r, sizeof(report_extra_t), NULL); 368 Endpoint_Write_Stream_LE(&r, sizeof(report_extra_t), NULL);
363 Endpoint_ClearIN(); 369 Endpoint_ClearIN();
364 } 370 }
diff --git a/protocol/lufa/lufa.h b/protocol/lufa/lufa.h
index efb8c3837..71c279b0d 100644
--- a/protocol/lufa/lufa.h
+++ b/protocol/lufa/lufa.h
@@ -1,3 +1,10 @@
1/*
2 * Copyright 2012 Jun Wako <wakojun@gmail.com>
3 * This file is based on:
4 * LUFA-120219/Demos/Device/Lowlevel/KeyboardMouse
5 * LUFA-120219/Demos/Device/Lowlevel/GenericHID
6 */
7
1/* 8/*
2 LUFA Library 9 LUFA Library
3 Copyright (C) Dean Camera, 2012. 10 Copyright (C) Dean Camera, 2012.
@@ -32,7 +39,6 @@
32#ifndef _LUFA_H_ 39#ifndef _LUFA_H_
33#define _LUFA_H_ 40#define _LUFA_H_
34 41
35 /* Includes: */
36#include <avr/io.h> 42#include <avr/io.h>
37#include <avr/wdt.h> 43#include <avr/wdt.h>
38#include <avr/power.h> 44#include <avr/power.h>
@@ -42,4 +48,11 @@
42#include <LUFA/Version.h> 48#include <LUFA/Version.h>
43#include <LUFA/Drivers/USB/USB.h> 49#include <LUFA/Drivers/USB/USB.h>
44 50
51
52/* extra report structure */
53typedef struct {
54 uint8_t report_id;
55 uint16_t usage;
56} __attribute__ ((packed)) report_extra_t;
57
45#endif 58#endif