mirror of
https://github.com/apache/nuttx.git
synced 2025-01-13 10:58:49 +08:00
Adds a driver for the PCA9635PW I2C LED driver IC which can be used to control the intensity of up to 16 LEDs. From Alexander Entinger
This commit is contained in:
parent
ebfead6f0d
commit
d62a626703
10 changed files with 672 additions and 2 deletions
|
@ -11242,4 +11242,7 @@
|
|||
(2015-12-12),
|
||||
* arch/arm/src/armv7-r: Add basic architecture support for the ARMv7-R
|
||||
processor family (2015-12-13).
|
||||
* drivers/led: Adds a driver for the PCA9635PW I2C LED driver IC which
|
||||
can be used to control the intensity of up to 16 LEDs. From Alexander
|
||||
Entinger (2015-12-15).
|
||||
|
||||
|
|
2
arch
2
arch
|
@ -1 +1 @@
|
|||
Subproject commit 42f1034f2722b51eaacc08389558405404eb5074
|
||||
Subproject commit c2384128a314987c0076f01435923de22ebbe785
|
|
@ -405,6 +405,8 @@ if LCD
|
|||
source drivers/lcd/Kconfig
|
||||
endif # LCD
|
||||
|
||||
source drivers/leds/Kconfig
|
||||
|
||||
menuconfig MMCSD
|
||||
bool "MMC/SD Driver Support"
|
||||
default n
|
||||
|
|
|
@ -55,6 +55,7 @@ include bch$(DELIM)Make.defs
|
|||
include input$(DELIM)Make.defs
|
||||
include discrete$(DELIM)Make.defs
|
||||
include lcd$(DELIM)Make.defs
|
||||
include leds$(DELIM)Make.defs
|
||||
include loop$(DELIM)Make.defs
|
||||
include mmcsd$(DELIM)Make.defs
|
||||
include mtd$(DELIM)Make.defs
|
||||
|
|
|
@ -81,6 +81,10 @@ lcd/
|
|||
Drivers for parallel and serial LCD and OLED type devices. These
|
||||
drivers support interfaces as defined in include/nuttx/lcd/lcd.h
|
||||
|
||||
leds/
|
||||
Various LED-related drivers including discrete as well as PWM-
|
||||
driven LEDs.
|
||||
|
||||
loop/
|
||||
Supports the standard loop device that can be used to export a
|
||||
file (or character device) as a block device. See losetup() and
|
||||
|
|
16
drivers/leds/Kconfig
Normal file
16
drivers/leds/Kconfig
Normal file
|
@ -0,0 +1,16 @@
|
|||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
menu "LED Support"
|
||||
|
||||
config PCA9635PW
|
||||
bool "PCA9635PW I2C LED Driver"
|
||||
default n
|
||||
select I2C
|
||||
---help---
|
||||
Enable support for the NXP PCA9635PW LED driver which can be
|
||||
utilized to drive up to 16 LED's.
|
||||
|
||||
endmenu # LED Support
|
51
drivers/leds/Make.defs
Normal file
51
drivers/leds/Make.defs
Normal file
|
@ -0,0 +1,51 @@
|
|||
############################################################################
|
||||
# drivers/leds/Make.defs
|
||||
# Various LED-related drivers
|
||||
#
|
||||
# Copyright (C) 2015 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
# Include LED drivers
|
||||
|
||||
LEDDEPATH =
|
||||
LEDVPATH =
|
||||
|
||||
ifeq ($(CONFIG_PCA9635PW),y)
|
||||
CSRCS += pca9635pw.c
|
||||
LEDDEPATH = --dep-path leds
|
||||
LEDVPATH = :leds
|
||||
endif
|
||||
|
||||
# Include LED build support (if any LED drivers were selected)
|
||||
|
||||
DEPPATH += $(LEDDEPATH)
|
||||
VPATH += $(LEDVPATH)
|
392
drivers/leds/pca9635pw.c
Normal file
392
drivers/leds/pca9635pw.c
Normal file
|
@ -0,0 +1,392 @@
|
|||
/****************************************************************************
|
||||
* drivers/leds/pca9635pw.c
|
||||
*
|
||||
* Copyright (C) 2015 DS-Automotion GmbH. All rights reserved.
|
||||
* Author: Alexander Entinger <a.entinger@ds-automotion.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/i2c.h>
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/leds/pca9635pw.h>
|
||||
|
||||
#if defined(CONFIG_I2C) && defined(CONFIG_PCA9635PW)
|
||||
|
||||
/****************************************************************************
|
||||
* Private Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
struct pca9635pw_dev_s
|
||||
{
|
||||
FAR struct i2c_dev_s *i2c;
|
||||
uint8_t i2c_addr;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static int pca9635pw_i2c_write_byte(FAR struct pca9635pw_dev_s *priv,
|
||||
uint8_t const reg_addr,
|
||||
uint8_t const reg_val);
|
||||
static int pca9635pw_set_led_mode(FAR struct pca9635pw_dev_s *priv,
|
||||
uint8_t const led_out_x_mode);
|
||||
|
||||
static int pca9635pw_open(FAR struct file *filep);
|
||||
static int pca9635pw_close(FAR struct file *filep);
|
||||
static int pca9635pw_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static const struct file_operations g_pca9635pw_fileops =
|
||||
{
|
||||
pca9635pw_open, /* open */
|
||||
pca9635pw_close, /* close */
|
||||
0, /* read */
|
||||
0, /* write */
|
||||
0, /* seek */
|
||||
pca9635pw_ioctl, /* ioctl */
|
||||
0 /* poll */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pca9635pw_i2c_write_byte
|
||||
*
|
||||
* Description:
|
||||
* Write a single byte to one of the PCA9635PW configuration registers.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int pca9635pw_i2c_write_byte(FAR struct pca9635pw_dev_s *priv,
|
||||
uint8_t const reg_addr,
|
||||
uint8_t const reg_val)
|
||||
{
|
||||
dbg("pca9635pw_i2c_write_byte\n");
|
||||
|
||||
/* assemble the 2 byte message comprised of reg_addr and reg_val */
|
||||
|
||||
uint8_t const BUFFER_SIZE = 2;
|
||||
uint8_t buffer[BUFFER_SIZE];
|
||||
|
||||
buffer[0] = reg_addr;
|
||||
buffer[1] = reg_val;
|
||||
|
||||
/* Write the register address followed by the data (no RESTART) */
|
||||
|
||||
uint8_t const NUMBER_OF_I2C_ADDRESS_BITS = 7;
|
||||
|
||||
dbg("i2c addr: 0x%02X reg addr: 0x%02X value: 0x%02X\n", priv->i2c_addr,
|
||||
buffer[0], buffer[1]);
|
||||
|
||||
int ret = I2C_SETADDRESS(priv->i2c, priv->i2c_addr,
|
||||
NUMBER_OF_I2C_ADDRESS_BITS);
|
||||
if (ret != OK)
|
||||
{
|
||||
dbg("I2C_SETADDRESS returned error code %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = I2C_WRITE(priv->i2c, buffer, BUFFER_SIZE);
|
||||
if (ret != OK)
|
||||
{
|
||||
dbg("I2C_WRITE returned error code %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pca9635pw_set_led_mode
|
||||
*
|
||||
* Description:
|
||||
* Set the led output mode (see PCA9635PW_LED_OUT_x register value definitions)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int pca9635pw_set_led_mode(FAR struct pca9635pw_dev_s *priv,
|
||||
uint8_t const led_out_x_mode)
|
||||
{
|
||||
uint8_t current_ledout_reg = PCA9635PW_LED_OUT_0;
|
||||
|
||||
for (; current_ledout_reg <= PCA9635PW_LED_OUT_3; current_ledout_reg++)
|
||||
{
|
||||
int const ret = pca9635pw_i2c_write_byte(priv, current_ledout_reg,
|
||||
led_out_x_mode);
|
||||
if (ret != OK)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pca9635pw_open
|
||||
*
|
||||
* Description:
|
||||
* This function is called whenever a PCA9635PW device is opened.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int pca9635pw_open(FAR struct file *filep)
|
||||
{
|
||||
dbg("pca9635pw_open\n");
|
||||
|
||||
FAR struct inode *inode = filep->f_inode;
|
||||
FAR struct pca9635pw_dev_s *priv = inode->i_private;
|
||||
|
||||
int ret = -1;
|
||||
|
||||
/* Wake up the PCA9635PW (sleep bit PCA9635PW_MODE_1_SLEEP is set to zero
|
||||
* and enable register auto increment - this way we can write to multiple
|
||||
* consecutive I2C registers without having to always write first the
|
||||
* address and then the data byte.
|
||||
*/
|
||||
|
||||
uint8_t const PCA9635PW_MODE_1_INITIAL_VALUE = PCA9635PW_MODE_1_AI2;
|
||||
|
||||
ret = pca9635pw_i2c_write_byte(priv, PCA9635PW_MODE_1,
|
||||
PCA9635PW_MODE_1_INITIAL_VALUE);
|
||||
if (ret != OK)
|
||||
{
|
||||
dbg("Could not set initial config for PCA9635PW_MODE_1\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Configure the PCA9635PW output drivers for totem-pole structure since
|
||||
* the output of the PCA9635PW are coupled with the Gates of MOSFET's
|
||||
* which then drive the LED's. Since we have this kind of schematic
|
||||
* structure we also need to invert the output.
|
||||
*/
|
||||
|
||||
uint8_t const PCA9635PW_MODE_2_INITIAL_VALUE =
|
||||
PCA9635PW_MODE_2_INVRT | PCA9635PW_MODE_2_OUTDRV;
|
||||
|
||||
ret = pca9635pw_i2c_write_byte(priv, PCA9635PW_MODE_2,
|
||||
PCA9635PW_MODE_2_INITIAL_VALUE);
|
||||
if (ret != OK)
|
||||
{
|
||||
dbg("Could not set initial config for PCA9635PW_MODE_2\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* A delay of 500 us is necessary since this is the maximum time which the
|
||||
* oscillator of the PCA9635PW needs to be up and running once sleep mode was
|
||||
* left.
|
||||
*/
|
||||
|
||||
usleep(500);
|
||||
|
||||
/* Turn all led drivers to mode 2 in which the led brightness is controlled
|
||||
* by the indiviual pwm registers.
|
||||
*/
|
||||
|
||||
ret = pca9635pw_set_led_mode(priv, PCA9635PW_LED_OUT_x_MODE_2);
|
||||
if (ret != OK)
|
||||
{
|
||||
dbg("Could not set led driver outputs to MODE2 (LED's brightness are "
|
||||
"controlled by pwm registers)\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pca9635pw_close
|
||||
*
|
||||
* Description:
|
||||
* This function is called whenever a PCA9635PW device is closed.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int pca9635pw_close(FAR struct file *filep)
|
||||
{
|
||||
dbg("pca9635pw_close\n");
|
||||
|
||||
FAR struct inode *inode = filep->f_inode;
|
||||
FAR struct pca9635pw_dev_s *priv = inode->i_private;
|
||||
|
||||
int ret = -1;
|
||||
|
||||
/* Turn all led drivers off */
|
||||
|
||||
ret = pca9635pw_set_led_mode(priv, PCA9635PW_LED_OUT_x_MODE_0);
|
||||
if (ret != OK)
|
||||
{
|
||||
dbg("Could not set led driver outputs to MODE0 (LED's are off)\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Send the PCA9635PW back to sleep mode */
|
||||
|
||||
uint8_t const PCA9635PW_MODE_1_FINAL_VALUE = PCA9635PW_MODE_1_SLEEP;
|
||||
|
||||
ret =pca9635pw_i2c_write_byte(priv, PCA9635PW_MODE_1,
|
||||
PCA9635PW_MODE_1_FINAL_VALUE);
|
||||
if (ret != OK)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pca9635pw_close
|
||||
*
|
||||
* Description:
|
||||
* This function is called whenever an ioctl call to a PCA9635PW is performed.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int pca9635pw_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
||||
{
|
||||
dbg("pca9635pw_ioctl\n");
|
||||
|
||||
FAR struct inode *inode = filep->f_inode;
|
||||
FAR struct pca9635pw_dev_s *priv = inode->i_private;
|
||||
|
||||
int ret = OK;
|
||||
|
||||
dbg("cmd: %d arg: %ld\n", cmd, arg);
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
/* Set the brightness of an indivual LED. Arg: pca9635pw_led_brightness_s
|
||||
* pointer.
|
||||
*/
|
||||
|
||||
case PWMIOC_SETLED_BRIGHTNESS:
|
||||
{
|
||||
/* Retrieve the information handed over as argument for this ioctl */
|
||||
|
||||
FAR const struct pca9635pw_setled_brightness_arg_s *ptr =
|
||||
(FAR const struct pca9635pw_setled_brightness_arg_s *)((uintptr_t)arg);
|
||||
|
||||
DEBUGASSERT(ptr != NULL);
|
||||
|
||||
/* Set the brighntess of the led */
|
||||
|
||||
ret = pca9635pw_i2c_write_byte(priv, ptr->led, ptr->brightness);
|
||||
}
|
||||
break;
|
||||
|
||||
/* The used ioctl command was invalid */
|
||||
|
||||
default:
|
||||
{
|
||||
dbg("Unrecognized cmd: %d\n", cmd);
|
||||
ret = -ENOTTY;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pca9635pw_register
|
||||
*
|
||||
* Description:
|
||||
* Register the PCA9635PW device as 'devpath'
|
||||
*
|
||||
* Input Parameters:
|
||||
* devpath - The full path to the driver to register. E.g., "/dev/leddrv0".
|
||||
* i2c - An instance of the I2C interface to use to communicate
|
||||
* with the LM92.
|
||||
* pca9635pw_i2c_addr
|
||||
* - The I2C address of the PCA9635PW.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int pca9635pw_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c,
|
||||
uint8_t const pca9635pw_i2c_addr)
|
||||
{
|
||||
/* Sanity check */
|
||||
|
||||
DEBUGASSERT(i2c != NULL);
|
||||
|
||||
/* Initialize the PCA9635PW device structure */
|
||||
|
||||
FAR struct pca9635pw_dev_s *priv =
|
||||
(FAR struct pca9635pw_dev_s *)kmm_malloc(sizeof(struct pca9635pw_dev_s));
|
||||
|
||||
if (priv == NULL)
|
||||
{
|
||||
dbg("Failed to allocate instance of pca9635pw_dev_s\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
priv->i2c = i2c;
|
||||
priv->i2c_addr = pca9635pw_i2c_addr;
|
||||
|
||||
/* Register the character driver */
|
||||
|
||||
int const ret = register_driver(devpath, &g_pca9635pw_fileops, 666, priv);
|
||||
if (ret != OK)
|
||||
{
|
||||
dbg("Failed to register driver: %d\n", ret);
|
||||
kmm_free(priv);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* setup i2c frequency */
|
||||
|
||||
I2C_SETFREQUENCY(priv->i2c, I2C_BUS_FREQ_HZ);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_I2C && CONFIG_I2C_PCA9635PW */
|
|
@ -2,7 +2,7 @@
|
|||
# drivers/timers/Make.defs
|
||||
# These drivers support various timer devices
|
||||
#
|
||||
# Copyright (C) 20125Gregory Nutt. All rights reserved.
|
||||
# Copyright (C) 2015 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
|
|
201
include/nuttx/leds/pca9635pw.h
Normal file
201
include/nuttx/leds/pca9635pw.h
Normal file
|
@ -0,0 +1,201 @@
|
|||
/****************************************************************************
|
||||
* include/nuttx/leds/pca9635pw.h
|
||||
*
|
||||
* Copyright (C) 2015 DS-Automotion GmbH. All rights reserved.
|
||||
* Author: Alexander Entinger <a.entinger@ds-automotion.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_LEDS_PCA9635PW_H
|
||||
#define __INCLUDE_NUTTX_LEDS_PCA9635PW_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/fs/ioctl.h>
|
||||
|
||||
/* Configuration
|
||||
* CONFIG_I2C - Enables support for I2C drivers
|
||||
* CONFIG_PCA9635PW - Enables support for the PCA9635PW driver
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_I2C) && defined(CONFIG_PCA9635PW)
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* I2C definitions */
|
||||
|
||||
#define I2C_BUS_FREQ_HZ (1000000)
|
||||
|
||||
/* PCA9635PW register addresses */
|
||||
|
||||
#define PCA9635PW_MODE_1 (0x00) /* Mode register 1 */
|
||||
#define PCA9635PW_MODE_2 (0x01) /* Mode register 2 */
|
||||
#define PCA9635PW_LED_0 (0x02) /* LED 0 brightness control */
|
||||
#define PCA9635PW_LED_1 (PCA9635PW_LED_0 + 1) /* LED 1 brightness control */
|
||||
#define PCA9635PW_LED_2 (PCA9635PW_LED_0 + 2) /* LED 2 brightness control */
|
||||
#define PCA9635PW_LED_3 (PCA9635PW_LED_0 + 3) /* LED 3 brightness control */
|
||||
#define PCA9635PW_LED_4 (PCA9635PW_LED_0 + 4) /* LED 4 brightness control */
|
||||
#define PCA9635PW_LED_5 (PCA9635PW_LED_0 + 5) /* LED 5 brightness control */
|
||||
#define PCA9635PW_LED_6 (PCA9635PW_LED_0 + 6) /* LED 6 brightness control */
|
||||
#define PCA9635PW_LED_7 (PCA9635PW_LED_0 + 7) /* LED 7 brightness control */
|
||||
#define PCA9635PW_LED_8 (PCA9635PW_LED_0 + 8) /* LED 8 brightness control */
|
||||
#define PCA9635PW_LED_9 (PCA9635PW_LED_0 + 9) /* LED 9 brightness control */
|
||||
#define PCA9635PW_LED_10 (PCA9635PW_LED_0 + 10) /* LED 10 brightness control */
|
||||
#define PCA9635PW_LED_11 (PCA9635PW_LED_0 + 11) /* LED 11 brightness control */
|
||||
#define PCA9635PW_LED_12 (PCA9635PW_LED_0 + 12) /* LED 12 brightness control */
|
||||
#define PCA9635PW_LED_13 (PCA9635PW_LED_0 + 13) /* LED 13 brightness control */
|
||||
#define PCA9635PW_LED_14 (PCA9635PW_LED_0 + 14) /* LED 14 brightness control */
|
||||
#define PCA9635PW_LED_15 (PCA9635PW_LED_0 + 15) /* LED 15 brightness control */
|
||||
#define PCA9635PW_GRPPWM (0x12) /* Group duty cycle control */
|
||||
#define PCA9635PW_GRPFREQ (0x13) /* group frequency */
|
||||
#define PCA9635PW_LED_OUT_0 (0x14) /* LED output state 0 */
|
||||
#define PCA9635PW_LED_OUT_1 (PCA9635PW_LED_OUT_0 + 1) /* LED output state 1 */
|
||||
#define PCA9635PW_LED_OUT_2 (PCA9635PW_LED_OUT_0 + 2) /* LED output state 2 */
|
||||
#define PCA9635PW_LED_OUT_3 (PCA9635PW_LED_OUT_0 + 3) /* LED output state 3 */
|
||||
|
||||
/* PCA9635PW_MODE_1 bit definitions */
|
||||
|
||||
#define PCA9635PW_MODE_1_AI2 (1<<7) /* auto increment enable/disable */
|
||||
#define PCA9635PW_MODE_1_AI1 (1<<6) /* auto increment bit 1 */
|
||||
#define PCA9635PW_MODE_1_AI0 (1<<5) /* auto increment bit 0 */
|
||||
#define PCA9635PW_MODE_1_SLEEP (1<<4) /* low power mode/sleep enable/disable */
|
||||
#define PCA9635PW_MODE_1_SUB1 (1<<3) /* PCA9635PW reponds to I2C subaddress 1 enable/disable */
|
||||
#define PCA9635PW_MODE_1_SUB2 (1<<2) /* PCA9635PW reponds to I2C subaddress 2 enable/disable */
|
||||
#define PCA9635PW_MODE_1_SUB3 (1<<1) /* PCA9635PW reponds to I2C subaddress 3 enable/disable */
|
||||
#define PCA9635PW_MODE_1_ALLCALL (1<<0) /* PCA9635PW reponds to led all call I2C address enable/disable */
|
||||
|
||||
/* PCA9635PW_MODE_2 bit definitions */
|
||||
|
||||
#define PCA9635PW_MODE_2_DMBLNK (1<<5) /* group control dimming/blinking */
|
||||
#define PCA9635PW_MODE_2_INVRT (1<<4) /* output logic state inverted/not inverted */
|
||||
#define PCA9635PW_MODE_2_OCH (1<<3) /* output change on stop command/on ACK */
|
||||
#define PCA9635PW_MODE_2_OUTDRV (1<<2) /* outputs are configured with an open-drain-structure/totem-pole-structure */
|
||||
#define PCA9635PW_MODE_2_OUTNE1 (1<<1) /* handling of outputs in dependency of !OE pin */
|
||||
#define PCA9635PW_MODE_2_OUTNE0 (1<<0) /* handling of outputs in dependency of !OE pin */
|
||||
|
||||
/* PCA9635PW_LED_OUT_x register value definitions */
|
||||
|
||||
#define PCA9635PW_LED_OUT_x_MODE_0 (0x00) /* all led drivers are turned off */
|
||||
#define PCA9635PW_LED_OUT_x_MODE_1 (0x55) /* all led drivers are fully turned on */
|
||||
#define PCA9635PW_LED_OUT_x_MODE_2 (0xAA) /* all led drivers individual brightness can be controlled by their individual pwm registers */
|
||||
#define PCA9635PW_LED_OUT_x_MODE_3 (0xFF) /* all led drivers individual brightness and group dimming/blinking can be controlled by their individual pwm registers and the GRPPWM register */
|
||||
|
||||
/* IOCTL commands */
|
||||
|
||||
#define PWMIOC_SETLED_BRIGHTNESS _PWMIOC(1) /* Arg: pca9635pw_setled_brightness_arg_s * pointer */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
enum led_select_e
|
||||
{
|
||||
LED_0 = PCA9635PW_LED_0,
|
||||
LED_1 = PCA9635PW_LED_1,
|
||||
LED_2 = PCA9635PW_LED_2,
|
||||
LED_3 = PCA9635PW_LED_3,
|
||||
LED_4 = PCA9635PW_LED_4,
|
||||
LED_5 = PCA9635PW_LED_5,
|
||||
LED_6 = PCA9635PW_LED_6,
|
||||
LED_7 = PCA9635PW_LED_7,
|
||||
LED_8 = PCA9635PW_LED_8,
|
||||
LED_9 = PCA9635PW_LED_9,
|
||||
LED_10 = PCA9635PW_LED_10,
|
||||
LED_11 = PCA9635PW_LED_11,
|
||||
LED_12 = PCA9635PW_LED_12,
|
||||
LED_13 = PCA9635PW_LED_13,
|
||||
LED_14 = PCA9635PW_LED_14,
|
||||
LED_15 = PCA9635PW_LED_15
|
||||
};
|
||||
|
||||
/* This structure is used in an IOCTL command for setting the PWM of an individual
|
||||
* LED. The desired LED is selected by setting the 'led' parameter accordingly
|
||||
* whereas the 'led_pwm' field governs the brightness of the selected LED. A value
|
||||
* of 0 (0x00) leads to a duty cycle of 0 % = LED off while a value of 255 (0xFF)
|
||||
* leads to a duty cycle of 99.6 % = Maximum brightness.
|
||||
*/
|
||||
|
||||
struct pca9635pw_setled_brightness_arg_s
|
||||
{
|
||||
enum led_select_e led;
|
||||
uint8_t brightness;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Forward declarations
|
||||
****************************************************************************/
|
||||
|
||||
struct i2c_dev_s;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pca9635pw_register
|
||||
*
|
||||
* Description:
|
||||
* Register the PCA9635PW device as 'devpath'
|
||||
*
|
||||
* Input Parameters:
|
||||
* devpath - The full path to the driver to register. E.g., "/dev/leddrv0".
|
||||
* i2c - An instance of the I2C interface to use to communicate
|
||||
* with the LM92.
|
||||
* pca9635pw_i2c_addr
|
||||
* - The I2C address of the PCA9635PW.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int pca9635pw_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c,
|
||||
uint8_t const pca9635pw_i2c_addr);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_I2C && CONFIG_I2C_PCA9635PW */
|
||||
#endif /* __INCLUDE_NUTTX_LEDS_PCA9635PW_H */
|
Loading…
Reference in a new issue