ioexpander: add support for pcf8575 expander

This adds support for 16 bit io expander pcf8575. The driver is basically
the same as for pcf8574 however it is for 16 bits instead of 8 bits. Since
pcf8575 and pcf8574 can be both used on the same i2c bus the driver for
pcf8575 is implemented in a different file to reduce the code size
and complexity and to have less if statements in the driver.

Signed-off-by: Michal Lenc <michallenc@seznam.cz>
This commit is contained in:
Michal Lenc
2023-08-01 16:25:06 +02:00
committed by Xiang Xiao
parent 580d09b5a1
commit bf90361895
5 changed files with 865 additions and 0 deletions
+19
View File
@@ -297,6 +297,25 @@ config PCF8574_INT_POLLDELAY
endif # IOEXPANDER_PCF8574
config IOEXPANDER_PCF8575
bool "PCF8575 I2C IO expander"
default n
depends on I2C
---help---
Enable support for 16 bit PCF8575 IO Expander. Software driver
interrupt is currently not supported therefore decated HW interrupt
pin should be used.
if IOEXPANDER_PCF8575
config PCF8575_MULTIPLE
bool "Multiple PCF8575 Devices"
default n
---help---
Can be defined to support multiple PCF8575 devices on board.
endif # IOEXPANDER_PCF8575
config IOEXPANDER_SX1509
bool "SX1509 I2C IO expander"
default n
+4
View File
@@ -48,6 +48,10 @@ ifeq ($(CONFIG_IOEXPANDER_PCF8574),y)
CSRCS += pcf8574.c
endif
ifeq ($(CONFIG_IOEXPANDER_PCF8575),y)
CSRCS += pcf8575.c
endif
ifeq ($(CONFIG_IOEXPANDER_MCP23X17),y)
CSRCS += mcp23x17.c
endif
File diff suppressed because it is too large Load Diff
+82
View File
@@ -0,0 +1,82 @@
/****************************************************************************
* drivers/ioexpander/pcf8575.h
*
* 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_PCF8575_H
#define __DRIVERS_IOEXPANDER_PCF8575_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/mutex.h>
#include <nuttx/ioexpander/ioexpander.h>
#include <nuttx/ioexpander/pcf8575.h>
#include <nuttx/i2c/i2c_master.h>
#if defined(CONFIG_IOEXPANDER) && defined(CONFIG_IOEXPANDER_PCF8575)
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
/* Prerequisites:
* CONFIG_I2C
* I2C support is required
* CONFIG_IOEXPANDER
* Enables I/O expander support
*
* CONFIG_IOEXPANDER_PCF8575
* Enables support for the PCF8575 driver (Needs CONFIG_INPUT)
* CONFIG_PCF8575_MULTIPLE
* Can be defined to support multiple PCF8575 devices on board.
*/
#ifndef CONFIG_I2C
# error "CONFIG_I2C is required by PCF8575"
#endif
/* PCF8575 Definitions ******************************************************/
#define PCF8575_I2C_MAXFREQUENCY 400000 /* 400KHz */
/****************************************************************************
* Public Types
****************************************************************************/
/* This structure represents the state of the PCF8575 driver */
struct pcf8575_dev_s
{
struct ioexpander_dev_s dev; /* Nested structure to allow casting as public gpio
* expander. */
FAR struct pcf8575_config_s *config; /* Board configuration data */
FAR struct i2c_master_s *i2c; /* Saved I2C driver instance */
mutex_t lock; /* Mutual exclusion */
uint16_t inpins; /* Set of input pins */
uint16_t outstate; /* State of all output pins */
};
#endif /* CONFIG_IOEXPANDER && CONFIG_IOEXPANDER_PCF8575 */
#endif /* __DRIVERS_IOEXPANDER_PCF8575_H */
+79
View File
@@ -0,0 +1,79 @@
/****************************************************************************
* include/nuttx/ioexpander/pcf8575.h
*
* 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 __INCLUDE_NUTTX_IOEXPANDER_PCF8575_H
#define __INCLUDE_NUTTX_IOEXPANDER_PCF8575_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
/****************************************************************************
* Public Types
****************************************************************************/
/* A reference to a structure of this type must be passed to the PCF8575xx
* driver when the driver is instantiated. This structure provides
* information about the configuration of the PCF8575xx 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.
*/
struct pcf8575_config_s
{
/* Device characterization */
uint8_t address; /* 7-bit I2C address (only bits 0-6 used) */
uint32_t frequency; /* I2C frequency */
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: pcf8575_initialize
*
* Description:
* Instantiate and configure the PCF8575xx device driver to use the
* provided I2C device instance.
*
* Input Parameters:
* i2c - An I2C driver instance
* minor - The device i2c address
* config - Persistent board configuration data
*
* Returned Value:
* an ioexpander_dev_s instance on success, NULL on failure.
*
****************************************************************************/
struct i2c_master_s;
FAR struct ioexpander_dev_s *pcf8575_initialize(FAR struct i2c_master_s *i2c,
FAR struct pcf8575_config_s *config);
#endif /* __INCLUDE_NUTTX_IOEXPANDER_PCF8575_H */