7 #include <avr/interrupt.h>
8 #include <util/delay.h>
11 // Timer resolution check
12 #if (1000000/TIMER_RAW_FREQ > 20)
13 # error "Timer resolution(>20us) is not enough for HHKB matrix scan tweak on V-USB."
20 * row: HC4051[A,B,C] selects scan row0-7
21 * row-ext: [En0,En1] row extention for JP
22 * col: LS145[A,B,C,D] selects scan col0-7 and enable(D)
24 * prev: hysteresis control: assert(1) when previous key state is on
29 * Pin configuration for ATMega32U4
32 * Col: PB0-2, 3(Z5 ~EN), 4(Z4 ~EN)
36 static inline void KEY_ENABLE(void) { (PORTD
&= ~(1<<7)); }
37 static inline void KEY_UNABLE(void) { (PORTD
|= (1<<7)); }
38 static inline bool KEY_STATE(void) { return (PINC
& (1<<6)); }
39 static inline void KEY_HYS_ON(void) { (PORTC
|= (1<<7)); }
40 static inline void KEY_HYS_OFF(void) { (PORTC
&= ~(1<<7)); }
41 static inline void KEY_INIT(void)
45 /* Key: input with pull-up */
56 static inline void SET_ROW(uint8_t ROW
)
58 // set row with unabling key
59 PORTD
= (PORTD
& 0x0F) | (1<<7) | ((ROW
& 0x07) << 4);
61 static inline void SET_COL(uint8_t COL
)
63 // |PB3(Z5 ~EN)|PB4(Z4 ~EN)
64 // --------|-----------|-----------
67 PORTB
= (PORTB
& 0xE0) | ((COL
& 0x08) ? 1<<4 : 1<<3) | (COL
& 0x07);