Skip to content

Commit a227c60

Browse files
committed
feat(repo): refactor with esp-lib-utils
1 parent bccbedd commit a227c60

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1969
-1239
lines changed

.codespellrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
[codespell]
2-
skip = ./src/touch/base/esp_lcd_touch_xpt2046.c

.github/workflows/build_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
container: espressif/idf:${{ matrix.idf_ver }}
1616
steps:
1717
- uses: actions/checkout@v3
18-
- name: Build ESP_IOExpander Test Application
18+
- name: Build Test Application
1919
env:
2020
IDF_TARGET: ${{ matrix.idf_target }}
2121
working-directory: test_apps

README.md

Lines changed: 90 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,62 +2,106 @@
22

33
**Latest Arduino Library Version**: [![GitHub Release](https://img.shields.io/github/v/release/esp-arduino-libs/ESP32_IO_Expander)](https://github.com/esp-arduino-libs/ESP32_IO_Expander/releases)
44

5-
**Latest Espressif Component Version**: [![Espressif Release](https://components.espressif.com/components/espressif/ESP32_IO_Expander/badge.svg)](https://components.espressif.com/components/espressif/ESP32_IO_Expander)
5+
**Latest Espressif Component Version**: [![Espressif Release](https://components.espressif.com/components/espressif/esp32_io_expander/badge.svg)](https://components.espressif.com/components/espressif/esp32_io_expander)
66

77
# ESP32_IO_Expander
88

9-
ESP32_IO_Expander is a library designed for driving [IO expander chips](#supported-drivers) using ESP32 SoCs.
9+
## Overview
10+
11+
`ESP32_IO_Expander` is a library designed for driving [IO expander chips](#supported-drivers) using ESP SoCs. It encapsulates various components from the [Espressif Components Registry](https://components.espressif.com/) and includes the following features:
12+
13+
* Supports various IO expander chips, such as TCA95xx, HT8574, and CH422G.
14+
* Supports controlling individual IO pin with functions like `pinMode()`, `digitalWrite()`, and `digitalRead()`.
15+
* Supports controlling multiple IO pins simultaneously with functions like `multiPinMode()`, `multiDigitalWrite()`, and `multiDigitalRead()`.
16+
* Compatible with the `Arduino`, `ESP-IDF` and `MicroPython` for compilation.
17+
18+
## Table of Contents
19+
20+
- [ESP32\_IO\_Expander](#esp32_io_expander)
21+
- [Overview](#overview)
22+
- [Table of Contents](#table-of-contents)
23+
- [Supported Drivers](#supported-drivers)
24+
- [How to Use](#how-to-use)
25+
- [ESP-IDF Framework](#esp-idf-framework)
26+
- [Dependencies and Versions](#dependencies-and-versions)
27+
- [Adding to Project](#adding-to-project)
28+
- [Configuration Instructions](#configuration-instructions)
29+
- [Arduino IDE](#arduino-ide)
30+
- [Dependencies and Versions](#dependencies-and-versions-1)
31+
- [Installing the Library](#installing-the-library)
32+
- [Configuration Instructions](#configuration-instructions-1)
33+
- [Examples](#examples)
34+
- [Detailed Usage](#detailed-usage)
35+
- [FAQ](#faq)
36+
- [Where is the directory for Arduino libraries?](#where-is-the-directory-for-arduino-libraries)
37+
- [How to Install ESP32\_IO\_Expander in Arduino IDE?](#how-to-install-esp32_io_expander-in-arduino-ide)
1038

11-
ESP32_IO_Expander encapsulates various components from the [Espressif Components Registry](https://components.espressif.com/). It is developed based on [arduino-esp32](https://github.com/espressif/arduino-esp32) or [esp-idf](https://github.com/espressif/esp-idf), and can be easily downloaded and integrated into the Arduino IDE.
39+
## Supported Drivers
1240

13-
## Features
41+
| **Driver** | **Version** |
42+
| ---------------------------------------------------------------------------------------------------- | ----------- |
43+
| [esp_io_expander](https://components.espressif.com/components/espressif/esp_io_expander) | 1.0.1 |
44+
| [TCA95XX_8BIT](https://components.espressif.com/components/espressif/esp_io_expander_tca9554) | 1.0.1 |
45+
| [TCA95XX_16BIT](https://components.espressif.com/components/espressif/esp_io_expander_tca95xx_16bit) | 1.0.0 |
46+
| [HT8574](https://components.espressif.com/components/espressif/esp_io_expander_ht8574) | 1.0.0 |
47+
| CH422G | x |
1448

15-
* Supports various IO expander chips.
16-
* Supports controlling individual IO pin (using pinMode(), digitalRead(), and digitalWrite() functions).
17-
* Supports controlling multiple IO pins simultaneously.
18-
* Supports building on the Arduino IDE and the ESP-IDF framework.
49+
## How to Use
1950

20-
## Supported Drivers
51+
### ESP-IDF Framework
2152

22-
| **Driver** | **Version** |
23-
| ------------------------------------------------------------------------------------------------------ | ----------- |
24-
| [esp_io_expander](https://components.espressif.com/components/espressif/esp_io_expander) | 1.0.1 |
25-
| [TCA95xx (8bit)](https://components.espressif.com/components/espressif/esp_io_expander_tca9554) | 1.0.1 |
26-
| [TCA95xx (16bit)](https://components.espressif.com/components/espressif/esp_io_expander_tca95xx_16bit) | 1.0.0 |
27-
| [HT8574](https://components.espressif.com/components/espressif/esp_io_expander_ht8574) | 1.0.0 |
28-
| CH422G | x |
53+
#### Dependencies and Versions
2954

30-
## Dependencies Version
55+
| **Dependency** | **Version** |
56+
| ------------------------------------------------------------------ | -------------------- |
57+
| [esp-idf](https://github.com/espressif/esp-idf) | >= 5.1 |
58+
| [esp-lib-utils](https://github.com/esp-arduino-libs/esp-lib-utils) | >= 0.1.0 && <= 0.2.0 |
3159

32-
### Arduino
60+
#### Adding to Project
3361

34-
| **Name** | **Version** |
35-
| ----------------------------------------------------------- | ----------- |
36-
| [arduino-esp32](https://github.com/espressif/arduino-esp32) | >= v3.0.0 |
62+
`ESP32_IO_Expander` has been uploaded to the [Espressif Component Registry](https://components.espressif.com/), and users can add it to their project using the `idf.py add-dependency` command, for example:
3763

38-
### ESP-IDF
64+
```bash
65+
idf.py add-dependency "espressif/ESP32_IO_Expander"
66+
```
3967

40-
| **Name** | **Version** |
41-
| ----------------------------------------------- | ----------- |
42-
| [esp-idf](https://github.com/espressif/esp-idf) | >= v5.1 |
68+
Alternatively, users can create or modify the *idf_component.yml* file in the project directory. For more details, please refer to the [Espressif Documentation - IDF Component Manager](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/tools/idf-component-manager.html).
4369

44-
## How to Use
70+
#### Configuration Instructions
71+
72+
Since `ESP32_IO_Expander` depends on the `esp-lib-utils` library which implements the `logging`, `checking`, and `memory` functions, to configure it when using ESP-IDF, please refer to the [instructions](https://github.com/esp-arduino-libs/esp-lib-utils#configuration-instructions).
73+
74+
### Arduino IDE
75+
76+
#### Dependencies and Versions
77+
78+
| **Dependency** | **Version** |
79+
| ------------------------------------------------------------------ | -------------------- |
80+
| [arduino-esp32](https://github.com/espressif/arduino-esp32) | >= v3.0.0 |
81+
| [esp-lib-utils](https://github.com/esp-arduino-libs/esp-lib-utils) | >= 0.1.0 && <= 0.2.0 |
4582

46-
For information on how to use the library in the Arduino IDE, please refer to the documentation for [Arduino IDE v1.x.x](https://docs.arduino.cc/software/ide-v1/tutorials/installing-libraries) or [Arduino IDE v2.x.x](https://docs.arduino.cc/software/ide-v2/tutorials/ide-v2-installing-a-library).
83+
#### Installing the Library
84+
85+
For installation of the `ESP32_IO_Expander` library, refer to [How to Install ESP32_IO_Expander in Arduino IDE](#how-to-install-ESP32_IO_Expander-in-arduino-ide).
86+
87+
#### Configuration Instructions
88+
89+
Since `ESP32_IO_Expander` depends on the `esp-lib-utils` library which implements the `logging`, `checking`, and `memory` functions, to configure it when using Arduino, please refer to the [instructions](https://github.com/esp-arduino-libs/esp-lib-utils#configuration-instructions-1).
4790

4891
### Examples
4992

50-
* [Test Functions](examples/TestFunctions): Demonstrates how to use ESP32_IO_Expander and test all functions.
51-
* [Test CH422G](examples/TestCH422G): Demonstrates how to use ESP32_IO_Expander with the CH422G chip.
93+
* [General](examples/general): Demonstrates how to use `ESP32_IO_Expander` and test general functions.
94+
* [CH422G](examples/ch422g): Demonstrates how to use `ESP32_IO_Expander` specifically with the CH422G chip.
5295

5396
### Detailed Usage
5497

5598
```cpp
56-
#include <ESP_IOExpander_Library.h>
99+
#include <esp_io_expander.hpp>
57100

58-
// Create and initialize an ESP_IOExpander object according to the chip type
59-
ESP_IOExpander *expander = new ESP_IOExpander_TCA95xx_8bit(EXAMPLE_I2C_NUM_0, ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_000,
60-
EXAMPLE_I2C_SCL_PIN, EXAMPLE_I2C_SDA_PIN);
101+
// Create and initialize the IO expander chip, such as TCA95XX_8BIT
102+
esp_expander::Base *expander = new esp_expander::TCA95XX_8BIT(
103+
EXAMPLE_I2C_SCL_PIN, EXAMPLE_I2C_SDA_PIN, ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_000
104+
);
61105
expander->init();
62106
expander->begin();
63107

@@ -75,6 +119,18 @@ expander->multiDigitalWrite(IO_EXPANDER_PIN_NUM_0 | IO_EXPANDER_PIN_NUM_1, LOW);
75119
expander->multiPinMode(IO_EXPANDER_PIN_NUM_0 | IO_EXPANDER_PIN_NUM_1, INPUT);
76120
uint32_t level = expander->multiDigitalRead(IO_EXPANDER_PIN_NUM_2 | IO_EXPANDER_PIN_NUM_3);
77121

78-
// Release the ESP_IOExpander object
122+
// Release the Base object
79123
delete expander;
80124
```
125+
126+
## FAQ
127+
128+
### Where is the directory for Arduino libraries?
129+
130+
Users can find and modify the directory path for Arduino libraries by selecting `File` > `Preferences` > `Settings` > `Sketchbook location` from the menu bar in the Arduino IDE.
131+
132+
### How to Install ESP32_IO_Expander in Arduino IDE?
133+
134+
- **If users want to install online**, navigate to `Sketch` > `Include Library` > `Manage Libraries...` in the Arduino IDE, then search for `ESP32_IO_Expander` and click the `Install` button to install it.
135+
- **If users want to install manually**, download the required version of the `.zip` file from [ESP32_IO_Expander](https://github.com/esp-arduino-libs/ESP32_IO_Expander), then navigate to `Sketch` > `Include Library` > `Add .ZIP Library...` in the Arduino IDE, select the downloaded `.zip` file, and click `Open` to install it.
136+
- Users can also refer to the guides on library installation in the [Arduino IDE v1.x.x](https://docs.arduino.cc/software/ide-v1/tutorials/installing-libraries) or [Arduino IDE v2.x.x](https://docs.arduino.cc/software/ide-v2/tutorials/ide-v2-installing-a-library) documentation.

examples/TestFunctions/TestFunctions.ino

Lines changed: 0 additions & 88 deletions
This file was deleted.

examples/TestCH422G/TestCH422G.ino renamed to examples/ch422g/ch422g.ino

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* | Supported IO Expanders | CH422G |
2+
* | Supported IO Expanders | CH422G |
33
* | ------------------------- | ------ |
44
*
55
* # CH422G Test Example
@@ -38,25 +38,23 @@
3838
*/
3939

4040
#include <Arduino.h>
41-
#include <ESP_IOExpander_Library.h>
41+
#include <esp_io_expander.hpp>
4242

43-
#define EXAMPLE_I2C_NUM (0)
4443
#define EXAMPLE_I2C_SDA_PIN (8)
4544
#define EXAMPLE_I2C_SCL_PIN (9)
4645
#define EXAMPLE_I2C_ADDR (ESP_IO_EXPANDER_I2C_CH422G_ADDRESS)
4746

48-
ESP_IOExpander_CH422G *expander = NULL;
47+
esp_expander::CH422G *expander = NULL;
4948

5049
void setup() {
5150
Serial.begin(115200);
5251
delay(1000);
5352
Serial.println("Test begin");
5453

55-
expander = new ESP_IOExpander_CH422G((i2c_port_t)EXAMPLE_I2C_NUM, EXAMPLE_I2C_ADDR, EXAMPLE_I2C_SCL_PIN, EXAMPLE_I2C_SDA_PIN);
54+
expander = new esp_expander::CH422G(EXAMPLE_I2C_SCL_PIN, EXAMPLE_I2C_SDA_PIN, EXAMPLE_I2C_ADDR);
5655
expander->init();
5756
expander->begin();
5857

59-
/* For CH422G */
6058
Serial.println("Set the OC pin to push-pull output mode.");
6159
expander->enableOC_PushPull();
6260

examples/general/general.ino

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#include <Arduino.h>
2+
#include <esp_io_expander.hpp>
3+
4+
/* The following default configurations are for the board 'Espressif: ESP32_S3_LCD_EV_BOARD_V1_5, TCA9554' */
5+
/**
6+
* Choose one of the following chip names:
7+
* - TCA95XX_8BIT
8+
* - TCA95XX_16BIT
9+
* - HT8574
10+
* - CH422G
11+
*/
12+
#define EXAMPLE_CHIP_NAME TCA95XX_8BIT
13+
#define EXAMPLE_I2C_SDA_PIN (47)
14+
#define EXAMPLE_I2C_SCL_PIN (48)
15+
#define EXAMPLE_I2C_ADDR (ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_000) // Change this value according to the
16+
// hardware address
17+
18+
#define _EXAMPLE_CHIP_CLASS(name, ...) esp_expander::name(__VA_ARGS__)
19+
#define EXAMPLE_CHIP_CLASS(name, ...) _EXAMPLE_CHIP_CLASS(name, ##__VA_ARGS__)
20+
21+
esp_expander::Base *expander = nullptr;
22+
23+
void setup()
24+
{
25+
Serial.begin(115200);
26+
Serial.println("Test begin");
27+
28+
/**
29+
* Taking `TCA95XX_8BIT` as an example, the following is the code after macro expansion:
30+
* expander = new esp_expander::TCA95XX_8BIT((48), (47), (0x20))
31+
*/
32+
expander = new EXAMPLE_CHIP_CLASS(
33+
EXAMPLE_CHIP_NAME, EXAMPLE_I2C_SCL_PIN, EXAMPLE_I2C_SDA_PIN, ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_000
34+
);
35+
expander->init();
36+
expander->begin();
37+
38+
/* For CH422G */
39+
// static_cast<esp_expander::CH422G *>(expander)->enableOC_OpenDrain();
40+
// static_cast<esp_expander::CH422G *>(expander)->enableOC_PushPull();
41+
// static_cast<esp_expander::CH422G *>(expander)->enableAllIO_Input();
42+
// static_cast<esp_expander::CH422G *>(expander)->enableAllIO_Output();
43+
44+
Serial.println("Original status:");
45+
expander->printStatus();
46+
47+
expander->pinMode(0, OUTPUT);
48+
expander->pinMode(1, OUTPUT);
49+
expander->multiPinMode(IO_EXPANDER_PIN_NUM_2 | IO_EXPANDER_PIN_NUM_3, OUTPUT);
50+
51+
Serial.println("Set pint 0-3 to output mode:");
52+
expander->printStatus();
53+
54+
expander->digitalWrite(0, LOW);
55+
expander->digitalWrite(1, LOW);
56+
expander->multiDigitalWrite(IO_EXPANDER_PIN_NUM_2 | IO_EXPANDER_PIN_NUM_3, LOW);
57+
58+
Serial.println("Set pint 0-3 to low level:");
59+
expander->printStatus();
60+
61+
expander->pinMode(0, INPUT);
62+
expander->pinMode(1, INPUT);
63+
expander->multiPinMode(IO_EXPANDER_PIN_NUM_2 | IO_EXPANDER_PIN_NUM_3, INPUT);
64+
65+
Serial.println("Set pint 0-3 to input mode:");
66+
expander->printStatus();
67+
}
68+
69+
int level[4] = {0, 0, 0, 0};
70+
uint32_t level_temp;
71+
72+
void loop()
73+
{
74+
// Read pin 0-3 level
75+
level[0] = expander->digitalRead(0);
76+
level[1] = expander->digitalRead(1);
77+
level_temp = expander->multiDigitalRead(IO_EXPANDER_PIN_NUM_2 | IO_EXPANDER_PIN_NUM_3);
78+
level[2] = level_temp & IO_EXPANDER_PIN_NUM_2 ? HIGH : LOW;
79+
level[3] = level_temp & IO_EXPANDER_PIN_NUM_3 ? HIGH : LOW;
80+
Serial.printf("Pin level: %d, %d, %d, %d\n", level[0], level[1], level[2], level[3]);
81+
82+
delay(1000);
83+
}

idf_component.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
version: "0.1.0"
2-
description: ESP32_IO_Expander is a library designed for driving IO expander chips using ESP32 SoCs
1+
version: "1.0.0"
2+
description: ESP32_IO_Expander is a library designed for driving IO expander chips using ESP SoCs
33
url: https://github.com/esp-arduino-libs/ESP32_IO_Expander
44
repository: https://github.com/esp-arduino-libs/ESP32_IO_Expander.git
55
issues: https://github.com/esp-arduino-libs/ESP32_IO_Expander/issues
66
dependencies:
77
idf: ">=5.1"
8+
espressif/esp-lib-utils:
9+
version: ">=0.1.0,<=0.2.0"
10+
public: true

0 commit comments

Comments
 (0)