diff options
author | Wai-Hong Tam <waihong@google.com> | 2020-11-16 11:42:27 -0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-11-18 23:52:14 +0000 |
commit | 1f1781f1af527edcab886fb54b540a7879291295 (patch) | |
tree | b0d14d9e5150c7513f329dcddeb4a937cf731aa8 /board/coachz/board.c | |
parent | 0e4740eaaac3e434120447e1913badfeca6cfa1a (diff) | |
download | chrome-ec-1f1781f1af527edcab886fb54b540a7879291295.tar.gz |
Coachz: Detect kickstand position and notify body proximity
Implement the kickstand hall sensor interrupts and the signal
debouncing. Use the kickstand position to approach the human
body proximity and update the EC_MKBP_FRONT_PROXIMITY event
to kernel.
BRANCH=Trogdor
BUG=b:168714440
TEST=Built the image correctly. Faked the signals and checked
the interrupts triggered and the proximity event updated.
Change-Id: I493b87ba5d6d8a801cc9aa6e181f72bf26bcafd6
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2543112
Reviewed-by: Stephen Boyd <swboyd@chromium.org>
Diffstat (limited to 'board/coachz/board.c')
-rw-r--r-- | board/coachz/board.c | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/board/coachz/board.c b/board/coachz/board.c index b7911214d5..1191b4566a 100644 --- a/board/coachz/board.c +++ b/board/coachz/board.c @@ -17,6 +17,7 @@ #include "driver/tcpm/tcpci.h" #include "gpio.h" #include "hooks.h" +#include "keyboard_mkbp.h" #include "keyboard_scan.h" #include "lid_switch.h" #include "pi3usb9201.h" @@ -34,6 +35,8 @@ #define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args) #define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args) +#define KS_DEBOUNCE_US (30 * MSEC) /* Debounce time for kickstand switch */ + /* Forward declaration */ static void tcpc_alert_event(enum gpio_signal signal); static void usb0_evt(enum gpio_signal signal); @@ -102,9 +105,58 @@ static void board_connect_c0_sbu(enum gpio_signal s) hook_call_deferred(&board_connect_c0_sbu_deferred_data, 0); } +static int debounced_ks_attached; +static int debounced_ks_open; + +/** + * Kickstand switch initialization + */ +static void ks_init(void) +{ + debounced_ks_attached = !gpio_get_level(GPIO_KS_ATTACHED_L); + debounced_ks_open = gpio_get_level(GPIO_KS_OPEN); + + /* Enable interrupts, now that we've initialized */ + gpio_enable_interrupt(GPIO_KS_ATTACHED_L); + gpio_enable_interrupt(GPIO_KS_OPEN); +} +DECLARE_HOOK(HOOK_INIT, ks_init, HOOK_PRIO_INIT_SWITCH); + +/** + * Handle debounced kickstand switch changing state. + */ +static void ks_change_deferred(void) +{ + const int ks_attached = !gpio_get_level(GPIO_KS_ATTACHED_L); + const int ks_open = gpio_get_level(GPIO_KS_OPEN); + int proximity_detected; + + /* If the switches haven't changed, nothing to do */ + if (ks_attached == debounced_ks_attached && + ks_open == debounced_ks_open) + return; + + /* + * A heuristic method to use the kickstand position to approach + * the human body proximity. + */ + proximity_detected = !(ks_attached && ks_open); + CPRINTS("ks %s %s -> proximity %s", + ks_attached ? "attached" : "detached", + ks_open ? "open" : "close", + proximity_detected ? "on" : "off"); + + debounced_ks_attached = ks_attached; + debounced_ks_open = ks_open; + + mkbp_update_switches(EC_MKBP_FRONT_PROXIMITY, proximity_detected); +} +DECLARE_DEFERRED(ks_change_deferred); + static void ks_interrupt(enum gpio_signal s) { - /* TODO(b/168714440): Implement the interrupt */ + /* Reset kickstand debounce time */ + hook_call_deferred(&ks_change_deferred_data, KS_DEBOUNCE_US); } /* I2C port map */ |