tca9555_driver.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "tca9555_driver.h"
  2. #include "esp_log.h"
  3. #include "bsp_board.h"
  4. esp_io_expander_handle_t io_expander = NULL;
  5. void tca9555_driver_init(void)
  6. {
  7. i2c_master_bus_handle_t i2c_bus = esp_ret_i2c_handle();
  8. esp_err_t ret = esp_io_expander_new_i2c_tca95xx_16bit(i2c_bus, ESP_IO_EXPANDER_I2C_TCA9555_ADDRESS_000, &io_expander);
  9. /* Test output level function */
  10. ret = esp_io_expander_set_dir(io_expander, (IO_EXPANDER_PIN_NUM_0 | IO_EXPANDER_PIN_NUM_1 | IO_EXPANDER_PIN_NUM_5 | IO_EXPANDER_PIN_NUM_6 | IO_EXPANDER_PIN_NUM_8), IO_EXPANDER_OUTPUT);
  11. if(ret != ESP_OK){
  12. printf("EXIO Mode setting failure!!\r\n");
  13. }
  14. ret = esp_io_expander_set_dir(io_expander, (IO_EXPANDER_PIN_NUM_2 | IO_EXPANDER_PIN_NUM_9 | IO_EXPANDER_PIN_NUM_10 | IO_EXPANDER_PIN_NUM_11), IO_EXPANDER_INPUT);
  15. if(ret != ESP_OK){
  16. printf("EXIO Mode setting failure!!\r\n");
  17. }
  18. }
  19. /********************************************************** Set the EXIO output status **********************************************************/
  20. void Set_EXIO(uint32_t Pin,uint8_t State) // Sets the level state of the Pin without affecting the other pins(PIN:1~8)
  21. {
  22. esp_err_t ret;
  23. ret = esp_io_expander_set_level(io_expander, Pin, State);
  24. if(ret != ESP_OK){
  25. printf("EXIO level setting failure!!\r\n");
  26. }
  27. }
  28. /********************************************************** Read EXIO status **********************************************************/
  29. bool Read_EXIO(uint32_t Pin) // Read the level of the TCA9555PWR Pin
  30. {
  31. esp_err_t ret;
  32. uint32_t input_level_mask = 0;
  33. ret = esp_io_expander_get_level(io_expander, Pin, &input_level_mask);
  34. if(ret != ESP_OK){
  35. printf("EXIO level reading failure!!\r\n");
  36. }
  37. bool bitStatus = input_level_mask & Pin;
  38. return bitStatus;
  39. }