drivrs/ioexpander: Add support for a very simple GPIO drivers. It supports only pre-conrigured input and output pins and only basic input and output operations.

This commit is contained in:
Gregory Nutt
2016-06-24 09:43:49 -06:00
parent 8afe721612
commit ae19ca45e0
7 changed files with 475 additions and 24 deletions
+6
View File
@@ -83,6 +83,7 @@
#define _LOOPBASE (0x1e00) /* Loop device commands */
#define _MODEMBASE (0x1f00) /* Modem ioctl commands */
#define _I2CBASE (0x2000) /* I2C driver commands */
#define _GPIOBASE (0x2100) /* GPIO driver commands */
/* boardctl commands share the same number space */
@@ -381,6 +382,11 @@
#define _I2CIOCVALID(c) (_IOC_TYPE(c)==_I2CBASE)
#define _I2CIOC(nr) _IOC(_I2CBASE,nr)
/* GPIO driver command definitions ******************************************/
#define _GPIOCVALID(c) (_IOC_TYPE(c)==_GPIOBASE)
#define _GPIOC(nr) _IOC(_GPIOBASE,nr)
/* boardctl() command definitions *******************************************/
#define _BOARDIOCVALID(c) (_IOC_TYPE(c)==_BOARDBASE)
+132
View File
@@ -0,0 +1,132 @@
/********************************************************************************************
* include/nuttx/ioexpander/gpio.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_GPIO_H
#define __INCLUDE_NUTTX_IOEXPANDER_GPIO_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/fs/ioctl.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Command: GPIO_WRITE
* Description: Set the value of an output GPIO
* Argument: 0=output a low value; 1=outut a high value
*
* Command: GPIO_READ
* Description: Read the value of an input or output GPIO
* Argument: A pointer to an integer value to receive the result:
* 0=low value; 1=high value.
*/
#define GPIO_WRITE _GPIOC(1)
#define GPIO_READ _GPIOC(2)
/****************************************************************************
* Public Types
****************************************************************************/
/* Common interface definition. Must be cast-compatible with struct
* gpio_input_dev_s and struct gpio_output_dev_s
*/
struct gpio_common_dev_s
{
bool output;
uint8_t unused[3];
};
/* The interface to a GPIO input pin */
struct gpio_input_dev_s
{
bool output;
uint8_t unused[3];
CODE int (*gpin_read)(FAR struct gpio_input_dev_s *dev);
};
/* The interface to a GPIO input pin */
struct gpio_output_dev_s
{
bool output;
uint8_t unused[3];
CODE int (*gpout_read)(FAR struct gpio_output_dev_s *dev);
CODE int (*gpout_write)(FAR struct gpio_output_dev_s *dev, int value);
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Name: gpio_input_register
*
* Description:
* Register GPIO input pin device driver.
*
****************************************************************************/
int gpio_input_register(FAR struct gpio_input_dev_s *dev, int minor);
/****************************************************************************
* Name: gpio_output_register
*
* Description:
* Register GPIO output pin device driver.
*
****************************************************************************/
int gpio_output_register(FAR struct gpio_output_dev_s *dev, int minor);
#ifdef __cplusplus
}
#endif
#endif /* __INCLUDE_NUTTX_IOEXPANDER_GPIO_H */
+26 -14
View File
@@ -1,4 +1,4 @@
/********************************************************************************************
/****************************************************************************
* include/nuttx/ioexpander/pca9555.h
*
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
@@ -35,20 +35,31 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
********************************************************************************************/
****************************************************************************/
#ifndef __INCLUDE_NUTTX_IOEXPANDER_PCA9555_H
#define __INCLUDE_NUTTX_IOEXPANDER_PCA9555_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/i2c/i2c_master.h>
/* A reference to a structure of this type must be passed to the PCA9555 driver when the
* driver is instantiated. This structure provides information about the configuration of
* the PCA9555 and provides some board-specific hooks.
/****************************************************************************
* Public Types
****************************************************************************/
/* A reference to a structure of this type must be passed to the PCA9555
* driver when the driver is instantiated. This structure provides
* information about the configuration of the PCA9555 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.
* 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 pca9555_config_s
@@ -81,9 +92,9 @@ struct pca9555_config_s
#endif
};
/********************************************************************************************
/****************************************************************************
* Public Function Prototypes
********************************************************************************************/
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
@@ -93,11 +104,12 @@ extern "C"
#define EXTERN extern
#endif
/********************************************************************************************
/****************************************************************************
* Name: pca9555_initialize
*
* Description:
* Instantiate and configure the PCA9555 device driver to use the provided I2C device
* Instantiate and configure the PCA9555 device driver to use the provided
* I2C device
* instance.
*
* Input Parameters:
@@ -108,9 +120,9 @@ extern "C"
* Returned Value:
* an ioexpander_dev_s instance on success, NULL on failure.
*
********************************************************************************************/
****************************************************************************/
FAR struct ioexpander_dev_s* pca9555_initialize(FAR struct i2c_master_s *dev,
FAR struct ioexpander_dev_s *pca9555_initialize(FAR struct i2c_master_s *dev,
FAR struct pca9555_config_s *config);
#ifdef __cplusplus