Squashed commit of the following:

driver/ioexpander:  Add gpio_pin_unregister function to GPIO driver
  driver/ioexpander:  Add pinset struct to GPIO driver for interrupt pins larger than 64
  driver/ioexpander:  Initialize pintype/inttype when registering ioexpander device
  driver/ioexpander:  Add SETPINTYPE ioctl command to the GPIO driver
This commit is contained in:
zhuyanlin
2018-08-27 09:25:11 -06:00
committed by Gregory Nutt
parent b5f8c035a6
commit 459d9f2851
5 changed files with 185 additions and 13 deletions
+31
View File
@@ -75,6 +75,11 @@
* Command: GPIOC_UNREGISTER
* Description: Stop receiving signals for pin interrupts.
* Argument: None.
*
* Command: GPIOC_SETPINTYPE
* Description: Set the GPIO pin type.
* Argument: The enum gpio_pintype_e type.
*
*/
#define GPIOC_WRITE _GPIOC(1)
@@ -82,6 +87,7 @@
#define GPIOC_PINTYPE _GPIOC(3)
#define GPIOC_REGISTER _GPIOC(4)
#define GPIOC_UNREGISTER _GPIOC(5)
#define GPIOC_SETPINTYPE _GPIOC(6)
/****************************************************************************
* Public Types
@@ -94,6 +100,11 @@ enum gpio_pintype_e
GPIO_INPUT_PIN = 0,
GPIO_OUTPUT_PIN,
GPIO_INTERRUPT_PIN,
GPIO_INTERRUPT_HIGH_PIN,
GPIO_INTERRUPT_LOW_PIN,
GPIO_INTERRUPT_RISING_PIN,
GPIO_INTERRUPT_FALLING_PIN,
GPIO_INTERRUPT_BOTH_PIN,
GPIO_NPINTYPES
};
@@ -110,6 +121,7 @@ typedef CODE int (*pin_interrupt_t)(FAR struct gpio_dev_s *dev);
* for other pin types may be NULL.
* - go_attach and gp_eanble. Required only the GPIO_INTERRUPT_PIN pin
* type. Unused for other pin types may be NULL.
* - go_setpinytype. Required for all all pin types.
*/
struct gpio_dev_s;
@@ -122,6 +134,8 @@ struct gpio_operations_s
CODE int (*go_attach)(FAR struct gpio_dev_s *dev,
pin_interrupt_t callback);
CODE int (*go_enable)(FAR struct gpio_dev_s *dev, bool enable);
CODE int (*go_setpintype)(FAR struct gpio_dev_s *dev,
enum gpio_pintype_e pintype);
};
/* Pin interface definition. Must lie in writable memory. */
@@ -177,6 +191,23 @@ extern "C"
int gpio_pin_register(FAR struct gpio_dev_s *dev, int minor);
/****************************************************************************
* Name: gpio_pin_unregister
*
* Description:
* Unregister GPIO pin device driver.
*
* - Input pin types will be registered at /dev/gpinN
* - Output pin types will be registered at /dev/gpoutN
* - Interrupt pin types will be registered at /dev/gpintN
*
* Where N is the provided minor number in the range of 0-99.
*
*
****************************************************************************/
void gpio_pin_unregister(FAR struct gpio_dev_s *dev, int minor);
/****************************************************************************
* Name: gpio_lower_half
*
+11 -8
View File
@@ -1,7 +1,7 @@
/****************************************************************************
* include/nuttx/ioexpander/ioexpander.h
*
* Copyright (C) 2015-2016 Gregory Nutt. All rights reserved.
* Copyright (C) 2015-2016, 2018 Gregory Nutt. All rights reserved.
* Author: Sebastien Lorquet <sebastien@lorquet.fr>
*
* Redistribution and use in source and binary forms, with or without
@@ -41,6 +41,7 @@
****************************************************************************/
#include <nuttx/config.h>
#include <stdbool.h>
#include <stdint.h>
#ifdef CONFIG_IOEXPANDER
@@ -55,10 +56,6 @@
# define CONFIG_IOEXPANDER_NPINS 16
#endif
#if CONFIG_IOEXPANDER_NPINS > 64
# error No support for devices with more than 64 pins
#endif
/* Pin definitions **********************************************************/
#define IOEXPANDER_DIRECTION_IN 0
@@ -101,7 +98,7 @@
*
****************************************************************************/
#define IOEXP_SETDIRECTION(dev,pin,dir) ((dev)->ops->ioe_direction(dev,pin,dir))
#define IOEXP_SETDIRECTION(dev,pin,dir) ((dev)->ops->ioe_direction(dev,pin,dir))
/****************************************************************************
* Name: IOEXP_SETOPTION
@@ -293,7 +290,11 @@
* Public Types
****************************************************************************/
/* This type represents a bitmap of pins */
/* This type represents a bitmap of pins
*
* For IOE NPINS greater than 64, ioe_pinset_t represent one interrupt pin
* number instead of a bitmap of pins.
*/
#if CONFIG_IOEXPANDER_NPINS <= 8
typedef uint8_t ioe_pinset_t;
@@ -301,8 +302,10 @@ typedef uint8_t ioe_pinset_t;
typedef uint16_t ioe_pinset_t;
#elif CONFIG_IOEXPANDER_NPINS <= 32
typedef uint32_t ioe_pinset_t;
#else /* if CONFIG_IOEXPANDER_NPINS <= 64 */
#elif CONFIG_IOEXPANDER_NPINS <= 64
typedef uint64_t ioe_pinset_t;
#else
typedef uint8_t ioe_pinset_t;
#endif
#ifdef CONFIG_IOEXPANDER_INT_ENABLE