Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: add PCF857X I2C I/O expander driver #10430

Merged
merged 4 commits into from
Dec 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions drivers/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ rsource "ds3231/Kconfig"
rsource "ds3234/Kconfig"
rsource "edbg_eui/Kconfig"
rsource "io1_xplained/Kconfig"
rsource "pcf857x/Kconfig"
rsource "tps6274x/Kconfig"
rsource "uart_half_duplex/Kconfig"
rsource "usbdev_mock/Kconfig"
Expand Down
4 changes: 4 additions & 0 deletions drivers/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ ifneq (,$(filter nrf24l01p_ng_%,$(USEMODULE)))
USEMODULE += nrf24l01p_ng
endif

ifneq (,$(filter pcf857%,$(USEMODULE)))
USEMODULE += pcf857x
endif

ifneq (,$(filter periph_ptp_timer periph_ptp_speed_adjustment,$(FEATURES_USED)))
FEATURES_REQUIRED += periph_ptp
endif
Expand Down
600 changes: 600 additions & 0 deletions drivers/include/pcf857x.h

Large diffs are not rendered by default.

65 changes: 65 additions & 0 deletions drivers/pcf857x/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Copyright (c) 2021 Gunar Schorcht
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
#

menuconfig MODULE_PCF857X
bool "PCF857x Remote I/O Expander for I2C Bus"
depends on HAS_PERIPH_GPIO
depends on HAS_PERIPH_I2C
depends on TEST_KCONFIG
select MODULE_PERIPH_GPIO
select MODULE_PERIPH_I2C
help
Driver for Texas Instruments PCF857X I2C I/O expanders.
The driver supports the PCF8574, PCF8574A, and PCF8575 variants.
Select the variants used by your application.

if MODULE_PCF857X

config MODULE_PCF8574
bool "PCF8574 Remote 8-Bit I/O is used"

config MODULE_PCF8574A
bool "PCF8574A Remote 8-Bit I/O is used"

config MODULE_PCF8575
bool "PCF8575 Remote 16-Bit I/O is used"
default y

config MODULE_PCF857X_IRQ
bool "Interrupt support for PCF857x I/O Expander pins"
depends on MODULE_PCF857X
depends on HAS_PERIPH_GPIO_IRQ
select MODULE_PERIPH_GPIO_IRQ
select MODULE_EVENT
select MODULE_EVENT_THREAD
help
To use the IRQs the MODULE_EVENT_THREAD symbol should be set.

choice
bool "Thread priority"
depends on MODULE_PCF857X_IRQ
default MODULE_PCF857X_IRQ_MEDIUM
help
To process IRQs an event thread is used. The MODULE_EVENT_THREAD
symbol should be set. Choose a priority for the thread that
processes the IRQs. The default is medium priority.

config MODULE_PCF857X_IRQ_LOW
bool "Low"
select MODULE_EVENT_THREAD_LOW

config MODULE_PCF857X_IRQ_MEDIUM
bool "Medium"
select MODULE_EVENT_THREAD_MEDIUM

config MODULE_PCF857X_IRQ_HIGHEST
bool "Highest"
select MODULE_EVENT_THREAD_HIGHEST

endchoice

endif # MODULE_PCF857X
1 change: 1 addition & 0 deletions drivers/pcf857x/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include $(RIOTBASE)/Makefile.base
19 changes: 19 additions & 0 deletions drivers/pcf857x/Makefile.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FEATURES_REQUIRED += periph_gpio
FEATURES_REQUIRED += periph_i2c

_PCF857X_IRQ_MODULE := $(filter pcf857x_irq_%,$(USEMODULE))
ifneq (,$(_PCF857X_IRQ_MODULE))
# pull in the correspondant event_thread_<priority> module
USEMODULE += $(_PCF857X_IRQ_MODULE:pcf857x_irq_%=event_thread_%)
USEMODULE += pcf857x_irq
else
ifneq (,$(filter pcf857x_irq,$(USEMODULE)))
# pull in the pcf857x_irq_medium module as default if pcf857x_irq is used.
USEMODULE += pcf857x_irq_medium
endif
endif

