samples: add IS31FL3194 RGB LED driver sample

This sample app cycles several colors on an RGB LED forever using the LED
API. It can be built and executed on an Arduino Nicla Sense ME, or on any
board where the devicetree has a similar compatible I2C device node.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
This commit is contained in:
Luca Burelli 2024-02-16 11:05:49 +01:00 committed by Anas Nashif
commit 0d2b3e1f36
5 changed files with 105 additions and 0 deletions

View file

@ -0,0 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(led_is31fl3194)
target_sources(app PRIVATE src/main.c)

View file

@ -0,0 +1,28 @@
.. zephyr:code-sample:: is31fl3194
:name: IS31FL3194 RGB LED
:relevant-api: led_interface
Cycle colors on an RGB LED connected to the IS31FL3194 using the LED API.
Overview
********
This sample cycles several colors on an RGB LED forever using the LED API.
Building and Running
********************
This sample can be built and executed on an Arduino Nicla Sense ME, or on
any board where the devicetree has an I2C device node with compatible
:dtcompatible:`issi,is31fl3194` enabled, along with the relevant bus
controller node also being enabled.
.. zephyr-app-commands::
:zephyr-app: samples/drivers/led/issi_is31fl3194
:board: arduino_nicla_sense_me
:goals: build flash
:compact:
After flashing, the LED starts to switch colors and messages with the current
LED color are printed on the console. If a runtime error occurs, the sample
exits without printing to the console.

View file

@ -0,0 +1,2 @@
CONFIG_LED=y
CONFIG_LOG=y

View file

@ -0,0 +1,10 @@
sample:
description: Demonstration of the IS31FL3194 LED driver
name: is31fl3194 sample
tests:
sample.drivers.led.is31fl3194:
filter: dt_compat_enabled("issi,is31fl3194")
tags: LED
depends_on: i2c
integration_platforms:
- arduino_nicla_sense_me

View file

@ -0,0 +1,58 @@
/*
* Copyright (c) 2024 Arduino SA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdio.h>
#include <zephyr/kernel.h>
#include <zephyr/drivers/led.h>
/* 1000 msec = 1 sec */
#define SLEEP_TIME_MS 1000
/* Structure describing a color by its component values and name */
struct color_data {
uint8_t r, g, b;
const char *name;
};
/* The sequence of colors the RGB LED will display */
static const struct color_data color_sequence[] = {
{ 0xFF, 0x00, 0x00, "Red" },
{ 0x00, 0xFF, 0x00, "Green" },
{ 0x00, 0x00, 0xFF, "Blue" },
{ 0xFF, 0xFF, 0xFF, "White" },
{ 0xFF, 0xFF, 0x00, "Yellow" },
{ 0xFF, 0x00, 0xFF, "Purple" },
{ 0x00, 0xFF, 0xFF, "Cyan" },
{ 0xF4, 0x79, 0x20, "Orange" },
};
/*
* A build error on this line means your board is unsupported.
*/
const struct device *led = DEVICE_DT_GET_ANY(issi_is31fl3194);
int main(void)
{
int ret;
int i = 0;
if (!device_is_ready(led)) {
return 0;
}
while (1) {
ret = led_set_color(led, 0, 3, &(color_sequence[i].r));
if (ret < 0) {
return 0;
}
printk("LED color: %s\n", color_sequence[i].name);
k_msleep(SLEEP_TIME_MS);
i = (i + 1) % ARRAY_SIZE(color_sequence);
}
return 0;
}