aboutsummaryrefslogtreecommitdiff
path: root/keyboard/hhkb/matrix.c
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2013-07-08 14:38:03 +0900
committertmk <nobody@nowhere>2013-07-08 14:38:03 +0900
commit0e37dd2ec56114221d8c3eaf98e02b95fa15fa74 (patch)
treec96e5c0804ee16fb56a39078950b90ab5a9d2743 /keyboard/hhkb/matrix.c
parentd965822857e4933b1fcb0e940f4251468b32de9a (diff)
downloadqmk_firmware-0e37dd2ec56114221d8c3eaf98e02b95fa15fa74.tar.gz
qmk_firmware-0e37dd2ec56114221d8c3eaf98e02b95fa15fa74.zip
Add power control of keyswitch board and tweak scan wait
Diffstat (limited to 'keyboard/hhkb/matrix.c')
-rw-r--r--keyboard/hhkb/matrix.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/keyboard/hhkb/matrix.c b/keyboard/hhkb/matrix.c
index cf4bf9a7d..d0731ef1f 100644
--- a/keyboard/hhkb/matrix.c
+++ b/keyboard/hhkb/matrix.c
@@ -63,7 +63,7 @@ static matrix_row_t _matrix1[MATRIX_ROWS];
63 PORTE |= (1<<6); \ 63 PORTE |= (1<<6); \
64} while (0) 64} while (0)
65#define KEY_SELECT(ROW, COL) (PORTB = (PORTB & 0xC0) | \ 65#define KEY_SELECT(ROW, COL) (PORTB = (PORTB & 0xC0) | \
66 (((COL) & 0x07)<<3) | \ 66 (((COL) & 0x07)<<3) | \
67 ((ROW) & 0x07)) 67 ((ROW) & 0x07))
68#define KEY_ENABLE() (PORTB &= ~(1<<6)) 68#define KEY_ENABLE() (PORTB &= ~(1<<6))
69#define KEY_UNABLE() (PORTB |= (1<<6)) 69#define KEY_UNABLE() (PORTB |= (1<<6))
@@ -79,16 +79,20 @@ static matrix_row_t _matrix1[MATRIX_ROWS];
79// col: PB3-5,6 79// col: PB3-5,6
80// key: PD7(pull-uped) 80// key: PD7(pull-uped)
81// prev: PB7 81// prev: PB7
82// power: PD4(L:off/H:on)
82#define KEY_INIT() do { \ 83#define KEY_INIT() do { \
83 DDRB = 0xFF; \ 84 DDRB = 0xFF; \
84 PORTB = 0x00; \ 85 PORTB = 0x00; \
85 DDRD &= ~0x80; \ 86 DDRD &= ~0x80; \
86 PORTD |= 0x80; \ 87 PORTD |= 0x80; \
88 /* keyswitch board power on */ \
89 DDRD |= (1<<4); \
90 PORTD |= (1<<4); \
87 KEY_UNABLE(); \ 91 KEY_UNABLE(); \
88 KEY_PREV_OFF(); \ 92 KEY_PREV_OFF(); \
89} while (0) 93} while (0)
90#define KEY_SELECT(ROW, COL) (PORTB = (PORTB & 0xC0) | \ 94#define KEY_SELECT(ROW, COL) (PORTB = (PORTB & 0xC0) | \
91 (((COL) & 0x07)<<3) | \ 95 (((COL) & 0x07)<<3) | \
92 ((ROW) & 0x07)) 96 ((ROW) & 0x07))
93#define KEY_ENABLE() (PORTB &= ~(1<<6)) 97#define KEY_ENABLE() (PORTB &= ~(1<<6))
94#define KEY_UNABLE() (PORTB |= (1<<6)) 98#define KEY_UNABLE() (PORTB |= (1<<6))
@@ -97,6 +101,20 @@ static matrix_row_t _matrix1[MATRIX_ROWS];
97#define KEY_PREV_OFF() (PORTB &= ~(1<<7)) 101#define KEY_PREV_OFF() (PORTB &= ~(1<<7))
98#define KEY_POWER_ON() 102#define KEY_POWER_ON()
99#define KEY_POWER_OFF() 103#define KEY_POWER_OFF()
104/*
105#define KEY_POWER_ON() do { \
106 KEY_INIT(); \
107 PORTD |= (1<<4); \
108 _delay_ms(1); \
109} while (0)
110#define KEY_POWER_OFF() do { \
111 PORTD &= ~(1<<4); \
112 DDRB &= ~0xFF; \
113 PORTB &= ~0xFF; \
114 DDRB &= ~0x80; \
115 PORTB &= ~0x80; \
116} while (0)
117*/
100 118
101 119
102#elif defined(__AVR_ATmega328P__) 120#elif defined(__AVR_ATmega328P__)
@@ -195,16 +213,21 @@ uint8_t matrix_scan(void)
195 uint8_t last = TIMER_RAW; 213 uint8_t last = TIMER_RAW;
196 214
197 KEY_ENABLE(); 215 KEY_ENABLE();
216
198 // Wait for KEY_STATE outputs its value. 217 // Wait for KEY_STATE outputs its value.
199 // 1us was ok on one HHKB, but not worked on another. 218 // 1us was ok on one HHKB, but not worked on another.
200 // no wait doesn't work on Teensy++ with pro(1us works) 219 // no wait doesn't work on Teensy++ with pro(1us works)
201 // no wait does work on tmk PCB(8MHz) with pro2 220 // no wait does work on tmk PCB(8MHz) with pro2
202 // 1us wait does work on both of above 221 // 1us wait does work on both of above
222 // 1us wait doesn't work on tmk(16MHz)
223 // 5us wait does work on tmk(16MHz)
224 // 5us wait does work on tmk(16MHz/2)
225 // 5us wait does work on tmk(8MHz)
203 // 10us wait does work on Teensy++ with pro 226 // 10us wait does work on Teensy++ with pro
204 // 10us wait does work on 328p+iwrap with pro 227 // 10us wait does work on 328p+iwrap with pro
205 // 10us wait doesn't work on tmk PCB(8MHz) with pro2(very lagged scan) 228 // 10us wait doesn't work on tmk PCB(8MHz) with pro2(very lagged scan)
206 _delay_us(1); 229 _delay_us(5);
207// _delay_us(10); 230
208 if (KEY_STATE()) { 231 if (KEY_STATE()) {
209 matrix[row] &= ~(1<<col); 232 matrix[row] &= ~(1<<col);
210 } else { 233 } else {