aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README17
-rw-r--r--hhkb/matrix.c18
-rw-r--r--key_process.c1
-rw-r--r--print.c9
-rw-r--r--print.h4
-rw-r--r--tmk.c26
6 files changed, 61 insertions, 14 deletions
diff --git a/README b/README
index 74a5014af..9bc883410 100644
--- a/README
+++ b/README
@@ -45,6 +45,12 @@ $ cd <target> (hhkb or macway)
45$ make 45$ make
46 46
47 47
48Debuging
49--------
50Debug print is on if 4 keys are pressed during booting.
51Use PJRC's hid_listen.exe to see debug messages.
52
53
48AVR Target board 54AVR Target board
49---------------- 55----------------
50Teensy/Teensy++ 56Teensy/Teensy++
@@ -84,9 +90,14 @@ debouncing logic
84 will be coded when bouncing occurs. 90 will be coded when bouncing occurs.
85 bouncing doesnt occur on my ALPS switch so far. 91 bouncing doesnt occur on my ALPS switch so far.
86 scan rate is too slow?(to be measure) 92 scan rate is too slow?(to be measure)
87layer switch 93layer switching
88 time before switching 94 time before switching
89 timeout when not used during specific time 95 timeout when not used during specific time
96debug on/off
97 Fn key conbination during normal operation
98 matrix print on/off
99 key print on/off
100 mouse print on/off
90 101
91Trackpoint(PS/2) 102Trackpoint(PS/2)
92 receive PS/2 signal from TrackPoint 103 receive PS/2 signal from TrackPoint
@@ -116,6 +127,10 @@ keymap
116 2010/10/23 127 2010/10/23
117souce code cleaning 128souce code cleaning
118 2010/10/23 129 2010/10/23
130debug on/off
131 debug off by default
132 pressing keys during booting
133 2010/10/23
119 134
120 135
121EOF 136EOF
diff --git a/hhkb/matrix.c b/hhkb/matrix.c
index a1917793e..a425439cc 100644
--- a/hhkb/matrix.c
+++ b/hhkb/matrix.c
@@ -32,6 +32,7 @@ static uint8_t _matrix1[MATRIX_ROWS];
32 32
33 33
34static bool matrix_has_ghost_in_row(int row); 34static bool matrix_has_ghost_in_row(int row);
35static int bit_pop(uint8_t bits);
35 36
36 37
37inline 38inline
@@ -88,7 +89,7 @@ int matrix_scan(void)
88} 89}
89 90
90bool matrix_is_modified(void) { 91bool matrix_is_modified(void) {
91 for (int i=0; i <MATRIX_ROWS; i++) { 92 for (int i = 0; i < MATRIX_ROWS; i++) {
92 if (matrix[i] != matrix_prev[i]) 93 if (matrix[i] != matrix_prev[i])
93 return true; 94 return true;
94 } 95 }
@@ -117,7 +118,22 @@ void matrix_print(void) {
117 } 118 }
118} 119}
119 120
121int matrix_key_count(void) {
122 int count = 0;
123 for (int i = 0; i < MATRIX_ROWS; i++) {
124 count += bit_pop(~matrix[i]);
125 }
126 return count;
127}
128
120inline 129inline
121static bool matrix_has_ghost_in_row(int row) { 130static bool matrix_has_ghost_in_row(int row) {
122 return false; 131 return false;
123} 132}
133
134static int bit_pop(uint8_t bits) {
135 int c;
136 for (c = 0; bits; c++)
137 bits &= bits -1;
138 return c;
139}
diff --git a/key_process.c b/key_process.c
index 8006ae72f..10cac032b 100644
--- a/key_process.c
+++ b/key_process.c
@@ -25,6 +25,7 @@
25#define MOUSE_DELAY_ACC 5 25#define MOUSE_DELAY_ACC 5
26 26
27 27
28// TODO: refactoring
28void proc_matrix(void) { 29void proc_matrix(void) {
29 static int mouse_repeat = 0; 30 static int mouse_repeat = 0;
30 31
diff --git a/print.c b/print.c
index 5395fa348..59b4bca18 100644
--- a/print.c
+++ b/print.c
@@ -27,8 +27,12 @@
27#include <avr/pgmspace.h> 27#include <avr/pgmspace.h>
28#include "print.h" 28#include "print.h"
29 29
30
31bool print_enable = false;
32
30void print_P(const char *s) 33void print_P(const char *s)
31{ 34{
35 if (!print_enable) return;
32 char c; 36 char c;
33 37
34 while (1) { 38 while (1) {
@@ -41,17 +45,20 @@ void print_P(const char *s)
41 45
42void phex1(unsigned char c) 46void phex1(unsigned char c)
43{ 47{
48 if (!print_enable) return;
44 usb_debug_putchar(c + ((c < 10) ? '0' : 'A' - 10)); 49 usb_debug_putchar(c + ((c < 10) ? '0' : 'A' - 10));
45} 50}
46 51
47void phex(unsigned char c) 52void phex(unsigned char c)
48{ 53{
54 if (!print_enable) return;
49 phex1(c >> 4); 55 phex1(c >> 4);
50 phex1(c & 15); 56 phex1(c & 15);
51} 57}
52 58
53void phex16(unsigned int i) 59void phex16(unsigned int i)
54{ 60{
61 if (!print_enable) return;
55 phex(i >> 8); 62 phex(i >> 8);
56 phex(i); 63 phex(i);
57} 64}
@@ -59,6 +66,7 @@ void phex16(unsigned int i)
59 66
60void pbin(unsigned char c) 67void pbin(unsigned char c)
61{ 68{
69 if (!print_enable) return;
62 for (int i = 7; i >= 0; i--) { 70 for (int i = 7; i >= 0; i--) {
63 usb_debug_putchar((c & (1<<i)) ? '1' : '0'); 71 usb_debug_putchar((c & (1<<i)) ? '1' : '0');
64 } 72 }
@@ -66,6 +74,7 @@ void pbin(unsigned char c)
66 74
67void pbin_reverse(unsigned char c) 75void pbin_reverse(unsigned char c)
68{ 76{
77 if (!print_enable) return;
69 for (int i = 0; i < 8; i++) { 78 for (int i = 0; i < 8; i++) {
70 usb_debug_putchar((c & (1<<i)) ? '1' : '0'); 79 usb_debug_putchar((c & (1<<i)) ? '1' : '0');
71 } 80 }
diff --git a/print.h b/print.h
index d61e5de3e..77290520e 100644
--- a/print.h
+++ b/print.h
@@ -1,9 +1,13 @@
1#ifndef PRINT_H__ 1#ifndef PRINT_H__
2#define PRINT_H__ 1 2#define PRINT_H__ 1
3 3
4#include <stdbool.h>
4#include <avr/pgmspace.h> 5#include <avr/pgmspace.h>
5#include "usb_debug.h" 6#include "usb_debug.h"
6 7
8
9bool print_enable;
10
7// this macro allows you to write print("some text") and 11// this macro allows you to write print("some text") and
8// the string is automatically placed into flash memory :) 12// the string is automatically placed into flash memory :)
9#define print(s) print_P(PSTR(s)) 13#define print(s) print_P(PSTR(s))
diff --git a/tmk.c b/tmk.c
index cd52d318e..54b02fcbc 100644
--- a/tmk.c
+++ b/tmk.c
@@ -63,18 +63,6 @@ int main(void)
63 usb_init(); 63 usb_init();
64 while (!usb_configured()) /* wait */ ; 64 while (!usb_configured()) /* wait */ ;
65 65
66 // Wait an extra second for the PC's operating system to load drivers
67 // and do whatever it does to actually be ready for input
68 // needs such long time in my PC.
69 /* wait for debug print. no need for normal use */
70 for (int i =0; i < 6; i++) {
71 LED_CONFIG;
72 LED_ON;
73 _delay_ms(500);
74 LED_OFF;
75 _delay_ms(500);
76 }
77
78 // Configure timer 0 to generate a timer overflow interrupt every 66 // Configure timer 0 to generate a timer overflow interrupt every
79 // 256*1024 clock cycles, or approx 61 Hz when using 16 MHz clock 67 // 256*1024 clock cycles, or approx 61 Hz when using 16 MHz clock
80 // This demonstrates how to use interrupts to implement a simple 68 // This demonstrates how to use interrupts to implement a simple
@@ -85,6 +73,20 @@ int main(void)
85 73
86 74
87 matrix_init(); 75 matrix_init();
76 matrix_scan();
77 // debug on when 4 keys are pressed
78 if (matrix_key_count() == 4) print_enable = true;
79
80 /* wait for debug pipe to print greetings. */
81 if (print_enable) {
82 for (int i =0; i < 6; i++) {
83 LED_CONFIG;
84 LED_ON;
85 _delay_ms(500);
86 LED_OFF;
87 _delay_ms(500);
88 }
89 }
88 print("\nt.m.k. keyboard 1.2\n"); 90 print("\nt.m.k. keyboard 1.2\n");
89 while (1) { 91 while (1) {
90 proc_matrix(); 92 proc_matrix();