SC-F001 way better logging and parameters. not integrated yet but.

This commit is contained in:
Thaddeus Hughes
2025-12-13 10:57:09 -06:00
commit ac030005c3
505 changed files with 174645 additions and 0 deletions

View File

@@ -0,0 +1 @@
--ignore-dir=build

View File

@@ -0,0 +1,17 @@
--align-reference=name
--attach-classes
--attach-classes
--attach-namespaces
--convert-tabs
--exclude=build
--exclude=common
--exclude=managed_components
--ignore-exclude-errors
--indent-switches
--indent=spaces=4
--keep-one-line-statements
--max-continuation-indent=120
--pad-header
--pad-oper
--style=allman
--unpad-paren

View File

@@ -0,0 +1,66 @@
---
Language: Cpp
BasedOnStyle: WebKit
AlignConsecutiveMacros: true
AlignOperands: true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: false
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: true
AfterControlStatement: Always
AfterEnum: false
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: false
BeforeCatch: true
BeforeElse: true
BeforeLambdaBody: false
BeforeWhile: true
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
ColumnLimit: 200
CompactNamespaces: true
Cpp11BracedListStyle: false
FixNamespaceComments: true
IndentCaseLabels: true
IndentWidth: 4
KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 1
NamespaceIndentation: Inner
PointerAlignment: Right
ReflowComments: true
SortIncludes: false
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeInheritanceColon: false
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: false
SpaceInEmptyParentheses: false
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
TabWidth: 4
UseTab: Never

View File

@@ -0,0 +1 @@
4bbdbd82828cf1fd5c03fd07e3ea2cb0f36daf16cb3ac7219d1e5decb9ec04ee

View File

@@ -0,0 +1,28 @@
---
name: tca95x5
description: Driver for TCA9535/TCA9555 remote 16-bit I/O expanders for I2C-bus
version: 1.0.7
groups:
- gpio
code_owners: UncleRus
depends:
- i2cdev
- log
- esp_idf_lib_helpers
thread_safe: yes
targets:
- esp32
- esp8266
- esp32s2
- esp32c3
- esp32s3
- esp32c2
- esp32c6
- esp32h2
- esp32p4
- esp32c5
- esp32c61
license: BSD-3
copyrights:
- name: UncleRus
year: 2019

View File

@@ -0,0 +1,7 @@
examples/**/sdkconfig
examples/**/sdkconfig.old
examples/**/build/
examples/**/dependencies.lock
docs/_*/
docs/doxygen.log
*.swp

View File

@@ -0,0 +1,3 @@
[submodule "common"]
path = common
url = https://github.com/esp-idf-lib/common.git

View File

@@ -0,0 +1,13 @@
idf_component_register(
SRCS tca95x5.c
INCLUDE_DIRS .
REQUIRES i2cdev log esp_idf_lib_helpers
)
# include common cmake file for components
set(ESP_IDF_LIB_CMAKE ${CMAKE_CURRENT_LIST_DIR}/common/cmake/esp-idf-lib.cmake)
if(EXISTS ${ESP_IDF_LIB_CMAKE})
include(${ESP_IDF_LIB_CMAKE})
else()
message(WARNING "${ESP_IDF_LIB_CMAKE} not found")
endif()

View File

@@ -0,0 +1,19 @@
config EXAMPLE_I2C_MASTER_SCL
int "SCL GPIO Number"
default 5 if IDF_TARGET_ESP8266
default 6 if IDF_TARGET_ESP32C2 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32C5 || IDF_TARGET_ESP32C6 || IDF_TARGET_ESP32C61
default 19 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
default 4 if IDF_TARGET_ESP32H2
default 4 if IDF_TARGET_ESP32P4
help
GPIO number for I2C Master clock line.
config EXAMPLE_I2C_MASTER_SDA
int "SDA GPIO Number"
default 4 if IDF_TARGET_ESP8266
default 5 if IDF_TARGET_ESP32C2 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32C5 || IDF_TARGET_ESP32C6 || IDF_TARGET_ESP32C61
default 18 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
default 3 if IDF_TARGET_ESP32H2
default 3 if IDF_TARGET_ESP32P4
help
GPIO number for I2C Master data line.

View File

