X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=keyboard%2Fhhkb%2Fhhkb_avr.h;h=5cb1d0d7d8365d594450b0ddcde0704c650767ee;hb=12e5a3a13eb86852ad58c131e28ba29c5f09bb2d;hp=46fb16679d37e7bc8e2685b7b729c5d5b8f70810;hpb=60134830506043be0c6d9d5ab37cf65dad3cc85f;p=max%2Ftmk_keyboard.git diff --git a/keyboard/hhkb/hhkb_avr.h b/keyboard/hhkb/hhkb_avr.h index 46fb1667..5cb1d0d7 100644 --- a/keyboard/hhkb/hhkb_avr.h +++ b/keyboard/hhkb/hhkb_avr.h @@ -41,24 +41,45 @@ static inline void KEY_UNABLE(void) { (PORTB |= (1<<6)); } static inline bool KEY_STATE(void) { return (PIND & (1<<7)); } static inline void KEY_PREV_ON(void) { (PORTB |= (1<<7)); } static inline void KEY_PREV_OFF(void) { (PORTB &= ~(1<<7)); } +#ifdef HHKB_POWER_SAVING +static inline void KEY_POWER_ON(void) { + DDRB = 0xFF; PORTB = 0x40; // change pins output + DDRD |= (1<<4); PORTD |= (1<<4); // MOS FET switch on + /* Without this wait you will miss or get false key events. */ + _delay_ms(5); // wait for powering up +} +static inline void KEY_POWER_OFF(void) { + /* input with pull-up consumes less than without it when pin is open. */ + DDRB = 0x00; PORTB = 0xFF; // change pins input with pull-up + DDRD |= (1<<4); PORTD &= ~(1<<4); // MOS FET switch off +} +static inline bool KEY_POWER_STATE(void) { return PORTD & (1<<4); } +#else static inline void KEY_POWER_ON(void) {} static inline void KEY_POWER_OFF(void) {} +static inline bool KEY_POWER_STATE(void) { return true; } +#endif static inline void KEY_INIT(void) { + /* row,col,prev: output */ DDRB = 0xFF; - PORTB = 0x00; + PORTB = 0x40; // unable + /* key: input with pull-up */ DDRD &= ~0x80; - PORTD |= 0x80; - /* keyswitch board power on */ - DDRD |= (1<<4); - PORTD |= (1<<4); + PORTD |= 0x80; #ifdef HHKB_JP /* row extention for HHKB JP */ DDRC |= (1<<6|1<<7); PORTC |= (1<<6|1<<7); +#else + /* input with pull up to save power */ + DDRC &= ~(1<<6|1<<7); + PORTC |= (1<<6|1<<7); #endif KEY_UNABLE(); KEY_PREV_OFF(); + + KEY_POWER_OFF(); } static inline void KEY_SELECT(uint8_t ROW, uint8_t COL) { @@ -71,13 +92,14 @@ static inline void KEY_SELECT(uint8_t ROW, uint8_t COL) #elif defined(__AVR_AT90USB1286__) -/* +/* * For Teensy++(AT90USB1286) * - * row: PB0-2 - * col: PB3-5,6 - * key: PE6(pull-uped) - * prev: PE7 + * HHKB pro HHKB pro2 + * row: PB0-2 (6-8) (5-7) + * col: PB3-5,6 (9-12) (8-11) + * key: PE6(pull-uped) (4) (3) + * prev: PE7 (5) (4) * * TODO: convert into 'staitc inline' function */ @@ -97,6 +119,7 @@ static inline void KEY_SELECT(uint8_t ROW, uint8_t COL) #define KEY_PREV_OFF() (PORTE &= ~(1<<7)) #define KEY_POWER_ON() #define KEY_POWER_OFF() +#define KEY_POWER_STATE() true #else