aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common.mk9
-rw-r--r--common/action_code.h2
-rw-r--r--common/action_macro.c2
-rw-r--r--common/action_util.c6
-rw-r--r--common/avr/bootloader.c49
-rw-r--r--common/avr/suspend.c2
-rw-r--r--common/command.c198
-rw-r--r--common/keyboard.c6
-rw-r--r--common/keyboard.h8
-rw-r--r--common/keycode.h9
-rw-r--r--common/keymap.c6
-rw-r--r--common/led.h8
-rw-r--r--common/matrix.h4
-rw-r--r--ldscript_keymap_avr35.x268
-rw-r--r--ldscript_keymap_avr5.x6
-rw-r--r--protocol/ibm4704.c45
-rw-r--r--protocol/lufa/lufa.c47
-rw-r--r--protocol/next_kbd.c16
-rw-r--r--protocol/pjrc/main.c2
m---------protocol/usb_hid/USB_Host_Shield_2.0/examples/testusbhostFAT/Arduino_Makefile_master0
m---------protocol/usb_hid/USB_Host_Shield_2.0/examples/testusbhostFAT/RTClib0
m---------protocol/usb_hid/USB_Host_Shield_2.0/examples/testusbhostFAT/generic_storage0
m---------protocol/usb_hid/USB_Host_Shield_2.0/examples/testusbhostFAT/xmem20
-rw-r--r--protocol/usb_hid/leonardo_led.h10
-rw-r--r--protocol/usb_hid/parser.cpp27
-rw-r--r--rules.mk1
26 files changed, 550 insertions, 181 deletions
diff --git a/common.mk b/common.mk
index d22adff51..cb030b331 100644
--- a/common.mk
+++ b/common.mk
@@ -66,7 +66,14 @@ endif
66 66
67ifdef KEYMAP_SECTION_ENABLE 67ifdef KEYMAP_SECTION_ENABLE
68 OPT_DEFS += -DKEYMAP_SECTION_ENABLE 68 OPT_DEFS += -DKEYMAP_SECTION_ENABLE
69 EXTRALDFLAGS = -Wl,-L$(TMK_DIR),-Tldscript_keymap_avr5.x 69
70 ifeq ($(strip $(MCU)),atmega32u2)
71 EXTRALDFLAGS = -Wl,-L$(TMK_DIR),-Tldscript_keymap_avr35.x
72 else ifeq ($(strip $(MCU)),atmega32u4)
73 EXTRALDFLAGS = -Wl,-L$(TMK_DIR),-Tldscript_keymap_avr5.x
74 else
75 EXTRALDFLAGS = $(error no ldscript for keymap section)
76 endif
70endif 77endif
71 78
72# Version string 79# Version string
diff --git a/common/action_code.h b/common/action_code.h
index 32ef07216..4fe9c1d58 100644
--- a/common/action_code.h
+++ b/common/action_code.h
@@ -266,7 +266,7 @@ enum layer_pram_tap_op {
266#define ACTION_LAYER_ON_OFF(layer) ACTION_LAYER_TAP((layer), OP_ON_OFF) 266#define ACTION_LAYER_ON_OFF(layer) ACTION_LAYER_TAP((layer), OP_ON_OFF)
267#define ACTION_LAYER_OFF_ON(layer) ACTION_LAYER_TAP((layer), OP_OFF_ON) 267#define ACTION_LAYER_OFF_ON(layer) ACTION_LAYER_TAP((layer), OP_OFF_ON)
268#define ACTION_LAYER_SET_CLEAR(layer) ACTION_LAYER_TAP((layer), OP_SET_CLEAR) 268#define ACTION_LAYER_SET_CLEAR(layer) ACTION_LAYER_TAP((layer), OP_SET_CLEAR)
269#define ACTION_LAYER_MODS(layer, mods) ACTION_LAYER_TAP((layer), 0xe0 | (mods)&0x0f) 269#define ACTION_LAYER_MODS(layer, mods) ACTION_LAYER_TAP((layer), 0xe0 | ((mods)&0x0f))
270/* With Tapping */ 270/* With Tapping */
271#define ACTION_LAYER_TAP_KEY(layer, key) ACTION_LAYER_TAP((layer), (key)) 271#define ACTION_LAYER_TAP_KEY(layer, key) ACTION_LAYER_TAP((layer), (key))
272#define ACTION_LAYER_TAP_TOGGLE(layer) ACTION_LAYER_TAP((layer), OP_TAP_TOGGLE) 272#define ACTION_LAYER_TAP_TOGGLE(layer) ACTION_LAYER_TAP((layer), OP_TAP_TOGGLE)
diff --git a/common/action_macro.c b/common/action_macro.c
index ba93fc8b2..ffaf125c0 100644
--- a/common/action_macro.c
+++ b/common/action_macro.c
@@ -42,6 +42,7 @@ void action_macro_play(const macro_t *macro_p)
42 dprintf("KEY_DOWN(%02X)\n", macro); 42 dprintf("KEY_DOWN(%02X)\n", macro);
43 if (IS_MOD(macro)) { 43 if (IS_MOD(macro)) {
44 add_weak_mods(MOD_BIT(macro)); 44 add_weak_mods(MOD_BIT(macro));
45 send_keyboard_report();
45 } else { 46 } else {
46 register_code(macro); 47 register_code(macro);
47 } 48 }
@@ -51,6 +52,7 @@ void action_macro_play(const macro_t *macro_p)
51 dprintf("KEY_UP(%02X)\n", macro); 52 dprintf("KEY_UP(%02X)\n", macro);
52 if (IS_MOD(macro)) { 53 if (IS_MOD(macro)) {
53 del_weak_mods(MOD_BIT(macro)); 54 del_weak_mods(MOD_BIT(macro));
55 send_keyboard_report();
54 } else { 56 } else {
55 unregister_code(macro); 57 unregister_code(macro);
56 } 58 }
diff --git a/common/action_util.c b/common/action_util.c
index dbee630d1..f81877dd9 100644
--- a/common/action_util.c
+++ b/common/action_util.c
@@ -76,7 +76,7 @@ void send_keyboard_report(void) {
76void add_key(uint8_t key) 76void add_key(uint8_t key)
77{ 77{
78#ifdef NKRO_ENABLE 78#ifdef NKRO_ENABLE
79 if (keyboard_nkro) { 79 if (keyboard_protocol && keyboard_nkro) {
80 add_key_bit(key); 80 add_key_bit(key);
81 return; 81 return;
82 } 82 }
@@ -87,7 +87,7 @@ void add_key(uint8_t key)
87void del_key(uint8_t key) 87void del_key(uint8_t key)
88{ 88{
89#ifdef NKRO_ENABLE 89#ifdef NKRO_ENABLE
90 if (keyboard_nkro) { 90 if (keyboard_protocol && keyboard_nkro) {
91 del_key_bit(key); 91 del_key_bit(key);
92 return; 92 return;
93 } 93 }
@@ -160,7 +160,7 @@ uint8_t has_anymod(void)
160uint8_t get_first_key(void) 160uint8_t get_first_key(void)
161{ 161{
162#ifdef NKRO_ENABLE 162#ifdef NKRO_ENABLE
163 if (keyboard_nkro) { 163 if (keyboard_protocol && keyboard_nkro) {
164 uint8_t i = 0; 164 uint8_t i = 0;
165 for (; i < KEYBOARD_REPORT_BITS && !keyboard_report->nkro.bits[i]; i++) 165 for (; i < KEYBOARD_REPORT_BITS && !keyboard_report->nkro.bits[i]; i++)
166 ; 166 ;
diff --git a/common/avr/bootloader.c b/common/avr/bootloader.c
index cda295b18..7c744e8c7 100644
--- a/common/avr/bootloader.c
+++ b/common/avr/bootloader.c
@@ -11,12 +11,49 @@
11#endif 11#endif
12 12
13 13
14/* Boot Section Size in *BYTEs* 14/* Bootloader Size in *bytes*
15 * Teensy halfKay 512 15 *
16 * Teensy++ halfKay 1024 16 * AVR Boot section size are defined by setting BOOTSZ fuse in fact. Consult with your MCU datasheet.
17 * Atmel DFU loader 4096 17 * Note that 'Word'(2 bytes) size and address are used in datasheet while TMK uses 'Byte'.
18 * LUFA bootloader 4096 18 *
19 * USBaspLoader 2048 19 *
20 * Size of Bootloaders in bytes:
21 * Atmel DFU loader(ATmega32U4) 4096
22 * Atmel DFU loader(AT90USB128) 8192
23 * LUFA bootloader(ATmega32U4) 4096
24 * Arduino Caterina(ATmega32U4) 4096
25 * USBaspLoader(ATmega***) 2048
26 * Teensy halfKay(ATmega32U4) 512
27 * Teensy++ halfKay(AT90USB128) 1024
28 *
29 *
30 * AVR Boot section is located at the end of Flash memory like the followings.
31 *
32 *
33 * byte Atmel/LUFA(ATMega32u4) byte Atmel(AT90SUB128)
34 * 0x0000 +---------------+ 0x00000 +---------------+
35 * | | | |
36 * | | | |
37 * | Application | | Application |
38 * | | | |
39 * = = = =
40 * | | 32KB-4KB | | 128KB-8KB
41 * 0x6000 +---------------+ 0x1FC00 +---------------+
42 * | Bootloader | 4KB | Bootloader | 8KB
43 * 0x7FFF +---------------+ 0x1FFFF +---------------+
44 *
45 *
46 * byte Teensy(ATMega32u4) byte Teensy++(AT90SUB128)
47 * 0x0000 +---------------+ 0x00000 +---------------+
48 * | | | |
49 * | | | |
50 * | Application | | Application |
51 * | | | |
52 * = = = =
53 * | | 32KB-512B | | 128KB-1KB
54 * 0x7E00 +---------------+ 0x1FC00 +---------------+
55 * | Bootloader | 512B | Bootloader | 1KB
56 * 0x7FFF +---------------+ 0x1FFFF +---------------+
20 */ 57 */
21#ifndef BOOTLOADER_SIZE 58#ifndef BOOTLOADER_SIZE
22#warning To use bootloader_jump() you need to define BOOTLOADER_SIZE in config.h. 59#warning To use bootloader_jump() you need to define BOOTLOADER_SIZE in config.h.
diff --git a/common/avr/suspend.c b/common/avr/suspend.c
index 80243f02b..af99f52b5 100644
--- a/common/avr/suspend.c
+++ b/common/avr/suspend.c
@@ -85,6 +85,8 @@ void suspend_power_down(void)
85 power_down(WDTO_15MS); 85 power_down(WDTO_15MS);
86} 86}
87 87
88__attribute__ ((weak)) void matrix_power_up(void) {}
89__attribute__ ((weak)) void matrix_power_down(void) {}
88bool suspend_wakeup_condition(void) 90bool suspend_wakeup_condition(void)
89{ 91{
90 matrix_power_up(); 92 matrix_power_up();
diff --git a/common/command.c b/common/command.c
index fbaa9f2d7..d59bb01bb 100644
--- a/common/command.c
+++ b/common/command.c
@@ -112,30 +112,33 @@ bool command_console_extra(uint8_t code)
112 ***********************************************************/ 112 ***********************************************************/
113static void command_common_help(void) 113static void command_common_help(void)
114{ 114{
115 print("\n\n----- Command Help -----\n"); 115 print("\n\t- Magic -\n"
116 print("c: enter console mode\n"); 116 "d: debug\n"
117 print("d: toggle debug enable\n"); 117 "x: debug matrix\n"
118 print("x: toggle matrix debug\n"); 118 "k: debug keyboard\n"
119 print("k: toggle keyboard debug\n"); 119 "m: debug mouse\n"
120 print("m: toggle mouse debug\n"); 120 "v: version\n"
121#ifdef SLEEP_LED_ENABLE 121 "s: status\n"
122 print("z: toggle sleep LED test\n"); 122 "c: console mode\n"
123 "0-4: layer0-4(F10-F4)\n"
124 "Paus: bootloader\n"
125
126#ifdef KEYBOARD_LOCK_ENABLE
127 "Caps: Lock\n"
128#endif
129
130#ifdef BOOTMAGIC_ENABLE
131 "e: eeprom\n"
123#endif 132#endif
124 print("v: print device version & info\n"); 133
125 print("t: print timer count\n");
126 print("s: print status\n");
127 print("e: print eeprom config\n");
128#ifdef NKRO_ENABLE 134#ifdef NKRO_ENABLE
129 print("n: toggle NKRO\n"); 135 "n: NKRO\n"
136#endif
137
138#ifdef SLEEP_LED_ENABLE
139 "z: sleep LED test\n"
130#endif 140#endif
131 print("0/F10: switch to Layer0 \n"); 141 );
132 print("1/F1: switch to Layer1 \n");
133 print("2/F2: switch to Layer2 \n");
134 print("3/F3: switch to Layer3 \n");
135 print("4/F4: switch to Layer4 \n");
136 print("PScr: power down/remote wake-up\n");
137 print("Caps: Lock Keyboard(Child Proof)\n");
138 print("Paus: jump to bootloader\n");
139} 142}
140 143
141#ifdef BOOTMAGIC_ENABLE 144#ifdef BOOTMAGIC_ENABLE
@@ -191,6 +194,7 @@ static bool command_common(uint8_t code)
191 print_eeconfig(); 194 print_eeconfig();
192 break; 195 break;
193#endif 196#endif
197#ifdef KEYBOARD_LOCK_ENABLE
194 case KC_CAPSLOCK: 198 case KC_CAPSLOCK:
195 if (host_get_driver()) { 199 if (host_get_driver()) {
196 host_driver = host_get_driver(); 200 host_driver = host_get_driver();
@@ -202,6 +206,7 @@ static bool command_common(uint8_t code)
202 print("Unlocked.\n"); 206 print("Unlocked.\n");
203 } 207 }
204 break; 208 break;
209#endif
205 case KC_H: 210 case KC_H:
206 case KC_SLASH: /* ? */ 211 case KC_SLASH: /* ? */
207 command_common_help(); 212 command_common_help();
@@ -212,58 +217,56 @@ static bool command_common(uint8_t code)
212 debug_mouse = false; 217 debug_mouse = false;
213 debug_enable = false; 218 debug_enable = false;
214 command_console_help(); 219 command_console_help();
215 print("\nEnter Console Mode\n");
216 print("C> "); 220 print("C> ");
217 command_state = CONSOLE; 221 command_state = CONSOLE;
218 break; 222 break;
219 case KC_PAUSE: 223 case KC_PAUSE:
220 clear_keyboard(); 224 clear_keyboard();
221 print("\n\nJump to bootloader... "); 225 print("\n\nbootloader... ");
222 _delay_ms(1000); 226 _delay_ms(1000);
223 bootloader_jump(); // not return 227 bootloader_jump(); // not return
224 print("not supported.\n");
225 break; 228 break;
226 case KC_D: 229 case KC_D:
227 if (debug_enable) { 230 if (debug_enable) {
228 print("\nDEBUG: disabled.\n"); 231 print("\ndebug: off\n");
229 debug_matrix = false; 232 debug_matrix = false;
230 debug_keyboard = false; 233 debug_keyboard = false;
231 debug_mouse = false; 234 debug_mouse = false;
232 debug_enable = false; 235 debug_enable = false;
233 } else { 236 } else {
234 print("\nDEBUG: enabled.\n"); 237 print("\ndebug: on\n");
235 debug_enable = true; 238 debug_enable = true;
236 } 239 }
237 break; 240 break;
238 case KC_X: // debug matrix toggle 241 case KC_X: // debug matrix toggle
239 debug_matrix = !debug_matrix; 242 debug_matrix = !debug_matrix;
240 if (debug_matrix) { 243 if (debug_matrix) {
241 print("\nDEBUG: matrix enabled.\n"); 244 print("\nmatrix: on\n");
242 debug_enable = true; 245 debug_enable = true;
243 } else { 246 } else {
244 print("\nDEBUG: matrix disabled.\n"); 247 print("\nmatrix: off\n");
245 } 248 }
246 break; 249 break;
247 case KC_K: // debug keyboard toggle 250 case KC_K: // debug keyboard toggle
248 debug_keyboard = !debug_keyboard; 251 debug_keyboard = !debug_keyboard;
249 if (debug_keyboard) { 252 if (debug_keyboard) {
250 print("\nDEBUG: keyboard enabled.\n"); 253 print("\nkeyboard: on\n");
251 debug_enable = true; 254 debug_enable = true;
252 } else { 255 } else {
253 print("\nDEBUG: keyboard disabled.\n"); 256 print("\nkeyboard: off\n");
254 } 257 }
255 break; 258 break;
256 case KC_M: // debug mouse toggle 259 case KC_M: // debug mouse toggle
257 debug_mouse = !debug_mouse; 260 debug_mouse = !debug_mouse;
258 if (debug_mouse) { 261 if (debug_mouse) {
259 print("\nDEBUG: mouse enabled.\n"); 262 print("\nmouse: on\n");
260 debug_enable = true; 263 debug_enable = true;
261 } else { 264 } else {
262 print("\nDEBUG: mouse disabled.\n"); 265 print("\nmouse: off\n");
263 } 266 }
264 break; 267 break;
265 case KC_V: // print version & information 268 case KC_V: // print version & information
266 print("\n\n----- Version -----\n"); 269 print("\n\t- Version -\n");
267 print("DESC: " STR(DESCRIPTION) "\n"); 270 print("DESC: " STR(DESCRIPTION) "\n");
268 print("VID: " STR(VENDOR_ID) "(" STR(MANUFACTURER) ") " 271 print("VID: " STR(VENDOR_ID) "(" STR(MANUFACTURER) ") "
269 "PID: " STR(PRODUCT_ID) "(" STR(PRODUCT) ") " 272 "PID: " STR(PRODUCT_ID) "(" STR(PRODUCT) ") "
@@ -307,14 +310,16 @@ static bool command_common(uint8_t code)
307 " AVR-LIBC: " __AVR_LIBC_VERSION_STRING__ 310 " AVR-LIBC: " __AVR_LIBC_VERSION_STRING__
308 " AVR_ARCH: avr" STR(__AVR_ARCH__) "\n"); 311 " AVR_ARCH: avr" STR(__AVR_ARCH__) "\n");
309 break; 312 break;
310 case KC_T: // print timer
311 print_val_hex32(timer_count);
312 break;
313 case KC_S: 313 case KC_S:
314 print("\n\n----- Status -----\n"); 314 print("\n\t- Status -\n");
315 print_val_hex8(host_keyboard_leds()); 315 print_val_hex8(host_keyboard_leds());
316 print_val_hex8(keyboard_protocol); 316 print_val_hex8(keyboard_protocol);
317 print_val_hex8(keyboard_idle); 317 print_val_hex8(keyboard_idle);
318#ifdef NKRO_ENABLE
319 print_val_hex8(keyboard_nkro);
320#endif
321 print_val_hex32(timer_count);
322
318#ifdef PROTOCOL_PJRC 323#ifdef PROTOCOL_PJRC
319 print_val_hex8(UDCON); 324 print_val_hex8(UDCON);
320 print_val_hex8(UDIEN); 325 print_val_hex8(UDIEN);
@@ -334,39 +339,21 @@ static bool command_common(uint8_t code)
334 clear_keyboard(); //Prevents stuck keys. 339 clear_keyboard(); //Prevents stuck keys.
335 keyboard_nkro = !keyboard_nkro; 340 keyboard_nkro = !keyboard_nkro;
336 if (keyboard_nkro) 341 if (keyboard_nkro)
337 print("NKRO: enabled\n"); 342 print("NKRO: on\n");
338 else 343 else
339 print("NKRO: disabled\n"); 344 print("NKRO: off\n");
340 break;
341#endif
342#ifdef EXTRAKEY_ENABLE
343 case KC_PSCREEN:
344 // TODO: Power key should take this feature? otherwise any key during suspend.
345#ifdef PROTOCOL_PJRC
346 if (suspend && remote_wakeup) {
347 usb_remote_wakeup();
348 } else {
349 host_system_send(SYSTEM_POWER_DOWN);
350 host_system_send(0);
351 _delay_ms(500);
352 }
353#else
354 host_system_send(SYSTEM_POWER_DOWN);
355 _delay_ms(100);
356 host_system_send(0);
357 _delay_ms(500);
358#endif
359 break; 345 break;
360#endif 346#endif
361 case KC_ESC: 347 case KC_ESC:
362 case KC_GRV: 348 case KC_GRV:
363 case KC_0: 349 case KC_0:
350 case KC_F10:
364 switch_default_layer(0); 351 switch_default_layer(0);
365 break; 352 break;
366 case KC_1 ... KC_9: 353 case KC_1 ... KC_9:
367 switch_default_layer((code - KC_1) + 1); 354 switch_default_layer((code - KC_1) + 1);
368 break; 355 break;
369 case KC_F1 ... KC_F12: 356 case KC_F1 ... KC_F9:
370 switch_default_layer((code - KC_F1) + 1); 357 switch_default_layer((code - KC_F1) + 1);
371 break; 358 break;
372 default: 359 default:
@@ -382,11 +369,12 @@ static bool command_common(uint8_t code)
382 ***********************************************************/ 369 ***********************************************************/
383static void command_console_help(void) 370static void command_console_help(void)
384{ 371{
385 print("\n\n----- Console Help -----\n"); 372 print("\n\t- Console -\n"
386 print("ESC/q: quit\n"); 373 "ESC/q: quit\n"
387#ifdef MOUSEKEY_ENABLE 374#ifdef MOUSEKEY_ENABLE
388 print("m: mousekey\n"); 375 "m: mousekey\n"
389#endif 376#endif
377 );
390} 378}
391 379
392static bool command_console(uint8_t code) 380static bool command_console(uint8_t code)
@@ -398,14 +386,12 @@ static bool command_console(uint8_t code)
398 break; 386 break;
399 case KC_Q: 387 case KC_Q:
400 case KC_ESC: 388 case KC_ESC:
401 print("\nQuit Console Mode\n");
402 command_state = ONESHOT; 389 command_state = ONESHOT;
403 return false; 390 return false;
404#ifdef MOUSEKEY_ENABLE 391#ifdef MOUSEKEY_ENABLE
405 case KC_M: 392 case KC_M:
406 mousekey_console_help(); 393 mousekey_console_help();
407 print("\nEnter Mousekey Console\n"); 394 print("M> ");
408 print("M0>");
409 command_state = MOUSEKEY; 395 command_state = MOUSEKEY;
410 return true; 396 return true;
411#endif 397#endif
@@ -426,16 +412,17 @@ static uint8_t mousekey_param = 0;
426 412
427static void mousekey_param_print(void) 413static void mousekey_param_print(void)
428{ 414{
429 print("\n\n----- Mousekey Parameters -----\n"); 415 print("\n\t- Values -\n");
430 print("1: mk_delay(*10ms): "); pdec(mk_delay); print("\n"); 416 print("1: delay(*10ms): "); pdec(mk_delay); print("\n");
431 print("2: mk_interval(ms): "); pdec(mk_interval); print("\n"); 417 print("2: interval(ms): "); pdec(mk_interval); print("\n");
432 print("3: mk_max_speed: "); pdec(mk_max_speed); print("\n"); 418 print("3: max_speed: "); pdec(mk_max_speed); print("\n");
433 print("4: mk_time_to_max: "); pdec(mk_time_to_max); print("\n"); 419 print("4: time_to_max: "); pdec(mk_time_to_max); print("\n");
434 print("5: mk_wheel_max_speed: "); pdec(mk_wheel_max_speed); print("\n"); 420 print("5: wheel_max_speed: "); pdec(mk_wheel_max_speed); print("\n");
435 print("6: mk_wheel_time_to_max: "); pdec(mk_wheel_time_to_max); print("\n"); 421 print("6: wheel_time_to_max: "); pdec(mk_wheel_time_to_max); print("\n");
436} 422}
437 423
438#define PRINT_SET_VAL(v) print(#v " = "); print_dec(v); print("\n"); 424//#define PRINT_SET_VAL(v) print(#v " = "); print_dec(v); print("\n");
425#define PRINT_SET_VAL(v) xprintf(#v " = %d\n", (v))
439static void mousekey_param_inc(uint8_t param, uint8_t inc) 426static void mousekey_param_inc(uint8_t param, uint8_t inc)
440{ 427{
441 switch (param) { 428 switch (param) {
@@ -534,24 +521,25 @@ static void mousekey_param_dec(uint8_t param, uint8_t dec)
534 521
535static void mousekey_console_help(void) 522static void mousekey_console_help(void)
536{ 523{
537 print("\n\n----- Mousekey Parameters Help -----\n"); 524 print("\n\t- Mousekey -\n"
538 print("ESC/q: quit\n"); 525 "ESC/q: quit\n"
539 print("1: select mk_delay(*10ms)\n"); 526 "1: delay(*10ms)\n"
540 print("2: select mk_interval(ms)\n"); 527 "2: interval(ms)\n"
541 print("3: select mk_max_speed\n"); 528 "3: max_speed\n"
542 print("4: select mk_time_to_max\n"); 529 "4: time_to_max\n"
543 print("5: select mk_wheel_max_speed\n"); 530 "5: wheel_max_speed\n"
544 print("6: select mk_wheel_time_to_max\n"); 531 "6: wheel_time_to_max\n"
545 print("p: print parameters\n"); 532 "\n"
546 print("d: set default values\n"); 533 "p: print values\n"
547 print("up: increase parameters(+1)\n"); 534 "d: set defaults\n"
548 print("down: decrease parameters(-1)\n"); 535 "up: +1\n"
549 print("pgup: increase parameters(+10)\n"); 536 "down: -1\n"
550 print("pgdown: decrease parameters(-10)\n"); 537 "pgup: +10\n"
551 print("\nspeed = delta * max_speed * (repeat / time_to_max)\n"); 538 "pgdown: -10\n"
552 print("where delta: cursor="); pdec(MOUSEKEY_MOVE_DELTA); 539 "\n"
553 print(", wheel="); pdec(MOUSEKEY_WHEEL_DELTA); print("\n"); 540 "speed = delta * max_speed * (repeat / time_to_max)\n");
554 print("See http://en.wikipedia.org/wiki/Mouse_keys\n"); 541 xprintf("where delta: cursor=%d, wheel=%d\n"
542 "See http://en.wikipedia.org/wiki/Mouse_keys\n", MOUSEKEY_MOVE_DELTA, MOUSEKEY_WHEEL_DELTA);
555} 543}
556 544
557static bool mousekey_console(uint8_t code) 545static bool mousekey_console(uint8_t code)
@@ -563,11 +551,14 @@ static bool mousekey_console(uint8_t code)
563 break; 551 break;
564 case KC_Q: 552 case KC_Q:
565 case KC_ESC: 553 case KC_ESC:
566 mousekey_param = 0; 554 if (mousekey_param) {
567 print("\nQuit Mousekey Console\n"); 555 mousekey_param = 0;
568 print("C> "); 556 } else {
569 command_state = CONSOLE; 557 print("C> ");
570 return false; 558 command_state = CONSOLE;
559 return false;
560 }
561 break;
571 case KC_P: 562 case KC_P:
572 mousekey_param_print(); 563 mousekey_param_print();
573 break; 564 break;
@@ -577,12 +568,7 @@ static bool mousekey_console(uint8_t code)
577 case KC_4: 568 case KC_4:
578 case KC_5: 569 case KC_5:
579 case KC_6: 570 case KC_6:
580 case KC_7:
581 case KC_8:
582 case KC_9:
583 case KC_0:
584 mousekey_param = numkey2num(code); 571 mousekey_param = numkey2num(code);
585 print("selected parameter: "); pdec(mousekey_param); print("\n");
586 break; 572 break;
587 case KC_UP: 573 case KC_UP:
588 mousekey_param_inc(mousekey_param, 1); 574 mousekey_param_inc(mousekey_param, 1);
@@ -603,13 +589,16 @@ static bool mousekey_console(uint8_t code)
603 mk_time_to_max = MOUSEKEY_TIME_TO_MAX; 589 mk_time_to_max = MOUSEKEY_TIME_TO_MAX;
604 mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED; 590 mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED;
605 mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX; 591 mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX;
606 print("set default values.\n"); 592 print("set default\n");
607 break; 593 break;
608 default: 594 default:
609 print("?"); 595 print("?");
610 return false; 596 return false;
611 } 597 }
612 print("M"); pdec(mousekey_param); print("> "); 598 if (mousekey_param)
599 xprintf("M%d> ", mousekey_param);
600 else
601 print("M>" );
613 return true; 602 return true;
614} 603}
615#endif 604#endif
@@ -637,8 +626,7 @@ static uint8_t numkey2num(uint8_t code)
637 626
638static void switch_default_layer(uint8_t layer) 627static void switch_default_layer(uint8_t layer)
639{ 628{
640 print("switch_default_layer: "); print_dec(biton32(default_layer_state)); 629 xprintf("L%d\n", layer);
641 print(" to "); print_dec(layer); print("\n");
642 default_layer_set(1UL<<layer); 630 default_layer_set(1UL<<layer);
643 clear_keyboard(); 631 clear_keyboard();
644} 632}
diff --git a/common/keyboard.c b/common/keyboard.c
index b03b124d7..eb7b096be 100644
--- a/common/keyboard.c
+++ b/common/keyboard.c
@@ -62,6 +62,12 @@ static bool has_ghost_in_row(uint8_t row)
62#endif 62#endif
63 63
64 64
65__attribute__ ((weak)) void matrix_setup(void) {}
66void keyboard_setup(void)
67{
68 matrix_setup();
69}
70
65void keyboard_init(void) 71void keyboard_init(void)
66{ 72{
67 timer_init(); 73 timer_init();
diff --git a/common/keyboard.h b/common/keyboard.h
index 6442716fc..7738251b6 100644
--- a/common/keyboard.h
+++ b/common/keyboard.h
@@ -58,13 +58,15 @@ static inline bool IS_RELEASED(keyevent_t event) { return (!IS_NOEVENT(event) &&
58} 58}
59 59
60 60
61/* it runs once at early stage of startup before keyboard_init. */
62void keyboard_setup(void);
63/* it runs once after initializing host side protocol, debug and MCU peripherals. */
61void keyboard_init(void); 64void keyboard_init(void);
65/* it runs repeatedly in main loop */
62void keyboard_task(void); 66void keyboard_task(void);
67/* it runs when host LED status is updated */
63void keyboard_set_leds(uint8_t leds); 68void keyboard_set_leds(uint8_t leds);
64 69
65__attribute__ ((weak)) void matrix_power_up(void) {}
66__attribute__ ((weak)) void matrix_power_down(void) {}
67
68#ifdef __cplusplus 70#ifdef __cplusplus
69} 71}
70#endif 72#endif
diff --git a/common/keycode.h b/common/keycode.h
index ac4ef00db..448195306 100644
--- a/common/keycode.h
+++ b/common/keycode.h
@@ -156,6 +156,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
156#define KC_WSTP KC_WWW_STOP 156#define KC_WSTP KC_WWW_STOP
157#define KC_WREF KC_WWW_REFRESH 157#define KC_WREF KC_WWW_REFRESH
158#define KC_WFAV KC_WWW_FAVORITES 158#define KC_WFAV KC_WWW_FAVORITES
159/* Jump to bootloader */
160#define KC_BTLD KC_BOOTLOADER
159/* Transparent */ 161/* Transparent */
160#define KC_TRANSPARENT 1 162#define KC_TRANSPARENT 1
161#define KC_TRNS KC_TRANSPARENT 163#define KC_TRNS KC_TRANSPARENT
@@ -214,7 +216,7 @@ enum hid_keyboard_keypad_usage {
214 KC_LBRACKET, 216 KC_LBRACKET,
215 KC_RBRACKET, /* 0x30 */ 217 KC_RBRACKET, /* 0x30 */
216 KC_BSLASH, /* \ (and |) */ 218 KC_BSLASH, /* \ (and |) */
217 KC_NONUS_HASH, /* Non-US # and ~ */ 219 KC_NONUS_HASH, /* Non-US # and ~ (Typically near the Enter key) */
218 KC_SCOLON, /* ; (and :) */ 220 KC_SCOLON, /* ; (and :) */
219 KC_QUOTE, /* ' and " */ 221 KC_QUOTE, /* ' and " */
220 KC_GRAVE, /* Grave accent and tilde */ 222 KC_GRAVE, /* Grave accent and tilde */
@@ -264,7 +266,7 @@ enum hid_keyboard_keypad_usage {
264 KC_KP_9, 266 KC_KP_9,
265 KC_KP_0, 267 KC_KP_0,
266 KC_KP_DOT, 268 KC_KP_DOT,
267 KC_NONUS_BSLASH, /* Non-US \ and | */ 269 KC_NONUS_BSLASH, /* Non-US \ and | (Typically near the Left-Shift key) */
268 KC_APPLICATION, 270 KC_APPLICATION,
269 KC_POWER, 271 KC_POWER,
270 KC_KP_EQUAL, 272 KC_KP_EQUAL,
@@ -426,6 +428,9 @@ enum internal_special_keycodes {
426 KC_MEDIA_FAST_FORWARD, 428 KC_MEDIA_FAST_FORWARD,
427 KC_MEDIA_REWIND, /* 0xBC */ 429 KC_MEDIA_REWIND, /* 0xBC */
428 430
431 /* Jump to bootloader */
432 KC_BOOTLOADER = 0xBF,
433
429 /* Fn key */ 434 /* Fn key */
430 KC_FN0 = 0xC0, 435 KC_FN0 = 0xC0,
431 KC_FN1, 436 KC_FN1,
diff --git a/common/keymap.c b/common/keymap.c
index 9f4fab521..d48923808 100644
--- a/common/keymap.c
+++ b/common/keymap.c
@@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
20#include "action_layer.h" 20#include "action_layer.h"
21#include "action.h" 21#include "action.h"
22#include "action_macro.h" 22#include "action_macro.h"
23#include "wait.h"
23#include "debug.h" 24#include "debug.h"
24 25
25 26
@@ -140,6 +141,11 @@ static action_t keycode_to_action(uint8_t keycode)
140 case KC_TRNS: 141 case KC_TRNS:
141 action.code = ACTION_TRANSPARENT; 142 action.code = ACTION_TRANSPARENT;
142 break; 143 break;
144 case KC_BOOTLOADER:
145 clear_keyboard();
146 wait_ms(50);
147 bootloader_jump(); // not return
148 break;
143 default: 149 default:
144 action.code = ACTION_NO; 150 action.code = ACTION_NO;
145 break; 151 break;
diff --git a/common/led.h b/common/led.h
index 402a247b9..d5fc051bf 100644
--- a/common/led.h
+++ b/common/led.h
@@ -28,6 +28,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
28#define USB_LED_KANA 4 28#define USB_LED_KANA 4
29 29
30 30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
31void led_set(uint8_t usb_led); 35void led_set(uint8_t usb_led);
32 36
37#ifdef __cplusplus
38}
39#endif
40
33#endif 41#endif
diff --git a/common/matrix.h b/common/matrix.h
index 107ee7265..ec6f8cd43 100644
--- a/common/matrix.h
+++ b/common/matrix.h
@@ -43,7 +43,9 @@ extern "C" {
43uint8_t matrix_rows(void); 43uint8_t matrix_rows(void);
44/* number of matrix columns */ 44/* number of matrix columns */
45uint8_t matrix_cols(void); 45uint8_t matrix_cols(void);
46/* intialize matrix for scaning. should be called once. */ 46/* should be called at early stage of startup before matrix_init.(optional) */
47void matrix_setup(void);
48/* intialize matrix for scaning. */
47void matrix_init(void); 49void matrix_init(void);
48/* scan all key states on matrix */ 50/* scan all key states on matrix */
49uint8_t matrix_scan(void); 51uint8_t matrix_scan(void);
diff --git a/ldscript_keymap_avr35.x b/ldscript_keymap_avr35.x
new file mode 100644
index 000000000..6665020af
--- /dev/null
+++ b/ldscript_keymap_avr35.x
@@ -0,0 +1,268 @@
1/*
2 * linker script for configurable keymap
3 *
4 * This adds keymap section which places keymap at fixed address and
5 * is based on binutils-avr ldscripts(/usr/lib/ldscripts/avr5.x).
6 */
7OUTPUT_FORMAT("elf32-avr","elf32-avr","elf32-avr")
8OUTPUT_ARCH(avr:35)
9MEMORY
10{
11 /* With keymap section
12 *
13 * Flash Map of ATMega32U4(32KB)
14 * +------------+ 0x0000
15 * | .vectors |
16 * | .progmem |
17 * | .init0-9 | > text region
18 * | .text |
19 * | .fini9-0 |
20 * | |
21 * |------------| _etext
22 * | .data |
23 * | .bss | > data region
24 * | .noinit |
25 * | |
26 * |------------| 0x6800
27 * | .keymap | > keymap region(2KB)
28 * |------------| 0x7000
29 * | bootloader | 4KB
30 * +------------+ 0x7FFF
31 */
32 text (rx) : ORIGIN = 0, LENGTH = 64K
33 keymap (rw!x) : ORIGIN = 0x6800, LENGTH = 2K
34 data (rw!x) : ORIGIN = 0x800060, LENGTH = 0xffa0
35 eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = 64K
36 fuse (rw!x) : ORIGIN = 0x820000, LENGTH = 1K
37 lock (rw!x) : ORIGIN = 0x830000, LENGTH = 1K
38 signature (rw!x) : ORIGIN = 0x840000, LENGTH = 1K
39}
40SECTIONS
41{
42 /* Read-only sections, merged into text segment: */
43 .hash : { *(.hash) }
44 .dynsym : { *(.dynsym) }
45 .dynstr : { *(.dynstr) }
46 .gnu.version : { *(.gnu.version) }
47 .gnu.version_d : { *(.gnu.version_d) }
48 .gnu.version_r : { *(.gnu.version_r) }
49 .rel.init : { *(.rel.init) }
50 .rela.init : { *(.rela.init) }
51 .rel.text :
52 {
53 *(.rel.text)
54 *(.rel.text.*)
55 *(.rel.gnu.linkonce.t*)
56 }
57 .rela.text :
58 {
59 *(.rela.text)
60 *(.rela.text.*)
61 *(.rela.gnu.linkonce.t*)
62 }
63 .rel.fini : { *(.rel.fini) }
64 .rela.fini : { *(.rela.fini) }
65 .rel.rodata :
66 {
67 *(.rel.rodata)
68 *(.rel.rodata.*)
69 *(.rel.gnu.linkonce.r*)
70 }
71 .rela.rodata :
72 {
73 *(.rela.rodata)
74 *(.rela.rodata.*)
75 *(.rela.gnu.linkonce.r*)
76 }
77 .rel.data :
78 {
79 *(.rel.data)
80 *(.rel.data.*)
81 *(.rel.gnu.linkonce.d*)
82 }
83 .rela.data :
84 {
85 *(.rela.data)
86 *(.rela.data.*)
87 *(.rela.gnu.linkonce.d*)
88 }
89 .rel.ctors : { *(.rel.ctors) }
90 .rela.ctors : { *(.rela.ctors) }
91 .rel.dtors : { *(.rel.dtors) }
92 .rela.dtors : { *(.rela.dtors) }
93 .rel.got : { *(.rel.got) }
94 .rela.got : { *(.rela.got) }
95 .rel.bss : { *(.rel.bss) }
96 .rela.bss : { *(.rela.bss) }
97 .rel.plt : { *(.rel.plt) }
98 .rela.plt : { *(.rela.plt) }
99 /* Internal text space or external memory. */
100 .text :
101 {
102 *(.vectors)
103 KEEP(*(.vectors))
104 /* For data that needs to reside in the lower 64k of progmem. */
105 *(.progmem.gcc*)
106 *(.progmem*)
107 . = ALIGN(2);
108 __trampolines_start = . ;
109 /* The jump trampolines for the 16-bit limited relocs will reside here. */
110 *(.trampolines)
111 *(.trampolines*)
112 __trampolines_end = . ;
113 /* For future tablejump instruction arrays for 3 byte pc devices.
114 We don't relax jump/call instructions within these sections. */
115 *(.jumptables)
116 *(.jumptables*)
117 /* For code that needs to reside in the lower 128k progmem. */
118 *(.lowtext)
119 *(.lowtext*)
120 __ctors_start = . ;
121 *(.ctors)
122 __ctors_end = . ;
123 __dtors_start = . ;
124 *(.dtors)
125 __dtors_end = . ;
126 KEEP(SORT(*)(.ctors))
127 KEEP(SORT(*)(.dtors))
128 /* From this point on, we don't bother about wether the insns are
129 below or above the 16 bits boundary. */
130 *(.init0) /* Start here after reset. */
131 KEEP (*(.init0))
132 *(.init1)
133 KEEP (*(.init1))
134 *(.init2) /* Clear __zero_reg__, set up stack pointer. */
135 KEEP (*(.init2))
136 *(.init3)
137 KEEP (*(.init3))
138 *(.init4) /* Initialize data and BSS. */
139 KEEP (*(.init4))
140 *(.init5)
141 KEEP (*(.init5))
142 *(.init6) /* C++ constructors. */
143 KEEP (*(.init6))
144 *(.init7)
145 KEEP (*(.init7))
146 *(.init8)
147 KEEP (*(.init8))
148 *(.init9) /* Call main(). */
149 KEEP (*(.init9))
150 *(.text)
151 . = ALIGN(2);
152 *(.text.*)
153 . = ALIGN(2);
154 *(.fini9) /* _exit() starts here. */
155 KEEP (*(.fini9))
156 *(.fini8)
157 KEEP (*(.fini8))
158 *(.fini7)
159 KEEP (*(.fini7))
160 *(.fini6) /* C++ destructors. */
161 KEEP (*(.fini6))
162 *(.fini5)
163 KEEP (*(.fini5))
164 *(.fini4)
165 KEEP (*(.fini4))
166 *(.fini3)
167 KEEP (*(.fini3))
168 *(.fini2)
169 KEEP (*(.fini2))
170 *(.fini1)
171 KEEP (*(.fini1))
172 *(.fini0) /* Infinite loop after program termination. */
173 KEEP (*(.fini0))
174 _etext = . ;
175 } > text
176 .data : AT (ADDR (.text) + SIZEOF (.text))
177 {
178 PROVIDE (__data_start = .) ;
179 *(.data)
180 *(.data*)
181 *(.rodata) /* We need to include .rodata here if gcc is used */
182 *(.rodata*) /* with -fdata-sections. */
183 *(.gnu.linkonce.d*)
184 . = ALIGN(2);
185 _edata = . ;
186 PROVIDE (__data_end = .) ;
187 } > data
188 .bss : AT (ADDR (.bss))
189 {
190 PROVIDE (__bss_start = .) ;
191 *(.bss)
192 *(.bss*)
193 *(COMMON)
194 PROVIDE (__bss_end = .) ;
195 } > data
196 __data_load_start = LOADADDR(.data);
197 __data_load_end = __data_load_start + SIZEOF(.data);
198 /* Global data not cleared after reset. */
199 .noinit :
200 {
201 PROVIDE (__noinit_start = .) ;
202 *(.noinit*)
203 PROVIDE (__noinit_end = .) ;
204 _end = . ;
205 PROVIDE (__heap_start = .) ;
206 } > data
207 /* keymap region is located at end of flash
208 * .fn_actions Fn actions definitions
209 * .keymaps Mapping layers
210 */
211 .keymap :
212 {
213 PROVIDE(__keymap_start = .) ;
214 *(.keymap.fn_actions) /* 32*actions = 64bytes */
215 . = ALIGN(0x40);
216 *(.keymap.keymaps) /* rest of .keymap section */
217 *(.keymap*)
218 /* . = ALIGN(0x800); */ /* keymap section takes 2KB- */
219 } > keymap = 0x00 /* zero fill */
220 .eeprom :
221 {
222 *(.eeprom*)
223 __eeprom_end = . ;
224 } > eeprom
225 .fuse :
226 {
227 KEEP(*(.fuse))
228 KEEP(*(.lfuse))
229 KEEP(*(.hfuse))
230 KEEP(*(.efuse))
231 } > fuse
232 .lock :
233 {
234 KEEP(*(.lock*))
235 } > lock
236 .signature :
237 {
238 KEEP(*(.signature*))
239 } > signature
240 /* Stabs debugging sections. */
241 .stab 0 : { *(.stab) }
242 .stabstr 0 : { *(.stabstr) }
243 .stab.excl 0 : { *(.stab.excl) }
244 .stab.exclstr 0 : { *(.stab.exclstr) }
245 .stab.index 0 : { *(.stab.index) }
246 .stab.indexstr 0 : { *(.stab.indexstr) }
247 .comment 0 : { *(.comment) }
248 /* DWARF debug sections.
249 Symbols in the DWARF debugging sections are relative to the beginning
250 of the section so we begin them at 0. */
251 /* DWARF 1 */
252 .debug 0 : { *(.debug) }
253 .line 0 : { *(.line) }
254 /* GNU DWARF 1 extensions */
255 .debug_srcinfo 0 : { *(.debug_srcinfo) }
256 .debug_sfnames 0 : { *(.debug_sfnames) }
257 /* DWARF 1.1 and DWARF 2 */
258 .debug_aranges 0 : { *(.debug_aranges) }
259 .debug_pubnames 0 : { *(.debug_pubnames) }
260 /* DWARF 2 */
261 .debug_info 0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }
262 .debug_abbrev 0 : { *(.debug_abbrev) }
263 .debug_line 0 : { *(.debug_line) }
264 .debug_frame 0 : { *(.debug_frame) }
265 .debug_str 0 : { *(.debug_str) }
266 .debug_loc 0 : { *(.debug_loc) }
267 .debug_macinfo 0 : { *(.debug_macinfo) }
268}
diff --git a/ldscript_keymap_avr5.x b/ldscript_keymap_avr5.x
index c09693e51..9b46e6c36 100644
--- a/ldscript_keymap_avr5.x
+++ b/ldscript_keymap_avr5.x
@@ -1,4 +1,4 @@
1/* 1/*
2 * linker script for configurable keymap 2 * linker script for configurable keymap
3 * 3 *
4 * This adds keymap section which places keymap at fixed address and 4 * This adds keymap section which places keymap at fixed address and
@@ -8,7 +8,7 @@ OUTPUT_FORMAT("elf32-avr","elf32-avr","elf32-avr")
8OUTPUT_ARCH(avr:5) 8OUTPUT_ARCH(avr:5)
9MEMORY 9MEMORY
10{ 10{
11 /* With keymap section 11 /* With keymap section
12 * 12 *
13 * Flash Map of ATMega32U4(32KB) 13 * Flash Map of ATMega32U4(32KB)
14 * +------------+ 0x0000 14 * +------------+ 0x0000
@@ -212,7 +212,7 @@ SECTIONS
212 { 212 {
213 PROVIDE(__keymap_start = .) ; 213 PROVIDE(__keymap_start = .) ;
214 *(.keymap.fn_actions) /* 32*actions = 64bytes */ 214 *(.keymap.fn_actions) /* 32*actions = 64bytes */
215 . = ALIGN(0x40); 215 . = ALIGN(0x40);
216 *(.keymap.keymaps) /* rest of .keymap section */ 216 *(.keymap.keymaps) /* rest of .keymap section */
217 *(.keymap*) 217 *(.keymap*)
218 /* . = ALIGN(0x800); */ /* keymap section takes 2KB- */ 218 /* . = ALIGN(0x800); */ /* keymap section takes 2KB- */
diff --git a/protocol/ibm4704.c b/protocol/ibm4704.c
index a10a5e74d..6a03cd441 100644
--- a/protocol/ibm4704.c
+++ b/protocol/ibm4704.c
@@ -21,9 +21,10 @@ uint8_t ibm4704_error = 0;
21 21
22void ibm4704_init(void) 22void ibm4704_init(void)
23{ 23{
24 inhibit(); // keep keyboard from sending
24 IBM4704_INT_INIT(); 25 IBM4704_INT_INIT();
25 IBM4704_INT_ON(); 26 IBM4704_INT_ON();
26 idle(); 27 idle(); // allow keyboard sending
27} 28}
28 29
29/* 30/*
@@ -104,51 +105,44 @@ uint8_t ibm4704_recv_response(void)
104 return rbuf_dequeue(); 105 return rbuf_dequeue();
105} 106}
106 107
108uint8_t ibm4704_recv(void)
109{
110 if (rbuf_has_data()) {
111 return rbuf_dequeue();
112 } else {
113 return -1;
114 }
115}
116
107/* 117/*
108Keyboard to Host 118Keyboard to Host
109---------------- 119----------------
110Data bits are LSB first and Parity is odd. Clock has around 60us high and 30us low part. 120Data bits are LSB first and Parity is odd. Clock has around 60us high and 30us low part.
111 121
112 ____ __ __ __ __ __ __ __ __ __ ________ 122 ____ __ __ __ __ __ __ __ __ __ _______
113Clock \____/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ 123Clock \_____/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/
114 ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ 124 ____ ____ ____ ____ ____ ____ ____ ____ ____ ____
115Data ____/ X____X____X____X____X____X____X____X____X____X________ 125Data ____/ X____X____X____X____X____X____X____X____X____X________
116 Start 0 1 2 3 4 5 6 7 P Stop 126 Start 0 1 2 3 4 5 6 7 P Stop
117 127
118Start bit: can be long as 300-350us. 128Start bit: can be long as 300-350us.
119Inhibit: Pull Data line down to inhibit keyboard to send. 129Inhibit: Pull Data line down to inhibit keyboard to send.
120Timing: Host reads bit while Clock is hi. 130Timing: Host reads bit while Clock is hi.(rising edge)
121Stop bit: Keyboard pulls down Data line to lo after 9th clock. 131Stop bit: Keyboard pulls down Data line to lo after 9th clock.
122*/ 132*/
123uint8_t ibm4704_recv(void)
124{
125 if (rbuf_has_data()) {
126 return rbuf_dequeue();
127 } else {
128 return -1;
129 }
130}
131
132ISR(IBM4704_INT_VECT) 133ISR(IBM4704_INT_VECT)
133{ 134{
134 static enum { 135 static enum {
135 INIT, START, BIT0, BIT1, BIT2, BIT3, BIT4, BIT5, BIT6, BIT7, PARITY, 136 BIT0, BIT1, BIT2, BIT3, BIT4, BIT5, BIT6, BIT7, PARITY, STOP
136 } state = INIT; 137 } state = BIT0;
137 // LSB first 138 // LSB first
138 static uint8_t data = 0; 139 static uint8_t data = 0;
139 // Odd parity 140 // Odd parity
140 static uint8_t parity = false; 141 static uint8_t parity = false;
141 142
142 ibm4704_error = 0; 143 ibm4704_error = 0;
143 // return unless falling edge
144 if (clock_in()) { goto RETURN; } // why this occurs?
145 144
146 state++;
147 switch (state) { 145 switch (state) {
148 case START:
149 // Data:Low
150 WAIT(data_hi, 10, state);
151 break;
152 case BIT0: 146 case BIT0:
153 case BIT1: 147 case BIT1:
154 case BIT2: 148 case BIT2:
@@ -169,6 +163,10 @@ ISR(IBM4704_INT_VECT)
169 } 163 }
170 if (!parity) 164 if (!parity)
171 goto ERROR; 165 goto ERROR;
166 break;
167 case STOP:
168 // Data:Low
169 WAIT(data_lo, 100, state);
172 rbuf_enqueue(data); 170 rbuf_enqueue(data);
173 ibm4704_error = IBM4704_ERR_NONE; 171 ibm4704_error = IBM4704_ERR_NONE;
174 goto DONE; 172 goto DONE;
@@ -176,13 +174,14 @@ ISR(IBM4704_INT_VECT)
176 default: 174 default:
177 goto ERROR; 175 goto ERROR;
178 } 176 }
177 state++;
179 goto RETURN; 178 goto RETURN;
180ERROR: 179ERROR:
181 ibm4704_error = state; 180 ibm4704_error = state;
182 while (ibm4704_send(0xFE)) _delay_ms(1); // resend 181 while (ibm4704_send(0xFE)) _delay_ms(1); // resend
183 xprintf("R:%02X%02X\n", state, data); 182 xprintf("R:%02X%02X\n", state, data);
184DONE: 183DONE:
185 state = INIT; 184 state = BIT0;
186 data = 0; 185 data = 0;
187 parity = false; 186 parity = false;
188RETURN: 187RETURN:
diff --git a/protocol/lufa/lufa.c b/protocol/lufa/lufa.c
index cdfc7bc6a..345630aa9 100644
--- a/protocol/lufa/lufa.c
+++ b/protocol/lufa/lufa.c
@@ -53,6 +53,7 @@
53#include "lufa.h" 53#include "lufa.h"
54 54
55uint8_t keyboard_idle = 0; 55uint8_t keyboard_idle = 0;
56/* 0: Boot Protocol, 1: Report Protocol(default) */
56uint8_t keyboard_protocol = 1; 57uint8_t keyboard_protocol = 1;
57static uint8_t keyboard_led_stats = 0; 58static uint8_t keyboard_led_stats = 0;
58 59
@@ -179,7 +180,6 @@ void EVENT_USB_Device_Reset(void)
179void EVENT_USB_Device_Suspend() 180void EVENT_USB_Device_Suspend()
180{ 181{
181 print("[S]"); 182 print("[S]");
182 matrix_power_down();
183#ifdef SLEEP_LED_ENABLE 183#ifdef SLEEP_LED_ENABLE
184 sleep_led_enable(); 184 sleep_led_enable();
185#endif 185#endif
@@ -197,13 +197,30 @@ void EVENT_USB_Device_WakeUp()
197#endif 197#endif
198} 198}
199 199
200#ifdef CONSOLE_ENABLE
201static bool console_flush = false;
202#define CONSOLE_FLUSH_SET(b) do { \
203 uint8_t sreg = SREG; cli(); console_flush = b; SREG = sreg; \
204} while (0)
205
206// called every 1ms
200void EVENT_USB_Device_StartOfFrame(void) 207void EVENT_USB_Device_StartOfFrame(void)
201{ 208{
209 static uint8_t count;
210 if (++count % 50) return;
211 count = 0;
212
213 if (!console_flush) return;
202 Console_Task(); 214 Console_Task();
215 console_flush = false;
203} 216}
217#endif
204 218
205/** Event handler for the USB_ConfigurationChanged event. 219/** Event handler for the USB_ConfigurationChanged event.
206 * This is fired when the host sets the current configuration of the USB device after enumeration. 220 * This is fired when the host sets the current configuration of the USB device after enumeration.
221 *
222 * ATMega32u2 supports dual bank(ping-pong mode) only on endpoint 3 and 4,
223 * it is safe to use singl bank for all endpoints.
207 */ 224 */
208void EVENT_USB_Device_ConfigurationChanged(void) 225void EVENT_USB_Device_ConfigurationChanged(void)
209{ 226{
@@ -228,7 +245,7 @@ void EVENT_USB_Device_ConfigurationChanged(void)
228#ifdef CONSOLE_ENABLE 245#ifdef CONSOLE_ENABLE
229 /* Setup Console HID Report Endpoints */ 246 /* Setup Console HID Report Endpoints */
230 ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, 247 ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
231 CONSOLE_EPSIZE, ENDPOINT_BANK_DOUBLE); 248 CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE);
232#if 0 249#if 0
233 ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT, 250 ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT,
234 CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE); 251 CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE);
@@ -333,10 +350,7 @@ void EVENT_USB_Device_ControlRequest(void)
333 Endpoint_ClearSETUP(); 350 Endpoint_ClearSETUP();
334 Endpoint_ClearStatusStage(); 351 Endpoint_ClearStatusStage();
335 352
336 keyboard_protocol = ((USB_ControlRequest.wValue & 0xFF) != 0x00); 353 keyboard_protocol = (USB_ControlRequest.wValue & 0xFF);
337#ifdef NKRO_ENABLE
338 keyboard_nkro = !!keyboard_protocol;
339#endif
340 clear_keyboard(); 354 clear_keyboard();
341 } 355 }
342 } 356 }
@@ -383,7 +397,7 @@ static void send_keyboard(report_keyboard_t *report)
383 397
384 /* Select the Keyboard Report Endpoint */ 398 /* Select the Keyboard Report Endpoint */
385#ifdef NKRO_ENABLE 399#ifdef NKRO_ENABLE
386 if (keyboard_nkro) { 400 if (keyboard_protocol && keyboard_nkro) {
387 /* Report protocol - NKRO */ 401 /* Report protocol - NKRO */
388 Endpoint_SelectEndpoint(NKRO_IN_EPNUM); 402 Endpoint_SelectEndpoint(NKRO_IN_EPNUM);
389 403
@@ -491,6 +505,10 @@ int8_t sendchar(uint8_t c)
491 // Because sendchar() is called so many times, waiting each call causes big lag. 505 // Because sendchar() is called so many times, waiting each call causes big lag.
492 static bool timeouted = false; 506 static bool timeouted = false;
493 507
508 // prevents Console_Task() from running during sendchar() runs.
509 // or char will be lost. These two function is mutually exclusive.
510 CONSOLE_FLUSH_SET(false);
511
494 if (USB_DeviceState != DEVICE_STATE_Configured) 512 if (USB_DeviceState != DEVICE_STATE_Configured)
495 return -1; 513 return -1;
496 514
@@ -524,8 +542,12 @@ int8_t sendchar(uint8_t c)
524 Endpoint_Write_8(c); 542 Endpoint_Write_8(c);
525 543
526 // send when bank is full 544 // send when bank is full
527 if (!Endpoint_IsReadWriteAllowed()) 545 if (!Endpoint_IsReadWriteAllowed()) {
546 while (!(Endpoint_IsINReady()));
528 Endpoint_ClearIN(); 547 Endpoint_ClearIN();
548 } else {
549 CONSOLE_FLUSH_SET(true);
550 }
529 551
530 Endpoint_SelectEndpoint(ep); 552 Endpoint_SelectEndpoint(ep);
531 return 0; 553 return 0;
@@ -544,7 +566,7 @@ int8_t sendchar(uint8_t c)
544/******************************************************************************* 566/*******************************************************************************
545 * main 567 * main
546 ******************************************************************************/ 568 ******************************************************************************/
547static void SetupHardware(void) 569static void setup_mcu(void)
548{ 570{
549 /* Disable watchdog if enabled by bootloader/fuses */ 571 /* Disable watchdog if enabled by bootloader/fuses */
550 MCUSR &= ~(1 << WDRF); 572 MCUSR &= ~(1 << WDRF);
@@ -552,7 +574,10 @@ static void SetupHardware(void)
552 574
553 /* Disable clock division */ 575 /* Disable clock division */
554 clock_prescale_set(clock_div_1); 576 clock_prescale_set(clock_div_1);
577}
555 578
579static void setup_usb(void)
580{
556 // Leonardo needs. Without this USB device is not recognized. 581 // Leonardo needs. Without this USB device is not recognized.
557 USB_Disable(); 582 USB_Disable();
558 583
@@ -566,7 +591,9 @@ static void SetupHardware(void)
566int main(void) __attribute__ ((weak)); 591int main(void) __attribute__ ((weak));
567int main(void) 592int main(void)
568{ 593{
569 SetupHardware(); 594 setup_mcu();
595 keyboard_setup();
596 setup_usb();
570 sei(); 597 sei();
571 598
572 /* wait for USB startup & debug output */ 599 /* wait for USB startup & debug output */
diff --git a/protocol/next_kbd.c b/protocol/next_kbd.c
index a5a07a7a8..fa3034b3f 100644
--- a/protocol/next_kbd.c
+++ b/protocol/next_kbd.c
@@ -59,10 +59,16 @@ static inline void query(void);
59static inline void reset(void); 59static inline void reset(void);
60static inline uint32_t response(void); 60static inline uint32_t response(void);
61 61
62#define out_hi_delay(intervals) do { out_hi(); _delay_us(NEXT_KBD_TIMING * intervals); } while (0); 62/* The keyboard sends signal with 50us pulse width on OUT line
63#define out_lo_delay(intervals) do { out_lo(); _delay_us(NEXT_KBD_TIMING * intervals); } while (0); 63 * while it seems to miss the 50us pulse on In line.
64#define query_delay(intervals) do { query(); _delay_us(NEXT_KBD_TIMING * intervals); } while (0); 64 * next_kbd_set_leds() often fails to sync LED status with 50us
65#define reset_delay(intervals) do { reset(); _delay_us(NEXT_KBD_TIMING * intervals); } while (0); 65 * but it works well with 51us(+1us) on TMK converter(ATMeaga32u2) at least.
66 * TODO: test on Teensy and Pro Micro configuration
67 */
68#define out_hi_delay(intervals) do { out_hi(); _delay_us((NEXT_KBD_TIMING+1) * intervals); } while (0);
69#define out_lo_delay(intervals) do { out_lo(); _delay_us((NEXT_KBD_TIMING+1) * intervals); } while (0);
70#define query_delay(intervals) do { query(); _delay_us((NEXT_KBD_TIMING+1) * intervals); } while (0);
71#define reset_delay(intervals) do { reset(); _delay_us((NEXT_KBD_TIMING+1) * intervals); } while (0);
66 72
67void next_kbd_init(void) 73void next_kbd_init(void)
68{ 74{
@@ -79,6 +85,7 @@ void next_kbd_init(void)
79 85
80void next_kbd_set_leds(bool left, bool right) 86void next_kbd_set_leds(bool left, bool right)
81{ 87{
88 cli();
82 out_lo_delay(9); 89 out_lo_delay(9);
83 90
84 out_hi_delay(3); 91 out_hi_delay(3);
@@ -98,6 +105,7 @@ void next_kbd_set_leds(bool left, bool right)
98 105
99 out_lo_delay(7); 106 out_lo_delay(7);
100 out_hi(); 107 out_hi();
108 sei();
101} 109}
102 110
103#define NEXT_KBD_READ (NEXT_KBD_IN_PIN&(1<<NEXT_KBD_IN_BIT)) 111#define NEXT_KBD_READ (NEXT_KBD_IN_PIN&(1<<NEXT_KBD_IN_BIT))
diff --git a/protocol/pjrc/main.c b/protocol/pjrc/main.c
index e7bdcc059..45eb17d4c 100644
--- a/protocol/pjrc/main.c
+++ b/protocol/pjrc/main.c
@@ -46,6 +46,8 @@ int main(void)
46 // set for 16 MHz clock 46 // set for 16 MHz clock
47 CPU_PRESCALE(0); 47 CPU_PRESCALE(0);
48 48
49 keyboard_setup();
50
49 // Initialize the USB, and then wait for the host to set configuration. 51 // Initialize the USB, and then wait for the host to set configuration.
50 // If the Teensy is powered without a PC connected to the USB port, 52 // If the Teensy is powered without a PC connected to the USB port,
51 // this will wait forever. 53 // this will wait forever.
diff --git a/protocol/usb_hid/USB_Host_Shield_2.0/examples/testusbhostFAT/Arduino_Makefile_master b/protocol/usb_hid/USB_Host_Shield_2.0/examples/testusbhostFAT/Arduino_Makefile_master
deleted file mode 160000
Subproject 94c560c854c7a1dfc35e9de9db05de1b202de6c
diff --git a/protocol/usb_hid/USB_Host_Shield_2.0/examples/testusbhostFAT/RTClib b/protocol/usb_hid/USB_Host_Shield_2.0/examples/testusbhostFAT/RTClib
deleted file mode 160000
Subproject c30fcdf1f112de581de7b145a97630539e5cff4
diff --git a/protocol/usb_hid/USB_Host_Shield_2.0/examples/testusbhostFAT/generic_storage b/protocol/usb_hid/USB_Host_Shield_2.0/examples/testusbhostFAT/generic_storage
deleted file mode 160000
Subproject 77762338286535dabb9c94b87060e33e487ff0f
diff --git a/protocol/usb_hid/USB_Host_Shield_2.0/examples/testusbhostFAT/xmem2 b/protocol/usb_hid/USB_Host_Shield_2.0/examples/testusbhostFAT/xmem2
deleted file mode 160000
Subproject 77b033420485f7d3d35430c0e8d4d844aa89483
diff --git a/protocol/usb_hid/leonardo_led.h b/protocol/usb_hid/leonardo_led.h
deleted file mode 100644
index 6f67a88f5..000000000
--- a/protocol/usb_hid/leonardo_led.h
+++ /dev/null
@@ -1,10 +0,0 @@
1#ifndef LEONARDO_LED_H
2#define LEONARDO_LED_H
3
4// Leonardo "TX" LED for debug
5#define LED_TX_INIT (DDRD |= (1<<5))
6#define LED_TX_ON (PORTD &= ~(1<<5))
7#define LED_TX_OFF (PORTD |= (1<<5))
8#define LED_TX_TOGGLE (PORTD ^= (1<<5))
9
10#endif
diff --git a/protocol/usb_hid/parser.cpp b/protocol/usb_hid/parser.cpp
index 28151f9d5..1a152ff3f 100644
--- a/protocol/usb_hid/parser.cpp
+++ b/protocol/usb_hid/parser.cpp
@@ -10,15 +10,24 @@ uint16_t usb_hid_time_stamp;
10 10
11void KBDReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) 11void KBDReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
12{ 12{
13 ::memcpy(&usb_hid_keyboard_report, buf, sizeof(report_keyboard_t)); 13 bool is_error = false;
14 usb_hid_time_stamp = millis(); 14 report_keyboard_t *report = (report_keyboard_t *)buf;
15
16 dprintf("KBDReport: %02X %02X", report->mods, report->reserved);
17 for (uint8_t i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
18 if (IS_ERROR(report->keys[i])) {
19 is_error = true;
20 }
21 dprintf(" %02X", report->keys[i]);
22 }
23 dprint("\r\n");
15 24
16 debug("KBDReport: "); 25 // ignore error and not send report to computer
17 debug_hex(usb_hid_keyboard_report.mods); 26 if (is_error) {
18 debug(" --"); 27 dprint("Error usage! \r\n");
19 for (uint8_t i = 0; i < 6; i++) { 28 return;
20 debug(" ");
21 debug_hex(usb_hid_keyboard_report.keys[i]);
22 } 29 }
23 debug("\r\n"); 30
31 ::memcpy(&usb_hid_keyboard_report, buf, sizeof(report_keyboard_t));
32 usb_hid_time_stamp = millis();
24} 33}
diff --git a/rules.mk b/rules.mk
index a790f874b..860fc1a93 100644
--- a/rules.mk
+++ b/rules.mk
@@ -124,6 +124,7 @@ CFLAGS += -O$(OPT)
124CFLAGS += -funsigned-char 124CFLAGS += -funsigned-char
125CFLAGS += -funsigned-bitfields 125CFLAGS += -funsigned-bitfields
126CFLAGS += -ffunction-sections 126CFLAGS += -ffunction-sections
127CFLAGS += -fdata-sections
127CFLAGS += -fno-inline-small-functions 128CFLAGS += -fno-inline-small-functions
128CFLAGS += -fpack-struct 129CFLAGS += -fpack-struct
129CFLAGS += -fshort-enums 130CFLAGS += -fshort-enums