Ooops.. forgot to add files before last commit

This commit is contained in:
Gregory Nutt 2016-08-01 11:15:29 -06:00
parent d47aa75669
commit d0f6a23a32
5 changed files with 1422 additions and 0 deletions

View File

@ -309,6 +309,8 @@ static int gplh_enable(FAR struct gpio_dev_s *gpio, bool enable)
*
* Description:
* Create a GPIO pin device driver instance for an I/O expander pin.
* The I/O expander pin must have already been configured by the caller
* for the particular pintype.
*
* Input Parameters:
* ioe - An instance of the I/O expander interface

1132
drivers/ioexpander/pcf8574.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,172 @@
/********************************************************************************************
* drivers/ioexpander/pcf8574.h
*
* Copyright (C) 2016 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.
*
********************************************************************************************/
#ifndef __DRIVERS_IOEXPANDER_PCF8574_H
#define __DRIVERS_IOEXPANDER_PCF8574_H
/********************************************************************************************
* Included Files
********************************************************************************************/
#include <nuttx/config.h>
#include <semaphore.h>
#include <nuttx/wdog.h>
#include <nuttx/clock.h>
#include <nuttx/wqueue.h>
#include <nuttx/ioexpander/ioexpander.h>
#include <nuttx/ioexpander/pcf8574.h>
#include <nuttx/i2c/i2c_master.h>
#include <nuttx/irq.h>
#if defined(CONFIG_IOEXPANDER) && defined(CONFIG_IOEXPANDER_PCF8574)
/********************************************************************************************
* Pre-processor Definitions
********************************************************************************************/
/* Configuration ****************************************************************************/
/* Prerequisites:
* CONFIG_I2C
* I2C support is required
* CONFIG_IOEXPANDER
* Enables I/O expander support
*
* Other settings that effect the driver: CONFIG_DISABLE_POLL
*
* CONFIG_IOEXPANDER_PCF8574
* Enables support for the PCF8574 driver (Needs CONFIG_INPUT)
* CONFIG_PCF8574_MULTIPLE
* Can be defined to support multiple PCF8574 devices on board.
* CONFIG_PCF8574_INT_NCALLBACKS
* Maximum number of supported pin interrupt callbacks.
* CONFIG_PCF8574_INT_POLL
* Enables a poll for missed interrupts
* CONFIG_PCF8574_INT_POLLDELAY
* If CONFIG_PCF8574_INT_POLL=y, then this is the delay in microseconds
* between polls for missed interrupts.
*/
#ifndef CONFIG_I2C
# error "CONFIG_I2C is required by PCF8574"
#endif
#ifdef CONFIG_IOEXPANDER_INT_ENABLE
# ifndef CONFIG_PCF8574_INT_NCALLBACKS
# define CONFIG_PCF8574_INT_NCALLBACKS 4
# endif
#endif
#ifdef CONFIG_IOEXPANDER_INT_ENABLE
# ifndef CONFIG_SCHED_WORKQUEUE
# error Work queue support required. CONFIG_SCHED_WORKQUEUE must be selected.
# endif
#endif
#ifndef CONFIG_PCF8574_INT_POLLDELAY
# define CONFIG_PCF8574_INT_POLLDELAY 500000
#endif
/* PCF8574 Definitions **********************************************************************/
#define PCF8574_I2C_MAXFREQUENCY 400000 /* 400KHz */
#define PCF8574_POLLDELAY (CONFIG_PCF8574_INT_POLLDELAY / USEC_PER_TICK)
#define PCF8574_LEVEL_SENSITIVE(d,p) \
(((d)->trigger & ((ioe_pinset_t)1 << (p))) == 0)
#define PCF8574_LEVEL_HIGH(d,p) \
(((d)->level[0] & ((ioe_pinset_t)1 << (p))) != 0)
#define PCF8574_LEVEL_LOW(d,p) \
(((d)->level[1] & ((ioe_pinset_t)1 << (p))) != 0)
#define PCF8574_EDGE_SENSITIVE(d,p) \
(((d)->trigger & ((ioe_pinset_t)1 << (p))) != 0)
#define PCF8574_EDGE_RISING(d,p) \
(((d)->level[0] & ((ioe_pinset_t)1 << (p))) != 0)
#define PCF8574_EDGE_FALLING(d,p) \
(((d)->level[1] & ((ioe_pinset_t)1 << (p))) != 0)
#define PCF8574_EDGE_BOTH(d,p) \
(PCF8574_LEVEL_RISING(d,p) && PCF8574_LEVEL_FALLING(d,p))
/********************************************************************************************
* Public Types
********************************************************************************************/
#ifdef CONFIG_IOEXPANDER_INT_ENABLE
/* This type represents on registered pin interrupt callback */
struct pcf8574_callback_s
{
ioe_pinset_t pinset; /* Set of pin interrupts that will generate
* the callback. */
ioe_callback_t cbfunc; /* The saved callback function pointer */
FAR void *cbarg; /* Callback argument */
};
#endif
/* This structure represents the state of the PCF8574 driver */
struct pcf8574_dev_s
{
struct ioexpander_dev_s dev; /* Nested structure to allow casting as public gpio
* expander. */
FAR struct pcf8574_config_s *config; /* Board configuration data */
FAR struct i2c_master_s *i2c; /* Saved I2C driver instance */
sem_t exclsem; /* Mutual exclusion */
uint8_t inpins; /* Set of input pins */
uint8_t outstate; /* State of all output pins */
#ifdef CONFIG_IOEXPANDER_INT_ENABLE
#ifdef CONFIG_PCF8574_INT_POLL
WDOG_ID wdog; /* Timer used to poll for missed interrupts */
#endif
uint8_t input; /* Last input registeres */
uint8_t intstat; /* Pending interrupts */
uint8_t trigger; /* Bit encoded: 0=level 1=edge */
uint8_t level[2]; /* Bit encoded: 01=high/rising, 10 low/falling, 11 both */
struct work_s work; /* Supports the interrupt handling "bottom half" */
/* Saved callback information for each I/O expander client */
struct pcf8574_callback_s cb[CONFIG_PCF8574_INT_NCALLBACKS];
#endif
};
#endif /* CONFIG_IOEXPANDER && CONFIG_IOEXPANDER_PCF8574 */
#endif /* __DRIVERS_IOEXPANDER_PCF8574_H */

