aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/command.c31
-rw-r--r--common/debug.c1
-rw-r--r--common/debug.h35
-rw-r--r--common/mousekey.c12
-rw-r--r--common/print.c71
-rw-r--r--common/print.h47
6 files changed, 130 insertions, 67 deletions
diff --git a/common/command.c b/common/command.c
index 85cc05733..a06e6a00d 100644
--- a/common/command.c
+++ b/common/command.c
@@ -164,9 +164,6 @@ static bool command_common(uint8_t code)
164 debug_enable = false; 164 debug_enable = false;
165 } else { 165 } else {
166 print("\nDEBUG: enabled.\n"); 166 print("\nDEBUG: enabled.\n");
167 debug_matrix = true;
168 debug_keyboard = true;
169 debug_mouse = true;
170 debug_enable = true; 167 debug_enable = true;
171 } 168 }
172 break; 169 break;
@@ -205,7 +202,7 @@ static bool command_common(uint8_t code)
205 print("VERSION: " STR(DEVICE_VER) "\n"); 202 print("VERSION: " STR(DEVICE_VER) "\n");
206 break; 203 break;
207 case KC_T: // print timer 204 case KC_T: // print timer
208 pv_hex32(timer_count); 205 print_val_hex32(timer_count);
209 break; 206 break;
210 case KC_P: // print toggle 207 case KC_P: // print toggle
211 if (print_enable) { 208 if (print_enable) {
@@ -218,20 +215,20 @@ static bool command_common(uint8_t code)
218 break; 215 break;
219 case KC_S: 216 case KC_S:
220 print("\n\n----- Status -----\n"); 217 print("\n\n----- Status -----\n");
221 pv_hex8(host_keyboard_leds()); 218 print_val_hex8(host_keyboard_leds());
222#ifdef HOST_PJRC 219#ifdef HOST_PJRC
223 pv_hex8(UDCON); 220 print_val_hex8(UDCON);
224 pv_hex8(UDIEN); 221 print_val_hex8(UDIEN);
225 pv_hex8(UDINT); 222 print_val_hex8(UDINT);
226 pv_hex8(usb_keyboard_leds); 223 print_val_hex8(usb_keyboard_leds);
227 pv_hex8(usb_keyboard_protocol); 224 print_val_hex8(usb_keyboard_protocol);
228 pv_hex8(usb_keyboard_idle_config); 225 print_val_hex8(usb_keyboard_idle_config);
229 pv_hex8(usb_keyboard_idle_count); 226 print_val_hex8(usb_keyboard_idle_count);
230#endif 227#endif
231 228
232#ifdef HOST_VUSB 229#ifdef HOST_VUSB
233# if USB_COUNT_SOF 230# if USB_COUNT_SOF
234 pv_hex8(usbSofCount); 231 print_val_hex8(usbSofCount);
235# endif 232# endif
236#endif 233#endif
237 break; 234 break;
@@ -350,7 +347,7 @@ static void mousekey_param_print(void)
350 print("6: mk_wheel_time_to_max: "); pdec(mk_wheel_time_to_max); print("\n"); 347 print("6: mk_wheel_time_to_max: "); pdec(mk_wheel_time_to_max); print("\n");
351} 348}
352 349
353#define PRINT_SET_VAL(v) print(#v " = "); print_dec8(v); print("\n"); 350#define PRINT_SET_VAL(v) print(#v " = "); print_dec(v); print("\n");
354static void mousekey_param_inc(uint8_t param, uint8_t inc) 351static void mousekey_param_inc(uint8_t param, uint8_t inc)
355{ 352{
356 switch (param) { 353 switch (param) {
@@ -552,11 +549,11 @@ static uint8_t numkey2num(uint8_t code)
552 549
553static void switch_layer(uint8_t layer) 550static void switch_layer(uint8_t layer)
554{ 551{
555 pv_hex8(current_layer); 552 print_val_hex8(current_layer);
556 pv_hex8(default_layer); 553 print_val_hex8(default_layer);
557 current_layer = layer; 554 current_layer = layer;
558 default_layer = layer; 555 default_layer = layer;
559 print("switch to "); pv_hex8(layer); 556 print("switch to "); print_val_hex8(layer);
560} 557}
561 558
562static void clear_keyboard(void) 559static void clear_keyboard(void)
diff --git a/common/debug.c b/common/debug.c
index 41d566ee3..e406d39b0 100644
--- a/common/debug.c
+++ b/common/debug.c
@@ -6,4 +6,3 @@ bool debug_enable = false;
6bool debug_matrix = false; 6bool debug_matrix = false;
7bool debug_keyboard = false; 7bool debug_keyboard = false;
8bool debug_mouse = false; 8bool debug_mouse = false;
9
diff --git a/common/debug.h b/common/debug.h
index 1d56e21f7..c12f2cb00 100644
--- a/common/debug.h
+++ b/common/debug.h
@@ -22,13 +22,34 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
22#include "print.h" 22#include "print.h"
23 23
24 24
25#define debug(s) if(debug_enable) print_P(PSTR(s)) 25#define debug(s) do { if (debug_enable) print(s); } while (0)
26#define debug_P(s) if(debug_enable) print_P(s) 26#define debugln(s) do { if (debug_enable) println(s); } while (0)
27#define debug_S(s) if(debug_enable) print_S(s) 27#define debug_S(s) do { if (debug_enable) print_S(s); } while (0)
28#define debug_hex(c) if(debug_enable) phex(c) 28#define debug_P(s) do { if (debug_enable) print_P(s); } while (0)
29#define debug_hex16(i) if(debug_enable) phex16(i) 29#define debug_msg(s) do { \
30#define debug_bin(c) if(debug_enable) pbin(c) 30 if (debug_enable) { \
31#define debug_bin_reverse(c) if(debug_enable) pbin_reverse(c) 31 print(__FILE__); print(" at "); print_dec(__LINE__); print(" in "); print(": "); print(s); \
32 } \
33} while (0)
34
35
36
37#define debug_dec(data) do { if (debug_enable) print_dec(data); } while (0)
38#define debug_decs(data) do { if (debug_enable) print_decs(data); } while (0)
39#define debug_hex8(data) do { if (debug_enable) print_hex8(data); } while (0)
40#define debug_hex16(data) do { if (debug_enable) print_hex16(data); } while (0)
41#define debug_hex32(data) do { if (debug_enable) print_hex32(data); } while (0)
42#define debug_bin8(data) do { if (debug_enable) print_bin8(data); } while (0)
43#define debug_bin16(data) do { if (debug_enable) print_bin16(data); } while (0)
44#define debug_bin32(data) do { if (debug_enable) print_bin32(data); } while (0)
45#define debug_bin_reverse8(data) do { if (debug_enable) print_bin_reverse8(data); } while (0)
46#define debug_bin_reverse16(data) do { if (debug_enable) print_bin_reverse16(data); } while (0)
47#define debug_bin_reverse32(data) do { if (debug_enable) print_bin_reverse32(data); } while (0)
48
49#define debug_dec(data) debug_dec(data)
50#define debug_hex(data) debug_hex8(data)
51#define debug_bin(data) debug_bin8(data)
52#define debug_bin_reverse(data) debug_bin8(data)
32 53
33 54
34#ifdef __cplusplus 55#ifdef __cplusplus
diff --git a/common/mousekey.c b/common/mousekey.c
index d26b26306..3068fc5e3 100644
--- a/common/mousekey.c
+++ b/common/mousekey.c
@@ -187,10 +187,10 @@ static void mousekey_debug(void)
187 if (!debug_mouse) return; 187 if (!debug_mouse) return;
188 print("mousekey [btn|x y v h](rep/acl): ["); 188 print("mousekey [btn|x y v h](rep/acl): [");
189 phex(mouse_report.buttons); print("|"); 189 phex(mouse_report.buttons); print("|");
190 phex(mouse_report.x); print(" "); 190 print_decs(mouse_report.x); print(" ");
191 phex(mouse_report.y); print(" "); 191 print_decs(mouse_report.y); print(" ");
192 phex(mouse_report.v); print(" "); 192 print_decs(mouse_report.v); print(" ");
193 phex(mouse_report.h); print("]("); 193 print_decs(mouse_report.h); print("](");
194 phex(mousekey_repeat); print("/"); 194 print_dec(mousekey_repeat); print("/");
195 phex(mousekey_accel); print(")\n"); 195 print_dec(mousekey_accel); print(")\n");
196} 196}
diff --git a/common/print.c b/common/print.c
index dd73ff59d..6a8a725bc 100644
--- a/common/print.c
+++ b/common/print.c
@@ -22,16 +22,18 @@
22 * THE SOFTWARE. 22 * THE SOFTWARE.
23 */ 23 */
24 24
25#include <stdio.h>
26#include <avr/io.h> 25#include <avr/io.h>
27#include <avr/pgmspace.h> 26#include <avr/pgmspace.h>
28#include "print.h" 27#include "print.h"
28
29
29#define sendchar(c) do { if (print_enable && print_sendchar_func) (print_sendchar_func)(c); } while (0) 30#define sendchar(c) do { if (print_enable && print_sendchar_func) (print_sendchar_func)(c); } while (0)
30 31
31 32
32int8_t (*print_sendchar_func)(uint8_t) = NULL; 33int8_t (*print_sendchar_func)(uint8_t) = 0;
33bool print_enable = false; 34bool print_enable = false;
34 35
36
35/* print string stored in data memory(SRAM) 37/* print string stored in data memory(SRAM)
36 * print_P("hello world"); 38 * print_P("hello world");
37 * This consumes precious SRAM memory space for string. 39 * This consumes precious SRAM memory space for string.
@@ -62,6 +64,55 @@ void print_P(const char *s)
62 } 64 }
63} 65}
64 66
67void print_CRLF(void)
68{
69 sendchar('\r'); sendchar('\n');
70}
71
72
73#define SIGNED 0x80
74#define BIN 2
75#define OCT 8
76#define DEC 10
77#define HEX 16
78
79static inline
80char itoc(uint8_t i)
81{
82 return (i < 10 ? '0' + i : 'A' + i - 10);
83}
84
85static inline
86void print_int(uint16_t data, uint8_t base)
87{
88 char buf[7] = {'\0'};
89 char *p = &buf[6];
90 if ((base & SIGNED) && (data & 0x8000)) {
91 data = -data;
92 buf[0] = '-';
93 }
94 base &= ~SIGNED;
95 uint16_t n;
96 do {
97 n = data;
98 data /= base;
99 *(--p) = itoc(n - data*base);
100 } while (data);
101 if (buf[0]) *(--p) = buf[0];
102 print_S(p);
103}
104
105void print_dec(uint16_t data)
106{
107 print_int(data, DEC);
108}
109
110void print_decs(int16_t data)
111{
112 print_int(data, DEC|SIGNED);
113}
114
115
65static inline 116static inline
66void print_hex4(uint8_t data) 117void print_hex4(uint8_t data)
67{ 118{
@@ -86,22 +137,6 @@ void print_hex32(uint32_t data)
86 print_hex16(data); 137 print_hex16(data);
87} 138}
88 139
89void print_dec8(uint8_t data)
90{
91 if (data/100) sendchar('0' + (data/100));
92 if (data/100 || data%100/10) sendchar('0' + (data%100/10));
93 sendchar('0' + (data%10));
94}
95
96void print_dec16(uint16_t data)
97{
98 // TODO
99}
100
101void print_dec32(uint32_t data)
102{
103 // TODO
104}
105 140
106void print_bin(uint8_t data) 141void print_bin(uint8_t data)
107{ 142{
diff --git a/common/print.h b/common/print.h
index 3a949ba05..9c31b24a2 100644
--- a/common/print.h
+++ b/common/print.h
@@ -34,15 +34,16 @@
34#ifndef __cplusplus 34#ifndef __cplusplus
35// this macro allows you to write print("some text") and 35// this macro allows you to write print("some text") and
36// the string is automatically placed into flash memory :) 36// the string is automatically placed into flash memory :)
37#define print(s) print_P(PSTR(s)) 37#define print(s) print_P(PSTR(s))
38#endif 38#endif
39 39
40#define println(s) print_P(PSTR(s "\n")) 40#define println(s) print_P(PSTR(s "\n"))
41 41
42/* for old name */
43#define pdec(data) print_dec(data)
44#define pdec16(data) print_dec(data)
42#define phex(data) print_hex8(data) 45#define phex(data) print_hex8(data)
43#define phex16(data) print_hex16(data) 46#define phex16(data) print_hex16(data)
44#define pdec(data) print_dec8(data)
45#define pdec16(data) print_dec16(data)
46#define pbin(data) print_bin8(data) 47#define pbin(data) print_bin8(data)
47#define pbin16(data) print_bin16(data) 48#define pbin16(data) print_bin16(data)
48#define pbin_reverse(data) print_bin_reverse8(data) 49#define pbin_reverse(data) print_bin_reverse8(data)
@@ -50,18 +51,19 @@
50 51
51 52
52/* print value utility */ 53/* print value utility */
53#define pv_hex8(v) do { print_P(PSTR(#v ": ")); print_hex8(v); print_P(PSTR("\n")); } while (0) 54#define print_val_dec(v) do { print_P(PSTR(#v ": ")); print_dec(v); print_P(PSTR("\n")); } while (0)
54#define pv_hex16(v) do { print_P(PSTR(#v ": ")); print_hex16(v); print_P(PSTR("\n")); } while (0) 55#define print_val_decs(v) do { print_P(PSTR(#v ": ")); print_decs(v); print_P(PSTR("\n")); } while (0)
55#define pv_hex32(v) do { print_P(PSTR(#v ": ")); print_hex32(v); print_P(PSTR("\n")); } while (0) 56
56#define pv_dec8(v) do { print_P(PSTR(#v ": ")); print_dec8(v); print_P(PSTR("\n")); } while (0) 57#define print_val_hex8(v) do { print_P(PSTR(#v ": ")); print_hex8(v); print_P(PSTR("\n")); } while (0)
57#define pv_dec16(v) do { print_P(PSTR(#v ": ")); print_dec16(v); print_P(PSTR("\n")); } while (0) 58#define print_val_hex16(v) do { print_P(PSTR(#v ": ")); print_hex16(v); print_P(PSTR("\n")); } while (0)
58#define pv_dec32(v) do { print_P(PSTR(#v ": ")); print_dec32(v); print_P(PSTR("\n")); } while (0) 59#define print_val_hex32(v) do { print_P(PSTR(#v ": ")); print_hex32(v); print_P(PSTR("\n")); } while (0)
59#define pv_bin8(v) do { print_P(PSTR(#v ": ")); print_bin8(v); print_P(PSTR("\n")); } while (0) 60
60#define pv_bin16(v) do { print_P(PSTR(#v ": ")); print_bin16(v); print_P(PSTR("\n")); } while (0) 61#define print_val_bin8(v) do { print_P(PSTR(#v ": ")); print_bin8(v); print_P(PSTR("\n")); } while (0)
61#define pv_bin32(v) do { print_P(PSTR(#v ": ")); print_bin32(v); print_P(PSTR("\n")); } while (0) 62#define print_val_bin16(v) do { print_P(PSTR(#v ": ")); print_bin16(v); print_P(PSTR("\n")); } while (0)
62#define pv_bin_reverse8(v) do { print_P(PSTR(#v ": ")); print_bin_reverse8(v); print_P(PSTR("\n")); } while (0) 63#define print_val_bin32(v) do { print_P(PSTR(#v ": ")); print_bin32(v); print_P(PSTR("\n")); } while (0)
63#define pv_bin_reverse16(v) do { print_P(PSTR(#v ": ")); print_bin_reverse16(v); print_P(PSTR("\n")); } while (0) 64#define print_val_bin_reverse8(v) do { print_P(PSTR(#v ": ")); print_bin_reverse8(v); print_P(PSTR("\n")); } while (0)
64#define pv_bin_reverse32(v) do { print_P(PSTR(#v ": ")); print_bin_reverse32(v); print_P(PSTR("\n")); } while (0) 65#define print_val_bin_reverse16(v) do { print_P(PSTR(#v ": ")); print_bin_reverse16(v); print_P(PSTR("\n")); } while (0)
66#define print_val_bin_reverse32(v) do { print_P(PSTR(#v ": ")); print_bin_reverse32(v); print_P(PSTR("\n")); } while (0)
65 67
66 68
67 69
@@ -78,15 +80,24 @@ void print_S(const char *s);
78/* print string stored in program memory(FLASH) */ 80/* print string stored in program memory(FLASH) */
79void print_P(const char *s); 81void print_P(const char *s);
80 82
83void print_CRLF(void);
84
85/* decimal */
86void print_dec(uint16_t data);
87void print_decs(int16_t data);
88
89/* hex */
81void print_hex8(uint8_t data); 90void print_hex8(uint8_t data);
82void print_hex16(uint16_t data); 91void print_hex16(uint16_t data);
83void print_hex32(uint32_t data); 92void print_hex32(uint32_t data);
84void print_dec8(uint8_t data); 93
85void print_dec16(uint16_t data); 94/* binary */
86void print_bin8(uint8_t data); 95void print_bin8(uint8_t data);
87void print_bin16(uint16_t data); 96void print_bin16(uint16_t data);
97void print_bin32(uint32_t data);
88void print_bin_reverse8(uint8_t data); 98void print_bin_reverse8(uint8_t data);
89void print_bin_reverse16(uint16_t data); 99void print_bin_reverse16(uint16_t data);
100void print_bin_reverse32(uint32_t data);
90 101
91#ifdef __cplusplus 102#ifdef __cplusplus
92} 103}