From 86c81f6101d1dbc6cb04ceeb351f710527cf4db5 Mon Sep 17 00:00:00 2001 From: Liu Zhongwei Date: Mon, 7 Jul 2025 15:44:30 +0800 Subject: [PATCH 1/2] fix(port): fix discarded qualifiers warning @isthaison (#22) Closes https://github.com/esp-arduino-libs/ESP32_IO_Expander/issues/22 --- idf_component.yml | 2 +- library.properties | 2 +- src/port/esp_io_expander.c | 2 +- src/port/esp_io_expander_ht8574.c | 2 +- src/port/esp_io_expander_tca9554.c | 2 +- src/port/esp_io_expander_tca95xx_16bit.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/idf_component.yml b/idf_component.yml index 3cd47cf..4ad0e50 100644 --- a/idf_component.yml +++ b/idf_component.yml @@ -1,4 +1,4 @@ -version: "1.1.0" +version: "1.1.1" description: ESP32_IO_Expander is a library designed for driving IO expander chips using ESP SoCs url: https://github.com/esp-arduino-libs/ESP32_IO_Expander repository: https://github.com/esp-arduino-libs/ESP32_IO_Expander.git diff --git a/library.properties b/library.properties index 46fc8ad..4065fba 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ESP32_IO_Expander -version=1.1.0 +version=1.1.1 author=espressif maintainer=espressif sentence=ESP32_IO_Expander is a library designed for driving IO expander chips using ESP SoCs diff --git a/src/port/esp_io_expander.c b/src/port/esp_io_expander.c index d93f50b..f442168 100644 --- a/src/port/esp_io_expander.c +++ b/src/port/esp_io_expander.c @@ -26,7 +26,7 @@ typedef enum { REG_DIRECTION, } reg_type_t; -static char *TAG = "io_expander"; +static const char *TAG = "io_expander"; static esp_err_t write_reg(esp_io_expander_handle_t handle, reg_type_t reg, uint32_t value); static esp_err_t read_reg(esp_io_expander_handle_t handle, reg_type_t reg, uint32_t *value); diff --git a/src/port/esp_io_expander_ht8574.c b/src/port/esp_io_expander_ht8574.c index bbfd79a..840992f 100644 --- a/src/port/esp_io_expander_ht8574.c +++ b/src/port/esp_io_expander_ht8574.c @@ -40,7 +40,7 @@ typedef struct { } regs; } esp_io_expander_ht8574_t; -static char *TAG = "ht8574"; +static const char *TAG = "ht8574"; static esp_err_t read_input_reg(esp_io_expander_handle_t handle, uint32_t *value); static esp_err_t write_output_reg(esp_io_expander_handle_t handle, uint32_t value); diff --git a/src/port/esp_io_expander_tca9554.c b/src/port/esp_io_expander_tca9554.c index 3732bd7..ef17872 100644 --- a/src/port/esp_io_expander_tca9554.c +++ b/src/port/esp_io_expander_tca9554.c @@ -45,7 +45,7 @@ typedef struct { } regs; } esp_io_expander_tca9554_t; -static char *TAG = "tca9554"; +static const char *TAG = "tca9554"; static esp_err_t read_input_reg(esp_io_expander_handle_t handle, uint32_t *value); static esp_err_t write_output_reg(esp_io_expander_handle_t handle, uint32_t value); diff --git a/src/port/esp_io_expander_tca95xx_16bit.c b/src/port/esp_io_expander_tca95xx_16bit.c index b9f2f17..4062d31 100644 --- a/src/port/esp_io_expander_tca95xx_16bit.c +++ b/src/port/esp_io_expander_tca95xx_16bit.c @@ -45,7 +45,7 @@ typedef struct { } regs; } esp_io_expander_tca95xx_16bit_t; -static char *TAG = "tca95xx_16"; +static const char *TAG = "tca95xx_16"; static esp_err_t read_input_reg(esp_io_expander_handle_t handle, uint32_t *value); static esp_err_t write_output_reg(esp_io_expander_handle_t handle, uint32_t value); From 8cb62dbc69965ab98fd77eb924ecf9f9fcb87edb Mon Sep 17 00:00:00 2001 From: Liu Zhongwei Date: Mon, 7 Jul 2025 15:44:45 +0800 Subject: [PATCH 2/2] feat(ch422g): support enter/exit sleep --- .github/workflows/arduino_lint.yml | 3 ++ .github/workflows/build_test.yml | 3 ++ .github/workflows/issue_comment.yml | 24 -------------- .github/workflows/new_issues.yml | 24 -------------- .github/workflows/new_prs.yml | 29 ----------------- .github/workflows/pre-commit.yml | 2 +- .github/workflows/upload_component.yml | 2 +- CHANGELOG.md | 10 ++++++ src/chip/esp_expander_ch422g.cpp | 30 ++++++++++++++++++ src/chip/esp_expander_ch422g.hpp | 14 +++++++++ src/port/esp_io_expander_ch422g.c | 43 +++++++++++++++++++++++--- src/port/esp_io_expander_ch422g.h | 4 +++ 12 files changed, 104 insertions(+), 84 deletions(-) delete mode 100644 .github/workflows/issue_comment.yml delete mode 100644 .github/workflows/new_issues.yml delete mode 100644 .github/workflows/new_prs.yml diff --git a/.github/workflows/arduino_lint.yml b/.github/workflows/arduino_lint.yml index 0a6b9a8..a0f4707 100644 --- a/.github/workflows/arduino_lint.yml +++ b/.github/workflows/arduino_lint.yml @@ -4,6 +4,9 @@ on: workflow_dispatch: pull_request: types: [opened, reopened, synchronize] + push: + branches: + - master jobs: lint: diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index 9d3c04c..e87ca79 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -4,6 +4,9 @@ on: workflow_dispatch: pull_request: types: [opened, reopened, synchronize] + push: + branches: + - master jobs: build: diff --git a/.github/workflows/issue_comment.yml b/.github/workflows/issue_comment.yml deleted file mode 100644 index 3b6fcc1..0000000 --- a/.github/workflows/issue_comment.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: Sync issue comments to JIRA - -# This workflow will be triggered when new issue comment is created (including PR comments) -on: issue_comment - -# Limit to single concurrent run for workflows which can create Jira issues. -# Same concurrency group is used in new_issues.yml -concurrency: jira_issues - -jobs: - sync_issue_comments_to_jira: - name: Sync Issue Comments to Jira - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Sync issue comments to JIRA - uses: espressif/github-actions/sync_issues_to_jira@master - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - JIRA_PASS: ${{ secrets.JIRA_PASS }} - JIRA_PROJECT: ${{ secrets.JIRA_PROJECT }} - JIRA_COMPONENT: ${{ secrets.JIRA_COMPONENT }} - JIRA_URL: ${{ secrets.JIRA_URL }} - JIRA_USER: ${{ secrets.JIRA_USER }} diff --git a/.github/workflows/new_issues.yml b/.github/workflows/new_issues.yml deleted file mode 100644 index f0fa402..0000000 --- a/.github/workflows/new_issues.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: Sync issues to Jira - -# This workflow will be triggered when a new issue is opened -on: issues - -# Limit to single concurrent run for workflows which can create Jira issues. -# Same concurrency group is used in issue_comment.yml -concurrency: jira_issues - -jobs: - sync_issues_to_jira: - name: Sync issues to Jira - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Sync GitHub issues to Jira project - uses: espressif/github-actions/sync_issues_to_jira@master - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - JIRA_PASS: ${{ secrets.JIRA_PASS }} - JIRA_PROJECT: ${{ secrets.JIRA_PROJECT }} - JIRA_COMPONENT: ${{ secrets.JIRA_COMPONENT }} - JIRA_URL: ${{ secrets.JIRA_URL }} - JIRA_USER: ${{ secrets.JIRA_USER }} diff --git a/.github/workflows/new_prs.yml b/.github/workflows/new_prs.yml deleted file mode 100644 index 01d7fe2..0000000 --- a/.github/workflows/new_prs.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Sync remain PRs to Jira - -# This workflow will be triggered every hour, to sync remaining PRs (i.e. PRs with zero comment) to Jira project -# Note that, PRs can also get synced when new PR comment is created -on: - schedule: - - cron: "0 * * * *" - -# Limit to single concurrent run for workflows which can create Jira issues. -# Same concurrency group is used in issue_comment.yml -concurrency: jira_issues - -jobs: - sync_prs_to_jira: - name: Sync PRs to Jira - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Sync PRs to Jira project - uses: espressif/github-actions/sync_issues_to_jira@master - with: - cron_job: true - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - JIRA_PASS: ${{ secrets.JIRA_PASS }} - JIRA_PROJECT: ${{ secrets.JIRA_PROJECT }} - JIRA_COMPONENT: ${{ secrets.JIRA_COMPONENT }} - JIRA_URL: ${{ secrets.JIRA_URL }} - JIRA_USER: ${{ secrets.JIRA_USER }} diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 7111ea9..cc477db 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -11,4 +11,4 @@ jobs: steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 - - uses: pre-commit/action@v2.0.3 + - uses: pre-commit/action@v3.0.1 diff --git a/.github/workflows/upload_component.yml b/.github/workflows/upload_component.yml index 45e9b78..333c718 100644 --- a/.github/workflows/upload_component.yml +++ b/.github/workflows/upload_component.yml @@ -15,6 +15,6 @@ jobs: - name: Upload components to component service uses: espressif/upload-components-ci-action@v1 with: - name: "ESP32_IO_Expander" + name: "esp32_io_expander" namespace: "espressif" api_token: ${{ secrets.IDF_COMPONENT_API_TOKEN }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b1a2ff..4e14044 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # ChangeLog +## v1.1.1 - 2025-07-07 + +### Enhancements: + +* feat(ch422g): support enter/exit sleep + +### Bug Fixes: + +* fix(port): fix discarded qualifiers warning + ## v1.1.0 - 2025-02-07 ### Enhancements: diff --git a/src/chip/esp_expander_ch422g.cpp b/src/chip/esp_expander_ch422g.cpp index 1a0dcbd..dcf3223 100644 --- a/src/chip/esp_expander_ch422g.cpp +++ b/src/chip/esp_expander_ch422g.cpp @@ -104,4 +104,34 @@ bool CH422G::enableAllIO_Output(void) return true; } +bool CH422G::enterSleep(void) +{ + ESP_UTILS_LOG_TRACE_ENTER_WITH_THIS(); + + ESP_UTILS_CHECK_FALSE_RETURN(isOverState(State::BEGIN), false, "Not begun"); + + ESP_UTILS_CHECK_ERROR_RETURN( + esp_io_expander_ch422g_enter_sleep(device_handle), false, "Enter sleep failed" + ); + + ESP_UTILS_LOG_TRACE_EXIT_WITH_THIS(); + + return true; +} + +bool CH422G::exitSleep(void) +{ + ESP_UTILS_LOG_TRACE_ENTER_WITH_THIS(); + + ESP_UTILS_CHECK_FALSE_RETURN(isOverState(State::BEGIN), false, "Not begun"); + + ESP_UTILS_CHECK_ERROR_RETURN( + esp_io_expander_ch422g_exit_sleep(device_handle), false, "Exit sleep failed" + ); + + ESP_UTILS_LOG_TRACE_EXIT_WITH_THIS(); + + return true; +} + } // namespace esp_expander diff --git a/src/chip/esp_expander_ch422g.hpp b/src/chip/esp_expander_ch422g.hpp index ab54b04..c438bde 100644 --- a/src/chip/esp_expander_ch422g.hpp +++ b/src/chip/esp_expander_ch422g.hpp @@ -99,6 +99,20 @@ class CH422G: public Base { * @return true if success, otherwise false */ bool enableAllIO_Output(void); + + /** + * @brief Enter sleep mode + * + * @return true if success, otherwise false + */ + bool enterSleep(void); + + /** + * @brief Exit sleep mode + * + * @return true if success, otherwise false + */ + bool exitSleep(void); }; } // namespace esp_expander diff --git a/src/port/esp_io_expander_ch422g.c b/src/port/esp_io_expander_ch422g.c index 59c8d17..f16fd02 100644 --- a/src/port/esp_io_expander_ch422g.c +++ b/src/port/esp_io_expander_ch422g.c @@ -38,13 +38,14 @@ // Default: | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | // *INDENT-OFF* -#define REG_WR_OC_DEFAULT_VAL (0x0FUL) -#define REG_WR_IO_DEFAULT_VAL (0xFFUL) +#define REG_WR_OC_DEFAULT_VAL (0x0FU) +#define REG_WR_IO_DEFAULT_VAL (0xFFU) #define REG_OUT_DEFAULT_VAL ((REG_WR_OC_DEFAULT_VAL << 8) | REG_WR_IO_DEFAULT_VAL) -#define REG_DIR_DEFAULT_VAL (0xFFFUL) +#define REG_DIR_DEFAULT_VAL (0xFFFU) -#define REG_WR_SET_BIT_IO_OE (1 << 0) -#define REG_WR_SET_BIT_OD_EN (1 << 2) +#define REG_WR_SET_BIT_IO_OE (1U << 0) +#define REG_WR_SET_BIT_OD_EN (1U << 2) +#define REG_WR_SET_BIT_SLEEP (1U << 3) /** * @brief Device Structure Type @@ -171,6 +172,38 @@ esp_err_t esp_io_expander_ch422g_set_all_output(esp_io_expander_handle_t handle) return ESP_OK; } +esp_err_t esp_io_expander_ch422g_enter_sleep(esp_io_expander_handle_t handle) +{ + esp_io_expander_ch422g_t *ch422g = (esp_io_expander_ch422g_t *)__containerof(handle, esp_io_expander_ch422g_t, base); + uint8_t data = (uint8_t)(ch422g->regs.wr_set | REG_WR_SET_BIT_SLEEP); + + // WR-SET + ESP_RETURN_ON_ERROR( + i2c_master_write_to_device( + ch422g->i2c_num, CH422G_REG_WR_SET, &data, sizeof(data), pdMS_TO_TICKS(I2C_TIMEOUT_MS) + ), TAG, "Write WR_SET reg failed" + ); + ch422g->regs.wr_set = data; + + return ESP_OK; +} + +esp_err_t esp_io_expander_ch422g_exit_sleep(esp_io_expander_handle_t handle) +{ + esp_io_expander_ch422g_t *ch422g = (esp_io_expander_ch422g_t *)__containerof(handle, esp_io_expander_ch422g_t, base); + uint8_t data = (uint8_t)(ch422g->regs.wr_set & ~REG_WR_SET_BIT_SLEEP); + + // WR-SET + ESP_RETURN_ON_ERROR( + i2c_master_write_to_device( + ch422g->i2c_num, CH422G_REG_WR_SET, &data, sizeof(data), pdMS_TO_TICKS(I2C_TIMEOUT_MS) + ), TAG, "Write WR_SET reg failed" + ); + ch422g->regs.wr_set = data; + + return ESP_OK; +} + static esp_err_t read_input_reg(esp_io_expander_handle_t handle, uint32_t *value) { esp_io_expander_ch422g_t *ch422g = (esp_io_expander_ch422g_t *)__containerof(handle, esp_io_expander_ch422g_t, base); diff --git a/src/port/esp_io_expander_ch422g.h b/src/port/esp_io_expander_ch422g.h index 1aecf43..a312edf 100644 --- a/src/port/esp_io_expander_ch422g.h +++ b/src/port/esp_io_expander_ch422g.h @@ -48,6 +48,10 @@ esp_err_t esp_io_expander_ch422g_set_all_input(esp_io_expander_handle_t handle); esp_err_t esp_io_expander_ch422g_set_all_output(esp_io_expander_handle_t handle); +esp_err_t esp_io_expander_ch422g_enter_sleep(esp_io_expander_handle_t handle); + +esp_err_t esp_io_expander_ch422g_exit_sleep(esp_io_expander_handle_t handle); + #ifdef __cplusplus } #endif