diff options
Diffstat (limited to 'tmk_core/common')
-rw-r--r-- | tmk_core/common/action.c | 7 | ||||
-rw-r--r-- | tmk_core/common/action_util.c | 10 | ||||
-rw-r--r-- | tmk_core/common/avr/bootloader.c | 8 | ||||
-rw-r--r-- | tmk_core/common/avr/xprintf.S | 1000 | ||||
-rw-r--r-- | tmk_core/common/avr/xprintf.h | 222 | ||||
-rw-r--r-- | tmk_core/common/bootmagic.c | 4 | ||||
-rw-r--r-- | tmk_core/common/command.c | 20 | ||||
-rw-r--r-- | tmk_core/common/host.c | 5 | ||||
-rw-r--r-- | tmk_core/common/host.h | 4 | ||||
-rw-r--r-- | tmk_core/common/keyboard.c | 4 | ||||
-rw-r--r-- | tmk_core/common/magic.c | 4 | ||||
-rw-r--r-- | tmk_core/common/mbed/xprintf.cpp | 2 | ||||
-rw-r--r-- | tmk_core/common/mbed/xprintf.h | 2 | ||||
-rw-r--r-- | tmk_core/common/print.h | 168 |
14 files changed, 792 insertions, 668 deletions
diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c index 08ef22eb97..d485b46c77 100644 --- a/tmk_core/common/action.c +++ b/tmk_core/common/action.c @@ -155,9 +155,10 @@ void process_action(keyrecord_t *record, action_t action) action.key.mods<<4; if (event.pressed) { if (mods) { - if (IS_MOD(action.key.code)) { + if (IS_MOD(action.key.code) || action.key.code == KC_NO) { // e.g. LSFT(KC_LGUI): we don't want the LSFT to be weak as it would make it useless. - // this also makes LSFT(KC_LGUI) behave exactly the same as LGUI(KC_LSFT) + // This also makes LSFT(KC_LGUI) behave exactly the same as LGUI(KC_LSFT). + // Same applies for some keys like KC_MEH which are declared as MEH(KC_NO). add_mods(mods); } else { add_weak_mods(mods); @@ -168,7 +169,7 @@ void process_action(keyrecord_t *record, action_t action) } else { unregister_code(action.key.code); if (mods) { - if (IS_MOD(action.key.code)) { + if (IS_MOD(action.key.code) || action.key.code == KC_NO) { del_mods(mods); } else { del_weak_mods(mods); diff --git a/tmk_core/common/action_util.c b/tmk_core/common/action_util.c index 61ff202bef..cb4b252648 100644 --- a/tmk_core/common/action_util.c +++ b/tmk_core/common/action_util.c @@ -20,6 +20,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "action_util.h" #include "action_layer.h" #include "timer.h" +#include "keycode_config.h" + +extern keymap_config_t keymap_config; + static inline void add_key_byte(uint8_t code); static inline void del_key_byte(uint8_t code); @@ -139,7 +143,7 @@ void send_keyboard_report(void) { void add_key(uint8_t key) { #ifdef NKRO_ENABLE - if (keyboard_protocol && keyboard_nkro) { + if (keyboard_protocol && keymap_config.nkro) { add_key_bit(key); return; } @@ -150,7 +154,7 @@ void add_key(uint8_t key) void del_key(uint8_t key) { #ifdef NKRO_ENABLE - if (keyboard_protocol && keyboard_nkro) { + if (keyboard_protocol && keymap_config.nkro) { del_key_bit(key); return; } @@ -231,7 +235,7 @@ uint8_t has_anymod(void) uint8_t get_first_key(void) { #ifdef NKRO_ENABLE - if (keyboard_protocol && keyboard_nkro) { + if (keyboard_protocol && keymap_config.nkro) { uint8_t i = 0; for (; i < KEYBOARD_REPORT_BITS && !keyboard_report->nkro.bits[i]; i++) ; diff --git a/tmk_core/common/avr/bootloader.c b/tmk_core/common/avr/bootloader.c index fb9bf2d1c3..ad547b9853 100644 --- a/tmk_core/common/avr/bootloader.c +++ b/tmk_core/common/avr/bootloader.c @@ -38,7 +38,7 @@ * | | | | * = = = = * | | 32KB-4KB | | 128KB-8KB - * 0x6000 +---------------+ 0x1FC00 +---------------+ + * 0x7000 +---------------+ 0x1E000 +---------------+ * | Bootloader | 4KB | Bootloader | 8KB * 0x7FFF +---------------+ 0x1FFFF +---------------+ * @@ -64,8 +64,8 @@ #define BOOTLOADER_START (FLASH_SIZE - BOOTLOADER_SIZE) -/* - * Entering the Bootloader via Software +/* + * Entering the Bootloader via Software * http://www.fourwalledcubicle.com/files/LUFA/Doc/120730/html/_page__software_bootloader_start.html */ #define BOOTLOADER_RESET_KEY 0xB007B007 @@ -137,7 +137,7 @@ void bootloader_jump_after_watchdog_reset(void) #if 0 /* Jumping To The Bootloader * http://www.pjrc.com/teensy/jump_to_bootloader.html - * + * * This method doen't work when using LUFA. idk why. * - needs to initialize more regisers or interrupt setting? */ diff --git a/tmk_core/common/avr/xprintf.S b/tmk_core/common/avr/xprintf.S index 0cec70ce22..06434b98d9 100644 --- a/tmk_core/common/avr/xprintf.S +++ b/tmk_core/common/avr/xprintf.S @@ -1,500 +1,500 @@ -;---------------------------------------------------------------------------;
-; Extended itoa, puts, printf and atoi (C)ChaN, 2011
-;---------------------------------------------------------------------------;
-
- // Base size is 152 bytes
-#define CR_CRLF 0 // Convert \n to \r\n (+10 bytes)
-#define USE_XPRINTF 1 // Enable xprintf function (+194 bytes)
-#define USE_XSPRINTF 0 // Add xsprintf function (+78 bytes)
-#define USE_XFPRINTF 0 // Add xfprintf function (+54 bytes)
-#define USE_XATOI 0 // Enable xatoi function (+182 bytes)
-
-
-#if FLASHEND > 0x1FFFF
-#error xitoa module does not support 256K devices
-#endif
-
-.nolist
-#include <avr/io.h> // Include device specific definitions.
-.list
-
-#ifdef SPM_PAGESIZE // Recent devices have "lpm Rd,Z+" and "movw".
-.macro _LPMI reg
- lpm \reg, Z+
-.endm
-.macro _MOVW dh,dl, sh,sl
- movw \dl, \sl
-.endm
-#else // Earlier devices do not have "lpm Rd,Z+" nor "movw".
-.macro _LPMI reg
- lpm
- mov \reg, r0
- adiw ZL, 1
-.endm
-.macro _MOVW dh,dl, sh,sl
- mov \dl, \sl
- mov \dh, \sh
-.endm
-#endif
-
-
-
-;---------------------------------------------------------------------------
-; Stub function to forward to user output function
-;
-;Prototype: void xputc (char chr // a character to be output
-; );
-;Size: 12/12 words
-
-.section .bss
-.global xfunc_out ; xfunc_out must be initialized before using this module.
-xfunc_out: .ds.w 1
-.section .text
-
-
-.func xputc
-.global xputc
-xputc:
-#if CR_CRLF
- cpi r24, 10 ;LF --> CRLF
- brne 1f ;
- ldi r24, 13 ;
- rcall 1f ;
- ldi r24, 10 ;/
-1:
-#endif
- push ZH
- push ZL
- lds ZL, xfunc_out+0 ;Pointer to the registered output function.
- lds ZH, xfunc_out+1 ;/
- sbiw ZL, 0 ;Skip if null
- breq 2f ;/
- icall
-2: pop ZL
- pop ZH
- ret
-.endfunc
-
-
-
-;---------------------------------------------------------------------------
-; Direct ROM string output
-;
-;Prototype: void xputs (const char *str_p // rom string to be output
-; );
-
-.func xputs
-.global xputs
-xputs:
- _MOVW ZH,ZL, r25,r24 ; Z = pointer to rom string
-1: _LPMI r24
- cpi r24, 0
- breq 2f
- rcall xputc
- rjmp 1b
-2: ret
-.endfunc
-
-
-;---------------------------------------------------------------------------
-; Extended direct numeral string output (32bit version)
-;
-;Prototype: void xitoa (long value, // value to be output
-; char radix, // radix
-; char width); // minimum width
-;
-
-.func xitoa
-.global xitoa
-xitoa:
- ;r25:r22 = value, r20 = base, r18 = digits
- clr r31 ;r31 = stack level
- ldi r30, ' ' ;r30 = sign
- ldi r19, ' ' ;r19 = filler
- sbrs r20, 7 ;When base indicates signd format and the value
- rjmp 0f ;is minus, add a '-'.
- neg r20 ;
- sbrs r25, 7 ;
- rjmp 0f ;
- ldi r30, '-' ;
- com r22 ;
- com r23 ;
- com r24 ;
- com r25 ;
- adc r22, r1 ;
- adc r23, r1 ;
- adc r24, r1 ;
- adc r25, r1 ;/
-0: sbrs r18, 7 ;When digits indicates zero filled,
- rjmp 1f ;filler is '0'.
- neg r18 ;
- ldi r19, '0' ;/
- ;----- string conversion loop
-1: ldi r21, 32 ;r26 = r25:r22 % r20
- clr r26 ;r25:r22 /= r20
-2: lsl r22 ;
- rol r23 ;
- rol r24 ;
- rol r25 ;
- rol r26 ;
- cp r26, r20 ;
- brcs 3f ;
- sub r26, r20 ;
- inc r22 ;
-3: dec r21 ;
- brne 2b ;/
- cpi r26, 10 ;r26 is a numeral digit '0'-'F'
- brcs 4f ;
- subi r26, -7 ;
-4: subi r26, -'0' ;/
- push r26 ;Stack it
- inc r31 ;/
- cp r22, r1 ;Repeat until r25:r22 gets zero
- cpc r23, r1 ;
- cpc r24, r1 ;
- cpc r25, r1 ;
- brne 1b ;/
-
- cpi r30, '-' ;Minus sign if needed
- brne 5f ;
- push r30 ;
- inc r31 ;/
-5: cp r31, r18 ;Filler
- brcc 6f ;
- push r19 ;
- inc r31 ;
- rjmp 5b ;/
-
-6: pop r24 ;Flush stacked digits and exit
- rcall xputc ;
- dec r31 ;
- brne 6b ;/
-
- ret
-.endfunc
-
-
-
-;---------------------------------------------------------------------------;
-; Formatted string output (16/32bit version)
-;
-;Prototype:
-; void __xprintf (const char *format_p, ...);
-; void __xsprintf(char*, const char *format_p, ...);
-; void __xfprintf(void(*func)(char), const char *format_p, ...);
-;
-
-#if USE_XPRINTF
-
-.func xvprintf
-xvprintf:
- ld ZL, Y+ ;Z = pointer to format string
- ld ZH, Y+ ;/
-
-0: _LPMI r24 ;Get a format char
- cpi r24, 0 ;End of format string?
- breq 90f ;/
- cpi r24, '%' ;Is format?
- breq 20f ;/
-1: rcall xputc ;Put a normal character
- rjmp 0b ;/
-90: ret
-
-20: ldi r18, 0 ;r18: digits
- clt ;T: filler
- _LPMI r21 ;Get flags
- cpi r21, '%' ;Is a %?
- breq 1b ;/
- cpi r21, '0' ;Zero filled?
- brne 23f ;
- set ;/
-22: _LPMI r21 ;Get width
-23: cpi r21, '9'+1 ;
- brcc 24f ;
- subi r21, '0' ;
- brcs 90b ;
- lsl r18 ;
- mov r0, r18 ;
- lsl r18 ;
- lsl r18 ;
- add r18, r0 ;
- add r18, r21 ;
- rjmp 22b ;/
-
-24: brtc 25f ;get value (low word)
- neg r18 ;
-25: ld r24, Y+ ;
- ld r25, Y+ ;/
- cpi r21, 'c' ;Is type character?
- breq 1b ;/
- cpi r21, 's' ;Is type RAM string?
- breq 50f ;/
- cpi r21, 'S' ;Is type ROM string?
- breq 60f ;/
- _MOVW r23,r22,r25,r24 ;r25:r22 = value
- clr r24 ;
- clr r25 ;
- clt ;/
- cpi r21, 'l' ;Is long int?
- brne 26f ;
- ld r24, Y+ ;get value (high word)
- ld r25, Y+ ;
- set ;
- _LPMI r21 ;/
-26: cpi r21, 'd' ;Is type signed decimal?
- brne 27f ;/
- ldi r20, -10 ;
- brts 40f ;
- sbrs r23, 7 ;
- rjmp 40f ;
- ldi r24, -1 ;
- ldi r25, -1 ;
- rjmp 40f ;/
-27: cpi r21, 'u' ;Is type unsigned decimal?
- ldi r20, 10 ;
- breq 40f ;/
- cpi r21, 'X' ;Is type hexdecimal?
- ldi r20, 16 ;
- breq 40f ;/
- cpi r21, 'b' ;Is type binary?
- ldi r20, 2 ;
- breq 40f ;/
- ret ;abort
-40: push ZH ;Output the value
- push ZL ;
- rcall xitoa ;
-42: pop ZL ;
- pop ZH ;
- rjmp 0b ;/
-
-50: push ZH ;Put a string on the RAM
- push ZL
- _MOVW ZH,ZL, r25,r24
-51: ld r24, Z+
- cpi r24, 0
- breq 42b
- rcall xputc
- rjmp 51b
-
-60: push ZH ;Put a string on the ROM
- push ZL
- rcall xputs
- rjmp 42b
-.endfunc
-
-
-.func __xprintf
-.global __xprintf
-__xprintf:
- push YH
- push YL
- in YL, _SFR_IO_ADDR(SPL)
-#ifdef SPH
- in YH, _SFR_IO_ADDR(SPH)
-#else
- clr YH
-#endif
- adiw YL, 5 ;Y = pointer to arguments
- rcall xvprintf
- pop YL
- pop YH
- ret
-.endfunc
-
-
-#if USE_XSPRINTF
-
-.func __xsprintf
-putram:
- _MOVW ZH,ZL, r15,r14
- st Z+, r24
- _MOVW r15,r14, ZH,ZL
- ret
-.global __xsprintf
-__xsprintf:
- push YH
- push YL
- in YL, _SFR_IO_ADDR(SPL)
-#ifdef SPH
- in YH, _SFR_IO_ADDR(SPH)
-#else
- clr YH
-#endif
- adiw YL, 5 ;Y = pointer to arguments
- lds ZL, xfunc_out+0 ;Save registered output function
- lds ZH, xfunc_out+1 ;
- push ZL ;
- push ZH ;/
- ldi ZL, lo8(pm(putram));Set local output function
- ldi ZH, hi8(pm(putram));
- sts xfunc_out+0, ZL ;
- sts xfunc_out+1, ZH ;/
- push r15 ;Initialize pointer to string buffer
- push r14 ;
- ld r14, Y+ ;
- ld r15, Y+ ;/
- rcall xvprintf
- _MOVW ZH,ZL, r15,r14 ;Terminate string
- st Z, r1 ;
- pop r14 ;
- pop r15 ;/
- pop ZH ;Restore registered output function
- pop ZL ;
- sts xfunc_out+0, ZL ;
- sts xfunc_out+1, ZH ;/
- pop YL
- pop YH
- ret
-.endfunc
-#endif
-
-
-#if USE_XFPRINTF
-.func __xfprintf
-.global __xfprintf
-__xfprintf:
- push YH
- push YL
- in YL, _SFR_IO_ADDR(SPL)
-#ifdef SPH
- in YH, _SFR_IO_ADDR(SPH)
-#else
- clr YH
-#endif
- adiw YL, 5 ;Y = pointer to arguments
- lds ZL, xfunc_out+0 ;Save registered output function
- lds ZH, xfunc_out+1 ;
- push ZL ;
- push ZH ;/
- ld ZL, Y+ ;Set output function
- ld ZH, Y+ ;
- sts xfunc_out+0, ZL ;
- sts xfunc_out+1, ZH ;/
- rcall xvprintf
- pop ZH ;Restore registered output function
- pop ZL ;
- sts xfunc_out+0, ZL ;
- sts xfunc_out+1, ZH ;/
- pop YL
- pop YH
- ret
-.endfunc
-#endif
-
-#endif
-
-
-
-;---------------------------------------------------------------------------
-; Extended numeral string input
-;
-;Prototype:
-; char xatoi ( /* 1: Successful, 0: Failed */
-; const char **str, /* pointer to pointer to source string */
-; long *res /* result */
-; );
-;
-
-
-#if USE_XATOI
-.func xatoi
-.global xatoi
-xatoi:
- _MOVW r1, r0, r23, r22
- _MOVW XH, XL, r25, r24
- ld ZL, X+
- ld ZH, X+
- clr r18 ;r21:r18 = 0;
- clr r19 ;
- clr r20 ;
- clr r21 ;/
- clt ;T = 0;
-
- ldi r25, 10 ;r25 = 10;
- rjmp 41f ;/
-40: adiw ZL, 1 ;Z++;
-41: ld r22, Z ;r22 = *Z;
- cpi r22, ' ' ;if(r22 == ' ') continue
- breq 40b ;/
- brcs 70f ;if(r22 < ' ') error;
- cpi r22, '-' ;if(r22 == '-') {
- brne 42f ; T = 1;
- set ; continue;
- rjmp 40b ;}
-42: cpi r22, '9'+1 ;if(r22 > '9') error;
- brcc 70f ;/
- cpi r22, '0' ;if(r22 < '0') error;
- brcs 70f ;/
- brne 51f ;if(r22 > '0') cv_start;
- ldi r25, 8 ;r25 = 8;
- adiw ZL, 1 ;r22 = *(++Z);
- ld r22, Z ;/
- cpi r22, ' '+1 ;if(r22 <= ' ') exit;
- brcs 80f ;/
- cpi r22, 'b' ;if(r22 == 'b') {
- brne 43f ; r25 = 2;
- ldi r25, 2 ; cv_start;
- rjmp 50f ;}
-43: cpi r22, 'x' ;if(r22 != 'x') error;
- brne 51f ;/
- ldi r25, 16 ;r25 = 16;
-
-50: adiw ZL, 1 ;Z++;
- ld r22, Z ;r22 = *Z;
-51: cpi r22, ' '+1 ;if(r22 <= ' ') break;
- brcs 80f ;/
- cpi r22, 'a' ;if(r22 >= 'a') r22 =- 0x20;
- brcs 52f ;
- subi r22, 0x20 ;/
-52: subi r22, '0' ;if((r22 -= '0') < 0) error;
- brcs 70f ;/
- cpi r22, 10 ;if(r22 >= 10) {
- brcs 53f ; r22 -= 7;
- subi r22, 7 ; if(r22 < 10)
- cpi r22, 10 ;
- brcs 70f ;}
-53: cp r22, r25 ;if(r22 >= r25) error;
- brcc 70f ;/
-60: ldi r24, 33 ;r21:r18 *= r25;
- sub r23, r23 ;
-61: brcc 62f ;
- add r23, r25 ;
-62: lsr r23 ;
- ror r21 ;
- ror r20 ;
- ror r19 ;
- ror r18 ;
- dec r24 ;
- brne 61b ;/
- add r18, r22 ;r21:r18 += r22;
- adc r19, r24 ;
- adc r20, r24 ;
- adc r21, r24 ;/
- rjmp 50b ;repeat
-
-70: ldi r24, 0
- rjmp 81f
-80: ldi r24, 1
-81: brtc 82f
- clr r22
- com r18
- com r19
- com r20
- com r21
- adc r18, r22
- adc r19, r22
- adc r20, r22
- adc r21, r22
-82: st -X, ZH
- st -X, ZL
- _MOVW XH, XL, r1, r0
- st X+, r18
- st X+, r19
- st X+, r20
- st X+, r21
- clr r1
- ret
-.endfunc
-#endif
-
-
+;---------------------------------------------------------------------------; +; Extended itoa, puts, printf and atoi (C)ChaN, 2011 +;---------------------------------------------------------------------------; + + // Base size is 152 bytes +#define CR_CRLF 0 // Convert \n to \r\n (+10 bytes) +#define USE_XPRINTF 1 // Enable xprintf function (+194 bytes) +#define USE_XSPRINTF 0 // Add xsprintf function (+78 bytes) +#define USE_XFPRINTF 0 // Add xfprintf function (+54 bytes) +#define USE_XATOI 0 // Enable xatoi function (+182 bytes) + + +#if FLASHEND > 0x1FFFF +#error xitoa module does not support 256K devices +#endif + +.nolist +#include <avr/io.h> // Include device specific definitions. +.list + +#ifdef SPM_PAGESIZE // Recent devices have "lpm Rd,Z+" and "movw". +.macro _LPMI reg + lpm \reg, Z+ +.endm +.macro _MOVW dh,dl, sh,sl + movw \dl, \sl +.endm +#else // Earlier devices do not have "lpm Rd,Z+" nor "movw". +.macro _LPMI reg + lpm + mov \reg, r0 + adiw ZL, 1 +.endm +.macro _MOVW dh,dl, sh,sl + mov \dl, \sl + mov \dh, \sh +.endm +#endif + + + +;--------------------------------------------------------------------------- +; Stub function to forward to user output function +; +;Prototype: void xputc (char chr // a character to be output +; ); +;Size: 12/12 words + +.section .bss +.global xfunc_out ; xfunc_out must be initialized before using this module. +xfunc_out: .ds.w 1 +.section .text + + +.func xputc +.global xputc +xputc: +#if CR_CRLF + cpi r24, 10 ;LF --> CRLF + brne 1f ; + ldi r24, 13 ; + rcall 1f ; + ldi r24, 10 ;/ +1: +#endif + push ZH + push ZL + lds ZL, xfunc_out+0 ;Pointer to the registered output function. + lds ZH, xfunc_out+1 ;/ + sbiw ZL, 0 ;Skip if null + breq 2f ;/ + icall +2: pop ZL + pop ZH + ret +.endfunc + + + +;--------------------------------------------------------------------------- +; Direct ROM string output +; +;Prototype: void xputs (const char *str_p // rom string to be output +; ); + +.func xputs +.global xputs +xputs: + _MOVW ZH,ZL, r25,r24 ; Z = pointer to rom string +1: _LPMI r24 + cpi r24, 0 + breq 2f + rcall xputc + rjmp 1b +2: ret +.endfunc + + +;--------------------------------------------------------------------------- +; Extended direct numeral string output (32bit version) +; +;Prototype: void xitoa (long value, // value to be output +; char radix, // radix +; char width); // minimum width +; + +.func xitoa +.global xitoa +xitoa: + ;r25:r22 = value, r20 = base, r18 = digits + clr r31 ;r31 = stack level + ldi r30, ' ' ;r30 = sign + ldi r19, ' ' ;r19 = filler + sbrs r20, 7 ;When base indicates signd format and the value + rjmp 0f ;is minus, add a '-'. + neg r20 ; + sbrs r25, 7 ; + rjmp 0f ; + ldi r30, '-' ; + com r22 ; + com r23 ; + com r24 ; + com r25 ; + adc r22, r1 ; + adc r23, r1 ; + adc r24, r1 ; + adc r25, r1 ;/ +0: sbrs r18, 7 ;When digits indicates zero filled, + rjmp 1f ;filler is '0'. + neg r18 ; + ldi r19, '0' ;/ + ;----- string conversion loop +1: ldi r21, 32 ;r26 = r25:r22 % r20 + clr r26 ;r25:r22 /= r20 +2: lsl r22 ; + rol r23 ; + rol r24 ; + rol r25 ; + rol r26 ; + cp r26, r20 ; + brcs 3f ; + sub r26, r20 ; + inc r22 ; +3: dec r21 ; + brne 2b ;/ + cpi r26, 10 ;r26 is a numeral digit '0'-'F' + brcs 4f ; + subi r26, -7 ; +4: subi r26, -'0' ;/ + push r26 ;Stack it + inc r31 ;/ + cp r22, r1 ;Repeat until r25:r22 gets zero + cpc r23, r1 ; + cpc r24, r1 ; + cpc r25, r1 ; + brne 1b ;/ + + cpi r30, '-' ;Minus sign if needed + brne 5f ; + push r30 ; + inc r31 ;/ +5: cp r31, r18 ;Filler + brcc 6f ; + push r19 ; + inc r31 ; + rjmp 5b ;/ + +6: pop r24 ;Flush stacked digits and exit + rcall xputc ; + dec r31 ; + brne 6b ;/ + + ret +.endfunc + + + +;---------------------------------------------------------------------------; +; Formatted string output (16/32bit version) +; +;Prototype: +; void __xprintf (const char *format_p, ...); +; void __xsprintf(char*, const char *format_p, ...); +; void __xfprintf(void(*func)(char), const char *format_p, ...); +; + +#if USE_XPRINTF + +.func xvprintf +xvprintf: + ld ZL, Y+ ;Z = pointer to format string + ld ZH, Y+ ;/ + +0: _LPMI r24 ;Get a format char + cpi r24, 0 ;End of format string? + breq 90f ;/ + cpi r24, '%' ;Is format? + breq 20f ;/ +1: rcall xputc ;Put a normal character + rjmp 0b ;/ +90: ret + +20: ldi r18, 0 ;r18: digits + clt ;T: filler + _LPMI r21 ;Get flags + cpi r21, '%' ;Is a %? + breq 1b ;/ + cpi r21, '0' ;Zero filled? + brne 23f ; + set ;/ +22: _LPMI r21 ;Get width +23: cpi r21, '9'+1 ; + brcc 24f ; + subi r21, '0' ; + brcs 90b ; + lsl r18 ; + mov r0, r18 ; + lsl r18 ; + lsl r18 ; + add r18, r0 ; + add r18, r21 ; + rjmp 22b ;/ + +24: brtc 25f ;get value (low word) + neg r18 ; +25: ld r24, Y+ ; + ld r25, Y+ ;/ + cpi r21, 'c' ;Is type character? + breq 1b ;/ + cpi r21, 's' ;Is type RAM string? + breq 50f ;/ + cpi r21, 'S' ;Is type ROM string? + breq 60f ;/ + _MOVW r23,r22,r25,r24 ;r25:r22 = value + clr r24 ; + clr r25 ; + clt ;/ + cpi r21, 'l' ;Is long int? + brne 26f ; + ld r24, Y+ ;get value (high word) + ld r25, Y+ ; + set ; + _LPMI r21 ;/ +26: cpi r21, 'd' ;Is type signed decimal? + brne 27f ;/ + ldi r20, -10 ; + brts 40f ; + sbrs r23, 7 ; + rjmp 40f ; + ldi r24, -1 ; + ldi r25, -1 ; + rjmp 40f ;/ +27: cpi r21, 'u' ;Is type unsigned decimal? + ldi r20, 10 ; + breq 40f ;/ + cpi r21, 'X' ;Is type hexdecimal? + ldi r20, 16 ; + breq 40f ;/ + cpi r21, 'b' ;Is type binary? + ldi r20, 2 ; + breq 40f ;/ + ret ;abort +40: push ZH ;Output the value + push ZL ; + rcall xitoa ; +42: pop ZL ; + pop ZH ; + rjmp 0b ;/ + +50: push ZH ;Put a string on the RAM + push ZL + _MOVW ZH,ZL, r25,r24 +51: ld r24, Z+ + cpi r24, 0 + breq 42b + rcall xputc + rjmp 51b + +60: push ZH ;Put a string on the ROM + push ZL + rcall xputs + rjmp 42b +.endfunc + + +.func __xprintf +.global __xprintf +__xprintf: + push YH + push YL + in YL, _SFR_IO_ADDR(SPL) +#ifdef SPH + in YH, _SFR_IO_ADDR(SPH) +#else + clr YH +#endif + adiw YL, 5 ;Y = pointer to arguments + rcall xvprintf + pop YL + pop YH + ret +.endfunc + + +#if USE_XSPRINTF + +.func __xsprintf +putram: + _MOVW ZH,ZL, r15,r14 + st Z+, r24 + _MOVW r15,r14, ZH,ZL + ret +.global __xsprintf +__xsprintf: + push YH + push YL + in YL, _SFR_IO_ADDR(SPL) +#ifdef SPH + in YH, _SFR_IO_ADDR(SPH) +#else + clr YH +#endif + adiw YL, 5 ;Y = pointer to arguments + lds ZL, xfunc_out+0 ;Save registered output function + lds ZH, xfunc_out+1 ; + push ZL ; + push ZH ;/ + ldi ZL, lo8(pm(putram));Set local output function + ldi ZH, hi8(pm(putram)); + sts xfunc_out+0, ZL ; + sts xfunc_out+1, ZH ;/ + push r15 ;Initialize pointer to string buffer + push r14 ; + ld r14, Y+ ; + ld r15, Y+ ;/ + rcall xvprintf + _MOVW ZH,ZL, r15,r14 ;Terminate string + st Z, r1 ; + pop r14 ; + pop r15 ;/ + pop ZH ;Restore registered output function + pop ZL ; + sts xfunc_out+0, ZL ; + sts xfunc_out+1, ZH ;/ + pop YL + pop YH + ret +.endfunc +#endif + + +#if USE_XFPRINTF +.func __xfprintf +.global __xfprintf +__xfprintf: + push YH + push YL + in YL, _SFR_IO_ADDR(SPL) +#ifdef SPH + in YH, _SFR_IO_ADDR(SPH) +#else + clr YH +#endif + adiw YL, 5 ;Y = pointer to arguments + lds ZL, xfunc_out+0 ;Save registered output function + lds ZH, xfunc_out+1 ; + push ZL ; + push ZH ;/ + ld ZL, Y+ ;Set output function + ld ZH, Y+ ; + sts xfunc_out+0, ZL ; + sts xfunc_out+1, ZH ;/ + rcall xvprintf + pop ZH ;Restore registered output function + pop ZL ; + sts xfunc_out+0, ZL ; + sts xfunc_out+1, ZH ;/ + pop YL + pop YH + ret +.endfunc +#endif + +#endif + + + +;--------------------------------------------------------------------------- +; Extended numeral string input +; +;Prototype: +; char xatoi ( /* 1: Successful, 0: Failed */ +; const char **str, /* pointer to pointer to source string */ +; long *res /* result */ +; ); +; + + +#if USE_XATOI +.func xatoi +.global xatoi +xatoi: + _MOVW r1, r0, r23, r22 + _MOVW XH, XL, r25, r24 + ld ZL, X+ + ld ZH, X+ + clr r18 ;r21:r18 = 0; + clr r19 ; + clr r20 ; + clr r21 ;/ + clt ;T = 0; + + ldi r25, 10 ;r25 = 10; + rjmp 41f ;/ +40: adiw ZL, 1 ;Z++; +41: ld r22, Z ;r22 = *Z; + cpi r22, ' ' ;if(r22 == ' ') continue + breq 40b ;/ + brcs 70f ;if(r22 < ' ') error; + cpi r22, '-' ;if(r22 == '-') { + brne 42f ; T = 1; + set ; continue; + rjmp 40b ;} +42: cpi r22, '9'+1 ;if(r22 > '9') error; + brcc 70f ;/ + cpi r22, '0' ;if(r22 < '0') error; + brcs 70f ;/ + brne 51f ;if(r22 > '0') cv_start; + ldi r25, 8 ;r25 = 8; + adiw ZL, 1 ;r22 = *(++Z); + ld r22, Z ;/ + cpi r22, ' '+1 ;if(r22 <= ' ') exit; + brcs 80f ;/ + cpi r22, 'b' ;if(r22 == 'b') { + brne 43f ; r25 = 2; + ldi r25, 2 ; cv_start; + rjmp 50f ;} +43: cpi r22, 'x' ;if(r22 != 'x') error; + brne 51f ;/ + ldi r25, 16 ;r25 = 16; + +50: adiw ZL, 1 ;Z++; + ld r22, Z ;r22 = *Z; +51: cpi r22, ' '+1 ;if(r22 <= ' ') break; + brcs 80f ;/ + cpi r22, 'a' ;if(r22 >= 'a') r22 =- 0x20; + brcs 52f ; + subi r22, 0x20 ;/ +52: subi r22, '0' ;if((r22 -= '0') < 0) error; + brcs 70f ;/ + cpi r22, 10 ;if(r22 >= 10) { + brcs 53f ; r22 -= 7; + subi r22, 7 ; if(r22 < 10) + cpi r22, 10 ; + brcs 70f ;} +53: cp r22, r25 ;if(r22 >= r25) error; + brcc 70f ;/ +60: ldi r24, 33 ;r21:r18 *= r25; + sub r23, r23 ; +61: brcc 62f ; + add r23, r25 ; +62: lsr r23 ; + ror r21 ; + ror r20 ; + ror r19 ; + ror r18 ; + dec r24 ; + brne 61b ;/ + add r18, r22 ;r21:r18 += r22; + adc r19, r24 ; + adc r20, r24 ; + adc r21, r24 ;/ + rjmp 50b ;repeat + +70: ldi r24, 0 + rjmp 81f +80: ldi r24, 1 +81: brtc 82f + clr r22 + com r18 + com r19 + com r20 + com r21 + adc r18, r22 + adc r19, r22 + adc r20, r22 + adc r21, r22 +82: st -X, ZH + st -X, ZL + _MOVW XH, XL, r1, r0 + st X+, r18 + st X+, r19 + st X+, r20 + st X+, r21 + clr r1 + ret +.endfunc +#endif + + diff --git a/tmk_core/common/avr/xprintf.h b/tmk_core/common/avr/xprintf.h index 59c6f25312..08d9f93a0c 100644 --- a/tmk_core/common/avr/xprintf.h +++ b/tmk_core/common/avr/xprintf.h @@ -1,111 +1,111 @@ -/*---------------------------------------------------------------------------
- Extended itoa, puts and printf (C)ChaN, 2011
------------------------------------------------------------------------------*/
-
-#ifndef XPRINTF_H
-#define XPRINTF_H
-
-#include <inttypes.h>
-#include <avr/pgmspace.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern void (*xfunc_out)(uint8_t);
-#define xdev_out(func) xfunc_out = (void(*)(uint8_t))(func)
-
-/* This is a pointer to user defined output function. It must be initialized
- before using this modle.
-*/
-
-void xputc(char chr);
-
-/* This is a stub function to forward outputs to user defined output function.
- All outputs from this module are output via this function.
-*/
-
-
-/*-----------------------------------------------------------------------------*/
-void xputs(const char *string_p);
-
-/* The string placed in the ROM is forwarded to xputc() directly.
-*/
-
-
-/*-----------------------------------------------------------------------------*/
-void xitoa(long value, char radix, char width);
-
-/* Extended itoa().
-
- value radix width output
- 100 10 6 " 100"
- 100 10 -6 "000100"
- 100 10 0 "100"
- 4294967295 10 0 "4294967295"
- 4294967295 -10 0 "-1"
- 655360 16 -8 "000A0000"
- 1024 16 0 "400"
- 0x55 2 -8 "01010101"
-*/
-
-
-/*-----------------------------------------------------------------------------*/
-#define xprintf(format, ...) __xprintf(PSTR(format), ##__VA_ARGS__)
-#define xsprintf(str, format, ...) __xsprintf(str, PSTR(format), ##__VA_ARGS__)
-#define xfprintf(func, format, ...) __xfprintf(func, PSTR(format), ##__VA_ARGS__)
-
-void __xprintf(const char *format_p, ...); /* Send formatted string to the registered device */
-void __xsprintf(char*, const char *format_p, ...); /* Put formatted string to the memory */
-void __xfprintf(void(*func)(uint8_t), const char *format_p, ...); /* Send formatted string to the specified device */
-
-/* Format string is placed in the ROM. The format flags is similar to printf().
-
- %[flag][width][size]type
-
- flag
- A '0' means filled with '0' when output is shorter than width.
- ' ' is used in default. This is effective only numeral type.
- width
- Minimum width in decimal number. This is effective only numeral type.
- Default width is zero.
- size
- A 'l' means the argument is long(32bit). Default is short(16bit).
- This is effective only numeral type.
- type
- 'c' : Character, argument is the value
- 's' : String placed on the RAM, argument is the pointer
- 'S' : String placed on the ROM, argument is the pointer
- 'd' : Signed decimal, argument is the value
- 'u' : Unsigned decimal, argument is the value
- 'X' : Hexdecimal, argument is the value
- 'b' : Binary, argument is the value
- '%' : '%'
-
-*/
-
-
-/*-----------------------------------------------------------------------------*/
-char xatoi(char **str, long *ret);
-
-/* Get value of the numeral string.
-
- str
- Pointer to pointer to source string
-
- "0b11001010" binary
- "0377" octal
- "0xff800" hexdecimal
- "1250000" decimal
- "-25000" decimal
-
- ret
- Pointer to return value
-*/
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
+/*--------------------------------------------------------------------------- + Extended itoa, puts and printf (C)ChaN, 2011 +-----------------------------------------------------------------------------*/ + +#ifndef XPRINTF_H +#define XPRINTF_H + +#include <inttypes.h> +#include <avr/pgmspace.h> + +#ifdef __cplusplus +extern "C" { +#endif + +extern void (*xfunc_out)(uint8_t); +#define xdev_out(func) xfunc_out = (void(*)(uint8_t))(func) + +/* This is a pointer to user defined output function. It must be initialized + before using this modle. +*/ + +void xputc(char chr); + +/* This is a stub function to forward outputs to user defined output function. + All outputs from this module are output via this function. +*/ + + +/*-----------------------------------------------------------------------------*/ +void xputs(const char *string_p); + +/* The string placed in the ROM is forwarded to xputc() directly. +*/ + + +/*-----------------------------------------------------------------------------*/ +void xitoa(long value, char radix, char width); + +/* Extended itoa(). + + value radix width output + 100 10 6 " 100" + 100 10 -6 "000100" + 100 10 0 "100" + 4294967295 10 0 "4294967295" + 4294967295 -10 0 "-1" + 655360 16 -8 "000A0000" + 1024 16 0 "400" + 0x55 2 -8 "01010101" +*/ + + +/*-----------------------------------------------------------------------------*/ +#define xprintf(format, ...) __xprintf(PSTR(format), ##__VA_ARGS__) +#define xsprintf(str, format, ...) __xsprintf(str, PSTR(format), ##__VA_ARGS__) +#define xfprintf(func, format, ...) __xfprintf(func, PSTR(format), ##__VA_ARGS__) + +void __xprintf(const char *format_p, ...); /* Send formatted string to the registered device */ +// void __xsprintf(char*, const char *format_p, ...); /* Put formatted string to the memory */ +// void __xfprintf(void(*func)(uint8_t), const char *format_p, ...); /* Send formatted string to the specified device */ + +/* Format string is placed in the ROM. The format flags is similar to printf(). + + %[flag][width][size]type + + flag + A '0' means filled with '0' when output is shorter than width. + ' ' is used in default. This is effective only numeral type. + width + Minimum width in decimal number. This is effective only numeral type. + Default width is zero. + size + A 'l' means the argument is long(32bit). Default is short(16bit). + This is effective only numeral type. + type + 'c' : Character, argument is the value + 's' : String placed on the RAM, argument is the pointer + 'S' : String placed on the ROM, argument is the pointer + 'd' : Signed decimal, argument is the value + 'u' : Unsigned decimal, argument is the value + 'X' : Hexdecimal, argument is the value + 'b' : Binary, argument is the value + '%' : '%' + +*/ + + +/*-----------------------------------------------------------------------------*/ +char xatoi(char **str, long *ret); + +/* Get value of the numeral string. + + str + Pointer to pointer to source string + + "0b11001010" binary + "0377" octal + "0xff800" hexdecimal + "1250000" decimal + "-25000" decimal + + ret + Pointer to return value +*/ + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/tmk_core/common/bootmagic.c b/tmk_core/common/bootmagic.c index 6730a2a4aa..2c6bcbae56 100644 --- a/tmk_core/common/bootmagic.c +++ b/tmk_core/common/bootmagic.c @@ -83,10 +83,6 @@ void bootmagic(void) } eeconfig_update_keymap(keymap_config.raw); -#ifdef NKRO_ENABLE - keyboard_nkro = keymap_config.nkro; -#endif - /* default layer */ uint8_t default_layer = 0; if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_0)) { default_layer |= (1<<0); } diff --git a/tmk_core/common/command.c b/tmk_core/common/command.c index 084c9fe155..f3e1bf6234 100644 --- a/tmk_core/common/command.c +++ b/tmk_core/common/command.c @@ -34,6 +34,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "command.h" #include "backlight.h" #include "quantum.h" +#include "version.h" #ifdef MOUSEKEY_ENABLE #include "mousekey.h" @@ -180,7 +181,7 @@ static void print_version(void) print("VID: " STR(VENDOR_ID) "(" STR(MANUFACTURER) ") " "PID: " STR(PRODUCT_ID) "(" STR(PRODUCT) ") " "VER: " STR(DEVICE_VER) "\n"); - print("BUILD: " STR(VERSION) " (" __TIME__ " " __DATE__ ")\n"); + print("BUILD: " STR(QMK_VERSION) " (" __TIME__ " " __DATE__ ")\n"); /* build options */ print("OPTIONS:" @@ -237,7 +238,7 @@ static void print_status(void) print_val_hex8(keyboard_protocol); print_val_hex8(keyboard_idle); #ifdef NKRO_ENABLE - print_val_hex8(keyboard_nkro); + print_val_hex8(keymap_config.nkro); #endif print_val_hex32(timer_read32()); @@ -260,7 +261,10 @@ static void print_status(void) #ifdef BOOTMAGIC_ENABLE static void print_eeconfig(void) { -#ifndef NO_PRINT + +// Print these variables if NO_PRINT or USER_PRINT are not defined. +#if !defined(NO_PRINT) && !defined(USER_PRINT) + print("default_layer: "); print_dec(eeconfig_read_default_layer()); print("\n"); debug_config_t dc; @@ -380,9 +384,6 @@ static bool command_common(uint8_t code) debug_mouse = true; } else { print("\ndebug: off\n"); - debug_matrix = false; - debug_keyboard = false; - debug_mouse = false; } break; @@ -434,8 +435,8 @@ static bool command_common(uint8_t code) // NKRO toggle case MAGIC_KC(MAGIC_KEY_NKRO): clear_keyboard(); // clear to prevent stuck keys - keyboard_nkro = !keyboard_nkro; - if (keyboard_nkro) { + keymap_config.nkro = !keymap_config.nkro; + if (keymap_config.nkro) { print("NKRO: on\n"); } else { print("NKRO: off\n"); @@ -570,7 +571,8 @@ static uint8_t mousekey_param = 0; static void mousekey_param_print(void) { -#ifndef NO_PRINT +// Print these variables if NO_PRINT or USER_PRINT are not defined. +#if !defined(NO_PRINT) && !defined(USER_PRINT) print("\n\t- Values -\n"); print("1: delay(*10ms): "); pdec(mk_delay); print("\n"); print("2: interval(ms): "); pdec(mk_interval); print("\n"); diff --git a/tmk_core/common/host.c b/tmk_core/common/host.c index 11a05c2ddd..e12b622165 100644 --- a/tmk_core/common/host.c +++ b/tmk_core/common/host.c @@ -22,11 +22,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "util.h" #include "debug.h" - -#ifdef NKRO_ENABLE -bool keyboard_nkro = true; -#endif - static host_driver_t *driver; static uint16_t last_system_report = 0; static uint16_t last_consumer_report = 0; diff --git a/tmk_core/common/host.h b/tmk_core/common/host.h index 9814b10d2d..aeabba7107 100644 --- a/tmk_core/common/host.h +++ b/tmk_core/common/host.h @@ -28,10 +28,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. extern "C" { #endif -#ifdef NKRO_ENABLE -extern bool keyboard_nkro; -#endif - extern uint8_t keyboard_idle; extern uint8_t keyboard_protocol; diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c index c46a701b3b..371d93f3e5 100644 --- a/tmk_core/common/keyboard.c +++ b/tmk_core/common/keyboard.c @@ -57,6 +57,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. # include "visualizer/visualizer.h" #endif + + #ifdef MATRIX_HAS_GHOST static bool has_ghost_in_row(uint8_t row) { @@ -106,7 +108,7 @@ void keyboard_init(void) { rgblight_init(); #endif #if defined(NKRO_ENABLE) && defined(FORCE_NKRO) - keyboard_nkro = true; + keymap_config.nkro = 1; #endif } diff --git a/tmk_core/common/magic.c b/tmk_core/common/magic.c index 194e4cc026..49617a3d10 100644 --- a/tmk_core/common/magic.c +++ b/tmk_core/common/magic.c @@ -27,10 +27,6 @@ void magic(void) /* keymap config */ keymap_config.raw = eeconfig_read_keymap(); -#ifdef NKRO_ENABLE - keyboard_nkro = keymap_config.nkro; -#endif - uint8_t default_layer = 0; default_layer = eeconfig_read_default_layer(); default_layer_set((uint32_t)default_layer); diff --git a/tmk_core/common/mbed/xprintf.cpp b/tmk_core/common/mbed/xprintf.cpp index 3647ece751..b1aac2c99d 100644 --- a/tmk_core/common/mbed/xprintf.cpp +++ b/tmk_core/common/mbed/xprintf.cpp @@ -7,7 +7,7 @@ #define STRING_STACK_LIMIT 120 //TODO -int xprintf(const char* format, ...) { return 0; } +int __xprintf(const char* format, ...) { return 0; } #if 0 /* mbed Serial */ diff --git a/tmk_core/common/mbed/xprintf.h b/tmk_core/common/mbed/xprintf.h index 26bc529e5b..1e7a48c06d 100644 --- a/tmk_core/common/mbed/xprintf.h +++ b/tmk_core/common/mbed/xprintf.h @@ -7,7 +7,7 @@ extern "C" { #endif -int xprintf(const char *format, ...); +int __xprintf(const char *format, ...); #ifdef __cplusplus } diff --git a/tmk_core/common/print.h b/tmk_core/common/print.h index a1352527fc..8836c0fc7c 100644 --- a/tmk_core/common/print.h +++ b/tmk_core/common/print.h @@ -36,40 +36,140 @@ #ifndef NO_PRINT +#if defined(__AVR__) /* __AVR__ */ -#if defined(__AVR__) +# include "avr/xprintf.h" -#include "avr/xprintf.h" -#define print(s) xputs(PSTR(s)) -#define println(s) xputs(PSTR(s "\r\n")) +# ifdef USER_PRINT /* USER_PRINT */ -#ifdef __cplusplus +// Remove normal print defines +# define print(s) +# define println(s) +# undef xprintf +# define xprintf(fmt, ...) + +// Create user print defines +# define uprint(s) xputs(PSTR(s)) +# define uprintln(s) xputs(PSTR(s "\r\n")) +# define uprintf(fmt, ...) __xprintf(PSTR(fmt), ##__VA_ARGS__) + +# else /* NORMAL PRINT */ + +// Create user & normal print defines +# define print(s) xputs(PSTR(s)) +# define println(s) xputs(PSTR(s "\r\n")) +# define uprint(s) print(s) +# define uprintln(s) println(s) +# define uprintf(fmt, ...) xprintf(fmt, ...) + +# endif /* USER_PRINT / NORMAL PRINT */ + +# ifdef __cplusplus extern "C" -#endif +# endif + /* function pointer of sendchar to be used by print utility */ void print_set_sendchar(int8_t (*print_sendchar_func)(uint8_t)); -#elif defined(PROTOCOL_CHIBIOS) /* __AVR__ */ +#elif defined(PROTOCOL_CHIBIOS) /* PROTOCOL_CHIBIOS */ + +# include "chibios/printf.h" + +# ifdef USER_PRINT /* USER_PRINT */ + +// Remove normal print defines +# define print(s) +# define println(s) +# define xprintf(fmt, ...) + +// Create user print defines +# define uprint(s) printf(s) +# define uprintln(s) printf(s "\r\n") +# define uprintf printf + +# else /* NORMAL PRINT */ + +// Create user & normal print defines +# define print(s) printf(s) +# define println(s) printf(s "\r\n") +# define xprintf printf +# define uprint(s) printf(s) +# define uprintln(s) printf(s "\r\n") +# define uprintf printf -#include "chibios/printf.h" +# endif /* USER_PRINT / NORMAL PRINT */ -#define print(s) printf(s) -#define println(s) printf(s "\r\n") -#define xprintf printf +#elif defined(__arm__) /* __arm__ */ -#elif defined(__arm__) /* __AVR__ */ +# include "mbed/xprintf.h" -#include "mbed/xprintf.h" +# ifdef USER_PRINT /* USER_PRINT */ -#define print(s) xprintf(s) -#define println(s) xprintf(s "\r\n") +// Remove normal print defines +# define print(s) +# define println(s) +# define xprintf(fmt, ...) + +// Create user print defines +# define uprintf(fmt, ...) __xprintf(fmt, ...) +# define uprint(s) xprintf(s) +# define uprintln(s) xprintf(s "\r\n") + +# else /* NORMAL PRINT */ + +// Create user & normal print defines +# define xprintf(fmt, ...) __xprintf(fmt, ...) +# define print(s) xprintf(s) +# define println(s) xprintf(s "\r\n") +# define uprint(s) print(s) +# define uprintln(s) println(s) +# define uprintf(fmt, ...) xprintf(fmt, ...) + +# endif /* USER_PRINT / NORMAL PRINT */ /* TODO: to select output destinations: UART/USBSerial */ -#define print_set_sendchar(func) +# define print_set_sendchar(func) + +#endif /* __AVR__ / PROTOCOL_CHIBIOS / __arm__ */ + +// User print disables the normal print messages in the body of QMK/TMK code and +// is meant as a lightweight alternative to NOPRINT. Use it when you only want to do +// a spot of debugging but lack flash resources for allowing all of the codebase to +// print (and store their wasteful strings). +// +// !!! DO NOT USE USER PRINT CALLS IN THE BODY OF QMK/TMK !!! +// +#ifdef USER_PRINT -#endif /* __AVR__ */ +// Disable normal print +#define print_dec(data) +#define print_decs(data) +#define print_hex4(data) +#define print_hex8(data) +#define print_hex16(data) +#define print_hex32(data) +#define print_bin4(data) +#define print_bin8(data) +#define print_bin16(data) +#define print_bin32(data) +#define print_bin_reverse8(data) +#define print_bin_reverse16(data) +#define print_bin_reverse32(data) +#define print_val_dec(v) +#define print_val_decs(v) +#define print_val_hex8(v) +#define print_val_hex16(v) +#define print_val_hex32(v) +#define print_val_bin8(v) +#define print_val_bin16(v) +#define print_val_bin32(v) +#define print_val_bin_reverse8(v) +#define print_val_bin_reverse16(v) +#define print_val_bin_reverse32(v) +#else /* NORMAL_PRINT */ +//Enable normal print /* decimal */ #define print_dec(i) xprintf("%u", i) #define print_decs(i) xprintf("%d", i) @@ -99,6 +199,39 @@ void print_set_sendchar(int8_t (*print_sendchar_func)(uint8_t)); #define print_val_bin_reverse16(v) xprintf(#v ": %016b\n", bitrev16(v)) #define print_val_bin_reverse32(v) xprintf(#v ": %032lb\n", bitrev32(v)) +#endif /* USER_PRINT / NORMAL_PRINT */ + +// User Print + +/* decimal */ +#define uprint_dec(i) uprintf("%u", i) +#define uprint_decs(i) uprintf("%d", i) +/* hex */ +#define uprint_hex4(i) uprintf("%X", i) +#define uprint_hex8(i) uprintf("%02X", i) +#define uprint_hex16(i) uprintf("%04X", i) +#define uprint_hex32(i) uprintf("%08lX", i) +/* binary */ +#define uprint_bin4(i) uprintf("%04b", i) +#define uprint_bin8(i) uprintf("%08b", i) +#define uprint_bin16(i) uprintf("%016b", i) +#define uprint_bin32(i) uprintf("%032lb", i) +#define uprint_bin_reverse8(i) uprintf("%08b", bitrev(i)) +#define uprint_bin_reverse16(i) uprintf("%016b", bitrev16(i)) +#define uprint_bin_reverse32(i) uprintf("%032lb", bitrev32(i)) +/* print value utility */ +#define uprint_val_dec(v) uprintf(#v ": %u\n", v) +#define uprint_val_decs(v) uprintf(#v ": %d\n", v) +#define uprint_val_hex8(v) uprintf(#v ": %X\n", v) +#define uprint_val_hex16(v) uprintf(#v ": %02X\n", v) +#define uprint_val_hex32(v) uprintf(#v ": %04lX\n", v) +#define uprint_val_bin8(v) uprintf(#v ": %08b\n", v) +#define uprint_val_bin16(v) uprintf(#v ": %016b\n", v) +#define uprint_val_bin32(v) uprintf(#v ": %032lb\n", v) +#define uprint_val_bin_reverse8(v) uprintf(#v ": %08b\n", bitrev(v)) +#define uprint_val_bin_reverse16(v) uprintf(#v ": %016b\n", bitrev16(v)) +#define uprint_val_bin_reverse32(v) uprintf(#v ": %032lb\n", bitrev32(v)) + #else /* NO_PRINT */ #define xprintf(fmt, ...) @@ -143,5 +276,4 @@ void print_set_sendchar(int8_t (*print_sendchar_func)(uint8_t)); #define pbin_reverse(data) print_bin_reverse8(data) #define pbin_reverse16(data) print_bin_reverse16(data) - #endif |