tca95x5 - Driver for TCA9535/TCA9555 remote 16-bit I/O expanders for I2C-bus

group tca95x5

ESP-IDF driver for TCA9535/TCA9555 remote 16-bit I/O expanders for I2C-bus.

Copyright (C) 2019 Ruslan V. Uss https://github.com/UncleRus

BSD Licensed as described in the file LICENSE

Defines

TCA95X5_I2C_ADDR_BASE

Functions

esp_err_t tca95x5_init_desc(i2c_dev_t *dev, i2c_port_t port, uint8_t addr, gpio_num_t sda_gpio, gpio_num_t scl_gpio)

Initialize device descriptor.

Default SCL frequency is 400kHz

Parameters
  • dev – Pointer to I2C device descriptor

  • port – I2C port number

  • addr – I2C address (0b0100<A2><A1><A0>)

  • sda_gpio – SDA GPIO

  • scl_gpio – SCL GPIO

Returns

ESP_OK on success

esp_err_t tca95x5_free_desc(i2c_dev_t *dev)

Free device descriptor.

Parameters

dev – Pointer to I2C device descriptor

Returns

ESP_OK on success

esp_err_t tca95x5_port_get_mode(i2c_dev_t *dev, uint16_t *mode)

Get GPIO pins mode.

0 - output, 1 - input for each bit in val

Parameters
  • dev – Pointer to device descriptor

  • [out] mode – Buffer to store mode, 0 bit for P0.0 .. 15 bit for P1.7

Returns

ESP_OK on success

esp_err_t tca95x5_port_set_mode(i2c_dev_t *dev, uint16_t mode)

Set GPIO pins mode.

0 - output, 1 - input for each bit in val

Parameters
  • dev – Pointer to device descriptor

  • mode – Mode, 0 bit for P0.0 .. 15 bit for P1.7

Returns

ESP_OK on success

esp_err_t tca95x5_port_read(i2c_dev_t *dev, uint16_t *val)

Read GPIO port value.

Parameters
  • dev – Pointer to I2C device descriptor

  • val – 16-bit GPIO port value, 0 bit for P0.0 .. 15 bit for P1.7

Returns

ESP_OK on success

esp_err_t tca95x5_port_write(i2c_dev_t *dev, uint16_t val)

Write value to GPIO port.

Parameters
  • dev – Pointer to I2C device descriptor

  • val – GPIO port value, 0 bit for P0.0 .. 15 bit for P1.7

Returns

ESP_OK on success

esp_err_t tca95x5_get_level(i2c_dev_t *dev, uint8_t pin, uint32_t *val)

Read GPIO pin level.

Parameters
  • dev – Pointer to device descriptor

  • pin – Pin number, 0 for P0.0 .. 15 for P1.7

  • [out] valtrue if pin currently in high state

Returns

ESP_OK on success

esp_err_t tca95x5_set_level(i2c_dev_t *dev, uint8_t pin, uint32_t val)

Set GPIO pin level.

Pin must be set up as output

Parameters
  • dev – Pointer to device descriptor

  • pin – Pin number, 0 for P0.0 .. 15 for P1.7

  • [out] valtrue if pin currently in high state

Returns

ESP_OK on success