@@ -0,0 +1,26 @@
Copyright (c) 2019 Ruslan V. Uss <unclerus@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of itscontributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@@ -0,0 +1,30 @@
# esp-idf-lib/tca95x5
[![Build examples](https://github.com/esp-idf-lib/tca95x5/actions/workflows//build.yml/badge.svg)](https://github.com/esp-idf-lib/tca95x5/actions/workflows//build.yml)
[![Build docs](https://github.com/esp-idf-lib/tca95x5/actions/workflows//build-docs.yml/badge.svg)](https://github.com/esp-idf-lib/tca95x5/actions/workflows//build-docs.yml)
[![Validation](https://github.com/esp-idf-lib/tca95x5/actions/workflows//validate-component.yml/badge.svg)](https://github.com/esp-idf-lib/tca95x5/actions/workflows//validate-component.yml)
Driver for TCA9535/TCA9555 remote 16-bit I/O expanders for I2C-bus.
* [Documentation](https://esp-idf-lib.github.io/tca95x5/)
* [Repository](https://github.com/esp-idf-lib/tca95x5)
* [Issues](https://github.com/esp-idf-lib/tca95x5/issues)
* [Discussions and questions](https://github.com/esp-idf-lib/core/discussions)
* [Component page at the ESP Component Registry](https://components.espressif.com/components/esp-idf-lib/tca95x5)
## Installation
```sh
idf.py add-dependency esp-idf-lib/tca95x5
```
## Support
For questions and discussions about the component, please use
[Discussions](https://github.com/esp-idf-lib/core/discussions)
at [esp-idf-lib/core](https://github.com/esp-idf-lib/core).
## Contributing
Please read [CONTRIBUTING.md](https://github.com/esp-idf-lib/core/blob/main/CONTRIBUTING.md)
at [esp-idf-lib/core](https://github.com/esp-idf-lib/core).

View File

@@ -0,0 +1,18 @@
#!/usr/bin/env ruby
require "pathname"
require "yaml"
# A simple CLI to get values in .eil.yml
key = ARGV.shift
project_root = Pathname.new(File.expand_path(__FILE__)).parent.parent
eil_file = project_root / ".eil.yml"
doc = YAML.safe_load(File.read eil_file)
case key
when "copyright_string"
puts doc["copyrights"].map { |e| "#{e['year']}, #{e['name']}" }.join(", ")
else
puts doc[key]
end

View File

@@ -0,0 +1,36 @@
# Set common build flags but enable them only when the build is in our CI,
# making them optional. The idea is, fail when compiled in our CI but just
# warn in any other cases. Code that compiles with one toolchain warning-free
# may not do so with another toolchain, which creates a project dependency on
# specific toolchain vendors and versions.
#
# Define flags that may cause failures here.
if (DEFINED ENV{ESP_IDF_LIB_CI})
set(ESP_IDF_LIB_CI_FLAGS
-Werror=unused-variable
-Werror=unused-function
-Werror=write-strings
-Werror
)
endif()
# Set common build flags. Mandatory.
#
# Define flags that do not cause failures here.
set(ESP_IDF_LIB_FLAGS
-Wextra
-Wwrite-strings
-Wunused-variable
-Wunused-function
-Wreturn-type
)
# When COMPONENT_LIB is INTERFACE_LIBRARY, or a header-only library, do not
# set the flags.
get_target_property(COMPONENT_TYPE ${COMPONENT_LIB} TYPE)
if(NOT COMPONENT_TYPE STREQUAL "INTERFACE_LIBRARY")
target_compile_options(${COMPONENT_LIB} PRIVATE
${ESP_IDF_LIB_FLAGS}
${ESP_IDF_LIB_CI_FLAGS}
)
endif()

View File

@@ -0,0 +1,2 @@
COMPONENT_ADD_INCLUDEDIRS = .
COMPONENT_DEPENDS = i2cdev log esp_idf_lib_helpers

View File

@@ -0,0 +1,7 @@
# The following four lines of boilerplate have to be in your project's CMakeLists
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(example-tca95x5)

View File

@@ -0,0 +1,6 @@
#V := 1
PROJECT_NAME := example-tca95x5
include $(IDF_PATH)/make/project.mk

View File

@@ -0,0 +1,13 @@
## What the example does
* Initializes the driver
* Configure a pin as input
* Registers an interrupt that logs port value of the INT pin
* Blinks, or toggles, P10 output
## Wiring
Connect an LED with an appropriate register to P10.
Connect a switch that toggle its voltage HIGH or LOW to INT GPIO. The INT GPIO
can be set in `menuconfig`. See the defaults in `Kconfig.projbuild`.

View File

@@ -0,0 +1,2 @@
idf_component_register(SRCS "main.c"
INCLUDE_DIRS ".")

View File

@@ -0,0 +1,21 @@
menu "Example configuration"
config EXAMPLE_I2C_ADDR
hex "I2C address of TCA9555"
default 0x20
help
I2C address of TCA9555. The default is `TCA95X5_I2C_ADDR_BASE`, or
0x20. See available options in datasheet.
config EXAMPLE_INT_GPIO
int "INT GPIO Number"
default 14 if IDF_TARGET_ESP8266
default 7 if IDF_TARGET_ESP32C2 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32C5 || IDF_TARGET_ESP32C6 || IDF_TARGET_ESP32C61
default 5 if IDF_TARGET_ESP32H2
default 5 if IDF_TARGET_ESP32P4
default 5 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
help
GPIO number connected to INT pin.
rsource "../../../Kconfig.i2c"
endmenu

View File

@@ -0,0 +1 @@
COMPONENT_ADD_INCLUDEDIRS = . include/

View File

@@ -0,0 +1,9 @@
dependencies:
esp-idf-lib/esp_idf_lib_helpers:
version: '*'
esp-idf-lib/i2cdev:
version: '*'
esp-idf-lib/tca95x5:
version: '*'
description: default
version: 1.0.0

View File

@@ -0,0 +1,80 @@
#include <stdio.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <freertos/queue.h>
#include <tca95x5.h>
#include <driver/gpio.h>
#include <esp_log.h>
static i2c_dev_t tca9555 = { 0 };
static QueueHandle_t gpio_queue = NULL;
static const char *TAG = "tca95x5-example";
// Interrupt handler
static void IRAM_ATTR intr_handler(void *arg)
{
gpio_num_t gpio = (gpio_num_t)arg;
xQueueSendFromISR(gpio_queue, &gpio, NULL);
}
// Interrupt event receiver
static void gpio_recv_task(void *arg)
{
gpio_num_t gpio;
while (1)
{
if (xQueueReceive(gpio_queue, &gpio, portMAX_DELAY))
{
ESP_LOGI(TAG, "GPIO interrupt on pin %d", gpio);
if (gpio != CONFIG_EXAMPLE_INT_GPIO) continue;
uint16_t val;
esp_err_t res = tca95x5_port_read(&tca9555, &val);
if (res != ESP_OK)
{
ESP_LOGE(TAG, "Error reading TCA9555: %d (%s)", res, esp_err_to_name(res));
continue;
}
ESP_LOGI(TAG, "TCA9555 port value: 0x%04x", val);
}
}
}
void main_task(void *pvParameters)
{
// Init descriptor
ESP_ERROR_CHECK(tca95x5_init_desc(&tca9555, CONFIG_EXAMPLE_I2C_ADDR, 0, CONFIG_EXAMPLE_I2C_MASTER_SDA, CONFIG_EXAMPLE_I2C_MASTER_SCL));
// Setup P00, P01 and P02 as input, others as output
ESP_ERROR_CHECK(tca95x5_port_set_mode(&tca9555, 0x0007)); // 0b0000000000000111
// Create queue
gpio_queue = xQueueCreate(5, sizeof(gpio_num_t));
// Run event receiver
xTaskCreate(gpio_recv_task, "gpio_recv_task", 4096, NULL, 5, NULL);
// Setup GPIO interrupt
gpio_set_direction(CONFIG_EXAMPLE_INT_GPIO, GPIO_MODE_INPUT);
gpio_set_intr_type(CONFIG_EXAMPLE_INT_GPIO, GPIO_INTR_NEGEDGE);
gpio_install_isr_service(0);
gpio_isr_handler_add(CONFIG_EXAMPLE_INT_GPIO, intr_handler, (void *)CONFIG_EXAMPLE_INT_GPIO);
// blink on P10
bool on = true;
while (1)
{
ESP_ERROR_CHECK(tca95x5_set_level(&tca9555, 8, on));
on = !on;
vTaskDelay(pdMS_TO_TICKS(500));
}
}
void app_main()
{
ESP_ERROR_CHECK(i2cdev_init());
xTaskCreate(main_task, "main_task", configMINIMAL_STACK_SIZE * 6, NULL, 5, NULL);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

View File

@@ -0,0 +1,32 @@
dependencies:
esp-idf-lib/esp_idf_lib_helpers:
version: '*'
esp-idf-lib/i2cdev:
version: '*'
description: Driver for TCA9535/TCA9555 remote 16-bit I/O expanders for I2C-bus
discussion: https://github.com/esp-idf-lib/core/discussions
documentation: https://esp-idf-lib.github.io/tca95x5/
files:
exclude:
- docs/**/*
issues: https://github.com/esp-idf-lib/tca95x5/issues
license: BSD-3
maintainers:
- Ruslan V. Uss (@UncleRus) <unclerus@gmail.com>
repository: git://github.com/esp-idf-lib/tca95x5.git
repository_info:
commit_sha: 1334d902c73251c88a70f37c271a335d6a5868e5
path: .
targets:
- esp32
- esp32c2
- esp32c3
- esp32c5
- esp32c6
- esp32c61
- esp32h2
- esp32p4
- esp32s2
- esp32s3
url: https://github.com/esp-idf-lib/core
version: 1.0.7

View File

@@ -0,0 +1,138 @@
/*
* Copyright (c) 2019 Ruslan V. Uss <unclerus@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of itscontributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file tca95x5.c
*
* ESP-IDF driver for TCA9535/TCA9555 remote 16-bit I/O expanders for I2C-bus
*
* Copyright (c) 2019 Ruslan V. Uss <unclerus@gmail.com>
*
* BSD Licensed as described in the file LICENSE
*/
#include <esp_idf_lib_helpers.h>
#include "tca95x5.h"
#define I2C_FREQ_HZ 400000
#define REG_IN0 0x00
#define REG_OUT0 0x02
#define REG_CONF0 0x06
#define CHECK(x) do { esp_err_t __; if ((__ = x) != ESP_OK) return __; } while (0)
#define CHECK_ARG(VAL) do { if (!(VAL)) return ESP_ERR_INVALID_ARG; } while (0)
#define BV(x) (1 << (x))
static esp_err_t read_reg_16(i2c_dev_t *dev, uint8_t reg, uint16_t *val)
{
CHECK_ARG(dev && val);
I2C_DEV_TAKE_MUTEX(dev);
I2C_DEV_CHECK(dev, i2c_dev_read_reg(dev, reg, val, 2));
I2C_DEV_GIVE_MUTEX(dev);
return ESP_OK;
}
static esp_err_t write_reg_16(i2c_dev_t *dev, uint8_t reg, uint16_t val)
{
CHECK_ARG(dev);
I2C_DEV_TAKE_MUTEX(dev);
I2C_DEV_CHECK(dev, i2c_dev_write_reg(dev, reg, &val, 2));
I2C_DEV_GIVE_MUTEX(dev);
return ESP_OK;
}
///////////////////////////////////////////////////////////////////////////////
esp_err_t tca95x5_init_desc(i2c_dev_t *dev, uint8_t addr, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio)
{
CHECK_ARG(dev && (addr & TCA95X5_I2C_ADDR_BASE));
dev->port = port;
dev->addr = addr;
dev->cfg.sda_io_num = sda_gpio;
dev->cfg.scl_io_num = scl_gpio;
#if HELPER_TARGET_IS_ESP32
dev->cfg.master.clk_speed = I2C_FREQ_HZ;
#endif
return i2c_dev_create_mutex(dev);
}
esp_err_t tca95x5_free_desc(i2c_dev_t *dev)
{
CHECK_ARG(dev);
return i2c_dev_delete_mutex(dev);
}
esp_err_t tca95x5_port_get_mode(i2c_dev_t *dev, uint16_t *mode)
{
return read_reg_16(dev, REG_CONF0, mode);
}
esp_err_t tca95x5_port_set_mode(i2c_dev_t *dev, uint16_t mode)
{
return write_reg_16(dev, REG_CONF0, mode);
}
esp_err_t tca95x5_port_read(i2c_dev_t *dev, uint16_t *val)
{
return read_reg_16(dev, REG_IN0, val);
}
esp_err_t tca95x5_port_write(i2c_dev_t *dev, uint16_t val)
{
return write_reg_16(dev, REG_OUT0, val);
}
esp_err_t tca95x5_get_level(i2c_dev_t *dev, uint8_t pin, uint32_t *val)
{
uint16_t v;
CHECK(read_reg_16(dev, REG_IN0, &v));
*val = v & BV(pin) ? 1 : 0;
return ESP_OK;
}
esp_err_t tca95x5_set_level(i2c_dev_t *dev, uint8_t pin, uint32_t val)
{
uint16_t v;
I2C_DEV_TAKE_MUTEX(dev);
I2C_DEV_CHECK(dev, i2c_dev_read_reg(dev, REG_OUT0, &v, 2));
v = (v & ~BV(pin)) | (val ? BV(pin) : 0);
I2C_DEV_CHECK(dev, i2c_dev_write_reg(dev, REG_OUT0, &v, 2));
I2C_DEV_GIVE_MUTEX(dev);
return ESP_OK;
}

View File

@@ -0,0 +1,141 @@
/*
* Copyright (c) 2019 Ruslan V. Uss <unclerus@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of itscontributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file tca95x5.h
* @defgroup tca95x5 tca95x5
* @{
*
* ESP-IDF driver for TCA9535/TCA9555 remote 16-bit I/O expanders for I2C-bus
*
* Copyright (c) 2019 Ruslan V. Uss <unclerus@gmail.com>
*
* BSD Licensed as described in the file LICENSE
*/
#ifndef __TCA95X5_H__
#define __TCA95X5_H__
#include <stddef.h>
#include <i2cdev.h>
#include <esp_err.h>
#ifdef __cplusplus
extern "C" {
#endif
#define TCA95X5_I2C_ADDR_BASE 0x20
/**
* @brief Initialize device descriptor
*
* Default SCL frequency is 400kHz
*
* @param dev Pointer to I2C device descriptor
* @param addr I2C address (`0b0100<A2><A1><A0>`)
* @param port I2C port number
* @param sda_gpio SDA GPIO
* @param scl_gpio SCL GPIO
* @return `ESP_OK` on success
*/
esp_err_t tca95x5_init_desc(i2c_dev_t *dev, uint8_t addr, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio);
/**
* @brief Free device descriptor
* @param dev Pointer to I2C device descriptor
* @return `ESP_OK` on success
*/
esp_err_t tca95x5_free_desc(i2c_dev_t *dev);
/**
* @brief Get GPIO pins mode
*
* 0 - output, 1 - input for each bit in `val`
*
* @param dev Pointer to device descriptor
* @param[out] mode Buffer to store mode, 0 bit for P0.0 .. 15 bit for P1.7
* @return `ESP_OK` on success
*/
esp_err_t tca95x5_port_get_mode(i2c_dev_t *dev, uint16_t *mode);
/**
* @brief Set GPIO pins mode
*
* 0 - output, 1 - input for each bit in `val`
*
* @param dev Pointer to device descriptor
* @param mode Mode, 0 bit for P0.0 .. 15 bit for P1.7
* @return `ESP_OK` on success
*/
esp_err_t tca95x5_port_set_mode(i2c_dev_t *dev, uint16_t mode);
/**
* @brief Read GPIO port value
*
* @param dev Pointer to I2C device descriptor
* @param val 16-bit GPIO port value, 0 bit for P0.0 .. 15 bit for P1.7
* @return `ESP_OK` on success
*/
esp_err_t tca95x5_port_read(i2c_dev_t *dev, uint16_t *val);
/**
* @brief Write value to GPIO port
*
* @param dev Pointer to I2C device descriptor
* @param val GPIO port value, 0 bit for P0.0 .. 15 bit for P1.7
* @return ESP_OK on success
*/
esp_err_t tca95x5_port_write(i2c_dev_t *dev, uint16_t val);
/**
* @brief Read GPIO pin level
*
* @param dev Pointer to device descriptor
* @param pin Pin number, 0 for P0.0 .. 15 for P1.7
* @param[out] val `true` if pin currently in high state
* @return `ESP_OK` on success
*/
esp_err_t tca95x5_get_level(i2c_dev_t *dev, uint8_t pin, uint32_t *val);
/**
* @brief Set GPIO pin level
*
* Pin must be set up as output
*
* @param dev Pointer to device descriptor
* @param pin Pin number, 0 for P0.0 .. 15 for P1.7
* @param[out] val `true` if pin currently in high state
* @return `ESP_OK` on success
*/
esp_err_t tca95x5_set_level(i2c_dev_t *dev, uint8_t pin, uint32_t val);
#ifdef __cplusplus
}
#endif
/**@}*/
#endif /* __TCA95X5_H__ */