diff options
author | tmk <nobody@nowhere> | 2014-11-24 13:50:33 +0900 |
---|---|---|
committer | tmk <nobody@nowhere> | 2014-11-24 13:50:33 +0900 |
commit | 363950982a291c3bfa03ac6362061b1d37dc06b0 (patch) | |
tree | c46fc53fe00137ced3c8edd3d0766ee844f77516 /common | |
parent | eb90ed6238426db9367e294abfaefb5de07564f5 (diff) | |
parent | 60096e11c77980ca6b54674c5b68248e8aa15d8d (diff) | |
download | qmk_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
Diffstat (limited to 'common')
42 files changed, 610 insertions, 325 deletions
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 | ||
512 | bool is_tap_key(key_t key) | 512 | bool 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 | ||
29 | extern "C" { | ||
30 | #endif | ||
31 | |||
28 | /* tapping count and state */ | 32 | /* tapping count and state */ |
29 | typedef struct { | 33 | typedef 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 */ |
47 | void action_exec(keyevent_t event); | 50 | void action_exec(keyevent_t event); |
48 | 51 | ||
49 | /* action for key */ | 52 | /* action for key */ |
50 | action_t action_for_key(uint8_t layer, key_t key); | 53 | action_t action_for_key(uint8_t layer, keypos_t key); |
51 | 54 | ||
52 | /* macro */ | 55 | /* macro */ |
53 | const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt); | 56 | const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt); |
@@ -65,11 +68,15 @@ void unregister_mods(uint8_t mods); | |||
65 | void clear_keyboard(void); | 68 | void clear_keyboard(void); |
66 | void clear_keyboard_but_mods(void); | 69 | void clear_keyboard_but_mods(void); |
67 | void layer_switch(uint8_t new_layer); | 70 | void layer_switch(uint8_t new_layer); |
68 | bool is_tap_key(key_t key); | 71 | bool is_tap_key(keypos_t key); |
69 | 72 | ||
70 | /* debug */ | 73 | /* debug */ |
71 | void debug_event(keyevent_t event); | 74 | void debug_event(keyevent_t event); |
72 | void debug_record(keyrecord_t record); | 75 | void debug_record(keyrecord_t record); |
73 | void debug_action(action_t action); | 76 | void 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 | ||
115 | action_t layer_switch_get_action(key_t key) | 115 | action_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 */ |
75 | action_t layer_switch_get_action(key_t key); | 75 | action_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. | |||
14 | You should have received a copy of the GNU General Public License | 14 | You should have received a copy of the GNU General Public License |
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | along 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++)) |
32 | void action_macro_play(const macro_t *macro_p) | 32 | void 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 | ||
27 | typedef uint8_t macro_t; | 27 | typedef 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; | |||
31 | static uint8_t weak_mods = 0; | 31 | static 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) |
38 | static int8_t cb_head = 0; | 38 | static int8_t cb_head = 0; |
@@ -98,7 +98,7 @@ void del_key(uint8_t key) | |||
98 | void clear_keys(void) | 98 | void 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) | |||
145 | uint8_t has_anykey(void) | 145 | uint8_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 |
290 | static inline void add_key_bit(uint8_t code) | 290 | static 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 | ||
299 | static inline void del_key_bit(uint8_t code) | 299 | static 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 | ||
24 | extern "C" { | ||
25 | #endif | ||
26 | |||
23 | extern report_keyboard_t *keyboard_report; | 27 | extern report_keyboard_t *keyboard_report; |
24 | 28 | ||
25 | void send_keyboard_report(void); | 29 | void send_keyboard_report(void); |
@@ -54,4 +58,9 @@ void oneshot_disable(void); | |||
54 | uint8_t has_anykey(void); | 58 | uint8_t has_anykey(void); |
55 | uint8_t has_anymod(void); | 59 | uint8_t has_anymod(void); |
56 | uint8_t get_first_key(void); | 60 | uint8_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 | |||
32 | void 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 | */ | ||
55 | void 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 | |||
81 | bool 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 | ||
93 | void 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 */ | ||
104 | ISR(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 | /* | ||
2 | Copyright 2011 Jun Wako <wakojun@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along 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); | |||
63 | static void switch_default_layer(uint8_t layer); | 63 | static void switch_default_layer(uint8_t layer); |
64 | 64 | ||
65 | 65 | ||
66 | typedef enum { ONESHOT, CONSOLE, MOUSEKEY } cmdstate_t; | 66 | command_state_t command_state = ONESHOT; |
67 | static cmdstate_t state = ONESHOT; | ||
68 | 67 | ||
69 | 68 | ||
70 | bool command_proc(uint8_t code) | 69 | bool 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. */ |
93 | bool command_extra(uint8_t code) __attribute__ ((weak)); | 97 | bool command_extra(uint8_t code) __attribute__ ((weak)); |
94 | bool command_extra(uint8_t code) | 98 | bool 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 | ||
103 | bool command_console_extra(uint8_t code) __attribute__ ((weak)); | ||
104 | bool 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 */ | ||
22 | typedef enum { ONESHOT, CONSOLE, MOUSEKEY } command_state_t; | ||
23 | extern command_state_t command_state; | ||
24 | |||
25 | /* This allows to extend commands. Return false when command is not processed. */ | ||
26 | bool command_extra(uint8_t code); | ||
27 | bool command_console_extra(uint8_t code); | ||
28 | |||
21 | #ifdef COMMAND_ENABLE | 29 | #ifdef COMMAND_ENABLE |
22 | bool command_proc(uint8_t code); | 30 | bool command_proc(uint8_t code); |
23 | /* This allows to extend commands. Return 0 when command is not processed. */ | ||
24 | bool 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 | ||
28 | extern "C" { | ||
29 | #endif | ||
30 | |||
31 | typedef 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 | |||
42 | extern debug_config_t debug_config; | ||
43 | debug_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 | |||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | along 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" { | |||
30 | typedef struct { | 30 | typedef 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 */ |
36 | typedef struct { | 36 | typedef 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); | |||
62 | void keyboard_task(void); | 62 | void keyboard_task(void); |
63 | void keyboard_set_leds(uint8_t leds); | 63 | void 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. | |||
14 | You should have received a copy of the GNU General Public License | 14 | You should have received a copy of the GNU General Public License |
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | along 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 */ |
31 | action_t action_for_key(uint8_t layer, key_t key) | 30 | action_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)) |
159 | uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) | 158 | uint8_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 */ |
46 | uint8_t keymap_key_to_keycode(uint8_t layer, key_t key); | 46 | uint8_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 */ |
49 | action_t keymap_fn_to_action(uint8_t keycode); | 49 | action_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); | |||
53 | void matrix_print(void); | 53 | void matrix_print(void); |
54 | 54 | ||
55 | 55 | ||
56 | /* power control */ | ||
57 | void matrix_power_up(void); | ||
58 | void 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 | |||
4 | void 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 | |||
4 | void suspend_power_down(void) {} | ||
5 | bool suspend_wakeup_condition(void) { return true; } | ||
6 | void 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 */ | ||
5 | volatile uint32_t timer_count = 0; | ||
6 | |||
7 | /* Timer interrupt handler */ | ||
8 | void SysTick_Handler(void) { | ||
9 | timer_count++; | ||
10 | } | ||
11 | |||
12 | void timer_init(void) | ||
13 | { | ||
14 | timer_count = 0; | ||
15 | SysTick_Config(SystemCoreClock / 1000); /* 1ms tick */ | ||
16 | } | ||
17 | |||
18 | void timer_clear(void) | ||
19 | { | ||
20 | timer_count = 0; | ||
21 | } | ||
22 | |||
23 | uint16_t timer_read(void) | ||
24 | { | ||
25 | return (uint16_t)(timer_count & 0xFFFF); | ||
26 | } | ||
27 | |||
28 | uint32_t timer_read32(void) | ||
29 | { | ||
30 | return timer_count; | ||
31 | } | ||
32 | |||
33 | uint16_t timer_elapsed(uint16_t last) | ||
34 | { | ||
35 | return TIMER_DIFF_16(timer_read(), last); | ||
36 | } | ||
37 | |||
38 | uint32_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 */ | ||
10 | Serial ser(UART_TX, UART_RX); | ||
11 | |||
12 | /* TODO: Need small implementation for embedded */ | ||
13 | int 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 | ||
7 | extern "C" { | ||
8 | #endif | ||
9 | |||
10 | int 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 | ||
55 | uint8_t mk_delay; | 55 | #ifdef __cplusplus |
56 | uint8_t mk_interval; | 56 | extern "C" { |
57 | uint8_t mk_max_speed; | 57 | #endif |
58 | uint8_t mk_time_to_max; | 58 | |
59 | uint8_t mk_wheel_max_speed; | 59 | extern uint8_t mk_delay; |
60 | uint8_t mk_wheel_time_to_max; | 60 | extern uint8_t mk_interval; |
61 | extern uint8_t mk_max_speed; | ||
62 | extern uint8_t mk_time_to_max; | ||
63 | extern uint8_t mk_wheel_max_speed; | ||
64 | extern uint8_t mk_wheel_time_to_max; | ||
61 | 65 | ||
62 | 66 | ||
63 | void mousekey_task(void); | 67 | void mousekey_task(void); |
@@ -66,4 +70,8 @@ void mousekey_off(uint8_t code); | |||
66 | void mousekey_clear(void); | 70 | void mousekey_clear(void); |
67 | void mousekey_send(void); | 71 | void 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 | ||
40 | void 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 | |||
51 | void print_lf(void) | ||
52 | { | ||
53 | sendchar('\n'); | ||
54 | } | ||
55 | |||
56 | void 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 | |
68 | extern "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 | ||
50 | extern "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 */ |
72 | void print_set_sendchar(int8_t (*print_sendchar_func)(uint8_t)); | 53 | void 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 | */ | ||
78 | void print_S(const char *s); | ||
79 | 56 | ||
80 | void print_lf(void); | 57 | #include "mbed/xprintf.h" |
81 | void 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 | */ |
117 | typedef union { | 117 | typedef 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 | |||
7 | void 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 | |||
42 | bool 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 | ||
52 | void 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 */ | ||
63 | ISR(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) \ | 8 | void suspend_idle(uint8_t timeout); |
12 | __asm__ __volatile__ ( \ | 9 | void 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 | |||
28 | void suspend_power_down(void); | ||
29 | bool suspend_wakeup_condition(void); | 10 | bool suspend_wakeup_condition(void); |
30 | void suspend_wakeup_init(void); | 11 | void 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 | ||
5 | extern "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 | ||