summaryrefslogtreecommitdiff
path: root/common/blink.c
diff options
context:
space:
mode:
authorCraig Hesling <hesling@chromium.org>2020-02-29 21:44:31 -0800
committerCommit Bot <commit-bot@chromium.org>2020-03-25 03:23:58 +0000
commit5d1fa1bc15a6edd4188d551270b661f4a858b435 (patch)
tree8760141853e625143859d0f93e6bdcca7a2aed6d /common/blink.c
parent6d2a49dc7f603551ec3d898b74b8740fe0736cd9 (diff)
downloadchrome-ec-5d1fa1bc15a6edd4188d551270b661f4a858b435.tar.gz
common: Add blink example
Sometime you really just need a sanity check that the system is still ticking or that a new chip works. This is "the" rudimentary blink example. BRANCH=none BUG=none TEST=# Add CONFIG_BLINK to nucleo-h743zi board.h make BOARD=nucleo-h743zi # Flash to nucleo # Check lights are counting in binary Signed-off-by: Craig Hesling <hesling@chromium.org> Change-Id: Idf2d2bb245bd261806d7202f1557ced477b483c1 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2082074 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Diffstat (limited to 'common/blink.c')
-rw-r--r--common/blink.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/common/blink.c b/common/blink.c
new file mode 100644
index 0000000000..4231e38195
--- /dev/null
+++ b/common/blink.c
@@ -0,0 +1,30 @@
+/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* This is a sanity check program for boards that have LEDs. */
+
+#include "common.h"
+#include "gpio.h"
+#include "hooks.h"
+
+#ifndef CONFIG_BLINK_LEDS
+ #error The macro CONFIG_BLINK_LEDS must be specified to use BLINK.
+#endif
+
+static const enum gpio_signal leds[] = { CONFIG_BLINK_LEDS };
+
+BUILD_ASSERT(ARRAY_SIZE(leds) <= sizeof(int)*8, "Too many LEDs to drive.");
+BUILD_ASSERT(ARRAY_SIZE(leds) > 0, "Must have at least one LED to blink.");
+
+static void blink(void)
+{
+ static int led_values;
+
+ int i;
+ for (i = 0; i < ARRAY_SIZE(leds); i++)
+ gpio_set_level(leds[i], BIT(i) & led_values);
+ led_values++;
+}
+DECLARE_HOOK(HOOK_TICK, blink, HOOK_PRIO_DEFAULT);