samples: Add is31fl3216a LED sample

This demonstrates and tests is31fl3216a driver functionality.

Signed-off-by: Guy Morand <guy.morand@bytesatwork.ch>
This commit is contained in:
Guy Morand 2023-05-03 14:43:53 +02:00 committed by Carles Cufí
commit d87d934e75
7 changed files with 200 additions and 0 deletions

View 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_is31fl3216a)
FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})

View file

@ -0,0 +1,42 @@
.. _is31fl3216a:
is31fl3216a: 16 channels PWD LEDs controller
############################################
Overview
********
This sample controls up to 16 LEDs connected to a is31fl3216a driver.
Each LED is gradually pulsed until it reach 100% of luminosity and gradually
turned off again.
Once each LED was pulsed, multiple LEDs are pulse simultaneously using the
``write_channels`` LED API.
Test pattern
============
For each LED:
- Increase the luminosity until 100% is reached
- Decrease the luminosity until completely turned off
- Increase the luminosity of LEDs 2 to 4 until 100% is reached
- Decrease the luminosity of LEDs 2 to 4 until completely turned off
Building and Running
********************
This sample can be built and executed when the devicetree has an I2C device node
with compatible :dtcompatible:`issi,is31fl3216a` enabled, along with the relevant
bus controller node also being enabled.
As an example this sample provides a DTS overlay for the :ref:`lpcxpresso55s28`
board (:file:`boards/lpcxpresso55s28.overlay`). It assumes that a I2C
_is31fl3216a LED driver (with 16 LEDs wired) is connected to the I2C bus at
address 0x74.
References
**********
- is31fl3216a: https://lumissil.com/assets/pdf/core/IS31FL3216A_DS.pdf

View file

@ -0,0 +1,19 @@
/*
* Copyright (c) 2023 Endor AG
*
* SPDX-License-Identifier: Apache-2.0
*/
/*
* Example configuration of a is31fl3216a device on an Arduino I2C bus.
*
* Device address 0x74 is assumed. Your device may have a different
* address; check your device documentation if unsure.
*/
&arduino_i2c {
status = "okay";
is31fl3216a@74 {
compatible = "issi,is31fl3216a";
reg = <0x74>;
};
};

View file

@ -0,0 +1,15 @@
/*
* Copyright (c) 2023 Endor AG
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/dt-bindings/led/led.h>
&flexcomm4 {
status = "okay";
is31fl3216a@74 {
compatible = "issi,is31fl3216a";
reg = <0x74>;
};
};

View file

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

View file

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

View file

@ -0,0 +1,105 @@
/*
* Copyright (c) 2023 Endor AG
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/device.h>
#include <zephyr/drivers/led.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(main, CONFIG_LOG_DEFAULT_LEVEL);
#define MAX_BRIGHTNESS 100
#define LAST_LED 15
#define SLEEP_DELAY_MS 100
#define FADE_DELAY_MS 10
#define WRITE_CHANNELS_LEDS_COUNT 3
#define WRITE_CHANNELS_LED_START 2
static void pulse_led(int led, const struct device *const dev)
{
int status;
uint8_t percent;
for (percent = 1 ; percent <= MAX_BRIGHTNESS ; percent++) {
status = led_set_brightness(dev, led, percent);
if (status) {
LOG_ERR("Could not change brightness: %i", status);
return;
}
k_msleep(FADE_DELAY_MS);
}
k_msleep(SLEEP_DELAY_MS);
for (percent = MAX_BRIGHTNESS;
percent <= MAX_BRIGHTNESS; percent--) {
status = led_set_brightness(dev, led, percent);
if (status) {
LOG_ERR("Could not change brightness: %i", status);
return;
}
k_msleep(FADE_DELAY_MS);
}
}
static void pulse_leds(const struct device *const dev)
{
int status;
uint8_t brightness[WRITE_CHANNELS_LEDS_COUNT];
uint8_t percent;
for (percent = 1; percent <= MAX_BRIGHTNESS; percent++) {
memset(brightness, percent, sizeof(brightness));
status = led_write_channels(dev, WRITE_CHANNELS_LED_START,
WRITE_CHANNELS_LEDS_COUNT,
brightness);
if (status) {
LOG_ERR("Could not change brightness: %i", status);
return;
}
k_msleep(FADE_DELAY_MS);
}
k_msleep(SLEEP_DELAY_MS);
for (percent = MAX_BRIGHTNESS;
percent <= MAX_BRIGHTNESS; percent--) {
memset(brightness, percent, sizeof(brightness));
status = led_write_channels(dev, WRITE_CHANNELS_LED_START,
WRITE_CHANNELS_LEDS_COUNT,
brightness);
if (status) {
LOG_ERR("Could not change brightness: %i", status);
return;
}
k_msleep(FADE_DELAY_MS);
}
}
int main(void)
{
int led;
const struct device *const is31fl3216a =
DEVICE_DT_GET_ANY(issi_is31fl3216a);
if (!is31fl3216a) {
LOG_ERR("No device with compatible issi,is31fl3216a found");
return 0;
} else if (!device_is_ready(is31fl3216a)) {
LOG_ERR("LED controller %s is not ready", is31fl3216a->name);
return 0;
}
LOG_INF("Found LED controller %s", is31fl3216a->name);
for (;;) {
LOG_INF("Pulsing single LED");
for (led = 0 ; led <= LAST_LED ; led++) {
pulse_led(led, is31fl3216a);
}
LOG_INF("Pulsing multiple LEDs");
pulse_leds(is31fl3216a);
}
return 0;
}