aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2014-11-24 13:50:33 +0900
committertmk <nobody@nowhere>2014-11-24 13:50:33 +0900
commit363950982a291c3bfa03ac6362061b1d37dc06b0 (patch)
treec46fc53fe00137ced3c8edd3d0766ee844f77516
parenteb90ed6238426db9367e294abfaefb5de07564f5 (diff)
parent60096e11c77980ca6b54674c5b68248e8aa15d8d (diff)
downloadqmk_firmware-363950982a291c3bfa03ac6362061b1d37dc06b0.tar.gz
qmk_firmware-363950982a291c3bfa03ac6362061b1d37dc06b0.zip
Merge branch 'rn42' into merge_rn42
Conflicts: .gitignore common.mk common/debug_config.h common/print.h
-rw-r--r--.gitignore2
-rw-r--r--common.mk12
-rw-r--r--common/action.c2
-rw-r--r--common/action.h13
-rw-r--r--common/action_layer.c2
-rw-r--r--common/action_layer.h2
-rw-r--r--common/action_macro.c8
-rw-r--r--common/action_macro.h8
-rw-r--r--common/action_util.c20
-rw-r--r--common/action_util.h9
-rw-r--r--common/avr/bootloader.c (renamed from common/bootloader.c)0
-rw-r--r--common/avr/eeconfig.c (renamed from common/eeconfig.c)0
-rw-r--r--common/avr/suspend.c117
-rw-r--r--common/avr/suspend_avr.h27
-rw-r--r--common/avr/timer.c (renamed from common/timer.c)1
-rw-r--r--common/avr/timer_avr.h42
-rw-r--r--common/avr/xprintf.S (renamed from common/xprintf.S)0
-rw-r--r--common/avr/xprintf.h (renamed from common/xprintf.h)0
-rw-r--r--common/bootmagic.c2
-rw-r--r--common/command.c28
-rw-r--r--common/command.h10
-rw-r--r--common/debug.h112
-rw-r--r--common/host.c4
-rw-r--r--common/keyboard.c3
-rw-r--r--common/keyboard.h11
-rw-r--r--common/keymap.c5
-rw-r--r--common/keymap.h2
-rw-r--r--common/matrix.h5
-rw-r--r--common/mbed/bootloader.c4
-rw-r--r--common/mbed/suspend.c6
-rw-r--r--common/mbed/timer.c41
-rw-r--r--common/mbed/xprintf.cpp46
-rw-r--r--common/mbed/xprintf.h17
-rw-r--r--common/mousekey.c1
-rw-r--r--common/mousekey.h20
-rw-r--r--common/nodebug.h30
-rw-r--r--common/print.c22
-rw-r--r--common/print.h144
-rw-r--r--common/progmem.h12
-rw-r--r--common/report.h22
-rw-r--r--common/suspend.c76
-rw-r--r--common/suspend.h23
-rw-r--r--common/timer.h18
-rw-r--r--common/wait.h20
-rw-r--r--converter/ps2_usb/Makefile.mbed44
-rw-r--r--converter/ps2_usb/config_mbed.h60
-rw-r--r--converter/ps2_usb/keymap_common.c3
-rw-r--r--converter/ps2_usb/keymap_common.h1
-rw-r--r--converter/ps2_usb/main.cpp46
-rw-r--r--converter/ps2_usb/matrix.c3
-rw-r--r--keyboard/hhkb/keymap_common.c2
-rw-r--r--keyboard/hhkb_rn42/MEMO.txt523
-rw-r--r--keyboard/hhkb_rn42/Makefile157
-rw-r--r--keyboard/hhkb_rn42/PowerSave.txt102
-rw-r--r--keyboard/hhkb_rn42/config.h112
-rw-r--r--keyboard/hhkb_rn42/hhkb_avr.h164
-rw-r--r--keyboard/hhkb_rn42/keymap_common.c33
-rw-r--r--keyboard/hhkb_rn42/keymap_common.h84
-rw-r--r--keyboard/hhkb_rn42/keymap_hasu.c282
-rw-r--r--keyboard/hhkb_rn42/keymap_jp.c50
-rw-r--r--keyboard/hhkb_rn42/led.c33
-rw-r--r--keyboard/hhkb_rn42/matrix.c191
-rw-r--r--keyboard/hhkb_rn42/rn42.mk12
-rw-r--r--keyboard/hhkb_rn42/rn42/battery.c136
-rw-r--r--keyboard/hhkb_rn42/rn42/battery.h35
-rw-r--r--keyboard/hhkb_rn42/rn42/main.c102
-rw-r--r--keyboard/hhkb_rn42/rn42/rn42.c208
-rw-r--r--keyboard/hhkb_rn42/rn42/rn42.h20
-rw-r--r--keyboard/hhkb_rn42/rn42/rn42_task.c294
-rw-r--r--keyboard/hhkb_rn42/rn42/rn42_task.h10
-rw-r--r--keyboard/hhkb_rn42/rn42/suart.S156
-rw-r--r--keyboard/hhkb_rn42/rn42/suart.h8
-rw-r--r--keyboard/mbed_onekey/Makefile33
-rw-r--r--keyboard/mbed_onekey/config.h7
-rw-r--r--keyboard/mbed_onekey/main.cpp33
-rw-r--r--protocol.mk1
-rw-r--r--protocol/lufa/lufa.c15
-rw-r--r--protocol/mbed/HIDKeyboard.cpp271
-rw-r--r--protocol/mbed/HIDKeyboard.h31
-rw-r--r--protocol/mbed/mbed_driver.cpp41
-rw-r--r--protocol/mbed/mbed_driver.h3
-rw-r--r--protocol/ps2.h65
-rw-r--r--protocol/ps2_busywait.c16
-rw-r--r--protocol/ps2_io.h15
-rw-r--r--protocol/ps2_io_avr.c74
-rw-r--r--protocol/ps2_io_mbed.c60
-rw-r--r--protocol/serial_uart.c21
-rw-r--r--rules.mk1
-rw-r--r--tool/mbed/common.mk79
-rw-r--r--tool/mbed/gcc.mk80
-rw-r--r--tool/mbed/lpc-vector-checksum.c99
-rw-r--r--tool/mbed/mbed.mk99
92 files changed, 4462 insertions, 402 deletions
diff --git a/.gitignore b/.gitignore
index 0fd85b531..f3f46872a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,3 +9,5 @@
9*.sym 9*.sym
10tags 10tags
11*~ 11*~
12build/
13*.bak
diff --git a/common.mk b/common.mk
index 1cffc3cc2..b854f09cd 100644
--- a/common.mk
+++ b/common.mk
@@ -7,19 +7,19 @@ SRC += $(COMMON_DIR)/host.c \
7 $(COMMON_DIR)/action_layer.c \ 7 $(COMMON_DIR)/action_layer.c \
8 $(COMMON_DIR)/action_util.c \ 8 $(COMMON_DIR)/action_util.c \
9 $(COMMON_DIR)/keymap.c \ 9 $(COMMON_DIR)/keymap.c \
10 $(COMMON_DIR)/timer.c \
11 $(COMMON_DIR)/print.c \ 10 $(COMMON_DIR)/print.c \
12 $(COMMON_DIR)/debug.c \ 11 $(COMMON_DIR)/debug.c \
13 $(COMMON_DIR)/bootloader.c \ 12 $(COMMON_DIR)/util.c \
14 $(COMMON_DIR)/suspend.c \ 13 $(COMMON_DIR)/avr/suspend.c \
15 $(COMMON_DIR)/xprintf.S \ 14 $(COMMON_DIR)/avr/xprintf.S \
16 $(COMMON_DIR)/util.c 15 $(COMMON_DIR)/avr/timer.c \
16 $(COMMON_DIR)/avr/bootloader.c
17 17
18 18
19# Option modules 19# Option modules
20ifdef BOOTMAGIC_ENABLE 20ifdef BOOTMAGIC_ENABLE
21 SRC += $(COMMON_DIR)/bootmagic.c 21 SRC += $(COMMON_DIR)/bootmagic.c
22 SRC += $(COMMON_DIR)/eeconfig.c 22 SRC += $(COMMON_DIR)/avr/eeconfig.c
23 OPT_DEFS += -DBOOTMAGIC_ENABLE 23 OPT_DEFS += -DBOOTMAGIC_ENABLE
24endif 24endif
25 25
diff --git a/common/action.c b/common/action.c
index 83bc8a618..ec8eeae7b 100644
--- a/common/action.c
+++ b/common/action.c
@@ -509,7 +509,7 @@ void clear_keyboard_but_mods(void)
509#endif 509#endif
510} 510}
511 511
512bool is_tap_key(key_t key) 512bool is_tap_key(keypos_t key)
513{ 513{
514 action_t action = layer_switch_get_action(key); 514 action_t action = layer_switch_get_action(key);
515 515
diff --git a/common/action.h b/common/action.h
index 077711c23..8a4736d7b 100644
--- a/common/action.h
+++ b/common/action.h
@@ -25,6 +25,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
25#include "action_macro.h" 25#include "action_macro.h"
26 26
27 27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
28/* tapping count and state */ 32/* tapping count and state */
29typedef struct { 33typedef struct {
30 bool interrupted :1; 34 bool interrupted :1;
@@ -42,12 +46,11 @@ typedef struct {
42#endif 46#endif
43} keyrecord_t; 47} keyrecord_t;
44 48
45
46/* Execute action per keyevent */ 49/* Execute action per keyevent */
47void action_exec(keyevent_t event); 50void action_exec(keyevent_t event);
48 51
49/* action for key */ 52/* action for key */
50action_t action_for_key(uint8_t layer, key_t key); 53action_t action_for_key(uint8_t layer, keypos_t key);
51 54
52/* macro */ 55/* macro */
53const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt); 56const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt);
@@ -65,11 +68,15 @@ void unregister_mods(uint8_t mods);
65void clear_keyboard(void); 68void clear_keyboard(void);
66void clear_keyboard_but_mods(void); 69void clear_keyboard_but_mods(void);
67void layer_switch(uint8_t new_layer); 70void layer_switch(uint8_t new_layer);
68bool is_tap_key(key_t key); 71bool is_tap_key(keypos_t key);
69 72
70/* debug */ 73/* debug */
71void debug_event(keyevent_t event); 74void debug_event(keyevent_t event);
72void debug_record(keyrecord_t record); 75void debug_record(keyrecord_t record);
73void debug_action(action_t action); 76void debug_action(action_t action);
74 77
78#ifdef __cplusplus
79}
80#endif
81
75#endif /* ACTION_H */ 82#endif /* ACTION_H */
diff --git a/common/action_layer.c b/common/action_layer.c
index 526e24d53..c535615f4 100644
--- a/common/action_layer.c
+++ b/common/action_layer.c
@@ -112,7 +112,7 @@ void layer_debug(void)
112 112
113 113
114 114
115action_t layer_switch_get_action(key_t key) 115action_t layer_switch_get_action(keypos_t key)
116{ 116{
117 action_t action; 117 action_t action;
118 action.code = ACTION_TRANSPARENT; 118 action.code = ACTION_TRANSPARENT;
diff --git a/common/action_layer.h b/common/action_layer.h
index 034e00027..b6da353cf 100644
--- a/common/action_layer.h
+++ b/common/action_layer.h
@@ -72,6 +72,6 @@ void layer_xor(uint32_t state);
72 72
73 73
74/* return action depending on current layer status */ 74/* return action depending on current layer status */
75action_t layer_switch_get_action(key_t key); 75action_t layer_switch_get_action(keypos_t key);
76 76
77#endif 77#endif
diff --git a/common/action_macro.c b/common/action_macro.c
index d85aee379..ba93fc8b2 100644
--- a/common/action_macro.c
+++ b/common/action_macro.c
@@ -14,10 +14,10 @@ GNU General Public License for more details.
14You should have received a copy of the GNU General Public License 14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>. 15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/ 16*/
17#include <util/delay.h>
18#include "action.h" 17#include "action.h"
19#include "action_util.h" 18#include "action_util.h"
20#include "action_macro.h" 19#include "action_macro.h"
20#include "wait.h"
21 21
22#ifdef DEBUG_ACTION 22#ifdef DEBUG_ACTION
23#include "debug.h" 23#include "debug.h"
@@ -28,7 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
28 28
29#ifndef NO_ACTION_MACRO 29#ifndef NO_ACTION_MACRO
30 30
31#define MACRO_READ() (macro = pgm_read_byte(macro_p++)) 31#define MACRO_READ() (macro = MACRO_GET(macro_p++))
32void action_macro_play(const macro_t *macro_p) 32void action_macro_play(const macro_t *macro_p)
33{ 33{
34 macro_t macro = END; 34 macro_t macro = END;
@@ -58,7 +58,7 @@ void action_macro_play(const macro_t *macro_p)
58 case WAIT: 58 case WAIT:
59 MACRO_READ(); 59 MACRO_READ();
60 dprintf("WAIT(%u)\n", macro); 60 dprintf("WAIT(%u)\n", macro);
61 { uint8_t ms = macro; while (ms--) _delay_ms(1); } 61 { uint8_t ms = macro; while (ms--) wait_ms(1); }
62 break; 62 break;
63 case INTERVAL: 63 case INTERVAL:
64 interval = MACRO_READ(); 64 interval = MACRO_READ();
@@ -77,7 +77,7 @@ void action_macro_play(const macro_t *macro_p)
77 return; 77 return;
78 } 78 }
79 // interval 79 // interval
80 { uint8_t ms = interval; while (ms--) _delay_ms(1); } 80 { uint8_t ms = interval; while (ms--) wait_ms(1); }
81 } 81 }
82} 82}
83#endif 83#endif
diff --git a/common/action_macro.h b/common/action_macro.h
index 621826308..aedc32ec6 100644
--- a/common/action_macro.h
+++ b/common/action_macro.h
@@ -17,12 +17,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
17#ifndef ACTION_MACRO_H 17#ifndef ACTION_MACRO_H
18#define ACTION_MACRO_H 18#define ACTION_MACRO_H
19#include <stdint.h> 19#include <stdint.h>
20#include <avr/pgmspace.h> 20#include "progmem.h"
21 21
22 22
23#define MACRO_NONE 0 23#define MACRO_NONE 0
24#define MACRO(...) ({ static const macro_t __m[] PROGMEM = { __VA_ARGS__ }; &__m[0]; }) 24#define MACRO(...) ({ static const macro_t __m[] PROGMEM = { __VA_ARGS__ }; &__m[0]; })
25 25#define MACRO_GET(p) pgm_read_byte(p)
26 26
27typedef uint8_t macro_t; 27typedef uint8_t macro_t;
28 28
diff --git a/common/action_util.c b/common/action_util.c
index 5f44b3812..dbee630d1 100644
--- a/common/action_util.c
+++ b/common/action_util.c
@@ -31,8 +31,8 @@ static uint8_t real_mods = 0;
31static uint8_t weak_mods = 0; 31static uint8_t weak_mods = 0;
32 32
33#ifdef USB_6KRO_ENABLE 33#ifdef USB_6KRO_ENABLE
34#define RO_ADD(a, b) ((a + b) % REPORT_KEYS) 34#define RO_ADD(a, b) ((a + b) % KEYBOARD_REPORT_KEYS)
35#define RO_SUB(a, b) ((a - b + REPORT_KEYS) % REPORT_KEYS) 35#define RO_SUB(a, b) ((a - b + KEYBOARD_REPORT_KEYS) % KEYBOARD_REPORT_KEYS)
36#define RO_INC(a) RO_ADD(a, 1) 36#define RO_INC(a) RO_ADD(a, 1)
37#define RO_DEC(a) RO_SUB(a, 1) 37#define RO_DEC(a) RO_SUB(a, 1)
38static int8_t cb_head = 0; 38static int8_t cb_head = 0;
@@ -98,7 +98,7 @@ void del_key(uint8_t key)
98void clear_keys(void) 98void clear_keys(void)
99{ 99{
100 // not clear mods 100 // not clear mods
101 for (int8_t i = 1; i < REPORT_SIZE; i++) { 101 for (int8_t i = 1; i < KEYBOARD_REPORT_SIZE; i++) {
102 keyboard_report->raw[i] = 0; 102 keyboard_report->raw[i] = 0;
103 } 103 }
104} 104}
@@ -145,7 +145,7 @@ void clear_oneshot_mods(void)
145uint8_t has_anykey(void) 145uint8_t has_anykey(void)
146{ 146{
147 uint8_t cnt = 0; 147 uint8_t cnt = 0;
148 for (uint8_t i = 1; i < REPORT_SIZE; i++) { 148 for (uint8_t i = 1; i < KEYBOARD_REPORT_SIZE; i++) {
149 if (keyboard_report->raw[i]) 149 if (keyboard_report->raw[i])
150 cnt++; 150 cnt++;
151 } 151 }
@@ -162,7 +162,7 @@ uint8_t get_first_key(void)
162#ifdef NKRO_ENABLE 162#ifdef NKRO_ENABLE
163 if (keyboard_nkro) { 163 if (keyboard_nkro) {
164 uint8_t i = 0; 164 uint8_t i = 0;
165 for (; i < REPORT_BITS && !keyboard_report->nkro.bits[i]; i++) 165 for (; i < KEYBOARD_REPORT_BITS && !keyboard_report->nkro.bits[i]; i++)
166 ; 166 ;
167 return i<<3 | biton(keyboard_report->nkro.bits[i]); 167 return i<<3 | biton(keyboard_report->nkro.bits[i]);
168 } 168 }
@@ -234,7 +234,7 @@ static inline void add_key_byte(uint8_t code)
234#else 234#else
235 int8_t i = 0; 235 int8_t i = 0;
236 int8_t empty = -1; 236 int8_t empty = -1;
237 for (; i < REPORT_KEYS; i++) { 237 for (; i < KEYBOARD_REPORT_KEYS; i++) {
238 if (keyboard_report->keys[i] == code) { 238 if (keyboard_report->keys[i] == code) {
239 break; 239 break;
240 } 240 }
@@ -242,7 +242,7 @@ static inline void add_key_byte(uint8_t code)
242 empty = i; 242 empty = i;
243 } 243 }
244 } 244 }
245 if (i == REPORT_KEYS) { 245 if (i == KEYBOARD_REPORT_KEYS) {
246 if (empty != -1) { 246 if (empty != -1) {
247 keyboard_report->keys[empty] = code; 247 keyboard_report->keys[empty] = code;
248 } 248 }
@@ -278,7 +278,7 @@ static inline void del_key_byte(uint8_t code)
278 } while (i != cb_tail); 278 } while (i != cb_tail);
279 } 279 }
280#else 280#else
281 for (uint8_t i = 0; i < REPORT_KEYS; i++) { 281 for (uint8_t i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
282 if (keyboard_report->keys[i] == code) { 282 if (keyboard_report->keys[i] == code) {
283 keyboard_report->keys[i] = 0; 283 keyboard_report->keys[i] = 0;
284 } 284 }
@@ -289,7 +289,7 @@ static inline void del_key_byte(uint8_t code)
289#ifdef NKRO_ENABLE 289#ifdef NKRO_ENABLE
290static inline void add_key_bit(uint8_t code) 290static inline void add_key_bit(uint8_t code)
291{ 291{
292 if ((code>>3) < REPORT_BITS) { 292 if ((code>>3) < KEYBOARD_REPORT_BITS) {
293 keyboard_report->nkro.bits[code>>3] |= 1<<(code&7); 293 keyboard_report->nkro.bits[code>>3] |= 1<<(code&7);
294 } else { 294 } else {
295 dprintf("add_key_bit: can't add: %02X\n", code); 295 dprintf("add_key_bit: can't add: %02X\n", code);
@@ -298,7 +298,7 @@ static inline void add_key_bit(uint8_t code)
298 298
299static inline void del_key_bit(uint8_t code) 299static inline void del_key_bit(uint8_t code)
300{ 300{
301 if ((code>>3) < REPORT_BITS) { 301 if ((code>>3) < KEYBOARD_REPORT_BITS) {
302 keyboard_report->nkro.bits[code>>3] &= ~(1<<(code&7)); 302 keyboard_report->nkro.bits[code>>3] &= ~(1<<(code&7));
303 } else { 303 } else {
304 dprintf("del_key_bit: can't del: %02X\n", code); 304 dprintf("del_key_bit: can't del: %02X\n", code);
diff --git a/common/action_util.h b/common/action_util.h
index f9d3161a8..a955638b4 100644
--- a/common/action_util.h
+++ b/common/action_util.h
@@ -20,6 +20,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
20#include <stdint.h> 20#include <stdint.h>
21#include "report.h" 21#include "report.h"
22 22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
23extern report_keyboard_t *keyboard_report; 27extern report_keyboard_t *keyboard_report;
24 28
25void send_keyboard_report(void); 29void send_keyboard_report(void);
@@ -54,4 +58,9 @@ void oneshot_disable(void);
54uint8_t has_anykey(void); 58uint8_t has_anykey(void);
55uint8_t has_anymod(void); 59uint8_t has_anymod(void);
56uint8_t get_first_key(void); 60uint8_t get_first_key(void);
61
62#ifdef __cplusplus
63}
64#endif
65
57#endif 66#endif
diff --git a/common/bootloader.c b/common/avr/bootloader.c
index cda295b18..cda295b18 100644
--- a/common/bootloader.c
+++ b/common/avr/bootloader.c
diff --git a/common/eeconfig.c b/common/avr/eeconfig.c
index 5bd47dc6a..5bd47dc6a 100644
--- a/common/eeconfig.c
+++ b/common/avr/eeconfig.c
diff --git a/common/avr/suspend.c b/common/avr/suspend.c
new file mode 100644
index 000000000..66a579fd7
--- /dev/null
+++ b/common/avr/suspend.c
@@ -0,0 +1,117 @@
1#include <stdbool.h>
2#include <avr/sleep.h>
3#include <avr/wdt.h>
4#include <avr/interrupt.h>
5#include "matrix.h"
6#include "action.h"
7#include "backlight.h"
8#include "suspend_avr.h"
9#include "suspend.h"
10#ifdef PROTOCOL_LUFA
11#include "lufa.h"
12#endif
13
14
15#define wdt_intr_enable(value) \
16__asm__ __volatile__ ( \
17 "in __tmp_reg__,__SREG__" "\n\t" \
18 "cli" "\n\t" \
19 "wdr" "\n\t" \
20 "sts %0,%1" "\n\t" \
21 "out __SREG__,__tmp_reg__" "\n\t" \
22 "sts %0,%2" "\n\t" \
23 : /* no outputs */ \
24 : "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \
25 "r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)), \
26 "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | \
27 _BV(WDIE) | (value & 0x07)) ) \
28 : "r0" \
29)
30
31
32void suspend_idle(uint8_t time)
33{
34 cli();
35 set_sleep_mode(SLEEP_MODE_IDLE);
36 sleep_enable();
37 sei();
38 sleep_cpu();
39 sleep_disable();
40}
41
42/* Power down MCU with watchdog timer
43 * wdto: watchdog timer timeout defined in <avr/wdt.h>
44 * WDTO_15MS
45 * WDTO_30MS
46 * WDTO_60MS
47 * WDTO_120MS
48 * WDTO_250MS
49 * WDTO_500MS
50 * WDTO_1S
51 * WDTO_2S
52 * WDTO_4S
53 * WDTO_8S
54 */
55void suspend_power_down(uint8_t wdto)
56{
57#ifdef PROTOCOL_LUFA
58 if (USB_DeviceState == DEVICE_STATE_Configured) return;
59#endif
60
61 // Watchdog Interrupt Mode
62 wdt_intr_enable(wdto);
63
64 // TODO: more power saving
65 // See PicoPower application note
66 // - I/O port input with pullup
67 // - prescale clock
68 // - BOD disable
69 // - Power Reduction Register PRR
70
71 set_sleep_mode(SLEEP_MODE_PWR_DOWN);
72 sleep_enable();
73 sei();
74 sleep_cpu();
75 sleep_disable();
76
77 // Disable watchdog after sleep
78 wdt_disable();
79}
80
81bool suspend_wakeup_condition(void)
82{
83 matrix_power_up();
84 matrix_scan();
85 matrix_power_down();
86 for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
87 if (matrix_get_row(r)) return true;
88 }
89 return false;
90}
91
92// run immediately after wakeup
93void suspend_wakeup_init(void)
94{
95 // clear keyboard state
96 clear_keyboard();
97#ifdef BACKLIGHT_ENABLE
98 backlight_init();
99#endif
100}
101
102#ifndef NO_SUSPEND_POWER_DOWN
103/* watchdog timeout */
104ISR(WDT_vect)
105{
106 /* wakeup from MCU sleep mode */
107/*
108 // blink LED
109 static uint8_t led_state = 0;
110 static uint8_t led_count = 0;
111 led_count++;
112 if ((led_count & 0x07) == 0) {
113 led_set((led_state ^= (1<<USB_LED_CAPS_LOCK)));
114 }
115*/
116}
117#endif
diff --git a/common/avr/suspend_avr.h b/common/avr/suspend_avr.h
new file mode 100644
index 000000000..357102da4
--- /dev/null
+++ b/common/avr/suspend_avr.h
@@ -0,0 +1,27 @@
1#ifndef SUSPEND_AVR_H
2#define SUSPEND_AVR_H
3
4#include <stdint.h>
5#include <stdbool.h>
6#include <avr/sleep.h>
7#include <avr/wdt.h>
8#include <avr/interrupt.h>
9
10
11#define wdt_intr_enable(value) \
12__asm__ __volatile__ ( \
13 "in __tmp_reg__,__SREG__" "\n\t" \
14 "cli" "\n\t" \
15 "wdr" "\n\t" \
16 "sts %0,%1" "\n\t" \
17 "out __SREG__,__tmp_reg__" "\n\t" \
18 "sts %0,%2" "\n\t" \
19 : /* no outputs */ \
20 : "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \
21 "r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)), \
22 "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | \
23 _BV(WDIE) | (value & 0x07)) ) \
24 : "r0" \
25)
26
27#endif
diff --git a/common/timer.c b/common/avr/timer.c
index e0dec6cef..292b41c3a 100644
--- a/common/timer.c
+++ b/common/avr/timer.c
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
18#include <avr/io.h> 18#include <avr/io.h>
19#include <avr/interrupt.h> 19#include <avr/interrupt.h>
20#include <stdint.h> 20#include <stdint.h>
21#include "timer_avr.h"
21#include "timer.h" 22#include "timer.h"
22 23
23 24
diff --git a/common/avr/timer_avr.h b/common/avr/timer_avr.h
new file mode 100644
index 000000000..0e85eb101
--- /dev/null
+++ b/common/avr/timer_avr.h
@@ -0,0 +1,42 @@
1/*
2Copyright 2011 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#ifndef TIMER_AVR_H
19#define TIMER_AVR_H 1
20
21#include <stdint.h>
22
23#ifndef TIMER_PRESCALER
24# if F_CPU > 16000000
25# define TIMER_PRESCALER 256
26# elif F_CPU > 2000000
27# define TIMER_PRESCALER 64
28# elif F_CPU > 250000
29# define TIMER_PRESCALER 8
30# else
31# define TIMER_PRESCALER 1
32# endif
33#endif
34#define TIMER_RAW_FREQ (F_CPU/TIMER_PRESCALER)
35#define TIMER_RAW TCNT0
36#define TIMER_RAW_TOP (TIMER_RAW_FREQ/1000)
37
38#if (TIMER_RAW_TOP > 255)
39# error "Timer0 can't count 1ms at this clock freq. Use larger prescaler."
40#endif
41
42#endif
diff --git a/common/xprintf.S b/common/avr/xprintf.S
index 0cec70ce2..0cec70ce2 100644
--- a/common/xprintf.S
+++ b/common/avr/xprintf.S
diff --git a/common/xprintf.h b/common/avr/xprintf.h
index 59c6f2531..59c6f2531 100644
--- a/common/xprintf.h
+++ b/common/avr/xprintf.h
diff --git a/common/bootmagic.c b/common/bootmagic.c
index 642d5face..b002a5856 100644
--- a/common/bootmagic.c
+++ b/common/bootmagic.c
@@ -111,7 +111,7 @@ static bool scan_keycode(uint8_t keycode)
111 matrix_row_t matrix_row = matrix_get_row(r); 111 matrix_row_t matrix_row = matrix_get_row(r);
112 for (uint8_t c = 0; c < MATRIX_COLS; c++) { 112 for (uint8_t c = 0; c < MATRIX_COLS; c++) {
113 if (matrix_row & ((matrix_row_t)1<<c)) { 113 if (matrix_row & ((matrix_row_t)1<<c)) {
114 if (keycode == keymap_key_to_keycode(0, (key_t){ .row = r, .col = c })) { 114 if (keycode == keymap_key_to_keycode(0, (keypos_t){ .row = r, .col = c })) {
115 return true; 115 return true;
116 } 116 }
117 } 117 }
diff --git a/common/command.c b/common/command.c
index 2c65f0da7..971ef7f0a 100644
--- a/common/command.c
+++ b/common/command.c
@@ -63,19 +63,22 @@ static uint8_t numkey2num(uint8_t code);
63static void switch_default_layer(uint8_t layer); 63static void switch_default_layer(uint8_t layer);
64 64
65 65
66typedef enum { ONESHOT, CONSOLE, MOUSEKEY } cmdstate_t; 66command_state_t command_state = ONESHOT;
67static cmdstate_t state = ONESHOT;
68 67
69 68
70bool command_proc(uint8_t code) 69bool command_proc(uint8_t code)
71{ 70{
72 switch (state) { 71 switch (command_state) {
73 case ONESHOT: 72 case ONESHOT:
74 if (!IS_COMMAND()) 73 if (!IS_COMMAND())
75 return false; 74 return false;
76 return (command_extra(code) || command_common(code)); 75 return (command_extra(code) || command_common(code));
76 break;
77 case CONSOLE: 77 case CONSOLE:
78 command_console(code); 78 if (IS_COMMAND())
79 return (command_extra(code) || command_common(code));
80 else
81 return (command_console_extra(code) || command_console(code));
79 break; 82 break;
80#ifdef MOUSEKEY_ENABLE 83#ifdef MOUSEKEY_ENABLE
81 case MOUSEKEY: 84 case MOUSEKEY:
@@ -83,12 +86,13 @@ bool command_proc(uint8_t code)
83 break; 86 break;
84#endif 87#endif
85 default: 88 default:
86 state = ONESHOT; 89 command_state = ONESHOT;
87 return false; 90 return false;
88 } 91 }
89 return true; 92 return true;
90} 93}
91 94
95/* TODO: Refactoring is needed. */
92/* This allows to define extra commands. return false when not processed. */ 96/* This allows to define extra commands. return false when not processed. */
93bool command_extra(uint8_t code) __attribute__ ((weak)); 97bool command_extra(uint8_t code) __attribute__ ((weak));
94bool command_extra(uint8_t code) 98bool command_extra(uint8_t code)
@@ -96,6 +100,12 @@ bool command_extra(uint8_t code)
96 return false; 100 return false;
97} 101}
98 102
103bool command_console_extra(uint8_t code) __attribute__ ((weak));
104bool command_console_extra(uint8_t code)
105{
106 return false;
107}
108
99 109
100/*********************************************************** 110/***********************************************************
101 * Command common 111 * Command common
@@ -203,7 +213,7 @@ static bool command_common(uint8_t code)
203 command_console_help(); 213 command_console_help();
204 print("\nEnter Console Mode\n"); 214 print("\nEnter Console Mode\n");
205 print("C> "); 215 print("C> ");
206 state = CONSOLE; 216 command_state = CONSOLE;
207 break; 217 break;
208 case KC_PAUSE: 218 case KC_PAUSE:
209 clear_keyboard(); 219 clear_keyboard();
@@ -388,14 +398,14 @@ static bool command_console(uint8_t code)
388 case KC_Q: 398 case KC_Q:
389 case KC_ESC: 399 case KC_ESC:
390 print("\nQuit Console Mode\n"); 400 print("\nQuit Console Mode\n");
391 state = ONESHOT; 401 command_state = ONESHOT;
392 return false; 402 return false;
393#ifdef MOUSEKEY_ENABLE 403#ifdef MOUSEKEY_ENABLE
394 case KC_M: 404 case KC_M:
395 mousekey_console_help(); 405 mousekey_console_help();
396 print("\nEnter Mousekey Console\n"); 406 print("\nEnter Mousekey Console\n");
397 print("M0>"); 407 print("M0>");
398 state = MOUSEKEY; 408 command_state = MOUSEKEY;
399 return true; 409 return true;
400#endif 410#endif
401 default: 411 default:
@@ -555,7 +565,7 @@ static bool mousekey_console(uint8_t code)
555 mousekey_param = 0; 565 mousekey_param = 0;
556 print("\nQuit Mousekey Console\n"); 566 print("\nQuit Mousekey Console\n");
557 print("C> "); 567 print("C> ");
558 state = CONSOLE; 568 command_state = CONSOLE;
559 return false; 569 return false;
560 case KC_P: 570 case KC_P:
561 mousekey_param_print(); 571 mousekey_param_print();
diff --git a/common/command.h b/common/command.h
index be739fafe..b57a6c1ce 100644
--- a/common/command.h
+++ b/common/command.h
@@ -18,10 +18,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
18#ifndef COMMAND_H 18#ifndef COMMAND_H
19#define COMMAND 19#define COMMAND
20 20
21/* TODO: Refactoring */
22typedef enum { ONESHOT, CONSOLE, MOUSEKEY } command_state_t;
23extern command_state_t command_state;
24
25/* This allows to extend commands. Return false when command is not processed. */
26bool command_extra(uint8_t code);
27bool command_console_extra(uint8_t code);
28
21#ifdef COMMAND_ENABLE 29#ifdef COMMAND_ENABLE
22bool command_proc(uint8_t code); 30bool command_proc(uint8_t code);
23/* This allows to extend commands. Return 0 when command is not processed. */
24bool command_extra(uint8_t code);
25#else 31#else
26#define command_proc(code) false 32#define command_proc(code) false
27#endif 33#endif
diff --git a/common/debug.h b/common/debug.h
index 8aaa5ed91..472dd478c 100644
--- a/common/debug.h
+++ b/common/debug.h
@@ -19,44 +19,100 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
19#define DEBUG_H 1 19#define DEBUG_H 1
20 20
21#include "print.h" 21#include "print.h"
22#include "debug_config.h"
23 22
24 23
24/*
25 * Debug output control
26 */
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31typedef union {
32 struct {
33 bool enable:1;
34 bool matrix:1;
35 bool keyboard:1;
36 bool mouse:1;
37 uint8_t reserved:4;
38 };
39 uint8_t raw;
40} debug_config_t;
41
42extern debug_config_t debug_config;
43debug_config_t debug_config __attribute__ ((weak)) = {};
44
45#ifdef __cplusplus
46}
47#endif
48
49#define debug_enable (debug_config.enable)
50#define debug_matrix (debug_config.matrix)
51#define debug_keyboard (debug_config.keyboard)
52#define debug_mouse (debug_config.mouse)
53
54
55
56/*
57 * Debug print utils
58 */
25#ifndef NO_DEBUG 59#ifndef NO_DEBUG
26 60
27#define dprint(s) do { if (debug_enable) print(s); } while (0) 61#define dprint(s) do { if (debug_enable) print(s); } while (0)
28#define dprintln() do { if (debug_enable) print_crlf(); } while (0) 62#define dprintln(s) do { if (debug_enable) println(s); } while (0)
29#define dprintf(fmt, ...) do { if (debug_enable) __xprintf(PSTR(fmt), ##__VA_ARGS__); } while (0) 63#define dprintf(fmt, ...) do { if (debug_enable) xprintf(fmt, ##__VA_ARGS__); } while (0)
30#define dmsg(s) dprintf("%s at %s: %S\n", __FILE__, __LINE__, PSTR(s)) 64#define dmsg(s) dprintf("%s at %s: %S\n", __FILE__, __LINE__, PSTR(s))
31 65
32/* DO NOT USE these anymore */ 66/* Deprecated. DO NOT USE these anymore, use dprintf instead. */
33#define debug(s) do { if (debug_enable) print(s); } while (0) 67#define debug(s) do { if (debug_enable) print(s); } while (0)
34#define debugln(s) do { if (debug_enable) print_crlf(); } while (0) 68#define debugln(s) do { if (debug_enable) println(s); } while (0)
35#define debug_S(s) do { if (debug_enable) print_S(s); } while (0) 69#define debug_msg(s) do { \
36#define debug_P(s) do { if (debug_enable) print_P(s); } while (0)
37#define debug_msg(s) do { \
38 if (debug_enable) { \ 70 if (debug_enable) { \
39 print(__FILE__); print(" at "); print_dec(__LINE__); print(" in "); print(": "); print(s); \ 71 print(__FILE__); print(" at "); print_dec(__LINE__); print(" in "); print(": "); print(s); \
40 } \ 72 } \
41} while (0) 73} while (0)
42#define debug_dec(data) do { if (debug_enable) print_dec(data); } while (0) 74#define debug_dec(data) do { if (debug_enable) print_dec(data); } while (0)
43#define debug_decs(data) do { if (debug_enable) print_decs(data); } while (0) 75#define debug_decs(data) do { if (debug_enable) print_decs(data); } while (0)
44#define debug_hex4(data) do { if (debug_enable) print_hex4(data); } while (0) 76#define debug_hex4(data) do { if (debug_enable) print_hex4(data); } while (0)
45#define debug_hex8(data) do { if (debug_enable) print_hex8(data); } while (0) 77#define debug_hex8(data) do { if (debug_enable) print_hex8(data); } while (0)
46#define debug_hex16(data) do { if (debug_enable) print_hex16(data); } while (0) 78#define debug_hex16(data) do { if (debug_enable) print_hex16(data); } while (0)
47#define debug_hex32(data) do { if (debug_enable) print_hex32(data); } while (0) 79#define debug_hex32(data) do { if (debug_enable) print_hex32(data); } while (0)
48#define debug_bin8(data) do { if (debug_enable) print_bin8(data); } while (0) 80#define debug_bin8(data) do { if (debug_enable) print_bin8(data); } while (0)
49#define debug_bin16(data) do { if (debug_enable) print_bin16(data); } while (0) 81#define debug_bin16(data) do { if (debug_enable) print_bin16(data); } while (0)
50#define debug_bin32(data) do { if (debug_enable) print_bin32(data); } while (0) 82#define debug_bin32(data) do { if (debug_enable) print_bin32(data); } while (0)
51#define debug_bin_reverse8(data) do { if (debug_enable) print_bin_reverse8(data); } while (0) 83#define debug_bin_reverse8(data) do { if (debug_enable) print_bin_reverse8(data); } while (0)
52#define debug_bin_reverse16(data) do { if (debug_enable) print_bin_reverse16(data); } while (0) 84#define debug_bin_reverse16(data) do { if (debug_enable) print_bin_reverse16(data); } while (0)
53#define debug_bin_reverse32(data) do { if (debug_enable) print_bin_reverse32(data); } while (0) 85#define debug_bin_reverse32(data) do { if (debug_enable) print_bin_reverse32(data); } while (0)
54#define debug_hex(data) debug_hex8(data) 86#define debug_hex(data) debug_hex8(data)
55#define debug_bin(data) debug_bin8(data) 87#define debug_bin(data) debug_bin8(data)
56#define debug_bin_reverse(data) debug_bin8(data) 88#define debug_bin_reverse(data) debug_bin8(data)
57 89
58#else 90#else
59#include "nodebug.h" 91
92/* NO_DEBUG */
93#define dprint(s)
94#define dprintln(s)
95#define dprintf(fmt, ...)
96#define dmsg(s)
97#define debug(s)
98#define debugln(s)
99#define debug_msg(s)
100#define debug_dec(data)
101#define debug_decs(data)
102#define debug_hex4(data)
103#define debug_hex8(data)
104#define debug_hex16(data)
105#define debug_hex32(data)
106#define debug_bin8(data)
107#define debug_bin16(data)
108#define debug_bin32(data)
109#define debug_bin_reverse8(data)
110#define debug_bin_reverse16(data)
111#define debug_bin_reverse32(data)
112#define debug_hex(data)
113#define debug_bin(data)
114#define debug_bin_reverse(data)
115
60#endif 116#endif
61 117
62#endif 118#endif
diff --git a/common/host.c b/common/host.c
index 2e56971bd..e9b791670 100644
--- a/common/host.c
+++ b/common/host.c
@@ -16,7 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/ 16*/
17 17
18#include <stdint.h> 18#include <stdint.h>
19#include <avr/interrupt.h> 19//#include <avr/interrupt.h>
20#include "keycode.h" 20#include "keycode.h"
21#include "host.h" 21#include "host.h"
22#include "util.h" 22#include "util.h"
@@ -55,7 +55,7 @@ void host_keyboard_send(report_keyboard_t *report)
55 55
56 if (debug_keyboard) { 56 if (debug_keyboard) {
57 dprint("keyboard_report: "); 57 dprint("keyboard_report: ");
58 for (uint8_t i = 0; i < REPORT_SIZE; i++) { 58 for (uint8_t i = 0; i < KEYBOARD_REPORT_SIZE; i++) {
59 dprintf("%02X ", report->raw[i]); 59 dprintf("%02X ", report->raw[i]);
60 } 60 }
61 dprint("\n"); 61 dprint("\n");
diff --git a/common/keyboard.c b/common/keyboard.c
index 020be8ead..1e3fb510a 100644
--- a/common/keyboard.c
+++ b/common/keyboard.c
@@ -15,7 +15,6 @@ You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>. 15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/ 16*/
17#include <stdint.h> 17#include <stdint.h>
18#include <util/delay.h>
19#include "keyboard.h" 18#include "keyboard.h"
20#include "matrix.h" 19#include "matrix.h"
21#include "keymap.h" 20#include "keymap.h"
@@ -107,7 +106,7 @@ void keyboard_task(void)
107 for (uint8_t c = 0; c < MATRIX_COLS; c++) { 106 for (uint8_t c = 0; c < MATRIX_COLS; c++) {
108 if (matrix_change & ((matrix_row_t)1<<c)) { 107 if (matrix_change & ((matrix_row_t)1<<c)) {
109 action_exec((keyevent_t){ 108 action_exec((keyevent_t){
110 .key = (key_t){ .row = r, .col = c }, 109 .key = (keypos_t){ .row = r, .col = c },
111 .pressed = (matrix_row & ((matrix_row_t)1<<c)), 110 .pressed = (matrix_row & ((matrix_row_t)1<<c)),
112 .time = (timer_read() | 1) /* time should not be 0 */ 111 .time = (timer_read() | 1) /* time should not be 0 */
113 }); 112 });
diff --git a/common/keyboard.h b/common/keyboard.h
index d1a922420..6442716fc 100644
--- a/common/keyboard.h
+++ b/common/keyboard.h
@@ -30,16 +30,16 @@ extern "C" {
30typedef struct { 30typedef struct {
31 uint8_t col; 31 uint8_t col;
32 uint8_t row; 32 uint8_t row;
33} key_t; 33} keypos_t;
34 34
35/* key event */ 35/* key event */
36typedef struct { 36typedef struct {
37 key_t key; 37 keypos_t key;
38 bool pressed; 38 bool pressed;
39 uint16_t time; 39 uint16_t time;
40} keyevent_t; 40} keyevent_t;
41 41
42/* equivalent test of key_t */ 42/* equivalent test of keypos_t */
43#define KEYEQ(keya, keyb) ((keya).row == (keyb).row && (keya).col == (keyb).col) 43#define KEYEQ(keya, keyb) ((keya).row == (keyb).row && (keya).col == (keyb).col)
44 44
45/* Rules for No Event: 45/* Rules for No Event:
@@ -52,7 +52,7 @@ static inline bool IS_RELEASED(keyevent_t event) { return (!IS_NOEVENT(event) &&
52 52
53/* Tick event */ 53/* Tick event */
54#define TICK (keyevent_t){ \ 54#define TICK (keyevent_t){ \
55 .key = (key_t){ .row = 255, .col = 255 }, \ 55 .key = (keypos_t){ .row = 255, .col = 255 }, \
56 .pressed = false, \ 56 .pressed = false, \
57 .time = (timer_read() | 1) \ 57 .time = (timer_read() | 1) \
58} 58}
@@ -62,6 +62,9 @@ void keyboard_init(void);
62void keyboard_task(void); 62void keyboard_task(void);
63void keyboard_set_leds(uint8_t leds); 63void keyboard_set_leds(uint8_t leds);
64 64
65__attribute__ ((weak)) void matrix_power_up(void) {}
66__attribute__ ((weak)) void matrix_power_down(void) {}
67
65#ifdef __cplusplus 68#ifdef __cplusplus
66} 69}
67#endif 70#endif
diff --git a/common/keymap.c b/common/keymap.c
index bfb8ffac1..4c0b61b8c 100644
--- a/common/keymap.c
+++ b/common/keymap.c
@@ -14,7 +14,6 @@ GNU General Public License for more details.
14You should have received a copy of the GNU General Public License 14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>. 15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/ 16*/
17#include <avr/pgmspace.h>
18#include "keymap.h" 17#include "keymap.h"
19#include "report.h" 18#include "report.h"
20#include "keycode.h" 19#include "keycode.h"
@@ -28,7 +27,7 @@ static action_t keycode_to_action(uint8_t keycode);
28 27
29 28
30/* converts key to action */ 29/* converts key to action */
31action_t action_for_key(uint8_t layer, key_t key) 30action_t action_for_key(uint8_t layer, keypos_t key)
32{ 31{
33 uint8_t keycode = keymap_key_to_keycode(layer, key); 32 uint8_t keycode = keymap_key_to_keycode(layer, key);
34 switch (keycode) { 33 switch (keycode) {
@@ -156,7 +155,7 @@ static action_t keycode_to_action(uint8_t keycode)
156 * Consider using new keymap API instead. 155 * Consider using new keymap API instead.
157 */ 156 */
158__attribute__ ((weak)) 157__attribute__ ((weak))
159uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) 158uint8_t keymap_key_to_keycode(uint8_t layer, keypos_t key)
160{ 159{
161 return keymap_get_keycode(layer, key.row, key.col); 160 return keymap_get_keycode(layer, key.row, key.col);
162} 161}
diff --git a/common/keymap.h b/common/keymap.h
index 4c3019a36..e1a6f992e 100644
--- a/common/keymap.h
+++ b/common/keymap.h
@@ -43,7 +43,7 @@ keymap_config_t keymap_config;
43 43
44 44
45/* translates key to keycode */ 45/* translates key to keycode */
46uint8_t keymap_key_to_keycode(uint8_t layer, key_t key); 46uint8_t keymap_key_to_keycode(uint8_t layer, keypos_t key);
47 47
48/* translates Fn keycode to action */ 48/* translates Fn keycode to action */
49action_t keymap_fn_to_action(uint8_t keycode); 49action_t keymap_fn_to_action(uint8_t keycode);
diff --git a/common/matrix.h b/common/matrix.h
index d1d14a6ea..23fef78f7 100644
--- a/common/matrix.h
+++ b/common/matrix.h
@@ -53,4 +53,9 @@ matrix_row_t matrix_get_row(uint8_t row);
53void matrix_print(void); 53void matrix_print(void);
54 54
55 55
56/* power control */
57void matrix_power_up(void);
58void matrix_power_down(void);
59
60
56#endif 61#endif
diff --git a/common/mbed/bootloader.c b/common/mbed/bootloader.c
new file mode 100644
index 000000000..b51e83943
--- /dev/null
+++ b/common/mbed/bootloader.c
@@ -0,0 +1,4 @@
1#include "bootloader.h"
2
3
4void bootloader_jump(void) {}
diff --git a/common/mbed/suspend.c b/common/mbed/suspend.c
new file mode 100644
index 000000000..32651574f
--- /dev/null
+++ b/common/mbed/suspend.c
@@ -0,0 +1,6 @@
1#include <stdbool.h>
2
3
4void suspend_power_down(void) {}
5bool suspend_wakeup_condition(void) { return true; }
6void suspend_wakeup_init(void) {}
diff --git a/common/mbed/timer.c b/common/mbed/timer.c
new file mode 100644
index 000000000..c357ceb78
--- /dev/null
+++ b/common/mbed/timer.c
@@ -0,0 +1,41 @@
1#include "cmsis.h"
2#include "timer.h"
3
4/* Mill second tick count */
5volatile uint32_t timer_count = 0;
6
7/* Timer interrupt handler */
8void SysTick_Handler(void) {
9 timer_count++;
10}
11
12void timer_init(void)
13{
14 timer_count = 0;
15 SysTick_Config(SystemCoreClock / 1000); /* 1ms tick */
16}
17
18void timer_clear(void)
19{
20 timer_count = 0;
21}
22
23uint16_t timer_read(void)
24{
25 return (uint16_t)(timer_count & 0xFFFF);
26}
27
28uint32_t timer_read32(void)
29{
30 return timer_count;
31}
32
33uint16_t timer_elapsed(uint16_t last)
34{
35 return TIMER_DIFF_16(timer_read(), last);
36}
37
38uint32_t timer_elapsed32(uint32_t last)
39{
40 return TIMER_DIFF_32(timer_read32(), last);
41}
diff --git a/common/mbed/xprintf.cpp b/common/mbed/xprintf.cpp
new file mode 100644
index 000000000..4342b79f8
--- /dev/null
+++ b/common/mbed/xprintf.cpp
@@ -0,0 +1,46 @@
1#include <cstdarg>
2//#include <stdarg.h>
3#include "mbed.h"
4#include "mbed/xprintf.h"
5
6
7#define STRING_STACK_LIMIT 120
8
9/* mbed Serial */
10Serial ser(UART_TX, UART_RX);
11
12/* TODO: Need small implementation for embedded */
13int xprintf(const char* format, ...)
14{
15 /* copy from mbed/common/RawSerial.cpp */
16 std::va_list arg;
17 va_start(arg, format);
18 int len = vsnprintf(NULL, 0, format, arg);
19 if (len < STRING_STACK_LIMIT) {
20 char temp[STRING_STACK_LIMIT];
21 vsprintf(temp, format, arg);
22 ser.puts(temp);
23 } else {
24 char *temp = new char[len + 1];
25 vsprintf(temp, format, arg);
26 ser.puts(temp);
27 delete[] temp;
28 }
29 va_end(arg);
30 return len;
31
32/* Fail: __builtin_va_arg_pack?
33 * https://gcc.gnu.org/onlinedocs/gcc-4.3.5/gcc/Constructing-Calls.html#Constructing-Calls
34 void *arg = __builtin_apply_args();
35 void *ret = __builtin_apply((void*)(&(ser.printf)), arg, 100);
36 __builtin_return(ret)
37*/
38/* Fail: varargs can not be passed to printf
39 //int r = ser.printf("test %i\r\n", 123);
40 va_list arg;
41 va_start(arg, format);
42 int r = ser.printf(format, arg);
43 va_end(arg);
44 return r;
45*/
46}
diff --git a/common/mbed/xprintf.h b/common/mbed/xprintf.h
new file mode 100644
index 000000000..26bc529e5
--- /dev/null
+++ b/common/mbed/xprintf.h
@@ -0,0 +1,17 @@
1#ifndef XPRINTF_H
2#define XPRINTF_H
3
4//#define xprintf(format, ...) __xprintf(format, ##__VA_ARGS__)
5
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10int xprintf(const char *format, ...);
11
12#ifdef __cplusplus
13}
14#endif
15
16
17#endif
diff --git a/common/mousekey.c b/common/mousekey.c
index 017be9411..23469476e 100644
--- a/common/mousekey.c
+++ b/common/mousekey.c
@@ -16,7 +16,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/ 16*/
17 17
18#include <stdint.h> 18#include <stdint.h>
19#include <util/delay.h>
20#include "keycode.h" 19#include "keycode.h"
21#include "host.h" 20#include "host.h"
22#include "timer.h" 21#include "timer.h"
diff --git a/common/mousekey.h b/common/mousekey.h
index d8d7beaaa..6eede06b4 100644
--- a/common/mousekey.h
+++ b/common/mousekey.h
@@ -52,12 +52,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
52#endif 52#endif
53 53
54 54
55uint8_t mk_delay; 55#ifdef __cplusplus
56uint8_t mk_interval; 56extern "C" {
57uint8_t mk_max_speed; 57#endif
58uint8_t mk_time_to_max; 58
59uint8_t mk_wheel_max_speed; 59extern uint8_t mk_delay;
60uint8_t mk_wheel_time_to_max; 60extern uint8_t mk_interval;
61extern uint8_t mk_max_speed;
62extern uint8_t mk_time_to_max;
63extern uint8_t mk_wheel_max_speed;
64extern uint8_t mk_wheel_time_to_max;
61 65
62 66
63void mousekey_task(void); 67void mousekey_task(void);
@@ -66,4 +70,8 @@ void mousekey_off(uint8_t code);
66void mousekey_clear(void); 70void mousekey_clear(void);
67void mousekey_send(void); 71void mousekey_send(void);
68 72
73#ifdef __cplusplus
74}
75#endif
76
69#endif 77#endif
diff --git a/common/nodebug.h b/common/nodebug.h
index aec790bbc..93309ada4 100644
--- a/common/nodebug.h
+++ b/common/nodebug.h
@@ -18,32 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
18#ifndef NODEBUG_H 18#ifndef NODEBUG_H
19#define NODEBUG_H 1 19#define NODEBUG_H 1
20 20
21#include "debug_config.h" 21#define NO_DEBUG
22 22#include "debug.h"
23#define dprint(s) 23#undef NO_DEBUG
24#define dprintln(s)
25#define dprintf(fmt, ...)
26#define dmsg(s)
27
28#define debug(s)
29#define debugln(s)
30#define debug_S(s)
31#define debug_P(s)
32#define debug_msg(s)
33#define debug_dec(data)
34#define debug_decs(data)
35#define debug_hex4(data)
36#define debug_hex8(data)
37#define debug_hex16(data)
38#define debug_hex32(data)
39#define debug_bin8(data)
40#define debug_bin16(data)
41#define debug_bin32(data)
42#define debug_bin_reverse8(data)
43#define debug_bin_reverse16(data)
44#define debug_bin_reverse32(data)
45#define debug_hex(data)
46#define debug_bin(data)
47#define debug_bin_reverse(data)
48 24
49#endif 25#endif
diff --git a/common/print.c b/common/print.c
index 783bb4e9b..c13a29f31 100644
--- a/common/print.c
+++ b/common/print.c
@@ -37,26 +37,4 @@ void print_set_sendchar(int8_t (*sendchar_func)(uint8_t))
37 xdev_out(sendchar_func); 37 xdev_out(sendchar_func);
38} 38}
39 39
40void print_S(const char *s)
41{
42 uint8_t c;
43 while (1) {
44 c = *s++;
45 if (!c) break;
46 if (c == '\n') sendchar('\r');
47 sendchar(c);
48 }
49}
50
51void print_lf(void)
52{
53 sendchar('\n');
54}
55
56void print_crlf(void)
57{
58 sendchar('\r');
59 sendchar('\n');
60}
61
62#endif 40#endif
diff --git a/common/print.h b/common/print.h
index 779932891..a8dbbc020 100644
--- a/common/print.h
+++ b/common/print.h
@@ -27,95 +27,79 @@
27 27
28#include <stdint.h> 28#include <stdint.h>
29#include <stdbool.h> 29#include <stdbool.h>
30#include <avr/pgmspace.h>
31#include "xprintf.h"
32#include "util.h" 30#include "util.h"
33 31
34 32
35// this macro allows you to write print("some text") and
36// the string is automatically placed into flash memory :)
37#define print(s) print_P(PSTR(s))
38#define println(s) print_P(PSTR(s "\n"))
39 33
40/* for old name */
41#define pdec(data) print_dec(data)
42#define pdec16(data) print_dec(data)
43#define phex(data) print_hex8(data)
44#define phex16(data) print_hex16(data)
45#define pbin(data) print_bin8(data)
46#define pbin16(data) print_bin16(data)
47#define pbin_reverse(data) print_bin_reverse8(data)
48#define pbin_reverse16(data) print_bin_reverse16(data)
49 34
50/* print value utility */ 35#ifndef NO_PRINT
51#define print_val_dec(v) xprintf(#v ": %u\n", v)
52#define print_val_decs(v) xprintf(#v ": %d\n", v)
53#define print_val_hex8(v) xprintf(#v ": %X\n", v)
54#define print_val_hex16(v) xprintf(#v ": %02X\n", v)
55#define print_val_hex32(v) xprintf(#v ": %04lX\n", v)
56#define print_val_bin8(v) xprintf(#v ": %08b\n", v)
57#define print_val_bin16(v) xprintf(#v ": %016b\n", v)
58#define print_val_bin32(v) xprintf(#v ": %032lb\n", v)
59#define print_val_bin_reverse8(v) xprintf(#v ": %08b\n", bitrev(v))
60#define print_val_bin_reverse16(v) xprintf(#v ": %016b\n", bitrev16(v))
61#define print_val_bin_reverse32(v) xprintf(#v ": %032lb\n", bitrev32(v))
62 36
63 37
38#if defined(__AVR__)
64 39
65#ifndef NO_PRINT 40#include "avr/xprintf.h"
66 41
67#ifdef __cplusplus 42
68extern "C" { 43// TODO: avoid collision with arduino/Print.h
44#ifndef __cplusplus
45#define print(s) xputs(PSTR(s))
69#endif 46#endif
47#define println(s) xputs(PSTR(s "\r\n"))
70 48
49#ifdef __cplusplus
50extern "C"
51#endif
71/* function pointer of sendchar to be used by print utility */ 52/* function pointer of sendchar to be used by print utility */
72void print_set_sendchar(int8_t (*print_sendchar_func)(uint8_t)); 53void print_set_sendchar(int8_t (*print_sendchar_func)(uint8_t));
73 54
74/* print string stored in data memory(SRAM) 55#elif defined(__arm__)
75 * print_S("hello world");
76 * This consumes precious SRAM memory space for string.
77 */
78void print_S(const char *s);
79 56
80void print_lf(void); 57#include "mbed/xprintf.h"
81void print_crlf(void);
82 58
59#define print(s) xprintf(s)
60#define println(s) xprintf(s "\r\n")
83 61
84/* print string stored in program memory(FLASH) 62/* TODO: to select output destinations: UART/USBSerial */
85 * print_P(PSTR("hello world"); 63#define print_set_sendchar(func)
86 * This consumes relatively abundant FLASH memory area not SRAM.
87 */
88#define print_P(s) xputs(s)
89 64
90/* decimal */ 65#endif /* __AVR__ */
91#define print_dec(i) xprintf("%u", i)
92#define print_decs(i) xprintf("%d", i)
93 66
94/* hex */
95#define print_hex4(i) xprintf("%X", i)
96#define print_hex8(i) xprintf("%02X", i)
97#define print_hex16(i) xprintf("%04X", i)
98#define print_hex32(i) xprintf("%08lX", i)
99 67
68/* decimal */
69#define print_dec(i) xprintf("%u", i)
70#define print_decs(i) xprintf("%d", i)
71/* hex */
72#define print_hex4(i) xprintf("%X", i)
73#define print_hex8(i) xprintf("%02X", i)
74#define print_hex16(i) xprintf("%04X", i)
75#define print_hex32(i) xprintf("%08lX", i)
100/* binary */ 76/* binary */
101#define print_bin4(i) xprintf("%04b", i) 77#define print_bin4(i) xprintf("%04b", i)
102#define print_bin8(i) xprintf("%08b", i) 78#define print_bin8(i) xprintf("%08b", i)
103#define print_bin16(i) xprintf("%016b", i) 79#define print_bin16(i) xprintf("%016b", i)
104#define print_bin32(i) xprintf("%032lb", i) 80#define print_bin32(i) xprintf("%032lb", i)
105 81#define print_bin_reverse8(i) xprintf("%08b", bitrev(i))
106#define print_bin_reverse8(i) xprintf("%08b", bitrev(i)) 82#define print_bin_reverse16(i) xprintf("%016b", bitrev16(i))
107#define print_bin_reverse16(i) xprintf("%016b", bitrev16(i)) 83#define print_bin_reverse32(i) xprintf("%032lb", bitrev32(i))
108#define print_bin_reverse32(i) xprintf("%032lb", bitrev32(i)) 84/* print value utility */
109 85#define print_val_dec(v) xprintf(#v ": %u\n", v)
110#ifdef __cplusplus 86#define print_val_decs(v) xprintf(#v ": %d\n", v)
111} 87#define print_val_hex8(v) xprintf(#v ": %X\n", v)
112#endif 88#define print_val_hex16(v) xprintf(#v ": %02X\n", v)
113 89#define print_val_hex32(v) xprintf(#v ": %04lX\n", v)
114#else 90#define print_val_bin8(v) xprintf(#v ": %08b\n", v)
115 91#define print_val_bin16(v) xprintf(#v ": %016b\n", v)
92#define print_val_bin32(v) xprintf(#v ": %032lb\n", v)
93#define print_val_bin_reverse8(v) xprintf(#v ": %08b\n", bitrev(v))
94#define print_val_bin_reverse16(v) xprintf(#v ": %016b\n", bitrev16(v))
95#define print_val_bin_reverse32(v) xprintf(#v ": %032lb\n", bitrev32(v))
96
97#else /* NO_PRINT */
98
99#define xprintf
100#define print
101#define println
116#define print_set_sendchar(func) 102#define print_set_sendchar(func)
117#define print_S(s)
118#define print_P(s)
119#define print_dec(data) 103#define print_dec(data)
120#define print_decs(data) 104#define print_decs(data)
121#define print_hex4(data) 105#define print_hex4(data)
@@ -129,8 +113,30 @@ void print_crlf(void);
129#define print_bin_reverse8(data) 113#define print_bin_reverse8(data)
130#define print_bin_reverse16(data) 114#define print_bin_reverse16(data)
131#define print_bin_reverse32(data) 115#define print_bin_reverse32(data)
132 116#define print_val_dec(v)
133#endif 117#define print_val_decs(v)
118#define print_val_hex8(v)
119#define print_val_hex16(v)
120#define print_val_hex32(v)
121#define print_val_bin8(v)
122#define print_val_bin16(v)
123#define print_val_bin32(v)
124#define print_val_bin_reverse8(v)
125#define print_val_bin_reverse16(v)
126#define print_val_bin_reverse32(v)
127
128#endif /* NO_PRINT */
129
130
131/* Backward compatiblitly for old name */
132#define pdec(data) print_dec(data)
133#define pdec16(data) print_dec(data)
134#define phex(data) print_hex8(data)
135#define phex16(data) print_hex16(data)
136#define pbin(data) print_bin8(data)
137#define pbin16(data) print_bin16(data)
138#define pbin_reverse(data) print_bin_reverse8(data)
139#define pbin_reverse16(data) print_bin_reverse16(data)
134 140
135 141
136#endif 142#endif
diff --git a/common/progmem.h b/common/progmem.h
new file mode 100644
index 000000000..199b1bedf
--- /dev/null
+++ b/common/progmem.h
@@ -0,0 +1,12 @@
1#ifndef PROGMEM_H
2#define PROGMEM_H 1
3
4#if defined(__AVR__)
5# include <avr/pgmspace.h>
6#elif defined(__arm__)
7# define PROGMEM
8# define pgm_read_byte(p) *(p)
9# define pgm_read_word(p) *(p)
10#endif
11
12#endif
diff --git a/common/report.h b/common/report.h
index 71543cc23..62190469a 100644
--- a/common/report.h
+++ b/common/report.h
@@ -74,19 +74,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
74/* key report size(NKRO or boot mode) */ 74/* key report size(NKRO or boot mode) */
75#if defined(PROTOCOL_PJRC) && defined(NKRO_ENABLE) 75#if defined(PROTOCOL_PJRC) && defined(NKRO_ENABLE)
76# include "usb.h" 76# include "usb.h"
77# define REPORT_SIZE KBD2_SIZE 77# define KEYBOARD_REPORT_SIZE KBD2_SIZE
78# define REPORT_KEYS (KBD2_SIZE - 2) 78# define KEYBOARD_REPORT_KEYS (KBD2_SIZE - 2)
79# define REPORT_BITS (KBD2_SIZE - 1) 79# define KEYBOARD_REPORT_BITS (KBD2_SIZE - 1)
80 80
81#elif defined(PROTOCOL_LUFA) && defined(NKRO_ENABLE) 81#elif defined(PROTOCOL_LUFA) && defined(NKRO_ENABLE)
82# include "protocol/lufa/descriptor.h" 82# include "protocol/lufa/descriptor.h"
83# define REPORT_SIZE NKRO_EPSIZE 83# define KEYBOARD_REPORT_SIZE NKRO_EPSIZE
84# define REPORT_KEYS (NKRO_EPSIZE - 2) 84# define KEYBOARD_REPORT_KEYS (NKRO_EPSIZE - 2)
85# define REPORT_BITS (NKRO_EPSIZE - 1) 85# define KEYBOARD_REPORT_BITS (NKRO_EPSIZE - 1)
86 86
87#else 87#else
88# define REPORT_SIZE 8 88# define KEYBOARD_REPORT_SIZE 8
89# define REPORT_KEYS 6 89# define KEYBOARD_REPORT_KEYS 6
90#endif 90#endif
91 91
92 92
@@ -115,16 +115,16 @@ extern "C" {
115 * 115 *
116 */ 116 */
117typedef union { 117typedef union {
118 uint8_t raw[REPORT_SIZE]; 118 uint8_t raw[KEYBOARD_REPORT_SIZE];
119 struct { 119 struct {
120 uint8_t mods; 120 uint8_t mods;
121 uint8_t reserved; 121 uint8_t reserved;
122 uint8_t keys[REPORT_KEYS]; 122 uint8_t keys[KEYBOARD_REPORT_KEYS];
123 }; 123 };
124#ifdef NKRO_ENABLE 124#ifdef NKRO_ENABLE
125 struct { 125 struct {
126 uint8_t mods; 126 uint8_t mods;
127 uint8_t bits[REPORT_BITS]; 127 uint8_t bits[KEYBOARD_REPORT_BITS];
128 } nkro; 128 } nkro;
129#endif 129#endif
130} __attribute__ ((packed)) report_keyboard_t; 130} __attribute__ ((packed)) report_keyboard_t;
diff --git a/common/suspend.c b/common/suspend.c
deleted file mode 100644
index 5b378892f..000000000
--- a/common/suspend.c
+++ /dev/null
@@ -1,76 +0,0 @@
1#include "suspend.h"
2#include "matrix.h"
3#include "action.h"
4#include "backlight.h"
5
6
7void suspend_power_down(void)
8{
9#ifdef BACKLIGHT_ENABLE
10 backlight_set(0);
11#endif
12#ifndef NO_SUSPEND_POWER_DOWN
13 // Enable watchdog to wake from MCU sleep
14 cli();
15 wdt_reset();
16
17 // Watchdog Interrupt and System Reset Mode
18 //wdt_enable(WDTO_1S);
19 //WDTCSR |= _BV(WDIE);
20
21 // Watchdog Interrupt Mode
22 wdt_intr_enable(WDTO_120MS);
23
24 // TODO: more power saving
25 // See PicoPower application note
26 // - I/O port input with pullup
27 // - prescale clock
28 // - BOD disable
29 // - Power Reduction Register PRR
30 // sleep in power down mode
31 set_sleep_mode(SLEEP_MODE_PWR_DOWN);
32 sleep_enable();
33 sei();
34 sleep_cpu();
35 sleep_disable();
36
37 // Disable watchdog after sleep
38 wdt_disable();
39#endif
40}
41
42bool suspend_wakeup_condition(void)
43{
44 matrix_scan();
45 for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
46 if (matrix_get_row(r)) return true;
47 }
48 return false;
49}
50
51// run immediately after wakeup
52void suspend_wakeup_init(void)
53{
54 // clear keyboard state
55 clear_keyboard();
56#ifdef BACKLIGHT_ENABLE
57 backlight_init();
58#endif
59}
60
61#ifndef NO_SUSPEND_POWER_DOWN
62/* watchdog timeout */
63ISR(WDT_vect)
64{
65 /* wakeup from MCU sleep mode */
66/*
67 // blink LED
68 static uint8_t led_state = 0;
69 static uint8_t led_count = 0;
70 led_count++;
71 if ((led_count & 0x07) == 0) {
72 led_set((led_state ^= (1<<USB_LED_CAPS_LOCK)));
73 }
74*/
75}
76#endif
diff --git a/common/suspend.h b/common/suspend.h
index 1c1e41ac3..f339c670a 100644
--- a/common/suspend.h
+++ b/common/suspend.h
@@ -3,29 +3,10 @@
3 3
4#include <stdint.h> 4#include <stdint.h>
5#include <stdbool.h> 5#include <stdbool.h>
6#include <avr/sleep.h>
7#include <avr/wdt.h>
8#include <avr/interrupt.h>
9 6
10 7
11#define wdt_intr_enable(value) \ 8void suspend_idle(uint8_t timeout);
12__asm__ __volatile__ ( \ 9void suspend_power_down(uint8_t timeout);
13 "in __tmp_reg__,__SREG__" "\n\t" \
14 "cli" "\n\t" \
15 "wdr" "\n\t" \
16 "sts %0,%1" "\n\t" \
17 "out __SREG__,__tmp_reg__" "\n\t" \
18 "sts %0,%2" "\n\t" \
19 : /* no outputs */ \
20 : "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \
21 "r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)), \
22 "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | \
23 _BV(WDIE) | (value & 0x07)) ) \
24 : "r0" \
25)
26
27
28void suspend_power_down(void);
29bool suspend_wakeup_condition(void); 10bool suspend_wakeup_condition(void);
30void suspend_wakeup_init(void); 11void suspend_wakeup_init(void);
31 12
diff --git a/common/timer.h b/common/timer.h
index 6437473ff..fe23f87ae 100644
--- a/common/timer.h
+++ b/common/timer.h
@@ -20,24 +20,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
20 20
21#include <stdint.h> 21#include <stdint.h>
22 22
23#ifndef TIMER_PRESCALER 23#if defined(__AVR__)
24# if F_CPU > 16000000 24#include "avr/timer_avr.h"
25# define TIMER_PRESCALER 256
26# elif F_CPU > 2000000
27# define TIMER_PRESCALER 64
28# elif F_CPU > 250000
29# define TIMER_PRESCALER 8
30# else
31# define TIMER_PRESCALER 1
32# endif
33#endif 25#endif
34#define TIMER_RAW_FREQ (F_CPU/TIMER_PRESCALER)
35#define TIMER_RAW TCNT0
36#define TIMER_RAW_TOP (TIMER_RAW_FREQ/1000)
37 26
38#if (TIMER_RAW_TOP > 255)
39# error "Timer0 can't count 1ms at this clock freq. Use larger prescaler."
40#endif
41 27
42#define TIMER_DIFF(a, b, max) ((a) >= (b) ? (a) - (b) : (max) - (b) + (a)) 28#define TIMER_DIFF(a, b, max) ((a) >= (b) ? (a) - (b) : (max) - (b) + (a))
43#define TIMER_DIFF_8(a, b) TIMER_DIFF(a, b, UINT8_MAX) 29#define TIMER_DIFF_8(a, b) TIMER_DIFF(a, b, UINT8_MAX)
diff --git a/common/wait.h b/common/wait.h
new file mode 100644
index 000000000..40d00b0c7
--- /dev/null
+++ b/common/wait.h
@@ -0,0 +1,20 @@
1#ifndef WAIT_H
2#define WAIT_H
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#if defined(__AVR__)
9# include <util/delay.h>
10# define wait_ms(ms) _delay_ms(ms)
11# define wait_us(us) _delay_us(us)
12#elif defined(__arm__)
13# include "wait_api.h"
14#endif
15
16#ifdef __cplusplus
17}
18#endif
19
20#endif
diff --git a/converter/ps2_usb/Makefile.mbed b/converter/ps2_usb/Makefile.mbed
new file mode 100644
index 000000000..631f270f7
--- /dev/null
+++ b/converter/ps2_usb/Makefile.mbed
@@ -0,0 +1,44 @@
1PROJECT = ps2_usb
2
3TMK_DIR = ../..
4MBED_DIR = $(TMK_DIR)/mbed-sdk
5
6#VPATH += $(MBED_DIR):$(TMK_DIR)
7vpath %.s .:$(MBED_DIR):$(TMK_DIR)
8vpath %.c .:$(MBED_DIR):$(TMK_DIR)
9vpath %.cpp .:$(MBED_DIR):$(TMK_DIR)
10
11OBJDIR = ./build
12
13OBJECTS = \
14 $(OBJDIR)/protocol/ps2_busywait.o \
15 $(OBJDIR)/protocol/ps2_io_mbed.o \
16 $(OBJDIR)/./keymap_common.o \
17 $(OBJDIR)/./matrix.o \
18 $(OBJDIR)/./led.o \
19 $(OBJDIR)/./main.o
20
21ifdef KEYMAP
22 OBJECTS := $(OBJDIR)/keymap_$(KEYMAP).o $(OBJECTS)
23else
24 OBJECTS := $(OBJDIR)/keymap_plain.o $(OBJECTS)
25endif
26
27CONFIG_H = config_mbed.h
28
29SYS_OBJECTS =
30
31INCLUDE_PATHS = -I.
32
33LIBRARY_PATHS =
34LIBRARIES =
35
36# Build Options
37# Comment out to disable
38#BOOTMAGIC_ENABLE = yes
39MOUSEKEY_ENABLE = yes
40
41
42include $(TMK_DIR)/tool/mbed/mbed.mk
43include $(TMK_DIR)/tool/mbed/common.mk
44include $(TMK_DIR)/tool/mbed/gcc.mk
diff --git a/converter/ps2_usb/config_mbed.h b/converter/ps2_usb/config_mbed.h
new file mode 100644
index 000000000..5819763e6
--- /dev/null
+++ b/converter/ps2_usb/config_mbed.h
@@ -0,0 +1,60 @@
1/*
2Copyright 2012 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#ifndef CONFIG_MBED_H
19#define CONFIG_MBED_H
20
21
22#if 0
23// duplicated name against mbed USBDeivce
24#define VENDOR_ID 0xFEED
25#define PRODUCT_ID 0x6512
26#endif
27#define DEVICE_VER 0x0001
28#define MANUFACTURER t.m.k.
29#define PRODUCT PS/2 keyboard converter
30#define DESCRIPTION convert PS/2 keyboard to USB
31
32
33/* matrix size */
34#define MATRIX_ROWS 32 // keycode bit: 3-0
35#define MATRIX_COLS 8 // keycode bit: 6-4
36
37
38/* key combination for command */
39#define IS_COMMAND() ( \
40 keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) || \
41 keyboard_report->mods == (MOD_BIT(KC_LCTRL) | MOD_BIT(KC_RSHIFT)) \
42)
43
44
45/*
46 * PS/2 Busywait
47 */
48#ifdef PS2_USE_BUSYWAIT
49# define PS2_CLOCK_PORT PORTD
50# define PS2_CLOCK_PIN PIND
51# define PS2_CLOCK_DDR DDRD
52# define PS2_CLOCK_BIT 5
53# define PS2_DATA_PORT PORTD
54# define PS2_DATA_PIN PIND
55# define PS2_DATA_DDR DDRD
56# define PS2_DATA_BIT 2
57#endif
58
59
60#endif
diff --git a/converter/ps2_usb/keymap_common.c b/converter/ps2_usb/keymap_common.c
index 241d2e33b..e344fb416 100644
--- a/converter/ps2_usb/keymap_common.c
+++ b/converter/ps2_usb/keymap_common.c
@@ -15,10 +15,11 @@ You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>. 15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/ 16*/
17#include "keymap_common.h" 17#include "keymap_common.h"
18#include "progmem.h"
18 19
19 20
20/* translates key to keycode */ 21/* translates key to keycode */
21uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) 22uint8_t keymap_key_to_keycode(uint8_t layer, keypos_t key)
22{ 23{
23 return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]); 24 return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]);
24} 25}
diff --git a/converter/ps2_usb/keymap_common.h b/converter/ps2_usb/keymap_common.h
index 216a8dc02..d783e01de 100644
--- a/converter/ps2_usb/keymap_common.h
+++ b/converter/ps2_usb/keymap_common.h
@@ -19,7 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20#include <stdint.h> 20#include <stdint.h>
21#include <stdbool.h> 21#include <stdbool.h>
22#include <avr/pgmspace.h>
23#include "keycode.h" 22#include "keycode.h"
24#include "action.h" 23#include "action.h"
25#include "action_macro.h" 24#include "action_macro.h"
diff --git a/converter/ps2_usb/main.cpp b/converter/ps2_usb/main.cpp
new file mode 100644
index 000000000..860af149a
--- /dev/null
+++ b/converter/ps2_usb/main.cpp
@@ -0,0 +1,46 @@
1#include "mbed.h"
2#include "debug.h"
3#include "timer.h"
4#include "action.h"
5#include "keycode.h"
6#include "host.h"
7#include "host_driver.h"
8#include "mbed_driver.h"
9
10
11// Button and LEDs of LPC11U35 board
12DigitalIn isp(P0_1); // ISP button
13DigitalOut led_red(P0_20);
14DigitalOut led_green(P0_21);
15
16
17int main(void) {
18 isp.mode(PullUp);
19 led_red = 1;
20 led_green = 0;
21
22 timer_init();
23 host_set_driver(&mbed_driver);
24 keyboard_init();
25
26 //debug_enable = true;
27 xprintf("mbed_onekey ver.eee:\r\n");
28
29
30 bool last_isp = isp;
31 while (1) {
32 keyboard_task();
33
34 //led_green = !led_green;
35 if (last_isp == isp) continue;
36 last_isp = isp;
37 if (last_isp == 0) {
38 led_red = 0; // on
39 dprintf("timer: %i\r\n", timer_read());
40 //register_code(KC_A);
41 } else {
42 led_red = 1; // off
43 //unregister_code(KC_A);
44 }
45 }
46}
diff --git a/converter/ps2_usb/matrix.c b/converter/ps2_usb/matrix.c
index 45344c0f7..45cf2a4a9 100644
--- a/converter/ps2_usb/matrix.c
+++ b/converter/ps2_usb/matrix.c
@@ -17,8 +17,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18#include <stdint.h> 18#include <stdint.h>
19#include <stdbool.h> 19#include <stdbool.h>
20#include <avr/io.h>
21#include <util/delay.h>
22#include "action.h" 20#include "action.h"
23#include "print.h" 21#include "print.h"
24#include "util.h" 22#include "util.h"
@@ -189,6 +187,7 @@ uint8_t matrix_scan(void)
189 } 187 }
190 188
191 uint8_t code = ps2_host_recv(); 189 uint8_t code = ps2_host_recv();
190 if (code) xprintf("%i\r\n", code);
192 if (!ps2_error) { 191 if (!ps2_error) {
193 switch (state) { 192 switch (state) {
194 case INIT: 193 case INIT:
diff --git a/keyboard/hhkb/keymap_common.c b/keyboard/hhkb/keymap_common.c
index 67b3db85d..e938fb627 100644
--- a/keyboard/hhkb/keymap_common.c
+++ b/keyboard/hhkb/keymap_common.c
@@ -21,7 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
21 21
22 22
23/* translates key to keycode */ 23/* translates key to keycode */
24uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) 24uint8_t keymap_key_to_keycode(uint8_t layer, keypos_t key)
25{ 25{
26 return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]); 26 return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]);
27} 27}
diff --git a/keyboard/hhkb_rn42/MEMO.txt b/keyboard/hhkb_rn42/MEMO.txt
new file mode 100644
index 000000000..337dad603
--- /dev/null
+++ b/keyboard/hhkb_rn42/MEMO.txt
@@ -0,0 +1,523 @@
1Roving RN-42
2============
3
4Bug:
5- with Nexus5 keyboard and mouse are very laggy.
6
7- lose USB connection during power-down mode
8 - USB initialize code in main() causes this - WRONG
9 - Do not power-down during USB connection is active - DONE 11/11
10 (USB_DeviceState == USB_DEVICE_Configured) is used to check USB connection
11 matrix_power_down() matrix.c - 11/23
12
13Todo:
14
15Design:
16- remove MCU dependent power saving code from core/keyboard
17 - it should be located in project matrix.c - DONE 11/23
18- HHKB matrix.c needs matrix_prev?
19 - is_modified() is obsolete now. really needs?
20
21
22LUFA:
23USB connection check: state of USB deivce
24- USB_DeviceState:
25 USB_Deivce_State_t { Unattached, Powered, Default, Addressed, Configured*, Suspended* }
26- USB_IsInitialized: state of LUFA core setup
27 becomes true in USB_Init() USBController_AVR8.c
28 becomes false in USB_Disable() USBController_AVR8.c
29- USB_VBUS_GetStatus(): state of VBUS(power/connection)
30- USB_Disable() detaches, disables all interrupts, controller, PLL, regulater.
31
32
33Power saving:
34- confirm suspend mode lufa.c: matrix_power_*, suspend_wakeup_condition
35- 8MHz clock
36- When not connected in a few minutes get into deep sleep to save battery life
37- CTS is needed for waking up from deep sleep? How deep sleep is activated?
38- firmware controlled 3.3V DC converter to switch on/off BT module
39- sleep MCU and BT module(keyboard is not used)
40- deep sleep MCU and BT module(keyboard is not used for long time)
41- deep sleep MCU and turn off BT module(keyboard is not used and not connected)
42- Battery ADC; switching, high resistance
43 - switching gnd end of divider with PF4
44 - high resistor 100K/1M?
45 capacitor 10nF
46 http://www.eevblog.com/forum/beginners/measuring-battery-voltage-without-consuming-current/
47- During USB suspend change clock source to internal RC from external Xtal(6.8)
48- FRZCLK: you can freeze clock for power saving. still WAKEUPI and VBUSTI interrupts are available while freezing.(21.7.3)
49- Suspend: Clear Suspend Bit, Freeze clock, disable PLL, MCU sleep(21.13)
50
51Improving:
52- BT LED; connecting, linked, sleeping, deep sleeping
53- Battry LED; blink(using timer?)
54- move rn42 to protocol directory when it becomes reusable stack
55- LUFA sendchar should be buffered and serial_uart.c buffur size is too large(256).
56- ADC resolution
57 AVR120
58 AVR32138
59
60Testing:
61- Factroy reset doesn't work; need to **test again** 10K pull-up is too high?
62- Lipo voltage ADC value is not stabilized
63- DCDC converter: squeaky inducter; try other inductors
64
65- Keymap layer bug: during space is pressed(mousekey) press Fn(HHKB) then release space before Fn, in result HHKB layer is locked(toggled) unintentionally.
66
67
68Done:
69- low battery alert(solid light) 09/04
70
71
72Power routing
73-------------
74Current:
75(USB) +---(Lipo)
76 | | |
77 | | +------+ DPDT
78 | | |Switch/-----------------------+
79 | | +------+ |
80 | +-------+ | |
81 +-|Charger| | |
82 | +-------+ | +---+ |
83 | | |MCU| |
84 | | +---+ |
85 | | | |
86 | | | |
87+--------------+ +-----+ +------+ +---/--+ +-----+
88|Power Selector|--|DC 5V|--|DC3.3V|---|Switch|----|RN-42|
89+--------------+ +-----+ +------+ +------+ +-----+
90USB Power is boosted unnecessarily, not harmful?
91
92Idea 1:
93(USB) +---(Lipo)
94 | | |
95 | | +------+ DPDT
96 | | |Switch/----------+
97 | | +------+ |
98 | +-------+ | |
99 +-|Charger| | |
100 | +-------+ | +---+ |
101 | +-----+ |MCU| |
102 | |DC 5V| +---+ |
103 | +-----+ | |
104 | | | |
105+--------------+ | +---/--+ +------+ +-----+
106|Power Selector|-----+---|Switch|----|DC3.3V|-----|RN-42|
107+--------------+ +------+ +------+ +-----+
108To enable BT when USB powered it still needs to turn siwtch on, Lipo consumes quinscent current at 5V converter in vain.(Not good)
109
110Idea 2:
111(USB) +---(Lipo)
112 | | |
113 | | +------+
114 | | |Switch|
115 | | +------+
116 | +-------+ |
117 +-|Charger| |
118 | +-------+ | +---+
119 | +-----+ |MCU|----+ Controlled by firmware
120 | |DC 5V| +---+ | On: Lipo powered
121 | +-----+ | | Off: USB powered
122 | | | |enable
123+--------------+ | +------+ +-----+
124|Power Selector|-----+---|DC3.3V|-----|RN-42|
125+--------------+ +------+ +-----+
126MCU can controlled power of RN-42 without hardware switch.
127When USB powered and switch is on Lipo consumes quinscent current at 5V converter in vain.(Not good)
128
129Idea 3:
130(USB) +---(Lipo)
131 | | |
132 | | +------+
133 | | |Switch|SPST(or without)
134 | | +------+
135 | +-------+ |
136 +-|Charger| |
137 | +-------+ | +---+
138 | | |MCU|----+ Controlled by firmware
139 | | +---+ | On: Lipo powered
140 | | | | Off: USB powered
141 | | | |enable
142+--------------+ +-----+ +------+ +-----+
143|Power Selector|-|DC 5V|-|DC3.3V|-----|RN-42|
144+--------------+ +-----+ +------+ +-----+
145Switch is needed to save Lipo when not used because decent power saving is not available now. If firmware can turn off BT module completely and make MCU deep sleep the switch will be not even needed.
146
147
148
149
150
151DONE:
152- BT_INDICATOR LED turns on wrongly when touching line or pin. -- pull-up enabled on PF6/GPIO2 08/30
153- Lipo charger configuration: fast charge time: USB charger spec? -- used 2kohm
154- use LED of charger to alarm low battery. LED should be powered directly from Lipo? - cancel; powered from VUSB
155- Use RTS in serial_uart.c to resolve missing chars from help message of RN-42 - done
156- CTS/RTS lines are needed? just connect in loop back if no flow control is needed. - done
157- add IO pin to charger status CHRG; LED control(low) and detect charge status(input HiZ) 07.24
158- LINKED: add trace on PIO2 to PF6 07.24
159- Lipo voltage ADC sensing
160- Lipo charger MCP73831: needs capacitor 4.7uF *2
161- USB connection check - 07.01
162- BT on/off check: whether RX line is pulled up? - checking RTS 07.01
163- USB/BT switching BT is on -> BT, BT is off -> USB - 07.01
164- Under voltage lock out UVLO for protection of Lipo - Lipo has discharge protection at 3.100V 07.01
165- Power saving: HHKB scan, BT radio control - 9h with 850mAh, this is enough 07.01
166- Power selector doesn't work; Q4 MOSFET leaks from Lipo to USB power line. -- use Schottky instead 07/04
167
168
169
170TROUBLE SHOOT
171-------------
17207/16 After fix of voltage dividor on GPIO6, had a trouble that it could not send a char to BT module, though could receive.
173 Found R8 had wrong 1K resistor and changed to 10K, after that it can send to the module again. Not sure how it had sent with the wrong 1K before.
174
17507/18 On Linux, had an USB related trouble; keyobard or console didn't work for some reason. Changing PID cured this problem. Very annoying, took very long time before resolved it.
176
177
178
179Lipo
180----
181850mA lasts around 9 hours(07/28)
182
183Sparkfun Polymer Lithium Ion Battery 850mAh:
184https://www.sparkfun.com/products/341
185Lipo Cell spec:
186https://www.sparkfun.com/datasheets/Batteries/063048%20Li-polymer.pdf
187Protection spec:
188http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Prototyping/BatteryProtection.pdf
189 min typical max
190 over-charge 4.255 4.280 4.305
191 over-charge discover? 4.030 4.080 4.130
192 over-discharge 2.827 2.900 2.973
193 over-discharge discover 3.022 3.100 3.178
194
195ADC voltage monitor: voltage divider 10K+10K(0.5)
196 ADC=V*0.5/2.56*1024
197
198 V ADC
199 ------------------
200 4.20 0x347(839)
201 3.10 0x26b(619)
202
203
204
205
206Configuration
207-------------
208Ver 6.15 04/26/2013
209(c) Roving Networks
210***Settings***
211BTA=0006664B3AE3
212BTName=tmkBT-3AE3
213Baudrt(SW4)=115K
214Mode =DTR
215Authen=2
216Bonded=0
217Rem=000000000000
218***ADVANCED Settings***
219SrvName= keyboard/mouse
220SrvClass=0000
221DevClass=0000
222InqWindw=0100
223PagWindw=0100
224CfgTimer=255
225StatuStr=NULL
226HidFlags=3c
227DTRtimer=8
228KeySwapr=0
229***OTHER Settings***
230Profile= HID
231CfgChar= $
232SniffEna=8010
233LowPower=0
234TX Power=0
235IOPorts= 0
236IOValues=0
237Sleeptmr=0
238DebugMod=0
239RoleSwch=0
240
241
242
243Serial connection
244-----------------
245Serial line: 115200bps, 8bit, 1-stopbit, non-parity, no flow control
246SSP: 115200bps, 8bit, 1-stopbit, non-parity, no flow control(via Bluetooth)
247
248To enter command mode disconnect the module from host and type '$$$'.(you will see 'CMD')
249To exit type '---'(you will see 'END') and '+' to get local echo.
250
251
252
253Setting command mode
254--------------------
255S-,tmkBT // Device name
256SS,keyboard/mouse // service name
257SM,4 // Auto Connect DTR mode
258SW,8010 // Sniff enable 0x10*0.625ms=10ms; 50ms is laggish and not much power save
259S~,6 // HID profile
260SH,003C // HID register
261SY,0004 // Transmit power
262
263
264
265
266Other options:
267SC,0000 // COD: 000005C0 (see HID spec/Bluegiga doc)
268SD,05C0 // bit 12-8 7 6 5-0
269 // 00101 1 1 0
270 // peripheral pointing keybaord joystick, gamepad, ...
271SM,6 // Pairing mode: auto connect
272SM,4 // Master mode: Connection can be controled with GPIO6
273
274
275
276
277HID profile
278-----------
279S~,6 HID profile
280S~,0 SPP profile
281R,1 reboot
282
283
284Apple iOS
285---------
286Keyboard can be used with iPhone, but mouse cannot.
287To operate iOS with keyboard is not so useful, though.
288There may be iOS specific scancodes?
289
290
291HID flag register
292-----------------
293SH,0200
294GH
295
29610 0000 0000(0200) default
29700 0011 1000(0038) Combo
298|| | | |\_\____ number of paired devices to which the module can reconnect
299|| | | \_______ send out reports over UART (0xFF <len> <data>)
300|| \__\_________ descriptor type
301|\______________ toggle virtual keyboard on iOS when first connected
302\_______________ Force HID mode if GPIO11 is high on power-up
303
304 Descriptor type:
305 0000: keybaord
306 0001: Game Pad
307 0010: Mouse
308 0011: Combo
309 0100: Joystick
310 1xxx: reserved
311
312
313Out report - Indicator
314----------------------
3150xFE 0x02 0x01 <LED_state>
316
317
318LED Status
319----------
320Configuring 10 times per sec
321Startup/configuration timer 2 times per sec
322Discoverable/Inquiring/Idle once per sec
323Connected solid on
324
325
326Pairing
327-------
328First, host initiates pairing process and once it is done, auto connect will work thereafter.
329SM,3 Master mode
330SM,4 Auto Connect DTR Mode uses GPIO6 to make and break connection(Mode =DTR)
331 confirm: auto connect works and control connection with GPIO6
332SM,5 Auto Connect ANY Mode (Mode =ANY)
333 each time GPIO is set, make inquiry and connect to the first found device
334SM,6 automatically reconnect(Mode =Pair)
335 confirm: auto connect works well but difficult to enter command mode.
336
337SR,Z removes all remote addresses for reconnecting.
338 can be used to connect another host
339SR,I registers last inquiry address
340
341
342Fast data mode
343--------------
344The module enters fast data mode after 'remote configuration timer' window is passed from power on.
345In this mode the module does not accept '$$$' to enter command mode.
346
347Power Management
348----------------
349Inquiry and Page window Idle or Active (3.1.1)
350 Downside: delay in discovery or connection time
351 SI, // set inquiry scan window(discovery) on/off duty?
352 SJ, // set page scan window(connection)
353 This reduces averaege power >20mA to 5mA(3mA in Sniff mode)
354
355Sniff mode Transmit
356 Sniff mode is disabled by default and radio is active continuously when connected.(25-30mA)
357 In Sniff mode the radio wakes up intermittently and sleeps in very low power mode.(2mA)
358 SW,<val> // set interval timer(*0.625ms) 0000-7FFF
359
360Deep sleep Idle (3.1.2)
361 In this mode the module shuts down completly and only draws about 300uA. To enable this set the most signifant bit(0x8000) of Sniff interaval timer.
362 SW,8320 // deep sleep enable(interval=0x320*0.625=500ms)
363 In normal sleep the firmware is still running in idle mode, and wakes up about 20 times per second to check ports, update LEDs, etc. During deep sleep, the firmware actually stops runnig some tasks and the LEDs only update about once per second.
364 To wake from deep sleep there are three ways: (in worst case wake up takes 5ms)
365 *send a charactor to the UART(first charactor will be lost)
366 *toggle CTS low to high and wait 5ms
367 *wake automatically every slot time(<val>*0.625ms)
368 Once the radio is awake it stay active for exactly 1 second of inactivity and then sleeps again.
369 Downside: latency and data loss
370
371Disable Output driver Idle or Active (3.1.3)
372 S%,1000 // set all GPIO pins(0-11) to inputs.
373
374Lower Transmit Power Idle or Active (3.1.4)
375 SY,<hex> // transmit power setting(takes effect after a power cycle and reboot)
376 Downside: reducing effective range
377
378
379Optimizig for Latency
380---------------------
381By default the firmware is optimized for throughput.
382SQ,16 // set latency bit
383SQ,0 // unset latency bit
384
385
386Configuration timer settings
387----------------------------
388Remote configuration is used for the module to be configured with various commands over Bluetooth(SPP profile only?).
389
390The module has remote configuration timer to allow remote configuration over Bluetooth after power up in Slave mode. In Master modes the remote configuration timer is set to 0(no remote configuration). (In Trigger Master mode the timer is used as an idle timer to break the connection after time expires with no charactors receive.)
391 ST,0 // no remote, no local when connected
392 ST,<1-252> // local and remote with timeout in seconds from power up
393 ST,253 // local only without timeout
394 ST,254 // remote only without timeout
395 ST,255 // local and remote without timeout
396
397
398Android
399-------
4003.7.1.5 Note: To connect with Android phone the modules must wake up 11ms every 2.5seconds.
401
402
403Commands
404--------
405SC,
406SM,<val>
407SD,
408SP,<string> Pin code(alpahnumeric)
409SQ,<mask> Special configuration(GPIO, discovery mode, low latency, reboot, UART)
410SR,<hex> Store remote address
411SR,Z Erase all address
412SS,<string> Set service name(1-20)**
413ST,<val> Remote configuration timer(Master:0, Slave:0-255, Triger:as idle timer)
414SU,<val> UART baud rate
415SW,<val> low-power sniff mode** deep sleep and wake up every 625us * <val>
416SX,<0|1> bonding enable only acceps device that matches the stored address
417SY,<hex> power setting**
418SZ,<val> non-standard raw baud rate <val>=baud*0.004096
419S~,<val> Profile 0:SPP, 5:APL, 6:HID
420S-,<string> Device name -15 alphanumeric charactors
421S?,<0|1> role switch enable
422S$,<char> command mode char
423$|,<hex> low-power connect mode deep sleep/active(discoverable and connectable) cycle
424D display basic setting
425E display extended setting
426GB display the device's Bluetooth address
427GF display Bluetooth address of connected device
428GK show connection status
429GR show remote address for reconnecting
430G& show GPIO pin
431G<char> show stored setting
432+ toggle local echo on/off
433& show GPIO 3,4,6,7(DIP switch)
434C connect to stored remote address
435C,<address> connect last address
436CFI connect and go into fast data mode
437CFR connect and go into fast data mode
438CT,<address>,<val> connect to the address and disconnect after val?
439F,1 fast data mod:
440H display help
441I,<time>,<cod> inquiry scan with <cod>
442IN
443IQ scan
444IS inquiry scan with 001F00
445J hide pin code
446K, kill disconnects current connection
447L link quality
448M show modem signlal status
449O display other settings
450P,<car> pass through?
451Q quiet mode make the module not discoverable
452Q,0 discoverable and connectable
453Q,1 not discoverable and not connectable
454Q,2 not discoverable and connectable
455Q,? display current quiet mode
456R,1 reboot
457T,<0|1> pass received data while in command mode
458U,<baud>,<parity> change UART setting tentatively
459V display firmware version
460W wake from quiet mode enable discovery and connection
461Z deep sleep mode(<2mA)
462
463
464
465help
466----
467*** SET COMMANDS ***
468SA,<3,0> - Authentication
469SC,<hex> - Service Class
470SD,<hex> - Device Class
471SE,<1-16> - UUID
472SF,1 - Factory Defaults
473SH,<hex> - HID flags
474SI,<hex> - Inquiry Scan Window
475SJ,<hex> - Page Scan Window
476SL,<E,O,N> - Parity
477SM,<0-5> - Mode (0=slav,1=mstr,2=trig,3=auto,4=DTR,5=Any)
478SN,<name> - Name
479SO,<text> - conn/discon Status
480SP,<text> - Pin Code
481SR,<adr> - Remote Address
482SS,<text> - Service Name
483ST,<num> - Config Timer
484SU,<rate> - Baudrate
485SW,<hex> - Sniff Rate
486SX,<1,0> - Bonding
487SY,<hex> - TX power
488SZ,<num> - Raw Baudrate
489S~,<0-6> - Profile (0=SPP,1=DCE,2=DTE,3=MDM,4=D&S,6=HID
490S?,<0-1> - role switch
491S$,<char> - CMD mode char
492S@,<hex> - io port dir
493S&,<hex> - io port val
494S%,<hex> - io boot dir
495S^,<hex> - io boot val
496S*,<hex> - pio(8-11) set
497S|,<hex> - low power timers
498S+,<num> - DTR timer
499S=,<hex> - Key mapper
500S:,<num> - sleep timer
501*** DISPLAY ***
502D - Basic Settings
503E - Extended Settings
504G<X> - Stored setting
505GB - BT Address
506GF - BT Address of Last Connection
507GK - Connect Status
508G& - I/O Ports
509V - Firmare version
510*** OTHER ***
511C,<adr> - Connect
512F,1 - Fast Mode
513I,<time>,<cod> - Device Scan Inquiry
514J - Hide Pin Code
515K, - Kill (disconnect)
516L, - toggle local echo
517P,<text> - Pass Thru
518Q - Quiet (no discovery)
519R,1 - Reboot
520T,<0,1> - send data in CMD mode
521U,<rate>,<E,O,N> - Temp Uart Change
522Z - low power sleep
523& - Read switches
diff --git a/keyboard/hhkb_rn42/Makefile b/keyboard/hhkb_rn42/Makefile
new file mode 100644
index 000000000..3d9a602a5
--- /dev/null
+++ b/keyboard/hhkb_rn42/Makefile
@@ -0,0 +1,157 @@
1#----------------------------------------------------------------------------
2# On command line:
3#
4# make all = Make software.
5#
6# make clean = Clean out built project files.
7#
8# make coff = Convert ELF to AVR COFF.
9#
10# make extcoff = Convert ELF to AVR Extended COFF.
11#
12# make program = Download the hex file to the device.
13# Please customize your programmer settings(PROGRAM_CMD)
14#
15# make teensy = Download the hex file to the device, using teensy_loader_cli.
16# (must have teensy_loader_cli installed).
17#
18# make dfu = Download the hex file to the device, using dfu-programmer (must
19# have dfu-programmer installed).
20#
21# make flip = Download the hex file to the device, using Atmel FLIP (must
22# have Atmel FLIP installed).
23#
24# make dfu-ee = Download the eeprom file to the device, using dfu-programmer
25# (must have dfu-programmer installed).
26#
27# make flip-ee = Download the eeprom file to the device, using Atmel FLIP
28# (must have Atmel FLIP installed).
29#
30# make debug = Start either simulavr or avarice as specified for debugging,
31# with avr-gdb or avr-insight as the front end for debugging.
32#
33# make filename.s = Just compile filename.c into the assembler code only.
34#
35# make filename.i = Create a preprocessed source file for use in submitting
36# bug reports to the GCC project.
37#
38# To rebuild project do "make clean" then "make all".
39#----------------------------------------------------------------------------
40
41# Target file name (without extension).
42TARGET = hhkb_lufa
43
44# Directory common source filess exist
45TOP_DIR = ../..
46
47# Directory keyboard dependent files exist
48TARGET_DIR = .
49
50
51# List C source files here. (C dependencies are automatically generated.)
52SRC += keymap_common.c \
53 matrix.c \
54 led.c
55
56CONFIG_H = config.h
57
58
59# MCU name
60# PJRC Teensy++ 2.0
61#MCU = at90usb1286
62# TMK Alt Controller or PJRC Teensy 2.0
63MCU = atmega32u4
64
65# Processor frequency.
66# This will define a symbol, F_CPU, in all source code files equal to the
67# processor frequency in Hz. You can then use this symbol in your source code to
68# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
69# automatically to create a 32-bit value in your source code.
70#
71# This will be an integer division of F_USB below, as it is sourced by
72# F_USB after it has run through any CPU prescalers. Note that this value
73# does not *change* the processor frequency - it should merely be updated to
74# reflect the processor speed set externally so that the code can use accurate
75# software delays.
76F_CPU = 16000000
77
78
79#
80# LUFA specific
81#
82# Target architecture (see library "Board Types" documentation).
83ARCH = AVR8
84
85# Input clock frequency.
86# This will define a symbol, F_USB, in all source code files equal to the
87# input clock frequency (before any prescaling is performed) in Hz. This value may
88# differ from F_CPU if prescaling is used on the latter, and is required as the
89# raw input clock is fed directly to the PLL sections of the AVR for high speed
90# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
91# at the end, this will be done automatically to create a 32-bit value in your
92# source code.
93#
94# If no clock division is performed on the input clock inside the AVR (via the
95# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
96F_USB = $(F_CPU)
97
98# Interrupt driven control endpoint task
99#OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
100
101
102# Boot Section Size in *bytes*
103# Teensy halfKay 512
104# Teensy++ halfKay 1024
105# Atmel DFU loader 4096 (TMK Alt Controller)
106# LUFA bootloader 4096
107# USBaspLoader 2048
108OPT_DEFS += -DBOOTLOADER_SIZE=4096
109
110
111# Build Options
112# comment out to disable the options.
113#
114#BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration
115MOUSEKEY_ENABLE = yes # Mouse keys
116EXTRAKEY_ENABLE = yes # Audio control and System control
117CONSOLE_ENABLE = yes # Console for debug
118COMMAND_ENABLE = yes # Commands for debug and configuration
119#NKRO_ENABLE = yes # USB Nkey Rollover
120#KEYMAP_SECTION_ENABLE = yes # fixed address keymap for keymap editor
121#HHKB_JP = yes # HHKB JP support
122
123
124ifdef HHKB_JP
125 OPT_DEFS += -DHHKB_JP
126endif
127
128
129#
130# Keymap file
131#
132ifdef KEYMAP
133 SRC := keymap_$(KEYMAP).c $(SRC)
134else
135 ifdef HHKB_JP
136 SRC := keymap_jp.c $(SRC)
137 else
138 SRC := keymap_hasu.c $(SRC)
139 endif
140endif
141
142
143# Search Path
144VPATH += $(TARGET_DIR)
145VPATH += $(TOP_DIR)
146
147include rn42.mk
148include $(TOP_DIR)/protocol.mk
149include $(TOP_DIR)/protocol/lufa.mk
150include $(TOP_DIR)/common.mk
151include $(TOP_DIR)/rules.mk
152
153debug-on: EXTRAFLAGS += -DDEBUG -DDEBUG_ACTION
154debug-on: all
155
156debug-off: EXTRAFLAGS += -DNO_DEBUG -DNO_PRINT
157debug-off: all
diff --git a/keyboard/hhkb_rn42/PowerSave.txt b/keyboard/hhkb_rn42/PowerSave.txt
new file mode 100644
index 000000000..943923c33
--- /dev/null
+++ b/keyboard/hhkb_rn42/PowerSave.txt
@@ -0,0 +1,102 @@
1RN-42
2=====
3
4HHKB key switch power control
5-----------------------------
6MOS FET Nch: BSS138 or IRLML6344T, either works and no apparent difference.
7Normally on(pull-up) or off(pull-down)? interms of power saving it prefers pull-down?
8
9Pull-down will be better for power saving, normally off.
10
11
12
13Used Timer
14----------
15
168MHz clock
17----------
181) 16MHz xtal with system prescaler div2: F_CPU=8MHz, F_USB=16MHz
192) 8MHz xtal with div1: F_CPU=8MHz, F_USB=8MHz
20Hardware USART doesn't work at 115200bps with 8MHz(F_CPU).
21
22workaround:
23a) use Sotwre serial for communcation with RN-42
24b) reduce baud of RN-42 to lower rate;(factory default is 115200bps)
2510/03
26
27
28
29Slave mode
30----------
31Discovery/Inquire
32Connect/Page
33
34SI,0012
35SJ,0012
36InqWindw=0100
37PagWindw=0100
38
39
40Sniff mode
41----------
420.625ms * <hex>
43SW,0320 Very sluggish. Type is not lost but very slow to register.
44SW,0160 Still sluggish. may transposed? can type but ...
45 Mouse point move intermittently
46SW,0020 feel a bit late like stumble(20ms)
47SW,0010 feel no latency(10ms)
48
49
50Deep sleep
51----------
52SW,8010
53
54
55TX power
56--------
57SY,fff4
58
59
60IO pins
61-------
62S%,1000 status led and connection control don't work
63 GPIO5: status LED
64 GPIO6: Connection control
65 GPIO2: linked status
66
67
68
69
70
71Ver 6.15 04/26/2013
72(c) Roving Networks
73***Settings***
74BTA=00066667BBE9
75BTName=tmkBT-BBE9
76Baudrt(SW4)=115K
77Mode =DTR
78Authen=1
79Bonded=0
80Rem=001BDC06415B
81***ADVANCED Settings***
82SrvName= keyboard/mouse
83SrvClass=0000
84DevClass=1F00
85InqWindw=0012
86PagWindw=0012
87CfgTimer=255
88StatuStr=NULL
89HidFlags=3c
90DTRtimer=8
91KeySwapr=0
92***OTHER Settings***
93Profile= HID
94CfgChar= $
95SniffEna=8010
96LowPower=0 S|,
97TX Power=fff4 SY,
98IOPorts= 0
99IOValues=0
100Sleeptmr=0
101DebugMod=0
102RoleSwch=0
diff --git a/keyboard/hhkb_rn42/config.h b/keyboard/hhkb_rn42/config.h
new file mode 100644
index 000000000..21e73f1c5
--- /dev/null
+++ b/keyboard/hhkb_rn42/config.h
@@ -0,0 +1,112 @@
1/*
2Copyright 2011 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#ifndef CONFIG_H
19#define CONFIG_H
20
21
22#define VENDOR_ID 0xFEED
23#define PRODUCT_ID 0x4242
24#define DEVICE_VER 0x0104
25#define MANUFACTURER t.m.k.
26#define PRODUCT HHKB mod
27#define DESCRIPTION t.m.k. keyboard firmware for HHKB mod
28
29
30/* matrix size */
31#ifdef HHKB_JP
32# define MATRIX_ROWS 16
33#else
34# define MATRIX_ROWS 8
35#endif
36#define MATRIX_COLS 8
37
38
39/* key combination for command */
40#define IS_COMMAND() (keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)))
41
42
43/* period of tapping(ms) */
44#define TAPPING_TERM 300
45/* tap count needed for toggling a feature */
46#define TAPPING_TOGGLE 5
47/* Oneshot timeout(ms) */
48#define ONESHOT_TIMEOUT 300
49
50/* Boot Magic salt key: Space */
51#define BOOTMAGIC_KEY_SALT KC_FN6
52
53/* power control of key switch board */
54#define HHKB_POWER_SAVING
55
56/*
57 * Hardware Serial(UART)
58 * Baud rate are calculated with round off(+0.5).
59 */
60#ifdef __AVR_ATmega32U4__
61 /* iom32u4.h has no definition of UCSR1D. copy from iom32u2.h */
62 #define UCSR1D _SFR_MEM8(0xCB)
63 #define RTSEN 0
64 #define CTSEN 1
65
66 #define SERIAL_UART_BAUD 115200
67 #define SERIAL_UART_DATA UDR1
68 #define SERIAL_UART_UBRR ((F_CPU/(16.0*SERIAL_UART_BAUD)-1+0.5))
69 #define SERIAL_UART_RXD_VECT USART1_RX_vect
70 #define SERIAL_UART_TXD_READY (UCSR1A&(1<<UDRE1))
71 #define SERIAL_UART_INIT() do { \
72 UBRR1L = (uint8_t) SERIAL_UART_UBRR; /* baud rate */ \
73 UBRR1H = ((uint16_t)SERIAL_UART_UBRR>>8); /* baud rate */ \
74 UCSR1B |= (1<<RXCIE1) | (1<<RXEN1); /* RX interrupt, RX: enable */ \
75 UCSR1B |= (0<<TXCIE1) | (1<<TXEN1); /* TX interrupt, TX: enable */ \
76 UCSR1C |= (0<<UPM11) | (0<<UPM10); /* parity: none(00), even(01), odd(11) */ \
77 UCSR1D |= (0<<RTSEN) | (0<<CTSEN); /* RTS, CTS(no flow control by hardware) */ \
78 DDRD |= (1<<5); PORTD &= ~(1<<5); /* RTS for flow control by firmware */ \
79 sei(); \
80 } while(0)
81 #define SERIAL_UART_RTS_LO() do { PORTD &= ~(1<<5); } while (0)
82 #define SERIAL_UART_RTS_HI() do { PORTD |= (1<<5); } while (0)
83#else
84 #error "USART configuration is needed."
85#endif
86
87
88/* for debug */
89#define SUART_OUT_PORT PORTD
90#define SUART_OUT_BIT 0
91#define SUART_IN_PIN PIND
92#define SUART_IN_BIT 1
93
94
95/*
96 * Feature disable options
97 * These options are also useful to firmware size reduction.
98 */
99/* disable debug print */
100//#define NO_DEBUG
101
102/* disable print */
103//#define NO_PRINT
104
105/* disable action features */
106//#define NO_ACTION_LAYER
107//#define NO_ACTION_TAPPING
108//#define NO_ACTION_ONESHOT
109//#define NO_ACTION_MACRO
110//#define NO_ACTION_FUNCTION
111
112#endif
diff --git a/keyboard/hhkb_rn42/hhkb_avr.h b/keyboard/hhkb_rn42/hhkb_avr.h
new file mode 100644
index 000000000..f007d7667
--- /dev/null
+++ b/keyboard/hhkb_rn42/hhkb_avr.h
@@ -0,0 +1,164 @@
1#ifndef HHKB_AVR_H
2#define HHKB_AVR_H
3
4#include <stdint.h>
5#include <stdbool.h>
6#include <avr/io.h>
7#include <avr/interrupt.h>
8#include <util/delay.h>
9
10
11// Timer resolution check
12#if (1000000/TIMER_RAW_FREQ > 20)
13# error "Timer resolution(>20us) is not enough for HHKB matrix scan tweak on V-USB."
14#endif
15
16
17/*
18 * HHKB Matrix I/O
19 *
20 * row: HC4051[A,B,C] selects scan row0-7
21 * row-ext: [En0,En1] row extention for JP
22 * col: LS145[A,B,C,D] selects scan col0-7 and enable(D)
23 * key: on: 0/off: 1
24 * prev: hysteresis control: assert(1) when previous key state is on
25 */
26
27
28#if defined(__AVR_ATmega32U4__)
29/*
30 * For TMK HHKB alt controller(ATMega32U4)
31 *
32 * row: PB0-2
33 * col: PB3-5,6
34 * key: PD7(pull-uped)
35 * prev: PB7
36 * power: PD4(L:off/H:on)
37 * row-ext: PC6,7 for HHKB JP(active low)
38 */
39static inline void KEY_ENABLE(void) { (PORTB &= ~(1<<6)); }
40static inline void KEY_UNABLE(void) { (PORTB |= (1<<6)); }
41static inline bool KEY_STATE(void) { return (PIND & (1<<7)); }
42static inline void KEY_PREV_ON(void) { (PORTB |= (1<<7)); }
43static inline void KEY_PREV_OFF(void) { (PORTB &= ~(1<<7)); }
44#ifdef HHKB_POWER_SAVING
45static inline void KEY_POWER_ON(void) {
46 DDRB = 0xFF; PORTB = 0x40; // change pins output
47 DDRD |= (1<<4); PORTD |= (1<<4); // MOS FET switch on
48 /* Without this wait you will miss or get false key events. */
49 _delay_ms(5); // wait for powering up
50}
51static inline void KEY_POWER_OFF(void) {
52 /* input with pull-up consumes less than without it when pin is open. */
53 DDRB = 0x00; PORTB = 0xFF; // change pins input with pull-up
54 DDRD |= (1<<4); PORTD &= ~(1<<4); // MOS FET switch off
55}
56#else
57static inline void KEY_POWER_ON(void) {}
58static inline void KEY_POWER_OFF(void) {}
59#endif
60static inline void KEY_INIT(void)
61{
62 /* row,col,prev: output */
63 DDRB = 0xFF;
64 PORTB = 0x40; // unable
65 /* key: input with pull-up */
66 DDRD &= ~0x80;
67 PORTD |= 0x80;
68#ifdef HHKB_JP
69 /* row extention for HHKB JP */
70 DDRC |= (1<<6|1<<7);
71 PORTC |= (1<<6|1<<7);
72#endif
73 KEY_UNABLE();
74 KEY_PREV_OFF();
75
76 KEY_POWER_ON();
77}
78static inline void KEY_SELECT(uint8_t ROW, uint8_t COL)
79{
80 PORTB = (PORTB & 0xC0) | (((COL) & 0x07)<<3) | ((ROW) & 0x07);
81#ifdef HHKB_JP
82 if ((ROW) & 0x08) PORTC = (PORTC & ~(1<<6|1<<7)) | (1<<6);
83 else PORTC = (PORTC & ~(1<<6|1<<7)) | (1<<7);
84#endif
85}
86
87
88#elif defined(__AVR_AT90USB1286__)
89/*
90 * For Teensy++(AT90USB1286)
91 *
92 * HHKB pro HHKB pro2
93 * row: PB0-2 (6-8) (5-7)
94 * col: PB3-5,6 (9-12) (8-11)
95 * key: PE6(pull-uped) (4) (3)
96 * prev: PE7 (5) (4)
97 *
98 * TODO: convert into 'staitc inline' function
99 */
100#define KEY_INIT() do { \
101 DDRB |= 0x7F; \
102 DDRE |= (1<<7); \
103 DDRE &= ~(1<<6); \
104 PORTE |= (1<<6); \
105} while (0)
106#define KEY_SELECT(ROW, COL) (PORTB = (PORTB & 0xC0) | \
107 (((COL) & 0x07)<<3) | \
108 ((ROW) & 0x07))
109#define KEY_ENABLE() (PORTB &= ~(1<<6))
110#define KEY_UNABLE() (PORTB |= (1<<6))
111#define KEY_STATE() (PINE & (1<<6))
112#define KEY_PREV_ON() (PORTE |= (1<<7))
113#define KEY_PREV_OFF() (PORTE &= ~(1<<7))
114#define KEY_POWER_ON()
115#define KEY_POWER_OFF()
116
117
118#else
119# error "define code for matrix scan"
120#endif
121
122
123#if 0
124// For ATMega328P with V-USB
125//
126// #elif defined(__AVR_ATmega328P__)
127// Ports for V-USB
128// key: PB0(pull-uped)
129// prev: PB1
130// row: PB2-4
131// col: PC0-2,3
132// power: PB5(Low:on/Hi-z:off)
133#define KEY_INIT() do { \
134 DDRB |= 0x3E; \
135 DDRB &= ~(1<<0); \
136 PORTB |= 1<<0; \
137 DDRC |= 0x0F; \
138 KEY_UNABLE(); \
139 KEY_PREV_OFF(); \
140} while (0)
141#define KEY_SELECT(ROW, COL) do { \
142 PORTB = (PORTB & 0xE3) | ((ROW) & 0x07)<<2; \
143 PORTC = (PORTC & 0xF8) | ((COL) & 0x07); \
144} while (0)
145#define KEY_ENABLE() (PORTC &= ~(1<<3))
146#define KEY_UNABLE() (PORTC |= (1<<3))
147#define KEY_STATE() (PINB & (1<<0))
148#define KEY_PREV_ON() (PORTB |= (1<<1))
149#define KEY_PREV_OFF() (PORTB &= ~(1<<1))
150// Power supply switching
151#define KEY_POWER_ON() do { \
152 KEY_INIT(); \
153 PORTB &= ~(1<<5); \
154 _delay_ms(1); \
155} while (0)
156#define KEY_POWER_OFF() do { \
157 DDRB &= ~0x3F; \
158 PORTB &= ~0x3F; \
159 DDRC &= ~0x0F; \
160 PORTC &= ~0x0F; \
161} while (0)
162#endif
163
164#endif
diff --git a/keyboard/hhkb_rn42/keymap_common.c b/keyboard/hhkb_rn42/keymap_common.c
new file mode 100644
index 000000000..e938fb627
--- /dev/null
+++ b/keyboard/hhkb_rn42/keymap_common.c
@@ -0,0 +1,33 @@
1/*
2Copyright 2012,2013 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17#include <stdint.h>
18#include "action.h"
19#include <avr/pgmspace.h>
20#include "keymap_common.h"
21
22
23/* translates key to keycode */
24uint8_t keymap_key_to_keycode(uint8_t layer, keypos_t key)
25{
26 return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]);
27}
28
29/* translates Fn keycode to action */
30action_t keymap_fn_to_action(uint8_t keycode)
31{
32 return (action_t){ .code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]) };
33}
diff --git a/keyboard/hhkb_rn42/keymap_common.h b/keyboard/hhkb_rn42/keymap_common.h
new file mode 100644
index 000000000..3622665f3
--- /dev/null
+++ b/keyboard/hhkb_rn42/keymap_common.h
@@ -0,0 +1,84 @@
1/*
2Copyright 2012,2013 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17#ifndef KEYMAP_COMMON_H
18#define KEYMAP_COMMON_H
19
20#include <stdint.h>
21#include <stdbool.h>
22#include "keycode.h"
23#include "action.h"
24#include "action_code.h"
25#include "action_layer.h"
26#include "action_macro.h"
27#include "action_util.h"
28#include "report.h"
29#include "host.h"
30#include "print.h"
31#include "debug.h"
32#include "keymap.h"
33
34
35extern const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
36extern const uint16_t fn_actions[];
37
38
39#define KEYMAP( \
40 K31, K30, K00, K10, K11, K20, K21, K40, K41, K60, K61, K70, K71, K50, K51, \
41 K32, K01, K02, K13, K12, K23, K22, K42, K43, K62, K63, K73, K72, K52, \
42 K33, K04, K03, K14, K15, K24, K25, K45, K44, K65, K64, K74, K53, \
43 K34, K05, K06, K07, K16, K17, K26, K46, K66, K76, K75, K55, K54, \
44 K35, K36, K37, K57, K56 \
45) \
46{ \
47 { KC_##K00, KC_##K01, KC_##K02, KC_##K03, KC_##K04, KC_##K05, KC_##K06, KC_##K07 }, \
48 { KC_##K10, KC_##K11, KC_##K12, KC_##K13, KC_##K14, KC_##K15, KC_##K16, KC_##K17 }, \
49 { KC_##K20, KC_##K21, KC_##K22, KC_##K23, KC_##K24, KC_##K25, KC_##K26, KC_NO }, \
50 { KC_##K30, KC_##K31, KC_##K32, KC_##K33, KC_##K34, KC_##K35, KC_##K36, KC_##K37 }, \
51 { KC_##K40, KC_##K41, KC_##K42, KC_##K43, KC_##K44, KC_##K45, KC_##K46, KC_NO }, \
52 { KC_##K50, KC_##K51, KC_##K52, KC_##K53, KC_##K54, KC_##K55, KC_##K56, KC_##K57 }, \
53 { KC_##K60, KC_##K61, KC_##K62, KC_##K63, KC_##K64, KC_##K65, KC_##K66, KC_NO }, \
54 { KC_##K70, KC_##K71, KC_##K72, KC_##K73, KC_##K74, KC_##K75, KC_##K76, KC_NO } \
55}
56
57
58#define KEYMAP_JP( \
59 K02, K32, K62, K22, K12, K52, K72, KA2, K92, K82, KB2, KE2, KF2, KD2, KC2, \
60 K03, K63, K23, K13, K53, K73, KA3, K93, K83, KB3, KE3, KF3, KD3, \
61 K06, K66, K26, K16, K56, K76, KA6, K96, K86, KB6, KE6, KF6, KD6, KC6, \
62 K05, K65, K25, K15, K55, K75, KA5, K95, K85, KB5, KE5, KF5, KD5, KC5, \
63 K04, K34, K64, K24, K14, K74, K94, K84, KB4, KE4, KF4, KD4, KC4 \
64) \
65{ \
66 { KC_NO, KC_NO, KC_##K02, KC_##K03, KC_##K04, KC_##K05, KC_##K06, KC_NO }, \
67 { KC_NO, KC_NO, KC_##K12, KC_##K13, KC_##K14, KC_##K15, KC_##K16, KC_NO }, \
68 { KC_NO, KC_NO, KC_##K22, KC_##K23, KC_##K24, KC_##K25, KC_##K26, KC_NO }, \
69 { KC_NO, KC_NO, KC_##K32, KC_NO, KC_##K34, KC_NO, KC_NO, KC_NO }, \
70 { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \
71 { KC_NO, KC_NO, KC_##K52, KC_##K53, KC_NO, KC_##K55, KC_##K56, KC_NO }, \
72 { KC_NO, KC_NO, KC_##K62, KC_##K63, KC_##K64, KC_##K65, KC_##K66, KC_NO }, \
73 { KC_NO, KC_NO, KC_##K72, KC_##K73, KC_##K74, KC_##K75, KC_##K76, KC_NO }, \
74 { KC_NO, KC_NO, KC_##K82, KC_##K83, KC_##K84, KC_##K85, KC_##K86, KC_NO }, \
75 { KC_NO, KC_NO, KC_##K92, KC_##K93, KC_##K94, KC_##K95, KC_##K96, KC_NO }, \
76 { KC_NO, KC_NO, KC_##KA2, KC_##KA3, KC_NO, KC_##KA5, KC_##KA6, KC_NO }, \
77 { KC_NO, KC_NO, KC_##KB2, KC_##KB3, KC_##KB4, KC_##KB5, KC_##KB6, KC_NO }, \
78 { KC_NO, KC_NO, KC_##KC2, KC_NO, KC_##KC4, KC_##KC5, KC_##KC6, KC_NO }, \
79 { KC_NO, KC_NO, KC_##KD2, KC_##KD3, KC_##KD4, KC_##KD5, KC_##KD6, KC_NO }, \
80 { KC_NO, KC_NO, KC_##KE2, KC_##KE3, KC_##KE4, KC_##KE5, KC_##KE6, KC_NO }, \
81 { KC_NO, KC_NO, KC_##KF2, KC_##KF3, KC_##KF4, KC_##KF5, KC_##KF6, KC_NO } \
82}
83
84#endif
diff --git a/keyboard/hhkb_rn42/keymap_hasu.c b/keyboard/hhkb_rn42/keymap_hasu.c
new file mode 100644
index 000000000..7b9378908
--- /dev/null
+++ b/keyboard/hhkb_rn42/keymap_hasu.c
@@ -0,0 +1,282 @@
1/*
2 * Hasu: my personal keymap
3 */
4#include "keymap_common.h"
5
6
7#ifdef KEYMAP_SECTION_ENABLE
8const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] __attribute__ ((section (".keymap.keymaps"))) = {
9#else
10const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
11#endif
12 /* Layer 0: Default Layer
13 * ,-----------------------------------------------------------.
14 * |Esc| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =| \| `|
15 * |-----------------------------------------------------------|
16 * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]|Backs|
17 * |-----------------------------------------------------------|
18 * |Contro| A| S| D| F| G| H| J| K| L|Fn3| '|Fn6 |
19 * |-----------------------------------------------------------|
20 * |Fn7 | Z| X| C| V| B| N| M| ,| .|Fn2|Shift |Fn1|
21 * `-----------------------------------------------------------'
22 * |Gui|Alt | Fn4 |Fn5 |Gui|
23 * `-------------------------------------------'
24 */
25 [0] = \
26 KEYMAP(ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSLS,GRV, \
27 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSPC, \
28 LCTL,A, S, D, F, G, H, J, K, L, FN3, QUOT,FN6, \
29 FN7, Z, X, C, V, B, N, M, COMM,DOT, FN2, RSFT,FN1, \
30 LGUI,LALT, FN4, FN5, RGUI),
31
32 /* Layer 1: HHKB mode[HHKB Fn]
33 * ,-----------------------------------------------------------.
34 * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del|
35 * |-----------------------------------------------------------|
36 * |Caps | | | | | | | |Psc|Slk|Pus|Up | |Backs|
37 * |-----------------------------------------------------------|
38 * |Contro|VoD|VoU|Mut| | | *| /|Hom|PgU|Lef|Rig|Enter |
39 * |-----------------------------------------------------------|
40 * |Shift | | | | | | +| -|End|PgD|Dow|Shift | |
41 * `-----------------------------------------------------------'
42 * |Gui|Alt | Space |Alt |Gui|
43 * `-------------------------------------------'
44 */
45 [1] = \
46 KEYMAP(GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
47 CAPS,NO, NO, NO, NO, NO, NO, NO, PSCR,SLCK,PAUS, UP, NO, BSPC, \
48 LCTL,VOLD,VOLU,MUTE,NO, NO, PAST,PSLS,HOME,PGUP,LEFT,RGHT,ENT, \
49 LSFT,NO, NO, NO, NO, NO, PPLS,PMNS,END, PGDN,DOWN,RSFT,TRNS, \
50 LGUI,LALT, SPC, RALT,RGUI),
51
52 /* Layer 2: Vi mode[Slash]
53 * ,-----------------------------------------------------------.
54 * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del|
55 * |-----------------------------------------------------------|
56 * |Tab |Hom|PgD|Up |PgU|End|Hom|PgD|PgUlEnd| | | |Backs|
57 * |-----------------------------------------------------------|
58 * |Contro| |Lef|Dow|Rig| |Lef|Dow|Up |Rig| | |Return |
59 * |-----------------------------------------------------------|
60 * |Shift | | | | | |Hom|PgD|PgUlEnd|Fn0|Shift | |
61 * `-----------------------------------------------------------'
62 * |Gui|Alt | Space |Alt |Gui|
63 * `-------------------------------------------'
64 */
65 [2] = \
66 KEYMAP(GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
67 TAB, HOME,PGDN,UP, PGUP,END, HOME,PGDN,PGUP,END, NO, NO, NO, BSPC, \
68 LCTL,NO, LEFT,DOWN,RGHT,NO, LEFT,DOWN,UP, RGHT,NO, NO, ENT, \
69 LSFT,NO, NO, NO, NO, NO, HOME,PGDN,PGUP,END, TRNS,RSFT,NO, \
70 LGUI,LALT, SPC, RALT,RGUI),
71
72 /* Layer 3: Mouse mode(IJKL)[Semicolon]
73 * ,-----------------------------------------------------------.
74 * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del|
75 * |-----------------------------------------------------------|
76 * |Tab | | | | | |MwL|MwD|McU|MwU|MwR|Wbk|Wfr|Alt-T|
77 * |-----------------------------------------------------------|
78 * |Contro| | | | | |Mb2|McL|McD|McR|Fn | |Return |
79 * |-----------------------------------------------------------|
80 * |Shift | | | | |Mb3|Mb2|Mb1|Mb4|Mb5| |Shift | |
81 * `-----------------------------------------------------------'
82 * |Gui |Alt | Mb1 |Fn |Fn |
83 * `--------------------------------------------'
84 * Mc: Mouse Cursor / Mb: Mouse Button / Mw: Mouse Wheel8
85 */
86 [3] = \
87 KEYMAP(GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
88 FN8, NO, NO, NO, NO, NO, LEFT,WH_D,MS_U,WH_U,RGHT,FN9, FN10,FN8, \
89 LCTL,ACL0,ACL1,ACL2,ACL2,NO, NO, MS_L,MS_D,MS_R,TRNS,NO, ENT, \
90 LSFT,NO, NO, NO, NO, BTN3,BTN2,BTN1,FN9, FN10,NO, RSFT,NO, \
91 LGUI,LALT, BTN1, TRNS,TRNS),
92
93 /* Layer 5: Mouse mode(IJKL)[Space]
94 * ,-----------------------------------------------------------.
95 * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del|
96 * |-----------------------------------------------------------|
97 * |Tab | | | | | |MwL|MwD|McU|MwU|MwR|Wbk|Wfr|Alt-T|
98 * |-----------------------------------------------------------|
99 * |Contro| | | | | |Mb2|McL|McD|McR|Mb1| |Return |
100 * |-----------------------------------------------------------|
101 * |Shift | | | | |Mb3|Mb2|Mb1|Mb4|Mb5| |Shift | |
102 * `-----------------------------------------------------------'
103 * |Gui |Alt | Mb1 |Fn |Fn |
104 * `--------------------------------------------'
105 * Mc: Mouse Cursor / Mb: Mouse Button / Mw: Mouse Wheel8
106 */
107 [4] = \
108 KEYMAP(GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
109 FN8, NO, NO, NO, NO, NO, LEFT,WH_D,MS_U,WH_U,RGHT,FN9, FN10,FN8, \
110 LCTL,VOLD,VOLU,MUTE,NO, NO, NO, MS_L,MS_D,MS_R,BTN1,NO, ENT, \
111 LSFT,NO, NO, NO, NO, BTN3,BTN2,BTN1,FN9, FN10,NO, RSFT,NO, \
112 LGUI,LALT, TRNS, TRNS,TRNS),
113
114#if 0
115 /* Layer 3: Mouse mode(HJKL)[Semicolon]
116 * ,-----------------------------------------------------------.
117 * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del|
118 * |-----------------------------------------------------------|
119 * |Tab | | | | | |MwL|MwD|MwU|MwR| | | |Backs|
120 * |-----------------------------------------------------------|
121 * |Contro| | | | | |McL|McD|McU|McR|Fn0| |Return |
122 * |-----------------------------------------------------------|
123 * |Shift | | | | |Mb3|Mb2|Mb1|Mb4|Mb5| |Shift | |
124 * `-----------------------------------------------------------'
125 * |Gui |Alt | Mb1 |Alt |Fn0|
126 * `--------------------------------------------'
127 * Mc: Mouse Cursor / Mb: Mouse Button / Mw: Mouse Wheel
128 */
129 KEYMAP(GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
130 TAB, NO, NO, NO, NO, NO, LEFT,WH_D,WH_U,RGHT,NO, NO, NO, BSPC, \
131 LCTL,NO, ACL0,ACL1,ACL2,NO, MS_L,MS_D,MS_U,MS_R,TRNS,QUOT,ENT, \
132 LSFT,NO, NO, NO, NO, BTN3,BTN2,BTN1,FN9, FN10,SLSH,RSFT,NO, \
133 LGUI,LALT, BTN1, RALT,TRNS),
134
135 /* Layer4: Mouse mode(HJKL)[Space]
136 * ,-----------------------------------------------------------.
137 * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del|
138 * |-----------------------------------------------------------|
139 * |Tab | | | | | |MwL|MwD|MwU|MwR| |Wbk|Wfr|Alt-T|
140 * |-----------------------------------------------------------|
141 * |Contro| | | | | |McL|McD|McU|McR|Fn0| |Return |
142 * |-----------------------------------------------------------|
143 * |Shift | | | | |Mb3|Mb2|Mb1|Mb4|Mb5| |Shift | |
144 * `-----------------------------------------------------------'
145 * |Gui |Alt | Fn0 |Alt |Fn0|
146 * `--------------------------------------------'
147 * Mc: Mouse Cursor / Mb: Mouse Button / Mw: Mouse Wheel
148 */
149 KEYMAP(GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
150 FN8, NO, NO, NO, NO, NO, LEFT,WH_D,WH_U,RGHT,NO, FN9, FN10,FN8, \
151 LCTL,NO, ACL0,ACL1,ACL2,NO, MS_L,MS_D,MS_U,MS_R,BTN1,NO, ENT, \
152 LSFT,NO, NO, NO, NO, BTN3,BTN2,BTN1,FN9, FN10,NO, RSFT,NO, \
153 LGUI,LALT, TRNS, RALT,RGUI),
154#endif
155#if 0
156 /* Layer x: Matias half-qwerty keyboard style[Space]
157 * ,-----------------------------------------------------------.
158 * | -| 0| 9| 8| 7| 6| 5| 4| 3| 2| 1| | | |Esc|
159 * |-----------------------------------------------------------|
160 * |Backs| P| O| I| U| Y| T| R| E| W| Q| | |Tab |
161 * |-----------------------------------------------------------|
162 * |Contro| ;| L| K| J| H| G| F| D| S| A|Con|Control |
163 * |-----------------------------------------------------------|
164 * |Shift | /| .| ,| M| N| B| V| C| X| Z|Shift | |
165 * `-----------------------------------------------------------'
166 * |Gui |Alt | Fn0 |Alt |Gui|
167 * `--------------------------------------------'
168 */
169 KEYMAP(MINS,0, 9, 8, 7, 6, 5, 4, 3, 2, 1, NO, NO, NO, ESC, \
170 BSPC,P, O, I, U, Y, T, R, E, W, Q, NO, NO, TAB, \
171 LCTL,SCLN,L, K, J, H, G, F, D, S, A, RCTL,RCTL, \
172 LSFT,SLSH,DOT, COMM,M, N, B, V, C, X, Z, RSFT,NO, \
173 LGUI,LALT, TRNS, RALT,RGUI),
174#endif
175};
176
177
178
179/* id for user defined functions */
180enum function_id {
181 LSHIFT_LPAREN,
182};
183
184enum macro_id {
185 HELLO,
186 VOLUP,
187 ALT_TAB,
188};
189
190
191/*
192 * Fn action definition
193 */
194#ifdef KEYMAP_SECTION_ENABLE
195const uint16_t fn_actions[] __attribute__ ((section (".keymap.fn_actions"))) = {
196#else
197const uint16_t fn_actions[] PROGMEM = {
198#endif
199 [0] = ACTION_DEFAULT_LAYER_SET(0), // Default layer(not used)
200 [1] = ACTION_LAYER_TAP_TOGGLE(1), // HHKB layer(toggle with 5 taps)
201 [2] = ACTION_LAYER_TAP_KEY(2, KC_SLASH), // Cursor layer with Slash*
202 [3] = ACTION_LAYER_TAP_KEY(3, KC_SCLN), // Mousekey layer with Semicolon*
203 [4] = ACTION_LAYER_TAP_KEY(4, KC_SPC), // Mousekey layer with Space
204 [5] = ACTION_LAYER_MOMENTARY(4), // Mousekey layer(IJKL)
205 [6] = ACTION_MODS_TAP_KEY(MOD_RCTL, KC_ENT), // RControl with tap Enter
206 [7] = ACTION_MODS_ONESHOT(MOD_LSFT), // Oneshot Shift
207 [8] = ACTION_MACRO(ALT_TAB), // Application switching
208 [9] = ACTION_MODS_KEY(MOD_LALT, KC_LEFT),
209 [10] = ACTION_MODS_KEY(MOD_LALT, KC_RIGHT),
210
211// [x] = ACTION_LMOD_TAP_KEY(KC_LCTL, KC_BSPC), // LControl with tap Backspace
212// [x] = ACTION_LMOD_TAP_KEY(KC_LCTL, KC_ESC), // LControl with tap Esc
213// [x] = ACTION_FUNCTION_TAP(LSHIFT_LPAREN), // Function: LShift with tap '('
214// [x] = ACTION_MACRO(HELLO), // Macro: say hello
215// [x] = ACTION_MACRO(VOLUP), // Macro: media key
216};
217
218
219/*
220 * Macro definition
221 */
222const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
223{
224 switch (id) {
225 case HELLO:
226 return (record->event.pressed ?
227 MACRO( I(0), T(H), T(E), T(L), T(L), W(255), T(O), END ) :
228 MACRO_NONE );
229 case VOLUP:
230 return (record->event.pressed ?
231 MACRO( D(VOLU), U(VOLU), END ) :
232 MACRO_NONE );
233 case ALT_TAB:
234 return (record->event.pressed ?
235 MACRO( D(LALT), D(TAB), END ) :
236 MACRO( U(TAB), END ));
237 }
238 return MACRO_NONE;
239}
240
241
242
243/*
244 * user defined action function
245 */
246void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
247{
248 if (record->event.pressed) dprint("P"); else dprint("R");
249 dprintf("%d", record->tap.count);
250 if (record->tap.interrupted) dprint("i");
251 dprint("\n");
252
253 switch (id) {
254 case LSHIFT_LPAREN:
255 // Shift parentheses example: LShft + tap '('
256 // http://stevelosh.com/blog/2012/10/a-modern-space-cadet/#shift-parentheses
257 // http://geekhack.org/index.php?topic=41989.msg1304899#msg1304899
258 if (record->event.pressed) {
259 if (record->tap.count > 0 && !record->tap.interrupted) {
260 if (record->tap.interrupted) {
261 dprint("tap interrupted\n");
262 register_mods(MOD_BIT(KC_LSHIFT));
263 }
264 } else {
265 register_mods(MOD_BIT(KC_LSHIFT));
266 }
267 } else {
268 if (record->tap.count > 0 && !(record->tap.interrupted)) {
269 add_weak_mods(MOD_BIT(KC_LSHIFT));
270 send_keyboard_report();
271 register_code(KC_9);
272 unregister_code(KC_9);
273 del_weak_mods(MOD_BIT(KC_LSHIFT));
274 send_keyboard_report();
275 record->tap.count = 0; // ad hoc: cancel tap
276 } else {
277 unregister_mods(MOD_BIT(KC_LSHIFT));
278 }
279 }
280 break;
281 }
282}
diff --git a/keyboard/hhkb_rn42/keymap_jp.c b/keyboard/hhkb_rn42/keymap_jp.c
new file mode 100644
index 000000000..48d0ee70b
--- /dev/null
+++ b/keyboard/hhkb_rn42/keymap_jp.c
@@ -0,0 +1,50 @@
1/*
2 * HHKB JP Layout
3 */
4#include "keymap_common.h"
5
6
7#ifdef KEYMAP_SECTION_ENABLE
8const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] __attribute__ ((section (".keymap.keymaps"))) = {
9#else
10const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
11#endif
12 /* Layer 0: Default Layer */
13 KEYMAP_JP(ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, JYEN,BSPC, \
14 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC, \
15 LCTL,A, S, D, F, G, H, J, K, L, SCLN,QUOT,BSLS,ENT, \
16 LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH,RO, UP, RSFT, \
17 FN0, ZKHK,LGUI,LALT,MHEN, SPC, HENK,KANA,RALT,FN0, LEFT,DOWN,RGHT),
18
19 /* Layer 1: HHKB mode (HHKB Fn)
20 * ,-----------------------------------------------------------.
21 * |Pwr| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del|
22 * |-----------------------------------------------------------|
23 * |Caps | | | | | | | |Psc|Slk|Pus|Up | | |
24 * |------------------------------------------------------` |
25 * | |VoD|VoU|Mut| | | *| /|Hom|PgU|Lef|Rig| | |
26 * |-----------------------------------------------------------|
27 * | | | | | | | +| -|End|PgD|Dow| | | |
28 * |-----------------------------------------------------------|
29 * | || | | | | | | | | || | | |
30 * `-----------------------------------------------------------'
31 */
32 KEYMAP_JP(PWR, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
33 CAPS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,PSCR,SLCK,PAUS, UP, TRNS, \
34 TRNS,VOLD,VOLU,MUTE,TRNS,TRNS,PAST,PSLS,HOME,PGUP,LEFT,RGHT,TRNS,PENT, \
35 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,PPLS,PMNS,END, PGDN,DOWN,TRNS,TRNS,TRNS, \
36 TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS),
37};
38
39
40
41/*
42 * Fn action definition
43 */
44#ifdef KEYMAP_SECTION_ENABLE
45const uint16_t fn_actions[] __attribute__ ((section (".keymap.fn_actions"))) = {
46#else
47const uint16_t fn_actions[] PROGMEM = {
48#endif
49 [0] = ACTION_LAYER_MOMENTARY(1),
50};
diff --git a/keyboard/hhkb_rn42/led.c b/keyboard/hhkb_rn42/led.c
new file mode 100644
index 000000000..8a08fe27f
--- /dev/null
+++ b/keyboard/hhkb_rn42/led.c
@@ -0,0 +1,33 @@
1/*
2Copyright 2011 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include <avr/io.h>
19#include "stdint.h"
20#include "led.h"
21
22
23/* HHKB has no LEDs */
24void led_set(uint8_t usb_led)
25{
26 if (usb_led & (1<<USB_LED_CAPS_LOCK)) {
27 DDRD |= (1<<6);
28 PORTD |= (1<<6);
29 } else {
30 DDRD |= (1<<6);
31 PORTD &= ~(1<<6);
32 }
33}
diff --git a/keyboard/hhkb_rn42/matrix.c b/keyboard/hhkb_rn42/matrix.c
new file mode 100644
index 000000000..c6c444ff5
--- /dev/null
+++ b/keyboard/hhkb_rn42/matrix.c
@@ -0,0 +1,191 @@
1/*
2Copyright 2011 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18/*
19 * scan matrix
20 */
21#include <stdint.h>
22#include <stdbool.h>
23#include <util/delay.h>
24#include "print.h"
25#include "debug.h"
26#include "util.h"
27#include "timer.h"
28#include "matrix.h"
29#include "hhkb_avr.h"
30#include <avr/wdt.h>
31#include "suspend.h"
32#include "lufa.h"
33
34
35// matrix power saving
36#define MATRIX_POWER_SAVE 10000
37static uint32_t matrix_last_modified = 0;
38static bool matrix_power = true;
39
40// matrix state buffer(1:on, 0:off)
41static matrix_row_t *matrix;
42static matrix_row_t *matrix_prev;
43static matrix_row_t _matrix0[MATRIX_ROWS];
44static matrix_row_t _matrix1[MATRIX_ROWS];
45
46
47inline
48uint8_t matrix_rows(void)
49{
50 return MATRIX_ROWS;
51}
52
53inline
54uint8_t matrix_cols(void)
55{
56 return MATRIX_COLS;
57}
58
59void matrix_init(void)
60{
61#ifdef DEBUG
62 debug_enable = true;
63 debug_keyboard = true;
64#endif
65
66 KEY_INIT();
67
68 // initialize matrix state: all keys off
69 for (uint8_t i=0; i < MATRIX_ROWS; i++) _matrix0[i] = 0x00;
70 for (uint8_t i=0; i < MATRIX_ROWS; i++) _matrix1[i] = 0x00;
71 matrix = _matrix0;
72 matrix_prev = _matrix1;
73}
74
75uint8_t matrix_scan(void)
76{
77 uint8_t *tmp;
78
79 tmp = matrix_prev;
80 matrix_prev = matrix;
81 matrix = tmp;
82
83 matrix_power_up();
84 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
85 for (uint8_t col = 0; col < MATRIX_COLS; col++) {
86 KEY_SELECT(row, col);
87 _delay_us(5);
88
89 // Not sure this is needed. This just emulates HHKB controller's behaviour.
90 if (matrix_prev[row] & (1<<col)) {
91 KEY_PREV_ON();
92 }
93 _delay_us(10);
94
95 // NOTE: KEY_STATE is valid only in 20us after KEY_ENABLE.
96 // If V-USB interrupts in this section we could lose 40us or so
97 // and would read invalid value from KEY_STATE.
98 uint8_t last = TIMER_RAW;
99
100 KEY_ENABLE();
101
102 // Wait for KEY_STATE outputs its value.
103 // 1us was ok on one HHKB, but not worked on another.
104 // no wait doesn't work on Teensy++ with pro(1us works)
105 // no wait does work on tmk PCB(8MHz) with pro2
106 // 1us wait does work on both of above
107 // 1us wait doesn't work on tmk(16MHz)
108 // 5us wait does work on tmk(16MHz)
109 // 5us wait does work on tmk(16MHz/2)
110 // 5us wait does work on tmk(8MHz)
111 // 10us wait does work on Teensy++ with pro
112 // 10us wait does work on 328p+iwrap with pro
113 // 10us wait doesn't work on tmk PCB(8MHz) with pro2(very lagged scan)
114 _delay_us(5);
115
116 if (KEY_STATE()) {
117 matrix[row] &= ~(1<<col);
118 } else {
119 matrix[row] |= (1<<col);
120 }
121
122 // Ignore if this code region execution time elapses more than 20us.
123 // MEMO: 20[us] * (TIMER_RAW_FREQ / 1000000)[count per us]
124 // MEMO: then change above using this rule: a/(b/c) = a*1/(b/c) = a*(c/b)
125 if (TIMER_DIFF_RAW(TIMER_RAW, last) > 20/(1000000/TIMER_RAW_FREQ)) {
126 matrix[row] = matrix_prev[row];
127 }
128
129 _delay_us(5);
130 KEY_PREV_OFF();
131 KEY_UNABLE();
132
133 // NOTE: KEY_STATE keep its state in 20us after KEY_ENABLE.
134 // This takes 25us or more to make sure KEY_STATE returns to idle state.
135 _delay_us(75);
136 }
137 if (matrix[row] ^ matrix_prev[row]) matrix_last_modified = timer_read32();
138 }
139 matrix_power_down();
140 return 1;
141}
142
143bool matrix_is_modified(void)
144{
145 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
146 if (matrix[i] != matrix_prev[i])
147 return true;
148 }
149 return false;
150}
151
152inline
153bool matrix_has_ghost(void)
154{
155 return false;
156}
157
158inline
159bool matrix_is_on(uint8_t row, uint8_t col)
160{
161 return (matrix[row] & (1<<col));
162}
163
164inline
165matrix_row_t matrix_get_row(uint8_t row)
166{
167 return matrix[row];
168}
169
170void matrix_print(void)
171{
172 print("\nr/c 01234567\n");
173 for (uint8_t row = 0; row < matrix_rows(); row++) {
174 xprintf("%02X: %08b\n", row, bitrev(matrix_get_row(row)));
175 }
176}
177
178void matrix_power_up(void) {
179 if (matrix_power) return;
180 KEY_POWER_ON();
181 matrix_power = true;
182}
183void matrix_power_down(void) {
184 if (!matrix_power) return;
185 // doesn't power save while USB connection is active
186 if (USB_DeviceState == DEVICE_STATE_Configured) return;
187 if (timer_elapsed32(matrix_last_modified) <= MATRIX_POWER_SAVE) return;
188 KEY_POWER_OFF();
189 suspend_power_down(WDTO_15MS);
190 matrix_power = false;
191}
diff --git a/keyboard/hhkb_rn42/rn42.mk b/keyboard/hhkb_rn42/rn42.mk
new file mode 100644
index 000000000..fd6f7db1a
--- /dev/null
+++ b/keyboard/hhkb_rn42/rn42.mk
@@ -0,0 +1,12 @@
1RN42_DIR = rn42
2
3SRC += serial_uart.c \
4 rn42/suart.S \
5 rn42/rn42.c \
6 rn42/rn42_task.c \
7 rn42/battery.c \
8 rn42/main.c
9
10OPT_DEFS += -DPROTOCOL_RN42
11
12VPATH += $(RN42_DIR)
diff --git a/keyboard/hhkb_rn42/rn42/battery.c b/keyboard/hhkb_rn42/rn42/battery.c
new file mode 100644
index 000000000..0320e1baf
--- /dev/null
+++ b/keyboard/hhkb_rn42/rn42/battery.c
@@ -0,0 +1,136 @@
1#include <avr/io.h>
2#include <util/delay.h>
3#include "battery.h"
4
5
6/*
7 * Battery
8 */
9void battery_init(void)
10{
11 // blink
12 battery_led(LED_ON); _delay_ms(500);
13 battery_led(LED_OFF); _delay_ms(500);
14 battery_led(LED_ON); _delay_ms(500);
15 battery_led(LED_OFF); _delay_ms(500);
16 // LED indicates charger status
17 battery_led(LED_CHARGER);
18
19 // ADC setting for voltage monitor
20 // Ref:2.56V band-gap, Input:ADC0(PF0), Prescale:128(16MHz/128=125KHz)
21 ADMUX = (1<<REFS1) | (1<<REFS0);
22 ADCSRA = (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0);
23 ADCSRA |= (1<<ADEN);
24
25 // ADC disable voltate divider(PF4)
26 DDRF |= (1<<4);
27 PORTF &= ~(1<<4);
28}
29
30// Indicator for battery
31void battery_led(battery_led_t val)
32{
33 if (val == LED_TOGGLE) {
34 // Toggle LED
35 DDRF |= (1<<5);
36 PINF |= (1<<5);
37 } else if (val == LED_ON) {
38 // On overriding charger status
39 DDRF |= (1<<5);
40 PORTF &= ~(1<<5);
41 } else if (val == LED_OFF) {
42 // Off overriding charger status
43 DDRF |= (1<<5);
44 PORTF |= (1<<5);
45 } else {
46 // Display charger status
47 DDRF &= ~(1<<5);
48 PORTF &= ~(1<<5);
49 }
50}
51
52bool battery_charging(void)
53{
54 if (!(USBSTA&(1<<VBUS))) return false;
55
56 // Charger Status:
57 // MCP73831 MCP73832 LTC4054 Status
58 // Hi-Z Hi-Z Hi-Z Shutdown/No Battery
59 // Low Low Low Charging
60 // Hi Hi-Z Hi-Z Charged
61
62 // preserve last register status
63 uint8_t ddrf_prev = DDRF;
64 uint8_t portf_prev = PORTF;
65
66 // Input with pullup
67 DDRF &= ~(1<<5);
68 PORTF |= (1<<5);
69 _delay_ms(1);
70 bool charging = PINF&(1<<5) ? false : true;
71
72 // restore last register status
73 DDRF = (DDRF&~(1<<5)) | (ddrf_prev&(1<<5));
74 PORTF = (PORTF&~(1<<5)) | (portf_prev&(1<<5));
75
76 // TODO: With MCP73831 this can not get stable status when charging.
77 // LED is powered from PSEL line(USB or Lipo)
78 // due to weak low output of STAT pin?
79 // due to pull-up'd via resitor and LED?
80 return charging;
81}
82
83// Returns voltage in mV
84uint16_t battery_voltage(void)
85{
86 // ADC disable voltate divider(PF4)
87 DDRF |= (1<<4);
88 PORTF |= (1<<4);
89
90 volatile uint16_t bat;
91 //ADCSRA |= (1<<ADEN);
92
93 // discard first result
94 ADCSRA |= (1<<ADSC);
95 while (ADCSRA & (1<<ADSC)) ;
96 bat = ADC;
97
98 // discard second result
99 ADCSRA |= (1<<ADSC);
100 while (ADCSRA & (1<<ADSC)) ;
101 bat = ADC;
102
103 ADCSRA |= (1<<ADSC);
104 while (ADCSRA & (1<<ADSC)) ;
105 bat = ADC;
106
107 //ADCSRA &= ~(1<<ADEN);
108
109 // ADC disable voltate divider(PF4)
110 DDRF |= (1<<4);
111 PORTF &= ~(1<<4);
112
113 return (bat - BATTERY_ADC_OFFSET) * BATTERY_ADC_RESOLUTION;
114}
115
116static bool low_voltage(void) {
117 static bool low = false;
118 uint16_t v = battery_voltage();
119 if (v < BATTERY_VOLTAGE_LOW_LIMIT) {
120 low = true;
121 } else if (v > BATTERY_VOLTAGE_LOW_RECOVERY) {
122 low = false;
123 }
124 return low;
125}
126
127battery_status_t battery_status(void)
128{
129 if (USBSTA&(1<<VBUS)) {
130 /* powered */
131 return battery_charging() ? CHARGING : FULL_CHARGED;
132 } else {
133 /* not powered */
134 return low_voltage() ? LOW_VOLTAGE : DISCHARGING;
135 }
136}
diff --git a/keyboard/hhkb_rn42/rn42/battery.h b/keyboard/hhkb_rn42/rn42/battery.h
new file mode 100644
index 000000000..180d4dcfa
--- /dev/null
+++ b/keyboard/hhkb_rn42/rn42/battery.h
@@ -0,0 +1,35 @@
1#ifndef POWER_H
2#define POWER_H
3
4#include <stdint.h>
5#include <stdbool.h>
6
7typedef enum {
8 FULL_CHARGED,
9 CHARGING,
10 DISCHARGING,
11 LOW_VOLTAGE,
12 UNKNOWN,
13} battery_status_t;
14
15typedef enum {
16 LED_CHARGER = 0,
17 LED_ON,
18 LED_OFF,
19 LED_TOGGLE,
20} battery_led_t;
21
22/* Battery API */
23void battery_init(void);
24void battery_led(battery_led_t val);
25bool battery_charging(void);
26uint16_t battery_voltage(void);
27battery_status_t battery_status(void);
28
29#define BATTERY_VOLTAGE_LOW_LIMIT 3500
30#define BATTERY_VOLTAGE_LOW_RECOVERY 3700
31// ADC offset:16, resolution:5mV
32#define BATTERY_ADC_OFFSET 16
33#define BATTERY_ADC_RESOLUTION 5
34
35#endif
diff --git a/keyboard/hhkb_rn42/rn42/main.c b/keyboard/hhkb_rn42/rn42/main.c
new file mode 100644
index 000000000..43d887067
--- /dev/null
+++ b/keyboard/hhkb_rn42/rn42/main.c
@@ -0,0 +1,102 @@
1#include <avr/io.h>
2#include <avr/power.h>
3#include <avr/wdt.h>
4#include "lufa.h"
5#include "print.h"
6#include "sendchar.h"
7#include "rn42.h"
8#include "rn42_task.h"
9#include "serial.h"
10#include "keyboard.h"
11#include "keycode.h"
12#include "action.h"
13#include "action_util.h"
14#include "wait.h"
15#include "suart.h"
16#include "suspend.h"
17
18static int8_t sendchar_func(uint8_t c)
19{
20 sendchar(c); // LUFA
21 xmit(c); // SUART
22 return 0;
23}
24
25static void SetupHardware(void)
26{
27 /* Disable watchdog if enabled by bootloader/fuses */
28 MCUSR &= ~(1 << WDRF);
29 wdt_disable();
30
31 /* Disable clock division */
32 clock_prescale_set(clock_div_1);
33
34 // Leonardo needs. Without this USB device is not recognized.
35 USB_Disable();
36
37 USB_Init();
38
39 // for Console_Task
40 USB_Device_EnableSOFEvents();
41 print_set_sendchar(sendchar_func);
42
43 // SUART PD0:output, PD1:input
44 DDRD |= (1<<0);
45 PORTD |= (1<<0);
46 DDRD &= ~(1<<1);
47 PORTD |= (1<<1);
48}
49
50int main(void) __attribute__ ((weak));
51int main(void)
52{
53 SetupHardware();
54 sei();
55
56 /* wait for USB startup to get ready for debug output */
57 uint8_t timeout = 255; // timeout when USB is not available(Bluetooth)
58 while (timeout-- && USB_DeviceState != DEVICE_STATE_Configured) {
59 wait_ms(4);
60#if defined(INTERRUPT_CONTROL_ENDPOINT)
61 ;
62#else
63 USB_USBTask();
64#endif
65 }
66 print("USB configured.\n");
67
68 rn42_init();
69 rn42_task_init();
70 print("RN-42 init\n");
71
72 /* init modules */
73 keyboard_init();
74
75 if (!rn42_rts()) {
76 host_set_driver(&rn42_driver);
77 } else {
78 host_set_driver(&lufa_driver);
79 }
80
81#ifdef SLEEP_LED_ENABLE
82 sleep_led_init();
83#endif
84
85 print("Keyboard start.\n");
86 while (1) {
87 while (USB_DeviceState == DEVICE_STATE_Suspended) {
88 suspend_power_down(WDTO_120MS);
89 if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) {
90 USB_Device_SendRemoteWakeup();
91 }
92 }
93
94 keyboard_task();
95
96#if !defined(INTERRUPT_CONTROL_ENDPOINT)
97 USB_USBTask();
98#endif
99
100 rn42_task();
101 }
102}
diff --git a/keyboard/hhkb_rn42/rn42/rn42.c b/keyboard/hhkb_rn42/rn42/rn42.c
new file mode 100644
index 000000000..1565b4cf1
--- /dev/null
+++ b/keyboard/hhkb_rn42/rn42/rn42.c
@@ -0,0 +1,208 @@
1#include <avr/io.h>
2#include "host.h"
3#include "host_driver.h"
4#include "serial.h"
5#include "rn42.h"
6#include "print.h"
7#include "wait.h"
8
9
10/* Host driver */
11static uint8_t keyboard_leds(void);
12static void send_keyboard(report_keyboard_t *report);
13static void send_mouse(report_mouse_t *report);
14static void send_system(uint16_t data);
15static void send_consumer(uint16_t data);
16
17host_driver_t rn42_driver = {
18 keyboard_leds,
19 send_keyboard,
20 send_mouse,
21 send_system,
22 send_consumer
23};
24
25
26void rn42_init(void)
27{
28 // JTAG disable for PORT F. write JTD bit twice within four cycles.
29 MCUCR |= (1<<JTD);
30 MCUCR |= (1<<JTD);
31
32 // PF7: BT connection control(high: connect, low: disconnect)
33 rn42_autoconnect();
34
35 // PF6: linked(input without pull-up)
36 DDRF &= ~(1<<6);
37 PORTF |= (1<<6);
38
39 // PF1: RTS(low: allowed to send, high: not allowed)
40 DDRF &= ~(1<<1);
41 PORTF &= ~(1<<1);
42
43 // PD5: CTS(low: allow to send, high:not allow)
44 DDRD |= (1<<5);
45 PORTD &= ~(1<<5);
46
47 serial_init();
48}
49
50void rn42_putc(uint8_t c)
51{
52 serial_send(c);
53}
54
55bool rn42_autoconnecting(void)
56{
57 // GPIO6 for control connection(high: auto connect, low: disconnect)
58 // Note that this needs config: SM,4(Auto-Connect DTR Mode)
59 return (PORTF & (1<<7) ? true : false);
60}
61
62void rn42_autoconnect(void)
63{
64 // hi to auto connect
65 DDRF |= (1<<7);
66 PORTF |= (1<<7);
67}
68
69void rn42_disconnect(void)
70{
71 // low to disconnect
72 DDRF |= (1<<7);
73 PORTF &= ~(1<<7);
74}
75
76bool rn42_rts(void)
77{
78 // low when RN-42 is powered and ready to receive
79 return PINF&(1<<1);
80}
81
82void rn42_cts_hi(void)
83{
84 // not allow to send
85 PORTD |= (1<<5);
86}
87
88void rn42_cts_lo(void)
89{
90 // allow to send
91 PORTD &= ~(1<<5);
92}
93
94bool rn42_linked(void)
95{
96 // RN-42 GPIO2
97 // Hi-Z: Not powered
98 // High: Linked
99 // Low: Connecting
100 return !rn42_rts() && PINF&(1<<6);
101}
102
103
104static uint8_t leds = 0;
105static uint8_t keyboard_leds(void) { return leds; }
106void rn42_set_leds(uint8_t l) { leds = l; }
107
108static void send_keyboard(report_keyboard_t *report)
109{
110 // wake from deep sleep
111/*
112 PORTD |= (1<<5); // high
113 wait_ms(5);
114 PORTD &= ~(1<<5); // low
115*/
116
117 serial_send(0xFD); // Raw report mode
118 serial_send(9); // length
119 serial_send(1); // descriptor type
120 serial_send(report->mods);
121 serial_send(0x00);
122 serial_send(report->keys[0]);
123 serial_send(report->keys[1]);
124 serial_send(report->keys[2]);
125 serial_send(report->keys[3]);
126 serial_send(report->keys[4]);
127 serial_send(report->keys[5]);
128}
129
130static void send_mouse(report_mouse_t *report)
131{
132 // wake from deep sleep
133/*
134 PORTD |= (1<<5); // high
135 wait_ms(5);
136 PORTD &= ~(1<<5); // low
137*/
138
139 serial_send(0xFD); // Raw report mode
140 serial_send(5); // length
141 serial_send(2); // descriptor type
142 serial_send(report->buttons);
143 serial_send(report->x);
144 serial_send(report->y);
145 serial_send(report->v);
146}
147
148static void send_system(uint16_t data)
149{
150 // Table 5-6 of RN-BT-DATA-UB
151 // 81,82,83 scan codes can be used?
152}
153
154
155static uint16_t usage2bits(uint16_t usage)
156{
157 switch (usage) {
158 case AC_HOME: return 0x01;
159 case AL_EMAIL: return 0x02;
160 case AC_SEARCH: return 0x04;
161 //case AL_KBD_LAYOUT: return 0x08; // Apple virtual keybaord toggle
162 case AUDIO_VOL_UP: return 0x10;
163 case AUDIO_VOL_DOWN: return 0x20;
164 case AUDIO_MUTE: return 0x40;
165 case TRANSPORT_PLAY_PAUSE: return 0x80;
166 case TRANSPORT_NEXT_TRACK: return 0x100;
167 case TRANSPORT_PREV_TRACK: return 0x200;
168 case TRANSPORT_STOP: return 0x400;
169 case TRANSPORT_STOP_EJECT: return 0x800;
170 //case return 0x1000; // Fast forward
171 //case return 0x2000; // Rewind
172 //case return 0x4000; // Stop/eject
173 //case return 0x8000; // Internet browser
174 };
175 return 0;
176}
177
178static void send_consumer(uint16_t data)
179{
180 uint16_t bits = usage2bits(data);
181 serial_send(0xFD); // Raw report mode
182 serial_send(3); // length
183 serial_send(3); // descriptor type
184 serial_send(bits&0xFF);
185 serial_send((bits>>8)&0xFF);
186}
187
188
189/* Null driver for config_mode */
190static uint8_t config_keyboard_leds(void);
191static void config_send_keyboard(report_keyboard_t *report);
192static void config_send_mouse(report_mouse_t *report);
193static void config_send_system(uint16_t data);
194static void config_send_consumer(uint16_t data);
195
196host_driver_t rn42_config_driver = {
197 config_keyboard_leds,
198 config_send_keyboard,
199 config_send_mouse,
200 config_send_system,
201 config_send_consumer
202};
203
204static uint8_t config_keyboard_leds(void) { return leds; }
205static void config_send_keyboard(report_keyboard_t *report) {}
206static void config_send_mouse(report_mouse_t *report) {}
207static void config_send_system(uint16_t data) {}
208static void config_send_consumer(uint16_t data) {}
diff --git a/keyboard/hhkb_rn42/rn42/rn42.h b/keyboard/hhkb_rn42/rn42/rn42.h
new file mode 100644
index 000000000..5283a3648
--- /dev/null
+++ b/keyboard/hhkb_rn42/rn42/rn42.h
@@ -0,0 +1,20 @@
1#ifndef RN42_H
2#define RN42_H
3
4#include <stdbool.h>
5
6host_driver_t rn42_driver;
7host_driver_t rn42_config_driver;
8
9void rn42_init(void);
10void rn42_putc(uint8_t c);
11bool rn42_autoconnecting(void);
12void rn42_autoconnect(void);
13void rn42_disconnect(void);
14bool rn42_rts(void);
15void rn42_cts_hi(void);
16void rn42_cts_lo(void);
17bool rn42_linked(void);
18void rn42_set_leds(uint8_t l);
19
20#endif
diff --git a/keyboard/hhkb_rn42/rn42/rn42_task.c b/keyboard/hhkb_rn42/rn42/rn42_task.c
new file mode 100644
index 000000000..c3359ed50
--- /dev/null
+++ b/keyboard/hhkb_rn42/rn42/rn42_task.c
@@ -0,0 +1,294 @@
1#include <stdint.h>
2#include "keycode.h"
3#include "serial.h"
4#include "host.h"
5#include "action.h"
6#include "action_util.h"
7#include "lufa.h"
8#include "rn42_task.h"
9#include "print.h"
10#include "debug.h"
11#include "timer.h"
12#include "command.h"
13#include "battery.h"
14
15static bool config_mode = false;
16static bool force_usb = false;
17
18static void status_led(bool on)
19{
20 if (on) {
21 DDRE |= (1<<6);
22 PORTE &= ~(1<<6);
23 } else {
24 DDRE |= (1<<6);
25 PORTE |= (1<<6);
26 }
27}
28
29void rn42_task_init(void)
30{
31 battery_init();
32}
33
34void rn42_task(void)
35{
36 int16_t c;
37 if (config_mode) {
38 // Config mode: print output from RN-42
39 while ((c = serial_recv2()) != -1) {
40 // without flow control it'll fail to receive data when flooded
41 xprintf("%c", c);
42 }
43 } else {
44 // Raw mode: interpret output report of LED state
45 while ((c = serial_recv2()) != -1) {
46 // LED Out report: 0xFE, 0x02, 0x01, <leds>
47 // To get the report over UART set bit3 with SH, command.
48 static enum {LED_INIT, LED_FE, LED_02, LED_01} state = LED_INIT;
49 switch (state) {
50 case LED_INIT:
51 if (c == 0xFE) state = LED_FE;
52 else state = LED_INIT;
53 break;
54 case LED_FE:
55 if (c == 0x02) state = LED_02;
56 else state = LED_INIT;
57 break;
58 case LED_02:
59 if (c == 0x01) state = LED_01;
60 else state = LED_INIT;
61 break;
62 case LED_01:
63 dprintf("LED status: %02X\n", c);
64 rn42_set_leds(c);
65 state = LED_INIT;
66 break;
67 default:
68 state = LED_INIT;
69 }
70 }
71 }
72
73 /* Bluetooth mode when ready */
74 if (!config_mode && !force_usb) {
75 if (!rn42_rts() && host_get_driver() != &rn42_driver) {
76 clear_keyboard();
77 host_set_driver(&rn42_driver);
78 } else if (rn42_rts() && host_get_driver() != &lufa_driver) {
79 clear_keyboard();
80 host_set_driver(&lufa_driver);
81 }
82 }
83
84
85 static uint16_t prev_timer = 0;
86 uint16_t e = timer_elapsed(prev_timer);
87 if (e > 1000) {
88 /* every second */
89 prev_timer += e/1000*1000;
90
91 /* Low voltage alert */
92 uint8_t bs = battery_status();
93 if (bs == LOW_VOLTAGE) {
94 battery_led(LED_ON);
95 } else {
96 battery_led(LED_CHARGER);
97 }
98
99 static uint8_t prev_status = UNKNOWN;
100 if (bs != prev_status) {
101 prev_status = bs;
102 switch (bs) {
103 case FULL_CHARGED: xprintf("FULL_CHARGED\n"); break;
104 case CHARGING: xprintf("CHARGING\n"); break;
105 case DISCHARGING: xprintf("DISCHARGING\n"); break;
106 case LOW_VOLTAGE: xprintf("LOW_VOLTAGE\n"); break;
107 default: xprintf("UNKNOWN STATUS\n"); break;
108 };
109 }
110
111 /* every minute */
112 uint32_t t = timer_read32()/1000;
113 if (t%60 == 0) {
114 uint16_t v = battery_voltage();
115 uint8_t h = t/3600;
116 uint8_t m = t%3600/60;
117 uint8_t s = t%60;
118 xprintf("%02u:%02u:%02u\t%umV\n", h, m, s, v);
119 /* TODO: xprintf doesn't work for this.
120 xprintf("%02u:%02u:%02u\t%umV\n", (t/3600), (t%3600/60), (t%60), v);
121 */
122 }
123 }
124
125
126 /* Connection monitor */
127 if (rn42_linked()) {
128 status_led(true);
129 } else {
130 status_led(false);
131 }
132}
133
134
135
136/******************************************************************************
137 * Command
138 ******************************************************************************/
139bool command_extra(uint8_t code)
140{
141 uint32_t t;
142 uint16_t b;
143 static host_driver_t *prev_driver = &rn42_driver;
144 switch (code) {
145 case KC_H:
146 case KC_SLASH: /* ? */
147 print("\n\n----- Bluetooth RN-42 Help -----\n");
148 print("Del: enter/exit config mode(auto_connect/disconnect)\n");
149 print("i: RN-42 info\n");
150 print("b: battery voltage\n");
151
152 if (config_mode) {
153 return true;
154 } else {
155 print("u: Force USB mode\n");
156 return false; // to display default command help
157 }
158 case KC_DELETE:
159 if (rn42_autoconnecting()) {
160 prev_driver = host_get_driver();
161 clear_keyboard();
162 _delay_ms(500);
163 host_set_driver(&rn42_config_driver); // null driver; not to send a key to host
164 rn42_disconnect();
165 print("\nRN-42: disconnect\n");
166 print("Enter config mode\n");
167 print("type $$$ to start and + for local echo\n");
168 command_state = CONSOLE;
169 config_mode = true;
170 } else {
171 rn42_autoconnect();
172 print("\nRN-42: auto_connect\n");
173 print("Exit config mode\n");
174 command_state = ONESHOT;
175 config_mode = false;
176 //clear_keyboard();
177 host_set_driver(prev_driver);
178 }
179 return true;
180 case KC_U:
181 if (config_mode) return false;
182 if (force_usb) {
183 print("Auto mode\n");
184 force_usb = false;
185 } else {
186 print("USB mode\n");
187 force_usb = true;
188 clear_keyboard();
189 host_set_driver(&lufa_driver);
190 }
191 return true;
192 case KC_I:
193 print("\n----- RN-42 info -----\n");
194 xprintf("protocol: %s\n", (host_get_driver() == &rn42_driver) ? "RN-42" : "LUFA");
195 xprintf("force_usb: %X\n", force_usb);
196 xprintf("rn42_autoconnecting(): %X\n", rn42_autoconnecting());
197 xprintf("rn42_linked(): %X\n", rn42_linked());
198 xprintf("rn42_rts(): %X\n", rn42_rts());
199 xprintf("config_mode: %X\n", config_mode);
200 xprintf("VBUS: %X\n", USBSTA&(1<<VBUS));
201 xprintf("battery_charging: %X\n", battery_charging());
202 xprintf("battery_status: %X\n", battery_status());
203 return true;
204 case KC_B:
205 // battery monitor
206 t = timer_read32()/1000;
207 b = battery_voltage();
208 xprintf("BAT: %umV\t", b);
209 xprintf("%02u:", t/3600);
210 xprintf("%02u:", t%3600/60);
211 xprintf("%02u\n", t%60);
212 return true;
213 default:
214 if (config_mode)
215 return true;
216 else
217 return false; // exec default command
218 }
219 return true;
220}
221
222static uint8_t code2asc(uint8_t code);
223bool command_console_extra(uint8_t code)
224{
225 switch (code) {
226 default:
227 rn42_putc(code2asc(code));
228 return true;
229 }
230 return false;
231}
232
233// convert keycode into ascii charactor
234static uint8_t code2asc(uint8_t code)
235{
236 bool shifted = (get_mods() & (MOD_BIT(KC_LSHIFT)|MOD_BIT(KC_RSHIFT))) ? true : false;
237 switch (code) {
238 case KC_A: return (shifted ? 'A' : 'a');
239 case KC_B: return (shifted ? 'B' : 'b');
240 case KC_C: return (shifted ? 'C' : 'c');
241 case KC_D: return (shifted ? 'D' : 'd');
242 case KC_E: return (shifted ? 'E' : 'e');
243 case KC_F: return (shifted ? 'F' : 'f');
244 case KC_G: return (shifted ? 'G' : 'g');
245 case KC_H: return (shifted ? 'H' : 'h');
246 case KC_I: return (shifted ? 'I' : 'i');
247 case KC_J: return (shifted ? 'J' : 'j');
248 case KC_K: return (shifted ? 'K' : 'k');
249 case KC_L: return (shifted ? 'L' : 'l');
250 case KC_M: return (shifted ? 'M' : 'm');
251 case KC_N: return (shifted ? 'N' : 'n');
252 case KC_O: return (shifted ? 'O' : 'o');
253 case KC_P: return (shifted ? 'P' : 'p');
254 case KC_Q: return (shifted ? 'Q' : 'q');
255 case KC_R: return (shifted ? 'R' : 'r');
256 case KC_S: return (shifted ? 'S' : 's');
257 case KC_T: return (shifted ? 'T' : 't');
258 case KC_U: return (shifted ? 'U' : 'u');
259 case KC_V: return (shifted ? 'V' : 'v');
260 case KC_W: return (shifted ? 'W' : 'w');
261 case KC_X: return (shifted ? 'X' : 'x');
262 case KC_Y: return (shifted ? 'Y' : 'y');
263 case KC_Z: return (shifted ? 'Z' : 'z');
264 case KC_1: return (shifted ? '!' : '1');
265 case KC_2: return (shifted ? '@' : '2');
266 case KC_3: return (shifted ? '#' : '3');
267 case KC_4: return (shifted ? '$' : '4');
268 case KC_5: return (shifted ? '%' : '5');
269 case KC_6: return (shifted ? '^' : '6');
270 case KC_7: return (shifted ? '&' : '7');
271 case KC_8: return (shifted ? '*' : '8');
272 case KC_9: return (shifted ? '(' : '9');
273 case KC_0: return (shifted ? ')' : '0');
274 case KC_ENTER: return '\n';
275 case KC_ESCAPE: return 0x1B;
276 case KC_BSPACE: return '\b';
277 case KC_TAB: return '\t';
278 case KC_SPACE: return ' ';
279 case KC_MINUS: return (shifted ? '_' : '-');
280 case KC_EQUAL: return (shifted ? '+' : '=');
281 case KC_LBRACKET: return (shifted ? '{' : '[');
282 case KC_RBRACKET: return (shifted ? '}' : ']');
283 case KC_BSLASH: return (shifted ? '|' : '\\');
284 case KC_NONUS_HASH: return (shifted ? '|' : '\\');
285 case KC_SCOLON: return (shifted ? ':' : ';');
286 case KC_QUOTE: return (shifted ? '"' : '\'');
287 case KC_GRAVE: return (shifted ? '~' : '`');
288 case KC_COMMA: return (shifted ? '<' : ',');
289 case KC_DOT: return (shifted ? '>' : '.');
290 case KC_SLASH: return (shifted ? '?' : '/');
291 case KC_DELETE: return '\0'; // Delete to disconnect
292 default: return ' ';
293 }
294}
diff --git a/keyboard/hhkb_rn42/rn42/rn42_task.h b/keyboard/hhkb_rn42/rn42/rn42_task.h
new file mode 100644
index 000000000..8f6c3ab64
--- /dev/null
+++ b/keyboard/hhkb_rn42/rn42/rn42_task.h
@@ -0,0 +1,10 @@
1#ifndef RN42_TASK_H
2#define RN42_TASK_H
3
4#include <stdbool.h>
5#include "rn42.h"
6
7void rn42_task_init(void);
8void rn42_task(void);
9
10#endif
diff --git a/keyboard/hhkb_rn42/rn42/suart.S b/keyboard/hhkb_rn42/rn42/suart.S
new file mode 100644
index 000000000..9fa545292
--- /dev/null
+++ b/keyboard/hhkb_rn42/rn42/suart.S
@@ -0,0 +1,156 @@
1;---------------------------------------------------------------------------;
2; Software implemented UART module ;
3; (C)ChaN, 2005 (http://elm-chan.org/) ;
4;---------------------------------------------------------------------------;
5; Bit rate settings:
6;
7; 1MHz 2MHz 4MHz 6MHz 8MHz 10MHz 12MHz 16MHz 20MHz
8; 2.4kbps 138 - - - - - - - -
9; 4.8kbps 68 138 - - - - - - -
10; 9.6kbps 33 68 138 208 - - - - -
11; 19.2kbps - 33 68 102 138 173 208 - -
12; 38.4kbps - - 33 50 68 85 102 138 172
13; 57.6kbps - - 21 33 44 56 68 91 114
14; 115.2kbps - - - - 21 27 33 44 56
15
16.nolist
17#include <avr/io.h>
18.list
19
20#define BPS 44 /* Bit delay. (see above table) */
21#define BIDIR 0 /* 0:Separated Tx/Rx, 1:Shared Tx/Rx */
22
23#define OUT_1 sbi _SFR_IO_ADDR(SUART_OUT_PORT), SUART_OUT_BIT /* Output 1 */
24#define OUT_0 cbi _SFR_IO_ADDR(SUART_OUT_PORT), SUART_OUT_BIT /* Output 0 */
25#define SKIP_IN_1 sbis _SFR_IO_ADDR(SUART_IN_PIN), SUART_IN_BIT /* Skip if 1 */
26#define SKIP_IN_0 sbic _SFR_IO_ADDR(SUART_IN_PIN), SUART_IN_BIT /* Skip if 0 */
27
28
29
30#ifdef SPM_PAGESIZE
31.macro _LPMI reg
32 lpm \reg, Z+
33.endm
34.macro _MOVW dh,dl, sh,sl
35 movw \dl, \sl
36.endm
37#else
38.macro _LPMI reg
39 lpm
40 mov \reg, r0
41 adiw ZL, 1
42.endm
43.macro _MOVW dh,dl, sh,sl
44 mov \dl, \sl
45 mov \dh, \sh
46.endm
47#endif
48
49
50
51;---------------------------------------------------------------------------;
52; Transmit a byte in serial format of N81
53;
54;Prototype: void xmit (uint8_t data);
55;Size: 16 words
56
57.global xmit
58.func xmit
59xmit:
60#if BIDIR
61 ldi r23, BPS-1 ;Pre-idle time for bidirectional data line
625: dec r23 ;
63 brne 5b ;/
64#endif
65 in r0, _SFR_IO_ADDR(SREG) ;Save flags
66
67 com r24 ;C = start bit
68 ldi r25, 10 ;Bit counter
69 cli ;Start critical section
70
711: ldi r23, BPS-1 ;----- Bit transferring loop
722: dec r23 ;Wait for a bit time
73 brne 2b ;/
74 brcs 3f ;MISO = bit to be sent
75 OUT_1 ;
763: brcc 4f ;
77 OUT_0 ;/
784: lsr r24 ;Get next bit into C
79 dec r25 ;All bits sent?
80 brne 1b ; no, coutinue
81
82 out _SFR_IO_ADDR(SREG), r0 ;End of critical section
83 ret
84.endfunc
85
86
87
88;---------------------------------------------------------------------------;
89; Receive a byte
90;
91;Prototype: uint8_t rcvr (void);
92;Size: 19 words
93
94.global rcvr
95.func rcvr
96rcvr:
97 in r0, _SFR_IO_ADDR(SREG) ;Save flags
98
99 ldi r24, 0x80 ;Receiving shift reg
100 cli ;Start critical section
101
1021: SKIP_IN_1 ;Wait for idle
103 rjmp 1b
1042: SKIP_IN_0 ;Wait for start bit
105 rjmp 2b
106 ldi r25, BPS/2 ;Wait for half bit time
1073: dec r25
108 brne 3b
109
1104: ldi r25, BPS ;----- Bit receiving loop
1115: dec r25 ;Wait for a bit time
112 brne 5b ;/
113 lsr r24 ;Next bit
114 SKIP_IN_0 ;Get a data bit into r24.7
115 ori r24, 0x80
116 brcc 4b ;All bits received? no, continue
117
118 out _SFR_IO_ADDR(SREG), r0 ;End of critical section
119 ret
120.endfunc
121
122
123; Not wait for start bit. This should be called after detecting start bit.
124.global recv
125.func recv
126recv:
127 in r0, _SFR_IO_ADDR(SREG) ;Save flags
128
129 ldi r24, 0x80 ;Receiving shift reg
130 cli ;Start critical section
131
132;1: SKIP_IN_1 ;Wait for idle
133; rjmp 1b
134;2: SKIP_IN_0 ;Wait for start bit
135; rjmp 2b
136 ldi r25, BPS/2 ;Wait for half bit time
1373: dec r25
138 brne 3b
139
1404: ldi r25, BPS ;----- Bit receiving loop
1415: dec r25 ;Wait for a bit time
142 brne 5b ;/
143 lsr r24 ;Next bit
144 SKIP_IN_0 ;Get a data bit into r24.7
145 ori r24, 0x80
146 brcc 4b ;All bits received? no, continue
147
148 ldi r25, BPS/2 ;Wait for half bit time
1496: dec r25
150 brne 6b
1517: SKIP_IN_1 ;Wait for stop bit
152 rjmp 7b
153
154 out _SFR_IO_ADDR(SREG), r0 ;End of critical section
155 ret
156.endfunc
diff --git a/keyboard/hhkb_rn42/rn42/suart.h b/keyboard/hhkb_rn42/rn42/suart.h
new file mode 100644
index 000000000..72725b998
--- /dev/null
+++ b/keyboard/hhkb_rn42/rn42/suart.h
@@ -0,0 +1,8 @@
1#ifndef SUART
2#define SUART
3
4void xmit(uint8_t);
5uint8_t rcvr(void);
6uint8_t recv(void);
7
8#endif /* SUART */
diff --git a/keyboard/mbed_onekey/Makefile b/keyboard/mbed_onekey/Makefile
new file mode 100644
index 000000000..b1e5f5e59
--- /dev/null
+++ b/keyboard/mbed_onekey/Makefile
@@ -0,0 +1,33 @@
1PROJECT = mbed_onekey
2
3TMK_DIR = ../..
4MBED_DIR = $(TMK_DIR)/mbed-sdk
5
6#VPATH += $(MBED_DIR):$(TMK_DIR)
7vpath %.s .:$(MBED_DIR):$(TMK_DIR)
8vpath %.c .:$(MBED_DIR):$(TMK_DIR)
9vpath %.cpp .:$(MBED_DIR):$(TMK_DIR)
10
11OBJDIR = ./build
12
13OBJECTS = \
14 $(OBJDIR)/./main.o
15
16CONFIG_H = config.h
17
18SYS_OBJECTS =
19
20INCLUDE_PATHS = -I.
21
22LIBRARY_PATHS =
23LIBRARIES =
24
25# Build Options
26# Comment out to disable
27#BOOTMAGIC_ENABLE = yes
28#MOUSEKEY_ENABLE = yes
29
30
31include $(TMK_DIR)/tool/mbed/mbed.mk
32include $(TMK_DIR)/tool/mbed/common.mk
33include $(TMK_DIR)/tool/mbed/gcc.mk
diff --git a/keyboard/mbed_onekey/config.h b/keyboard/mbed_onekey/config.h
new file mode 100644
index 000000000..a3aadd038
--- /dev/null
+++ b/keyboard/mbed_onekey/config.h
@@ -0,0 +1,7 @@
1#ifndef CONFIG_H
2#define CONFIG_H
3
4#define MATRIX_ROWS 1
5#define MATRIX_COLS 1
6
7#endif
diff --git a/keyboard/mbed_onekey/main.cpp b/keyboard/mbed_onekey/main.cpp
new file mode 100644
index 000000000..71342e7ec
--- /dev/null
+++ b/keyboard/mbed_onekey/main.cpp
@@ -0,0 +1,33 @@
1#include "mbed.h"
2#include "action.h"
3#include "keycode.h"
4#include "host.h"
5#include "mbed_driver.h"
6
7
8// Button and LEDs of LPC11U35 board
9DigitalIn isp(P0_1); // ISP button
10DigitalOut led_red(P0_20);
11DigitalOut led_green(P0_21);
12
13
14int main(void) {
15 isp.mode(PullUp);
16 led_red = 1;
17 led_green = 0;
18
19 host_set_driver(&mbed_driver);
20
21 bool last_isp = isp;
22 while (1) {
23 if (last_isp == isp) continue;
24 last_isp = isp;
25 if (last_isp == 0) {
26 led_red = 0; // on
27 register_code(KC_A);
28 } else {
29 led_red = 1; // off
30 unregister_code(KC_A);
31 }
32 }
33}
diff --git a/protocol.mk b/protocol.mk
index de7014e86..e057d1d60 100644
--- a/protocol.mk
+++ b/protocol.mk
@@ -9,6 +9,7 @@ endif
9 9
10ifdef PS2_USE_BUSYWAIT 10ifdef PS2_USE_BUSYWAIT
11 SRC += protocol/ps2_busywait.c 11 SRC += protocol/ps2_busywait.c
12 SRC += protocol/ps2_io_avr.c
12 OPT_DEFS += -DPS2_USE_BUSYWAIT 13 OPT_DEFS += -DPS2_USE_BUSYWAIT
13endif 14endif
14 15
diff --git a/protocol/lufa/lufa.c b/protocol/lufa/lufa.c
index 16a602df1..6802f3b63 100644
--- a/protocol/lufa/lufa.c
+++ b/protocol/lufa/lufa.c
@@ -148,10 +148,23 @@ static void Console_Task(void)
148*/ 148*/
149void EVENT_USB_Device_Connect(void) 149void EVENT_USB_Device_Connect(void)
150{ 150{
151 /* For battery powered device */
152 if (!USB_IsInitialized) {
153 USB_Init();
154 USB_Device_EnableSOFEvents();
155 }
151} 156}
152 157
153void EVENT_USB_Device_Disconnect(void) 158void EVENT_USB_Device_Disconnect(void)
154{ 159{
160 /* For battery powered device */
161/* TODO: This doesn't work. After several plug in/outs can not be enumerated.
162 if (USB_IsInitialized) {
163 USB_Disable(); // Disable all interrupts
164 USB_Controller_Enable();
165 USB_INT_Enable(USB_INT_VBUSTI);
166 }
167*/
155} 168}
156 169
157void EVENT_USB_Device_Reset(void) 170void EVENT_USB_Device_Reset(void)
@@ -574,7 +587,7 @@ int main(void)
574 print("Keyboard start.\n"); 587 print("Keyboard start.\n");
575 while (1) { 588 while (1) {
576 while (USB_DeviceState == DEVICE_STATE_Suspended) { 589 while (USB_DeviceState == DEVICE_STATE_Suspended) {
577 suspend_power_down(); 590 suspend_power_down(WDTO_120MS);
578 if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) { 591 if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) {
579 USB_Device_SendRemoteWakeup(); 592 USB_Device_SendRemoteWakeup();
580 } 593 }
diff --git a/protocol/mbed/HIDKeyboard.cpp b/protocol/mbed/HIDKeyboard.cpp
new file mode 100644
index 000000000..947077cd2
--- /dev/null
+++ b/protocol/mbed/HIDKeyboard.cpp
@@ -0,0 +1,271 @@
1#include <stdint.h>
2#include "USBHID.h"
3#include "USBHID_Types.h"
4#include "USBDescriptor.h"
5#include "HIDKeyboard.h"
6
7#define DEFAULT_CONFIGURATION (1)
8
9
10HIDKeyboard::HIDKeyboard(uint16_t vendor_id, uint16_t product_id, uint16_t product_release): USBDevice(vendor_id, product_id, product_release)
11{
12 USBDevice::connect();
13}
14
15bool HIDKeyboard::sendReport(report_keyboard_t report) {
16 USBDevice::write(EP1IN, report.raw, sizeof(report), MAX_PACKET_SIZE_EP1);
17 return true;
18}
19
20uint8_t HIDKeyboard::leds() {
21 return led_state;
22}
23
24bool HIDKeyboard::USBCallback_setConfiguration(uint8_t configuration) {
25 if (configuration != DEFAULT_CONFIGURATION) {
26 return false;
27 }
28
29 // Configure endpoints > 0
30 addEndpoint(EPINT_IN, MAX_PACKET_SIZE_EPINT);
31 //addEndpoint(EPINT_OUT, MAX_PACKET_SIZE_EPINT);
32
33 // We activate the endpoint to be able to recceive data
34 //readStart(EPINT_OUT, MAX_PACKET_SIZE_EPINT);
35 return true;
36}
37
38
39uint8_t * HIDKeyboard::stringImanufacturerDesc() {
40 static uint8_t stringImanufacturerDescriptor[] = {
41 0x18, /*bLength*/
42 STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
43 't',0,'m',0,'k',0,'-',0,'k',0,'b',0,'d',0,'.',0,'c',0,'o',0,'m',0 /*bString iManufacturer*/
44 };
45 return stringImanufacturerDescriptor;
46}
47
48uint8_t * HIDKeyboard::stringIproductDesc() {
49 static uint8_t stringIproductDescriptor[] = {
50 0x0a, /*bLength*/
51 STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
52 'm',0,'b',0,'e',0,'d',0 /*bString iProduct*/
53 };
54 return stringIproductDescriptor;
55}
56
57uint8_t * HIDKeyboard::stringIserialDesc() {
58 static uint8_t stringIserialDescriptor[] = {
59 0x04, /*bLength*/
60 STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
61 '0',0 /*bString iSerial*/
62 };
63 return stringIserialDescriptor;
64}
65
66uint8_t * HIDKeyboard::reportDesc() {
67 static uint8_t reportDescriptor[] = {
68 USAGE_PAGE(1), 0x01, // Generic Desktop
69 USAGE(1), 0x06, // Keyboard
70 COLLECTION(1), 0x01, // Application
71
72 USAGE_PAGE(1), 0x07, // Key Codes
73 USAGE_MINIMUM(1), 0xE0,
74 USAGE_MAXIMUM(1), 0xE7,
75 LOGICAL_MINIMUM(1), 0x00,
76 LOGICAL_MAXIMUM(1), 0x01,
77 REPORT_SIZE(1), 0x01,
78 REPORT_COUNT(1), 0x08,
79 INPUT(1), 0x02, // Data, Variable, Absolute
80
81 REPORT_COUNT(1), 0x01,
82 REPORT_SIZE(1), 0x08,
83 INPUT(1), 0x01, // Constant
84
85 REPORT_COUNT(1), 0x05,
86 REPORT_SIZE(1), 0x01,
87 USAGE_PAGE(1), 0x08, // LEDs
88 USAGE_MINIMUM(1), 0x01,
89 USAGE_MAXIMUM(1), 0x05,
90 OUTPUT(1), 0x02, // Data, Variable, Absolute
91
92 REPORT_COUNT(1), 0x01,
93 REPORT_SIZE(1), 0x03,
94 OUTPUT(1), 0x01, // Constant
95
96
97 REPORT_COUNT(1), 0x06,
98 REPORT_SIZE(1), 0x08,
99 LOGICAL_MINIMUM(1), 0x00,
100 LOGICAL_MAXIMUM(1), 0xFF,
101 USAGE_PAGE(1), 0x07, // Key Codes
102 USAGE_MINIMUM(1), 0x00,
103 USAGE_MAXIMUM(1), 0xFF,
104 INPUT(1), 0x00, // Data, Array
105 END_COLLECTION(0),
106 };
107 reportLength = sizeof(reportDescriptor);
108 return reportDescriptor;
109}
110
111uint16_t HIDKeyboard::reportDescLength() {
112 reportDesc();
113 return reportLength;
114}
115
116#define TOTAL_DESCRIPTOR_LENGTH ((1 * CONFIGURATION_DESCRIPTOR_LENGTH) \
117 + (1 * INTERFACE_DESCRIPTOR_LENGTH) \
118 + (1 * HID_DESCRIPTOR_LENGTH) \
119 + (1 * ENDPOINT_DESCRIPTOR_LENGTH))
120uint8_t * HIDKeyboard::configurationDesc() {
121 static uint8_t configurationDescriptor[] = {
122 CONFIGURATION_DESCRIPTOR_LENGTH,// bLength
123 CONFIGURATION_DESCRIPTOR, // bDescriptorType
124 LSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (LSB)
125 MSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (MSB)
126 0x01, // bNumInterfaces
127 DEFAULT_CONFIGURATION, // bConfigurationValue
128 0x00, // iConfiguration
129 C_RESERVED | C_REMOTE_WAKEUP, // bmAttributes
130 C_POWER(100), // bMaxPowerHello World from Mbed
131
132 INTERFACE_DESCRIPTOR_LENGTH, // bLength
133 INTERFACE_DESCRIPTOR, // bDescriptorType
134 0x00, // bInterfaceNumber
135 0x00, // bAlternateSetting
136 0x01, // bNumEndpoints
137 HID_CLASS, // bInterfaceClass
138 1, // bInterfaceSubClass (boot)
139 1, // bInterfaceProtocol (keyboard)
140 0x00, // iInterface
141
142 HID_DESCRIPTOR_LENGTH, // bLength
143 HID_DESCRIPTOR, // bDescriptorType
144 LSB(HID_VERSION_1_11), // bcdHID (LSB)
145 MSB(HID_VERSION_1_11), // bcdHID (MSB)
146 0x00, // bCountryCode
147 0x01, // bNumDescriptors
148 REPORT_DESCRIPTOR, // bDescriptorType
149 (uint8_t)(LSB(reportDescLength())), // wDescriptorLength (LSB)
150 (uint8_t)(MSB(reportDescLength())), // wDescriptorLength (MSB)
151
152 ENDPOINT_DESCRIPTOR_LENGTH, // bLength
153 ENDPOINT_DESCRIPTOR, // bDescriptorType
154 PHY_TO_DESC(EP1IN), // bEndpointAddress
155 E_INTERRUPT, // bmAttributes
156 LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB)
157 MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB)
158 1, // bInterval (milliseconds)
159 };
160 return configurationDescriptor;
161}
162
163#if 0
164uint8_t * HIDKeyboard::deviceDesc() {
165 static uint8_t deviceDescriptor[] = {
166 DEVICE_DESCRIPTOR_LENGTH, /* bLength */
167 DEVICE_DESCRIPTOR, /* bDescriptorType */
168 LSB(USB_VERSION_2_0), /* bcdUSB (LSB) */
169 MSB(USB_VERSION_2_0), /* bcdUSB (MSB) */
170 0x00, /* bDeviceClass */
171 0x00, /* bDeviceSubClass */
172 0x00, /* bDeviceprotocol */
173 MAX_PACKET_SIZE_EP0, /* bMaxPacketSize0 */
174 (uint8_t)(LSB(0xfeed)), /* idVendor (LSB) */
175 (uint8_t)(MSB(0xfeed)), /* idVendor (MSB) */
176 (uint8_t)(LSB(0x1bed)), /* idProduct (LSB) */
177 (uint8_t)(MSB(0x1bed)), /* idProduct (MSB) */
178 (uint8_t)(LSB(0x0002)), /* bcdDevice (LSB) */
179 (uint8_t)(MSB(0x0002)), /* bcdDevice (MSB) */
180 0, /* iManufacturer */
181 0, /* iProduct */
182 0, /* iSerialNumber */
183 0x01 /* bNumConfigurations */
184 };
185 return deviceDescriptor;
186}
187#endif
188
189bool HIDKeyboard::USBCallback_request() {
190 bool success = false;
191 CONTROL_TRANSFER * transfer = getTransferPtr();
192 uint8_t *hidDescriptor;
193
194 // Process additional standard requests
195
196 if ((transfer->setup.bmRequestType.Type == STANDARD_TYPE))
197 {
198 switch (transfer->setup.bRequest)
199 {
200 case GET_DESCRIPTOR:
201 switch (DESCRIPTOR_TYPE(transfer->setup.wValue))
202 {
203 case REPORT_DESCRIPTOR:
204 if ((reportDesc() != NULL) \
205 && (reportDescLength() != 0))
206 {
207 transfer->remaining = reportDescLength();
208 transfer->ptr = reportDesc();
209 transfer->direction = DEVICE_TO_HOST;
210 success = true;
211 }
212 break;
213 case HID_DESCRIPTOR:
214 // Find the HID descriptor, after the configuration descriptor
215 hidDescriptor = findDescriptor(HID_DESCRIPTOR);
216 if (hidDescriptor != NULL)
217 {
218 transfer->remaining = HID_DESCRIPTOR_LENGTH;
219 transfer->ptr = hidDescriptor;
220 transfer->direction = DEVICE_TO_HOST;
221 success = true;
222 }
223 break;
224
225 default:
226 break;
227 }
228 break;
229 default:
230 break;
231 }
232 }
233
234 // Process class-specific requests
235 if (transfer->setup.bmRequestType.Type == CLASS_TYPE)
236 {
237 switch (transfer->setup.bRequest) {
238 case SET_REPORT:
239 // LED indicator
240 // TODO: check Interface and Report length?
241 // if (transfer->setup.wIndex == INTERFACE_KEYBOAD) { }
242 // if (transfer->setup.wLength == 1)
243
244 transfer->remaining = 1;
245 //transfer->ptr = ?? what ptr should be set when OUT(not used?)
246 transfer->direction = HOST_TO_DEVICE;
247 transfer->notify = true; /* notify with USBCallback_requestCompleted */
248 success = true;
249 default:
250 break;
251 }
252 }
253
254 return success;
255}
256
257void HIDKeyboard::USBCallback_requestCompleted(uint8_t * buf, uint32_t length)
258{
259 if (length > 0) {
260 CONTROL_TRANSFER *transfer = getTransferPtr();
261 if (transfer->setup.bmRequestType.Type == CLASS_TYPE) {
262 switch (transfer->setup.bRequest) {
263 case SET_REPORT:
264 led_state = buf[0];
265 break;
266 default:
267 break;
268 }
269 }
270 }
271}
diff --git a/protocol/mbed/HIDKeyboard.h b/protocol/mbed/HIDKeyboard.h
new file mode 100644
index 000000000..c537e5ece
--- /dev/null
+++ b/protocol/mbed/HIDKeyboard.h
@@ -0,0 +1,31 @@
1#ifndef HIDKEYBOARD_H
2
3#include "stdint.h"
4#include "stdbool.h"
5#include "USBHID.h"
6#include "report.h"
7
8
9class HIDKeyboard : public USBDevice {
10public:
11 HIDKeyboard(uint16_t vendor_id = 0xFEED, uint16_t product_id = 0xabed, uint16_t product_release = 0x0001);
12
13 bool sendReport(report_keyboard_t report);
14 uint8_t leds(void);
15protected:
16 uint16_t reportLength;
17 virtual bool USBCallback_setConfiguration(uint8_t configuration);
18 virtual uint8_t * stringImanufacturerDesc();
19 virtual uint8_t * stringIproductDesc();
20 virtual uint8_t * stringIserialDesc();
21 virtual uint16_t reportDescLength();
22 virtual uint8_t * reportDesc();
23 virtual uint8_t * configurationDesc();
24 //virtual uint8_t * deviceDesc();
25 virtual bool USBCallback_request();
26 virtual void USBCallback_requestCompleted(uint8_t * buf, uint32_t length);
27private:
28 uint8_t led_state;
29};
30
31#endif
diff --git a/protocol/mbed/mbed_driver.cpp b/protocol/mbed/mbed_driver.cpp
new file mode 100644
index 000000000..6c7b16e23
--- /dev/null
+++ b/protocol/mbed/mbed_driver.cpp
@@ -0,0 +1,41 @@
1#include "HIDKeyboard.h"
2#include "host.h"
3#include "host_driver.h"
4#include "mbed_driver.h"
5
6HIDKeyboard keyboard;
7
8
9/* Host driver */
10static uint8_t keyboard_leds(void);
11static void send_keyboard(report_keyboard_t *report);
12static void send_mouse(report_mouse_t *report);
13static void send_system(uint16_t data);
14static void send_consumer(uint16_t data);
15
16host_driver_t mbed_driver = {
17 keyboard_leds,
18 send_keyboard,
19 send_mouse,
20 send_system,
21 send_consumer
22};
23
24
25static uint8_t keyboard_leds(void)
26{
27 return keyboard.leds();
28}
29static void send_keyboard(report_keyboard_t *report)
30{
31 keyboard.sendReport(*report);
32}
33static void send_mouse(report_mouse_t *report)
34{
35}
36static void send_system(uint16_t data)
37{
38}
39static void send_consumer(uint16_t data)
40{
41}
diff --git a/protocol/mbed/mbed_driver.h b/protocol/mbed/mbed_driver.h
new file mode 100644
index 000000000..dd1153b43
--- /dev/null
+++ b/protocol/mbed/mbed_driver.h
@@ -0,0 +1,3 @@
1#include "host_driver.h"
2
3extern host_driver_t mbed_driver;
diff --git a/protocol/ps2.h b/protocol/ps2.h
index 483eea720..acde679cf 100644
--- a/protocol/ps2.h
+++ b/protocol/ps2.h
@@ -39,8 +39,9 @@ POSSIBILITY OF SUCH DAMAGE.
39#define PS2_H 39#define PS2_H
40 40
41#include <stdbool.h> 41#include <stdbool.h>
42#include <util/delay.h> 42#include "wait.h"
43#include <avr/io.h> 43#include "ps2_io.h"
44#include "print.h"
44 45
45/* 46/*
46 * Primitive PS/2 Library for AVR 47 * Primitive PS/2 Library for AVR
@@ -92,79 +93,27 @@ uint8_t ps2_host_recv(void);
92void ps2_host_set_led(uint8_t usb_led); 93void ps2_host_set_led(uint8_t usb_led);
93 94
94 95
95/* Check port settings for clock and data line */
96#if !(defined(PS2_CLOCK_PORT) && \
97 defined(PS2_CLOCK_PIN) && \
98 defined(PS2_CLOCK_DDR) && \
99 defined(PS2_CLOCK_BIT))
100# error "PS/2 clock port setting is required in config.h"
101#endif
102
103#if !(defined(PS2_DATA_PORT) && \
104 defined(PS2_DATA_PIN) && \
105 defined(PS2_DATA_DDR) && \
106 defined(PS2_DATA_BIT))
107# error "PS/2 data port setting is required in config.h"
108#endif
109
110/*-------------------------------------------------------------------- 96/*--------------------------------------------------------------------
111 * static functions 97 * static functions
112 *------------------------------------------------------------------*/ 98 *------------------------------------------------------------------*/
113static inline void clock_lo(void)
114{
115 PS2_CLOCK_PORT &= ~(1<<PS2_CLOCK_BIT);
116 PS2_CLOCK_DDR |= (1<<PS2_CLOCK_BIT);
117}
118static inline void clock_hi(void)
119{
120 /* input with pull up */
121 PS2_CLOCK_DDR &= ~(1<<PS2_CLOCK_BIT);
122 PS2_CLOCK_PORT |= (1<<PS2_CLOCK_BIT);
123}
124static inline bool clock_in(void)
125{
126 PS2_CLOCK_DDR &= ~(1<<PS2_CLOCK_BIT);
127 PS2_CLOCK_PORT |= (1<<PS2_CLOCK_BIT);
128 _delay_us(1);
129 return PS2_CLOCK_PIN&(1<<PS2_CLOCK_BIT);
130}
131static inline void data_lo(void)
132{
133 PS2_DATA_PORT &= ~(1<<PS2_DATA_BIT);
134 PS2_DATA_DDR |= (1<<PS2_DATA_BIT);
135}
136static inline void data_hi(void)
137{
138 /* input with pull up */
139 PS2_DATA_DDR &= ~(1<<PS2_DATA_BIT);
140 PS2_DATA_PORT |= (1<<PS2_DATA_BIT);
141}
142static inline bool data_in(void)
143{
144 PS2_DATA_DDR &= ~(1<<PS2_DATA_BIT);
145 PS2_DATA_PORT |= (1<<PS2_DATA_BIT);
146 _delay_us(1);
147 return PS2_DATA_PIN&(1<<PS2_DATA_BIT);
148}
149
150static inline uint16_t wait_clock_lo(uint16_t us) 99static inline uint16_t wait_clock_lo(uint16_t us)
151{ 100{
152 while (clock_in() && us) { asm(""); _delay_us(1); us--; } 101 while (clock_in() && us) { asm(""); wait_us(1); us--; }
153 return us; 102 return us;
154} 103}
155static inline uint16_t wait_clock_hi(uint16_t us) 104static inline uint16_t wait_clock_hi(uint16_t us)
156{ 105{
157 while (!clock_in() && us) { asm(""); _delay_us(1); us--; } 106 while (!clock_in() && us) { asm(""); wait_us(1); us--; }
158 return us; 107 return us;
159} 108}
160static inline uint16_t wait_data_lo(uint16_t us) 109static inline uint16_t wait_data_lo(uint16_t us)
161{ 110{
162 while (data_in() && us) { asm(""); _delay_us(1); us--; } 111 while (data_in() && us) { asm(""); wait_us(1); us--; }
163 return us; 112 return us;
164} 113}
165static inline uint16_t wait_data_hi(uint16_t us) 114static inline uint16_t wait_data_hi(uint16_t us)
166{ 115{
167 while (!data_in() && us) { asm(""); _delay_us(1); us--; } 116 while (!data_in() && us) { asm(""); wait_us(1); us--; }
168 return us; 117 return us;
169} 118}
170 119
diff --git a/protocol/ps2_busywait.c b/protocol/ps2_busywait.c
index 05dd7b27e..a64933219 100644
--- a/protocol/ps2_busywait.c
+++ b/protocol/ps2_busywait.c
@@ -40,8 +40,9 @@ POSSIBILITY OF SUCH DAMAGE.
40 */ 40 */
41 41
42#include <stdbool.h> 42#include <stdbool.h>
43#include <util/delay.h> 43#include "wait.h"
44#include "ps2.h" 44#include "ps2.h"
45#include "ps2_io.h"
45#include "debug.h" 46#include "debug.h"
46 47
47 48
@@ -58,8 +59,11 @@ uint8_t ps2_error = PS2_ERR_NONE;
58 59
59void ps2_host_init(void) 60void ps2_host_init(void)
60{ 61{
62 clock_init();
63 data_init();
64
61 // POR(150-2000ms) plus BAT(300-500ms) may take 2.5sec([3]p.20) 65 // POR(150-2000ms) plus BAT(300-500ms) may take 2.5sec([3]p.20)
62 _delay_ms(2500); 66 wait_ms(2500);
63 67
64 inhibit(); 68 inhibit();
65} 69}
@@ -71,7 +75,7 @@ uint8_t ps2_host_send(uint8_t data)
71 75
72 /* terminate a transmission if we have */ 76 /* terminate a transmission if we have */
73 inhibit(); 77 inhibit();
74 _delay_us(100); // 100us [4]p.13, [5]p.50 78 wait_us(100); // 100us [4]p.13, [5]p.50
75 79
76 /* 'Request to Send' and Start bit */ 80 /* 'Request to Send' and Start bit */
77 data_lo(); 81 data_lo();
@@ -80,7 +84,7 @@ uint8_t ps2_host_send(uint8_t data)
80 84
81 /* Data bit */ 85 /* Data bit */
82 for (uint8_t i = 0; i < 8; i++) { 86 for (uint8_t i = 0; i < 8; i++) {
83 _delay_us(15); 87 wait_us(15);
84 if (data&(1<<i)) { 88 if (data&(1<<i)) {
85 parity = !parity; 89 parity = !parity;
86 data_hi(); 90 data_hi();
@@ -92,13 +96,13 @@ uint8_t ps2_host_send(uint8_t data)
92 } 96 }
93 97
94 /* Parity bit */ 98 /* Parity bit */
95 _delay_us(15); 99 wait_us(15);
96 if (parity) { data_hi(); } else { data_lo(); } 100 if (parity) { data_hi(); } else { data_lo(); }
97 WAIT(clock_hi, 50, 4); 101 WAIT(clock_hi, 50, 4);
98 WAIT(clock_lo, 50, 5); 102 WAIT(clock_lo, 50, 5);
99 103
100 /* Stop bit */ 104 /* Stop bit */
101 _delay_us(15); 105 wait_us(15);
102 data_hi(); 106 data_hi();
103 107
104 /* Ack */ 108 /* Ack */
diff --git a/protocol/ps2_io.h b/protocol/ps2_io.h
new file mode 100644
index 000000000..a46a358e7
--- /dev/null
+++ b/protocol/ps2_io.h
@@ -0,0 +1,15 @@
1#ifndef PS2_IO_H
2#define PS2_IO_H
3
4
5void clock_init(void);
6void clock_lo(void);
7void clock_hi(void);
8bool clock_in(void);
9
10void data_init(void);
11void data_lo(void);
12void data_hi(void);
13bool data_in(void);
14
15#endif
diff --git a/protocol/ps2_io_avr.c b/protocol/ps2_io_avr.c
new file mode 100644
index 000000000..be13d6696
--- /dev/null
+++ b/protocol/ps2_io_avr.c
@@ -0,0 +1,74 @@
1#include <stdbool.h>
2#include <util/delay.h>
3
4/* Check port settings for clock and data line */
5#if !(defined(PS2_CLOCK_PORT) && \
6 defined(PS2_CLOCK_PIN) && \
7 defined(PS2_CLOCK_DDR) && \
8 defined(PS2_CLOCK_BIT))
9# error "PS/2 clock port setting is required in config.h"
10#endif
11
12#if !(defined(PS2_DATA_PORT) && \
13 defined(PS2_DATA_PIN) && \
14 defined(PS2_DATA_DDR) && \
15 defined(PS2_DATA_BIT))
16# error "PS/2 data port setting is required in config.h"
17#endif
18
19
20/*
21 * Clock
22 */
23void clock_init(void)
24{
25}
26
27void clock_lo(void)
28{
29 PS2_CLOCK_PORT &= ~(1<<PS2_CLOCK_BIT);
30 PS2_CLOCK_DDR |= (1<<PS2_CLOCK_BIT);
31}
32
33void clock_hi(void)
34{
35 /* input with pull up */
36 PS2_CLOCK_DDR &= ~(1<<PS2_CLOCK_BIT);
37 PS2_CLOCK_PORT |= (1<<PS2_CLOCK_BIT);
38}
39
40bool clock_in(void)
41{
42 PS2_CLOCK_DDR &= ~(1<<PS2_CLOCK_BIT);
43 PS2_CLOCK_PORT |= (1<<PS2_CLOCK_BIT);
44 _delay_us(1);
45 return PS2_CLOCK_PIN&(1<<PS2_CLOCK_BIT);
46}
47
48/*
49 * Data
50 */
51void data_init(void)
52{
53}
54
55void data_lo(void)
56{
57 PS2_DATA_PORT &= ~(1<<PS2_DATA_BIT);
58 PS2_DATA_DDR |= (1<<PS2_DATA_BIT);
59}
60
61void data_hi(void)
62{
63 /* input with pull up */
64 PS2_DATA_DDR &= ~(1<<PS2_DATA_BIT);
65 PS2_DATA_PORT |= (1<<PS2_DATA_BIT);
66}
67
68bool data_in(void)
69{
70 PS2_DATA_DDR &= ~(1<<PS2_DATA_BIT);
71 PS2_DATA_PORT |= (1<<PS2_DATA_BIT);
72 _delay_us(1);
73 return PS2_DATA_PIN&(1<<PS2_DATA_BIT);
74}
diff --git a/protocol/ps2_io_mbed.c b/protocol/ps2_io_mbed.c
new file mode 100644
index 000000000..83bdcef7f
--- /dev/null
+++ b/protocol/ps2_io_mbed.c
@@ -0,0 +1,60 @@
1#include <stdbool.h>
2#include "ps2_io.h"
3#include "gpio_api.h"
4
5
6static gpio_t clock;
7static gpio_t data;
8
9/*
10 * Clock
11 */
12void clock_init(void)
13{
14 gpio_init(&clock, P0_9);
15 gpio_mode(&clock, OpenDrain|PullNone);
16}
17
18void clock_lo(void)
19{
20 gpio_dir(&clock, PIN_OUTPUT);
21 gpio_write(&clock, 0);
22}
23void clock_hi(void)
24{
25 gpio_dir(&clock, PIN_OUTPUT);
26 gpio_write(&clock, 1);
27}
28
29bool clock_in(void)
30{
31 gpio_dir(&clock, PIN_INPUT);
32 return gpio_read(&clock);
33}
34
35/*
36 * Data
37 */
38void data_init(void)
39{
40 gpio_init(&data, P0_8);
41 gpio_mode(&data, OpenDrain|PullNone);
42}
43
44void data_lo(void)
45{
46 gpio_dir(&data, PIN_OUTPUT);
47 gpio_write(&data, 0);
48}
49
50void data_hi(void)
51{
52 gpio_dir(&data, PIN_OUTPUT);
53 gpio_write(&data, 1);
54}
55
56bool data_in(void)
57{
58 gpio_dir(&data, PIN_INPUT);
59 return gpio_read(&data);
60}
diff --git a/protocol/serial_uart.c b/protocol/serial_uart.c
index 6c0af8817..35df27fd6 100644
--- a/protocol/serial_uart.c
+++ b/protocol/serial_uart.c
@@ -41,13 +41,29 @@ POSSIBILITY OF SUCH DAMAGE.
41#include "serial.h" 41#include "serial.h"
42 42
43 43
44#if defined(SERIAL_UART_RTS_LO) && defined(SERIAL_UART_RTS_HI)
45 // Buffer state
46 // Empty: RBUF_SPACE == RBUF_SIZE(head==tail)
47 // Last 1 space: RBUF_SPACE == 2
48 // Full: RBUF_SPACE == 1(last cell of rbuf be never used.)
49 #define RBUF_SPACE() (rbuf_head < rbuf_tail ? (rbuf_tail - rbuf_head) : (RBUF_SIZE - rbuf_head + rbuf_tail))
50 // allow to send
51 #define rbuf_check_rts_lo() do { if (RBUF_SPACE() > 2) SERIAL_UART_RTS_LO(); } while (0)
52 // prohibit to send
53 #define rbuf_check_rts_hi() do { if (RBUF_SPACE() <= 2) SERIAL_UART_RTS_HI(); } while (0)
54#else
55 #define rbuf_check_rts_lo()
56 #define rbuf_check_rts_hi()
57#endif
58
59
44void serial_init(void) 60void serial_init(void)
45{ 61{
46 SERIAL_UART_INIT(); 62 SERIAL_UART_INIT();
47} 63}
48 64
49// RX ring buffer 65// RX ring buffer
50#define RBUF_SIZE 8 66#define RBUF_SIZE 256
51static uint8_t rbuf[RBUF_SIZE]; 67static uint8_t rbuf[RBUF_SIZE];
52static uint8_t rbuf_head = 0; 68static uint8_t rbuf_head = 0;
53static uint8_t rbuf_tail = 0; 69static uint8_t rbuf_tail = 0;
@@ -61,6 +77,7 @@ uint8_t serial_recv(void)
61 77
62 data = rbuf[rbuf_tail]; 78 data = rbuf[rbuf_tail];
63 rbuf_tail = (rbuf_tail + 1) % RBUF_SIZE; 79 rbuf_tail = (rbuf_tail + 1) % RBUF_SIZE;
80 rbuf_check_rts_lo();
64 return data; 81 return data;
65} 82}
66 83
@@ -73,6 +90,7 @@ int16_t serial_recv2(void)
73 90
74 data = rbuf[rbuf_tail]; 91 data = rbuf[rbuf_tail];
75 rbuf_tail = (rbuf_tail + 1) % RBUF_SIZE; 92 rbuf_tail = (rbuf_tail + 1) % RBUF_SIZE;
93 rbuf_check_rts_lo();
76 return data; 94 return data;
77} 95}
78 96
@@ -90,4 +108,5 @@ ISR(SERIAL_UART_RXD_VECT)
90 rbuf[rbuf_head] = SERIAL_UART_DATA; 108 rbuf[rbuf_head] = SERIAL_UART_DATA;
91 rbuf_head = next; 109 rbuf_head = next;
92 } 110 }
111 rbuf_check_rts_hi();
93} 112}
diff --git a/rules.mk b/rules.mk
index 7a40d1de9..83c9da5f8 100644
--- a/rules.mk
+++ b/rules.mk
@@ -565,6 +565,7 @@ $(OBJDIR)/%.o : %.cpp
565# Assemble: create object files from assembler source files. 565# Assemble: create object files from assembler source files.
566$(OBJDIR)/%.o : %.S 566$(OBJDIR)/%.o : %.S
567 @echo 567 @echo
568 mkdir -p $(@D)
568 @echo $(MSG_ASSEMBLING) $< 569 @echo $(MSG_ASSEMBLING) $<
569 $(CC) -c $(ALL_ASFLAGS) $< -o $@ 570 $(CC) -c $(ALL_ASFLAGS) $< -o $@
570 571
diff --git a/tool/mbed/common.mk b/tool/mbed/common.mk
new file mode 100644
index 000000000..93a927a3e
--- /dev/null
+++ b/tool/mbed/common.mk
@@ -0,0 +1,79 @@
1OBJECTS += \
2 $(OBJDIR)/common/action.o \
3 $(OBJDIR)/common/action_tapping.o \
4 $(OBJDIR)/common/action_macro.o \
5 $(OBJDIR)/common/action_layer.o \
6 $(OBJDIR)/common/action_util.o \
7 $(OBJDIR)/common/host.o \
8 $(OBJDIR)/common/keymap.o \
9 $(OBJDIR)/common/keyboard.o \
10 $(OBJDIR)/common/util.o \
11 $(OBJDIR)/common/mbed/suspend.o \
12 $(OBJDIR)/common/mbed/timer.o \
13 $(OBJDIR)/common/mbed/xprintf.o \
14 $(OBJDIR)/common/mbed/bootloader.o \
15
16INCLUDE_PATHS += \
17 -I$(TMK_DIR)/common \
18 -I$(TMK_DIR)/protocol
19
20CC_FLAGS += -include $(CONFIG_H)
21
22
23
24# Option modules
25ifdef BOOTMAGIC_ENABLE
26 $(error Not Supported)
27 OBJECTS += $(OBJDIR)/common/bootmagic.o
28 OBJECTS += $(OBJDIR)/common/mbed/eeprom.o
29 OPT_DEFS += -DBOOTMAGIC_ENABLE
30endif
31
32ifdef MOUSEKEY_ENABLE
33 OBJECTS += $(OBJDIR)/common/mousekey.o
34 OPT_DEFS += -DMOUSEKEY_ENABLE
35 OPT_DEFS += -DMOUSE_ENABLE
36endif
37
38ifdef EXTRAKEY_ENABLE
39 $(error Not Supported)
40 OPT_DEFS += -DEXTRAKEY_ENABLE
41endif
42
43ifdef CONSOLE_ENABLE
44 $(error Not Supported)
45 OPT_DEFS += -DCONSOLE_ENABLE
46else
47 OPT_DEFS += -DNO_PRINT
48 OPT_DEFS += -DNO_DEBUG
49endif
50
51ifdef COMMAND_ENABLE
52 $(error Not Supported)
53 SRC += common/command.c
54 OPT_DEFS += -DCOMMAND_ENABLE
55endif
56
57ifdef NKRO_ENABLE
58 $(error Not Supported)
59 OPT_DEFS += -DNKRO_ENABLE
60endif
61
62ifdef SLEEP_LED_ENABLE
63 $(error Not Supported)
64 SRC += common/sleep_led.c
65 OPT_DEFS += -DSLEEP_LED_ENABLE
66 OPT_DEFS += -DNO_SUSPEND_POWER_DOWN
67endif
68
69ifdef BACKLIGHT_ENABLE
70 $(error Not Supported)
71 SRC += common/backlight.c
72 OPT_DEFS += -DBACKLIGHT_ENABLE
73endif
74
75ifdef KEYMAP_SECTION_ENABLE
76 $(error Not Supported)
77 OPT_DEFS += -DKEYMAP_SECTION_ENABLE
78 EXTRALDFLAGS = -Wl,-L$(TOP_DIR),-Tldscript_keymap_avr5.x
79endif
diff --git a/tool/mbed/gcc.mk b/tool/mbed/gcc.mk
new file mode 100644
index 000000000..032f7c6ca
--- /dev/null
+++ b/tool/mbed/gcc.mk
@@ -0,0 +1,80 @@
1###############################################################################
2GCC_BIN =
3AS = $(GCC_BIN)arm-none-eabi-as
4CC = $(GCC_BIN)arm-none-eabi-gcc
5CPP = $(GCC_BIN)arm-none-eabi-g++
6LD = $(GCC_BIN)arm-none-eabi-gcc
7OBJCOPY = $(GCC_BIN)arm-none-eabi-objcopy
8OBJDUMP = $(GCC_BIN)arm-none-eabi-objdump
9SIZE = $(GCC_BIN)arm-none-eabi-size
10CHKSUM = $(TMK_DIR)/tool/mbed/lpc-vector-checksum
11
12CPU = -mcpu=cortex-m0 -mthumb
13
14CC_FLAGS += $(CPU) -c -g -fno-common -fmessage-length=0 -Wall -fno-exceptions -ffunction-sections -fdata-sections
15CC_FLAGS += -MMD -MP
16CC_SYMBOLS = -DTARGET_LPC11U35_401 -DTARGET_M0 -DTARGET_NXP -DTARGET_LPC11UXX -DTOOLCHAIN_GCC_ARM -DTOOLCHAIN_GCC -D__CORTEX_M0 -DARM_MATH_CM0 -DMBED_BUILD_TIMESTAMP=1399108688.49 -D__MBED__=1
17
18LD_FLAGS = -mcpu=cortex-m0 -mthumb -Wl,--gc-sections --specs=nano.specs
19LD_FLAGS += -Wl,-Map=$(OBJDIR)/$(PROJECT).map,--cref
20LD_SYS_LIBS = -lstdc++ -lsupc++ -lm -lc -lgcc -lnosys
21
22ifeq ($(DEBUG), 1)
23 CC_FLAGS += -DDEBUG -O0
24else
25 CC_FLAGS += -DNDEBUG -Os
26endif
27
28all: $(OBJDIR)/$(PROJECT).bin $(OBJDIR)/$(PROJECT).hex size
29
30clean:
31 rm -f $(OBJDIR)/$(PROJECT).bin $(OBJDIR)/$(PROJECT).elf $(OBJDIR)/$(PROJECT).hex $(OBJDIR)/$(PROJECT).map $(OBJDIR)/$(PROJECT).lst $(OBJECTS) $(DEPS)
32 rm -fr $(OBJDIR)
33
34$(OBJDIR)/%.o: %.s
35 mkdir -p $(@D)
36 $(AS) $(CPU) -o $@ $<
37
38$(OBJDIR)/%.o: %.c
39 mkdir -p $(@D)
40 $(CC) $(CC_FLAGS) $(CC_SYMBOLS) -std=gnu99 $(INCLUDE_PATHS) -o $@ $<
41
42$(OBJDIR)/%.o: %.cpp
43 mkdir -p $(@D)
44 $(CPP) $(CC_FLAGS) $(CC_SYMBOLS) -std=gnu++98 $(INCLUDE_PATHS) -o $@ $<
45
46
47$(OBJDIR)/$(PROJECT).elf: $(OBJECTS) $(SYS_OBJECTS)
48 $(LD) $(LD_FLAGS) -T$(LINKER_SCRIPT) $(LIBRARY_PATHS) -o $@ $^ $(LIBRARIES) $(LD_SYS_LIBS) $(LIBRARIES) $(LD_SYS_LIBS)
49 @echo ""
50 @echo "*****"
51 @echo "***** You must modify vector checksum value in *.bin and *.hex files."
52 @echo "*****"
53 @echo ""
54
55$(OBJDIR)/$(PROJECT).bin: $(OBJDIR)/$(PROJECT).elf
56 @$(OBJCOPY) -O binary $< $@
57 @echo "Writing vector checksum value into $@ ..."
58 @$(CHKSUM) $@
59 @echo
60
61$(OBJDIR)/$(PROJECT).hex: $(OBJDIR)/$(PROJECT).elf
62 @$(OBJCOPY) -O ihex $< $@
63
64$(OBJDIR)/$(PROJECT).lst: $(OBJDIR)/$(PROJECT).elf
65 @$(OBJDUMP) -Sdh $< > $@
66
67lst: $(OBJDIR)/$(PROJECT).lst
68
69size:
70 $(SIZE) $(OBJDIR)/$(PROJECT).elf
71
72prog: $(OBJDIR)/$(PROJECT).bin
73 @echo "Program..."
74ifneq ($(shell mount | grep 'CRP DISABLD'),)
75 umount /dev/nxpisp >/dev/null 2>&1
76endif
77 dd if=$< of=/dev/nxpisp seek=4
78
79DEPS = $(OBJECTS:.o=.d) $(SYS_OBJECTS:.o=.d)
80-include $(DEPS)
diff --git a/tool/mbed/lpc-vector-checksum.c b/tool/mbed/lpc-vector-checksum.c
new file mode 100644
index 000000000..316a1253a
--- /dev/null
+++ b/tool/mbed/lpc-vector-checksum.c
@@ -0,0 +1,99 @@
1/***************************************************************************
2* https://github.com/dhylands/projects/blob/master/lpc/lpc-vector-checksum/lpc-vector-checksum.c
3*
4* Copyright (c) 2012 by Dave Hylands
5* All Rights Reserved
6*
7* Permission is granted to any individual or institution to use, copy,
8* modify, or redistribute this file so long as it is not sold for profit,
9* and that this copyright notice is retained.
10*
11***************************************************************************
12*
13* This program calculates the vector checksum used in LPC17xx binary
14* images.
15*
16* Usage: lpc-vector-checksum file
17*
18***************************************************************************/
19
20#include <stdio.h>
21#include <stdlib.h>
22#include <stdint.h>
23#include <errno.h>
24#include <string.h>
25
26/***************************************************************************/
27/**
28* update_vector_checksum
29*
30* The algorithim is to write the checksum such that the checksum of the
31* first 8 words is equal to zero.
32*
33* The LPC1768 uses little-endian, and this particular routine assumes
34* that it's running on a little-endian architecture.
35*/
36static int update_vector_checksum( const char *filename )
37{
38 uint32_t sum;
39 uint32_t header[8];
40 FILE *fs;
41 int i;
42
43 if (( fs = fopen( filename, "r+b" )) == NULL )
44 {
45 fprintf( stderr, "Unable to open '%s' for reading/writing (%d): %s\n",
46 filename, errno, strerror( errno ));
47 return 0;
48 }
49
50 if ( fread( header, sizeof( header ), 1, fs ) != 1 )
51 {
52 fprintf( stderr, "Failed to read header from '%s' (perhaps the file is too small?)",
53 filename );
54 fclose( fs );
55 return 0;
56 }
57
58 sum = 0;
59 for ( i = 0; i < 7; i++ )
60 {
61 sum += header[i];
62 }
63 printf( "sum = 0x%08x, value to write = 0x%08x\n", sum, -sum );
64
65 /* write back the checksum to location 7
66 * http://sigalrm.blogspot.jp/2011/10/cortex-m3-exception-vector-checksum.html
67 */
68 fseek(fs, 0x1c, SEEK_SET);
69 sum = -sum;
70 fwrite(&sum, 4, 1, fs);
71
72 fclose( fs );
73
74 return 1;
75}
76
77/***************************************************************************/
78/**
79* main
80*/
81int main( int argc, char **argv )
82{
83 int arg;
84
85 if ( argc < 2)
86 {
87 fprintf( stderr, "Usage: lpc-vector-checksum file ...\n" );
88 exit( 1 );
89 }
90
91 for ( arg = 1; arg < argc; arg++ )
92 {
93 update_vector_checksum( argv[ arg ]);
94 }
95
96 exit( 0 );
97 return 0;
98}
99
diff --git a/tool/mbed/mbed.mk b/tool/mbed/mbed.mk
new file mode 100644
index 000000000..0f12ee2af
--- /dev/null
+++ b/tool/mbed/mbed.mk
@@ -0,0 +1,99 @@
1OBJECTS += \
2 $(OBJDIR)/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC11UXX/TOOLCHAIN_GCC_ARM/startup_LPC11xx.o \
3 $(OBJDIR)/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC11UXX/cmsis_nvic.o \
4 $(OBJDIR)/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC11UXX/system_LPC11Uxx.o \
5 $(OBJDIR)/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/port_api.o \
6 $(OBJDIR)/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/spi_api.o \
7 $(OBJDIR)/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/analogin_api.o \
8 $(OBJDIR)/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/gpio_api.o \
9 $(OBJDIR)/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/gpio_irq_api.o \
10 $(OBJDIR)/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/serial_api.o \
11 $(OBJDIR)/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/i2c_api.o \
12 $(OBJDIR)/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/pwmout_api.o \
13 $(OBJDIR)/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/sleep.o \
14 $(OBJDIR)/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/pinmap.o \
15 $(OBJDIR)/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/us_ticker.o \
16 $(OBJDIR)/libraries/mbed/common/board.o \
17 $(OBJDIR)/libraries/mbed/common/mbed_interface.o \
18 $(OBJDIR)/libraries/mbed/common/exit.o \
19 $(OBJDIR)/libraries/mbed/common/rtc_time.o \
20 $(OBJDIR)/libraries/mbed/common/us_ticker_api.o \
21 $(OBJDIR)/libraries/mbed/common/pinmap_common.o \
22 $(OBJDIR)/libraries/mbed/common/error.o \
23 $(OBJDIR)/libraries/mbed/common/gpio.o \
24 $(OBJDIR)/libraries/mbed/common/semihost_api.o \
25 $(OBJDIR)/libraries/mbed/common/wait_api.o \
26 $(OBJDIR)/libraries/mbed/common/RawSerial.o \
27 $(OBJDIR)/libraries/mbed/common/Ticker.o \
28 $(OBJDIR)/libraries/mbed/common/FilePath.o \
29 $(OBJDIR)/libraries/mbed/common/I2C.o \
30 $(OBJDIR)/libraries/mbed/common/FileBase.o \
31 $(OBJDIR)/libraries/mbed/common/retarget.o \
32 $(OBJDIR)/libraries/mbed/common/Serial.o \
33 $(OBJDIR)/libraries/mbed/common/Stream.o \
34 $(OBJDIR)/libraries/mbed/common/FileSystemLike.o \
35 $(OBJDIR)/libraries/mbed/common/CallChain.o \
36 $(OBJDIR)/libraries/mbed/common/InterruptManager.o \
37 $(OBJDIR)/libraries/mbed/common/SerialBase.o \
38 $(OBJDIR)/libraries/mbed/common/BusInOut.o \
39 $(OBJDIR)/libraries/mbed/common/SPISlave.o \
40 $(OBJDIR)/libraries/mbed/common/I2CSlave.o \
41 $(OBJDIR)/libraries/mbed/common/FunctionPointer.o \
42 $(OBJDIR)/libraries/mbed/common/Timer.o \
43 $(OBJDIR)/libraries/mbed/common/SPI.o \
44 $(OBJDIR)/libraries/mbed/common/Timeout.o \
45 $(OBJDIR)/libraries/mbed/common/Ethernet.o \
46 $(OBJDIR)/libraries/mbed/common/TimerEvent.o \
47 $(OBJDIR)/libraries/mbed/common/CAN.o \
48 $(OBJDIR)/libraries/mbed/common/BusOut.o \
49 $(OBJDIR)/libraries/mbed/common/FileLike.o \
50 $(OBJDIR)/libraries/mbed/common/BusIn.o \
51 $(OBJDIR)/libraries/mbed/common/InterruptIn.o \
52 $(OBJDIR)/libraries/mbed/common/LocalFileSystem.o \
53 $(OBJDIR)/libraries/USBDevice/USBHID/USBMouse.o \
54 $(OBJDIR)/libraries/USBDevice/USBHID/USBHID.o \
55 $(OBJDIR)/libraries/USBDevice/USBHID/USBMouseKeyboard.o \
56 $(OBJDIR)/libraries/USBDevice/USBHID/USBKeyboard.o \
57 $(OBJDIR)/libraries/USBDevice/USBDevice/USBHAL_KL25Z.o \
58 $(OBJDIR)/libraries/USBDevice/USBDevice/USBDevice.o \
59 $(OBJDIR)/libraries/USBDevice/USBDevice/USBHAL_LPC17.o \
60 $(OBJDIR)/libraries/USBDevice/USBDevice/USBHAL_LPC40.o \
61 $(OBJDIR)/libraries/USBDevice/USBDevice/USBHAL_LPC11U.o \
62 $(OBJDIR)/libraries/USBDevice/USBDevice/USBHAL_STM32F4.o \
63 $(OBJDIR)/libraries/USBDevice/USBAudio/USBAudio.o \
64 $(OBJDIR)/libraries/USBDevice/USBSerial/USBSerial.o \
65 $(OBJDIR)/libraries/USBDevice/USBSerial/USBCDC.o \
66 $(OBJDIR)/libraries/USBDevice/USBMSD/USBMSD.o \
67 $(OBJDIR)/libraries/USBDevice/USBMIDI/USBMIDI.o
68
69INCLUDE_PATHS += \
70 -I$(MBED_DIR)/libraries/mbed/targets \
71 -I$(MBED_DIR)/libraries/mbed/targets/hal \
72 -I$(MBED_DIR)/libraries/mbed/targets/hal/TARGET_NXP \
73 -I$(MBED_DIR)/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX \
74 -I$(MBED_DIR)/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/TARGET_LPC11U35_401 \
75 -I$(MBED_DIR)/libraries/mbed/targets/cmsis \
76 -I$(MBED_DIR)/libraries/mbed/targets/cmsis/TARGET_NXP \
77 -I$(MBED_DIR)/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC11UXX \
78 -I$(MBED_DIR)/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC11UXX/TOOLCHAIN_GCC_ARM \
79 -I$(MBED_DIR)/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC11UXX/TOOLCHAIN_GCC_ARM/TARGET_LPC11U35_401 \
80 -I$(MBED_DIR)/libraries/mbed \
81 -I$(MBED_DIR)/libraries/mbed/hal \
82 -I$(MBED_DIR)/libraries/mbed/api \
83 -I$(MBED_DIR)/libraries/mbed/common \
84 -I$(MBED_DIR)/libraries/USBDevice \
85 -I$(MBED_DIR)/libraries/USBDevice/USBHID \
86 -I$(MBED_DIR)/libraries/USBDevice/USBDevice \
87 -I$(MBED_DIR)/libraries/USBDevice/USBAudio \
88 -I$(MBED_DIR)/libraries/USBDevice/USBSerial \
89 -I$(MBED_DIR)/libraries/USBDevice/USBMSD \
90 -I$(MBED_DIR)/libraries/USBDevice/USBMIDI
91
92OBJECTS += \
93 $(OBJDIR)/protocol/mbed/mbed_driver.o \
94 $(OBJDIR)/protocol/mbed/HIDKeyboard.o \
95
96INCLUDE_PATHS += \
97 -I$(TMK_DIR)/protocol/mbed
98
99LINKER_SCRIPT = $(MBED_DIR)/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC11UXX/TOOLCHAIN_GCC_ARM/TARGET_LPC11U35_401/LPC11U35.ld