Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
samples: drivers: Add sample application for PCA9633
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
1 parent
ac1a9c4
commit 2ef1e72
Showing
8 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
CONFIG_I2C_STM32_V1=y | ||
CONFIG_I2C_1=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CONFIG_SYS_LOG=y | ||
|
||
CONFIG_I2C=y | ||
|
||
CONFIG_LED=y | ||
CONFIG_PCA9633=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
&i2c1 { | ||
status = "ok"; | ||
clock-frequency = <I2C_BITRATE_STANDARD>; | ||
|
||
pca9633@62 { | ||
compatible = "nxp,pca9633"; | ||
reg = <0x62>; | ||
label = "PCA9633"; | ||
}; | ||
}; |