View File

@ -171,6 +171,8 @@ int gpio_pin_register(FAR struct gpio_dev_s *dev, int minor);
*
* Description:
* Create a GPIO pin device driver instance for an I/O expander pin.
* The I/O expander pin must have already been configured by the caller
* for the particular pintype.
*
* Input Parameters:
* ioe - An instance of the I/O expander interface

View File

@ -0,0 +1,114 @@
/****************************************************************************
* include/nuttx/ioexpander/pcf8574.h
*
* Copyright (C) 2016 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.
*
********************************************************************************************/
#ifndef __INCLUDE_NUTTX_IOEXPANDER_PCF8574_H
#define __INCLUDE_NUTTX_IOEXPANDER_PCF8574_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
/****************************************************************************
* Public Types
****************************************************************************/
#ifdef CONFIG_PCF8574_INT_ENABLE
/* This is the type of the PCF8574xx interrupt handler */
typedef CODE void (*pcf8574_handler_t)(FAR void *arg);
#endif
/* A reference to a structure of this type must be passed to the PCF8574xx
* driver when the driver is instantiated. This structure provides
* information about the configuration of the PCF8574xx and provides some
* board-specific hooks.
*
* Memory for this structure is provided by the caller. It is not copied by
* the driver and is presumed to persist while the driver is active. The
* memory must be writeable because, under certain circumstances, the driver
* may modify the frequency.
*/
struct pcf8574_config_s
{
/* Device characterization */
uint8_t address; /* 7-bit I2C address (only bits 0-6 used) */
uint32_t frequency; /* I2C frequency */
#ifdef CONFIG_PCF8574_INT_ENABLE
/* IRQ/GPIO access callbacks. These operations all hidden behind
* callbacks to isolate the PCF8574xx driver from differences in GPIO
* interrupt handling by varying boards and MCUs.
*
* attach - Attach the PCF8574xx interrupt handler to the GPIO interrupt
* enable - Enable or disable the GPIO interrupt
*/
CODE int (*attach)(FAR struct pcf8574_config_s *state,
pcf8574_handler_t handler, FAR void *arg);
CODE void (*enable)(FAR struct pcf8574_config_s *state, bool enable);
#endif
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: pcf8574_initialize
*
* Description:
* Instantiate and configure the PCF8574xx device driver to use the provided
* I2C device instance.
*
* Input Parameters:
* i2c - An I2C driver instance
* minor - The device i2c address
* config - Persistent board configuration data
*
* Returned Value:
* an ioexpander_dev_s instance on success, NULL on failure.
*
****************************************************************************/
struct i2c_master_s;
FAR struct ioexpander_dev_s *pcf8574_initialize(FAR struct i2c_master_s *i2c,
FAR struct pcf8574_config_s *config);
#endif