summaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authorDaniel Leung <daniel.leung@intel.com>2016-01-26 13:02:02 -0800
committerAnas Nashif <anas.nashif@intel.com>2016-02-05 20:25:28 -0500
commit9709c1008a6c79d2a283b8ee42bc8b38070c89d4 (patch)
tree9eeee2077de73342a78f7fff67bce52d972b064b /samples
parent9183e1f4de334825d89e6af16b351bffb60037ab (diff)
samples: adds a sample for interfacing with APA102C LED
Change-Id: I653a47c942a36ce4002f0acad29c4978aa47080a Signed-off-by: Daniel Leung <daniel.leung@intel.com>
Diffstat (limited to 'samples')
-rw-r--r--samples/nanokernel/apps/led_apa102c/Makefile6
-rw-r--r--samples/nanokernel/apps/led_apa102c/prj_x86.conf7
-rw-r--r--samples/nanokernel/apps/led_apa102c/src/Makefile1
-rw-r--r--samples/nanokernel/apps/led_apa102c/src/main.c139
-rw-r--r--samples/nanokernel/apps/led_apa102c/testcase.ini6
5 files changed, 159 insertions, 0 deletions
diff --git a/samples/nanokernel/apps/led_apa102c/Makefile b/samples/nanokernel/apps/led_apa102c/Makefile
new file mode 100644
index 000000000..97f70d22e
--- /dev/null
+++ b/samples/nanokernel/apps/led_apa102c/Makefile
@@ -0,0 +1,6 @@
+BOARD ?= arduino_101
+
+KERNEL_TYPE ?= nano
+CONF_FILE = prj_$(ARCH).conf
+
+include ${ZEPHYR_BASE}/Makefile.inc
diff --git a/samples/nanokernel/apps/led_apa102c/prj_x86.conf b/samples/nanokernel/apps/led_apa102c/prj_x86.conf
new file mode 100644
index 000000000..d737bc377
--- /dev/null
+++ b/samples/nanokernel/apps/led_apa102c/prj_x86.conf
@@ -0,0 +1,7 @@
+CONFIG_STDOUT_CONSOLE=y
+CONFIG_PRINTK=y
+CONFIG_GPIO=y
+CONFIG_GPIO_DW=y
+CONFIG_GPIO_DW_0=y
+CONFIG_NANO_TIMERS=y
+CONFIG_NANO_TIMEOUTS=y
diff --git a/samples/nanokernel/apps/led_apa102c/src/Makefile b/samples/nanokernel/apps/led_apa102c/src/Makefile
new file mode 100644
index 000000000..00066e156
--- /dev/null
+++ b/samples/nanokernel/apps/led_apa102c/src/Makefile
@@ -0,0 +1 @@
+obj-y = main.o
diff --git a/samples/nanokernel/apps/led_apa102c/src/main.c b/samples/nanokernel/apps/led_apa102c/src/main.c
new file mode 100644
index 000000000..53c14397d
--- /dev/null
+++ b/samples/nanokernel/apps/led_apa102c/src/main.c
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2016 Intel Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file Sample app to utilize APA102C LED on Arduino 101 (x86).
+ *
+ * On x86 side of Arduino 101:
+ * 1. GPIO_16 is on IO8 (for data)
+ * 2. GPIO_19 is on IO4 (for clock)
+ *
+ * The gpio_dw driver is being used for bit-banging.
+ *
+ * The APA102/C requires 5V data and clock signals, so logic
+ * level shifter (preferred) or pull-up resistors are needed.
+ * Make sure the pins are 5V tolerant if using pull-up
+ * resistors.
+ *
+ * WARNING: the APA102C are very bright even at low settings.
+ * Protect your eyes and do not look directly into those LEDs.
+ */
+
+#include <zephyr.h>
+
+#if defined(CONFIG_STDOUT_CONSOLE)
+#include <stdio.h>
+#define PRINT printf
+#else
+#include <misc/printk.h>
+#define PRINT printk
+#endif
+
+#include <device.h>
+#include <gpio.h>
+#include <sys_clock.h>
+
+#define SLEEPTICKS MSEC(250)
+
+#define GPIO_DATA_PIN 16
+#define GPIO_CLK_PIN 19
+#define GPIO_NAME "GPIO_"
+
+#define GPIO_DRV_NAME CONFIG_GPIO_DW_0_NAME
+
+#define APA102C_START_FRAME 0x00000000
+#define APA102C_END_FRAME 0xFFFFFFFF
+
+/* The LED is very bright. So to protect the eyes,
+ * brightness is set very low, and RGB values are
+ * set low too.
+ */
+uint32_t rgb[] = {
+ 0xE1000010,
+ 0xE1001000,
+ 0xE1100000,
+ 0xE1101010,
+};
+#define NUM_RGB 4
+
+/* Number of LEDS linked together */
+#define NUM_LEDS 1
+
+void send_rgb(struct device *gpio_dev, uint32_t rgb)
+{
+ int i;
+
+ for (i = 0; i < 32; i++) {
+ /* MSB goes in first */
+ gpio_pin_write(gpio_dev, GPIO_DATA_PIN, !!(rgb & 0x80000000));
+
+ /* Latch data into LED */
+ gpio_pin_write(gpio_dev, GPIO_CLK_PIN, 1);
+ gpio_pin_write(gpio_dev, GPIO_CLK_PIN, 0);
+
+ rgb <<= 1;
+ }
+}
+
+void main(void)
+{
+ struct nano_timer timer;
+ void *timer_data[1];
+ struct device *gpio_dev;
+ int ret;
+ int idx = 0;
+ int leds = 0;
+
+ nano_timer_init(&timer, timer_data);
+
+ gpio_dev = device_get_binding(GPIO_DRV_NAME);
+ if (!gpio_dev) {
+ PRINT("Cannot find %s!\n", GPIO_DRV_NAME);
+ }
+
+ /* Setup GPIO output */
+ ret = gpio_pin_configure(gpio_dev, GPIO_DATA_PIN, (GPIO_DIR_OUT));
+ if (ret) {
+ PRINT("Error configuring " GPIO_NAME "%d!\n", GPIO_DATA_PIN);
+ }
+
+ ret = gpio_pin_configure(gpio_dev, GPIO_CLK_PIN, (GPIO_DIR_OUT));
+ if (ret) {
+ PRINT("Error configuring " GPIO_NAME "%d!\n", GPIO_CLK_PIN);
+ }
+
+ while (1) {
+ send_rgb(gpio_dev, APA102C_START_FRAME);
+
+ for (leds = 0; leds < NUM_LEDS; leds++) {
+ send_rgb(gpio_dev, rgb[(idx + leds) % NUM_RGB]);
+ }
+
+ /* If there are more LEDs linked together,
+ * then what NUM_LEDS is, the NUM_LEDS+1
+ * LED is going to be full bright.
+ */
+ send_rgb(gpio_dev, APA102C_END_FRAME);
+
+ idx++;
+ if (idx >= NUM_RGB) {
+ idx = 0;
+ }
+
+ nano_timer_start(&timer, SLEEPTICKS);
+ nano_timer_test(&timer, TICKS_UNLIMITED);
+ }
+}
diff --git a/samples/nanokernel/apps/led_apa102c/testcase.ini b/samples/nanokernel/apps/led_apa102c/testcase.ini
new file mode 100644
index 000000000..e7c54f38e
--- /dev/null
+++ b/samples/nanokernel/apps/led_apa102c/testcase.ini
@@ -0,0 +1,6 @@
+[test]
+build_only = true
+tags = samples
+
+arch_whitelist = x86
+platform_whitelist = arduino_101