ioexpander: add support for iC-JX expander

This commit adds basic support for iC-JX expander in SPI mode. The
expander is functional and supports both input and output pins. Further
expander functionalities (filtering, adc, interrupt support) are not
yet implemented.

Signed-off-by: Michal Lenc <michallenc@seznam.cz>
This commit is contained in:
Michal Lenc
2024-01-23 14:46:08 +01:00
committed by Alan Carvalho de Assis
parent f8b0b06b97
commit 22110b3b83
5 changed files with 970 additions and 0 deletions
+18
View File
@@ -56,6 +56,24 @@ config IOEXPANDER_DUMMY_INT_POLLDELAY
endif # IOEXPANDER_DUMMY
config IOEXPANDER_ICJX
bool "iC-JX SPI IO expander"
default n
depends on SPI
---help---
Enable support for the iC-JX expander from iC-Haus GmbH manufacturer.
SPI peripheral is used for the communication.
if IOEXPANDER_ICJX
config iC-JX_MULTIPLE
bool "Multiple iC-JX Devices"
default n
---help---
Can be defined to support multiple iC-JX devices on board.
endif # IOEXPANDER_ICJX
config IOEXPANDER_ISO1H812G
bool "ISO1H812G SPI IO expander"
default n
+4
View File
@@ -32,6 +32,10 @@ ifeq ($(CONFIG_IOEXPANDER_DUMMY),y)
CSRCS += ioe_dummy.c
endif
ifeq ($(CONFIG_IOEXPANDER_ICJX),y)
CSRCS += icjx.c
endif
ifeq ($(CONFIG_IOEXPANDER_ISO1H812G),y)
CSRCS += iso1h812g.c
endif
File diff suppressed because it is too large Load Diff
+102
View File
@@ -0,0 +1,102 @@
/****************************************************************************
* drivers/ioexpander/icjx.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_ICJX_H
#define __DRIVERS_IOEXPANDER_ICJX_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/mutex.h>
#if defined(CONFIG_IOEXPANDER) && defined(CONFIG_IOEXPANDER_ICJX)
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
/* Prerequisites:
* CONFIG_SPI
* SPI support is required
* CONFIG_IOEXPANDER
* Enables I/O expander support
*
* CONFIG_IOEXPANDER_ICJX
* Enables support for the ICJX driver (Needs CONFIG_INPUT)
* CONFIG_ICJX_MULTIPLE
* Can be defined to support multiple ICJX devices on board.
*/
#ifndef CONFIG_SPI
# error "CONFIG_SPI is required by ICJX"
#endif
/* iC-JX Registers **********************************************************/
#define ICJX_INPUT_A 0x00
#define ICJX_INPUT_B 0x01
#define ICJX_CHNG_MSG_A 0x02
#define ICJX_CNNG_MSG_B 0x03
#define ICJX_INT_STATUS_A 0x04
#define ICJX_INT_STATUS_B 0x05
#define ICJX_OVERCURR_MSG_A 0x06
#define ICJX_OVERCURR_MSG_B 0x07
#define ICJX_OVERCURR_STATUS_A 0x08
#define ICJX_OVERCURR_STATUS_B 0x09
#define ICJX_ADC_DATA_1 0x0A
#define ICJX_ADC_DATA_2 0x0B
#define ICJX_OUTPUT_A 0x0C
#define ICJX_OUTPUT_B 0x0D
#define ICJX_FLASH_PULSE_A 0x0E
#define ICJX_FLASH_PULSE_B 0x0F
#define ICJX_CHNG_INT_EN_A 0x10
#define ICJX_CHNG_INT_EN_B 0x11
#define ICJX_OVERCURR_INT_EN_A 0x12
#define ICJX_OVERCURR_INT_EN_B 0x13
#define ICJX_CTRL_WORD_1_A 0x14
#define ICJX_CTRL_WORD_1_B 0x15
#define ICJX_CTRL_WORD_2_A 0x16
#define ICJX_CTRL_WORD_2_B 0x17
#define ICJX_CTRL_WORD_3_A 0x18
#define ICJX_CTRL_WORD_3_B 0x19
#define ICJX_CTRL_WORD_4 0x1A
#define ICJX_CTRL_WORD_5 0x1B
#define ICJX_CTRL_WORD_6 0x1C
#define ICJX_DEV_ID 0x1D
#define ICJX_TEST_1 0x1E
#define ICJX_TEST_2 0x1F
/* Control Word 1 */
#define ICJX_CTRL_WORD_1_BYP0 (1 << 3)
#define ICJX_CTRL_WORD_1_BYP1 (1 << 7)
/* Control Word 2 */
#define ICJX_CTRL_WORD_2_NIOL (1 << 3)
#define ICJX_CTRL_WORD_2_NIOH (1 << 7)
#endif /* CONFIG_IOEXPANDER && CONFIG_IOEXPANDER_ICJX */
#endif /* __DRIVERS_IOEXPANDER_ICJX_H */
+96
View File
@@ -0,0 +1,96 @@
/****************************************************************************
* include/nuttx/ioexpander/icjx.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_ICJX_H
#define __INCLUDE_NUTTX_IOEXPANDER_ICJX_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define ICJX_CTRL_WORD_CURR_SRC_DIS 0 /* Pin current source disabled */
#define ICJX_CTRL_WORD_PULLDOWN_200U 1 /* 200 uA pull down */
#define ICJX_CTRL_WORD_PULLDOWN_600U 2 /* 600 uA pull down */
#define ICJX_CTRL_WORD_PULLDOWN_2M 3 /* 2 mA pull down */
#define ICJX_CTRL_WORD_PULLUP_200U 5 /* 200 uA pull up */
#define ICJX_CTRL_WORD_PULLUP_600U 6 /* 600 uA pull up */
#define ICJX_CTRL_WORD_PULLUP_2M 7 /* 2 mA pull up*/
/****************************************************************************
* Public Types
****************************************************************************/
/* A reference to a structure of this type must be passed to the iC-JX
* driver when the driver is instantiated. This structure provides
* information about the configuration of the iC-JX 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 icjx_config_s
{
/* Device characterization */
uint8_t id; /* Device ID (if more expanders are used) */
uint8_t verification; /* True if data verification on MISO line is used */
uint8_t current_src; /* Current sources for pin nibbles (pull up,
* pull down) - see Control Word 2 register
*/
uint8_t addr; /* Device address (set by A(1:0) pins) */
uint8_t mode; /* SPI mode */
uint32_t frequency; /* SPI frequency */
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: icjx_initialize
*
* Description:
* Instantiate and configure the iC-JX device driver to use the
* provided SPI device instance.
*
* Input Parameters:
* spi - A SPI driver instance
* config - Persistent board configuration data
*
* Returned Value:
* an ioexpander_dev_s instance on success, NULL on failure.
*
****************************************************************************/
struct spi_dev_s;
FAR struct ioexpander_dev_s *icjx_initialize(FAR struct spi_dev_s *spi,
FAR struct icjx_config_s *config);
#endif /* __INCLUDE_NUTTX_IOEXPANDER_ICJX_H */