Update I/O Expander skeleton.c file

This commit is contained in:
Gregory Nutt
2016-07-31 15:43:36 -06:00
parent 99843fe5fe
commit c6d65b0943
2 changed files with 180 additions and 19 deletions
+83 -9
View File
@@ -319,7 +319,15 @@ static int pca9555_getbit(FAR struct pca9555_dev_s *pca, uint8_t addr,
* Name: pca9555_direction * Name: pca9555_direction
* *
* Description: * Description:
* See include/nuttx/ioexpander/ioexpander.h * Set the direction of an ioexpander pin. Required.
*
* Input Parameters:
* dev - Device-specific state data
* pin - The index of the pin to alter in this call
* dir - One of the IOEXPANDER_DIRECTION_ macros
*
* Returned Value:
* 0 on success, else a negative error code
* *
****************************************************************************/ ****************************************************************************/
@@ -342,7 +350,18 @@ static int pca9555_direction(FAR struct ioexpander_dev_s *dev, uint8_t pin,
* Name: pca9555_option * Name: pca9555_option
* *
* Description: * Description:
* See include/nuttx/ioexpander/ioexpander.h * Set pin options. Required.
* Since all IO expanders have various pin options, this API allows setting
* pin options in a flexible way.
*
* Input Parameters:
* dev - Device-specific state data
* pin - The index of the pin to alter in this call
* opt - One of the IOEXPANDER_OPTION_ macros
* val - The option's value
*
* Returned Value:
* 0 on success, else a negative error code
* *
****************************************************************************/ ****************************************************************************/
@@ -350,7 +369,7 @@ static int pca9555_option(FAR struct ioexpander_dev_s *dev, uint8_t pin,
int opt, FAR void *val) int opt, FAR void *val)
{ {
FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)dev; FAR struct pca9555_dev_s *pca = (FAR struct pca9555_dev_s *)dev;
int ival = (int)val; int ival = (int)((intptr_t)val);
int ret = -EINVAL; int ret = -EINVAL;
if (opt == IOEXPANDER_OPTION_INVERT) if (opt == IOEXPANDER_OPTION_INVERT)
@@ -369,7 +388,16 @@ static int pca9555_option(FAR struct ioexpander_dev_s *dev, uint8_t pin,
* Name: pca9555_writepin * Name: pca9555_writepin
* *
* Description: * Description:
* See include/nuttx/ioexpander/ioexpander.h * Set the pin level. Required.
*
* Input Parameters:
* dev - Device-specific state data
* pin - The index of the pin to alter in this call
* val - The pin level. Usually TRUE will set the pin high,
* except if OPTION_INVERT has been set on this pin.
*
* Returned Value:
* 0 on success, else a negative error code
* *
****************************************************************************/ ****************************************************************************/
@@ -391,7 +419,17 @@ static int pca9555_writepin(FAR struct ioexpander_dev_s *dev, uint8_t pin,
* Name: pca9555_readpin * Name: pca9555_readpin
* *
* Description: * Description:
* See include/nuttx/ioexpander/ioexpander.h * Read the actual PIN level. This can be different from the last value written
* to this pin. Required.
*
* Input Parameters:
* dev - Device-specific state data
* pin - The index of the pin
* valptr - Pointer to a buffer where the pin level is stored. Usually TRUE
* if the pin is high, except if OPTION_INVERT has been set on this pin.
*
* Returned Value:
* 0 on success, else a negative error code
* *
****************************************************************************/ ****************************************************************************/
@@ -413,7 +451,16 @@ static int pca9555_readpin(FAR struct ioexpander_dev_s *dev, uint8_t pin,
* Name: pca9555_readbuf * Name: pca9555_readbuf
* *
* Description: * Description:
* See include/nuttx/ioexpander/ioexpander.h * Read the buffered pin level.
* This can be different from the actual pin state. Required.
*
* Input Parameters:
* dev - Device-specific state data
* pin - The index of the pin
* valptr - Pointer to a buffer where the level is stored.
*
* Returned Value:
* 0 on success, else a negative error code
* *
****************************************************************************/ ****************************************************************************/
@@ -490,7 +537,16 @@ static int pca9555_getmultibits(FAR struct pca9555_dev_s *pca, uint8_t addr,
* Name: pca9555_multiwritepin * Name: pca9555_multiwritepin
* *
* Description: * Description:
* See include/nuttx/ioexpander/ioexpander.h * Set the pin level for multiple pins. This routine may be faster than
* individual pin accesses. Optional.
*
* Input Parameters:
* dev - Device-specific state data
* pins - The list of pin indexes to alter in this call
* val - The list of pin levels.
*
* Returned Value:
* 0 on success, else a negative error code
* *
****************************************************************************/ ****************************************************************************/
@@ -574,7 +630,16 @@ static int pca9555_multiwritepin(FAR struct ioexpander_dev_s *dev,
* Name: pca9555_multireadpin * Name: pca9555_multireadpin
* *
* Description: * Description:
* See include/nuttx/ioexpander/ioexpander.h * Read the actual level for multiple pins. This routine may be faster than
* individual pin accesses. Optional.
*
* Input Parameters:
* dev - Device-specific state data
* pin - The list of pin indexes to read
* valptr - Pointer to a buffer where the pin levels are stored.
*
* Returned Value:
* 0 on success, else a negative error code
* *
****************************************************************************/ ****************************************************************************/
@@ -598,7 +663,16 @@ static int pca9555_multireadpin(FAR struct ioexpander_dev_s *dev,
* Name: pca9555_multireadbuf * Name: pca9555_multireadbuf
* *
* Description: * Description:
* See include/nuttx/ioexpander/ioexpander.h * Read the buffered level of multiple pins. This routine may be faster than
* individual pin accesses. Optional.
*
* Input Parameters:
* dev - Device-specific state data
* pin - The index of the pin
* valptr - Pointer to a buffer where the buffered levels are stored.
*
* Returned Value:
* 0 on success, else a negative error code
* *
****************************************************************************/ ****************************************************************************/
+97 -10
View File
@@ -182,7 +182,15 @@ static void skel_lock(FAR struct skel_dev_s *priv)
* Name: skel_direction * Name: skel_direction
* *
* Description: * Description:
* See include/nuttx/ioexpander/ioexpander.h * Set the direction of an ioexpander pin. Required.
*
* Input Parameters:
* dev - Device-specific state data
* pin - The index of the pin to alter in this call
* dir - One of the IOEXPANDER_DIRECTION_ macros
*
* Returned Value:
* 0 on success, else a negative error code
* *
****************************************************************************/ ****************************************************************************/
@@ -214,7 +222,18 @@ static int skel_direction(FAR struct ioexpander_dev_s *dev, uint8_t pin,
* Name: skel_option * Name: skel_option
* *
* Description: * Description:
* See include/nuttx/ioexpander/ioexpander.h * Set pin options. Required.
* Since all IO expanders have various pin options, this API allows setting
* pin options in a flexible way.
*
* Input Parameters:
* dev - Device-specific state data
* pin - The index of the pin to alter in this call
* opt - One of the IOEXPANDER_OPTION_ macros
* val - The option's value
*
* Returned Value:
* 0 on success, else a negative error code
* *
****************************************************************************/ ****************************************************************************/
@@ -222,8 +241,13 @@ static int skel_option(FAR struct ioexpander_dev_s *dev, uint8_t pin,
int opt, FAR void *val) int opt, FAR void *val)
{ {
FAR struct skel_dev_s *priv = (FAR struct skel_dev_s *)dev; FAR struct skel_dev_s *priv = (FAR struct skel_dev_s *)dev;
int ival = (int)((intptr_t)val); int ret = -ENOSYS;
int ret = -EINVAL;
gpioinfo("addr=%02x pin=%u option=%u\n", priv->addr, pin, opt);
DEBUGASSERT(priv != NULL);
/* Check for pin polarity inversion. */
if (opt == IOEXPANDER_OPTION_INVERT) if (opt == IOEXPANDER_OPTION_INVERT)
{ {
@@ -244,7 +268,16 @@ static int skel_option(FAR struct ioexpander_dev_s *dev, uint8_t pin,
* Name: skel_writepin * Name: skel_writepin
* *
* Description: * Description:
* See include/nuttx/ioexpander/ioexpander.h * Set the pin level. Required.
*
* Input Parameters:
* dev - Device-specific state data
* pin - The index of the pin to alter in this call
* val - The pin level. Usually TRUE will set the pin high,
* except if OPTION_INVERT has been set on this pin.
*
* Returned Value:
* 0 on success, else a negative error code
* *
****************************************************************************/ ****************************************************************************/
@@ -273,7 +306,17 @@ static int skel_writepin(FAR struct ioexpander_dev_s *dev, uint8_t pin,
* Name: skel_readpin * Name: skel_readpin
* *
* Description: * Description:
* See include/nuttx/ioexpander/ioexpander.h * Read the actual PIN level. This can be different from the last value written
* to this pin. Required.
*
* Input Parameters:
* dev - Device-specific state data
* pin - The index of the pin
* valptr - Pointer to a buffer where the pin level is stored. Usually TRUE
* if the pin is high, except if OPTION_INVERT has been set on this pin.
*
* Returned Value:
* 0 on success, else a negative error code
* *
****************************************************************************/ ****************************************************************************/
@@ -302,7 +345,16 @@ static int skel_readpin(FAR struct ioexpander_dev_s *dev, uint8_t pin,
* Name: skel_readbuf * Name: skel_readbuf
* *
* Description: * Description:
* See include/nuttx/ioexpander/ioexpander.h * Read the buffered pin level.
* This can be different from the actual pin state. Required.
*
* Input Parameters:
* dev - Device-specific state data
* pin - The index of the pin
* valptr - Pointer to a buffer where the level is stored.
*
* Returned Value:
* 0 on success, else a negative error code
* *
****************************************************************************/ ****************************************************************************/
@@ -364,7 +416,16 @@ static int skel_getmultibits(FAR struct skel_dev_s *priv, FAR uint8_t *pins,
* Name: skel_multiwritepin * Name: skel_multiwritepin
* *
* Description: * Description:
* See include/nuttx/ioexpander/ioexpander.h * Set the pin level for multiple pins. This routine may be faster than
* individual pin accesses. Optional.
*
* Input Parameters:
* dev - Device-specific state data
* pins - The list of pin indexes to alter in this call
* val - The list of pin levels.
*
* Returned Value:
* 0 on success, else a negative error code
* *
****************************************************************************/ ****************************************************************************/
@@ -419,7 +480,16 @@ static int skel_multiwritepin(FAR struct ioexpander_dev_s *dev,
* Name: skel_multireadpin * Name: skel_multireadpin
* *
* Description: * Description:
* See include/nuttx/ioexpander/ioexpander.h * Read the actual level for multiple pins. This routine may be faster than
* individual pin accesses. Optional.
*
* Input Parameters:
* dev - Device-specific state data
* pin - The list of pin indexes to read
* valptr - Pointer to a buffer where the pin levels are stored.
*
* Returned Value:
* 0 on success, else a negative error code
* *
****************************************************************************/ ****************************************************************************/
@@ -431,6 +501,10 @@ static int skel_multireadpin(FAR struct ioexpander_dev_s *dev,
FAR struct skel_dev_s *priv = (FAR struct skel_dev_s *)dev; FAR struct skel_dev_s *priv = (FAR struct skel_dev_s *)dev;
int ret; int ret;
gpioinfo("count=%u\n", count);
DEBUGASSERT(priv != NULL && pins != NULL && values != NULL && count > 0);
/* Get exclusive access to the I/O Expander */ /* Get exclusive access to the I/O Expander */
skel_lock(priv); skel_lock(priv);
@@ -444,7 +518,16 @@ static int skel_multireadpin(FAR struct ioexpander_dev_s *dev,
* Name: skel_multireadbuf * Name: skel_multireadbuf
* *
* Description: * Description:
* See include/nuttx/ioexpander/ioexpander.h * Read the buffered level of multiple pins. This routine may be faster than
* individual pin accesses. Optional.
*
* Input Parameters:
* dev - Device-specific state data
* pin - The index of the pin
* valptr - Pointer to a buffer where the buffered levels are stored.
*
* Returned Value:
* 0 on success, else a negative error code
* *
****************************************************************************/ ****************************************************************************/
@@ -456,6 +539,10 @@ static int skel_multireadbuf(FAR struct ioexpander_dev_s *dev,
FAR struct skel_dev_s *priv = (FAR struct skel_dev_s *)dev; FAR struct skel_dev_s *priv = (FAR struct skel_dev_s *)dev;
int ret; int ret;
gpioinfo("count=%u\n", count);
DEBUGASSERT(priv != NULL && pins != NULL && values != NULL && count > 0);
/* Get exclusive access to the I/O Expander */ /* Get exclusive access to the I/O Expander */
skel_lock(priv); skel_lock(priv);