drivers/ioexpander: Add support for PCA9557

Datasheet: https://www.ti.com/lit/ds/symlink/pca9557.pdf

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
This commit is contained in:
wangjianyu3
2025-03-24 19:48:47 +08:00
committed by Alan C. Assis
parent 5c2cfe8bac
commit b73d7f2922
5 changed files with 884 additions and 0 deletions
+31
View File
@@ -312,6 +312,37 @@ config PCA9538_RETRY
endif # IOEXPANDER_PCA9538
config IOEXPANDER_PCA9557
bool "PCA9557 I2C IO expander"
default n
depends on I2C
---help---
Enable support for the NXP PCA9557 IO Expander
if IOEXPANDER_PCA9557
config PCA9557_SHADOW_MODE
bool "Use Shadow Mode instead of Read-Modify-Write Operations"
default n
---help---
This setting enables a mode where the output and pin
configuration registers are held in RAM.
With this for example we do not need to read back the
output-register every time we want to change one pin.
We do instead change the bit in the internal register
and then just write this register to the IO-Expander.
This reduces bus traffic and eliminates the problem of
EMC-caused toggling of output pins.
config PCA9557_RETRY
bool "Retry to send commands and data at I2C communication errors"
default n
---help---
Retry to send commands and data if a I2C-communication
error occurs (eg. caused by EMC).
endif # IOEXPANDER_PCA9557
config IOEXPANDER_TCA64XX
bool "TCA64XX I2C IO expander"
default n
+4
View File
@@ -54,6 +54,10 @@ ifeq ($(CONFIG_IOEXPANDER_PCA9538),y)
CSRCS += pca9538.c
endif
ifeq ($(CONFIG_IOEXPANDER_PCA9557),y)
CSRCS += pca9557.c
endif
ifeq ($(CONFIG_IOEXPANDER_TCA64XX),y)
CSRCS += tca64xx.c
endif
File diff suppressed because it is too large Load Diff
+96
View File
@@ -0,0 +1,96 @@
/****************************************************************************
* drivers/ioexpander/pca9557.h
*
* SPDX-License-Identifier: Apache-2.0
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*
****************************************************************************/
#ifndef __DRIVERS_IOEXPANDER_PCA9557_H
#define __DRIVERS_IOEXPANDER_PCA9557_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/wdog.h>
#include <nuttx/clock.h>
#include <nuttx/mutex.h>
#include <nuttx/wqueue.h>
#include <nuttx/ioexpander/ioexpander.h>
#include <nuttx/ioexpander/pca9557.h>
#include <nuttx/i2c/i2c_master.h>
#include <nuttx/irq.h>
#if defined(CONFIG_IOEXPANDER) && defined(CONFIG_IOEXPANDER_PCA9557)
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
/* Prerequisites:
* CONFIG_I2C
* I2C support is required
* CONFIG_IOEXPANDER
* Enables support for the PCA9557 I/O expander
*
* CONFIG_IOEXPANDER_PCA9557
* Enables support for the PCA9557 driver (Needs CONFIG_INPUT)
*/
/* PCA9557 Resources ********************************************************/
#define PCA9557_GPIO_NPINS 8
#define PCA9557_MAXDEVS 8
/* I2C frequency */
#define PCA9557_I2C_MAXFREQUENCY 400000 /* 400KHz */
/* PCA9557 Registers ********************************************************/
#define PCA9557_REG_NUM 4
#define PCA9557_REG_INPUT 0x00
#define PCA9557_REG_OUTPUT 0x01
#define PCA9557_REG_POLINV 0x02
#define PCA9557_REG_CONFIG 0x03
/****************************************************************************
* Public Types
****************************************************************************/
/* This structure represents the state of the PCA9557 driver */
struct pca9557_dev_s
{
struct ioexpander_dev_s dev; /* Nested structure to allow casting
* as public gpio expander. */
#ifdef CONFIG_PCA9557_SHADOW_MODE
uint8_t sreg[PCA9557_REG_NUM]; /* Shadowed registers */
#endif
FAR struct pca9557_config_s *config; /* Board configuration data */
FAR struct i2c_master_s *i2c; /* Saved I2C driver instance */
rmutex_t lock; /* Mutual exclusion */
};
#endif /* CONFIG_IOEXPANDER && CONFIG_IOEXPANDER_PCA9557 */
#endif /* __DRIVERS_IOEXPANDER_PCA9557_H */