aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/common
diff options
context:
space:
mode:
authorJames Young <18669334+noroadsleft@users.noreply.github.com>2020-05-30 13:14:59 -0700
committerGitHub <noreply@github.com>2020-05-30 13:14:59 -0700
commitfced377ac007d27f2650ccffbe0b18abcdcfe23d (patch)
treebd5b141987394a5a16cfc416bfe2b9efdb14d067 /tmk_core/common
parent7b8a013826ad90714a05ea522de53adf964ab3b9 (diff)
downloadqmk_firmware-fced377ac007d27f2650ccffbe0b18abcdcfe23d.tar.gz
qmk_firmware-fced377ac007d27f2650ccffbe0b18abcdcfe23d.zip
2020 May 30 Breaking Changes Update (#9215)
* Branch point for 2020 May 30 Breaking Change * Migrate `ACTION_LAYER_TOGGLE` to `TG()` (#8954) * Migrate `ACTION_MODS_ONESHOT` to `OSM()` (#8957) * Migrate `ACTION_DEFAULT_LAYER_SET` to `DF()` (#8958) * Migrate `ACTION_LAYER_MODS` to `LM()` (#8959) * Migrate `ACTION_MODS_TAP_KEY` to `MT()` (#8968) * Convert V-USB usbdrv to a submodule (#8321) * Unify Tap Hold functions and documentation (#8348) * Changing board names to prevent confusion (#8412) * Move the Keyboardio Model01 to a keyboardio/ subdir (#8499) * Move spaceman keyboards (#8830) * Migrate miscellaneous `fn_actions` entries (#8977) * Migrate `ACTION_MODS_KEY` to chained mod keycodes (#8979) * Organizing my keyboards (plaid, tartan, ergoinu) (#8537) * Refactor Lily58 to use split_common (#6260) * Refactor zinc to use split_common (#7114) * Add a message if bin/qmk doesn't work (#9000) * Fix conflicting types for 'tfp_printf' (#8269) * Fixed RGB_DISABLE_AFTER_TIMEOUT to be seconds based & small internals cleanup (#6480) * Refactor and updates to TKC1800 code (#8472) * Switch to qmk forks for everything (#9019) * audio refactor: replace deprecated PLAY_NOTE_ARRAY (#8484) * Audio enable corrections (2/3) (#8903) * Split HHKB to ANSI and JP layouts and Add VIA support for each (#8582) * Audio enable corrections (Part 4) (#8974) * Fix typo from PR7114 (#9171) * Augment future branch Changelogs (#8978) * Revert "Branch point for 2020 May 30 Breaking Change"
Diffstat (limited to 'tmk_core/common')
-rw-r--r--tmk_core/common/action.c4
-rw-r--r--tmk_core/common/action_tapping.c6
-rw-r--r--tmk_core/common/action_tapping.h2
-rw-r--r--tmk_core/common/chibios/printf.c233
-rw-r--r--tmk_core/common/chibios/printf.h110
-rw-r--r--tmk_core/common/command.c4
-rw-r--r--tmk_core/common/print.h5
7 files changed, 7 insertions, 357 deletions
diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c
index 3b1268dc9..7a53e08ed 100644
--- a/tmk_core/common/action.c
+++ b/tmk_core/common/action.c
@@ -48,7 +48,7 @@ int retro_tapping_counter = 0;
48#endif 48#endif
49 49
50#ifdef IGNORE_MOD_TAP_INTERRUPT_PER_KEY 50#ifdef IGNORE_MOD_TAP_INTERRUPT_PER_KEY
51__attribute__((weak)) bool get_ignore_mod_tap_interrupt(uint16_t keycode) { return false; } 51__attribute__((weak)) bool get_ignore_mod_tap_interrupt(uint16_t keycode, keyrecord_t *record) { return false; }
52#endif 52#endif
53 53
54#ifndef TAP_CODE_DELAY 54#ifndef TAP_CODE_DELAY
@@ -335,7 +335,7 @@ void process_action(keyrecord_t *record, action_t action) {
335# if !defined(IGNORE_MOD_TAP_INTERRUPT) || defined(IGNORE_MOD_TAP_INTERRUPT_PER_KEY) 335# if !defined(IGNORE_MOD_TAP_INTERRUPT) || defined(IGNORE_MOD_TAP_INTERRUPT_PER_KEY)
336 if ( 336 if (
337# ifdef IGNORE_MOD_TAP_INTERRUPT_PER_KEY 337# ifdef IGNORE_MOD_TAP_INTERRUPT_PER_KEY
338 !get_ignore_mod_tap_interrupt(get_event_keycode(record->event, false)) && 338 !get_ignore_mod_tap_interrupt(get_event_keycode(record->event, false), &record) &&
339# endif 339# endif
340 record->tap.interrupted) { 340 record->tap.interrupted) {
341 dprint("mods_tap: tap: cancel: add_mods\n"); 341 dprint("mods_tap: tap: cancel: add_mods\n");
diff --git a/tmk_core/common/action_tapping.c b/tmk_core/common/action_tapping.c
index 34f08d890..fe545c79a 100644
--- a/tmk_core/common/action_tapping.c
+++ b/tmk_core/common/action_tapping.c
@@ -19,10 +19,10 @@
19# define IS_TAPPING_RELEASED() (IS_TAPPING() && !tapping_key.event.pressed) 19# define IS_TAPPING_RELEASED() (IS_TAPPING() && !tapping_key.event.pressed)
20# define IS_TAPPING_KEY(k) (IS_TAPPING() && KEYEQ(tapping_key.event.key, (k))) 20# define IS_TAPPING_KEY(k) (IS_TAPPING() && KEYEQ(tapping_key.event.key, (k)))
21 21
22__attribute__((weak)) uint16_t get_tapping_term(uint16_t keycode) { return TAPPING_TERM; } 22__attribute__((weak)) uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record) { return TAPPING_TERM; }
23 23
24# ifdef TAPPING_TERM_PER_KEY 24# ifdef TAPPING_TERM_PER_KEY
25# define WITHIN_TAPPING_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < get_tapping_term(get_event_keycode(tapping_key.event, false))) 25# define WITHIN_TAPPING_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < get_tapping_term(get_event_keycode(tapping_key.event, false), &tapping_key))
26# else 26# else
27# define WITHIN_TAPPING_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < TAPPING_TERM) 27# define WITHIN_TAPPING_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < TAPPING_TERM)
28# endif 28# endif
@@ -122,7 +122,7 @@ bool process_tapping(keyrecord_t *keyp) {
122# if defined(TAPPING_TERM_PER_KEY) || (TAPPING_TERM >= 500) || defined(PERMISSIVE_HOLD) || defined(PERMISSIVE_HOLD_PER_KEY) 122# if defined(TAPPING_TERM_PER_KEY) || (TAPPING_TERM >= 500) || defined(PERMISSIVE_HOLD) || defined(PERMISSIVE_HOLD_PER_KEY)
123 else if ( 123 else if (
124# ifdef TAPPING_TERM_PER_KEY 124# ifdef TAPPING_TERM_PER_KEY
125 (get_tapping_term(get_event_keycode(tapping_key.event, false)) >= 500) && 125 (get_tapping_term(get_event_keycode(tapping_key.event, false), keyp) >= 500) &&
126# endif 126# endif
127# ifdef PERMISSIVE_HOLD_PER_KEY 127# ifdef PERMISSIVE_HOLD_PER_KEY
128 !get_permissive_hold(get_event_keycode(tapping_key.event, false), keyp) && 128 !get_permissive_hold(get_event_keycode(tapping_key.event, false), keyp) &&
diff --git a/tmk_core/common/action_tapping.h b/tmk_core/common/action_tapping.h
index 5eaef1c5f..7015ce761 100644
--- a/tmk_core/common/action_tapping.h
+++ b/tmk_core/common/action_tapping.h
@@ -33,7 +33,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
33 33
34#ifndef NO_ACTION_TAPPING 34#ifndef NO_ACTION_TAPPING
35uint16_t get_event_keycode(keyevent_t event, bool update_layer_cache); 35uint16_t get_event_keycode(keyevent_t event, bool update_layer_cache);
36uint16_t get_tapping_term(uint16_t keycode); 36uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record);
37void action_tapping_process(keyrecord_t record); 37void action_tapping_process(keyrecord_t record);
38#endif 38#endif
39 39
diff --git a/tmk_core/common/chibios/printf.c b/tmk_core/common/chibios/printf.c
deleted file mode 100644
index a99752bb3..000000000
--- a/tmk_core/common/chibios/printf.c
+++ /dev/null
@@ -1,233 +0,0 @@
1/*
2 * found at: http://www.sparetimelabs.com/tinyprintf/tinyprintf.php
3 * and: http://www.sparetimelabs.com/printfrevisited/printfrevisited.php
4 */
5
6/*
7File: printf.c
8
9Copyright (C) 2004 Kustaa Nyholm
10
11This library is free software; you can redistribute it and/or
12modify it under the terms of the GNU Lesser General Public
13License as published by the Free Software Foundation; either
14version 2.1 of the License, or (at your option) any later version.
15
16This library is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19Lesser General Public License for more details.
20
21You should have received a copy of the GNU Lesser General Public
22License along with this library; if not, write to the Free Software
23Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
25*/
26
27#include "printf.h"
28
29typedef void (*putcf)(void*, char);
30static putcf stdout_putf;
31static void* stdout_putp;
32
33// this adds cca 400 bytes
34#define PRINTF_LONG_SUPPORT
35
36#ifdef PRINTF_LONG_SUPPORT
37
38static void uli2a(unsigned long int num, unsigned int base, int uc, char* bf) {
39 int n = 0;
40 unsigned int d = 1;
41 while (num / d >= base) d *= base;
42 while (d != 0) {
43 int dgt = num / d;
44 num %= d;
45 d /= base;
46 if (n || dgt > 0 || d == 0) {
47 *bf++ = dgt + (dgt < 10 ? '0' : (uc ? 'A' : 'a') - 10);
48 ++n;
49 }
50 }
51 *bf = 0;
52}
53
54static void li2a(long num, char* bf) {
55 if (num < 0) {
56 num = -num;
57 *bf++ = '-';
58 }
59 uli2a(num, 10, 0, bf);
60}
61
62#endif
63
64static void ui2a(unsigned int num, unsigned int base, int uc, char* bf) {
65 int n = 0;
66 unsigned int d = 1;
67 while (num / d >= base) d *= base;
68 while (d != 0) {
69 int dgt = num / d;
70 num %= d;
71 d /= base;
72 if (n || dgt > 0 || d == 0) {
73 *bf++ = dgt + (dgt < 10 ? '0' : (uc ? 'A' : 'a') - 10);
74 ++n;
75 }
76 }
77 *bf = 0;
78}
79
80static void i2a(int num, char* bf) {
81 if (num < 0) {
82 num = -num;
83 *bf++ = '-';
84 }
85 ui2a(num, 10, 0, bf);
86}
87
88static int a2d(char ch) {
89 if (ch >= '0' && ch <= '9')
90 return ch - '0';
91 else if (ch >= 'a' && ch <= 'f')
92 return ch - 'a' + 10;
93 else if (ch >= 'A' && ch <= 'F')
94 return ch - 'A' + 10;
95 else
96 return -1;
97}
98
99static char a2i(char ch, const char** src, int base, int* nump) {
100 const char* p = *src;
101 int num = 0;
102 int digit;
103 while ((digit = a2d(ch)) >= 0) {
104 if (digit > base) break;
105 num = num * base + digit;
106 ch = *p++;
107 }
108 *src = p;
109 *nump = num;
110 return ch;
111}
112
113static void putchw(void* putp, putcf putf, int n, char z, char* bf) {
114 char fc = z ? '0' : ' ';
115 char ch;
116 char* p = bf;
117 while (*p++ && n > 0) n--;
118 while (n-- > 0) putf(putp, fc);
119 while ((ch = *bf++)) putf(putp, ch);
120}
121
122void tfp_format(void* putp, putcf putf, const char* fmt, va_list va) {
123 // This used to handle max of 12, but binary support jumps this to at least 32
124 char bf[36];
125
126 char ch;
127
128 while ((ch = *(fmt++))) {
129 if (ch != '%')
130 putf(putp, ch);
131 else {
132 char lz = 0;
133#ifdef PRINTF_LONG_SUPPORT
134 char lng = 0;
135#endif
136 int w = 0;
137 ch = *(fmt++);
138 if (ch == '0') {
139 ch = *(fmt++);
140 lz = 1;
141 }
142 if (ch >= '0' && ch <= '9') {
143 ch = a2i(ch, &fmt, 10, &w);
144 }
145#ifdef PRINTF_LONG_SUPPORT
146 if (ch == 'l') {
147 ch = *(fmt++);
148 lng = 1;
149 }
150#endif
151 switch (ch) {
152 case 0:
153 goto abort;
154 case 'u': {
155#ifdef PRINTF_LONG_SUPPORT
156 if (lng)
157 uli2a(va_arg(va, unsigned long int), 10, 0, bf);
158 else
159#endif
160 ui2a(va_arg(va, unsigned int), 10, 0, bf);
161 putchw(putp, putf, w, lz, bf);
162 break;
163 }
164 case 'd': {
165#ifdef PRINTF_LONG_SUPPORT
166 if (lng)
167 li2a(va_arg(va, unsigned long int), bf);
168 else
169#endif
170 i2a(va_arg(va, int), bf);
171 putchw(putp, putf, w, lz, bf);
172 break;
173 }
174 case 'x':
175 case 'X':
176#ifdef PRINTF_LONG_SUPPORT
177 if (lng)
178 uli2a(va_arg(va, unsigned long int), 16, (ch == 'X'), bf);
179 else
180#endif
181 ui2a(va_arg(va, unsigned int), 16, (ch == 'X'), bf);
182 putchw(putp, putf, w, lz, bf);
183 break;
184 case 'c':
185 putf(putp, (char)(va_arg(va, int)));
186 break;
187 case 's':
188 putchw(putp, putf, w, 0, va_arg(va, char*));
189 break;
190 case 'b':
191#ifdef PRINTF_LONG_SUPPORT
192 if (lng)
193 uli2a(va_arg(va, unsigned long int), 2, 0, bf);
194 else
195#endif
196 ui2a(va_arg(va, unsigned int), 2, 0, bf);
197 putchw(putp, putf, w, lz, bf);
198 break;
199 case '%':
200 putf(putp, ch);
201 default:
202 break;
203 }
204 }
205 }
206abort:;
207}
208
209void init_printf(void* putp, void (*putf)(void*, char)) {
210 stdout_putf = putf;
211 stdout_putp = putp;
212}
213
214int tfp_printf(const char* fmt, ...) {
215 va_list va;
216 va_start(va, fmt);
217 tfp_format(stdout_putp, stdout_putf, fmt, va);
218 va_end(va);
219
220 return 1;
221}
222
223static void putcp(void* p, char c) { *(*((char**)p))++ = c; }
224
225int tfp_sprintf(char* s, const char* fmt, ...) {
226 va_list va;
227 va_start(va, fmt);
228 tfp_format(&s, putcp, fmt, va);
229 putcp(&s, 0);
230 va_end(va);
231
232 return 1;
233}
diff --git a/tmk_core/common/chibios/printf.h b/tmk_core/common/chibios/printf.h
deleted file mode 100644
index 775459e1e..000000000
--- a/tmk_core/common/chibios/printf.h
+++ /dev/null
@@ -1,110 +0,0 @@
1/*
2 * found at: http://www.sparetimelabs.com/tinyprintf/tinyprintf.php
3 * and: http://www.sparetimelabs.com/printfrevisited/printfrevisited.php
4 */
5
6/*
7File: printf.h
8
9Copyright (C) 2004 Kustaa Nyholm
10
11This library is free software; you can redistribute it and/or
12modify it under the terms of the GNU Lesser General Public
13License as published by the Free Software Foundation; either
14version 2.1 of the License, or (at your option) any later version.
15
16This library is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19See the GNU Lesser General Public License for more details.
20
21You should have received a copy of the GNU Lesser General Public
22License along with this library; if not, write to the Free Software
23Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
25This library is realy just two files: 'printf.h' and 'printf.c'.
26
27They provide a simple and small (+200 loc) printf functionality to
28be used in embedded systems.
29
30I've found them so usefull in debugging that I do not bother with a
31debugger at all.
32
33They are distributed in source form, so to use them, just compile them
34into your project.
35
36Two printf variants are provided: printf and sprintf.
37
38The formats supported by this implementation are: 'd' 'u' 'c' 's' 'x' 'X'.
39
40Zero padding and field width are also supported.
41
42If the library is compiled with 'PRINTF_SUPPORT_LONG' defined then the
43long specifier is also
44supported. Note that this will pull in some long math routines (pun intended!)
45and thus make your executable noticably longer.
46
47The memory foot print of course depends on the target cpu, compiler and
48compiler options, but a rough guestimate (based on a H8S target) is about
491.4 kB for code and some twenty 'int's and 'char's, say 60 bytes of stack space.
50Not too bad. Your milage may vary. By hacking the source code you can
51get rid of some hunred bytes, I'm sure, but personally I feel the balance of
52functionality and flexibility versus code size is close to optimal for
53many embedded systems.
54
55To use the printf you need to supply your own character output function,
56something like :
57
58 void putc ( void* p, char c)
59 {
60 while (!SERIAL_PORT_EMPTY) ;
61 SERIAL_PORT_TX_REGISTER = c;
62 }
63
64Before you can call printf you need to initialize it to use your
65character output function with something like:
66
67 init_printf(NULL,putc);
68
69Notice the 'NULL' in 'init_printf' and the parameter 'void* p' in 'putc',
70the NULL (or any pointer) you pass into the 'init_printf' will eventually be
71passed to your 'putc' routine. This allows you to pass some storage space (or
72anything realy) to the character output function, if necessary.
73This is not often needed but it was implemented like that because it made
74implementing the sprintf function so neat (look at the source code).
75
76The code is re-entrant, except for the 'init_printf' function, so it
77is safe to call it from interupts too, although this may result in mixed output.
78If you rely on re-entrancy, take care that your 'putc' function is re-entrant!
79
80The printf and sprintf functions are actually macros that translate to
81'tfp_printf' and 'tfp_sprintf'. This makes it possible
82to use them along with 'stdio.h' printf's in a single source file.
83You just need to undef the names before you include the 'stdio.h'.
84Note that these are not function like macros, so if you have variables
85or struct members with these names, things will explode in your face.
86Without variadic macros this is the best we can do to wrap these
87fucnction. If it is a problem just give up the macros and use the
88functions directly or rename them.
89
90For further details see source code.
91
92regs Kusti, 23.10.2004
93*/
94
95#ifndef __TFP_PRINTF__
96#define __TFP_PRINTF__
97
98#include <stdarg.h>
99
100void init_printf(void* putp, void (*putf)(void*, char));
101
102int tfp_printf(const char* fmt, ...);
103int tfp_sprintf(char* s, const char* fmt, ...);
104
105void tfp_format(void* putp, void (*putf)(void*, char), const char* fmt, va_list va);
106
107#define printf tfp_printf
108#define sprintf tfp_sprintf
109
110#endif
diff --git a/tmk_core/common/command.c b/tmk_core/common/command.c
index ee3188646..3cfcba305 100644
--- a/tmk_core/common/command.c
+++ b/tmk_core/common/command.c
@@ -43,10 +43,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
43# include "mousekey.h" 43# include "mousekey.h"
44#endif 44#endif
45 45
46#ifdef PROTOCOL_VUSB
47# include "usbdrv.h"
48#endif
49
50#ifdef AUDIO_ENABLE 46#ifdef AUDIO_ENABLE
51# include "audio.h" 47# include "audio.h"
52#endif /* AUDIO_ENABLE */ 48#endif /* AUDIO_ENABLE */
diff --git a/tmk_core/common/print.h b/tmk_core/common/print.h
index 04ca55810..1c7723621 100644
--- a/tmk_core/common/print.h
+++ b/tmk_core/common/print.h
@@ -72,9 +72,7 @@ extern "C"
72 72
73# elif defined(PROTOCOL_CHIBIOS) /* PROTOCOL_CHIBIOS */ 73# elif defined(PROTOCOL_CHIBIOS) /* PROTOCOL_CHIBIOS */
74 74
75# ifndef TERMINAL_ENABLE 75# include "printf.h" // lib/printf/printf.h
76# include "chibios/printf.h"
77# endif
78 76
79# ifdef USER_PRINT /* USER_PRINT */ 77# ifdef USER_PRINT /* USER_PRINT */
80 78
@@ -89,7 +87,6 @@ extern "C"
89# define uprintf printf 87# define uprintf printf
90 88
91# else /* NORMAL PRINT */ 89# else /* NORMAL PRINT */
92
93// Create user & normal print defines 90// Create user & normal print defines
94# define print(s) printf(s) 91# define print(s) printf(s)
95# define println(s) printf(s "\r\n") 92# define println(s) printf(s "\r\n")