samples: drivers: ht16k33: add sample application for the HT16K33
Add a sample application for showcasing the functionality of the Holtek HT16K33 LED driver with keyscan functionality. Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
This commit is contained in:
parent
98cecb3681
commit
d481fa8cce
7 changed files with 193 additions and 0 deletions
|
@ -246,6 +246,7 @@
|
||||||
/samples/boards/intel_s1000_crb/ @sathishkuttan @dcpleung @nashif
|
/samples/boards/intel_s1000_crb/ @sathishkuttan @dcpleung @nashif
|
||||||
/samples/display/ @vanwinkeljan
|
/samples/display/ @vanwinkeljan
|
||||||
/samples/drivers/CAN/ @alexanderwachter
|
/samples/drivers/CAN/ @alexanderwachter
|
||||||
|
/samples/drivers/ht16k33/ @henrikbrixandersen
|
||||||
/samples/gui/ @vanwinkeljan
|
/samples/gui/ @vanwinkeljan
|
||||||
/samples/net/ @jukkar @tbursztyka @pfalcon
|
/samples/net/ @jukkar @tbursztyka @pfalcon
|
||||||
/samples/net/dns_resolve/ @jukkar @tbursztyka @pfalcon
|
/samples/net/dns_resolve/ @jukkar @tbursztyka @pfalcon
|
||||||
|
|
9
samples/drivers/ht16k33/CMakeLists.txt
Normal file
9
samples/drivers/ht16k33/CMakeLists.txt
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.13.1)
|
||||||
|
|
||||||
|
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
|
||||||
|
project(ht16k33)
|
||||||
|
|
||||||
|
FILE(GLOB app_sources src/*.c)
|
||||||
|
target_sources(app PRIVATE ${app_sources})
|
42
samples/drivers/ht16k33/README.rst
Normal file
42
samples/drivers/ht16k33/README.rst
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
.. _ht16k33:
|
||||||
|
|
||||||
|
HT16K33 LED driver with keyscan
|
||||||
|
###############################
|
||||||
|
|
||||||
|
Overview
|
||||||
|
********
|
||||||
|
|
||||||
|
This sample controls the LEDs connected to a `Holtek HT16K33`_
|
||||||
|
driver. The sample supports up to 128 LEDs connected to the
|
||||||
|
rows/columns of the HT16K33.
|
||||||
|
|
||||||
|
The LEDs are controlled using the following pattern:
|
||||||
|
|
||||||
|
1. turn on all connected (up to 128) LEDs one-by-one
|
||||||
|
2. blink the LEDs at 2 Hz, 1 Hz, and 0.5 Hz
|
||||||
|
3. reduce the brightness gradually from 100% to 0%
|
||||||
|
4. turn off all LEDs, restore 100% brightness, and start over
|
||||||
|
|
||||||
|
The sample logs keyscan events on the console.
|
||||||
|
|
||||||
|
Building and Running
|
||||||
|
********************
|
||||||
|
|
||||||
|
Build the application for the :ref:`nrf52840_pca10056` board, and
|
||||||
|
connect a HT16K33 LED driver at address 0x70 on the I2C-0 bus.
|
||||||
|
|
||||||
|
.. zephyr-app-commands::
|
||||||
|
:zephyr-app: samples/drivers/ht16k33
|
||||||
|
:board: nrf52840_pca10056
|
||||||
|
:goals: build
|
||||||
|
:compact:
|
||||||
|
|
||||||
|
For flashing the application, refer to the Flashing section of the
|
||||||
|
:ref:`nrf52840_pca10056` board documentation.
|
||||||
|
|
||||||
|
References
|
||||||
|
**********
|
||||||
|
|
||||||
|
.. target-notes::
|
||||||
|
|
||||||
|
.. _Holtek HT16K33: http://www.holtek.com/productdetail/-/vg/HT16K33
|
35
samples/drivers/ht16k33/nrf52840_pca10056.overlay
Normal file
35
samples/drivers/ht16k33/nrf52840_pca10056.overlay
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 Henrik Brix Andersen <henrik@brixandersen.dk>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
&i2c0 {
|
||||||
|
clock-frequency = <I2C_BITRATE_STANDARD>;
|
||||||
|
|
||||||
|
ht16k33@70 {
|
||||||
|
compatible = "holtek,ht16k33";
|
||||||
|
reg = <0x70>;
|
||||||
|
label = "HT16K33";
|
||||||
|
/* Uncomment to use IRQ instead of polling: */
|
||||||
|
/* irq-gpios = <&gpio1 8 (GPIO_PUD_PULL_UP | GPIO_INT_ACTIVE_LOW)>; */
|
||||||
|
#address-cells = <1>;
|
||||||
|
#size-cells = <0>;
|
||||||
|
|
||||||
|
ks@0 {
|
||||||
|
compatible = "holtek,ht16k33-keyscan";
|
||||||
|
reg = <0x0>;
|
||||||
|
label = "KS0";
|
||||||
|
};
|
||||||
|
ks@1 {
|
||||||
|
compatible = "holtek,ht16k33-keyscan";
|
||||||
|
reg = <0x1>;
|
||||||
|
label = "KS1";
|
||||||
|
};
|
||||||
|
ks@2 {
|
||||||
|
compatible = "holtek,ht16k33-keyscan";
|
||||||
|
reg = <0x2>;
|
||||||
|
label = "KS2";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
6
samples/drivers/ht16k33/prj.conf
Normal file
6
samples/drivers/ht16k33/prj.conf
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
CONFIG_LOG=y
|
||||||
|
CONFIG_I2C=y
|
||||||
|
CONFIG_GPIO=y
|
||||||
|
CONFIG_LED=y
|
||||||
|
CONFIG_HT16K33=y
|
||||||
|
CONFIG_HT16K33_KEYSCAN=y
|
7
samples/drivers/ht16k33/sample.yaml
Normal file
7
samples/drivers/ht16k33/sample.yaml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
sample:
|
||||||
|
description: Demonstration of the HT16K33 LED driver with keyscan
|
||||||
|
name: HT16K33 sample
|
||||||
|
tests:
|
||||||
|
sample.driver.ht16k33:
|
||||||
|
platform_whitelist: nrf52840_pca10056
|
||||||
|
tags: LED
|
93
samples/drivers/ht16k33/src/main.c
Normal file
93
samples/drivers/ht16k33/src/main.c
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 Henrik Brix Andersen <henrik@brixandersen.dk>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <device.h>
|
||||||
|
#include <led.h>
|
||||||
|
#include <gpio.h>
|
||||||
|
#include <zephyr.h>
|
||||||
|
|
||||||
|
#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL
|
||||||
|
#include <logging/log.h>
|
||||||
|
LOG_MODULE_REGISTER(main);
|
||||||
|
|
||||||
|
#define LED_DEV_NAME DT_HOLTEK_HT16K33_0_LABEL
|
||||||
|
#define KS0_DEV_NAME DT_HOLTEK_HT16K33_KEYSCAN_0_LABEL
|
||||||
|
#define KS1_DEV_NAME DT_HOLTEK_HT16K33_KEYSCAN_1_LABEL
|
||||||
|
#define KS2_DEV_NAME DT_HOLTEK_HT16K33_KEYSCAN_2_LABEL
|
||||||
|
|
||||||
|
#define KEYSCAN_DEVICES 3
|
||||||
|
|
||||||
|
struct device *led_dev;
|
||||||
|
struct device *ks_dev[KEYSCAN_DEVICES];
|
||||||
|
static struct gpio_callback ks_cb[KEYSCAN_DEVICES];
|
||||||
|
|
||||||
|
static void keyscan_callback(struct device *gpiob,
|
||||||
|
struct gpio_callback *cb, u32_t pins)
|
||||||
|
{
|
||||||
|
LOG_INF("%s: 0x%08x", gpiob->config->name, pins);
|
||||||
|
}
|
||||||
|
|
||||||
|
void main(void)
|
||||||
|
{
|
||||||
|
int err;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* LED device binding */
|
||||||
|
led_dev = device_get_binding(LED_DEV_NAME);
|
||||||
|
if (!led_dev) {
|
||||||
|
LOG_ERR("LED device %s not found", LED_DEV_NAME);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Keyscan device bindings */
|
||||||
|
ks_dev[0] = device_get_binding(KS0_DEV_NAME);
|
||||||
|
ks_dev[1] = device_get_binding(KS1_DEV_NAME);
|
||||||
|
ks_dev[2] = device_get_binding(KS2_DEV_NAME);
|
||||||
|
for (i = 0; i < ARRAY_SIZE(ks_dev); i++) {
|
||||||
|
if (!ks_dev[i]) {
|
||||||
|
LOG_ERR("KS%d device not found", i);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
gpio_init_callback(&ks_cb[i], &keyscan_callback,
|
||||||
|
GENMASK(12, 0));
|
||||||
|
|
||||||
|
err = gpio_add_callback(ks_dev[i], &ks_cb[i]);
|
||||||
|
if (err) {
|
||||||
|
LOG_ERR("Failed to add KS%d GPIO callback (err %d)", i,
|
||||||
|
err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
LOG_INF("Iterating through all LEDs, turning them on "
|
||||||
|
"one-by-one");
|
||||||
|
for (i = 0; i < 128; i++) {
|
||||||
|
led_on(led_dev, i);
|
||||||
|
k_sleep(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 500; i <= 2000; i *= 2) {
|
||||||
|
LOG_INF("Blinking LEDs with a period of %d ms", i);
|
||||||
|
led_blink(led_dev, 0, i / 2, i / 2);
|
||||||
|
k_sleep(10 * i);
|
||||||
|
}
|
||||||
|
led_blink(led_dev, 0, 0, 0);
|
||||||
|
|
||||||
|
for (i = 100; i >= 0; i -= 10) {
|
||||||
|
LOG_INF("Setting LED brightness to %d%%", i);
|
||||||
|
led_set_brightness(led_dev, 0, i);
|
||||||
|
k_sleep(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_INF("Turning all LEDs off and restoring 100%% brightness");
|
||||||
|
for (i = 0; i < 128; i++) {
|
||||||
|
led_off(led_dev, i);
|
||||||
|
}
|
||||||
|
led_set_brightness(led_dev, 0, 100);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue