diff options
Diffstat (limited to 'chip')
-rw-r--r-- | chip/lm4/keyboard_scan.c | 14 | ||||
-rw-r--r-- | chip/lm4/power_button.c | 28 |
2 files changed, 28 insertions, 14 deletions
diff --git a/chip/lm4/keyboard_scan.c b/chip/lm4/keyboard_scan.c index 33c894e8c1..ef7dfd6b94 100644 --- a/chip/lm4/keyboard_scan.c +++ b/chip/lm4/keyboard_scan.c @@ -102,6 +102,12 @@ static void enter_polling_mode(void) lm4_select_column(COLUMN_TRI_STATE_ALL); } +static int is_scanning_enabled(void) +{ + /* Scan only if enabled AND lid is open. */ + return lm4_get_scanning_enabled() && power_lid_open_debounced(); +} + /** * Read the raw keyboard matrix state. * @@ -311,7 +317,7 @@ static int check_keys_changed(uint8_t *state) any_change = 1; /* Inform keyboard module if scanning is enabled */ - if (lm4_get_scanning_enabled()) + if (is_scanning_enabled()) keyboard_state_changed(i, c, new_mask ? 1 : 0); } } @@ -453,13 +459,13 @@ void keyboard_scan_task(void) * starting to pay attention to edges. */ if ((lm4_read_raw_row_state() == 0xff) || - !lm4_get_scanning_enabled()) + !is_scanning_enabled()) task_wait_event(-1); - } while (!lm4_get_scanning_enabled()); + } while (!is_scanning_enabled()); enter_polling_mode(); /* Busy polling keyboard state. */ - while (lm4_get_scanning_enabled()) { + while (is_scanning_enabled()) { /* Check for keys down */ if (check_keys_changed(debounced_state)) { key_press_timer = 0; diff --git a/chip/lm4/power_button.c b/chip/lm4/power_button.c index 3407d7e701..a928f4895b 100644 --- a/chip/lm4/power_button.c +++ b/chip/lm4/power_button.c @@ -130,25 +130,33 @@ static void set_pwrbtn_to_pch(int high) gpio_set_level(GPIO_PCH_PWRBTNn, high); } +/** + * Get raw lid switch state. + * + * @return 1 if lid is open, 0 if closed. + */ +static int get_lid_open(void) +{ + return gpio_get_level(GPIO_LID_SWITCHn) ? 1 : 0; +} -/* Get raw power button signal state; 1 if power button is pressed, 0 if not - * pressed. */ +/** + * Get raw power button signal state. + * + * @return 1 if power button is pressed, 0 if not pressed. + */ static int get_power_button_pressed(void) { if (simulate_power_pressed) return 1; - return gpio_get_level(GPIO_POWER_BUTTONn) ? 0 : 1; -} + /* Ignore power button if lid is closed */ + if (!get_lid_open()) + return 0; - -/* Get raw lid switch state; 1 if lid is open, 0 if closed. */ -static int get_lid_open(void) -{ - return gpio_get_level(GPIO_LID_SWITCHn) ? 1 : 0; + return gpio_get_level(GPIO_POWER_BUTTONn) ? 0 : 1; } - static void update_backlight(void) { /* Only enable the backlight if the lid is open */ |