summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/tablet_mode.c101
1 files changed, 54 insertions, 47 deletions
diff --git a/common/tablet_mode.c b/common/tablet_mode.c
index b74dc5fc49..5486ffc668 100644
--- a/common/tablet_mode.c
+++ b/common/tablet_mode.c
@@ -9,35 +9,60 @@
#include "hooks.h"
#include "host_command.h"
#include "lid_angle.h"
+#include "stdbool.h"
#include "tablet_mode.h"
#include "timer.h"
#define CPRINTS(format, args...) cprints(CC_MOTION_LID, format, ## args)
#define CPRINTF(format, args...) cprintf(CC_MOTION_LID, format, ## args)
-/* 1: in tablet mode; 0: notebook mode; -1: uninitialized */
-static int tablet_mode = -1;
-static int forced_tablet_mode = -1;
+/*
+ * Other code modules assume that notebook mode (i.e. tablet_mode = false) at
+ * startup
+ */
+static bool tablet_mode;
+
+/*
+ * Console command can force the value of tablet_mode. If tablet_mode_force is
+ * true, the all external set call for tablet_mode are ignored.
+ */
+static bool tablet_mode_forced;
-/* 1: GMR sensor is reporting 360 degrees. */
-static int gmr_sensor_at_360;
+/* True if GMR sensor is reporting 360 degrees. */
+static bool gmr_sensor_at_360;
/*
- * 1: all calls to tablet_set_mode are ignored and tablet_mode if forced to 0
- * 0: all calls to tablet_set_mode are honored
+ * True: all calls to tablet_set_mode are ignored and tablet_mode if forced to 0
+ * False: all calls to tablet_set_mode are honored
*/
-static int disabled;
+static bool disabled;
int tablet_get_mode(void)
{
- if (forced_tablet_mode != -1)
- return !!forced_tablet_mode;
- return !!tablet_mode;
+ return tablet_mode;
+}
+
+static void notify_tablet_mode_change(void)
+{
+ CPRINTS("tablet mode %sabled", tablet_mode ? "en" : "dis");
+ hook_notify(HOOK_TABLET_MODE_CHANGE);
+
+ /*
+ * When tablet mode changes, send an event to ACPI to retrieve
+ * tablet mode value and send an event to the kernel.
+ */
+ if (IS_ENABLED(CONFIG_HOSTCMD_EVENTS))
+ host_set_single_event(EC_HOST_EVENT_MODE_CHANGE);
+
}
void tablet_set_mode(int mode)
{
- if (tablet_mode == mode)
+ /* If tablet_mode is forced via a console command, ignore set. */
+ if (tablet_mode_forced)
+ return;
+
+ if (tablet_mode == !!mode)
return;
if (disabled) {
@@ -51,39 +76,15 @@ void tablet_set_mode(int mode)
return;
}
- tablet_mode = mode;
-
- if (forced_tablet_mode != -1)
- return;
-
- CPRINTS("tablet mode %sabled", mode ? "en" : "dis");
- hook_notify(HOOK_TABLET_MODE_CHANGE);
-
-#ifdef CONFIG_HOSTCMD_EVENTS
- /*
- * When tablet mode changes, send an event to ACPI to retrieve
- * tablet mode value and send an event to the kernel.
- */
- host_set_single_event(EC_HOST_EVENT_MODE_CHANGE);
-#endif
-}
+ tablet_mode = !!mode;
-static void tabletmode_force_state(int mode)
-{
- if (forced_tablet_mode == mode)
- return;
-
- forced_tablet_mode = mode;
-
- hook_notify(HOOK_TABLET_MODE_CHANGE);
- if (IS_ENABLED(CONFIG_HOSTCMD_EVENTS))
- host_set_single_event(EC_HOST_EVENT_MODE_CHANGE);
+ notify_tablet_mode_change();
}
void tablet_disable(void)
{
- tablet_mode = 0;
- disabled = 1;
+ tablet_mode = false;
+ disabled = true;
}
/* This ifdef can be removed once we clean up past projects which do own init */
@@ -169,14 +170,20 @@ static int command_settabletmode(int argc, char **argv)
{
if (argc != 2)
return EC_ERROR_PARAM_COUNT;
- if (argv[1][0] == 'o' && argv[1][1] == 'n')
- tabletmode_force_state(1);
- else if (argv[1][0] == 'o' && argv[1][1] == 'f')
- tabletmode_force_state(0);
- else if (argv[1][0] == 'r')
- tabletmode_force_state(-1);
- else
+
+ if (argv[1][0] == 'o' && argv[1][1] == 'n') {
+ tablet_mode = true;
+ tablet_mode_forced = true;
+ } else if (argv[1][0] == 'o' && argv[1][1] == 'f') {
+ tablet_mode = false;
+ tablet_mode_forced = true;
+ } else if (argv[1][0] == 'r') {
+ tablet_mode_forced = false;
+ } else {
return EC_ERROR_PARAM1;
+ }
+
+ notify_tablet_mode_change();
return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(tabletmode, command_settabletmode,