samples: drivers: led: add ktd202x driver sample
Adds sample application for Kinetic KTD202X 3/4 channel LED driver Signed-off-by: Michael Estes <michael.estes@byteserv.io>
This commit is contained in:
9
samples/drivers/led/ktd202x/CMakeLists.txt
Normal file
9
samples/drivers/led/ktd202x/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(led_pca9633)
|
||||
|
||||
FILE(GLOB app_sources src/*.c)
|
||||
target_sources(app PRIVATE ${app_sources})
|
||||
38
samples/drivers/led/ktd202x/README.rst
Normal file
38
samples/drivers/led/ktd202x/README.rst
Normal file
@@ -0,0 +1,38 @@
|
||||
.. zephyr:code-sample:: ktd202x
|
||||
:name: KTD202X LED
|
||||
:relevant-api: led_interface
|
||||
|
||||
Control 3 LEDs connected to a KTD2026 driver chip.
|
||||
|
||||
Overview
|
||||
********
|
||||
|
||||
This sample controls 3 LEDs connected to a KTD2026 driver, using the
|
||||
following pattern:
|
||||
|
||||
1. turn on LEDs
|
||||
2. turn off LEDs
|
||||
3. set the brightness to 50%
|
||||
4. turn off LEDs
|
||||
5. blink the LEDs
|
||||
6. turn off LEDs
|
||||
|
||||
Building and Running
|
||||
********************
|
||||
|
||||
Build the application for the :zephyr:board:`nucleo_g431rb` board, and connect
|
||||
a KTD2026 LED driver on the bus I2C Arduino.
|
||||
|
||||
.. zephyr-app-commands::
|
||||
:zephyr-app: samples/drivers/led/ktd2026
|
||||
:board: nucleo_g431rb_board
|
||||
:goals: build
|
||||
:compact:
|
||||
|
||||
For flashing the application, refer to the Flashing section of the
|
||||
:zephyr:board:`nucleo_g431rb` board documentation.
|
||||
|
||||
References
|
||||
**********
|
||||
|
||||
- KTD202X: https://www.kinet-ic.com/uploads/web/KTD2026/KTD2026-7-04h.pdf
|
||||
11
samples/drivers/led/ktd202x/app.overlay
Normal file
11
samples/drivers/led/ktd202x/app.overlay
Normal file
@@ -0,0 +1,11 @@
|
||||
/* SPDX-License-Identifier: Apache-2.0 */
|
||||
|
||||
&arduino_i2c {
|
||||
status = "okay";
|
||||
clock-frequency = <I2C_BITRATE_STANDARD>;
|
||||
|
||||
ktd202x@30 {
|
||||
compatible = "kinetic,ktd202x";
|
||||
reg = <0x30>;
|
||||
};
|
||||
};
|
||||
3
samples/drivers/led/ktd202x/prj.conf
Normal file
3
samples/drivers/led/ktd202x/prj.conf
Normal file
@@ -0,0 +1,3 @@
|
||||
CONFIG_LOG=y
|
||||
|
||||
CONFIG_LED=y
|
||||
8
samples/drivers/led/ktd202x/sample.yaml
Normal file
8
samples/drivers/led/ktd202x/sample.yaml
Normal file
@@ -0,0 +1,8 @@
|
||||
sample:
|
||||
description: Demonstration of the KTD202X LED driver
|
||||
name: KTD202X sample
|
||||
tests:
|
||||
sample.drivers.led.ktd2026:
|
||||
depends_on: arduino_i2c
|
||||
build_only: true
|
||||
tags: LED
|
||||
82
samples/drivers/led/ktd202x/src/main.c
Normal file
82
samples/drivers/led/ktd202x/src/main.c
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 2025 Michael Estes
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/device.h>
|
||||
#include <errno.h>
|
||||
#include <zephyr/drivers/led.h>
|
||||
#include <zephyr/sys/util.h>
|
||||
#include <zephyr/kernel.h>
|
||||
|
||||
#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL
|
||||
#include <zephyr/logging/log.h>
|
||||
LOG_MODULE_REGISTER(main);
|
||||
|
||||
#define NUM_LEDS 3
|
||||
#define HALF_BRIGHTNESS (LED_BRIGHTNESS_MAX / 2)
|
||||
#define BLINK_DELAY_ON 500
|
||||
#define BLINK_DELAY_OFF 500
|
||||
#define DELAY_TIME_MS 1000
|
||||
#define DELAY_TIME K_MSEC(DELAY_TIME_MS)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
const struct device *const led_dev = DEVICE_DT_GET_ANY(kinetic_ktd202x);
|
||||
int i, ret;
|
||||
|
||||
if (!led_dev) {
|
||||
LOG_ERR("No devices with compatible kinetic,ktd202x found");
|
||||
return 0;
|
||||
} else if (!device_is_ready(led_dev)) {
|
||||
LOG_ERR("LED device %s is not ready", led_dev->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
LOG_INF("Found LED device %s", led_dev->name);
|
||||
LOG_INF("Testing leds");
|
||||
|
||||
while (1) {
|
||||
/* Turn on LEDs one by one */
|
||||
for (i = 0; i < NUM_LEDS; i++) {
|
||||
ret = led_on(led_dev, i);
|
||||
if (ret < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
k_sleep(DELAY_TIME);
|
||||
}
|
||||
|
||||
/* Turn off LEDs one by one */
|
||||
for (i = 0; i < NUM_LEDS; i++) {
|
||||
ret = led_off(led_dev, i);
|
||||
if (ret < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
k_sleep(DELAY_TIME);
|
||||
}
|
||||
|
||||
/* Set the brightness to half max of LEDs one by one */
|
||||
for (i = 0; i < NUM_LEDS; i++) {
|
||||
ret = led_set_brightness(led_dev, i, HALF_BRIGHTNESS);
|
||||
if (ret < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
k_sleep(DELAY_TIME);
|
||||
}
|
||||
|
||||
/* Turn off LEDs one by one */
|
||||
for (i = 0; i < NUM_LEDS; i++) {
|
||||
ret = led_off(led_dev, i);
|
||||
if (ret < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
k_sleep(DELAY_TIME);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user