-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10430 from gschorcht/drivers_pcf857x
drivers: add PCF857X I2C I/O expander driver
- Loading branch information
Showing
18 changed files
with
2,004 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include $(RIOTBASE)/Makefile.base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ | ||
/** @} */ |
Oops, something went wrong.