2021-03-04 08:02:21 +01:00
|
|
|
/****************************************************************************
|
2015-12-15 15:40:34 +01:00
|
|
|
* drivers/ioexpander/pca9555.h
|
2015-07-09 15:31:22 +02:00
|
|
|
*
|
2021-03-20 11:10:04 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2015-07-09 15:31:22 +02:00
|
|
|
*
|
2021-03-20 11:10:04 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2015-07-09 15:31:22 +02:00
|
|
|
*
|
2021-03-20 11:10:04 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2015-07-09 15:31:22 +02:00
|
|
|
*
|
2021-03-04 08:02:21 +01:00
|
|
|
****************************************************************************/
|
2021-03-20 11:10:04 +01:00
|
|
|
|
|
|
|
/* References:
|
|
|
|
* "16-bit I2C-bus and SMBus I/O port with interrupt product datasheet",
|
|
|
|
* Rev. 08 - 22 October 2009, NXP
|
|
|
|
*/
|
2015-07-09 15:31:22 +02:00
|
|
|
|
2015-12-15 15:40:34 +01:00
|
|
|
#ifndef __DRIVERS_IOEXPANDER_PCA9555_H
|
|
|
|
#define __DRIVERS_IOEXPANDER_PCA9555_H
|
2015-07-09 15:31:22 +02:00
|
|
|
|
2021-03-04 08:02:21 +01:00
|
|
|
/****************************************************************************
|
2015-07-09 15:31:22 +02:00
|
|
|
* Included Files
|
2021-03-04 08:02:21 +01:00
|
|
|
****************************************************************************/
|
2015-07-09 15:31:22 +02:00
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <nuttx/wdog.h>
|
|
|
|
#include <nuttx/clock.h>
|
2022-09-06 08:18:45 +02:00
|
|
|
#include <nuttx/mutex.h>
|
2016-07-31 19:09:02 +02:00
|
|
|
#include <nuttx/wqueue.h>
|
2015-12-15 15:40:34 +01:00
|
|
|
#include <nuttx/ioexpander/ioexpander.h>
|
|
|
|
#include <nuttx/ioexpander/pca9555.h>
|
2015-07-09 15:31:22 +02:00
|
|
|
|
2016-01-30 15:00:16 +01:00
|
|
|
#include <nuttx/i2c/i2c_master.h>
|
2015-07-09 15:31:22 +02:00
|
|
|
#include <nuttx/irq.h>
|
|
|
|
|
|
|
|
#if defined(CONFIG_IOEXPANDER) && defined(CONFIG_IOEXPANDER_PCA9555)
|
|
|
|
|
2021-03-04 08:02:21 +01:00
|
|
|
/****************************************************************************
|
2015-07-09 15:31:22 +02:00
|
|
|
* Pre-processor Definitions
|
2021-03-04 08:02:21 +01:00
|
|
|
****************************************************************************/
|
2016-06-27 16:11:54 +02:00
|
|
|
|
2021-03-04 07:10:42 +01:00
|
|
|
/* Configuration ************************************************************/
|
|
|
|
|
2015-07-09 15:31:22 +02:00
|
|
|
/* Prerequisites:
|
|
|
|
* CONFIG_I2C
|
|
|
|
* I2C support is required
|
|
|
|
* CONFIG_IOEXPANDER
|
|
|
|
* Enables support for the PCA9555 I/O expander
|
|
|
|
*
|
|
|
|
* CONFIG_IOEXPANDER_PCA9555
|
|
|
|
* Enables support for the PCA9555 driver (Needs CONFIG_INPUT)
|
|
|
|
* CONFIG_PCA9555_MULTIPLE
|
|
|
|
* Can be defined to support multiple PCA9555 devices on board.
|
2016-07-31 19:09:02 +02:00
|
|
|
* CONFIG_PCA9555_INT_NCALLBACKS
|
|
|
|
* Maximum number of supported pin interrupt callbacks.
|
2015-07-09 15:31:22 +02:00
|
|
|
*/
|
|
|
|
|
2016-07-31 19:09:02 +02:00
|
|
|
#ifdef CONFIG_IOEXPANDER_INT_ENABLE
|
|
|
|
# ifndef CONFIG_PCA9555_INT_NCALLBACKS
|
|
|
|
# define CONFIG_PCA9555_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
|
|
|
|
|
2015-07-09 15:31:22 +02:00
|
|
|
#undef CONFIG_PCA9555_REFCNT
|
|
|
|
|
2021-03-04 07:10:42 +01:00
|
|
|
/* Driver support ***********************************************************/
|
|
|
|
|
|
|
|
/* This format is used to construct the /dev/input[n] device driver path.
|
|
|
|
* It defined here
|
2015-07-09 15:31:22 +02:00
|
|
|
* so that it will be used consistently in all places.
|
|
|
|
*/
|
|
|
|
|
2021-03-04 07:10:42 +01:00
|
|
|
/* PCA9555 Resources ********************************************************/
|
2015-07-09 15:31:22 +02:00
|
|
|
|
|
|
|
#define PCA9555_GPIO_NPINS 16 /* All pins can be used as GPIOs */
|
|
|
|
|
|
|
|
#ifndef CONFIG_I2C
|
|
|
|
#error "CONFIG_I2C is required by PCA9555"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define PCA9555_MAXDEVS 8
|
|
|
|
|
|
|
|
/* I2C frequency */
|
|
|
|
|
|
|
|
#define PCA9555_I2C_MAXFREQUENCY 400000 /* 400KHz */
|
|
|
|
|
2021-03-04 07:10:42 +01:00
|
|
|
/* PCA9555 Registers ********************************************************/
|
|
|
|
|
2015-07-09 15:31:22 +02:00
|
|
|
/* Register Addresses */
|
|
|
|
|
|
|
|
#define PCA9555_REG_INPUT 0x00
|
|
|
|
#define PCA9555_REG_OUTPUT 0x02
|
|
|
|
#define PCA9555_REG_POLINV 0x04
|
|
|
|
#define PCA9555_REG_CONFIG 0x06
|
|
|
|
|
2021-03-04 08:02:21 +01:00
|
|
|
/****************************************************************************
|
2015-07-09 15:31:22 +02:00
|
|
|
* Public Types
|
2021-03-04 08:02:21 +01:00
|
|
|
****************************************************************************/
|
2015-07-09 15:31:22 +02:00
|
|
|
|
2016-07-31 19:09:02 +02:00
|
|
|
#ifdef CONFIG_IOEXPANDER_INT_ENABLE
|
|
|
|
/* This type represents on registered pin interrupt callback */
|
|
|
|
|
|
|
|
struct pca9555_callback_s
|
|
|
|
{
|
2021-03-04 08:02:21 +01:00
|
|
|
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 */
|
2016-07-31 19:09:02 +02:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2015-07-09 15:31:22 +02:00
|
|
|
/* This structure represents the state of the PCA9555 driver */
|
|
|
|
|
|
|
|
struct pca9555_dev_s
|
|
|
|
{
|
2022-09-06 08:18:45 +02:00
|
|
|
struct ioexpander_dev_s dev; /* Nested structure to allow casting as public gpio
|
|
|
|
* expander. */
|
2016-08-01 19:10:11 +02:00
|
|
|
#ifdef CONFIG_PCA9555_SHADOW_MODE
|
2022-09-06 08:18:45 +02:00
|
|
|
uint8_t sreg[8]; /* Shadowed registers of the PCA9555 */
|
2016-06-27 16:11:54 +02:00
|
|
|
#endif
|
2015-07-09 15:31:22 +02:00
|
|
|
#ifdef CONFIG_PCA9555_MULTIPLE
|
2022-09-06 08:18:45 +02:00
|
|
|
FAR struct pca9555_dev_s *flink; /* Supports a singly linked list of drivers */
|
2015-07-09 15:31:22 +02:00
|
|
|
#endif
|
2022-09-06 08:18:45 +02:00
|
|
|
FAR struct pca9555_config_s *config; /* Board configuration data */
|
|
|
|
FAR struct i2c_master_s *i2c; /* Saved I2C driver instance */
|
|
|
|
mutex_t lock; /* Mutual exclusion */
|
2016-07-31 19:09:02 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_IOEXPANDER_INT_ENABLE
|
2022-09-06 08:18:45 +02:00
|
|
|
struct work_s work; /* Supports the interrupt handling "bottom half" */
|
2016-07-31 19:09:02 +02:00
|
|
|
|
|
|
|
/* Saved callback information for each I/O expander client */
|
|
|
|
|
|
|
|
struct pca9555_callback_s cb[CONFIG_PCA9555_INT_NCALLBACKS];
|
|
|
|
#endif
|
2015-07-09 15:31:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* CONFIG_IOEXPANDER && CONFIG_IOEXPANDER_PCA9555 */
|
2015-12-15 15:40:34 +01:00
|
|
|
#endif /* __DRIVERS_IOEXPANDER_PCA9555_H */
|