diff options
| -rw-r--r-- | README | 17 | ||||
| -rw-r--r-- | hhkb/matrix.c | 18 | ||||
| -rw-r--r-- | key_process.c | 1 | ||||
| -rw-r--r-- | print.c | 9 | ||||
| -rw-r--r-- | print.h | 4 | ||||
| -rw-r--r-- | tmk.c | 26 |
6 files changed, 61 insertions, 14 deletions
| @@ -45,6 +45,12 @@ $ cd <target> (hhkb or macway) | |||
| 45 | $ make | 45 | $ make |
| 46 | 46 | ||
| 47 | 47 | ||
| 48 | Debuging | ||
| 49 | -------- | ||
| 50 | Debug print is on if 4 keys are pressed during booting. | ||
| 51 | Use PJRC's hid_listen.exe to see debug messages. | ||
| 52 | |||
| 53 | |||
| 48 | AVR Target board | 54 | AVR Target board |
| 49 | ---------------- | 55 | ---------------- |
| 50 | Teensy/Teensy++ | 56 | Teensy/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) |
| 87 | layer switch | 93 | layer 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 |
| 96 | debug 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 | ||
| 91 | Trackpoint(PS/2) | 102 | Trackpoint(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 |
| 117 | souce code cleaning | 128 | souce code cleaning |
| 118 | 2010/10/23 | 129 | 2010/10/23 |
| 130 | debug on/off | ||
| 131 | debug off by default | ||
| 132 | pressing keys during booting | ||
| 133 | 2010/10/23 | ||
| 119 | 134 | ||
| 120 | 135 | ||
| 121 | EOF | 136 | EOF |
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 | ||
| 34 | static bool matrix_has_ghost_in_row(int row); | 34 | static bool matrix_has_ghost_in_row(int row); |
| 35 | static int bit_pop(uint8_t bits); | ||
| 35 | 36 | ||
| 36 | 37 | ||
| 37 | inline | 38 | inline |
| @@ -88,7 +89,7 @@ int matrix_scan(void) | |||
| 88 | } | 89 | } |
| 89 | 90 | ||
| 90 | bool matrix_is_modified(void) { | 91 | bool 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 | ||
| 121 | int 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 | |||
| 120 | inline | 129 | inline |
| 121 | static bool matrix_has_ghost_in_row(int row) { | 130 | static bool matrix_has_ghost_in_row(int row) { |
| 122 | return false; | 131 | return false; |
| 123 | } | 132 | } |
| 133 | |||
| 134 | static 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 | ||
| 28 | void proc_matrix(void) { | 29 | void proc_matrix(void) { |
| 29 | static int mouse_repeat = 0; | 30 | static int mouse_repeat = 0; |
| 30 | 31 | ||
| @@ -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 | |||
| 31 | bool print_enable = false; | ||
| 32 | |||
| 30 | void print_P(const char *s) | 33 | void 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 | ||
| 42 | void phex1(unsigned char c) | 46 | void 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 | ||
| 47 | void phex(unsigned char c) | 52 | void 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 | ||
| 53 | void phex16(unsigned int i) | 59 | void 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 | ||
| 60 | void pbin(unsigned char c) | 67 | void 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 | ||
| 67 | void pbin_reverse(unsigned char c) | 75 | void 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 | } |
| @@ -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 | |||
| 9 | bool 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)) |
| @@ -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(); |
