aboutsummaryrefslogtreecommitdiff
path: root/keyboard/hhkb/hhkb_avr.h
diff options
context:
space:
mode:
Diffstat (limited to 'keyboard/hhkb/hhkb_avr.h')
-rw-r--r--keyboard/hhkb/hhkb_avr.h28
1 files changed, 23 insertions, 5 deletions
diff --git a/keyboard/hhkb/hhkb_avr.h b/keyboard/hhkb/hhkb_avr.h
index b7bd507b5..7ea6322c7 100644
--- a/keyboard/hhkb/hhkb_avr.h
+++ b/keyboard/hhkb/hhkb_avr.h
@@ -41,17 +41,32 @@ static inline void KEY_UNABLE(void) { (PORTB |= (1<<6)); }
41static inline bool KEY_STATE(void) { return (PIND & (1<<7)); } 41static inline bool KEY_STATE(void) { return (PIND & (1<<7)); }
42static inline void KEY_PREV_ON(void) { (PORTB |= (1<<7)); } 42static inline void KEY_PREV_ON(void) { (PORTB |= (1<<7)); }
43static inline void KEY_PREV_OFF(void) { (PORTB &= ~(1<<7)); } 43static inline void KEY_PREV_OFF(void) { (PORTB &= ~(1<<7)); }
44#ifdef HHKB_POWER_SAVING
45static inline void KEY_POWER_ON(void) {
46 DDRB = 0xFF; PORTB = 0x40; // change pins output
47 DDRD |= (1<<4); PORTD |= (1<<4); // MOS FET switch on
48 /* Without this wait you will miss or get false key events. */
49 _delay_ms(5); // wait for powering up
50}
51static inline void KEY_POWER_OFF(void) {
52 /* input with pull-up consumes less than without it when pin is open. */
53 DDRB = 0x00; PORTB = 0xFF; // change pins input with pull-up
54 DDRD |= (1<<4); PORTD &= ~(1<<4); // MOS FET switch off
55}
56static inline bool KEY_POWER_STATE(void) { return PORTD & (1<<4); }
57#else
44static inline void KEY_POWER_ON(void) {} 58static inline void KEY_POWER_ON(void) {}
45static inline void KEY_POWER_OFF(void) {} 59static inline void KEY_POWER_OFF(void) {}
60static inline bool KEY_POWER_STATE(void) { return true; }
61#endif
46static inline void KEY_INIT(void) 62static inline void KEY_INIT(void)
47{ 63{
64 /* row,col,prev: output */
48 DDRB = 0xFF; 65 DDRB = 0xFF;
49 PORTB = 0x00; 66 PORTB = 0x40; // unable
67 /* key: input with pull-up */
50 DDRD &= ~0x80; 68 DDRD &= ~0x80;
51 PORTD |= 0x80; 69 PORTD |= 0x80;
52 /* keyswitch board power on */
53 DDRD |= (1<<4);
54 PORTD |= (1<<4);
55#ifdef HHKB_JP 70#ifdef HHKB_JP
56 /* row extention for HHKB JP */ 71 /* row extention for HHKB JP */
57 DDRC |= (1<<6|1<<7); 72 DDRC |= (1<<6|1<<7);
@@ -59,6 +74,8 @@ static inline void KEY_INIT(void)
59#endif 74#endif
60 KEY_UNABLE(); 75 KEY_UNABLE();
61 KEY_PREV_OFF(); 76 KEY_PREV_OFF();
77
78 KEY_POWER_OFF();
62} 79}
63static inline void KEY_SELECT(uint8_t ROW, uint8_t COL) 80static inline void KEY_SELECT(uint8_t ROW, uint8_t COL)
64{ 81{
@@ -98,6 +115,7 @@ static inline void KEY_SELECT(uint8_t ROW, uint8_t COL)
98#define KEY_PREV_OFF() (PORTE &= ~(1<<7)) 115#define KEY_PREV_OFF() (PORTE &= ~(1<<7))
99#define KEY_POWER_ON() 116#define KEY_POWER_ON()
100#define KEY_POWER_OFF() 117#define KEY_POWER_OFF()
118#define KEY_POWER_STATE() true
101 119
102 120
103#else 121#else