diff options
| -rw-r--r-- | keyboard/hhkb_rn42/config.h | 2 | ||||
| -rw-r--r-- | keyboard/hhkb_rn42/hhkb_avr.h | 26 |
2 files changed, 23 insertions, 5 deletions
diff --git a/keyboard/hhkb_rn42/config.h b/keyboard/hhkb_rn42/config.h index a46c7a8bf..21e73f1c5 100644 --- a/keyboard/hhkb_rn42/config.h +++ b/keyboard/hhkb_rn42/config.h | |||
| @@ -50,6 +50,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 50 | /* Boot Magic salt key: Space */ | 50 | /* Boot Magic salt key: Space */ |
| 51 | #define BOOTMAGIC_KEY_SALT KC_FN6 | 51 | #define BOOTMAGIC_KEY_SALT KC_FN6 |
| 52 | 52 | ||
| 53 | /* power control of key switch board */ | ||
| 54 | #define HHKB_POWER_SAVING | ||
| 53 | 55 | ||
| 54 | /* | 56 | /* |
| 55 | * Hardware Serial(UART) | 57 | * Hardware Serial(UART) |
diff --git a/keyboard/hhkb_rn42/hhkb_avr.h b/keyboard/hhkb_rn42/hhkb_avr.h index b7bd507b5..313effedf 100644 --- a/keyboard/hhkb_rn42/hhkb_avr.h +++ b/keyboard/hhkb_rn42/hhkb_avr.h | |||
| @@ -41,17 +41,31 @@ static inline void KEY_UNABLE(void) { (PORTB |= (1<<6)); } | |||
| 41 | static inline bool KEY_STATE(void) { return (PIND & (1<<7)); } | 41 | static inline bool KEY_STATE(void) { return (PIND & (1<<7)); } |
| 42 | static inline void KEY_PREV_ON(void) { (PORTB |= (1<<7)); } | 42 | static inline void KEY_PREV_ON(void) { (PORTB |= (1<<7)); } |
| 43 | static inline void KEY_PREV_OFF(void) { (PORTB &= ~(1<<7)); } | 43 | static inline void KEY_PREV_OFF(void) { (PORTB &= ~(1<<7)); } |
| 44 | #ifdef HHKB_POWER_SAVING | ||
| 45 | static inline void KEY_POWER_ON(void) { | ||
| 46 | _delay_ms(10); // TODO: sleep to save power | ||
| 47 | DDRB = 0xFF; PORTB = 0x40; // change pins output | ||
| 48 | DDRD |= (1<<4); PORTD |= (1<<4); // MOS FET switch on | ||
| 49 | /* Without this wait you will miss or get false key events. */ | ||
| 50 | _delay_ms(1); // wait for powering up | ||
| 51 | } | ||
| 52 | static inline void KEY_POWER_OFF(void) { | ||
| 53 | /* input with pull-up consumes less than without it when pin is open. */ | ||
| 54 | DDRB = 0x00; PORTB = 0xFF; // change pins input with pull-up | ||
| 55 | DDRD |= (1<<4); PORTD &= ~(1<<4); // MOS FET switch off | ||
| 56 | } | ||
| 57 | #else | ||
| 44 | static inline void KEY_POWER_ON(void) {} | 58 | static inline void KEY_POWER_ON(void) {} |
| 45 | static inline void KEY_POWER_OFF(void) {} | 59 | static inline void KEY_POWER_OFF(void) {} |
| 60 | #endif | ||
| 46 | static inline void KEY_INIT(void) | 61 | static inline void KEY_INIT(void) |
| 47 | { | 62 | { |
| 63 | /* row,col,prev: output */ | ||
| 48 | DDRB = 0xFF; | 64 | DDRB = 0xFF; |
| 49 | PORTB = 0x00; | 65 | PORTB = 0x40; // unable |
| 66 | /* key: input with pull-up */ | ||
| 50 | DDRD &= ~0x80; | 67 | DDRD &= ~0x80; |
| 51 | PORTD |= 0x80; | 68 | PORTD |= 0x80; |
| 52 | /* keyswitch board power on */ | ||
| 53 | DDRD |= (1<<4); | ||
| 54 | PORTD |= (1<<4); | ||
| 55 | #ifdef HHKB_JP | 69 | #ifdef HHKB_JP |
| 56 | /* row extention for HHKB JP */ | 70 | /* row extention for HHKB JP */ |
| 57 | DDRC |= (1<<6|1<<7); | 71 | DDRC |= (1<<6|1<<7); |
| @@ -59,6 +73,8 @@ static inline void KEY_INIT(void) | |||
| 59 | #endif | 73 | #endif |
| 60 | KEY_UNABLE(); | 74 | KEY_UNABLE(); |
| 61 | KEY_PREV_OFF(); | 75 | KEY_PREV_OFF(); |
| 76 | |||
| 77 | KEY_POWER_OFF(); | ||
| 62 | } | 78 | } |
| 63 | static inline void KEY_SELECT(uint8_t ROW, uint8_t COL) | 79 | static inline void KEY_SELECT(uint8_t ROW, uint8_t COL) |
| 64 | { | 80 | { |
