-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(io_expander): support i2c ng
- Loading branch information
Showing
29 changed files
with
693 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 6 additions & 5 deletions
11
components/io_expander/esp_io_expander_ht8574/idf_component.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
dependencies: | ||
esp_io_expander: | ||
version: ^1.0.1 | ||
idf: '>=4.4.2' | ||
version: 2.0.0 | ||
description: ESP IO Expander - HT8574 | ||
url: https://github.com/espressif/esp-bsp/tree/master/components/io_expander/esp_io_expander_ht8574 | ||
version: 1.0.0 | ||
dependencies: | ||
idf: ">=5.2" | ||
esp_io_expander: | ||
version: "^1.0.1" | ||
public: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
components/io_expander/esp_io_expander_ht8574/test_apps/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# The following lines of boilerplate have to be in your project's CMakeLists | ||
# in this exact order for cmake to work correctly | ||
cmake_minimum_required(VERSION 3.5) | ||
set(COMPONENTS main) | ||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
project(test_app_ht8574) |
4 changes: 4 additions & 0 deletions
4
components/io_expander/esp_io_expander_ht8574/test_apps/main/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
idf_component_register( | ||
SRCS "test_app_ht8574.c" | ||
REQUIRES unity | ||
) |
6 changes: 6 additions & 0 deletions
6
components/io_expander/esp_io_expander_ht8574/test_apps/main/idf_component.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
## IDF Component Manager Manifest File | ||
dependencies: | ||
idf: ">=5.2" | ||
esp_io_expander_ht8574: | ||
version: "*" | ||
override_path: "../../../esp_io_expander_ht8574" |
126 changes: 126 additions & 0 deletions
126
components/io_expander/esp_io_expander_ht8574/test_apps/main/test_app_ht8574.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include "freertos/FreeRTOS.h" | ||
#include "freertos/task.h" | ||
#include "unity.h" | ||
#include "unity_test_runner.h" | ||
#include "unity_test_utils_memory.h" | ||
#include "esp_system.h" | ||
#include "esp_log.h" | ||
#include "driver/i2c_master.h" | ||
#include "esp_io_expander_ht8574.h" | ||
|
||
// Pinout for ESP32-S3-LCD-Ev-Board | ||
#define I2C_MASTER_SCL_IO 48 /*!< gpio number for I2C master clock */ | ||
#define I2C_MASTER_SDA_IO 47 /*!< gpio number for I2C master data */ | ||
#define I2C_MASTER_NUM I2C_NUM_0 /*!< I2C port number for master dev */ | ||
#define I2C_ADDRESS ESP_IO_EXPANDER_I2C_HT8574_ADDRESS_000 | ||
/*!< I2C address of slave dev */ | ||
|
||
#define TEST_LOOP_CNT 100 | ||
#define TEST_LOOP_DELAY_MS 50 | ||
#define TEST_OUTPUT_PINS (IO_EXPANDER_PIN_NUM_0 | IO_EXPANDER_PIN_NUM_1) | ||
#define TEST_INPUT_PINS (IO_EXPANDER_PIN_NUM_2 | IO_EXPANDER_PIN_NUM_3) | ||
|
||
static const char *TAG = "ht8574 test"; | ||
static esp_io_expander_handle_t io_expander = NULL; | ||
static i2c_master_bus_handle_t i2c_handle = NULL; | ||
|
||
static void i2c_bus_init(void) | ||
{ | ||
const i2c_master_bus_config_t bus_config = { | ||
.i2c_port = I2C_MASTER_NUM, | ||
.sda_io_num = I2C_MASTER_SDA_IO, | ||
.scl_io_num = I2C_MASTER_SCL_IO, | ||
.clk_source = I2C_CLK_SRC_DEFAULT, | ||
}; | ||
|
||
esp_err_t ret = i2c_new_master_bus(&bus_config, &i2c_handle); | ||
TEST_ASSERT_EQUAL_MESSAGE(ESP_OK, ret, "I2C install returned error"); | ||
} | ||
|
||
static void i2c_bus_deinit(void) | ||
{ | ||
esp_err_t ret = i2c_del_master_bus(i2c_handle); | ||
TEST_ASSERT_EQUAL_MESSAGE(ESP_OK, ret, "I2C uninstall returned error"); | ||
} | ||
|
||
static void i2c_dev_ht8574_init(void) | ||
{ | ||
esp_err_t ret = esp_io_expander_new_i2c_ht8574(i2c_handle, I2C_ADDRESS, &io_expander); | ||
TEST_ASSERT_EQUAL_MESSAGE(ESP_OK, ret, "HT8574 create returned error"); | ||
} | ||
|
||
static void i2c_dev_ht8574_deinit(void) | ||
{ | ||
esp_err_t ret = esp_io_expander_del(io_expander); | ||
TEST_ASSERT_EQUAL_MESSAGE(ESP_OK, ret, "HT8574 delete returned error"); | ||
} | ||
|
||
TEST_CASE("IO expander ht8574 test", "[ht8574]") | ||
{ | ||
i2c_bus_init(); | ||
i2c_dev_ht8574_init(); | ||
|
||
esp_err_t ret; | ||
/* Test output level function */ | ||
ret = esp_io_expander_set_dir(io_expander, TEST_OUTPUT_PINS, IO_EXPANDER_OUTPUT); | ||
TEST_ASSERT_EQUAL(ESP_OK, ret); | ||
// Print state | ||
ret = esp_io_expander_print_state(io_expander); | ||
TEST_ASSERT_EQUAL(ESP_OK, ret); | ||
for (int i = 0; i < TEST_LOOP_CNT; i++) { | ||
// Set level to 0 | ||
ESP_LOGI(TAG, "Set level to 0"); | ||
ret = esp_io_expander_set_level(io_expander, TEST_OUTPUT_PINS, 0); | ||
TEST_ASSERT_EQUAL(ESP_OK, ret); | ||
vTaskDelay(pdMS_TO_TICKS(TEST_LOOP_DELAY_MS / 2)); | ||
// Set level to 1 | ||
ESP_LOGI(TAG, "Set level to 1"); | ||
ret = esp_io_expander_set_level(io_expander, TEST_OUTPUT_PINS, 1); | ||
TEST_ASSERT_EQUAL(ESP_OK, ret); | ||
vTaskDelay(pdMS_TO_TICKS(TEST_LOOP_DELAY_MS / 2)); | ||
} | ||
|
||
/* Test output level function */ | ||
uint32_t input_level_mask = 0; | ||
ret = esp_io_expander_set_dir(io_expander, TEST_INPUT_PINS, IO_EXPANDER_INPUT); | ||
TEST_ASSERT_EQUAL(ESP_OK, ret); | ||
// Print state | ||
ret = esp_io_expander_print_state(io_expander); | ||
TEST_ASSERT_EQUAL(ESP_OK, ret); | ||
for (int i = 0; i < TEST_LOOP_CNT; i++) { | ||
// Get input level | ||
ret = esp_io_expander_get_level(io_expander, TEST_INPUT_PINS, &input_level_mask); | ||
TEST_ASSERT_EQUAL(ESP_OK, ret); | ||
ESP_LOGI(TAG, "Input level mask: 0x%02" PRIX32, input_level_mask); | ||
vTaskDelay(pdMS_TO_TICKS(TEST_LOOP_DELAY_MS)); | ||
} | ||
|
||
i2c_dev_ht8574_deinit(); | ||
i2c_bus_deinit(); | ||
vTaskDelay(10); // Give FreeRTOS some time to free its resources | ||
} | ||
|
||
#define TEST_MEMORY_LEAK_THRESHOLD (500) | ||
|
||
void setUp(void) | ||
{ | ||
unity_utils_set_leak_level(TEST_MEMORY_LEAK_THRESHOLD); | ||
unity_utils_record_free_mem(); | ||
} | ||
|
||
void tearDown(void) | ||
{ | ||
unity_utils_evaluate_leaks(); | ||
} | ||
|
||
void app_main(void) | ||
{ | ||
unity_run_menu(); | ||
} |
Oops, something went wrong.