11/*
2- * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
2+ * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
33 *
44 * SPDX-License-Identifier: Apache-2.0
55 */
2121
2222#define IO_COUNT (8 )
2323
24+ /* Register address */
25+ #define CH422G_REG_IN (0x26 )
26+ #define CH422G_REG_OUT (0x38 )
27+
2428/* Default register value on power-up */
2529#define DIR_REG_DEFAULT_VAL (0xff )
2630#define OUT_REG_DEFAULT_VAL (0xdf )
@@ -98,17 +102,16 @@ static esp_err_t esp_io_expander_new_i2c_ch422g(i2c_port_t i2c_num, uint32_t i2c
98102 return ret;
99103}
100104
101- #define CH422G_REG_IN 0x26
102105static esp_err_t read_input_reg (esp_io_expander_handle_t handle, uint32_t *value)
103106{
104- esp_io_expander_ch422g_t *ch422g = (esp_io_expander_ch422g_t *)__containerof (handle, esp_io_expander_ch422g_t , base);
107+ esp_io_expander_ch422g_t *ch422g = (esp_io_expander_ch422g_t *)__containerof (handle, esp_io_expander_ch422g_t , base);
105108
106109 uint8_t temp = 0 ;
107-
108- ESP_RETURN_ON_ERROR (
110+
111+ ESP_RETURN_ON_ERROR (
109112 i2c_master_read_from_device (ch422g->i2c_num , ch422g->i2c_address , &temp, 1 , pdMS_TO_TICKS (I2C_TIMEOUT_MS)),
110113 TAG, " Read input reg failed" );
111-
114+
112115 // *INDENT-OFF*
113116 ESP_RETURN_ON_ERROR (
114117 i2c_master_read_from_device (ch422g->i2c_num , CH422G_REG_IN, &temp, 1 , pdMS_TO_TICKS (I2C_TIMEOUT_MS)),
@@ -118,17 +121,16 @@ static esp_err_t read_input_reg(esp_io_expander_handle_t handle, uint32_t *value
118121 return ESP_OK;
119122}
120123
121- #define CH422G_REG_OUT 0x38
122124static esp_err_t write_output_reg (esp_io_expander_handle_t handle, uint32_t value)
123125{
124126 esp_io_expander_ch422g_t *ch422g = (esp_io_expander_ch422g_t *)__containerof (handle, esp_io_expander_ch422g_t , base);
125127 value &= 0xff ;
126128
127- uint8_t out_temp = 0x01 ;
128- ESP_RETURN_ON_ERROR (
129+ uint8_t out_temp = 0x01 ;
130+ ESP_RETURN_ON_ERROR (
129131 i2c_master_write_to_device (ch422g->i2c_num , ch422g->i2c_address , &out_temp, 1 , pdMS_TO_TICKS (I2C_TIMEOUT_MS)),
130132 TAG, " Write output reg failed" );
131-
133+
132134 uint8_t data = (uint8_t )value;
133135 ESP_RETURN_ON_ERROR (
134136 i2c_master_write_to_device (ch422g->i2c_num , CH422G_REG_OUT, &data, 1 , pdMS_TO_TICKS (I2C_TIMEOUT_MS)),
0 commit comments