Skip to content

Commit

Permalink
samples: drivers: Add sample application for PCA9633
Browse files Browse the repository at this point in the history
Add sample application for NXP PCA9633 LED driver. This application
test the 4 LEDs by doing the following:
 - turn on LEDs
 - turn off LEDs
 - set the brightness to 50%
 - turn off LEDs
 - blink the LEDs
 - turn off LEDs

The application is based on the stm32373_eval board and expects to have
a PCA9633 LED driver on the bus I2C-1 at the address 0x62.

Signed-off-by: Sebastien Bourdelin <sebastien.bourdelin@savoirfairelinux.com>
  • Loading branch information
Sebastien Bourdelin authored and MaureenHelm committed Jul 2, 2018
1 parent ac1a9c4 commit 2ef1e72
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 0 deletions.
13 changes: 13 additions & 0 deletions samples/drivers/led_pca9633/CMakeLists.txt
@@ -0,0 +1,13 @@
macro(set_conf_file)
if(EXISTS ${APPLICATION_SOURCE_DIR}/boards/${BOARD}.conf)
set(CONF_FILE "prj.conf ${APPLICATION_SOURCE_DIR}/boards/${BOARD}.conf")
else()
set(CONF_FILE "prj.conf")
endif()
endmacro()

include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(NONE)

FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})
37 changes: 37 additions & 0 deletions samples/drivers/led_pca9633/README.rst
@@ -0,0 +1,37 @@
.. _pca9633:

PCA9633: 4-Channel RGB
######################

Overview
********

This sample controls 4 LEDs connected to a PCA9633 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 :ref:`stm32373c_eval_board` board, and connect
a PCA9633 LED driver on the bus I2C-1 at the address 0x62.

.. zephyr-app-commands::
:zephyr-app: samples/drivers/led_pca9633
:board: stm32373c_eval
:goals: build
:compact:

For flashing the application, refer to the Flashing section of the
:ref:`stm32373c_eval_board` board documentation.

References
**********

- PCA9633: https://www.nxp.com/docs/en/data-sheet/PCA9633.pdf
2 changes: 2 additions & 0 deletions samples/drivers/led_pca9633/boards/stm32373c_eval.conf
@@ -0,0 +1,2 @@
CONFIG_I2C_STM32_V1=y
CONFIG_I2C_1=y
9 changes: 9 additions & 0 deletions samples/drivers/led_pca9633/dts.fixup
@@ -0,0 +1,9 @@
#if defined(CONFIG_HAS_DTS_I2C_DEVICE)

#ifndef CONFIG_PCA9633_DEV_NAME
#define CONFIG_PCA9633_DEV_NAME ST_STM32_I2C_V2_40005400_NXP_PCA9633_62_LABEL
#define CONFIG_PCA9633_I2C_ADDRESS ST_STM32_I2C_V2_40005400_NXP_PCA9633_62_BASE_ADDRESS
#define CONFIG_PCA9633_I2C_MASTER_DEV_NAME ST_STM32_I2C_V2_40005400_NXP_PCA9633_62_BUS_NAME
#endif

#endif
6 changes: 6 additions & 0 deletions samples/drivers/led_pca9633/prj.conf
@@ -0,0 +1,6 @@
CONFIG_SYS_LOG=y

CONFIG_I2C=y

CONFIG_LED=y
CONFIG_PCA9633=y
8 changes: 8 additions & 0 deletions samples/drivers/led_pca9633/sample.yaml
@@ -0,0 +1,8 @@
sample:
description: Demonstration of the PCA9633 LED driver
name: PCA9633 sample
platforms: all
tests:
test:
platform_whitelist: stm32373c_eval
tags: samples
105 changes: 105 additions & 0 deletions samples/drivers/led_pca9633/src/main.c
@@ -0,0 +1,105 @@
/*
* Copyright (c) 2018 Savoir-Faire Linux.
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <device.h>
#include <errno.h>
#include <led.h>
#include <misc/util.h>
#include <zephyr.h>

#define SYS_LOG_LEVEL SYS_LOG_LEVEL_DEBUG
#include <logging/sys_log.h>

#define LED_DEV_NAME CONFIG_PCA9633_DEV_NAME
#define NUM_LEDS 4
#define MAX_BRIGHTNESS 100
#define HALF_BRIGHTNESS (MAX_BRIGHTNESS / 2)
#define BLINK_DELAY_ON 500
#define BLINK_DELAY_OFF 500
#define DELAY_TIME K_MSEC(1000)

void main(void)
{
struct device *led_dev;
int i, ret;

led_dev = device_get_binding(LED_DEV_NAME);
if (led_dev) {
SYS_LOG_INF("Found LED device %s", LED_DEV_NAME);
} else {
SYS_LOG_ERR("LED device %s not found", LED_DEV_NAME);
return;
}

SYS_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;
}

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;
}

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;
}

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;
}

k_sleep(DELAY_TIME);
}

/* Test the blinking of LEDs one by one */
for (i = 0; i < NUM_LEDS; i++) {
ret = led_blink(led_dev, i, BLINK_DELAY_ON,
BLINK_DELAY_OFF);
if (ret < 0) {
return;
}

k_sleep(DELAY_TIME);
}

/* Wait a few blinking before turning off the LEDs */
k_sleep(DELAY_TIME * 10);

/* Turn off LEDs one by one */
for (i = 0; i < NUM_LEDS; i++) {
ret = led_off(led_dev, i);
if (ret < 0) {
return;
}

k_sleep(DELAY_TIME);
}

}
}
10 changes: 10 additions & 0 deletions samples/drivers/led_pca9633/stm32373c_eval.overlay
@@ -0,0 +1,10 @@
&i2c1 {
status = "ok";
clock-frequency = <I2C_BITRATE_STANDARD>;

pca9633@62 {
compatible = "nxp,pca9633";
reg = <0x62>;
label = "PCA9633";
};
};

0 comments on commit 2ef1e72

Please sign in to comment.