summaryrefslogtreecommitdiff
path: root/tmk_core/common
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/common')
-rw-r--r--tmk_core/common/action.c82
-rw-r--r--tmk_core/common/action.h18
-rw-r--r--tmk_core/common/action_code.h28
-rw-r--r--tmk_core/common/avr/xprintf.S1000
-rw-r--r--tmk_core/common/avr/xprintf.h222
-rw-r--r--tmk_core/common/command.c3
-rw-r--r--tmk_core/common/virtser.h10
7 files changed, 750 insertions, 613 deletions
diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c
index be6dea2b79..08ef22eb97 100644
--- a/tmk_core/common/action.c
+++ b/tmk_core/common/action.c
@@ -41,6 +41,12 @@ void action_exec(keyevent_t event)
dprint("EVENT: "); debug_event(event); dprintln();
}
+#ifdef ONEHAND_ENABLE
+ if (!IS_NOEVENT(event)) {
+ process_hand_swap(&event);
+ }
+#endif
+
keyrecord_t record = { .event = event };
#ifndef NO_ACTION_TAPPING
@@ -53,6 +59,26 @@ void action_exec(keyevent_t event)
#endif
}
+#ifdef ONEHAND_ENABLE
+bool swap_hands = false;
+
+void process_hand_swap(keyevent_t *event) {
+ static swap_state_row_t swap_state[MATRIX_ROWS];
+
+ keypos_t pos = event->key;
+ swap_state_row_t col_bit = (swap_state_row_t)1<<pos.col;
+ bool do_swap = event->pressed ? swap_hands :
+ swap_state[pos.row] & (col_bit);
+
+ if (do_swap) {
+ event->key = hand_swap_config[pos.row][pos.col];
+ swap_state[pos.row] |= col_bit;
+ } else {
+ swap_state[pos.row] &= ~(col_bit);
+ }
+}
+#endif
+
#if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS)
bool disable_action_cache = false;
@@ -440,6 +466,54 @@ void process_action(keyrecord_t *record, action_t action)
#endif
case ACT_COMMAND:
break;
+#ifdef ONEHAND_ENABLE
+ case ACT_SWAP_HANDS:
+ switch (action.swap.code) {
+ case OP_SH_TOGGLE:
+ if (event.pressed) {
+ swap_hands = !swap_hands;
+ }
+ break;
+ case OP_SH_ON_OFF:
+ swap_hands = event.pressed;
+ break;
+ case OP_SH_OFF_ON:
+ swap_hands = !event.pressed;
+ break;
+ case OP_SH_ON:
+ if (!event.pressed) {
+ swap_hands = true;
+ }
+ break;
+ case OP_SH_OFF:
+ if (!event.pressed) {
+ swap_hands = false;
+ }
+ break;
+ #ifndef NO_ACTION_TAPPING
+ case OP_SH_TAP_TOGGLE:
+ /* tap toggle */
+ if (tap_count > 0) {
+ if (!event.pressed) {
+ swap_hands = !swap_hands;
+ }
+ } else {
+ swap_hands = event.pressed;
+ }
+ break;
+ default:
+ if (tap_count > 0) {
+ if (event.pressed) {
+ register_code(action.swap.code);
+ } else {
+ unregister_code(action.swap.code);
+ }
+ } else {
+ swap_hands = event.pressed;
+ }
+ #endif
+ }
+#endif
#ifndef NO_ACTION_FUNCTION
case ACT_FUNCTION:
action_function(record, action.func.id, action.func.opt);
@@ -652,6 +726,13 @@ bool is_tap_key(keypos_t key)
return true;
}
return false;
+ case ACT_SWAP_HANDS:
+ switch (action.swap.code) {
+ case 0x00 ... 0xdf:
+ case OP_SH_TAP_TOGGLE:
+ return true;
+ }
+ return false;
case ACT_MACRO:
case ACT_FUNCTION:
if (action.func.opt & FUNC_TAP) { return true; }
@@ -692,6 +773,7 @@ void debug_action(action_t action)
case ACT_MACRO: dprint("ACT_MACRO"); break;
case ACT_COMMAND: dprint("ACT_COMMAND"); break;
case ACT_FUNCTION: dprint("ACT_FUNCTION"); break;
+ case ACT_SWAP_HANDS: dprint("ACT_SWAP_HANDS"); break;
default: dprint("UNKNOWN"); break;
}
dprintf("[%X:%02X]", action.kind.param>>8, action.kind.param&0xff);
diff --git a/tmk_core/common/action.h b/tmk_core/common/action.h
index e8aa12a7cb..b9bdfe642c 100644
--- a/tmk_core/common/action.h
+++ b/tmk_core/common/action.h
@@ -65,6 +65,24 @@ bool process_record_quantum(keyrecord_t *record);
#if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS)
extern bool disable_action_cache;
#endif
+
+/* Code for handling one-handed key modifiers. */
+#ifdef ONEHAND_ENABLE
+extern bool swap_hands;
+extern const keypos_t hand_swap_config[MATRIX_ROWS][MATRIX_COLS];
+#if (MATRIX_COLS <= 8)
+typedef uint8_t swap_state_row_t;
+#elif (MATRIX_COLS <= 16)
+typedef uint16_t swap_state_row_t;
+#elif (MATRIX_COLS <= 32)
+typedef uint32_t swap_state_row_t;
+#else
+#error "MATRIX_COLS: invalid value"
+#endif
+
+void process_hand_swap(keyevent_t *record);
+#endif
+
void process_record_nocache(keyrecord_t *record);
void process_record(keyrecord_t *record);
void process_action(keyrecord_t *record, action_t action);
diff --git a/tmk_core/common/action_code.h b/tmk_core/common/action_code.h
index ca729aaece..33da35f35f 100644
--- a/tmk_core/common/action_code.h
+++ b/tmk_core/common/action_code.h
@@ -108,6 +108,8 @@ enum action_kind_id {
/* Other Keys */
ACT_USAGE = 0b0100,
ACT_MOUSEKEY = 0b0101,
+ /* One-hand Support */
+ ACT_SWAP_HANDS = 0b0110,
/* Layer Actions */
ACT_LAYER = 0b1000,
ACT_LAYER_TAP = 0b1010, /* Layer 0-15 */
@@ -178,6 +180,11 @@ typedef union {
uint8_t opt :4;
uint8_t kind :4;
} func;
+ struct action_swap {
+ uint8_t code :8;
+ uint8_t opt :4;
+ uint8_t kind :4;
+ } swap;
} action_t;
@@ -295,6 +302,7 @@ enum backlight_opt {
BACKLIGHT_STEP = 3,
BACKLIGHT_LEVEL = 4,
};
+
/* Macro */
#define ACTION_MACRO(id) ACTION(ACT_MACRO, (id))
#define ACTION_MACRO_TAP(id) ACTION(ACT_MACRO, FUNC_TAP<<8 | (id))
@@ -306,7 +314,7 @@ enum backlight_opt {
#define ACTION_BACKLIGHT_STEP() ACTION(ACT_BACKLIGHT, BACKLIGHT_STEP << 8)
#define ACTION_BACKLIGHT_LEVEL(level) ACTION(ACT_BACKLIGHT, BACKLIGHT_LEVEL << 8 | (level))
/* Command */
-#define ACTION_COMMAND(id, opt) ACTION(ACT_COMMAND, (opt)<<8 | (addr))
+#define ACTION_COMMAND(id, opt) ACTION(ACT_COMMAND, (opt)<<8 | (id))
/* Function */
enum function_opts {
FUNC_TAP = 0x8, /* indciates function is tappable */
@@ -314,5 +322,23 @@ enum function_opts {
#define ACTION_FUNCTION(id) ACTION(ACT_FUNCTION, (id))
#define ACTION_FUNCTION_TAP(id) ACTION(ACT_FUNCTION, FUNC_TAP<<8 | (id))
#define ACTION_FUNCTION_OPT(id, opt) ACTION(ACT_FUNCTION, (opt)<<8 | (id))
+/* OneHand Support */
+enum swap_hands_pram_tap_op {
+ OP_SH_TOGGLE = 0xF0,
+ OP_SH_TAP_TOGGLE,
+ OP_SH_ON_OFF,
+ OP_SH_OFF_ON,
+ OP_SH_OFF,
+ OP_SH_ON,
+};
+
+#define ACTION_SWAP_HANDS() ACTION_SWAP_HANDS_ON_OFF()
+#define ACTION_SWAP_HANDS_TOGGLE() ACTION(ACT_SWAP_HANDS, OP_SH_TOGGLE)
+#define ACTION_SWAP_HANDS_TAP_TOGGLE() ACTION(ACT_SWAP_HANDS, OP_SH_TAP_TOGGLE)
+#define ACTION_SWAP_HANDS_TAP_KEY(key) ACTION(ACT_SWAP_HANDS, key)
+#define ACTION_SWAP_HANDS_ON_OFF() ACTION(ACT_SWAP_HANDS, OP_SH_ON_OFF)
+#define ACTION_SWAP_HANDS_OFF_ON() ACTION(ACT_SWAP_HANDS, OP_SH_OFF_ON)
+#define ACTION_SWAP_HANDS_ON() ACTION(ACT_SWAP_HANDS, OP_SH_ON)
+#define ACTION_SWAP_HANDS_OFF() ACTION(ACT_SWAP_HANDS, OP_SH_OFF)
#endif /* ACTION_CODE_H */
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..e53c0dd8e0 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/command.c b/tmk_core/common/command.c
index 084c9fe155..476fc6fe3c 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:"
diff --git a/tmk_core/common/virtser.h b/tmk_core/common/virtser.h
new file mode 100644
index 0000000000..74891b6ae0
--- /dev/null
+++ b/tmk_core/common/virtser.h
@@ -0,0 +1,10 @@
+#ifndef _VIRTSER_H_
+#define _VIRTSER_H_
+
+/* Define this function in your code to process incoming bytes */
+void virtser_recv(const uint8_t ch);
+
+/* Call this to send a character over the Virtual Serial Device */
+void virtser_send(const uint8_t byte);
+
+#endif