esp_io_expander_tca9554.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file
  8. * @brief ESP IO expander: TCA9554
  9. */
  10. #pragma once
  11. #include <stdint.h>
  12. #include "esp_err.h"
  13. #include "driver/i2c_master.h"
  14. #include "esp_io_expander.h"
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. /**
  19. * @brief Create a TCA9554(A) IO expander object
  20. *
  21. * @param[in] i2c_bus I2C bus handle. Obtained from `i2c_new_master_bus()`
  22. * @param[in] dev_addr I2C device address of chip. Can be `ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_XXX` or `ESP_IO_EXPANDER_I2C_TCA9554A_ADDRESS_XXX`.
  23. * @param[out] handle_ret Handle to created IO expander object
  24. *
  25. * @return
  26. * - ESP_OK: Success, otherwise returns ESP_ERR_xxx
  27. */
  28. esp_err_t esp_io_expander_new_i2c_tca9554(i2c_master_bus_handle_t i2c_bus, uint32_t dev_addr, esp_io_expander_handle_t *handle_ret);
  29. /**
  30. * @brief I2C address of the TCA9554
  31. *
  32. * The 8-bit address format is as follows:
  33. *
  34. * (Slave Address)
  35. * ┌─────────────────┷─────────────────┐
  36. * ┌─────┐─────┐─────┐─────┐─────┐─────┐─────┐─────┐
  37. * | 0 | 1 | 0 | 0 | A2 | A1 | A0 | R/W |
  38. * └─────┘─────┘─────┘─────┘─────┘─────┘─────┘─────┘
  39. * └────────┯────────┘ └─────┯──────┘
  40. * (Fixed) (Hareware Selectable)
  41. *
  42. * And the 7-bit slave address is the most important data for users.
  43. * For example, if a chip's A0,A1,A2 are connected to GND, it's 7-bit slave address is 0100000b(0x20).
  44. * Then users can use `ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_000` to init it.
  45. */
  46. #define ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_000 (0x20)
  47. #define ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_001 (0x21)
  48. #define ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_010 (0x22)
  49. #define ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_011 (0x23)
  50. #define ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_100 (0x24)
  51. #define ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_101 (0x25)
  52. #define ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_110 (0x26)
  53. #define ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_111 (0x27)
  54. /**
  55. * @brief I2C address of the TCA9554A
  56. *
  57. * The 8-bit address format is as follows:
  58. *
  59. * (Slave Address)
  60. * ┌─────────────────┷─────────────────┐
  61. * ┌─────┐─────┐─────┐─────┐─────┐─────┐─────┐─────┐
  62. * | 0 | 1 | 1 | 1 | A2 | A1 | A0 | R/W |
  63. * └─────┘─────┘─────┘─────┘─────┘─────┘─────┘─────┘
  64. * └────────┯────────┘ └─────┯──────┘
  65. * (Fixed) (Hareware Selectable)
  66. *
  67. * And the 7-bit slave address is the most important data for users.
  68. * For example, if a chip's A0,A1,A2 are connected to GND, it's 7-bit slave address is 0111000b(0x38).
  69. * Then users can use `ESP_IO_EXPANDER_I2C_TCA9554A_ADDRESS_000` to init it.
  70. */
  71. #define ESP_IO_EXPANDER_I2C_TCA9554A_ADDRESS_000 (0x38)
  72. #define ESP_IO_EXPANDER_I2C_TCA9554A_ADDRESS_001 (0x39)
  73. #define ESP_IO_EXPANDER_I2C_TCA9554A_ADDRESS_010 (0x3A)
  74. #define ESP_IO_EXPANDER_I2C_TCA9554A_ADDRESS_011 (0x3B)
  75. #define ESP_IO_EXPANDER_I2C_TCA9554A_ADDRESS_100 (0x3C)
  76. #define ESP_IO_EXPANDER_I2C_TCA9554A_ADDRESS_101 (0x3D)
  77. #define ESP_IO_EXPANDER_I2C_TCA9554A_ADDRESS_110 (0x3E)
  78. #define ESP_IO_EXPANDER_I2C_TCA9554A_ADDRESS_111 (0x3F)
  79. #ifdef __cplusplus
  80. }
  81. #endif