Skip to content

Commit e5378da

Browse files
committed
Update the example to show how to use the CH422G
1 parent c118e4b commit e5378da

File tree

6 files changed

+43
-26
lines changed

6 files changed

+43
-26
lines changed

CHANGELOG.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
# ChangeLog
22

3-
## v0.0.1 - 2023-09-20
3+
## v0.0.3 - 2024-05-07
44

55
### Enhancements:
66

7-
* Support for various IO expander chips.
8-
* Support to control individual IO in the same way as Arduino
9-
* Support to control multiple IOs at the same time.
7+
* Add support for CH422G from Waveshare (@lboue)
8+
* Update the example to show how to use the CH422G
109

1110
## v0.0.2 - 2023-10-07
1211

1312
### Bug Fixes:
1413

1514
* Correct library name in `sentence` field of metadata
15+
16+
## v0.0.1 - 2023-09-20
17+
18+
### Enhancements:
19+
20+
* Support for various IO expander chips.
21+
* Support to control individual IO in the same way as Arduino
22+
* Support to control multiple IOs at the same time.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ ESP32_IO_Expander encapsulates various components from the [Espressif Components
2020
| [TCA95xx (8bit)](https://components.espressif.com/components/espressif/esp_io_expander_tca9554) | 1.0.1 |
2121
| [TCA95xx (16bit)](https://components.espressif.com/components/espressif/esp_io_expander_tca95xx_16bit) | 1.0.0 |
2222
| [HT8574](https://components.espressif.com/components/espressif/esp_io_expander_ht8574) | 1.0.0 |
23+
| CH422G | x |
2324

2425
## Dependencies Version
2526

2627
| **Name** | **Version** |
2728
| ----------------------------------------------------------- | ----------- |
28-
| ESP32_IO_Expander | v0.x.x |
2929
| [arduino-esp32](https://github.com/espressif/arduino-esp32) | >= v2.0.9 |
3030

3131
## How to Use

examples/TestFunctions/TestFunctions.ino

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
11
#include <Arduino.h>
22
#include <ESP_IOExpander_Library.h>
33

4-
#define EXAMPLE_I2C_NUM (0)
5-
#define EXAMPLE_I2C_SDA_PIN (8)
6-
#define EXAMPLE_I2C_SCL_PIN (18)
7-
84
/**
95
* Create an ESP_IOExpander object, Currently supports:
10-
* - TCA95xx (8bit)
11-
* - TCA95xx (16bit)
6+
* - TCA95xx_8bit
7+
* - TCA95xx_16bit
128
* - HT8574
9+
* - CH422G
1310
*/
14-
ESP_IOExpander *expander = new ESP_IOExpander_TCA95xx_8bit(EXAMPLE_I2C_NUM, ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_000, EXAMPLE_I2C_SCL_PIN, EXAMPLE_I2C_SDA_PIN);
11+
#define EXAMPLE_CHIP_NAME TCA95xx_8bit
12+
#define EXAMPLE_I2C_NUM (0)
13+
#define EXAMPLE_I2C_SDA_PIN (8)
14+
#define EXAMPLE_I2C_SCL_PIN (18)
15+
16+
#define _EXAMPLE_CHIP_CLASS(name, ...) ESP_IOExpander_##name(__VA_ARGS__)
17+
#define EXAMPLE_CHIP_CLASS(name, ...) _EXAMPLE_CHIP_CLASS(name, ##__VA_ARGS__)
18+
19+
ESP_IOExpander *expander = NULL;
1520

1621
void setup()
1722
{
1823
Serial.begin(115200);
1924
Serial.println("Test begin");
2025

26+
expander = new EXAMPLE_CHIP_CLASS(EXAMPLE_CHIP_NAME,
27+
(i2c_port_t)EXAMPLE_I2C_NUM, ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_000,
28+
EXAMPLE_I2C_SCL_PIN, EXAMPLE_I2C_SDA_PIN);
2129
expander->init();
2230
expander->begin();
2331

@@ -68,5 +76,5 @@ void loop()
6876
Serial.print(", ");
6977
Serial.println(level[3]);
7078

71-
sleep(1);
79+
delay(1000);
7280
}

library.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name=ESP32_IO_Expander
2-
version=0.0.2
2+
version=0.0.3
33
author=lzw655
44
maintainer=espressif
55
sentence=ESP32_IO_Expander is a library designed for driving IO expander chips using ESP32 SoCs
6-
paragraph=Currently support TCA95xx(8bit), TCA95xx(16bit), HT8574
6+
paragraph=Currently support TCA95xx(8bit), TCA95xx(16bit), HT8574, CH422G
77
category=Other
88
architectures=esp32
99
url=https://github.com/esp-arduino-libs/ESP32_IO_Expander

src/chip/CH422G.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
*/
@@ -21,6 +21,10 @@
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
102105
static 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
122124
static 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)),

src/chip/CH422G.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
*/

0 commit comments

Comments
 (0)