ifneq (,$(filter pcf857x_irq,$(USEMODULE)))
FEATURES_REQUIRED += periph_gpio_irq
USEMODULE += pcf857x
endif
11 changes: 11 additions & 0 deletions drivers/pcf857x/Makefile.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# include variants of PCF857X drivers as pseudo modules
PSEUDOMODULES += pcf8574
PSEUDOMODULES += pcf8574a
PSEUDOMODULES += pcf8575
PSEUDOMODULES += pcf857x_irq
PSEUDOMODULES += pcf857x_irq_low
PSEUDOMODULES += pcf857x_irq_medium
PSEUDOMODULES += pcf857x_irq_highest

USEMODULE_INCLUDES_pcf857x := $(LAST_MAKEFILEDIR)/include
USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_pcf857x)
123 changes: 123 additions & 0 deletions drivers/pcf857x/include/pcf857x_params.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* Copyright (C) 2018 Gunar Schorcht
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup drivers_pcf857x
* @brief Default configuration for Texas Instruments PCF857X I2C I/O expanders
* @author Gunar Schorcht <gunar@schorcht.net>
* @file
* @{
*/

#ifndef PCF857X_PARAMS_H
#define PCF857X_PARAMS_H

#include "board.h"
#include "pcf857x.h"
#include "saul_reg.h"
#include "saul/periph.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @name Set default configuration parameters
* @{
*/
#ifndef PCF857X_PARAM_DEV
/** device is I2C_DEV(0) */
#define PCF857X_PARAM_DEV I2C_DEV(0)
#endif

#ifndef PCF857X_PARAM_ADDR
/** I2C slave address offset is 0 */
#define PCF857X_PARAM_ADDR (0)
#endif

#ifndef PCF857X_PARAM_EXP
/** PCF857X expander variant used depends on enabled pseudomodules*/
#if IS_USED(MODULE_PCF8575) || DOXYGEN
#define PCF857X_PARAM_EXP (PCF857X_EXP_PCF8575)
#elif IS_USED(MODULE_PCF8574)
#define PCF857X_PARAM_EXP (PCF857X_EXP_PCF8574)
#elif IS_USED(MODULE_PCF8574A)
#define PCF857X_PARAM_EXP (PCF857X_EXP_PCF8574A)
#endif
#endif /* PCF857X_PARAM_EXP */

#ifndef PCF857X_PARAM_INT_PIN
/** MCU interrupt pin */
#define PCF857X_PARAM_INT_PIN (GPIO_UNDEF)
#endif

#ifndef PCF857X_PARAMS
#if IS_USED(MODULE_PCF857X_IRQ) || DOXYGEN
/** Default configuration parameter set */
#define PCF857X_PARAMS { \
.dev = PCF857X_PARAM_DEV, \
.addr = PCF857X_PARAM_ADDR, \
.exp = PCF857X_PARAM_EXP, \
.int_pin = PCF857X_PARAM_INT_PIN, \
},
#else
#define PCF857X_PARAMS { \
.dev = PCF857X_PARAM_DEV, \
.addr = PCF857X_PARAM_ADDR, \
.exp = PCF857X_PARAM_EXP, \
},
#endif
#endif /* PCF857X_PARAMS */

#ifndef PCF857X_SAUL_GPIO_PARAMS
/** Example for mapping expander pins to SAUL */
#define PCF857X_SAUL_GPIO_PARAMS { \
.dev = 0, \
.gpio = { \
.name = "P00 Output", \
.pin = PCF857X_GPIO_PIN(0, 0), \
.mode = GPIO_OUT, \
.flags = SAUL_GPIO_INIT_CLEAR, \
} \
}, \
{ \
.dev = 0, \
.gpio = { \
.name = "P01 Input", \
.pin = PCF857X_GPIO_PIN(0, 1), \
.mode = GPIO_IN, \
.flags = 0, \
} \
},
#endif
/**@}*/

/**
* @brief Allocate some memory to store the actual configuration
*/
static const pcf857x_params_t pcf857x_params[] =
{
PCF857X_PARAMS
};

#if IS_USED(MODULE_SAUL_GPIO) || DOXYGEN
/**
* @brief Additional meta information to keep in the SAUL registry
*/
static const pcf857x_saul_gpio_params_t pcf857x_saul_gpio_params[] =
{
PCF857X_SAUL_GPIO_PARAMS
};
#endif /* MODULE_SAUL_GPIO || DOXYGEN */

#ifdef __cplusplus
}
#endif

#endif /* PCF857X_PARAMS_H */
/** @} */
Loading