Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0be9f6e079 | ||
|
|
c09ded8f57 | ||
|
|
bbfac9aba1 | ||
|
|
674ff93b30 | ||
|
|
d79ed5a22b |
@ -0,0 +1,6 @@
|
|||||||
|
# The following five 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)
|
||||||
|
|
||||||
|
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||||
|
project(button_power_save)
|
||||||
@ -0,0 +1,43 @@
|
|||||||
|
## Button Power Save Example
|
||||||
|
|
||||||
|
This example demonstrates how to utilize the `button` component in conjunction with the light sleep low-power mode.
|
||||||
|
|
||||||
|
* `button` [Component Introduction](https://docs.espressif.com/projects/esp-iot-solution/en/latest/input_device/button.html)
|
||||||
|
|
||||||
|
## Hardware
|
||||||
|
|
||||||
|
* Any GPIO on any development board can be used in this example.
|
||||||
|
|
||||||
|
## Build and Flash
|
||||||
|
|
||||||
|
Build the project and flash it to the board, then run the monitor tool to view the serial output:
|
||||||
|
|
||||||
|
* Run `. ./export.sh` to set IDF environment
|
||||||
|
* Run `idf.py set-target esp32xx` to set target chip
|
||||||
|
* Run `idf.py -p PORT flash monitor` to build, flash and monitor the project
|
||||||
|
|
||||||
|
(To exit the serial monitor, type `Ctrl-]`.)
|
||||||
|
|
||||||
|
See the Getting Started Guide for all the steps to configure and use the ESP-IDF to build projects.
|
||||||
|
|
||||||
|
## Example Output
|
||||||
|
|
||||||
|
```
|
||||||
|
I (1139) pm: Frequency switching config: CPU_MAX: 160, APB_MAX: 80, APB_MIN: 80, Light sleep: ENABLED
|
||||||
|
I (1149) sleep: Code start at 42000020, total 119.03 KiB, data start at 3c000000, total 49152.00 KiB
|
||||||
|
I (1159) button: IoT Button Version: 3.2.0
|
||||||
|
I (1163) gpio: GPIO[0]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
|
||||||
|
I (2922) button_power_save: Button event BUTTON_PRESS_DOWN
|
||||||
|
I (3017) button_power_save: Button event BUTTON_PRESS_UP
|
||||||
|
I (3017) button_power_save: Wake up from light sleep, reason 4
|
||||||
|
I (3200) button_power_save: Button event BUTTON_SINGLE_CLICK
|
||||||
|
I (3200) button_power_save: Wake up from light sleep, reason 4
|
||||||
|
I (3202) button_power_save: Button event BUTTON_PRESS_REPEAT_DONE
|
||||||
|
I (3208) button_power_save: Wake up from light sleep, reason 4
|
||||||
|
I (3627) button_power_save: Button event BUTTON_PRESS_DOWN
|
||||||
|
I (3702) button_power_save: Button event BUTTON_PRESS_UP
|
||||||
|
I (3702) button_power_save: Wake up from light sleep, reason 4
|
||||||
|
I (3887) button_power_save: Button event BUTTON_SINGLE_CLICK
|
||||||
|
I (3887) button_power_save: Wake up from light sleep, reason 4
|
||||||
|
I (3889) button_power_save: Button event BUTTON_PRESS_REPEAT_DONE
|
||||||
|
```
|
||||||
@ -0,0 +1,2 @@
|
|||||||
|
idf_component_register(SRCS "main.c"
|
||||||
|
INCLUDE_DIRS ".")
|
||||||
@ -0,0 +1,87 @@
|
|||||||
|
menu "Example Configuration"
|
||||||
|
|
||||||
|
choice ENTER_LIGHT_SLEEP_MODE
|
||||||
|
prompt "Enter light sleep mode"
|
||||||
|
default ENTER_LIGHT_SLEEP_AUTO
|
||||||
|
depends on PM_ENABLE
|
||||||
|
help
|
||||||
|
Enable light sleep mode to save power.
|
||||||
|
|
||||||
|
config ENTER_LIGHT_SLEEP_AUTO
|
||||||
|
bool "Auto enter Light Sleep"
|
||||||
|
config ENTER_LIGHT_SLEEP_MODE_MANUALLY
|
||||||
|
bool "Manually enter Light Sleep"
|
||||||
|
endchoice
|
||||||
|
|
||||||
|
choice EXAMPLE_MAX_CPU_FREQ
|
||||||
|
prompt "Maximum CPU frequency"
|
||||||
|
default EXAMPLE_MAX_CPU_FREQ_80 if !IDF_TARGET_ESP32H2
|
||||||
|
default EXAMPLE_MAX_CPU_FREQ_96 if IDF_TARGET_ESP32H2
|
||||||
|
depends on PM_ENABLE
|
||||||
|
help
|
||||||
|
Maximum CPU frequency to use for dynamic frequency scaling.
|
||||||
|
|
||||||
|
config EXAMPLE_MAX_CPU_FREQ_80
|
||||||
|
bool "80 MHz"
|
||||||
|
config EXAMPLE_MAX_CPU_FREQ_96
|
||||||
|
bool "96 MHz"
|
||||||
|
depends on IDF_TARGET_ESP32H2
|
||||||
|
config EXAMPLE_MAX_CPU_FREQ_120
|
||||||
|
bool "120 MHz"
|
||||||
|
depends on IDF_TARGET_ESP32C2
|
||||||
|
config EXAMPLE_MAX_CPU_FREQ_160
|
||||||
|
bool "160 MHz"
|
||||||
|
depends on !IDF_TARGET_ESP32C2
|
||||||
|
config EXAMPLE_MAX_CPU_FREQ_240
|
||||||
|
bool "240 MHz"
|
||||||
|
depends on IDF_TARGET_ESP32 || IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
|
||||||
|
endchoice
|
||||||
|
|
||||||
|
config EXAMPLE_MAX_CPU_FREQ_MHZ
|
||||||
|
int
|
||||||
|
default 80 if EXAMPLE_MAX_CPU_FREQ_80
|
||||||
|
default 96 if EXAMPLE_MAX_CPU_FREQ_96
|
||||||
|
default 120 if EXAMPLE_MAX_CPU_FREQ_120
|
||||||
|
default 160 if EXAMPLE_MAX_CPU_FREQ_160
|
||||||
|
default 240 if EXAMPLE_MAX_CPU_FREQ_240
|
||||||
|
|
||||||
|
choice EXAMPLE_MIN_CPU_FREQ
|
||||||
|
prompt "Minimum CPU frequency"
|
||||||
|
default EXAMPLE_MIN_CPU_FREQ_10M if !IDF_TARGET_ESP32H2
|
||||||
|
default EXAMPLE_MIN_CPU_FREQ_32M if IDF_TARGET_ESP32H2
|
||||||
|
depends on PM_ENABLE
|
||||||
|
help
|
||||||
|
Minimum CPU frequency to use for dynamic frequency scaling.
|
||||||
|
Should be set to XTAL frequency or XTAL frequency divided by integer.
|
||||||
|
|
||||||
|
config EXAMPLE_MIN_CPU_FREQ_40M
|
||||||
|
bool "40 MHz (use with 40MHz XTAL)"
|
||||||
|
depends on XTAL_FREQ_40 || XTAL_FREQ_AUTO || ESP32_XTAL_FREQ_40 || ESP32_XTAL_FREQ_AUTO || !IDF_TARGET_ESP32
|
||||||
|
config EXAMPLE_MIN_CPU_FREQ_20M
|
||||||
|
bool "20 MHz (use with 40MHz XTAL)"
|
||||||
|
depends on XTAL_FREQ_40 || XTAL_FREQ_AUTO || ESP32_XTAL_FREQ_40 || ESP32_XTAL_FREQ_AUTO || !IDF_TARGET_ESP32
|
||||||
|
config EXAMPLE_MIN_CPU_FREQ_10M
|
||||||
|
bool "10 MHz (use with 40MHz XTAL)"
|
||||||
|
depends on XTAL_FREQ_40 || XTAL_FREQ_AUTO || ESP32_XTAL_FREQ_40 || ESP32_XTAL_FREQ_AUTO || !IDF_TARGET_ESP32
|
||||||
|
config EXAMPLE_MIN_CPU_FREQ_26M
|
||||||
|
bool "26 MHz (use with 26MHz XTAL)"
|
||||||
|
depends on XTAL_FREQ_26 || XTAL_FREQ_AUTO || ESP32_XTAL_FREQ_26 || ESP32_XTAL_FREQ_AUTO
|
||||||
|
config EXAMPLE_MIN_CPU_FREQ_13M
|
||||||
|
bool "13 MHz (use with 26MHz XTAL)"
|
||||||
|
depends on XTAL_FREQ_26 || XTAL_FREQ_AUTO || ESP32_XTAL_FREQ_26 || ESP32_XTAL_FREQ_AUTO
|
||||||
|
config EXAMPLE_MIN_CPU_FREQ_32M
|
||||||
|
bool "32 MHz (use with 32MHz XTAL)"
|
||||||
|
depends on IDF_TARGET_ESP32H2
|
||||||
|
depends on XTAL_FREQ_32 || XTAL_FREQ_AUTO
|
||||||
|
endchoice
|
||||||
|
|
||||||
|
config EXAMPLE_MIN_CPU_FREQ_MHZ
|
||||||
|
int
|
||||||
|
default 40 if EXAMPLE_MIN_CPU_FREQ_40M
|
||||||
|
default 20 if EXAMPLE_MIN_CPU_FREQ_20M
|
||||||
|
default 10 if EXAMPLE_MIN_CPU_FREQ_10M
|
||||||
|
default 26 if EXAMPLE_MIN_CPU_FREQ_26M
|
||||||
|
default 13 if EXAMPLE_MIN_CPU_FREQ_13M
|
||||||
|
default 32 if EXAMPLE_MIN_CPU_FREQ_32M
|
||||||
|
|
||||||
|
endmenu
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
version: "0.0.1"
|
||||||
|
dependencies:
|
||||||
|
idf: ">=4.4"
|
||||||
|
button:
|
||||||
|
version: "*"
|
||||||
|
override_path: "../../../../components/button"
|
||||||
@ -0,0 +1,139 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/task.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "esp_pm.h"
|
||||||
|
#include "iot_button.h"
|
||||||
|
#include "esp_sleep.h"
|
||||||
|
#include "esp_idf_version.h"
|
||||||
|
|
||||||
|
/* Most development boards have "boot" button attached to GPIO0.
|
||||||
|
* You can also change this to another pin.
|
||||||
|
*/
|
||||||
|
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32C6
|
||||||
|
#define BOOT_BUTTON_NUM 9
|
||||||
|
#else
|
||||||
|
#define BOOT_BUTTON_NUM 0
|
||||||
|
#endif
|
||||||
|
#define BUTTON_ACTIVE_LEVEL 0
|
||||||
|
|
||||||
|
static const char *TAG = "button_power_save";
|
||||||
|
|
||||||
|
const char *button_event_table[] = {
|
||||||
|
"BUTTON_PRESS_DOWN",
|
||||||
|
"BUTTON_PRESS_UP",
|
||||||
|
"BUTTON_PRESS_REPEAT",
|
||||||
|
"BUTTON_PRESS_REPEAT_DONE",
|
||||||
|
"BUTTON_SINGLE_CLICK",
|
||||||
|
"BUTTON_DOUBLE_CLICK",
|
||||||
|
"BUTTON_MULTIPLE_CLICK",
|
||||||
|
"BUTTON_LONG_PRESS_START",
|
||||||
|
"BUTTON_LONG_PRESS_HOLD",
|
||||||
|
"BUTTON_LONG_PRESS_UP",
|
||||||
|
"BUTTON_PRESS_END",
|
||||||
|
};
|
||||||
|
|
||||||
|
static void button_event_cb(void *arg, void *data)
|
||||||
|
{
|
||||||
|
ESP_LOGI(TAG, "Button event %s", button_event_table[(button_event_t)data]);
|
||||||
|
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
|
||||||
|
if (cause != ESP_SLEEP_WAKEUP_UNDEFINED) {
|
||||||
|
ESP_LOGI(TAG, "Wake up from light sleep, reason %d", cause);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if CONFIG_ENTER_LIGHT_SLEEP_MODE_MANUALLY
|
||||||
|
void button_enter_power_save(void *usr_data)
|
||||||
|
{
|
||||||
|
ESP_LOGI(TAG, "Can enter power save now");
|
||||||
|
esp_light_sleep_start();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void button_init(uint32_t button_num)
|
||||||
|
{
|
||||||
|
button_config_t btn_cfg = {
|
||||||
|
.type = BUTTON_TYPE_GPIO,
|
||||||
|
.gpio_button_config = {
|
||||||
|
.gpio_num = button_num,
|
||||||
|
.active_level = BUTTON_ACTIVE_LEVEL,
|
||||||
|
#if CONFIG_GPIO_BUTTON_SUPPORT_POWER_SAVE
|
||||||
|
.enable_power_save = true,
|
||||||
|
#endif
|
||||||
|
},
|
||||||
|
};
|
||||||
|
button_handle_t btn = iot_button_create(&btn_cfg);
|
||||||
|
assert(btn);
|
||||||
|
esp_err_t err = iot_button_register_cb(btn, BUTTON_PRESS_DOWN, button_event_cb, (void *)BUTTON_PRESS_DOWN);
|
||||||
|
err |= iot_button_register_cb(btn, BUTTON_PRESS_UP, button_event_cb, (void *)BUTTON_PRESS_UP);
|
||||||
|
err |= iot_button_register_cb(btn, BUTTON_PRESS_REPEAT, button_event_cb, (void *)BUTTON_PRESS_REPEAT);
|
||||||
|
err |= iot_button_register_cb(btn, BUTTON_PRESS_REPEAT_DONE, button_event_cb, (void *)BUTTON_PRESS_REPEAT_DONE);
|
||||||
|
err |= iot_button_register_cb(btn, BUTTON_SINGLE_CLICK, button_event_cb, (void *)BUTTON_SINGLE_CLICK);
|
||||||
|
err |= iot_button_register_cb(btn, BUTTON_DOUBLE_CLICK, button_event_cb, (void *)BUTTON_DOUBLE_CLICK);
|
||||||
|
err |= iot_button_register_cb(btn, BUTTON_LONG_PRESS_START, button_event_cb, (void *)BUTTON_LONG_PRESS_START);
|
||||||
|
err |= iot_button_register_cb(btn, BUTTON_LONG_PRESS_HOLD, button_event_cb, (void *)BUTTON_LONG_PRESS_HOLD);
|
||||||
|
err |= iot_button_register_cb(btn, BUTTON_LONG_PRESS_UP, button_event_cb, (void *)BUTTON_LONG_PRESS_UP);
|
||||||
|
err |= iot_button_register_cb(btn, BUTTON_PRESS_END, button_event_cb, (void *)BUTTON_PRESS_END);
|
||||||
|
|
||||||
|
#if CONFIG_ENTER_LIGHT_SLEEP_MODE_MANUALLY
|
||||||
|
/*!< For enter Power Save */
|
||||||
|
button_power_save_config_t config = {
|
||||||
|
.enter_power_save_cb = button_enter_power_save,
|
||||||
|
};
|
||||||
|
err |= iot_button_register_power_save_cb(&config);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 0)
|
||||||
|
void power_save_init(void)
|
||||||
|
{
|
||||||
|
esp_pm_config_t pm_config = {
|
||||||
|
.max_freq_mhz = CONFIG_EXAMPLE_MAX_CPU_FREQ_MHZ,
|
||||||
|
.min_freq_mhz = CONFIG_EXAMPLE_MIN_CPU_FREQ_MHZ,
|
||||||
|
#if CONFIG_FREERTOS_USE_TICKLESS_IDLE
|
||||||
|
.light_sleep_enable = true
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
ESP_ERROR_CHECK(esp_pm_configure(&pm_config));
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
void power_save_init(void)
|
||||||
|
{
|
||||||
|
#if CONFIG_IDF_TARGET_ESP32
|
||||||
|
esp_pm_config_esp32_t pm_config = {
|
||||||
|
#elif CONFIG_IDF_TARGET_ESP32S2
|
||||||
|
esp_pm_config_esp32s2_t pm_config = {
|
||||||
|
#elif CONFIG_IDF_TARGET_ESP32C3
|
||||||
|
esp_pm_config_esp32c3_t pm_config = {
|
||||||
|
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||||
|
esp_pm_config_esp32s3_t pm_config = {
|
||||||
|
#elif CONFIG_IDF_TARGET_ESP32C2
|
||||||
|
esp_pm_config_esp32c2_t pm_config = {
|
||||||
|
#endif
|
||||||
|
.max_freq_mhz = CONFIG_EXAMPLE_MAX_CPU_FREQ_MHZ,
|
||||||
|
.min_freq_mhz = CONFIG_EXAMPLE_MIN_CPU_FREQ_MHZ,
|
||||||
|
#if CONFIG_FREERTOS_USE_TICKLESS_IDLE
|
||||||
|
.light_sleep_enable = true
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
ESP_ERROR_CHECK(esp_pm_configure(&pm_config));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void app_main(void)
|
||||||
|
{
|
||||||
|
button_init(BOOT_BUTTON_NUM);
|
||||||
|
#if CONFIG_ENTER_LIGHT_SLEEP_AUTO
|
||||||
|
power_save_init();
|
||||||
|
#else
|
||||||
|
esp_light_sleep_start();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
9
components/espressif__button/test_apps/CMakeLists.txt
Normal file
9
components/espressif__button/test_apps/CMakeLists.txt
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
# 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(EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/unit-test-app/components"
|
||||||
|
"../../button")
|
||||||
|
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||||
|
project(button_test)
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER_EQUAL "5.0")
|
||||||
|
list(APPEND PRIVREQ esp_adc)
|
||||||
|
else()
|
||||||
|
list(APPEND PRIVREQ esp_adc_cal)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
idf_component_register(SRC_DIRS "."
|
||||||
|
PRIV_INCLUDE_DIRS "."
|
||||||
|
PRIV_REQUIRES unity test_utils button ${PRIVREQ})
|
||||||
767
components/espressif__button/test_apps/main/button_test.c
Normal file
767
components/espressif__button/test_apps/main/button_test.c
Normal file
@ -0,0 +1,767 @@
|
|||||||
|
/* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "stdio.h"
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/task.h"
|
||||||
|
#include "freertos/queue.h"
|
||||||
|
#include "freertos/timers.h"
|
||||||
|
#include "freertos/semphr.h"
|
||||||
|
#include "freertos/event_groups.h"
|
||||||
|
#include "esp_idf_version.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "unity.h"
|
||||||
|
#include "iot_button.h"
|
||||||
|
#include "sdkconfig.h"
|
||||||
|
|
||||||
|
static const char *TAG = "BUTTON TEST";
|
||||||
|
|
||||||
|
#define TEST_MEMORY_LEAK_THRESHOLD (-400)
|
||||||
|
#define BUTTON_IO_NUM 0
|
||||||
|
#define BUTTON_ACTIVE_LEVEL 0
|
||||||
|
#define BUTTON_NUM 16
|
||||||
|
|
||||||
|
static size_t before_free_8bit;
|
||||||
|
static size_t before_free_32bit;
|
||||||
|
static button_handle_t g_btns[BUTTON_NUM] = {0};
|
||||||
|
|
||||||
|
static int get_btn_index(button_handle_t btn)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < BUTTON_NUM; i++) {
|
||||||
|
if (btn == g_btns[i]) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void button_press_down_cb(void *arg, void *data)
|
||||||
|
{
|
||||||
|
TEST_ASSERT_EQUAL_HEX(BUTTON_PRESS_DOWN, iot_button_get_event(arg));
|
||||||
|
ESP_LOGI(TAG, "BTN%d: BUTTON_PRESS_DOWN", get_btn_index((button_handle_t)arg));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void button_press_up_cb(void *arg, void *data)
|
||||||
|
{
|
||||||
|
TEST_ASSERT_EQUAL_HEX(BUTTON_PRESS_UP, iot_button_get_event(arg));
|
||||||
|
ESP_LOGI(TAG, "BTN%d: BUTTON_PRESS_UP[%d]", get_btn_index((button_handle_t)arg), iot_button_get_ticks_time((button_handle_t)arg));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void button_press_repeat_cb(void *arg, void *data)
|
||||||
|
{
|
||||||
|
ESP_LOGI(TAG, "BTN%d: BUTTON_PRESS_REPEAT[%d]", get_btn_index((button_handle_t)arg), iot_button_get_repeat((button_handle_t)arg));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void button_single_click_cb(void *arg, void *data)
|
||||||
|
{
|
||||||
|
TEST_ASSERT_EQUAL_HEX(BUTTON_SINGLE_CLICK, iot_button_get_event(arg));
|
||||||
|
ESP_LOGI(TAG, "BTN%d: BUTTON_SINGLE_CLICK", get_btn_index((button_handle_t)arg));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void button_double_click_cb(void *arg, void *data)
|
||||||
|
{
|
||||||
|
TEST_ASSERT_EQUAL_HEX(BUTTON_DOUBLE_CLICK, iot_button_get_event(arg));
|
||||||
|
ESP_LOGI(TAG, "BTN%d: BUTTON_DOUBLE_CLICK", get_btn_index((button_handle_t)arg));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void button_long_press_start_cb(void *arg, void *data)
|
||||||
|
{
|
||||||
|
TEST_ASSERT_EQUAL_HEX(BUTTON_LONG_PRESS_START, iot_button_get_event(arg));
|
||||||
|
ESP_LOGI(TAG, "BTN%d: BUTTON_LONG_PRESS_START", get_btn_index((button_handle_t)arg));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void button_long_press_hold_cb(void *arg, void *data)
|
||||||
|
{
|
||||||
|
TEST_ASSERT_EQUAL_HEX(BUTTON_LONG_PRESS_HOLD, iot_button_get_event(arg));
|
||||||
|
ESP_LOGI(TAG, "BTN%d: BUTTON_LONG_PRESS_HOLD[%d],count is [%d]", get_btn_index((button_handle_t)arg), iot_button_get_ticks_time((button_handle_t)arg), iot_button_get_long_press_hold_cnt((button_handle_t)arg));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void button_press_repeat_done_cb(void *arg, void *data)
|
||||||
|
{
|
||||||
|
TEST_ASSERT_EQUAL_HEX(BUTTON_PRESS_REPEAT_DONE, iot_button_get_event(arg));
|
||||||
|
ESP_LOGI(TAG, "BTN%d: BUTTON_PRESS_REPEAT_DONE[%d]", get_btn_index((button_handle_t)arg), iot_button_get_repeat((button_handle_t)arg));
|
||||||
|
}
|
||||||
|
|
||||||
|
static esp_err_t custom_button_gpio_init(void *param)
|
||||||
|
{
|
||||||
|
button_gpio_config_t *cfg = (button_gpio_config_t *)param;
|
||||||
|
|
||||||
|
return button_gpio_init(cfg);
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint8_t custom_button_gpio_get_key_value(void *param)
|
||||||
|
{
|
||||||
|
button_gpio_config_t *cfg = (button_gpio_config_t *)param;
|
||||||
|
|
||||||
|
return button_gpio_get_key_level((void *)cfg->gpio_num);
|
||||||
|
}
|
||||||
|
|
||||||
|
static esp_err_t custom_button_gpio_deinit(void *param)
|
||||||
|
{
|
||||||
|
button_gpio_config_t *cfg = (button_gpio_config_t *)param;
|
||||||
|
|
||||||
|
return button_gpio_deinit(cfg->gpio_num);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("custom button test", "[button][iot]")
|
||||||
|
{
|
||||||
|
button_gpio_config_t *gpio_cfg = calloc(1, sizeof(button_gpio_config_t));
|
||||||
|
gpio_cfg->active_level = 0;
|
||||||
|
gpio_cfg->gpio_num = 0;
|
||||||
|
|
||||||
|
button_config_t cfg = {
|
||||||
|
.type = BUTTON_TYPE_CUSTOM,
|
||||||
|
.long_press_time = CONFIG_BUTTON_LONG_PRESS_TIME_MS,
|
||||||
|
.short_press_time = CONFIG_BUTTON_SHORT_PRESS_TIME_MS,
|
||||||
|
.custom_button_config = {
|
||||||
|
.button_custom_init = custom_button_gpio_init,
|
||||||
|
.button_custom_deinit = custom_button_gpio_deinit,
|
||||||
|
.button_custom_get_key_value = custom_button_gpio_get_key_value,
|
||||||
|
.active_level = 0,
|
||||||
|
.priv = gpio_cfg,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
g_btns[0] = iot_button_create(&cfg);
|
||||||
|
TEST_ASSERT_NOT_NULL(g_btns[0]);
|
||||||
|
iot_button_register_cb(g_btns[0], BUTTON_PRESS_DOWN, button_press_down_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[0], BUTTON_PRESS_UP, button_press_up_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[0], BUTTON_PRESS_REPEAT, button_press_repeat_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[0], BUTTON_SINGLE_CLICK, button_single_click_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[0], BUTTON_DOUBLE_CLICK, button_double_click_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[0], BUTTON_LONG_PRESS_START, button_long_press_start_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[0], BUTTON_LONG_PRESS_HOLD, button_long_press_hold_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[0], BUTTON_PRESS_REPEAT_DONE, button_press_repeat_done_cb, NULL);
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||||
|
}
|
||||||
|
|
||||||
|
iot_button_delete(g_btns[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("gpio button test", "[button][iot]")
|
||||||
|
{
|
||||||
|
button_config_t cfg = {
|
||||||
|
.type = BUTTON_TYPE_GPIO,
|
||||||
|
.long_press_time = CONFIG_BUTTON_LONG_PRESS_TIME_MS,
|
||||||
|
.short_press_time = CONFIG_BUTTON_SHORT_PRESS_TIME_MS,
|
||||||
|
.gpio_button_config = {
|
||||||
|
.gpio_num = 0,
|
||||||
|
.active_level = 0,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
g_btns[0] = iot_button_create(&cfg);
|
||||||
|
TEST_ASSERT_NOT_NULL(g_btns[0]);
|
||||||
|
iot_button_register_cb(g_btns[0], BUTTON_PRESS_DOWN, button_press_down_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[0], BUTTON_PRESS_UP, button_press_up_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[0], BUTTON_PRESS_REPEAT, button_press_repeat_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[0], BUTTON_SINGLE_CLICK, button_single_click_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[0], BUTTON_DOUBLE_CLICK, button_double_click_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[0], BUTTON_LONG_PRESS_START, button_long_press_start_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[0], BUTTON_LONG_PRESS_HOLD, button_long_press_hold_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[0], BUTTON_PRESS_REPEAT_DONE, button_press_repeat_done_cb, NULL);
|
||||||
|
|
||||||
|
uint8_t level = 0;
|
||||||
|
level = iot_button_get_key_level(g_btns[0]);
|
||||||
|
ESP_LOGI(TAG, "button level is %d", level);
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||||
|
}
|
||||||
|
|
||||||
|
iot_button_delete(g_btns[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("gpio button get event test", "[button][iot]")
|
||||||
|
{
|
||||||
|
const char *EVENT_STR[] = {"BUTTON_PRESS_DOWN",
|
||||||
|
"BUTTON_PRESS_UP",
|
||||||
|
"BUTTON_PRESS_REPEAT",
|
||||||
|
"BUTTON_PRESS_REPEAT_DONE",
|
||||||
|
"BUTTON_SINGLE_CLICK",
|
||||||
|
"BUTTON_DOUBLE_CLICK",
|
||||||
|
"BUTTON_MULTIPLE_CLICK",
|
||||||
|
"BUTTON_LONG_PRESS_START",
|
||||||
|
"BUTTON_LONG_PRESS_HOLD",
|
||||||
|
"BUTTON_LONG_PRESS_UP",
|
||||||
|
"BUTTON_PRESS_END",
|
||||||
|
};
|
||||||
|
|
||||||
|
button_config_t cfg = {
|
||||||
|
.type = BUTTON_TYPE_GPIO,
|
||||||
|
.long_press_time = CONFIG_BUTTON_LONG_PRESS_TIME_MS,
|
||||||
|
.short_press_time = CONFIG_BUTTON_SHORT_PRESS_TIME_MS,
|
||||||
|
.gpio_button_config = {
|
||||||
|
.gpio_num = 0,
|
||||||
|
.active_level = 0,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
g_btns[0] = iot_button_create(&cfg);
|
||||||
|
TEST_ASSERT_NOT_NULL(g_btns[0]);
|
||||||
|
|
||||||
|
uint8_t level = 0;
|
||||||
|
level = iot_button_get_key_level(g_btns[0]);
|
||||||
|
ESP_LOGI(TAG, "button level is %d", level);
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
button_event_t event = iot_button_get_event(g_btns[0]);
|
||||||
|
if (event != BUTTON_NONE_PRESS) {
|
||||||
|
printf("event is %s\n", EVENT_STR[event]);
|
||||||
|
}
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
iot_button_delete(g_btns[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("gpio button test power save", "[button][iot][power save]")
|
||||||
|
{
|
||||||
|
button_config_t cfg = {
|
||||||
|
.type = BUTTON_TYPE_GPIO,
|
||||||
|
.long_press_time = CONFIG_BUTTON_LONG_PRESS_TIME_MS,
|
||||||
|
.short_press_time = CONFIG_BUTTON_SHORT_PRESS_TIME_MS,
|
||||||
|
.gpio_button_config = {
|
||||||
|
.gpio_num = 0,
|
||||||
|
.active_level = 0,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
g_btns[0] = iot_button_create(&cfg);
|
||||||
|
TEST_ASSERT_NOT_NULL(g_btns[0]);
|
||||||
|
iot_button_register_cb(g_btns[0], BUTTON_PRESS_DOWN, button_press_down_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[0], BUTTON_PRESS_UP, button_press_up_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[0], BUTTON_PRESS_REPEAT, button_press_repeat_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[0], BUTTON_SINGLE_CLICK, button_single_click_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[0], BUTTON_DOUBLE_CLICK, button_double_click_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[0], BUTTON_LONG_PRESS_START, button_long_press_start_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[0], BUTTON_LONG_PRESS_HOLD, button_long_press_hold_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[0], BUTTON_PRESS_REPEAT_DONE, button_press_repeat_done_cb, NULL);
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL(ESP_OK, iot_button_stop());
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||||
|
TEST_ASSERT_EQUAL(ESP_OK, iot_button_resume());
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||||
|
}
|
||||||
|
|
||||||
|
iot_button_delete(g_btns[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("matrix keyboard button test", "[button][matrix key]")
|
||||||
|
{
|
||||||
|
int32_t row_gpio[4] = {4, 5, 6, 7};
|
||||||
|
int32_t col_gpio[4] = {3, 8, 16, 15};
|
||||||
|
button_config_t cfg = {
|
||||||
|
.type = BUTTON_TYPE_MATRIX,
|
||||||
|
.long_press_time = CONFIG_BUTTON_LONG_PRESS_TIME_MS,
|
||||||
|
.short_press_time = CONFIG_BUTTON_SHORT_PRESS_TIME_MS,
|
||||||
|
.matrix_button_config = {
|
||||||
|
.row_gpio_num = 0,
|
||||||
|
.col_gpio_num = 0,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
cfg.matrix_button_config.row_gpio_num = row_gpio[i];
|
||||||
|
for (int j = 0; j < 4; j++) {
|
||||||
|
cfg.matrix_button_config.col_gpio_num = col_gpio[j];
|
||||||
|
g_btns[i * 4 + j] = iot_button_create(&cfg);
|
||||||
|
TEST_ASSERT_NOT_NULL(g_btns[i * 4 + j]);
|
||||||
|
iot_button_register_cb(g_btns[i * 4 + j], BUTTON_PRESS_DOWN, button_press_down_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[i * 4 + j], BUTTON_PRESS_UP, button_press_up_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[i * 4 + j], BUTTON_PRESS_REPEAT, button_press_repeat_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[i * 4 + j], BUTTON_SINGLE_CLICK, button_single_click_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[i * 4 + j], BUTTON_DOUBLE_CLICK, button_double_click_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[i * 4 + j], BUTTON_LONG_PRESS_START, button_long_press_start_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[i * 4 + j], BUTTON_LONG_PRESS_HOLD, button_long_press_hold_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[i * 4 + j], BUTTON_PRESS_REPEAT_DONE, button_press_repeat_done_cb, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
for (int j = 0; j < 4; j++) {
|
||||||
|
iot_button_delete(g_btns[i * 4 + j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if CONFIG_SOC_ADC_SUPPORTED
|
||||||
|
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
|
||||||
|
TEST_CASE("adc button test", "[button][iot]")
|
||||||
|
{
|
||||||
|
/** ESP32-S3-Korvo board */
|
||||||
|
const uint16_t vol[6] = {380, 820, 1180, 1570, 1980, 2410};
|
||||||
|
button_config_t cfg = {0};
|
||||||
|
cfg.type = BUTTON_TYPE_ADC;
|
||||||
|
cfg.long_press_time = CONFIG_BUTTON_LONG_PRESS_TIME_MS;
|
||||||
|
cfg.short_press_time = CONFIG_BUTTON_SHORT_PRESS_TIME_MS;
|
||||||
|
for (size_t i = 0; i < 6; i++) {
|
||||||
|
cfg.adc_button_config.adc_channel = 7,
|
||||||
|
cfg.adc_button_config.button_index = i;
|
||||||
|
if (i == 0) {
|
||||||
|
cfg.adc_button_config.min = (0 + vol[i]) / 2;
|
||||||
|
} else {
|
||||||
|
cfg.adc_button_config.min = (vol[i - 1] + vol[i]) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i == 5) {
|
||||||
|
cfg.adc_button_config.max = (vol[i] + 3000) / 2;
|
||||||
|
} else {
|
||||||
|
cfg.adc_button_config.max = (vol[i] + vol[i + 1]) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_btns[i] = iot_button_create(&cfg);
|
||||||
|
TEST_ASSERT_NOT_NULL(g_btns[i]);
|
||||||
|
iot_button_register_cb(g_btns[i], BUTTON_PRESS_DOWN, button_press_down_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[i], BUTTON_PRESS_UP, button_press_up_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[i], BUTTON_PRESS_REPEAT, button_press_repeat_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[i], BUTTON_SINGLE_CLICK, button_single_click_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[i], BUTTON_DOUBLE_CLICK, button_double_click_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[i], BUTTON_LONG_PRESS_START, button_long_press_start_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[i], BUTTON_LONG_PRESS_HOLD, button_long_press_hold_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[i], BUTTON_PRESS_REPEAT_DONE, button_press_repeat_done_cb, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||||
|
}
|
||||||
|
for (size_t i = 0; i < 6; i++) {
|
||||||
|
iot_button_delete(g_btns[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include "esp_adc/adc_cali.h"
|
||||||
|
|
||||||
|
static esp_err_t adc_calibration_init(adc_unit_t unit, adc_atten_t atten, adc_cali_handle_t *out_handle)
|
||||||
|
{
|
||||||
|
|
||||||
|
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
|
||||||
|
#define ADC_BUTTON_WIDTH SOC_ADC_RTC_MAX_BITWIDTH
|
||||||
|
#else
|
||||||
|
#define ADC_BUTTON_WIDTH ADC_WIDTH_MAX - 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
adc_cali_handle_t handle = NULL;
|
||||||
|
esp_err_t ret = ESP_FAIL;
|
||||||
|
bool calibrated = false;
|
||||||
|
|
||||||
|
#if ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED
|
||||||
|
if (!calibrated) {
|
||||||
|
ESP_LOGI(TAG, "calibration scheme version is %s", "Curve Fitting");
|
||||||
|
adc_cali_curve_fitting_config_t cali_config = {
|
||||||
|
.unit_id = unit,
|
||||||
|
.atten = atten,
|
||||||
|
.bitwidth = ADC_BUTTON_WIDTH,
|
||||||
|
};
|
||||||
|
ret = adc_cali_create_scheme_curve_fitting(&cali_config, &handle);
|
||||||
|
if (ret == ESP_OK) {
|
||||||
|
calibrated = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if ADC_CALI_SCHEME_LINE_FITTING_SUPPORTED
|
||||||
|
if (!calibrated) {
|
||||||
|
ESP_LOGI(TAG, "calibration scheme version is %s", "Line Fitting");
|
||||||
|
adc_cali_line_fitting_config_t cali_config = {
|
||||||
|
.unit_id = unit,
|
||||||
|
.atten = atten,
|
||||||
|
.bitwidth = ADC_BUTTON_WIDTH,
|
||||||
|
};
|
||||||
|
ret = adc_cali_create_scheme_line_fitting(&cali_config, &handle);
|
||||||
|
if (ret == ESP_OK) {
|
||||||
|
calibrated = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
*out_handle = handle;
|
||||||
|
if (ret == ESP_OK) {
|
||||||
|
ESP_LOGI(TAG, "Calibration Success");
|
||||||
|
} else if (ret == ESP_ERR_NOT_SUPPORTED || !calibrated) {
|
||||||
|
ESP_LOGW(TAG, "eFuse not burnt, skip software calibration");
|
||||||
|
} else {
|
||||||
|
ESP_LOGE(TAG, "Invalid arg or no memory");
|
||||||
|
}
|
||||||
|
|
||||||
|
return calibrated ? ESP_OK : ESP_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("adc button idf5 drive test", "[button][iot]")
|
||||||
|
{
|
||||||
|
adc_oneshot_unit_handle_t adc1_handle;
|
||||||
|
adc_cali_handle_t adc1_cali_handle;
|
||||||
|
adc_oneshot_unit_init_cfg_t init_config = {
|
||||||
|
.unit_id = ADC_UNIT_1,
|
||||||
|
};
|
||||||
|
esp_err_t ret = adc_oneshot_new_unit(&init_config, &adc1_handle);
|
||||||
|
TEST_ASSERT_TRUE(ret == ESP_OK);
|
||||||
|
/*!< use atten 11db or 12db */
|
||||||
|
adc_calibration_init(ADC_UNIT_1, 3, &adc1_cali_handle);
|
||||||
|
|
||||||
|
/** ESP32-S3-Korvo board */
|
||||||
|
const uint16_t vol[6] = {380, 820, 1180, 1570, 1980, 2410};
|
||||||
|
button_config_t cfg = {0};
|
||||||
|
cfg.type = BUTTON_TYPE_ADC;
|
||||||
|
cfg.long_press_time = CONFIG_BUTTON_LONG_PRESS_TIME_MS;
|
||||||
|
cfg.short_press_time = CONFIG_BUTTON_SHORT_PRESS_TIME_MS;
|
||||||
|
for (size_t i = 0; i < 6; i++) {
|
||||||
|
cfg.adc_button_config.adc_handle = &adc1_handle;
|
||||||
|
cfg.adc_button_config.adc_channel = 7,
|
||||||
|
cfg.adc_button_config.button_index = i;
|
||||||
|
if (i == 0) {
|
||||||
|
cfg.adc_button_config.min = (0 + vol[i]) / 2;
|
||||||
|
} else {
|
||||||
|
cfg.adc_button_config.min = (vol[i - 1] + vol[i]) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i == 5) {
|
||||||
|
cfg.adc_button_config.max = (vol[i] + 3000) / 2;
|
||||||
|
} else {
|
||||||
|
cfg.adc_button_config.max = (vol[i] + vol[i + 1]) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_btns[i] = iot_button_create(&cfg);
|
||||||
|
TEST_ASSERT_NOT_NULL(g_btns[i]);
|
||||||
|
iot_button_register_cb(g_btns[i], BUTTON_PRESS_DOWN, button_press_down_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[i], BUTTON_PRESS_UP, button_press_up_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[i], BUTTON_PRESS_REPEAT, button_press_repeat_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[i], BUTTON_SINGLE_CLICK, button_single_click_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[i], BUTTON_DOUBLE_CLICK, button_double_click_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[i], BUTTON_LONG_PRESS_START, button_long_press_start_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[i], BUTTON_LONG_PRESS_HOLD, button_long_press_hold_cb, NULL);
|
||||||
|
iot_button_register_cb(g_btns[i], BUTTON_PRESS_REPEAT_DONE, button_press_repeat_done_cb, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||||
|
}
|
||||||
|
for (size_t i = 0; i < 6; i++) {
|
||||||
|
iot_button_delete(g_btns[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif // CONFIG_SOC_ADC_SUPPORTED
|
||||||
|
|
||||||
|
#define GPIO_OUTPUT_IO_45 45
|
||||||
|
static EventGroupHandle_t g_check = NULL;
|
||||||
|
static SemaphoreHandle_t g_auto_check_pass = NULL;
|
||||||
|
static const char* button_event_str[BUTTON_EVENT_MAX] = {
|
||||||
|
"BUTTON_PRESS_DOWN",
|
||||||
|
"BUTTON_PRESS_UP",
|
||||||
|
"BUTTON_PRESS_REPEAT",
|
||||||
|
"BUTTON_PRESS_REPEAT_DONE",
|
||||||
|
"BUTTON_SINGLE_CLICK",
|
||||||
|
"BUTTON_DOUBLE_CLICK",
|
||||||
|
"BUTTON_MULTIPLE_CLICK",
|
||||||
|
"BUTTON_LONG_PRESS_START",
|
||||||
|
"BUTTON_LONG_PRESS_HOLD",
|
||||||
|
"BUTTON_LONG_PRESS_UP",
|
||||||
|
"BUTTON_PRESS_END",
|
||||||
|
};
|
||||||
|
|
||||||
|
static button_event_t state = BUTTON_PRESS_DOWN;
|
||||||
|
|
||||||
|
static void button_auto_press_test_task(void *arg)
|
||||||
|
{
|
||||||
|
// test BUTTON_PRESS_DOWN
|
||||||
|
xEventGroupWaitBits(g_check, BIT(0) | BIT(1), pdTRUE, pdTRUE, portMAX_DELAY);
|
||||||
|
gpio_set_level(GPIO_OUTPUT_IO_45, 0);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
|
|
||||||
|
// // test BUTTON_PRESS_UP
|
||||||
|
xEventGroupWaitBits(g_check, BIT(0) | BIT(1), pdTRUE, pdTRUE, portMAX_DELAY);
|
||||||
|
gpio_set_level(GPIO_OUTPUT_IO_45, 1);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(200));
|
||||||
|
|
||||||
|
// test BUTTON_PRESS_REPEAT
|
||||||
|
xEventGroupWaitBits(g_check, BIT(0) | BIT(1), pdTRUE, pdTRUE, portMAX_DELAY);
|
||||||
|
gpio_set_level(GPIO_OUTPUT_IO_45, 0);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
|
gpio_set_level(GPIO_OUTPUT_IO_45, 1);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
|
gpio_set_level(GPIO_OUTPUT_IO_45, 0);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
|
|
||||||
|
// test BUTTON_PRESS_REPEAT_DONE
|
||||||
|
xEventGroupWaitBits(g_check, BIT(0) | BIT(1), pdTRUE, pdTRUE, portMAX_DELAY);
|
||||||
|
gpio_set_level(GPIO_OUTPUT_IO_45, 1);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(200));
|
||||||
|
|
||||||
|
// test BUTTON_SINGLE_CLICK
|
||||||
|
xEventGroupWaitBits(g_check, BIT(0) | BIT(1), pdTRUE, pdTRUE, portMAX_DELAY);
|
||||||
|
gpio_set_level(GPIO_OUTPUT_IO_45, 0);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
|
gpio_set_level(GPIO_OUTPUT_IO_45, 1);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(200));
|
||||||
|
|
||||||
|
// test BUTTON_DOUBLE_CLICK
|
||||||
|
xEventGroupWaitBits(g_check, BIT(0) | BIT(1), pdTRUE, pdTRUE, portMAX_DELAY);
|
||||||
|
gpio_set_level(GPIO_OUTPUT_IO_45, 0);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
|
gpio_set_level(GPIO_OUTPUT_IO_45, 1);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
|
gpio_set_level(GPIO_OUTPUT_IO_45, 0);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
|
gpio_set_level(GPIO_OUTPUT_IO_45, 1);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(200));
|
||||||
|
|
||||||
|
// test BUTTON_MULTIPLE_CLICK
|
||||||
|
xEventGroupWaitBits(g_check, BIT(0) | BIT(1), pdTRUE, pdTRUE, portMAX_DELAY);
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
gpio_set_level(GPIO_OUTPUT_IO_45, 0);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
|
gpio_set_level(GPIO_OUTPUT_IO_45, 1);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
|
}
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
|
|
||||||
|
// test BUTTON_LONG_PRESS_START
|
||||||
|
xEventGroupWaitBits(g_check, BIT(0) | BIT(1), pdTRUE, pdTRUE, portMAX_DELAY);
|
||||||
|
gpio_set_level(GPIO_OUTPUT_IO_45, 0);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(1600));
|
||||||
|
|
||||||
|
// test BUTTON_LONG_PRESS_HOLD and BUTTON_LONG_PRESS_UP
|
||||||
|
xEventGroupWaitBits(g_check, BIT(0) | BIT(1), pdTRUE, pdTRUE, portMAX_DELAY);
|
||||||
|
gpio_set_level(GPIO_OUTPUT_IO_45, 1);
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "Auto Press Success!");
|
||||||
|
vTaskDelete(NULL);
|
||||||
|
}
|
||||||
|
static void button_auto_check_cb_1(void *arg, void *data)
|
||||||
|
{
|
||||||
|
if (iot_button_get_event(g_btns[0]) == state) {
|
||||||
|
xEventGroupSetBits(g_check, BIT(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static void button_auto_check_cb(void *arg, void *data)
|
||||||
|
{
|
||||||
|
if (iot_button_get_event(g_btns[0]) == state) {
|
||||||
|
ESP_LOGI(TAG, "Auto check: button event %s pass", button_event_str[state]);
|
||||||
|
xEventGroupSetBits(g_check, BIT(0));
|
||||||
|
if (++state >= BUTTON_EVENT_MAX) {
|
||||||
|
xSemaphoreGive(g_auto_check_pass);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("gpio button auto-test", "[button][iot][auto]")
|
||||||
|
{
|
||||||
|
state = BUTTON_PRESS_DOWN;
|
||||||
|
g_check = xEventGroupCreate();
|
||||||
|
g_auto_check_pass = xSemaphoreCreateBinary();
|
||||||
|
xEventGroupSetBits(g_check, BIT(0) | BIT(1));
|
||||||
|
button_config_t cfg = {
|
||||||
|
.type = BUTTON_TYPE_GPIO,
|
||||||
|
.long_press_time = CONFIG_BUTTON_LONG_PRESS_TIME_MS,
|
||||||
|
.short_press_time = CONFIG_BUTTON_SHORT_PRESS_TIME_MS,
|
||||||
|
.gpio_button_config = {
|
||||||
|
.gpio_num = 0,
|
||||||
|
.active_level = 0,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
g_btns[0] = iot_button_create(&cfg);
|
||||||
|
TEST_ASSERT_NOT_NULL(g_btns[0]);
|
||||||
|
|
||||||
|
/* register iot_button callback for all the button_event */
|
||||||
|
for (uint8_t i = 0; i < BUTTON_EVENT_MAX; i++) {
|
||||||
|
if (i == BUTTON_MULTIPLE_CLICK) {
|
||||||
|
button_event_config_t btn_cfg;
|
||||||
|
btn_cfg.event = i;
|
||||||
|
btn_cfg.event_data.multiple_clicks.clicks = 4;
|
||||||
|
iot_button_register_event_cb(g_btns[0], btn_cfg, button_auto_check_cb_1, NULL);
|
||||||
|
iot_button_register_event_cb(g_btns[0], btn_cfg, button_auto_check_cb, NULL);
|
||||||
|
} else {
|
||||||
|
iot_button_register_cb(g_btns[0], i, button_auto_check_cb_1, NULL);
|
||||||
|
iot_button_register_cb(g_btns[0], i, button_auto_check_cb, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL(ESP_OK, iot_button_set_param(g_btns[0], BUTTON_LONG_PRESS_TIME_MS, (void *)1500));
|
||||||
|
|
||||||
|
gpio_config_t io_conf = {
|
||||||
|
.intr_type = GPIO_INTR_DISABLE,
|
||||||
|
.mode = GPIO_MODE_OUTPUT,
|
||||||
|
.pin_bit_mask = (1ULL << GPIO_OUTPUT_IO_45),
|
||||||
|
.pull_down_en = 0,
|
||||||
|
.pull_up_en = 0,
|
||||||
|
};
|
||||||
|
gpio_config(&io_conf);
|
||||||
|
gpio_set_level(GPIO_OUTPUT_IO_45, 1);
|
||||||
|
|
||||||
|
xTaskCreate(button_auto_press_test_task, "button_auto_press_test_task", 1024 * 4, NULL, 10, NULL);
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL(pdTRUE, xSemaphoreTake(g_auto_check_pass, pdMS_TO_TICKS(6000)));
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < BUTTON_EVENT_MAX; i++) {
|
||||||
|
button_event_config_t btn_cfg;
|
||||||
|
btn_cfg.event = i;
|
||||||
|
if (i == BUTTON_MULTIPLE_CLICK) {
|
||||||
|
btn_cfg.event_data.multiple_clicks.clicks = 4;
|
||||||
|
} else if (i == BUTTON_LONG_PRESS_UP || i == BUTTON_LONG_PRESS_START) {
|
||||||
|
btn_cfg.event_data.long_press.press_time = 1500;
|
||||||
|
}
|
||||||
|
iot_button_unregister_event(g_btns[0], btn_cfg, button_auto_check_cb);
|
||||||
|
iot_button_unregister_event(g_btns[0], btn_cfg, button_auto_check_cb_1);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL(ESP_OK, iot_button_delete(g_btns[0]));
|
||||||
|
vEventGroupDelete(g_check);
|
||||||
|
vSemaphoreDelete(g_auto_check_pass);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
|
}
|
||||||
|
|
||||||
|
#define TOLERANCE CONFIG_BUTTON_LONG_PRESS_TOLERANCE_MS
|
||||||
|
|
||||||
|
uint16_t long_press_time[5] = {2000, 2500, 3000, 3500, 4000};
|
||||||
|
static SemaphoreHandle_t long_press_check = NULL;
|
||||||
|
static SemaphoreHandle_t long_press_auto_check_pass = NULL;
|
||||||
|
unsigned int status = 0;
|
||||||
|
|
||||||
|
static void button_auto_long_press_test_task(void *arg)
|
||||||
|
{
|
||||||
|
// Test for BUTTON_LONG_PRESS_START
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
xSemaphoreTake(long_press_check, portMAX_DELAY);
|
||||||
|
gpio_set_level(GPIO_OUTPUT_IO_45, 0);
|
||||||
|
status = (BUTTON_LONG_PRESS_START << 16) | long_press_time[i];
|
||||||
|
if (i > 0) {
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(long_press_time[i] - long_press_time[i - 1]));
|
||||||
|
} else {
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(long_press_time[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
|
gpio_set_level(GPIO_OUTPUT_IO_45, 1);
|
||||||
|
xSemaphoreGive(long_press_auto_check_pass);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
|
// Test for BUTTON_LONG_PRESS_UP
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
xSemaphoreTake(long_press_check, portMAX_DELAY);
|
||||||
|
status = (BUTTON_LONG_PRESS_UP << 16) | long_press_time[i];
|
||||||
|
gpio_set_level(GPIO_OUTPUT_IO_45, 0);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(long_press_time[i] + 10));
|
||||||
|
gpio_set_level(GPIO_OUTPUT_IO_45, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "Auto Long Press Success!");
|
||||||
|
vTaskDelete(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void button_long_press_auto_check_cb(void *arg, void *data)
|
||||||
|
{
|
||||||
|
uint32_t value = (uint32_t)data;
|
||||||
|
uint16_t event = (0xffff0000 & value) >> 16;
|
||||||
|
uint16_t time = 0xffff & value;
|
||||||
|
uint16_t ticks_time = iot_button_get_ticks_time(g_btns[0]);
|
||||||
|
if (status == value && abs(ticks_time - time) <= TOLERANCE) {
|
||||||
|
ESP_LOGI(TAG, "Auto check: button event: %s and time: %d pass", button_event_str[event], time);
|
||||||
|
|
||||||
|
if (event == BUTTON_LONG_PRESS_UP && time == long_press_time[4]) {
|
||||||
|
xSemaphoreGive(long_press_auto_check_pass);
|
||||||
|
}
|
||||||
|
|
||||||
|
xSemaphoreGive(long_press_check);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("gpio button long_press auto-test", "[button][long_press][auto]")
|
||||||
|
{
|
||||||
|
ESP_LOGI(TAG, "Starting the test");
|
||||||
|
long_press_check = xSemaphoreCreateBinary();
|
||||||
|
long_press_auto_check_pass = xSemaphoreCreateBinary();
|
||||||
|
xSemaphoreGive(long_press_check);
|
||||||
|
button_config_t cfg = {
|
||||||
|
.type = BUTTON_TYPE_GPIO,
|
||||||
|
.long_press_time = CONFIG_BUTTON_LONG_PRESS_TIME_MS,
|
||||||
|
.short_press_time = CONFIG_BUTTON_SHORT_PRESS_TIME_MS,
|
||||||
|
.gpio_button_config = {
|
||||||
|
.gpio_num = 0,
|
||||||
|
.active_level = 0,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
g_btns[0] = iot_button_create(&cfg);
|
||||||
|
TEST_ASSERT_NOT_NULL(g_btns[0]);
|
||||||
|
|
||||||
|
button_event_config_t btn_cfg;
|
||||||
|
btn_cfg.event = BUTTON_LONG_PRESS_START;
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
btn_cfg.event_data.long_press.press_time = long_press_time[i];
|
||||||
|
uint32_t data = (btn_cfg.event << 16) | long_press_time[i];
|
||||||
|
iot_button_register_event_cb(g_btns[0], btn_cfg, button_long_press_auto_check_cb, (void*)data);
|
||||||
|
}
|
||||||
|
|
||||||
|
gpio_config_t io_conf = {
|
||||||
|
.intr_type = GPIO_INTR_DISABLE,
|
||||||
|
.mode = GPIO_MODE_OUTPUT,
|
||||||
|
.pin_bit_mask = (1ULL << GPIO_OUTPUT_IO_45),
|
||||||
|
.pull_down_en = 0,
|
||||||
|
.pull_up_en = 0,
|
||||||
|
};
|
||||||
|
gpio_config(&io_conf);
|
||||||
|
gpio_set_level(GPIO_OUTPUT_IO_45, 1);
|
||||||
|
xTaskCreate(button_auto_long_press_test_task, "button_auto_long_press_test_task", 1024 * 4, NULL, 10, NULL);
|
||||||
|
|
||||||
|
xSemaphoreTake(long_press_auto_check_pass, portMAX_DELAY);
|
||||||
|
iot_button_unregister_cb(g_btns[0], BUTTON_LONG_PRESS_START);
|
||||||
|
btn_cfg.event = BUTTON_LONG_PRESS_UP;
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
btn_cfg.event_data.long_press.press_time = long_press_time[i];
|
||||||
|
uint32_t data = (btn_cfg.event << 16) | long_press_time[i];
|
||||||
|
iot_button_register_event_cb(g_btns[0], btn_cfg, button_long_press_auto_check_cb, (void*)data);
|
||||||
|
}
|
||||||
|
TEST_ASSERT_EQUAL(pdTRUE, xSemaphoreTake(long_press_auto_check_pass, pdMS_TO_TICKS(17000)));
|
||||||
|
TEST_ASSERT_EQUAL(ESP_OK, iot_button_delete(g_btns[0]));
|
||||||
|
vSemaphoreDelete(long_press_check);
|
||||||
|
vSemaphoreDelete(long_press_auto_check_pass);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void check_leak(size_t before_free, size_t after_free, const char *type)
|
||||||
|
{
|
||||||
|
ssize_t delta = after_free - before_free;
|
||||||
|
printf("MALLOC_CAP_%s: Before %u bytes free, After %u bytes free (delta %d)\n", type, before_free, after_free, delta);
|
||||||
|
TEST_ASSERT_MESSAGE(delta >= TEST_MEMORY_LEAK_THRESHOLD, "memory leak");
|
||||||
|
}
|
||||||
|
|
||||||
|
void setUp(void)
|
||||||
|
{
|
||||||
|
before_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
|
||||||
|
before_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void tearDown(void)
|
||||||
|
{
|
||||||
|
size_t after_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
|
||||||
|
size_t after_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
|
||||||
|
check_leak(before_free_8bit, after_free_8bit, "8BIT");
|
||||||
|
check_leak(before_free_32bit, after_free_32bit, "32BIT");
|
||||||
|
}
|
||||||
|
|
||||||
|
void app_main(void)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* ____ _ _ _______ _
|
||||||
|
*| _ \ | | | | |__ __| | |
|
||||||
|
*| |_) | _ _ | |_ | |_ ___ _ __ | | ___ ___ | |_
|
||||||
|
*| _ < | | | || __|| __|/ _ \ | '_ \ | | / _ \/ __|| __|
|
||||||
|
*| |_) || |_| || |_ | |_| (_) || | | | | || __/\__ \| |_
|
||||||
|
*|____/ \__,_| \__| \__|\___/ |_| |_| |_| \___||___/ \__|
|
||||||
|
*/
|
||||||
|
printf(" ____ _ _ _______ _ \n");
|
||||||
|
printf(" | _ \\ | | | | |__ __| | | \n");
|
||||||
|
printf(" | |_) | _ _ | |_ | |_ ___ _ __ | | ___ ___ | |_ \n");
|
||||||
|
printf(" | _ < | | | || __|| __|/ _ \\ | '_ \\ | | / _ \\/ __|| __|\n");
|
||||||
|
printf(" | |_) || |_| || |_ | |_| (_) || | | | | || __/\\__ \\| |_ \n");
|
||||||
|
printf(" |____/ \\__,_| \\__| \\__|\\___/ |_| |_| |_| \\___||___/ \\__|\n");
|
||||||
|
unity_run_menu();
|
||||||
|
}
|
||||||
29
components/espressif__button/test_apps/pytest_button.py
Normal file
29
components/espressif__button/test_apps/pytest_button.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
'''
|
||||||
|
Steps to run these cases:
|
||||||
|
- Build
|
||||||
|
- . ${IDF_PATH}/export.sh
|
||||||
|
- pip install idf_build_apps
|
||||||
|
- python tools/build_apps.py components/button/test_apps -t esp32s3
|
||||||
|
- Test
|
||||||
|
- pip install -r tools/requirements/requirement.pytest.txt
|
||||||
|
- pytest components/button/test_apps --target esp32s3
|
||||||
|
'''
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from pytest_embedded import Dut
|
||||||
|
|
||||||
|
@pytest.mark.target('esp32s3')
|
||||||
|
@pytest.mark.env('button')
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
'config',
|
||||||
|
[
|
||||||
|
'defaults',
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_button(dut: Dut)-> None:
|
||||||
|
dut.expect_exact('Press ENTER to see the list of tests.')
|
||||||
|
dut.write('[auto]')
|
||||||
|
dut.expect_unity_test_output(timeout = 300)
|
||||||
1
components/espressif__cmake_utilities/.component_hash
Normal file
1
components/espressif__cmake_utilities/.component_hash
Normal file
@ -0,0 +1 @@
|
|||||||
|
351350613ceafba240b761b4ea991e0f231ac7a9f59a9ee901f751bddc0bb18f
|
||||||
89
components/espressif__cmake_utilities/CHANGELOG.md
Normal file
89
components/espressif__cmake_utilities/CHANGELOG.md
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
## v0.5.3 - 2023-09-15
|
||||||
|
|
||||||
|
* fix `add_dependencies called with incorrect number of arguments` in `relinker.cmake`
|
||||||
|
* `include(cmake_utilities)` is not suggested now, to avoid cmake_utilities dependency issue
|
||||||
|
|
||||||
|
## v0.5.2 - 2023-09-15
|
||||||
|
|
||||||
|
* Support work on older ESP-IDF, eg: 4.3.x
|
||||||
|
|
||||||
|
## v0.5.1 - 2023-08-22
|
||||||
|
|
||||||
|
* Add string 1-byte align support
|
||||||
|
|
||||||
|
## v0.5.0 - 2023-08-02
|
||||||
|
|
||||||
|
* Add GCC LTO support
|
||||||
|
|
||||||
|
## v0.4.8 - 2023-05-24
|
||||||
|
|
||||||
|
* Add unit test app
|
||||||
|
|
||||||
|
### Bugfix:
|
||||||
|
|
||||||
|
* fix customer target redefinition issue
|
||||||
|
|
||||||
|
## v0.4.7 - 2023-04-21
|
||||||
|
|
||||||
|
* gen_compressed_ota: support the addition of a v2 compressed OTA header to compressed firmware.
|
||||||
|
|
||||||
|
## v0.4.6 - 2023-04-20
|
||||||
|
|
||||||
|
* relinker: add IDF v4.3.x support
|
||||||
|
|
||||||
|
## v0.4.5 - 2023-04-17
|
||||||
|
|
||||||
|
* gen_compressed_ota: remove slash use in gen_custom_ota.py so that the script can be used in the Windows cmd terminal.
|
||||||
|
|
||||||
|
## v0.4.4 - 2023-04-07
|
||||||
|
|
||||||
|
* relinker: suppressing the creation of `__pycache__`
|
||||||
|
* relinker: support same name objects in one library
|
||||||
|
|
||||||
|
## v0.4.3 - 2023-03-24
|
||||||
|
|
||||||
|
* relinker: support decoding to get IRAM excluded libraries
|
||||||
|
|
||||||
|
## v0.4.2 - 2023-03-20
|
||||||
|
|
||||||
|
### Bugfix:
|
||||||
|
|
||||||
|
* gen_compressed_ota: Fix the number of bytes reserved in the v3 compressed image header
|
||||||
|
* gen_compressed_ota: Fix definition of MD5 length in compressed image header for different versions.
|
||||||
|
|
||||||
|
## v0.4.1 - 2023-03-15
|
||||||
|
|
||||||
|
* relinker: add option to use customized configuration files
|
||||||
|
* relinker: add option to print error information instead of throwing exception when missing function
|
||||||
|
* relinker: move functions of SPI flash from IRAM to flash only when enable CONFIG_SPI_FLASH_ROM_IMPL
|
||||||
|
* relinker: move some functions of esp_timer from IRAM to flash only when disable CONFIG_ESP_TIMER_SUPPORTS_ISR_DISPATCH_METHOD
|
||||||
|
|
||||||
|
## v0.4.0 - 2023-03-13
|
||||||
|
|
||||||
|
### Feature:
|
||||||
|
|
||||||
|
* Add command `idf.py gen_single_bin` to generate merged bin file
|
||||||
|
* Add command `idf.py flash_single_bin` to flash generated merged bin
|
||||||
|
* Add config `Color in diagnostics` to control the GCC color output
|
||||||
|
|
||||||
|
## v0.3.0 - 2023-03-10
|
||||||
|
|
||||||
|
* Add gen_compressed_ota functionality, please refer to [gen_compressed_ota.md](https://github.com/espressif/esp-iot-solution/tree/master/tools/cmake_utilities/docs/gen_compressed_ota.md)
|
||||||
|
|
||||||
|
## v0.2.1 - 2023-03-09
|
||||||
|
|
||||||
|
### Bugfix:
|
||||||
|
|
||||||
|
* package manager: Fix the compile issue when the name of the component has `-`, just like esp-xxx
|
||||||
|
|
||||||
|
## v0.2.0 - 2023-02-23
|
||||||
|
|
||||||
|
* Add relinker functionality, please refer to [relinker.md](https://github.com/espressif/esp-iot-solution/tree/master/tools/cmake_utilities/docs/relinker.md)
|
||||||
|
|
||||||
|
## v0.1.0 - 2023-01-12
|
||||||
|
|
||||||
|
### Feature:
|
||||||
|
|
||||||
|
* Add function cu_pkg_get_version
|
||||||
|
* Add macro cu_pkg_define_version
|
||||||
|
* Add cmake script to CMAKE_MODULE_PATH
|
||||||
1
components/espressif__cmake_utilities/CMakeLists.txt
Normal file
1
components/espressif__cmake_utilities/CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
idf_component_register()
|
||||||
65
components/espressif__cmake_utilities/Kconfig
Normal file
65
components/espressif__cmake_utilities/Kconfig
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
menu "CMake Utilities"
|
||||||
|
|
||||||
|
config CU_RELINKER_ENABLE
|
||||||
|
bool "Enable relinker"
|
||||||
|
default n
|
||||||
|
help
|
||||||
|
"Enable relinker to linker some IRAM functions to Flash"
|
||||||
|
|
||||||
|
if CU_RELINKER_ENABLE
|
||||||
|
config CU_RELINKER_ENABLE_PRINT_ERROR_INFO_WHEN_MISSING_FUNCTION
|
||||||
|
bool "Print error information when missing function"
|
||||||
|
default y
|
||||||
|
help
|
||||||
|
"Enable this option to print error information instead of
|
||||||
|
throwing exception when missing function"
|
||||||
|
|
||||||
|
config CU_RELINKER_ENABLE_CUSTOMIZED_CONFIGURATION_FILES
|
||||||
|
bool "Enable customized relinker configuration files"
|
||||||
|
default n
|
||||||
|
help
|
||||||
|
"Enable this option to use customized relinker configuration
|
||||||
|
files instead of default ones"
|
||||||
|
|
||||||
|
if CU_RELINKER_ENABLE_CUSTOMIZED_CONFIGURATION_FILES
|
||||||
|
config CU_RELINKER_CUSTOMIZED_CONFIGURATION_FILES_PATH
|
||||||
|
string "Customized relinker configuration files path"
|
||||||
|
default ""
|
||||||
|
help
|
||||||
|
"Customized relinker configuration files path. This path is
|
||||||
|
evaluated relative to the project root directory."
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
choice CU_DIAGNOSTICS_COLOR
|
||||||
|
prompt "Color in diagnostics"
|
||||||
|
default CU_DIAGNOSTICS_COLOR_ALWAYS
|
||||||
|
help
|
||||||
|
Use color in diagnostics. "never", "always", or "auto". If "always", GCC will output
|
||||||
|
with color defined in GCC_COLORS environment variable. If "never", only output plain
|
||||||
|
text. If "auto", only output with color when the standard error is a terminal and when
|
||||||
|
not executing in an emacs shell.
|
||||||
|
|
||||||
|
config CU_DIAGNOSTICS_COLOR_NEVER
|
||||||
|
bool "never"
|
||||||
|
config CU_DIAGNOSTICS_COLOR_ALWAYS
|
||||||
|
bool "always"
|
||||||
|
config CU_DIAGNOSTICS_COLOR_AUTO
|
||||||
|
bool "auto"
|
||||||
|
endchoice
|
||||||
|
|
||||||
|
config CU_GCC_LTO_ENABLE
|
||||||
|
bool "Enable GCC link time optimization(LTO)"
|
||||||
|
default n
|
||||||
|
help
|
||||||
|
"Enable this option, users can enable GCC link time optimization(LTO)
|
||||||
|
feature for target components or dependencies.
|
||||||
|
|
||||||
|
config CU_GCC_STRING_1BYTE_ALIGN
|
||||||
|
bool "GCC string 1-byte align"
|
||||||
|
default n
|
||||||
|
help
|
||||||
|
"Enable this option, user can make string in designated components align
|
||||||
|
by 1-byte instead 1-word(4-byte), this can reduce unnecessary filled data
|
||||||
|
so that to reduce firmware size."
|
||||||
|
endmenu
|
||||||
31
components/espressif__cmake_utilities/README.md
Normal file
31
components/espressif__cmake_utilities/README.md
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
# Cmake utilities
|
||||||
|
|
||||||
|
[](https://components.espressif.com/components/espressif/cmake_utilities)
|
||||||
|
|
||||||
|
This component is aiming to provide some useful CMake utilities outside of ESP-IDF.
|
||||||
|
|
||||||
|
## Use
|
||||||
|
|
||||||
|
1. Add dependency of this component in your component or project's idf_component.yml.
|
||||||
|
|
||||||
|
```yml
|
||||||
|
dependencies:
|
||||||
|
espressif/cmake_utilities: "0.*"
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Include the CMake file you need in your component's CMakeLists.txt after `idf_component_register`, or in your project's CMakeLists.txt
|
||||||
|
|
||||||
|
```cmake
|
||||||
|
// Note: should remove .cmake postfix when using include(), otherwise the requested file will not found
|
||||||
|
// Note: should place this line after `idf_component_register` function
|
||||||
|
// only include the one you needed.
|
||||||
|
include(package_manager)
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Then you can use the corresponding CMake function which is provided by the CMake file.
|
||||||
|
|
||||||
|
## Supported features
|
||||||
|
|
||||||
|
1. [relinker](https://github.com/espressif/esp-iot-solution/blob/master/tools/cmake_utilities/docs/relinker.md)
|
||||||
|
2. [gen_compressed_ota](https://github.com/espressif/esp-iot-solution/blob/master/tools/cmake_utilities/docs/gen_compressed_ota.md)
|
||||||
|
3. [GCC Optimization](https://github.com/espressif/esp-iot-solution/blob/master/tools/cmake_utilities/docs/gcc.md)
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
# Include all cmake modules
|
||||||
|
|
||||||
|
include(gcc)
|
||||||
|
include(gen_compressed_ota)
|
||||||
|
include(gen_single_bin)
|
||||||
|
include(package_manager)
|
||||||
|
include(relinker)
|
||||||
108
components/espressif__cmake_utilities/docs/gcc.md
Normal file
108
components/espressif__cmake_utilities/docs/gcc.md
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
# Link Time Optimization(LTO)
|
||||||
|
|
||||||
|
Link time optimization(LTO) improves the optimization effect of GCC, such as reducing binary size, increasing performance, and so on. For more details please refer to related [GCC documents](https://gcc.gnu.org/onlinedocs/gccint/LTO.html).
|
||||||
|
|
||||||
|
## Use
|
||||||
|
|
||||||
|
To use this feature, you need to include the required CMake file in your project's CMakeLists.txt after `project(XXXX)`.
|
||||||
|
|
||||||
|
```cmake
|
||||||
|
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||||
|
|
||||||
|
project(XXXX)
|
||||||
|
|
||||||
|
include(gcc)
|
||||||
|
```
|
||||||
|
|
||||||
|
The LTO feature is disabled by default. To use it, you should enable the option `CU_GCC_LTO_ENABLE` in menuconfig. Then specify target components or dependencies to be optimized by LTO after `include(gcc)` as follows:
|
||||||
|
|
||||||
|
```cmake
|
||||||
|
include(gcc)
|
||||||
|
|
||||||
|
cu_gcc_lto_set(COMPONENTS component_a component_b
|
||||||
|
DEPENDS dependence_a dependence_b)
|
||||||
|
|
||||||
|
cu_gcc_string_1byte_align(COMPONENTS component_c component_d
|
||||||
|
DEPENDS dependence_c dependence_d)
|
||||||
|
```
|
||||||
|
|
||||||
|
Based on your requirement, set compiling optimization level in the option `COMPILER_OPTIMIZATION`.
|
||||||
|
|
||||||
|
* Note
|
||||||
|
|
||||||
|
```
|
||||||
|
1. Reducing firmware size may decrease performance
|
||||||
|
2. Increasing performance may increase firmware size
|
||||||
|
3. Enable LTO cause compiling time cost increases a lot
|
||||||
|
4. Enable LTO may increase task stack cost
|
||||||
|
5. Enable string 1-byte align may decrease string process speed
|
||||||
|
```
|
||||||
|
|
||||||
|
## Limitation
|
||||||
|
|
||||||
|
At the linking stage, the LTO generates new function indexes instead of the file path as follows:
|
||||||
|
|
||||||
|
- LTO
|
||||||
|
|
||||||
|
```txt
|
||||||
|
.text 0x00000000420016f4 0x6 /tmp/ccdjwYMH.ltrans51.ltrans.o
|
||||||
|
0x00000000420016f4 app_main
|
||||||
|
```
|
||||||
|
|
||||||
|
- Without LTO
|
||||||
|
|
||||||
|
```txt
|
||||||
|
.text.app_main 0x00000000420016f4 0x6 esp-idf/main/libmain.a(app_main.c.obj)
|
||||||
|
0x00000000420016f4 app_main
|
||||||
|
```
|
||||||
|
|
||||||
|
So tools used to relink functions between flash and IRAM can't affect these optimized components and dependencies again. It is recommended that users had better optimize application components and dependencies than kernel and hardware driver ones.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
The example applies LTO in `light` of `esp-matter` because its application code is much larger. Add LTO configuration into project script `CMakeLists.txt` as follows:
|
||||||
|
|
||||||
|
```cmake
|
||||||
|
|
||||||
|
project(light)
|
||||||
|
|
||||||
|
include(gcc)
|
||||||
|
|
||||||
|
# Add
|
||||||
|
set(app_lto_components main chip esp_matter)
|
||||||
|
# Add
|
||||||
|
set(idf_lto_components lwip wpa_supplicant nvs_flash)
|
||||||
|
# Add
|
||||||
|
set(lto_depends mbedcrypto)
|
||||||
|
|
||||||
|
# Add
|
||||||
|
cu_gcc_lto_set(COMPONENTS ${app_lto_components} ${idf_lto_components}
|
||||||
|
DEPENDS ${lto_depends})
|
||||||
|
```
|
||||||
|
|
||||||
|
Configure `ESP32-C2` as the target platform, enable `CU_GCC_LTO_ENABLE` and `CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE`, set `COMPILER_OPTIMIZATION` to be `-Os`.
|
||||||
|
Increase the `main` task stack size to `5120` by option `ESP_MAIN_TASK_STACK_SIZE`.
|
||||||
|
Compile the project, and then you can see the firmware size decrease a lot:
|
||||||
|
|
||||||
|
Option | Firmware size | Stask cost
|
||||||
|
|:-:|:-:|:-:|
|
||||||
|
-Os | 1,113,376 | 2508
|
||||||
|
-Os + LTO | 1,020,640 | 4204
|
||||||
|
|
||||||
|
Then add `cu_gcc_string_1byte_align` after `cu_gcc_lto_set`:
|
||||||
|
|
||||||
|
```cmake
|
||||||
|
# Add
|
||||||
|
cu_gcc_lto_set(COMPONENTS ${app_lto_components} ${idf_lto_components}
|
||||||
|
DEPENDS ${lto_depends})
|
||||||
|
|
||||||
|
cu_gcc_string_1byte_align(COMPONENTS ${app_lto_components} ${idf_lto_components}
|
||||||
|
DEPENDS ${lto_depends})
|
||||||
|
```
|
||||||
|
|
||||||
|
Build the project and the firmware size is:
|
||||||
|
|
||||||
|
Option | Firmware size |
|
||||||
|
|:-:|:-:|
|
||||||
|
-Os + LTO | 1,020,640 |
|
||||||
|
-Os + LTO + string 1-byte align | 1,018,340 |
|
||||||
@ -0,0 +1,41 @@
|
|||||||
|
# Gen Compressed OTA
|
||||||
|
|
||||||
|
When using the compressed OTA, we need to generate the compressed app firmware. This document mainly describes how to generate the compressed app firmware.
|
||||||
|
|
||||||
|
For more information about compressed OTA, refer to [bootloader_support_plus](https://github.com/espressif/esp-iot-solution/tree/master/components/bootloader_support_plus).
|
||||||
|
|
||||||
|
## Use
|
||||||
|
In order to use this feature, you need to include the needed CMake file in your project's CMakeLists.txt after `project(XXXX)`.
|
||||||
|
|
||||||
|
```cmake
|
||||||
|
project(XXXX)
|
||||||
|
|
||||||
|
include(gen_compressed_ota)
|
||||||
|
```
|
||||||
|
|
||||||
|
Generate the compressed app firmware in an ESP-IDF "project" directory by running:
|
||||||
|
|
||||||
|
```plaintext
|
||||||
|
idf.py gen_compressed_ota
|
||||||
|
```
|
||||||
|
|
||||||
|
This command will compile your project first, then it will generate the compressed app firmware. For example, run the command under the project `simple_ota_examples` folder. If there are no errors, the `custom_ota_binaries` folder will be created and contains the following files:
|
||||||
|
|
||||||
|
```plaintext
|
||||||
|
simple_ota.bin.xz
|
||||||
|
simple_ota.bin.xz.packed
|
||||||
|
```
|
||||||
|
|
||||||
|
The file named `simple_ota.bin.xz.packed` is the actual compressed app binary file to be transferred.
|
||||||
|
|
||||||
|
In addition, if [secure boot](https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/security/secure-boot-v2.html) is enabled, the command will generate the signed compressed app binary file:
|
||||||
|
|
||||||
|
```plaintext
|
||||||
|
simple_ota.bin.xz.packed.signed
|
||||||
|
```
|
||||||
|
|
||||||
|
you can also use the script [gen_custom_ota.py](https://github.com/espressif/esp-iot-solution/tree/master/tools/cmake_utilities/scripts/gen_custom_ota.py) to compress the specified app:
|
||||||
|
|
||||||
|
```plaintext
|
||||||
|
python3 gen_custom_ota.py -i simple_ota.bin
|
||||||
|
```
|
||||||
66
components/espressif__cmake_utilities/docs/relinker.md
Normal file
66
components/espressif__cmake_utilities/docs/relinker.md
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
# Relinker
|
||||||
|
|
||||||
|
In ESP-IDF, some functions are put in SRAM when link stage, the reason is that some functions are critical, we need to put them in SRAM to speed up the program, or the functions will be executed when the cache is disabled. But actually, some functions can be put into Flash, here, we provide a script to let the user set the functions which are located in SRAM by default to put them into Flash, in order to save more SRAM which can be used as heap region later. This happens in the linker stage, so we call it as relinker.
|
||||||
|
|
||||||
|
## Use
|
||||||
|
|
||||||
|
In order to use this feature, you need to include the needed CMake file in your project's CMakeLists.txt after `project(XXXX)`.
|
||||||
|
|
||||||
|
```cmake
|
||||||
|
project(XXXX)
|
||||||
|
|
||||||
|
include(relinker)
|
||||||
|
```
|
||||||
|
|
||||||
|
The relinker feature is disabled by default, in order to use it, you need to enable the option `CU_RELINKER_ENABLE` in menuconfig.
|
||||||
|
|
||||||
|
Here are the default configuration files in the folder `cmake_utilities/scripts/relinker/examples/esp32c2`, it's just used as a reference. If you would like to use your own configuration files, please enable option `CU_RELINKER_ENABLE_CUSTOMIZED_CONFIGURATION_FILES` and set the path of your configuration files as following, this path is evaluated relative to the project root directory:
|
||||||
|
|
||||||
|
```
|
||||||
|
[*] Enable customized relinker configuration files
|
||||||
|
(path of your configuration files) Customized relinker configuration files path
|
||||||
|
```
|
||||||
|
|
||||||
|
> Note: Currently only esp32c2 is supported.
|
||||||
|
|
||||||
|
## Configuration Files
|
||||||
|
|
||||||
|
You can refer to the files in the directory of `cmake_utilities/scripts/relinker/examples/esp32c2`:
|
||||||
|
|
||||||
|
- library.csv
|
||||||
|
- object.csv
|
||||||
|
- function.csv
|
||||||
|
|
||||||
|
For example, if you want to link function `__getreent` from SRAM to Flash, firstly you should add it to `function.csv` file as following:
|
||||||
|
|
||||||
|
```
|
||||||
|
libfreertos.a,tasks.c.obj,__getreent,
|
||||||
|
```
|
||||||
|
|
||||||
|
This means function `__getreent` is in object file `tasks.c.obj`, and object file `tasks.c.obj` is in library `libfreertos.a`.
|
||||||
|
|
||||||
|
If function `__getreent` depends on the option `FREERTOS_PLACE_FUNCTIONS_INTO_FLASH` in menuconfig, then it should be:
|
||||||
|
|
||||||
|
```
|
||||||
|
libfreertos.a,tasks.c.obj,__getreent,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH
|
||||||
|
```
|
||||||
|
|
||||||
|
This means when only `FREERTOS_PLACE_FUNCTIONS_INTO_FLASH` is enabled in menuconfig, function `__getreent` will be linked from SRAM to Flash.
|
||||||
|
|
||||||
|
Next step you should add the path of the object file to `object.csv`:
|
||||||
|
|
||||||
|
```
|
||||||
|
libfreertos.a,tasks.c.obj,esp-idf/freertos/CMakeFiles/__idf_freertos.dir/FreeRTOS-Kernel/tasks.c.obj
|
||||||
|
```
|
||||||
|
|
||||||
|
This means the object file `tasks.c.obj` is in library `libfreertos.a` and its location is `esp-idf/freertos/CMakeFiles/__idf_freertos.dir/FreeRTOS-Kernel/tasks.c.obj` relative to directory of `build`.
|
||||||
|
|
||||||
|
Next step you should add path of library to `library.csv`:
|
||||||
|
|
||||||
|
```
|
||||||
|
libfreertos.a,./esp-idf/freertos/libfreertos.a
|
||||||
|
```
|
||||||
|
|
||||||
|
This means library `libfreertos.a`'s location is `./esp-idf/freertos/libfreertos.a` relative to `build`.
|
||||||
|
|
||||||
|
If above related data has exists in corresponding files, please don't add this repeatedly.
|
||||||
84
components/espressif__cmake_utilities/gcc.cmake
Normal file
84
components/espressif__cmake_utilities/gcc.cmake
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
if(CONFIG_CU_GCC_LTO_ENABLE)
|
||||||
|
# Enable cmake interprocedural optimization(IPO) support to check if GCC supports link time optimization(LTO)
|
||||||
|
cmake_policy(SET CMP0069 NEW)
|
||||||
|
include(CheckIPOSupported)
|
||||||
|
|
||||||
|
# Compare to "ar" and "ranlib", "gcc-ar" and "gcc-ranlib" integrate GCC LTO plugin
|
||||||
|
set(CMAKE_AR ${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar)
|
||||||
|
set(CMAKE_RANLIB ${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib)
|
||||||
|
|
||||||
|
macro(cu_gcc_lto_set)
|
||||||
|
check_ipo_supported(RESULT result)
|
||||||
|
if(result)
|
||||||
|
message(STATUS "GCC link time optimization(LTO) is enable")
|
||||||
|
|
||||||
|
set(multi_value COMPONENTS DEPENDS)
|
||||||
|
cmake_parse_arguments(LTO "" "" "${multi_value}" ${ARGN})
|
||||||
|
|
||||||
|
# Use full format LTO object file
|
||||||
|
set(GCC_LTO_OBJECT_TYPE "-ffat-lto-objects")
|
||||||
|
# Set compression level 9(min:0, max:9)
|
||||||
|
set(GCC_LTO_COMPRESSION_LEVEL "-flto-compression-level=9")
|
||||||
|
# Set partition level max to removed used symbol
|
||||||
|
set(GCC_LTO_PARTITION_LEVEL "-flto-partition=max")
|
||||||
|
|
||||||
|
# Set mode "auto" to increase compiling speed
|
||||||
|
set(GCC_LTO_COMPILE_OPTIONS "-flto=auto"
|
||||||
|
${GCC_LTO_OBJECT_TYPE}
|
||||||
|
${GCC_LTO_COMPRESSION_LEVEL})
|
||||||
|
|
||||||
|
# Enable GCC LTO and plugin when linking stage
|
||||||
|
set(GCC_LTO_LINK_OPTIONS "-flto"
|
||||||
|
"-fuse-linker-plugin"
|
||||||
|
${GCC_LTO_OBJECT_TYPE}
|
||||||
|
${GCC_LTO_PARTITION_LEVEL})
|
||||||
|
|
||||||
|
message(STATUS "GCC LTO for components: ${LTO_COMPONENTS}")
|
||||||
|
foreach(c ${LTO_COMPONENTS})
|
||||||
|
idf_component_get_property(t ${c} COMPONENT_LIB)
|
||||||
|
target_compile_options(${t} PRIVATE ${GCC_LTO_COMPILE_OPTIONS})
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
message(STATUS "GCC LTO for dependencies: ${LTO_DEPENDS}")
|
||||||
|
foreach(d ${LTO_DEPENDS})
|
||||||
|
target_compile_options(${d} PRIVATE ${GCC_LTO_COMPILE_OPTIONS})
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER_EQUAL "4.4")
|
||||||
|
target_link_libraries(${project_elf} PRIVATE ${GCC_LTO_LINK_OPTIONS})
|
||||||
|
else()
|
||||||
|
target_link_libraries(${project_elf} ${GCC_LTO_LINK_OPTIONS})
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "GCC link time optimization(LTO) is not supported")
|
||||||
|
endif()
|
||||||
|
endmacro()
|
||||||
|
else()
|
||||||
|
macro(cu_gcc_lto_set)
|
||||||
|
message(STATUS "GCC link time optimization(LTO) is not enable")
|
||||||
|
endmacro()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CONFIG_CU_GCC_STRING_1BYTE_ALIGN)
|
||||||
|
macro(cu_gcc_string_1byte_align)
|
||||||
|
message(STATUS "GCC string 1-byte align is enable")
|
||||||
|
|
||||||
|
set(multi_value COMPONENTS DEPENDS)
|
||||||
|
cmake_parse_arguments(STR_ALIGN "" "" "${multi_value}" ${ARGN})
|
||||||
|
|
||||||
|
message(STATUS "GCC string 1-byte align for components: ${STR_ALIGN_COMPONENTS}")
|
||||||
|
foreach(c ${STR_ALIGN_COMPONENTS})
|
||||||
|
idf_component_get_property(t ${c} COMPONENT_LIB)
|
||||||
|
target_compile_options(${t} PRIVATE "-malign-data=natural")
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
message(STATUS "GCC string 1-byte align for dependencies: ${STR_ALIGN_DEPENDS}")
|
||||||
|
foreach(d ${STR_ALIGN_DEPENDS})
|
||||||
|
target_compile_options(${d} PRIVATE "-malign-data=natural")
|
||||||
|
endforeach()
|
||||||
|
endmacro()
|
||||||
|
else()
|
||||||
|
macro(cu_gcc_string_1byte_align)
|
||||||
|
message(STATUS "GCC string 1-byte align is not enable")
|
||||||
|
endmacro()
|
||||||
|
endif()
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
if (NOT TARGET gen_compressed_ota)
|
||||||
|
add_custom_target(gen_compressed_ota)
|
||||||
|
|
||||||
|
if (CONFIG_SECURE_SIGNED_ON_UPDATE_NO_SECURE_BOOT OR CONFIG_SECURE_BOOT_V2_ENABLED)
|
||||||
|
set(COMPRESSED_OTA_BIN_SIGN_PARA --sign_key ${PROJECT_DIR}/${CONFIG_SECURE_BOOT_SIGNING_KEY})
|
||||||
|
else()
|
||||||
|
set(COMPRESSED_OTA_BIN_SIGN_PARA )
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(GEN_COMPRESSED_BIN_CMD ${CMAKE_CURRENT_LIST_DIR}/scripts/gen_custom_ota.py ${COMPRESSED_OTA_BIN_SIGN_PARA} --add_app_header)
|
||||||
|
|
||||||
|
add_custom_command(TARGET gen_compressed_ota
|
||||||
|
POST_BUILD
|
||||||
|
COMMAND ${PYTHON} ${GEN_COMPRESSED_BIN_CMD}
|
||||||
|
COMMENT "The gen compresssed bin cmd is: ${GEN_COMPRESSED_BIN_CMD}"
|
||||||
|
)
|
||||||
|
add_dependencies(gen_compressed_ota gen_project_binary)
|
||||||
|
endif()
|
||||||
27
components/espressif__cmake_utilities/gen_single_bin.cmake
Normal file
27
components/espressif__cmake_utilities/gen_single_bin.cmake
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# Extend command to idf.py
|
||||||
|
|
||||||
|
# Generate single bin with name ${CMAKE_PROJECT_NAME}_merged.bin
|
||||||
|
if (NOT TARGET gen_single_bin)
|
||||||
|
add_custom_target(
|
||||||
|
gen_single_bin
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E echo "Merge bin files to ${CMAKE_PROJECT_NAME}_merged.bin"
|
||||||
|
COMMAND ${ESPTOOLPY} --chip ${IDF_TARGET} merge_bin -o ${CMAKE_PROJECT_NAME}_merged.bin @flash_args
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E echo "Merge bin done"
|
||||||
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||||
|
DEPENDS gen_project_binary bootloader
|
||||||
|
VERBATIM USES_TERMINAL
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Flash bin ${CMAKE_PROJECT_NAME}_merged.bin to target chip
|
||||||
|
if (NOT TARGET flash_single_bin)
|
||||||
|
add_custom_target(
|
||||||
|
flash_single_bin
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E echo "Flash merged bin ${CMAKE_PROJECT_NAME}_merged.bin to address 0x0"
|
||||||
|
COMMAND ${ESPTOOLPY} --chip ${IDF_TARGET} write_flash 0x0 ${CMAKE_PROJECT_NAME}_merged.bin
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E echo "Flash merged bin done"
|
||||||
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||||
|
DEPENDS gen_single_bin
|
||||||
|
VERBATIM USES_TERMINAL
|
||||||
|
)
|
||||||
|
endif()
|
||||||
7
components/espressif__cmake_utilities/idf_component.yml
Normal file
7
components/espressif__cmake_utilities/idf_component.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
dependencies:
|
||||||
|
idf:
|
||||||
|
version: '>=4.1'
|
||||||
|
description: A collection of useful cmake utilities
|
||||||
|
issues: https://github.com/espressif/esp-iot-solution/issues
|
||||||
|
url: https://github.com/espressif/esp-iot-solution/tree/master/tools/cmake_utilities
|
||||||
|
version: 0.5.3
|
||||||
45
components/espressif__cmake_utilities/package_manager.cmake
Normal file
45
components/espressif__cmake_utilities/package_manager.cmake
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
# cu_pkg_get_version
|
||||||
|
#
|
||||||
|
# @brief Get the package's version information, the package is installed by component manager.
|
||||||
|
#
|
||||||
|
# @param[in] pkg_path the package's path, normally it's ${CMAKE_CURRENT_LIST_DIR}.
|
||||||
|
#
|
||||||
|
# @param[out] ver_major the major version of the package
|
||||||
|
# @param[out] ver_minor the minor version of the package
|
||||||
|
# @param[out] ver_patch the patch version of the package
|
||||||
|
function(cu_pkg_get_version pkg_path ver_major ver_minor ver_patch)
|
||||||
|
set(yml_file "${pkg_path}/idf_component.yml")
|
||||||
|
if(EXISTS ${yml_file})
|
||||||
|
file(READ ${yml_file} ver)
|
||||||
|
string(REGEX MATCH "(^|\n)version: \"?([0-9]+).([0-9]+).([0-9]+)\"?" _ ${ver})
|
||||||
|
set(${ver_major} ${CMAKE_MATCH_2} PARENT_SCOPE)
|
||||||
|
set(${ver_minor} ${CMAKE_MATCH_3} PARENT_SCOPE)
|
||||||
|
set(${ver_patch} ${CMAKE_MATCH_4} PARENT_SCOPE)
|
||||||
|
else()
|
||||||
|
message(WARNING " ${yml_file} not exist")
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
# cu_pkg_define_version
|
||||||
|
#
|
||||||
|
# @brief Add the package's version definitions using format ${NAME}_VER_MAJOR ${NAME}_VER_MINOR ${NAME}_VER_PATCH,
|
||||||
|
# the ${NAME} will be inferred from package path, and namespace like `espressif__` will be removed if the package download from esp-registry
|
||||||
|
# eg. espressif__usb_stream and usb_stream will generate same version definitions USB_STREAM_VER_MAJOR ...
|
||||||
|
#
|
||||||
|
# @param[in] pkg_path the package's path, normally it's ${CMAKE_CURRENT_LIST_DIR}.
|
||||||
|
#
|
||||||
|
macro(cu_pkg_define_version pkg_path)
|
||||||
|
cu_pkg_get_version(${pkg_path} ver_major ver_minor ver_patch)
|
||||||
|
get_filename_component(pkg_name ${pkg_path} NAME)
|
||||||
|
string(FIND ${pkg_name} "__" pkg_name_pos)
|
||||||
|
if(pkg_name_pos GREATER -1)
|
||||||
|
math(EXPR pkg_name_pos "${pkg_name_pos} + 2")
|
||||||
|
string(SUBSTRING ${pkg_name} ${pkg_name_pos} -1 pkg_name)
|
||||||
|
endif()
|
||||||
|
string(TOUPPER ${pkg_name} pkg_name)
|
||||||
|
string(REPLACE "-" "_" pkg_name ${pkg_name})
|
||||||
|
message(STATUS "${pkg_name}: ${ver_major}.${ver_minor}.${ver_patch}")
|
||||||
|
list(LENGTH pkg_name_list len)
|
||||||
|
target_compile_options(${COMPONENT_LIB} PUBLIC
|
||||||
|
-D${pkg_name}_VER_MAJOR=${ver_major} -D${pkg_name}_VER_MINOR=${ver_minor} -D${pkg_name}_VER_PATCH=${ver_patch})
|
||||||
|
endmacro()
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_MODULE_PATH})
|
||||||
|
|
||||||
|
if(CONFIG_CU_DIAGNOSTICS_COLOR_ALWAYS)
|
||||||
|
add_compile_options(-fdiagnostics-color=always)
|
||||||
|
elseif(CONFIG_CU_DIAGNOSTICS_COLOR_AUTO)
|
||||||
|
add_compile_options(-fdiagnostics-color=auto)
|
||||||
|
elseif(CONFIG_CU_DIAGNOSTICS_COLOR_NEVER)
|
||||||
|
add_compile_options(-fdiagnostics-color=never)
|
||||||
|
endif()
|
||||||
73
components/espressif__cmake_utilities/relinker.cmake
Normal file
73
components/espressif__cmake_utilities/relinker.cmake
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
# @brief Link designated functions from SRAM to Flash to save SRAM
|
||||||
|
if(CONFIG_CU_RELINKER_ENABLE)
|
||||||
|
# project_elf variable is only in project.cmake
|
||||||
|
if(NOT TARGET customer_sections AND DEFINED project_elf)
|
||||||
|
message(STATUS "Relinker is enabled.")
|
||||||
|
if(CONFIG_IDF_TARGET_ESP32C2)
|
||||||
|
set(target "esp32c2")
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "Other targets are not supported.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CONFIG_CU_RELINKER_ENABLE_CUSTOMIZED_CONFIGURATION_FILES)
|
||||||
|
idf_build_get_property(project_dir PROJECT_DIR)
|
||||||
|
get_filename_component(cfg_file_path "${CONFIG_CU_RELINKER_CUSTOMIZED_CONFIGURATION_FILES_PATH}"
|
||||||
|
ABSOLUTE BASE_DIR "${project_dir}")
|
||||||
|
|
||||||
|
if(NOT EXISTS "${cfg_file_path}")
|
||||||
|
message(FATAL_ERROR "Relinker Configuration files path ${cfg_file_path} is not found.")
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
set(cfg_file_path ${PROJECT_DIR}/relinker/${target})
|
||||||
|
if(NOT EXISTS ${cfg_file_path})
|
||||||
|
set(cfg_file_path ${CMAKE_CURRENT_LIST_DIR}/scripts/relinker/examples/${target})
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
message(STATUS "Relinker configuration files: ${cfg_file_path}")
|
||||||
|
|
||||||
|
set(library_file "${cfg_file_path}/library.csv")
|
||||||
|
set(object_file "${cfg_file_path}/object.csv")
|
||||||
|
set(function_file "${cfg_file_path}/function.csv")
|
||||||
|
set(relinker_script "${CMAKE_CURRENT_LIST_DIR}/scripts/relinker/relinker.py")
|
||||||
|
|
||||||
|
set(cmake_objdump "${CMAKE_OBJDUMP}")
|
||||||
|
set(link_path "${CMAKE_BINARY_DIR}/esp-idf/esp_system/ld")
|
||||||
|
set(link_src_file "${link_path}/sections.ld")
|
||||||
|
set(link_dst_file "${link_path}/customer_sections.ld")
|
||||||
|
|
||||||
|
set(relinker_opts --input ${link_src_file}
|
||||||
|
--output ${link_dst_file}
|
||||||
|
--library ${library_file}
|
||||||
|
--object ${object_file}
|
||||||
|
--function ${function_file}
|
||||||
|
--sdkconfig ${sdkconfig}
|
||||||
|
--objdump ${cmake_objdump})
|
||||||
|
|
||||||
|
if(CONFIG_CU_RELINKER_ENABLE_PRINT_ERROR_INFO_WHEN_MISSING_FUNCTION)
|
||||||
|
list(APPEND relinker_opts --missing_function_info True)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
idf_build_get_property(link_depends __LINK_DEPENDS)
|
||||||
|
|
||||||
|
add_custom_command(OUTPUT ${link_dst_file}
|
||||||
|
COMMAND ${python} -B ${relinker_script}
|
||||||
|
${relinker_opts}
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy
|
||||||
|
${link_dst_file}
|
||||||
|
${link_src_file}
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E echo
|
||||||
|
/*relinker*/ >>
|
||||||
|
${link_dst_file}
|
||||||
|
DEPENDS "${link_depends}"
|
||||||
|
"${library_file}"
|
||||||
|
"${object_file}"
|
||||||
|
"${function_file}"
|
||||||
|
VERBATIM)
|
||||||
|
|
||||||
|
add_custom_target(customer_sections DEPENDS ${link_dst_file})
|
||||||
|
add_dependencies(${project_elf} customer_sections)
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
message(STATUS "Relinker isn't enabled.")
|
||||||
|
endif()
|
||||||
243
components/espressif__cmake_utilities/scripts/gen_custom_ota.py
Executable file
243
components/espressif__cmake_utilities/scripts/gen_custom_ota.py
Executable file
@ -0,0 +1,243 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
#
|
||||||
|
# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import struct
|
||||||
|
import argparse
|
||||||
|
import binascii
|
||||||
|
import hashlib
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import shutil
|
||||||
|
import json
|
||||||
|
import lzma
|
||||||
|
|
||||||
|
# src_file = 'hello-world.bin'
|
||||||
|
# compressed_file = 'hello-world.bin.xz'
|
||||||
|
# packed_compressed_file = 'hello-world.bin.xz.packed'
|
||||||
|
# siged_packed_compressed_file = 'hello-world.bin.xz.packed.signed'
|
||||||
|
|
||||||
|
binary_compress_type = {'none': 0, 'xz':1}
|
||||||
|
header_version = {'v1': 1, 'v2': 2, 'v3': 3}
|
||||||
|
|
||||||
|
SCRIPT_VERSION = '1.0.0'
|
||||||
|
ORIGIN_APP_IMAGE_HEADER_LEN = 288 # sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t) + sizeof(esp_app_desc_t). See esp_app_format.h
|
||||||
|
# At present, we calculate the checksum of the first 4KB data of the old app.
|
||||||
|
OLD_APP_CHECK_DATA_SIZE = 4096
|
||||||
|
|
||||||
|
# v1 compressed data header:
|
||||||
|
# Note: Encryption_type field is deprecated, the field is reserved for compatibility.
|
||||||
|
# |------|---------|---------|----------|------------|------------|-----------|----------|----------------|----------------|--------------|------------|
|
||||||
|
# | | Magic | header | Compress | delta | Encryption | Reserved | Firmware | The length of | The MD5 of | The CRC32 for| compressed |
|
||||||
|
# | | number | version | type | type | type | | version | compressed data| compressed data| the header | data |
|
||||||
|
# |------|---------|---------|----------|------------|------------|-----------|----------|----------------|----------------|--------------|------------|
|
||||||
|
# | Size | 4 bytes | 1 byte | 4 bits | 4 bits | 1 bytes | 1 bytes | 32 bytes | 4 bytes | 32 bytes | 4 bytes | |
|
||||||
|
# |------|---------|---------|----------|------------|------------|-----------|----------|----------------|----------------|--------------|------------|
|
||||||
|
# | Data | String | | | | | | String | little-endian | byte string | little-endian| |
|
||||||
|
# | type | ended | | | | | | ended | integer | | integer | |
|
||||||
|
# | |with ‘\0’| | | | | | with ‘\0’| | | | Binary data|
|
||||||
|
# |------|---------|---------|----------|------------|------------|-----------|----------|----------------|----------------|--------------|------------|
|
||||||
|
# | Data | “ESP” | 1 | 0/1 | 0/1 | | | | | | | |
|
||||||
|
# |------|---------|---------|----------|------------|------------|-----------|----------|----------------|----------------|--------------|------------|
|
||||||
|
|
||||||
|
# v2 compressed data header
|
||||||
|
# Note: Encryption_type field is deprecated, the field is reserved for compatibility.
|
||||||
|
# |------|---------|---------|----------|------------|------------|-----------|----------|----------------|----------------|---------------|---------------|--------------|------------|
|
||||||
|
# | | Magic | header | Compress | delta | Encryption | Reserved | Firmware | The length of | The MD5 of | base app check| The CRC32 for | The CRC32 for| compressed |
|
||||||
|
# | | number | version | type | type | type | | version | compressed data| compressed data| data len | base app data | the header | data |
|
||||||
|
# |------|---------|---------|----------|------------|------------|-----------|----------|----------------|----------------|---------------|---------------|--------------|------------|
|
||||||
|
# | Size | 4 bytes | 1 byte | 4 bits | 4 bits | 1 bytes | 1 bytes | 32 bytes | 4 bytes | 32 bytes | 4 bytes | 4 bytes | 4 bytes | |
|
||||||
|
# |------|---------|---------|----------|------------|------------|-----------|----------|----------------|----------------|---------------|---------------|--------------|------------|
|
||||||
|
# | Data | String | | | | | | String | little-endian | byte string | little-endian | little-endian | little-endian| |
|
||||||
|
# | type | ended | | | | | | ended | integer | | integer | integer | integer | |
|
||||||
|
# | |with ‘\0’| | | | | | with ‘\0’| | | | | | Binary data|
|
||||||
|
# |------|---------|---------|----------|------------|------------|-----------|----------|----------------|----------------|---------------|---------------|--------------|------------|
|
||||||
|
# | Data | “ESP” | 1 | 0/1 | 0/1 | | | | | | | | | |
|
||||||
|
# |------|---------|---------|----------|------------|------------|-----------|----------|----------------|----------------|---------------|---------------|--------------|------------|
|
||||||
|
|
||||||
|
# v3 compressed data header:
|
||||||
|
# |------|---------|---------|----------|------------|-----------|----------------|----------------|--------------|------------|
|
||||||
|
# | | Magic | header | Compress | Reserved | Reserved | The length of | The MD5 of | The CRC32 for| compressed |
|
||||||
|
# | | number | version | type | | | compressed data| compressed data| the header | data |
|
||||||
|
# |------|---------|---------|----------|------------|-----------|----------------|----------------|--------------|------------|
|
||||||
|
# | Size | 4 bytes | 1 byte | 4 bits | 4 bits | 8 bytes | 4 bytes | 16 bytes | 4 bytes | |
|
||||||
|
# |------|---------|---------|----------|------------|-----------|----------------|----------------|--------------|------------|
|
||||||
|
# | Data | String | integer | | | | little-endian | byte string | little-endian| |
|
||||||
|
# | type | ended | | | | | integer | | integer | |
|
||||||
|
# | |with ‘\0’| | | | | | | | Binary data|
|
||||||
|
# |------|---------|---------|----------|------------|-----------|----------------|----------------|--------------|------------|
|
||||||
|
# | Data | “ESP” | 3 | 0/1 | | | | | | |
|
||||||
|
# |------|---------|---------|----------|------------|-----------|----------------|----------------|--------------|------------|
|
||||||
|
|
||||||
|
def xz_compress(store_directory, in_file):
|
||||||
|
compressed_file = ''.join([in_file,'.xz'])
|
||||||
|
if(os.path.exists(compressed_file)):
|
||||||
|
os.remove(compressed_file)
|
||||||
|
|
||||||
|
xz_compressor_filter = [
|
||||||
|
{"id": lzma.FILTER_LZMA2, "preset": 6, "dict_size": 64*1024},
|
||||||
|
]
|
||||||
|
with open(in_file, 'rb') as src_f:
|
||||||
|
data = src_f.read()
|
||||||
|
with lzma.open(compressed_file, "wb", format=lzma.FORMAT_XZ, check=lzma.CHECK_CRC32, filters=xz_compressor_filter) as f:
|
||||||
|
f.write(data)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
if not os.path.exists(os.path.join(store_directory, os.path.split(compressed_file)[1])):
|
||||||
|
shutil.copy(compressed_file, store_directory)
|
||||||
|
print('copy xz file done')
|
||||||
|
|
||||||
|
def secure_boot_sign(sign_key, in_file, out_file):
|
||||||
|
ret = subprocess.call('espsecure.py sign_data --version 2 --keyfile {} --output {} {}'.format(sign_key, out_file, in_file), shell = True)
|
||||||
|
if ret:
|
||||||
|
raise Exception('sign failed')
|
||||||
|
|
||||||
|
def get_app_name():
|
||||||
|
with open('flasher_args.json') as f:
|
||||||
|
try:
|
||||||
|
flasher_args = json.load(f)
|
||||||
|
return flasher_args['app']['file']
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
return ''
|
||||||
|
|
||||||
|
def get_script_version():
|
||||||
|
return SCRIPT_VERSION
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument('-hv', '--header_ver', nargs='?', choices = ['v1', 'v2', 'v3'],
|
||||||
|
default='v3', help='the version of the packed file header [default:v3]')
|
||||||
|
parser.add_argument('-c', '--compress_type', nargs= '?', choices = ['none', 'xz'],
|
||||||
|
default='xz', help='compressed type [default:xz]')
|
||||||
|
parser.add_argument('-i', '--in_file', nargs = '?',
|
||||||
|
default='', help='the new app firmware')
|
||||||
|
parser.add_argument('--sign_key', nargs = '?',
|
||||||
|
default='', help='the sign key used for secure boot')
|
||||||
|
parser.add_argument('-fv', '--fw_ver', nargs='?',
|
||||||
|
default='', help='the version of the compressed data(this field is deprecated in v3)')
|
||||||
|
parser.add_argument('--add_app_header', action="store_true", help='add app header to use native esp_ota_* & esp_https_ota_* APIs')
|
||||||
|
parser.add_argument('-v', '--version', action='version', version=get_script_version(), help='the version of the script')
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
compress_type = args.compress_type
|
||||||
|
firmware_ver = args.fw_ver
|
||||||
|
src_file = args.in_file
|
||||||
|
sign_key = args.sign_key
|
||||||
|
header_ver = args.header_ver
|
||||||
|
add_app_header = args.add_app_header
|
||||||
|
|
||||||
|
if src_file == '':
|
||||||
|
origin_app_name = get_app_name()
|
||||||
|
if(origin_app_name == ''):
|
||||||
|
print('get origin app name fail')
|
||||||
|
return
|
||||||
|
|
||||||
|
if os.path.exists(origin_app_name):
|
||||||
|
src_file = origin_app_name
|
||||||
|
else:
|
||||||
|
print('origin app.bin not found')
|
||||||
|
return
|
||||||
|
|
||||||
|
print('src file is: {}'.format(src_file))
|
||||||
|
|
||||||
|
# rebuild the cpmpressed_app directroy
|
||||||
|
cpmoressed_app_directory = 'custom_ota_binaries'
|
||||||
|
if os.path.exists(cpmoressed_app_directory):
|
||||||
|
shutil.rmtree(cpmoressed_app_directory)
|
||||||
|
|
||||||
|
os.mkdir(cpmoressed_app_directory)
|
||||||
|
print('The compressed file will store in {}'.format(cpmoressed_app_directory))
|
||||||
|
|
||||||
|
#step1: compress
|
||||||
|
if compress_type == 'xz':
|
||||||
|
xz_compress(cpmoressed_app_directory, os.path.abspath(src_file))
|
||||||
|
|
||||||
|
origin_app_name = os.path.split(src_file)[1]
|
||||||
|
|
||||||
|
compressed_file_name = ''.join([origin_app_name, '.xz'])
|
||||||
|
compressed_file = os.path.join(cpmoressed_app_directory, compressed_file_name)
|
||||||
|
else:
|
||||||
|
compressed_file = ''.join(src_file)
|
||||||
|
|
||||||
|
print('compressed file is: {}'.format(compressed_file))
|
||||||
|
|
||||||
|
#step2: packet the compressed image header
|
||||||
|
with open(src_file, 'rb') as s_f:
|
||||||
|
src_image_header = bytearray(s_f.read(ORIGIN_APP_IMAGE_HEADER_LEN))
|
||||||
|
src_image_header[1] = 0x00
|
||||||
|
|
||||||
|
packed_file = ''.join([compressed_file,'.packed'])
|
||||||
|
with open(compressed_file, 'rb') as src_f:
|
||||||
|
data = src_f.read()
|
||||||
|
f_len = src_f.tell()
|
||||||
|
# magic number
|
||||||
|
bin_data = struct.pack('4s', b'ESP')
|
||||||
|
# header version
|
||||||
|
bin_data += struct.pack('B', header_version[header_ver])
|
||||||
|
# Compress type
|
||||||
|
bin_data += struct.pack('B', binary_compress_type[compress_type])
|
||||||
|
print('compressed type: {}'.format(binary_compress_type[compress_type]))
|
||||||
|
# in header v1/v2, there is a field "Encryption type", this field has been deprecated in v3
|
||||||
|
if (header_version[header_ver] < 3):
|
||||||
|
bin_data += struct.pack('B', 0)
|
||||||
|
# Reserved
|
||||||
|
bin_data += struct.pack('?', 0)
|
||||||
|
# Firmware version
|
||||||
|
bin_data += struct.pack('32s', firmware_ver.encode())
|
||||||
|
else:
|
||||||
|
# Reserved
|
||||||
|
bin_data += struct.pack('10s', b'0')
|
||||||
|
# The length of the compressed data
|
||||||
|
bin_data += struct.pack('<I', f_len)
|
||||||
|
print('compressed data len: {}'.format(f_len))
|
||||||
|
# The MD5 for the compressed data
|
||||||
|
if (header_version[header_ver] < 3):
|
||||||
|
bin_data += struct.pack('32s', hashlib.md5(data).digest())
|
||||||
|
if (header_version[header_ver] == 2):
|
||||||
|
# Todo, if it's diff OTA, write base app check data len
|
||||||
|
bin_data += struct.pack('<I', 0)
|
||||||
|
# Todo, if it's diff OTA, write base app crc32 checksum
|
||||||
|
bin_data += struct.pack('<I', 0)
|
||||||
|
else:
|
||||||
|
bin_data += struct.pack('16s', hashlib.md5(data).digest())
|
||||||
|
# The CRC32 for the header
|
||||||
|
bin_data += struct.pack('<I', binascii.crc32(bin_data, 0x0))
|
||||||
|
|
||||||
|
# write compressed data
|
||||||
|
bin_data += data
|
||||||
|
with open(packed_file, 'wb') as dst_f:
|
||||||
|
# write compressed image header and compressed dada
|
||||||
|
dst_f.write(bin_data)
|
||||||
|
|
||||||
|
print('packed file is: {}'.format(packed_file))
|
||||||
|
|
||||||
|
#step3: if need sign, then sign the packed image
|
||||||
|
if sign_key != '':
|
||||||
|
signed_file = ''.join([packed_file,'.signed'])
|
||||||
|
secure_boot_sign(sign_key, packed_file, signed_file)
|
||||||
|
print('signed_file is: {}'.format(signed_file))
|
||||||
|
else:
|
||||||
|
signed_file = ''.join(packed_file)
|
||||||
|
|
||||||
|
if (header_version[header_ver] == 3) and add_app_header:
|
||||||
|
with open(signed_file, 'rb+') as src_f:
|
||||||
|
packed_data = src_f.read()
|
||||||
|
src_f.seek(0)
|
||||||
|
# write origin app image header
|
||||||
|
src_f.write(src_image_header)
|
||||||
|
# write compressed image header and compressed dada
|
||||||
|
src_f.write(packed_data)
|
||||||
|
print('app image header has been added')
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
try:
|
||||||
|
main()
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
sys.exit(2)
|
||||||
@ -0,0 +1,211 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
#
|
||||||
|
# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import csv
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import re
|
||||||
|
from io import StringIO
|
||||||
|
|
||||||
|
OPT_MIN_LEN = 7
|
||||||
|
|
||||||
|
espidf_objdump = None
|
||||||
|
espidf_missing_function_info = True
|
||||||
|
|
||||||
|
class sdkconfig_c:
|
||||||
|
def __init__(self, path):
|
||||||
|
lines = open(path).read().splitlines()
|
||||||
|
config = dict()
|
||||||
|
for l in lines:
|
||||||
|
if len(l) > OPT_MIN_LEN and l[0] != '#':
|
||||||
|
mo = re.match( r'(.*)=(.*)', l, re.M|re.I)
|
||||||
|
if mo:
|
||||||
|
config[mo.group(1)]=mo.group(2).replace('"', '')
|
||||||
|
self.config = config
|
||||||
|
|
||||||
|
def index(self, i):
|
||||||
|
return self.config[i]
|
||||||
|
|
||||||
|
def check(self, options):
|
||||||
|
options = options.replace(' ', '')
|
||||||
|
if '&&' in options:
|
||||||
|
for i in options.split('&&'):
|
||||||
|
if i[0] == '!':
|
||||||
|
i = i[1:]
|
||||||
|
if i in self.config:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
if i not in self.config:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
i = options
|
||||||
|
if i[0] == '!':
|
||||||
|
i = i[1:]
|
||||||
|
if i in self.config:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
if i not in self.config:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
class object_c:
|
||||||
|
def read_dump_info(self, pathes):
|
||||||
|
new_env = os.environ.copy()
|
||||||
|
new_env['LC_ALL'] = 'C'
|
||||||
|
dumps = list()
|
||||||
|
print('pathes:', pathes)
|
||||||
|
for path in pathes:
|
||||||
|
try:
|
||||||
|
dump = StringIO(subprocess.check_output([espidf_objdump, '-t', path], env=new_env).decode())
|
||||||
|
dumps.append(dump.readlines())
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
raise RuntimeError('cmd:%s result:%s'%(e.cmd, e.returncode))
|
||||||
|
return dumps
|
||||||
|
|
||||||
|
def get_func_section(self, dumps, func):
|
||||||
|
for dump in dumps:
|
||||||
|
for l in dump:
|
||||||
|
if ' %s'%(func) in l and '*UND*' not in l:
|
||||||
|
m = re.match(r'(\S*)\s*([glw])\s*([F|O])\s*(\S*)\s*(\S*)\s*(\S*)\s*', l, re.M|re.I)
|
||||||
|
if m and m[6] == func:
|
||||||
|
return m[4].replace('.text.', '')
|
||||||
|
if espidf_missing_function_info:
|
||||||
|
print('%s failed to find section'%(func))
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
raise RuntimeError('%s failed to find section'%(func))
|
||||||
|
|
||||||
|
def __init__(self, name, pathes, libray):
|
||||||
|
self.name = name
|
||||||
|
self.libray = libray
|
||||||
|
self.funcs = dict()
|
||||||
|
self.pathes = pathes
|
||||||
|
self.dumps = self.read_dump_info(pathes)
|
||||||
|
|
||||||
|
def append(self, func):
|
||||||
|
section = self.get_func_section(self.dumps, func)
|
||||||
|
if section != None:
|
||||||
|
self.funcs[func] = section
|
||||||
|
|
||||||
|
def functions(self):
|
||||||
|
nlist = list()
|
||||||
|
for i in self.funcs:
|
||||||
|
nlist.append(i)
|
||||||
|
return nlist
|
||||||
|
|
||||||
|
def sections(self):
|
||||||
|
nlist = list()
|
||||||
|
for i in self.funcs:
|
||||||
|
nlist.append(self.funcs[i])
|
||||||
|
return nlist
|
||||||
|
|
||||||
|
class library_c:
|
||||||
|
def __init__(self, name, path):
|
||||||
|
self.name = name
|
||||||
|
self.path = path
|
||||||
|
self.objs = dict()
|
||||||
|
|
||||||
|
def append(self, obj, path, func):
|
||||||
|
if obj not in self.objs:
|
||||||
|
self.objs[obj] = object_c(obj, path, self.name)
|
||||||
|
self.objs[obj].append(func)
|
||||||
|
|
||||||
|
class libraries_c:
|
||||||
|
def __init__(self):
|
||||||
|
self.libs = dict()
|
||||||
|
|
||||||
|
def append(self, lib, lib_path, obj, obj_path, func):
|
||||||
|
if lib not in self.libs:
|
||||||
|
self.libs[lib] = library_c(lib, lib_path)
|
||||||
|
self.libs[lib].append(obj, obj_path, func)
|
||||||
|
|
||||||
|
def dump(self):
|
||||||
|
for libname in self.libs:
|
||||||
|
lib = self.libs[libname]
|
||||||
|
for objname in lib.objs:
|
||||||
|
obj = lib.objs[objname]
|
||||||
|
print('%s, %s, %s, %s'%(libname, objname, obj.path, obj.funcs))
|
||||||
|
|
||||||
|
class paths_c:
|
||||||
|
def __init__(self):
|
||||||
|
self.paths = dict()
|
||||||
|
|
||||||
|
def append(self, lib, obj, path):
|
||||||
|
if '$IDF_PATH' in path:
|
||||||
|
path = path.replace('$IDF_PATH', os.environ['IDF_PATH'])
|
||||||
|
|
||||||
|
if lib not in self.paths:
|
||||||
|
self.paths[lib] = dict()
|
||||||
|
if obj not in self.paths[lib]:
|
||||||
|
self.paths[lib][obj] = list()
|
||||||
|
self.paths[lib][obj].append(path)
|
||||||
|
|
||||||
|
def index(self, lib, obj):
|
||||||
|
if lib not in self.paths:
|
||||||
|
return None
|
||||||
|
if '*' in self.paths[lib]:
|
||||||
|
obj = '*'
|
||||||
|
return self.paths[lib][obj]
|
||||||
|
|
||||||
|
def generator(library_file, object_file, function_file, sdkconfig_file, missing_function_info, objdump='riscv32-esp-elf-objdump'):
|
||||||
|
global espidf_objdump, espidf_missing_function_info
|
||||||
|
espidf_objdump = objdump
|
||||||
|
espidf_missing_function_info = missing_function_info
|
||||||
|
|
||||||
|
sdkconfig = sdkconfig_c(sdkconfig_file)
|
||||||
|
|
||||||
|
lib_paths = paths_c()
|
||||||
|
for p in csv.DictReader(open(library_file, 'r')):
|
||||||
|
lib_paths.append(p['library'], '*', p['path'])
|
||||||
|
|
||||||
|
obj_paths = paths_c()
|
||||||
|
for p in csv.DictReader(open(object_file, 'r')):
|
||||||
|
obj_paths.append(p['library'], p['object'], p['path'])
|
||||||
|
|
||||||
|
libraries = libraries_c()
|
||||||
|
for d in csv.DictReader(open(function_file, 'r')):
|
||||||
|
if d['option'] and sdkconfig.check(d['option']) == False:
|
||||||
|
print('skip %s(%s)'%(d['function'], d['option']))
|
||||||
|
continue
|
||||||
|
lib_path = lib_paths.index(d['library'], '*')
|
||||||
|
obj_path = obj_paths.index(d['library'], d['object'])
|
||||||
|
if not obj_path:
|
||||||
|
obj_path = lib_path
|
||||||
|
libraries.append(d['library'], lib_path[0], d['object'], obj_path, d['function'])
|
||||||
|
return libraries
|
||||||
|
|
||||||
|
def main():
|
||||||
|
argparser = argparse.ArgumentParser(description='Libraries management')
|
||||||
|
|
||||||
|
argparser.add_argument(
|
||||||
|
'--library', '-l',
|
||||||
|
help='Library description file',
|
||||||
|
type=str)
|
||||||
|
|
||||||
|
argparser.add_argument(
|
||||||
|
'--object', '-b',
|
||||||
|
help='Object description file',
|
||||||
|
type=str)
|
||||||
|
|
||||||
|
argparser.add_argument(
|
||||||
|
'--function', '-f',
|
||||||
|
help='Function description file',
|
||||||
|
type=str)
|
||||||
|
|
||||||
|
argparser.add_argument(
|
||||||
|
'--sdkconfig', '-s',
|
||||||
|
help='sdkconfig file',
|
||||||
|
type=str)
|
||||||
|
|
||||||
|
args = argparser.parse_args()
|
||||||
|
|
||||||
|
libraries = generator(args.library, args.object, args.function, args.sdkconfig)
|
||||||
|
# libraries.dump()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
@ -0,0 +1,365 @@
|
|||||||
|
library,object,function,option
|
||||||
|
libble_app.a,ble_hw.c.o,r_ble_hw_resolv_list_get_cur_entry,
|
||||||
|
libble_app.a,ble_ll_adv.c.o,r_ble_ll_adv_set_sched,
|
||||||
|
libble_app.a,ble_ll_adv.c.o,r_ble_ll_adv_sync_pdu_make,
|
||||||
|
libble_app.a,ble_ll_adv.c.o,r_ble_ll_adv_sync_calculate,
|
||||||
|
libble_app.a,ble_ll_conn.c.o,r_ble_ll_conn_is_dev_connected,
|
||||||
|
libble_app.a,ble_ll_ctrl.c.o,r_ble_ll_ctrl_tx_done,
|
||||||
|
libble_app.a,ble_lll_adv.c.o,r_ble_lll_adv_aux_scannable_pdu_payload_len,
|
||||||
|
libble_app.a,ble_lll_adv.c.o,r_ble_lll_adv_halt,
|
||||||
|
libble_app.a,ble_lll_adv.c.o,r_ble_lll_adv_periodic_schedule_next,
|
||||||
|
libble_app.a,ble_lll_conn.c.o,r_ble_lll_conn_cth_flow_free_credit,
|
||||||
|
libble_app.a,ble_lll_conn.c.o,r_ble_lll_conn_update_encryption,
|
||||||
|
libble_app.a,ble_lll_conn.c.o,r_ble_lll_conn_set_slave_flow_control,
|
||||||
|
libble_app.a,ble_lll_conn.c.o,r_ble_lll_init_rx_pkt_isr,
|
||||||
|
libble_app.a,ble_lll_conn.c.o,r_ble_lll_conn_get_rx_mbuf,
|
||||||
|
libble_app.a,ble_lll_rfmgmt.c.o,r_ble_lll_rfmgmt_enable,
|
||||||
|
libble_app.a,ble_lll_rfmgmt.c.o,r_ble_lll_rfmgmt_timer_reschedule,
|
||||||
|
libble_app.a,ble_lll_rfmgmt.c.o,r_ble_lll_rfmgmt_timer_exp,
|
||||||
|
libble_app.a,ble_lll_scan.c.o,r_ble_lll_scan_targeta_is_matched,
|
||||||
|
libble_app.a,ble_lll_scan.c.o,r_ble_lll_scan_rx_isr_on_legacy,
|
||||||
|
libble_app.a,ble_lll_scan.c.o,r_ble_lll_scan_rx_isr_on_aux,
|
||||||
|
libble_app.a,ble_lll_scan.c.o,r_ble_lll_scan_process_rsp_in_isr,
|
||||||
|
libble_app.a,ble_lll_scan.c.o,r_ble_lll_scan_rx_pkt_isr,
|
||||||
|
libble_app.a,ble_lll_sched.c.o,r_ble_lll_sched_execute_check,
|
||||||
|
libble_app.a,ble_lll_sync.c.o,r_ble_lll_sync_event_start_cb,
|
||||||
|
libble_app.a,ble_phy.c.o,r_ble_phy_set_rxhdr,
|
||||||
|
libble_app.a,ble_phy.c.o,r_ble_phy_update_conn_sequence,
|
||||||
|
libble_app.a,ble_phy.c.o,r_ble_phy_set_sequence_mode,
|
||||||
|
libble_app.a,ble_phy.c.o,r_ble_phy_txpower_round,
|
||||||
|
libble_app.a,os_mempool.c.obj,r_os_memblock_put,
|
||||||
|
libbootloader_support.a,bootloader_flash.c.obj,bootloader_read_flash_id,
|
||||||
|
libbootloader_support.a,flash_encrypt.c.obj,esp_flash_encryption_enabled,
|
||||||
|
libbt.a,bt_osi_mem.c.obj,bt_osi_mem_calloc,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,bt_osi_mem.c.obj,bt_osi_mem_malloc,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,bt_osi_mem.c.obj,bt_osi_mem_malloc_internal,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,bt_osi_mem.c.obj,bt_osi_mem_free,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,bt.c.obj,esp_reset_rpa_moudle,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,bt.c.obj,osi_assert_wrapper,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,bt.c.obj,osi_random_wrapper,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,nimble_port.c.obj,nimble_port_run,CONFIG_BT_NIMBLE_ENABLED
|
||||||
|
libbt.a,nimble_port.c.obj,nimble_port_get_dflt_eventq,CONFIG_BT_NIMBLE_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,os_callout_timer_cb,CONFIG_BT_ENABLED && !CONFIG_BT_NIMBLE_USE_ESP_TIMER
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_event_run,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_callout_stop,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_time_get,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_callout_reset,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_callout_is_active,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_callout_get_ticks,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_callout_remaining_ticks,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_time_delay,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_eventq_is_empty,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_mutex_pend,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_mutex_release,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_sem_init,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_sem_pend,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_sem_release,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_callout_init,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_callout_deinit,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_event_is_queued,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_event_get_arg,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_time_ms_to_ticks32,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_time_ticks_to_ms32,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_hw_is_in_critical,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_get_time_forever,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_os_started,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_get_current_task_id,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_event_reset,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_callout_mem_reset,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_event_init,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_sem_get_count,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_eventq_remove,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_hw_exit_critical,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_mutex_init,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_hw_enter_critical,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_eventq_put,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_eventq_get,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_sem_deinit,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_mutex_deinit,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_eventq_deinit,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_eventq_init,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_event_deinit,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_time_ticks_to_ms,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_time_ms_to_ticks,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_callout_set_arg,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_event_set_arg,CONFIG_BT_ENABLED
|
||||||
|
libbt.a,npl_os_freertos.c.obj,npl_freertos_eventq_put,CONFIG_BT_ENABLED
|
||||||
|
libdriver.a,gpio.c.obj,gpio_intr_service,
|
||||||
|
libesp_app_format.a,esp_app_desc.c.obj,esp_app_get_elf_sha256,
|
||||||
|
libesp_hw_support.a,cpu.c.obj,esp_cpu_wait_for_intr,
|
||||||
|
libesp_hw_support.a,cpu.c.obj,esp_cpu_reset,
|
||||||
|
libesp_hw_support.a,esp_clk.c.obj,esp_clk_cpu_freq,
|
||||||
|
libesp_hw_support.a,esp_clk.c.obj,esp_clk_apb_freq,
|
||||||
|
libesp_hw_support.a,esp_clk.c.obj,esp_clk_xtal_freq,
|
||||||
|
libesp_hw_support.a,esp_memory_utils.c.obj,esp_ptr_byte_accessible,
|
||||||
|
libesp_hw_support.a,hw_random.c.obj,esp_random,
|
||||||
|
libesp_hw_support.a,intr_alloc.c.obj,shared_intr_isr,
|
||||||
|
libesp_hw_support.a,intr_alloc.c.obj,esp_intr_noniram_disable,
|
||||||
|
libesp_hw_support.a,intr_alloc.c.obj,esp_intr_noniram_enable,
|
||||||
|
libesp_hw_support.a,intr_alloc.c.obj,esp_intr_enable,
|
||||||
|
libesp_hw_support.a,intr_alloc.c.obj,esp_intr_disable,
|
||||||
|
libesp_hw_support.a,periph_ctrl.c.obj,wifi_bt_common_module_enable,
|
||||||
|
libesp_hw_support.a,periph_ctrl.c.obj,wifi_bt_common_module_disable,
|
||||||
|
libesp_hw_support.a,regi2c_ctrl.c.obj,regi2c_ctrl_read_reg,
|
||||||
|
libesp_hw_support.a,regi2c_ctrl.c.obj,regi2c_ctrl_read_reg_mask,
|
||||||
|
libesp_hw_support.a,regi2c_ctrl.c.obj,regi2c_ctrl_write_reg,
|
||||||
|
libesp_hw_support.a,regi2c_ctrl.c.obj,regi2c_ctrl_write_reg_mask,
|
||||||
|
libesp_hw_support.a,regi2c_ctrl.c.obj,regi2c_enter_critical,
|
||||||
|
libesp_hw_support.a,regi2c_ctrl.c.obj,regi2c_exit_critical,
|
||||||
|
libesp_hw_support.a,regi2c_ctrl.c.obj,regi2c_analog_cali_reg_read,
|
||||||
|
libesp_hw_support.a,regi2c_ctrl.c.obj,regi2c_analog_cali_reg_write,
|
||||||
|
libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_32k_enable_external,
|
||||||
|
libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_fast_src_set,
|
||||||
|
libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_slow_freq_get_hz,
|
||||||
|
libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_slow_src_get,
|
||||||
|
libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_slow_src_set,
|
||||||
|
libesp_hw_support.a,rtc_clk.c.obj,rtc_dig_clk8m_disable,
|
||||||
|
libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_cpu_freq_set_config_fast,
|
||||||
|
libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_8m_enable,
|
||||||
|
libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_8md256_enabled,
|
||||||
|
libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_bbpll_configure,
|
||||||
|
libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_bbpll_enable,
|
||||||
|
libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_cpu_freq_get_config,
|
||||||
|
libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_cpu_freq_mhz_to_config,
|
||||||
|
libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_cpu_freq_set_config,
|
||||||
|
libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_cpu_freq_to_8m,
|
||||||
|
libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_cpu_freq_to_pll_mhz,
|
||||||
|
libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_cpu_freq_set_xtal,
|
||||||
|
libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_xtal_freq_get,
|
||||||
|
libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_cpu_freq_to_xtal,
|
||||||
|
libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_bbpll_disable,
|
||||||
|
libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_apb_freq_update,
|
||||||
|
libesp_hw_support.a,rtc_clk.c.obj,clk_ll_rtc_slow_get_src,FALSE
|
||||||
|
libesp_hw_support.a,rtc_init.c.obj,rtc_vddsdio_set_config,
|
||||||
|
libesp_hw_support.a,rtc_module.c.obj,rtc_isr,
|
||||||
|
libesp_hw_support.a,rtc_module.c.obj,rtc_isr_noniram_disable,
|
||||||
|
libesp_hw_support.a,rtc_module.c.obj,rtc_isr_noniram_enable,
|
||||||
|
libesp_hw_support.a,rtc_sleep.c.obj,rtc_sleep_pu,
|
||||||
|
libesp_hw_support.a,rtc_sleep.c.obj,rtc_sleep_finish,
|
||||||
|
libesp_hw_support.a,rtc_sleep.c.obj,rtc_sleep_get_default_config,
|
||||||
|
libesp_hw_support.a,rtc_sleep.c.obj,rtc_sleep_init,
|
||||||
|
libesp_hw_support.a,rtc_sleep.c.obj,rtc_sleep_low_init,
|
||||||
|
libesp_hw_support.a,rtc_sleep.c.obj,rtc_sleep_start,
|
||||||
|
libesp_hw_support.a,rtc_time.c.obj,rtc_clk_cal,
|
||||||
|
libesp_hw_support.a,rtc_time.c.obj,rtc_clk_cal_internal,
|
||||||
|
libesp_hw_support.a,rtc_time.c.obj,rtc_time_get,
|
||||||
|
libesp_hw_support.a,rtc_time.c.obj,rtc_time_us_to_slowclk,
|
||||||
|
libesp_hw_support.a,rtc_time.c.obj,rtc_time_slowclk_to_us,
|
||||||
|
libesp_hw_support.a,sleep_modes.c.obj,periph_ll_periph_enabled,
|
||||||
|
libesp_hw_support.a,sleep_modes.c.obj,flush_uarts,
|
||||||
|
libesp_hw_support.a,sleep_modes.c.obj,suspend_uarts,
|
||||||
|
libesp_hw_support.a,sleep_modes.c.obj,resume_uarts,
|
||||||
|
libesp_hw_support.a,sleep_modes.c.obj,esp_sleep_start,
|
||||||
|
libesp_hw_support.a,sleep_modes.c.obj,esp_deep_sleep_start,
|
||||||
|
libesp_hw_support.a,sleep_modes.c.obj,esp_light_sleep_inner,
|
||||||
|
libesp_phy.a,phy_init.c.obj,esp_phy_common_clock_enable,
|
||||||
|
libesp_phy.a,phy_init.c.obj,esp_phy_common_clock_disable,
|
||||||
|
libesp_phy.a,phy_init.c.obj,esp_wifi_bt_power_domain_on,
|
||||||
|
libesp_phy.a,phy_override.c.obj,phy_i2c_enter_critical,
|
||||||
|
libesp_phy.a,phy_override.c.obj,phy_i2c_exit_critical,
|
||||||
|
libesp_pm.a,pm_locks.c.obj,esp_pm_lock_acquire,
|
||||||
|
libesp_pm.a,pm_locks.c.obj,esp_pm_lock_release,
|
||||||
|
libesp_pm.a,pm_impl.c.obj,get_lowest_allowed_mode,
|
||||||
|
libesp_pm.a,pm_impl.c.obj,esp_pm_impl_switch_mode,
|
||||||
|
libesp_pm.a,pm_impl.c.obj,on_freq_update,
|
||||||
|
libesp_pm.a,pm_impl.c.obj,vApplicationSleep,CONFIG_FREERTOS_USE_TICKLESS_IDLE
|
||||||
|
libesp_pm.a,pm_impl.c.obj,do_switch,
|
||||||
|
libesp_ringbuf.a,ringbuf.c.obj,prvCheckItemAvail,
|
||||||
|
libesp_ringbuf.a,ringbuf.c.obj,prvGetFreeSize,
|
||||||
|
libesp_ringbuf.a,ringbuf.c.obj,prvReceiveGenericFromISR,
|
||||||
|
libesp_ringbuf.a,ringbuf.c.obj,xRingbufferGetMaxItemSize,
|
||||||
|
libesp_rom.a,esp_rom_systimer.c.obj,systimer_hal_init,
|
||||||
|
libesp_rom.a,esp_rom_systimer.c.obj,systimer_hal_set_alarm_period,
|
||||||
|
libesp_rom.a,esp_rom_systimer.c.obj,systimer_hal_set_alarm_target,
|
||||||
|
libesp_rom.a,esp_rom_systimer.c.obj,systimer_hal_set_tick_rate_ops,
|
||||||
|
libesp_rom.a,esp_rom_uart.c.obj,esp_rom_uart_set_clock_baudrate,
|
||||||
|
libesp_system.a,brownout.c.obj,rtc_brownout_isr_handler,
|
||||||
|
libesp_system.a,cache_err_int.c.obj,esp_cache_err_get_cpuid,
|
||||||
|
libesp_system.a,cpu_start.c.obj,call_start_cpu0,
|
||||||
|
libesp_system.a,crosscore_int.c.obj,esp_crosscore_int_send,
|
||||||
|
libesp_system.a,crosscore_int.c.obj,esp_crosscore_int_send_yield,
|
||||||
|
libesp_system.a,esp_system.c.obj,esp_restart,
|
||||||
|
libesp_system.a,esp_system.c.obj,esp_system_abort,
|
||||||
|
libesp_system.a,reset_reason.c.obj,esp_reset_reason_set_hint,
|
||||||
|
libesp_system.a,reset_reason.c.obj,esp_reset_reason_get_hint,
|
||||||
|
libesp_system.a,ubsan.c.obj,__ubsan_include,
|
||||||
|
libesp_timer.a,esp_timer.c.obj,esp_timer_get_next_alarm_for_wake_up,
|
||||||
|
libesp_timer.a,esp_timer.c.obj,timer_list_unlock,!CONFIG_ESP_TIMER_SUPPORTS_ISR_DISPATCH_METHOD
|
||||||
|
libesp_timer.a,esp_timer.c.obj,timer_list_lock,!CONFIG_ESP_TIMER_SUPPORTS_ISR_DISPATCH_METHOD
|
||||||
|
libesp_timer.a,esp_timer.c.obj,timer_armed,
|
||||||
|
libesp_timer.a,esp_timer.c.obj,timer_remove,
|
||||||
|
libesp_timer.a,esp_timer.c.obj,timer_insert,!CONFIG_ESP_TIMER_SUPPORTS_ISR_DISPATCH_METHOD
|
||||||
|
libesp_timer.a,esp_timer.c.obj,esp_timer_start_once,
|
||||||
|
libesp_timer.a,esp_timer.c.obj,esp_timer_start_periodic,
|
||||||
|
libesp_timer.a,esp_timer.c.obj,esp_timer_stop,
|
||||||
|
libesp_timer.a,esp_timer.c.obj,esp_timer_get_expiry_time,
|
||||||
|
libesp_timer.a,esp_timer_impl_systimer.c.obj,esp_timer_impl_get_time,!CONFIG_ESP_TIMER_SUPPORTS_ISR_DISPATCH_METHOD
|
||||||
|
libesp_timer.a,esp_timer_impl_systimer.c.obj,esp_timer_impl_set_alarm_id,!CONFIG_ESP_TIMER_SUPPORTS_ISR_DISPATCH_METHOD
|
||||||
|
libesp_timer.a,esp_timer_impl_systimer.c.obj,esp_timer_impl_update_apb_freq,
|
||||||
|
libesp_timer.a,esp_timer_impl_systimer.c.obj,esp_timer_impl_get_min_period_us,
|
||||||
|
libesp_timer.a,ets_timer_legacy.c.obj,timer_initialized,
|
||||||
|
libesp_timer.a,ets_timer_legacy.c.obj,ets_timer_arm_us,
|
||||||
|
libesp_timer.a,ets_timer_legacy.c.obj,ets_timer_arm,
|
||||||
|
libesp_timer.a,ets_timer_legacy.c.obj,ets_timer_disarm,
|
||||||
|
libesp_timer.a,system_time.c.obj,esp_system_get_time,
|
||||||
|
libesp_wifi.a,esp_adapter.c.obj,semphr_take_from_isr_wrapper,
|
||||||
|
libesp_wifi.a,esp_adapter.c.obj,wifi_realloc,
|
||||||
|
libesp_wifi.a,esp_adapter.c.obj,coex_event_duration_get_wrapper,
|
||||||
|
libesp_wifi.a,esp_adapter.c.obj,coex_schm_interval_set_wrapper,
|
||||||
|
libesp_wifi.a,esp_adapter.c.obj,esp_empty_wrapper,
|
||||||
|
libesp_wifi.a,esp_adapter.c.obj,wifi_calloc,
|
||||||
|
libesp_wifi.a,esp_adapter.c.obj,wifi_zalloc_wrapper,
|
||||||
|
libesp_wifi.a,esp_adapter.c.obj,env_is_chip_wrapper,
|
||||||
|
libesp_wifi.a,esp_adapter.c.obj,is_from_isr_wrapper,
|
||||||
|
libesp_wifi.a,esp_adapter.c.obj,semphr_give_from_isr_wrapper,
|
||||||
|
libesp_wifi.a,esp_adapter.c.obj,mutex_lock_wrapper,
|
||||||
|
libesp_wifi.a,esp_adapter.c.obj,mutex_unlock_wrapper,
|
||||||
|
libesp_wifi.a,esp_adapter.c.obj,task_ms_to_tick_wrapper,
|
||||||
|
libesp_wifi.a,esp_adapter.c.obj,wifi_apb80m_request_wrapper,
|
||||||
|
libesp_wifi.a,esp_adapter.c.obj,wifi_apb80m_release_wrapper,
|
||||||
|
libesp_wifi.a,esp_adapter.c.obj,timer_arm_wrapper,
|
||||||
|
libesp_wifi.a,esp_adapter.c.obj,wifi_malloc,
|
||||||
|
libesp_wifi.a,esp_adapter.c.obj,timer_disarm_wrapper,
|
||||||
|
libesp_wifi.a,esp_adapter.c.obj,timer_arm_us_wrapper,
|
||||||
|
libesp_wifi.a,esp_adapter.c.obj,wifi_rtc_enable_iso_wrapper,
|
||||||
|
libesp_wifi.a,esp_adapter.c.obj,wifi_rtc_disable_iso_wrapper,
|
||||||
|
libesp_wifi.a,esp_adapter.c.obj,malloc_internal_wrapper,
|
||||||
|
libesp_wifi.a,esp_adapter.c.obj,realloc_internal_wrapper,
|
||||||
|
libesp_wifi.a,esp_adapter.c.obj,calloc_internal_wrapper,
|
||||||
|
libesp_wifi.a,esp_adapter.c.obj,zalloc_internal_wrapper,
|
||||||
|
libesp_wifi.a,esp_adapter.c.obj,coex_status_get_wrapper,
|
||||||
|
libesp_wifi.a,esp_adapter.c.obj,coex_wifi_release_wrapper,
|
||||||
|
libfreertos.a,list.c.obj,uxListRemove,FALSE
|
||||||
|
libfreertos.a,list.c.obj,vListInitialise,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH
|
||||||
|
libfreertos.a,list.c.obj,vListInitialiseItem,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH
|
||||||
|
libfreertos.a,list.c.obj,vListInsert,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH
|
||||||
|
libfreertos.a,list.c.obj,vListInsertEnd,FALSE
|
||||||
|
libfreertos.a,port.c.obj,vApplicationStackOverflowHook,FALSE
|
||||||
|
libfreertos.a,port.c.obj,vPortYieldOtherCore,FALSE
|
||||||
|
libfreertos.a,port.c.obj,vPortYield,
|
||||||
|
libfreertos.a,port_common.c.obj,xPortcheckValidStackMem,
|
||||||
|
libfreertos.a,port_common.c.obj,vApplicationGetTimerTaskMemory,
|
||||||
|
libfreertos.a,port_common.c.obj,esp_startup_start_app_common,
|
||||||
|
libfreertos.a,port_common.c.obj,xPortCheckValidTCBMem,
|
||||||
|
libfreertos.a,port_common.c.obj,vApplicationGetIdleTaskMemory,
|
||||||
|
libfreertos.a,port_systick.c.obj,vPortSetupTimer,
|
||||||
|
libfreertos.a,port_systick.c.obj,xPortSysTickHandler,FALSE
|
||||||
|
libfreertos.a,queue.c.obj,prvCopyDataFromQueue,
|
||||||
|
libfreertos.a,queue.c.obj,prvGetDisinheritPriorityAfterTimeout,
|
||||||
|
libfreertos.a,queue.c.obj,prvIsQueueEmpty,
|
||||||
|
libfreertos.a,queue.c.obj,prvNotifyQueueSetContainer,
|
||||||
|
libfreertos.a,queue.c.obj,xQueueReceive,
|
||||||
|
libfreertos.a,queue.c.obj,prvUnlockQueue,
|
||||||
|
libfreertos.a,queue.c.obj,xQueueSemaphoreTake,
|
||||||
|
libfreertos.a,queue.c.obj,xQueueReceiveFromISR,
|
||||||
|
libfreertos.a,queue.c.obj,uxQueueMessagesWaitingFromISR,
|
||||||
|
libfreertos.a,queue.c.obj,xQueueIsQueueEmptyFromISR,
|
||||||
|
libfreertos.a,queue.c.obj,xQueueGiveFromISR,
|
||||||
|
libfreertos.a,tasks.c.obj,__getreent,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH
|
||||||
|
libfreertos.a,tasks.c.obj,pcTaskGetName,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH
|
||||||
|
libfreertos.a,tasks.c.obj,prvAddCurrentTaskToDelayedList,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH
|
||||||
|
libfreertos.a,tasks.c.obj,prvDeleteTLS,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH
|
||||||
|
libfreertos.a,tasks.c.obj,pvTaskIncrementMutexHeldCount,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH
|
||||||
|
libfreertos.a,tasks.c.obj,taskSelectHighestPriorityTaskSMP,FALSE
|
||||||
|
libfreertos.a,tasks.c.obj,taskYIELD_OTHER_CORE,FALSE
|
||||||
|
libfreertos.a,tasks.c.obj,vTaskGetSnapshot,CONFIG_FREERTOS_PLACE_SNAPSHOT_FUNS_INTO_FLASH
|
||||||
|
libfreertos.a,tasks.c.obj,vTaskInternalSetTimeOutState,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH
|
||||||
|
libfreertos.a,tasks.c.obj,vTaskPlaceOnEventList,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH
|
||||||
|
libfreertos.a,tasks.c.obj,vTaskPlaceOnEventListRestricted,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH
|
||||||
|
libfreertos.a,tasks.c.obj,vTaskPlaceOnUnorderedEventList,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH
|
||||||
|
libfreertos.a,tasks.c.obj,vTaskPriorityDisinheritAfterTimeout,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH
|
||||||
|
libfreertos.a,tasks.c.obj,vTaskReleaseEventListLock,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH
|
||||||
|
libfreertos.a,tasks.c.obj,vTaskTakeEventListLock,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH
|
||||||
|
libfreertos.a,tasks.c.obj,xTaskCheckForTimeOut,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH
|
||||||
|
libfreertos.a,tasks.c.obj,xTaskGetCurrentTaskHandle,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH
|
||||||
|
libfreertos.a,tasks.c.obj,xTaskGetSchedulerState,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH
|
||||||
|
libfreertos.a,tasks.c.obj,xTaskGetTickCount,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH
|
||||||
|
libfreertos.a,tasks.c.obj,xTaskPriorityDisinherit,FALSE
|
||||||
|
libfreertos.a,tasks.c.obj,xTaskPriorityInherit,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH
|
||||||
|
libfreertos.a,tasks.c.obj,prvGetExpectedIdleTime,FALSE
|
||||||
|
libfreertos.a,tasks.c.obj,vTaskStepTick,FALSE
|
||||||
|
libhal.a,brownout_hal.c.obj,brownout_hal_intr_clear,
|
||||||
|
libhal.a,efuse_hal.c.obj,efuse_hal_chip_revision,
|
||||||
|
libhal.a,efuse_hal.c.obj,efuse_hal_get_major_chip_version,
|
||||||
|
libhal.a,efuse_hal.c.obj,efuse_hal_get_minor_chip_version,
|
||||||
|
libheap.a,heap_caps.c.obj,dram_alloc_to_iram_addr,
|
||||||
|
libheap.a,heap_caps.c.obj,heap_caps_free,
|
||||||
|
libheap.a,heap_caps.c.obj,heap_caps_realloc_base,
|
||||||
|
libheap.a,heap_caps.c.obj,heap_caps_realloc,
|
||||||
|
libheap.a,heap_caps.c.obj,heap_caps_calloc_base,
|
||||||
|
libheap.a,heap_caps.c.obj,heap_caps_calloc,
|
||||||
|
libheap.a,heap_caps.c.obj,heap_caps_malloc_base,
|
||||||
|
libheap.a,heap_caps.c.obj,heap_caps_malloc,
|
||||||
|
libheap.a,heap_caps.c.obj,heap_caps_malloc_default,
|
||||||
|
libheap.a,heap_caps.c.obj,heap_caps_realloc_default,
|
||||||
|
libheap.a,heap_caps.c.obj,find_containing_heap,
|
||||||
|
libheap.a,multi_heap.c.obj,_multi_heap_lock,
|
||||||
|
libheap.a,multi_heap.c.obj,multi_heap_in_rom_init,
|
||||||
|
liblog.a,log_freertos.c.obj,esp_log_timestamp,
|
||||||
|
liblog.a,log_freertos.c.obj,esp_log_impl_lock,
|
||||||
|
liblog.a,log_freertos.c.obj,esp_log_impl_unlock,
|
||||||
|
liblog.a,log_freertos.c.obj,esp_log_impl_lock_timeout,
|
||||||
|
liblog.a,log_freertos.c.obj,esp_log_early_timestamp,
|
||||||
|
liblog.a,log.c.obj,esp_log_write,
|
||||||
|
libmbedcrypto.a,esp_mem.c.obj,esp_mbedtls_mem_calloc,!CONFIG_MBEDTLS_CUSTOM_MEM_ALLOC
|
||||||
|
libmbedcrypto.a,esp_mem.c.obj,esp_mbedtls_mem_free,!CONFIG_MBEDTLS_CUSTOM_MEM_ALLOC
|
||||||
|
libnewlib.a,assert.c.obj,__assert_func,
|
||||||
|
libnewlib.a,assert.c.obj,newlib_include_assert_impl,
|
||||||
|
libnewlib.a,heap.c.obj,_calloc_r,
|
||||||
|
libnewlib.a,heap.c.obj,_free_r,
|
||||||
|
libnewlib.a,heap.c.obj,_malloc_r,
|
||||||
|
libnewlib.a,heap.c.obj,_realloc_r,
|
||||||
|
libnewlib.a,heap.c.obj,calloc,
|
||||||
|
libnewlib.a,heap.c.obj,cfree,
|
||||||
|
libnewlib.a,heap.c.obj,free,
|
||||||
|
libnewlib.a,heap.c.obj,malloc,
|
||||||
|
libnewlib.a,heap.c.obj,newlib_include_heap_impl,
|
||||||
|
libnewlib.a,heap.c.obj,realloc,
|
||||||
|
libnewlib.a,locks.c.obj,_lock_try_acquire_recursive,
|
||||||
|
libnewlib.a,locks.c.obj,lock_release_generic,
|
||||||
|
libnewlib.a,locks.c.obj,_lock_release,
|
||||||
|
libnewlib.a,locks.c.obj,_lock_release_recursive,
|
||||||
|
libnewlib.a,locks.c.obj,__retarget_lock_init,
|
||||||
|
libnewlib.a,locks.c.obj,__retarget_lock_init_recursive,
|
||||||
|
libnewlib.a,locks.c.obj,__retarget_lock_close,
|
||||||
|
libnewlib.a,locks.c.obj,__retarget_lock_close_recursive,
|
||||||
|
libnewlib.a,locks.c.obj,check_lock_nonzero,
|
||||||
|
libnewlib.a,locks.c.obj,__retarget_lock_acquire,
|
||||||
|
libnewlib.a,locks.c.obj,lock_init_generic,
|
||||||
|
libnewlib.a,locks.c.obj,__retarget_lock_acquire_recursive,
|
||||||
|
libnewlib.a,locks.c.obj,__retarget_lock_try_acquire,
|
||||||
|
libnewlib.a,locks.c.obj,__retarget_lock_try_acquire_recursive,
|
||||||
|
libnewlib.a,locks.c.obj,__retarget_lock_release,
|
||||||
|
libnewlib.a,locks.c.obj,__retarget_lock_release_recursive,
|
||||||
|
libnewlib.a,locks.c.obj,_lock_close,
|
||||||
|
libnewlib.a,locks.c.obj,lock_acquire_generic,
|
||||||
|
libnewlib.a,locks.c.obj,_lock_acquire,
|
||||||
|
libnewlib.a,locks.c.obj,_lock_acquire_recursive,
|
||||||
|
libnewlib.a,locks.c.obj,_lock_try_acquire,
|
||||||
|
libnewlib.a,reent_init.c.obj,esp_reent_init,
|
||||||
|
libnewlib.a,time.c.obj,_times_r,
|
||||||
|
libnewlib.a,time.c.obj,_gettimeofday_r,
|
||||||
|
libpp.a,pp_debug.o,wifi_gpio_debug,
|
||||||
|
libpthread.a,pthread.c.obj,pthread_mutex_lock_internal,
|
||||||
|
libpthread.a,pthread.c.obj,pthread_mutex_lock,
|
||||||
|
libpthread.a,pthread.c.obj,pthread_mutex_unlock,
|
||||||
|
libriscv.a,interrupt.c.obj,intr_handler_get,
|
||||||
|
libriscv.a,interrupt.c.obj,intr_handler_set,
|
||||||
|
libriscv.a,interrupt.c.obj,intr_matrix_route,
|
||||||
|
libspi_flash.a,flash_brownout_hook.c.obj,spi_flash_needs_reset_check,FALSE
|
||||||
|
libspi_flash.a,flash_brownout_hook.c.obj,spi_flash_set_erasing_flag,FALSE
|
||||||
|
libspi_flash.a,flash_ops.c.obj,spi_flash_guard_set,CONFIG_SPI_FLASH_ROM_IMPL
|
||||||
|
libspi_flash.a,flash_ops.c.obj,spi_flash_malloc_internal,CONFIG_SPI_FLASH_ROM_IMPL
|
||||||
|
libspi_flash.a,flash_ops.c.obj,spi_flash_rom_impl_init,CONFIG_SPI_FLASH_ROM_IMPL
|
||||||
|
libspi_flash.a,flash_ops.c.obj,esp_mspi_pin_init,CONFIG_SPI_FLASH_ROM_IMPL
|
||||||
|
libspi_flash.a,flash_ops.c.obj,spi_flash_init_chip_state,CONFIG_SPI_FLASH_ROM_IMPL
|
||||||
|
libspi_flash.a,spi_flash_os_func_app.c.obj,delay_us,CONFIG_SPI_FLASH_ROM_IMPL
|
||||||
|
libspi_flash.a,spi_flash_os_func_app.c.obj,get_buffer_malloc,CONFIG_SPI_FLASH_ROM_IMPL
|
||||||
|
libspi_flash.a,spi_flash_os_func_app.c.obj,release_buffer_malloc,CONFIG_SPI_FLASH_ROM_IMPL
|
||||||
|
libspi_flash.a,spi_flash_os_func_app.c.obj,main_flash_region_protected,CONFIG_SPI_FLASH_ROM_IMPL
|
||||||
|
libspi_flash.a,spi_flash_os_func_app.c.obj,main_flash_op_status,CONFIG_SPI_FLASH_ROM_IMPL
|
||||||
|
libspi_flash.a,spi_flash_os_func_app.c.obj,spi1_flash_os_check_yield,CONFIG_SPI_FLASH_ROM_IMPL
|
||||||
|
libspi_flash.a,spi_flash_os_func_app.c.obj,spi1_flash_os_yield,CONFIG_SPI_FLASH_ROM_IMPL
|
||||||
|
libspi_flash.a,spi_flash_os_func_noos.c.obj,start,CONFIG_SPI_FLASH_ROM_IMPL
|
||||||
|
libspi_flash.a,spi_flash_os_func_noos.c.obj,end,CONFIG_SPI_FLASH_ROM_IMPL
|
||||||
|
libspi_flash.a,spi_flash_os_func_noos.c.obj,delay_us,CONFIG_SPI_FLASH_ROM_IMPL
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
library,path
|
||||||
|
libble_app.a,$IDF_PATH/components/bt/controller/lib_esp32c2/esp32c2-bt-lib/libble_app.a
|
||||||
|
libpp.a,$IDF_PATH/components/esp_wifi/lib/esp32c2/libpp.a
|
||||||
|
libbootloader_support.a,./esp-idf/bootloader_support/libbootloader_support.a
|
||||||
|
libbt.a,./esp-idf/bt/libbt.a
|
||||||
|
libdriver.a,./esp-idf/driver/libdriver.a
|
||||||
|
libesp_app_format.a,./esp-idf/esp_app_format/libesp_app_format.a
|
||||||
|
libesp_hw_support.a,./esp-idf/esp_hw_support/libesp_hw_support.a
|
||||||
|
libesp_phy.a,./esp-idf/esp_phy/libesp_phy.a
|
||||||
|
libesp_pm.a,./esp-idf/esp_pm/libesp_pm.a
|
||||||
|
libesp_ringbuf.a,./esp-idf/esp_ringbuf/libesp_ringbuf.a
|
||||||
|
libesp_rom.a,./esp-idf/esp_rom/libesp_rom.a
|
||||||
|
libesp_system.a,./esp-idf/esp_system/libesp_system.a
|
||||||
|
libesp_timer.a,./esp-idf/esp_timer/libesp_timer.a
|
||||||
|
libesp_wifi.a,./esp-idf/esp_wifi/libesp_wifi.a
|
||||||
|
libfreertos.a,./esp-idf/freertos/libfreertos.a
|
||||||
|
libhal.a,./esp-idf/hal/libhal.a
|
||||||
|
libheap.a,./esp-idf/heap/libheap.a
|
||||||
|
liblog.a,./esp-idf/log/liblog.a
|
||||||
|
libmbedcrypto.a,./esp-idf/mbedtls/mbedtls/library/libmbedcrypto.a
|
||||||
|
libnewlib.a,./esp-idf/newlib/libnewlib.a
|
||||||
|
libpthread.a,./esp-idf/pthread/libpthread.a
|
||||||
|
libriscv.a,./esp-idf/riscv/libriscv.a
|
||||||
|
libspi_flash.a,./esp-idf/spi_flash/libspi_flash.a
|
||||||
|
@ -0,0 +1,66 @@
|
|||||||
|
library,object,path
|
||||||
|
libbootloader_support.a,bootloader_flash.c.obj,esp-idf/bootloader_support/CMakeFiles/__idf_bootloader_support.dir/bootloader_flash/src/bootloader_flash.c.obj
|
||||||
|
libbootloader_support.a,flash_encrypt.c.obj,esp-idf/bootloader_support/CMakeFiles/__idf_bootloader_support.dir/src/flash_encrypt.c.obj
|
||||||
|
libbt.a,bt_osi_mem.c.obj,esp-idf/bt/CMakeFiles/__idf_bt.dir/porting/mem/bt_osi_mem.c.obj
|
||||||
|
libbt.a,bt.c.obj,esp-idf/bt/CMakeFiles/__idf_bt.dir/controller/esp32c2/bt.c.obj
|
||||||
|
libbt.a,npl_os_freertos.c.obj,esp-idf/bt/CMakeFiles/__idf_bt.dir/porting/npl/freertos/src/npl_os_freertos.c.obj
|
||||||
|
libbt.a,nimble_port.c.obj,esp-idf/bt/CMakeFiles/__idf_bt.dir/host/nimble/nimble/porting/nimble/src/nimble_port.c.obj
|
||||||
|
libdriver.a,gpio.c.obj,esp-idf/driver/CMakeFiles/__idf_driver.dir/gpio/gpio.c.obj
|
||||||
|
libesp_app_format.a,esp_app_desc.c.obj,esp-idf/esp_app_format/CMakeFiles/__idf_esp_app_format.dir/esp_app_desc.c.obj
|
||||||
|
libesp_hw_support.a,cpu.c.obj,esp-idf/esp_hw_support/CMakeFiles/__idf_esp_hw_support.dir/cpu.c.obj
|
||||||
|
libesp_hw_support.a,esp_clk.c.obj,esp-idf/esp_hw_support/CMakeFiles/__idf_esp_hw_support.dir/esp_clk.c.obj
|
||||||
|
libesp_hw_support.a,esp_memory_utils.c.obj,esp-idf/esp_hw_support/CMakeFiles/__idf_esp_hw_support.dir/esp_memory_utils.c.obj
|
||||||
|
libesp_hw_support.a,hw_random.c.obj,esp-idf/esp_hw_support/CMakeFiles/__idf_esp_hw_support.dir/hw_random.c.obj
|
||||||
|
libesp_hw_support.a,intr_alloc.c.obj,esp-idf/esp_hw_support/CMakeFiles/__idf_esp_hw_support.dir/intr_alloc.c.obj
|
||||||
|
libesp_hw_support.a,periph_ctrl.c.obj,esp-idf/esp_hw_support/CMakeFiles/__idf_esp_hw_support.dir/periph_ctrl.c.obj
|
||||||
|
libesp_hw_support.a,regi2c_ctrl.c.obj,esp-idf/esp_hw_support/CMakeFiles/__idf_esp_hw_support.dir/regi2c_ctrl.c.obj
|
||||||
|
libesp_hw_support.a,rtc_clk.c.obj,esp-idf/esp_hw_support/CMakeFiles/__idf_esp_hw_support.dir/port/esp32c2/rtc_clk.c.obj
|
||||||
|
libesp_hw_support.a,rtc_init.c.obj,esp-idf/esp_hw_support/CMakeFiles/__idf_esp_hw_support.dir/port/esp32c2/rtc_init.c.obj
|
||||||
|
libesp_hw_support.a,rtc_module.c.obj,esp-idf/esp_hw_support/CMakeFiles/__idf_esp_hw_support.dir/rtc_module.c.obj
|
||||||
|
libesp_hw_support.a,rtc_sleep.c.obj,esp-idf/esp_hw_support/CMakeFiles/__idf_esp_hw_support.dir/port/esp32c2/rtc_sleep.c.obj
|
||||||
|
libesp_hw_support.a,rtc_time.c.obj,esp-idf/esp_hw_support/CMakeFiles/__idf_esp_hw_support.dir/port/esp32c2/rtc_time.c.obj
|
||||||
|
libesp_hw_support.a,sleep_modes.c.obj,esp-idf/esp_hw_support/CMakeFiles/__idf_esp_hw_support.dir/sleep_modes.c.obj
|
||||||
|
libesp_phy.a,phy_init.c.obj,esp-idf/esp_phy/CMakeFiles/__idf_esp_phy.dir/src/phy_init.c.obj
|
||||||
|
libesp_phy.a,phy_override.c.obj,esp-idf/esp_phy/CMakeFiles/__idf_esp_phy.dir/src/phy_override.c.obj
|
||||||
|
libesp_pm.a,pm_locks.c.obj,esp-idf/esp_pm/CMakeFiles/__idf_esp_pm.dir/pm_locks.c.obj
|
||||||
|
libesp_pm.a,pm_impl.c.obj,esp-idf/esp_pm/CMakeFiles/__idf_esp_pm.dir/pm_impl.c.obj
|
||||||
|
libesp_ringbuf.a,ringbuf.c.obj,esp-idf/esp_ringbuf/CMakeFiles/__idf_esp_ringbuf.dir/ringbuf.c.obj
|
||||||
|
libesp_rom.a,esp_rom_systimer.c.obj,esp-idf/esp_rom/CMakeFiles/__idf_esp_rom.dir/patches/esp_rom_systimer.c.obj
|
||||||
|
libesp_rom.a,esp_rom_uart.c.obj,esp-idf/esp_rom/CMakeFiles/__idf_esp_rom.dir/patches/esp_rom_uart.c.obj
|
||||||
|
libesp_system.a,brownout.c.obj,esp-idf/esp_system/CMakeFiles/__idf_esp_system.dir/port/brownout.c.obj
|
||||||
|
libesp_system.a,cache_err_int.c.obj,esp-idf/esp_system/CMakeFiles/__idf_esp_system.dir/port/soc/esp32c2/cache_err_int.c.obj
|
||||||
|
libesp_system.a,cpu_start.c.obj,esp-idf/esp_system/CMakeFiles/__idf_esp_system.dir/port/cpu_start.c.obj
|
||||||
|
libesp_system.a,crosscore_int.c.obj,esp-idf/esp_system/CMakeFiles/__idf_esp_system.dir/crosscore_int.c.obj
|
||||||
|
libesp_system.a,esp_system.c.obj,esp-idf/esp_system/CMakeFiles/__idf_esp_system.dir/esp_system.c.obj
|
||||||
|
libesp_system.a,reset_reason.c.obj,esp-idf/esp_system/CMakeFiles/__idf_esp_system.dir/port/soc/esp32c2/reset_reason.c.obj
|
||||||
|
libesp_system.a,ubsan.c.obj,esp-idf/esp_system/CMakeFiles/__idf_esp_system.dir/ubsan.c.obj
|
||||||
|
libesp_timer.a,esp_timer.c.obj,esp-idf/esp_timer/CMakeFiles/__idf_esp_timer.dir/src/esp_timer.c.obj
|
||||||
|
libesp_timer.a,esp_timer_impl_systimer.c.obj,esp-idf/esp_timer/CMakeFiles/__idf_esp_timer.dir/src/esp_timer_impl_systimer.c.obj
|
||||||
|
libesp_timer.a,ets_timer_legacy.c.obj,esp-idf/esp_timer/CMakeFiles/__idf_esp_timer.dir/src/ets_timer_legacy.c.obj
|
||||||
|
libesp_timer.a,system_time.c.obj,esp-idf/esp_timer/CMakeFiles/__idf_esp_timer.dir/src/system_time.c.obj
|
||||||
|
libesp_wifi.a,esp_adapter.c.obj,esp-idf/esp_wifi/CMakeFiles/__idf_esp_wifi.dir/esp32c2/esp_adapter.c.obj
|
||||||
|
libfreertos.a,list.c.obj,esp-idf/freertos/CMakeFiles/__idf_freertos.dir/FreeRTOS-Kernel/list.c.obj
|
||||||
|
libfreertos.a,port.c.obj,esp-idf/freertos/CMakeFiles/__idf_freertos.dir/FreeRTOS-Kernel/portable/riscv/port.c.obj
|
||||||
|
libfreertos.a,port_common.c.obj,esp-idf/freertos/CMakeFiles/__idf_freertos.dir/FreeRTOS-Kernel/portable/port_common.c.obj
|
||||||
|
libfreertos.a,port_systick.c.obj,esp-idf/freertos/CMakeFiles/__idf_freertos.dir/FreeRTOS-Kernel/portable/port_systick.c.obj
|
||||||
|
libfreertos.a,queue.c.obj,esp-idf/freertos/CMakeFiles/__idf_freertos.dir/FreeRTOS-Kernel/queue.c.obj
|
||||||
|
libfreertos.a,tasks.c.obj,esp-idf/freertos/CMakeFiles/__idf_freertos.dir/FreeRTOS-Kernel/tasks.c.obj
|
||||||
|
libhal.a,brownout_hal.c.obj,esp-idf/hal/CMakeFiles/__idf_hal.dir/esp32c2/brownout_hal.c.obj
|
||||||
|
libhal.a,efuse_hal.c.obj,esp-idf/hal/CMakeFiles/__idf_hal.dir/efuse_hal.c.obj
|
||||||
|
libhal.a,efuse_hal.c.obj,esp-idf/hal/CMakeFiles/__idf_hal.dir/esp32c2/efuse_hal.c.obj
|
||||||
|
libheap.a,heap_caps.c.obj,esp-idf/heap/CMakeFiles/__idf_heap.dir/heap_caps.c.obj
|
||||||
|
libheap.a,multi_heap.c.obj,./esp-idf/heap/CMakeFiles/__idf_heap.dir/multi_heap.c.obj
|
||||||
|
liblog.a,log_freertos.c.obj,esp-idf/log/CMakeFiles/__idf_log.dir/log_freertos.c.obj
|
||||||
|
liblog.a,log.c.obj,esp-idf/log/CMakeFiles/__idf_log.dir/log.c.obj
|
||||||
|
libmbedcrypto.a,esp_mem.c.obj,esp-idf/mbedtls/mbedtls/library/CMakeFiles/mbedcrypto.dir/$IDF_PATH/components/mbedtls/port/esp_mem.c.obj
|
||||||
|
libnewlib.a,assert.c.obj,esp-idf/newlib/CMakeFiles/__idf_newlib.dir/assert.c.obj
|
||||||
|
libnewlib.a,heap.c.obj,esp-idf/newlib/CMakeFiles/__idf_newlib.dir/heap.c.obj
|
||||||
|
libnewlib.a,locks.c.obj,esp-idf/newlib/CMakeFiles/__idf_newlib.dir/locks.c.obj
|
||||||
|
libnewlib.a,reent_init.c.obj,esp-idf/newlib/CMakeFiles/__idf_newlib.dir/reent_init.c.obj
|
||||||
|
libnewlib.a,time.c.obj,esp-idf/newlib/CMakeFiles/__idf_newlib.dir/time.c.obj
|
||||||
|
libpthread.a,pthread.c.obj,esp-idf/pthread/CMakeFiles/__idf_pthread.dir/pthread.c.obj
|
||||||
|
libriscv.a,interrupt.c.obj,esp-idf/riscv/CMakeFiles/__idf_riscv.dir/interrupt.c.obj
|
||||||
|
libspi_flash.a,flash_brownout_hook.c.obj,esp-idf/spi_flash/CMakeFiles/__idf_spi_flash.dir/flash_brownout_hook.c.obj
|
||||||
|
libspi_flash.a,flash_ops.c.obj,esp-idf/spi_flash/CMakeFiles/__idf_spi_flash.dir/flash_ops.c.obj
|
||||||
|
libspi_flash.a,spi_flash_os_func_app.c.obj,esp-idf/spi_flash/CMakeFiles/__idf_spi_flash.dir/spi_flash_os_func_app.c.obj
|
||||||
|
libspi_flash.a,spi_flash_os_func_noos.c.obj,esp-idf/spi_flash/CMakeFiles/__idf_spi_flash.dir/spi_flash_os_func_noos.c.obj
|
||||||
|
311
components/espressif__cmake_utilities/scripts/relinker/relinker.py
Executable file
311
components/espressif__cmake_utilities/scripts/relinker/relinker.py
Executable file
@ -0,0 +1,311 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
#
|
||||||
|
# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import argparse
|
||||||
|
import csv
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import re
|
||||||
|
from io import StringIO
|
||||||
|
import configuration
|
||||||
|
|
||||||
|
sys.path.append(os.environ['IDF_PATH'] + '/tools/ldgen')
|
||||||
|
sys.path.append(os.environ['IDF_PATH'] + '/tools/ldgen/ldgen')
|
||||||
|
from entity import EntityDB
|
||||||
|
|
||||||
|
espidf_objdump = None
|
||||||
|
|
||||||
|
def lib_secs(lib, file, lib_path):
|
||||||
|
new_env = os.environ.copy()
|
||||||
|
new_env['LC_ALL'] = 'C'
|
||||||
|
dump = StringIO(subprocess.check_output([espidf_objdump, '-h', lib_path], env=new_env).decode())
|
||||||
|
dump.name = lib
|
||||||
|
|
||||||
|
sections_infos = EntityDB()
|
||||||
|
sections_infos.add_sections_info(dump)
|
||||||
|
|
||||||
|
secs = sections_infos.get_sections(lib, file.split('.')[0] + '.c')
|
||||||
|
if len(secs) == 0:
|
||||||
|
secs = sections_infos.get_sections(lib, file.split('.')[0])
|
||||||
|
if len(secs) == 0:
|
||||||
|
raise ValueError('Failed to get sections from lib %s'%(lib_path))
|
||||||
|
|
||||||
|
return secs
|
||||||
|
|
||||||
|
def filter_secs(secs_a, secs_b):
|
||||||
|
new_secs = list()
|
||||||
|
for s_a in secs_a:
|
||||||
|
for s_b in secs_b:
|
||||||
|
if s_b in s_a:
|
||||||
|
new_secs.append(s_a)
|
||||||
|
return new_secs
|
||||||
|
|
||||||
|
def strip_secs(secs_a, secs_b):
|
||||||
|
secs = list(set(secs_a) - set(secs_b))
|
||||||
|
secs.sort()
|
||||||
|
return secs
|
||||||
|
|
||||||
|
def func2sect(func):
|
||||||
|
if ' ' in func:
|
||||||
|
func_l = func.split(' ')
|
||||||
|
else:
|
||||||
|
func_l = list()
|
||||||
|
func_l.append(func)
|
||||||
|
|
||||||
|
secs = list()
|
||||||
|
for l in func_l:
|
||||||
|
if '.iram1.' not in l:
|
||||||
|
secs.append('.literal.%s'%(l,))
|
||||||
|
secs.append('.text.%s'%(l, ))
|
||||||
|
else:
|
||||||
|
secs.append(l)
|
||||||
|
return secs
|
||||||
|
|
||||||
|
class filter_c:
|
||||||
|
def __init__(self, file):
|
||||||
|
lines = open(file).read().splitlines()
|
||||||
|
self.libs_desc = ''
|
||||||
|
self.libs = ''
|
||||||
|
for l in lines:
|
||||||
|
if ') .iram1 EXCLUDE_FILE(*' in l and ') .iram1.*)' in l:
|
||||||
|
desc = '\(EXCLUDE_FILE\((.*)\) .iram1 '
|
||||||
|
self.libs_desc = re.search(desc, l)[1]
|
||||||
|
self.libs = self.libs_desc.replace('*', '')
|
||||||
|
return
|
||||||
|
|
||||||
|
def match(self, lib):
|
||||||
|
if lib in self.libs:
|
||||||
|
print('Remove lib %s'%(lib))
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def add(self):
|
||||||
|
return self.libs_desc
|
||||||
|
|
||||||
|
class target_c:
|
||||||
|
def __init__(self, lib, lib_path, file, fsecs):
|
||||||
|
self.lib = lib
|
||||||
|
self.file = file
|
||||||
|
|
||||||
|
self.lib_path = lib_path
|
||||||
|
self.fsecs = func2sect(fsecs)
|
||||||
|
self.desc = '*%s:%s.*'%(lib, file.split('.')[0])
|
||||||
|
|
||||||
|
secs = lib_secs(lib, file, lib_path)
|
||||||
|
if '.iram1.' in self.fsecs[0]:
|
||||||
|
self.secs = filter_secs(secs, ('.iram1.', ))
|
||||||
|
else:
|
||||||
|
self.secs = filter_secs(secs, ('.iram1.', '.text.', '.literal.'))
|
||||||
|
self.isecs = strip_secs(self.secs, self.fsecs)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
s = 'lib=%s\nfile=%s\lib_path=%s\ndesc=%s\nsecs=%s\nfsecs=%s\nisecs=%s\n'%(\
|
||||||
|
self.lib, self.file, self.lib_path, self.desc, self.secs, self.fsecs,\
|
||||||
|
self.isecs)
|
||||||
|
return s
|
||||||
|
|
||||||
|
class relink_c:
|
||||||
|
def __init__(self, input, library_file, object_file, function_file, sdkconfig_file, missing_function_info):
|
||||||
|
self.filter = filter_c(input)
|
||||||
|
|
||||||
|
libraries = configuration.generator(library_file, object_file, function_file, sdkconfig_file, missing_function_info, espidf_objdump)
|
||||||
|
self.targets = list()
|
||||||
|
for i in libraries.libs:
|
||||||
|
lib = libraries.libs[i]
|
||||||
|
|
||||||
|
if self.filter.match(lib.name):
|
||||||
|
continue
|
||||||
|
|
||||||
|
for j in lib.objs:
|
||||||
|
obj = lib.objs[j]
|
||||||
|
self.targets.append(target_c(lib.name, lib.path, obj.name,
|
||||||
|
' '.join(obj.sections())))
|
||||||
|
# for i in self.targets:
|
||||||
|
# print(i)
|
||||||
|
self.__transform__()
|
||||||
|
|
||||||
|
def __transform__(self):
|
||||||
|
iram1_exclude = list()
|
||||||
|
iram1_include = list()
|
||||||
|
flash_include = list()
|
||||||
|
|
||||||
|
for t in self.targets:
|
||||||
|
secs = filter_secs(t.fsecs, ('.iram1.', ))
|
||||||
|
if len(secs) > 0:
|
||||||
|
iram1_exclude.append(t.desc)
|
||||||
|
|
||||||
|
secs = filter_secs(t.isecs, ('.iram1.', ))
|
||||||
|
if len(secs) > 0:
|
||||||
|
iram1_include.append(' %s(%s)'%(t.desc, ' '.join(secs)))
|
||||||
|
|
||||||
|
secs = t.fsecs
|
||||||
|
if len(secs) > 0:
|
||||||
|
flash_include.append(' %s(%s)'%(t.desc, ' '.join(secs)))
|
||||||
|
|
||||||
|
self.iram1_exclude = ' *(EXCLUDE_FILE(%s %s) .iram1.*) *(EXCLUDE_FILE(%s %s) .iram1)' % \
|
||||||
|
(self.filter.add(), ' '.join(iram1_exclude), \
|
||||||
|
self.filter.add(), ' '.join(iram1_exclude))
|
||||||
|
self.iram1_include = '\n'.join(iram1_include)
|
||||||
|
self.flash_include = '\n'.join(flash_include)
|
||||||
|
|
||||||
|
logging.debug('IRAM1 Exclude: %s'%(self.iram1_exclude))
|
||||||
|
logging.debug('IRAM1 Include: %s'%(self.iram1_include))
|
||||||
|
logging.debug('Flash Include: %s'%(self.flash_include))
|
||||||
|
|
||||||
|
def __replace__(self, lines):
|
||||||
|
def is_iram_desc(l):
|
||||||
|
if '*(.iram1 .iram1.*)' in l or (') .iram1 EXCLUDE_FILE(*' in l and ') .iram1.*)' in l):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
iram_start = False
|
||||||
|
flash_done = False
|
||||||
|
|
||||||
|
for i in range(0, len(lines) - 1):
|
||||||
|
l = lines[i]
|
||||||
|
if '.iram0.text :' in l:
|
||||||
|
logging.debug('start to process .iram0.text')
|
||||||
|
iram_start = True
|
||||||
|
elif '.dram0.data :' in l:
|
||||||
|
logging.debug('end to process .iram0.text')
|
||||||
|
iram_start = False
|
||||||
|
elif is_iram_desc(l):
|
||||||
|
if iram_start:
|
||||||
|
lines[i] = '%s\n%s\n'%(self.iram1_exclude, self.iram1_include)
|
||||||
|
elif '(.stub .gnu.warning' in l:
|
||||||
|
if not flash_done:
|
||||||
|
lines[i] = '%s\n\n%s'%(self.flash_include, l)
|
||||||
|
elif self.flash_include in l:
|
||||||
|
flash_done = True
|
||||||
|
else:
|
||||||
|
if iram_start:
|
||||||
|
new_l = self._replace_func(l)
|
||||||
|
if new_l:
|
||||||
|
lines[i] = new_l
|
||||||
|
|
||||||
|
return lines
|
||||||
|
|
||||||
|
def _replace_func(self, l):
|
||||||
|
for t in self.targets:
|
||||||
|
if t.desc in l:
|
||||||
|
S = '.literal .literal.* .text .text.*'
|
||||||
|
if S in l:
|
||||||
|
if len(t.isecs) > 0:
|
||||||
|
return l.replace(S, ' '.join(t.isecs))
|
||||||
|
else:
|
||||||
|
return ' '
|
||||||
|
|
||||||
|
S = '%s(%s)'%(t.desc, ' '.join(t.fsecs))
|
||||||
|
if S in l:
|
||||||
|
return ' '
|
||||||
|
|
||||||
|
replaced = False
|
||||||
|
for s in t.fsecs:
|
||||||
|
s2 = s + ' '
|
||||||
|
if s2 in l:
|
||||||
|
l = l.replace(s2, '')
|
||||||
|
replaced = True
|
||||||
|
s2 = s + ')'
|
||||||
|
if s2 in l:
|
||||||
|
l = l.replace(s2, ')')
|
||||||
|
replaced = True
|
||||||
|
if '( )' in l or '()' in l:
|
||||||
|
return ' '
|
||||||
|
if replaced:
|
||||||
|
return l
|
||||||
|
else:
|
||||||
|
index = '*%s:(EXCLUDE_FILE'%(t.lib)
|
||||||
|
if index in l and t.file.split('.')[0] not in l:
|
||||||
|
for m in self.targets:
|
||||||
|
index = '*%s:(EXCLUDE_FILE'%(m.lib)
|
||||||
|
if index in l and m.file.split('.')[0] not in l:
|
||||||
|
l = l.replace('EXCLUDE_FILE(', 'EXCLUDE_FILE(%s '%(m.desc))
|
||||||
|
if len(m.isecs) > 0:
|
||||||
|
l += '\n %s(%s)'%(m.desc, ' '.join(m.isecs))
|
||||||
|
return l
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
def save(self, input, output):
|
||||||
|
lines = open(input).read().splitlines()
|
||||||
|
lines = self.__replace__(lines)
|
||||||
|
open(output, 'w+').write('\n'.join(lines))
|
||||||
|
|
||||||
|
def main():
|
||||||
|
argparser = argparse.ArgumentParser(description='Relinker script generator')
|
||||||
|
|
||||||
|
argparser.add_argument(
|
||||||
|
'--input', '-i',
|
||||||
|
help='Linker template file',
|
||||||
|
type=str)
|
||||||
|
|
||||||
|
argparser.add_argument(
|
||||||
|
'--output', '-o',
|
||||||
|
help='Output linker script',
|
||||||
|
type=str)
|
||||||
|
|
||||||
|
argparser.add_argument(
|
||||||
|
'--library', '-l',
|
||||||
|
help='Library description directory',
|
||||||
|
type=str)
|
||||||
|
|
||||||
|
argparser.add_argument(
|
||||||
|
'--object', '-b',
|
||||||
|
help='Object description file',
|
||||||
|
type=str)
|
||||||
|
|
||||||
|
argparser.add_argument(
|
||||||
|
'--function', '-f',
|
||||||
|
help='Function description file',
|
||||||
|
type=str)
|
||||||
|
|
||||||
|
argparser.add_argument(
|
||||||
|
'--sdkconfig', '-s',
|
||||||
|
help='sdkconfig file',
|
||||||
|
type=str)
|
||||||
|
|
||||||
|
argparser.add_argument(
|
||||||
|
'--objdump', '-g',
|
||||||
|
help='GCC objdump command',
|
||||||
|
type=str)
|
||||||
|
|
||||||
|
argparser.add_argument(
|
||||||
|
'--debug', '-d',
|
||||||
|
help='Debug level(option is \'debug\')',
|
||||||
|
default='no',
|
||||||
|
type=str)
|
||||||
|
|
||||||
|
argparser.add_argument(
|
||||||
|
'--missing_function_info',
|
||||||
|
help='Print error information instead of throwing exception when missing function',
|
||||||
|
default=False,
|
||||||
|
type=bool)
|
||||||
|
|
||||||
|
args = argparser.parse_args()
|
||||||
|
|
||||||
|
if args.debug == 'debug':
|
||||||
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
|
||||||
|
logging.debug('input: %s'%(args.input))
|
||||||
|
logging.debug('output: %s'%(args.output))
|
||||||
|
logging.debug('library: %s'%(args.library))
|
||||||
|
logging.debug('object: %s'%(args.object))
|
||||||
|
logging.debug('function: %s'%(args.function))
|
||||||
|
logging.debug('sdkconfig:%s'%(args.sdkconfig))
|
||||||
|
logging.debug('objdump: %s'%(args.objdump))
|
||||||
|
logging.debug('debug: %s'%(args.debug))
|
||||||
|
logging.debug('missing_function_info: %s'%(args.missing_function_info))
|
||||||
|
|
||||||
|
global espidf_objdump
|
||||||
|
espidf_objdump = args.objdump
|
||||||
|
|
||||||
|
relink = relink_c(args.input, args.library, args.object, args.function, args.sdkconfig, args.missing_function_info)
|
||||||
|
relink.save(args.input, args.output)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
# 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(EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/unit-test-app/components"
|
||||||
|
"../../cmake_utilities")
|
||||||
|
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||||
|
project(cmake_utilities_test_apps)
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
idf_component_register( SRC_DIRS "."
|
||||||
|
INCLUDE_DIRS "."
|
||||||
|
REQUIRES cmake_utilities)
|
||||||
|
|
||||||
|
include(gcc)
|
||||||
|
include(gen_compressed_ota)
|
||||||
|
include(gen_single_bin)
|
||||||
|
include(package_manager)
|
||||||
|
include(relinker)
|
||||||
|
cu_pkg_define_version(${CMAKE_CURRENT_LIST_DIR})
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
version: "3.2.1"
|
||||||
|
description: Test2 for cmake utilities
|
||||||
|
url: https://github.com/espressif/esp-iot-solution/tree/master/tools/cmake_utilities
|
||||||
|
issues: https://github.com/espressif/esp-iot-solution/issues
|
||||||
|
dependencies:
|
||||||
|
idf: ">=4.1"
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int test_component2_version_major()
|
||||||
|
{
|
||||||
|
return TEST_COMPONENT2_VER_MAJOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_component2_version_minor()
|
||||||
|
{
|
||||||
|
return TEST_COMPONENT2_VER_MINOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_component2_version_patch()
|
||||||
|
{
|
||||||
|
return TEST_COMPONENT2_VER_PATCH;
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int test_component2_version_major();
|
||||||
|
int test_component2_version_minor();
|
||||||
|
int test_component2_version_patch();
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
idf_component_register( SRC_DIRS "."
|
||||||
|
INCLUDE_DIRS "."
|
||||||
|
REQUIRES cmake_utilities)
|
||||||
|
|
||||||
|
include(gcc)
|
||||||
|
include(gen_compressed_ota)
|
||||||
|
include(gen_single_bin)
|
||||||
|
include(package_manager)
|
||||||
|
include(relinker)
|
||||||
|
cu_pkg_define_version(${CMAKE_CURRENT_LIST_DIR})
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
version: "1.2.3"
|
||||||
|
description: Test1 for cmake utilities
|
||||||
|
url: https://github.com/espressif/esp-iot-solution/tree/master/tools/cmake_utilities
|
||||||
|
issues: https://github.com/espressif/esp-iot-solution/issues
|
||||||
|
dependencies:
|
||||||
|
idf: ">=4.1"
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int test_component1_version_major()
|
||||||
|
{
|
||||||
|
return TEST_COMPONENT1_VER_MAJOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_component1_version_minor()
|
||||||
|
{
|
||||||
|
return TEST_COMPONENT1_VER_MINOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_component1_version_patch()
|
||||||
|
{
|
||||||
|
return TEST_COMPONENT1_VER_PATCH;
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int test_component1_version_major();
|
||||||
|
int test_component1_version_minor();
|
||||||
|
int test_component1_version_patch();
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
idf_component_register(SRC_DIRS "."
|
||||||
|
INCLUDE_DIRS "."
|
||||||
|
REQUIRES unity test_utils test_component1 TEST-component2)
|
||||||
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "esp_system.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "unity.h"
|
||||||
|
#include "test_component1.h"
|
||||||
|
#include "test_component2.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* USB PIN fixed in esp32-s2, can not use io matrix */
|
||||||
|
#define TEST_MEMORY_LEAK_THRESHOLD (-400)
|
||||||
|
|
||||||
|
TEST_CASE("Test package manager version", "[cmake_utilities][package_manager]")
|
||||||
|
{
|
||||||
|
esp_log_level_set("*", ESP_LOG_INFO);
|
||||||
|
TEST_ASSERT_EQUAL_INT(test_component1_version_major(), 1);
|
||||||
|
TEST_ASSERT_EQUAL_INT(test_component1_version_minor(), 2);
|
||||||
|
TEST_ASSERT_EQUAL_INT(test_component1_version_patch(), 3);
|
||||||
|
TEST_ASSERT_EQUAL_INT(test_component2_version_major(), 3);
|
||||||
|
TEST_ASSERT_EQUAL_INT(test_component2_version_minor(), 2);
|
||||||
|
TEST_ASSERT_EQUAL_INT(test_component2_version_patch(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static size_t before_free_8bit;
|
||||||
|
static size_t before_free_32bit;
|
||||||
|
|
||||||
|
static void check_leak(size_t before_free, size_t after_free, const char *type)
|
||||||
|
{
|
||||||
|
ssize_t delta = after_free - before_free;
|
||||||
|
printf("MALLOC_CAP_%s: Before %u bytes free, After %u bytes free (delta %d)\n", type, before_free, after_free, delta);
|
||||||
|
TEST_ASSERT_MESSAGE(delta >= TEST_MEMORY_LEAK_THRESHOLD, "memory leak");
|
||||||
|
}
|
||||||
|
|
||||||
|
void setUp(void)
|
||||||
|
{
|
||||||
|
before_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
|
||||||
|
before_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void tearDown(void)
|
||||||
|
{
|
||||||
|
size_t after_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
|
||||||
|
size_t after_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
|
||||||
|
check_leak(before_free_8bit, after_free_8bit, "8BIT");
|
||||||
|
check_leak(before_free_32bit, after_free_32bit, "32BIT");
|
||||||
|
}
|
||||||
|
|
||||||
|
void app_main(void)
|
||||||
|
{
|
||||||
|
printf("Cmake Utilities TEST \n");
|
||||||
|
unity_run_menu();
|
||||||
|
}
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
'''
|
||||||
|
Steps to run these cases:
|
||||||
|
- Build
|
||||||
|
- . ${IDF_PATH}/export.sh
|
||||||
|
- pip install idf_build_apps
|
||||||
|
- python tools/build_apps.py tools/cmake_utilities/test_apps -t esp32s2
|
||||||
|
- Test
|
||||||
|
- pip install -r tools/requirements/requirement.pytest.txt
|
||||||
|
- pytest tools/cmake_utilities/test_apps --target esp32s2
|
||||||
|
'''
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from pytest_embedded import Dut
|
||||||
|
|
||||||
|
@pytest.mark.target('esp32s3')
|
||||||
|
@pytest.mark.env('generic')
|
||||||
|
def test_cmake_utilities(dut: Dut)-> None:
|
||||||
|
dut.expect_exact('Press ENTER to see the list of tests.')
|
||||||
|
dut.write('*')
|
||||||
|
dut.expect_unity_test_output(timeout = 1000)
|
||||||
@ -1,9 +1,9 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
espressif/button:
|
espressif/button:
|
||||||
component_hash: c3ee3ba339a3848977496d0157008ae574a24fc59f54d27c93ab51b14446a2fb
|
component_hash: null
|
||||||
source:
|
source:
|
||||||
service_url: https://api.components.espressif.com/
|
path: /home/yu/Source_Space/ESP32_Project_Space/Air_58Printer/components/espressif__button
|
||||||
type: service
|
type: local
|
||||||
version: 3.3.1
|
version: 3.3.1
|
||||||
espressif/cmake_utilities:
|
espressif/cmake_utilities:
|
||||||
component_hash: 351350613ceafba240b761b4ea991e0f231ac7a9f59a9ee901f751bddc0bb18f
|
component_hash: 351350613ceafba240b761b4ea991e0f231ac7a9f59a9ee901f751bddc0bb18f
|
||||||
@ -11,23 +11,11 @@ dependencies:
|
|||||||
service_url: https://api.components.espressif.com/
|
service_url: https://api.components.espressif.com/
|
||||||
type: service
|
type: service
|
||||||
version: 0.5.3
|
version: 0.5.3
|
||||||
espressif/esp_tinyusb:
|
|
||||||
component_hash: f151d680d6847bfcfd5d8eb6d1c3ff926c208e6b963b2e83643a141bc70baa15
|
|
||||||
source:
|
|
||||||
service_url: https://api.components.espressif.com/
|
|
||||||
type: service
|
|
||||||
version: 1.4.4
|
|
||||||
espressif/tinyusb:
|
|
||||||
component_hash: 214989d502fc168241a4a4f83b097d8ac44a93cd6f1787b4ac10069a8b3bebd3
|
|
||||||
source:
|
|
||||||
service_url: https://api.components.espressif.com/
|
|
||||||
type: service
|
|
||||||
version: 0.15.0~10
|
|
||||||
idf:
|
idf:
|
||||||
component_hash: null
|
component_hash: null
|
||||||
source:
|
source:
|
||||||
type: idf
|
type: idf
|
||||||
version: 5.3.0
|
version: 5.3.0
|
||||||
manifest_hash: ad049ea0610606405810b748f12dbd7234230135e0c85ab105d02f6ae523ccdf
|
manifest_hash: 9a1ad333c087c0f6ba914b30dad014f27f8198c5ae062a2cb9a1a61b1a4126b0
|
||||||
target: esp32s3
|
target: esp32c3
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
## IDF Component Manager Manifest File
|
## IDF Component Manager Manifest File
|
||||||
dependencies:
|
dependencies:
|
||||||
espressif/button: "*"
|
espressif/button: "*"
|
||||||
espressif/esp_tinyusb: "^1"
|
|
||||||
## Required IDF version
|
## Required IDF version
|
||||||
idf:
|
idf:
|
||||||
version: ">=4.1.0"
|
version: ">=4.1.0"
|
||||||
|
|||||||
13
main/main.c
13
main/main.c
@ -9,9 +9,6 @@
|
|||||||
#include "driver/gpio.h"
|
#include "driver/gpio.h"
|
||||||
#include "esp_system.h"
|
#include "esp_system.h"
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "tinyusb.h"
|
|
||||||
#include "tusb_cdc_acm.h"
|
|
||||||
|
|
||||||
#include "module/include/Sys_Printer.h"
|
#include "module/include/Sys_Printer.h"
|
||||||
#include "module/Printer_Config.h"
|
#include "module/Printer_Config.h"
|
||||||
#include "esp_adc/adc_continuous.h"
|
#include "esp_adc/adc_continuous.h"
|
||||||
@ -57,14 +54,14 @@ void app_main(void)
|
|||||||
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");
|
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");
|
||||||
|
|
||||||
printf("Minimum free heap size: %" PRIu32 " bytes\n", esp_get_minimum_free_heap_size());
|
printf("Minimum free heap size: %" PRIu32 " bytes\n", esp_get_minimum_free_heap_size());
|
||||||
|
|
||||||
Usb_Virtual_serial_port_init();
|
Usb_Virtual_serial_port_init();
|
||||||
|
|
||||||
|
|
||||||
Printer_group = xEventGroupCreate();
|
Printer_group = xEventGroupCreate();
|
||||||
button_init();
|
// button_init();
|
||||||
register_gpio_wakeup();
|
// register_gpio_wakeup();
|
||||||
Printer_Bsp_Init();
|
// Printer_Bsp_Init();
|
||||||
Printer_run_init();
|
// Printer_run_init();
|
||||||
// xTaskCreate(light_sleep_task, "light_sleep_task", 4096, NULL, 6, NULL);
|
// xTaskCreate(light_sleep_task, "light_sleep_task", 4096, NULL, 6, NULL);
|
||||||
while (1) {
|
while (1) {
|
||||||
if(xQueueReceive(User_data_queue, &Receive_All_data, portMAX_DELAY))
|
if(xQueueReceive(User_data_queue, &Receive_All_data, portMAX_DELAY))
|
||||||
|
|||||||
@ -2,17 +2,22 @@
|
|||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "tinyusb.h"
|
|
||||||
#include "tusb_cdc_acm.h"
|
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
#include "include/Sys_Printer.h"
|
#include "include/Sys_Printer.h"
|
||||||
|
#include "driver/usb_serial_jtag.h"
|
||||||
|
|
||||||
static const char *TAG = "usb_cdc";
|
static const char *TAG = "usb_cdc";
|
||||||
|
|
||||||
|
#define BUF_SIZE (1024)
|
||||||
|
#define ECHO_TASK_STACK_SIZE (4096)
|
||||||
|
|
||||||
extern QueueHandle_t User_data_queue;
|
extern QueueHandle_t User_data_queue;
|
||||||
user_data_t Receive_usb_data;
|
user_data_t Receive_usb_data;
|
||||||
|
|
||||||
|
#if CONFIG_IDF_TARGET_ESP32S3
|
||||||
|
#include "tinyusb.h"
|
||||||
|
#include "tusb_cdc_acm.h"
|
||||||
|
|
||||||
// static uint8_t buf[CONFIG_TINYUSB_CDC_RX_BUFSIZE + 1];
|
// static uint8_t buf[CONFIG_TINYUSB_CDC_RX_BUFSIZE + 1];
|
||||||
|
|
||||||
void tinyusb_cdc_rx_callback(int itf, cdcacm_event_t *event)
|
void tinyusb_cdc_rx_callback(int itf, cdcacm_event_t *event)
|
||||||
@ -44,11 +49,40 @@ void tinyusb_cdc_line_state_changed_callback(int itf, cdcacm_event_t *event)
|
|||||||
int rts = event->line_state_changed_data.rts;
|
int rts = event->line_state_changed_data.rts;
|
||||||
ESP_LOGI(TAG, "Line state changed on channel %d: DTR:%d, RTS:%d", itf, dtr, rts);
|
ESP_LOGI(TAG, "Line state changed on channel %d: DTR:%d, RTS:%d", itf, dtr, rts);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if CONFIG_IDF_TARGET_ESP32C3
|
||||||
|
|
||||||
|
static void USB_Serial_rx_task(void *arg)
|
||||||
|
{
|
||||||
|
// Configure a temporary buffer for the incoming data
|
||||||
|
uint8_t *data = (uint8_t *) malloc(BUF_SIZE);
|
||||||
|
if (data == NULL) {
|
||||||
|
ESP_LOGE("usb_serial_jtag echo", "no memory for data");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
|
||||||
|
int len = usb_serial_jtag_read_bytes(data, (BUF_SIZE - 1), 20 / portTICK_PERIOD_MS);
|
||||||
|
|
||||||
|
// Write data back to the USB SERIAL JTAG
|
||||||
|
if (len) {
|
||||||
|
usb_serial_jtag_write_bytes((const char *) data, len, 20 / portTICK_PERIOD_MS);
|
||||||
|
data[len] = '\0';
|
||||||
|
ESP_LOG_BUFFER_HEXDUMP("Recv str: ", data, len, ESP_LOG_INFO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Usb_Virtual_serial_port_init(void)
|
void Usb_Virtual_serial_port_init(void)
|
||||||
{
|
{
|
||||||
ESP_LOGI(TAG, "USB initialization");
|
ESP_LOGI(TAG, "USB initialization");
|
||||||
|
#if CONFIG_IDF_TARGET_ESP32S3
|
||||||
const tinyusb_config_t tusb_cfg = {
|
const tinyusb_config_t tusb_cfg = {
|
||||||
.device_descriptor = NULL,
|
.device_descriptor = NULL,
|
||||||
.string_descriptor = NULL,
|
.string_descriptor = NULL,
|
||||||
@ -74,5 +108,19 @@ void Usb_Virtual_serial_port_init(void)
|
|||||||
TINYUSB_CDC_ACM_0,
|
TINYUSB_CDC_ACM_0,
|
||||||
CDC_EVENT_LINE_STATE_CHANGED,
|
CDC_EVENT_LINE_STATE_CHANGED,
|
||||||
&tinyusb_cdc_line_state_changed_callback));
|
&tinyusb_cdc_line_state_changed_callback));
|
||||||
|
#else
|
||||||
|
|
||||||
|
// Configure USB SERIAL JTAG
|
||||||
|
usb_serial_jtag_driver_config_t usb_serial_jtag_config = {
|
||||||
|
.rx_buffer_size = BUF_SIZE,
|
||||||
|
.tx_buffer_size = BUF_SIZE,
|
||||||
|
};
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK(usb_serial_jtag_driver_install(&usb_serial_jtag_config));
|
||||||
|
ESP_LOGI("usb_serial_jtag echo", "USB_SERIAL_JTAG init done");
|
||||||
|
|
||||||
|
xTaskCreate(USB_Serial_rx_task, "USB SERIAL JTAG_echo_task", ECHO_TASK_STACK_SIZE, NULL, 10, NULL);
|
||||||
|
|
||||||
|
#endif
|
||||||
ESP_LOGI(TAG, "USB initialization DONE");
|
ESP_LOGI(TAG, "USB initialization DONE");
|
||||||
}
|
}
|
||||||
@ -1 +0,0 @@
|
|||||||
f151d680d6847bfcfd5d8eb6d1c3ff926c208e6b963b2e83643a141bc70baa15
|
|
||||||
@ -1,53 +0,0 @@
|
|||||||
## 1.4.4
|
|
||||||
|
|
||||||
- esp_tinyusb: Added HighSpeed and Qualifier device descriptors in tinyusb configuration
|
|
||||||
- CDC-ACM: Removed MIN() definition if already defined
|
|
||||||
- MSC: Fixed EP size selecting in default configuration descriptor
|
|
||||||
|
|
||||||
## 1.4.3
|
|
||||||
|
|
||||||
- esp_tinyusb: Added ESP32P4 support (HS only)
|
|
||||||
|
|
||||||
## 1.4.2
|
|
||||||
|
|
||||||
- MSC: Fixed maximum files open
|
|
||||||
- Added uninstall function
|
|
||||||
|
|
||||||
## 1.4.0
|
|
||||||
|
|
||||||
- MSC: Fixed integer overflows
|
|
||||||
- CDC-ACM: Removed intermediate RX ringbuffer
|
|
||||||
- CDC-ACM: Increased default FIFO size to 512 bytes
|
|
||||||
- CDC-ACM: Fixed Virtual File System binding
|
|
||||||
|
|
||||||
## 1.3.0
|
|
||||||
|
|
||||||
- Added NCM extension
|
|
||||||
|
|
||||||
## 1.2.1 - 1.2.2
|
|
||||||
|
|
||||||
- Minor bugfixes
|
|
||||||
|
|
||||||
## 1.2.0
|
|
||||||
|
|
||||||
- Added MSC extension for accessing SPI Flash on memory card https://github.com/espressif/idf-extra-components/commit/a8c00d7707ba4ceeb0970c023d702c7768dba3dc
|
|
||||||
|
|
||||||
## 1.1.0
|
|
||||||
|
|
||||||
- Added support for NCM, ECM/RNDIS, DFU and Bluetooth TinyUSB drivers https://github.com/espressif/idf-extra-components/commit/79f35c9b047b583080f93a63310e2ee7d82ef17b
|
|
||||||
|
|
||||||
## 1.0.4
|
|
||||||
|
|
||||||
- Cleaned up string descriptors handling https://github.com/espressif/idf-extra-components/commit/046cc4b02f524d5c7e3e56480a473cfe844dc3d6
|
|
||||||
|
|
||||||
## 1.0.2 - 1.0.3
|
|
||||||
|
|
||||||
- Minor bugfixes
|
|
||||||
|
|
||||||
## 1.0.1
|
|
||||||
|
|
||||||
- CDC-ACM: Return ESP_OK if there is nothing to flush https://github.com/espressif/idf-extra-components/commit/388ff32eb09aa572d98c54cb355f1912ce42707c
|
|
||||||
|
|
||||||
## 1.0.0
|
|
||||||
|
|
||||||
- Initial version based on [esp-idf v4.4.3](https://github.com/espressif/esp-idf/tree/v4.4.3/components/tinyusb)
|
|
||||||
@ -1,53 +0,0 @@
|
|||||||
set(srcs
|
|
||||||
"descriptors_control.c"
|
|
||||||
"tinyusb.c"
|
|
||||||
"usb_descriptors.c"
|
|
||||||
)
|
|
||||||
|
|
||||||
if(NOT CONFIG_TINYUSB_NO_DEFAULT_TASK)
|
|
||||||
list(APPEND srcs "tusb_tasks.c")
|
|
||||||
endif() # CONFIG_TINYUSB_NO_DEFAULT_TASK
|
|
||||||
|
|
||||||
if(CONFIG_TINYUSB_CDC_ENABLED)
|
|
||||||
list(APPEND srcs
|
|
||||||
"cdc.c"
|
|
||||||
"tusb_cdc_acm.c"
|
|
||||||
)
|
|
||||||
if(CONFIG_VFS_SUPPORT_IO)
|
|
||||||
list(APPEND srcs
|
|
||||||
"tusb_console.c"
|
|
||||||
"vfs_tinyusb.c"
|
|
||||||
)
|
|
||||||
endif() # CONFIG_VFS_SUPPORT_IO
|
|
||||||
endif() # CONFIG_TINYUSB_CDC_ENABLED
|
|
||||||
|
|
||||||
if(CONFIG_TINYUSB_MSC_ENABLED)
|
|
||||||
list(APPEND srcs
|
|
||||||
tusb_msc_storage.c
|
|
||||||
)
|
|
||||||
endif() # CONFIG_TINYUSB_MSC_ENABLED
|
|
||||||
|
|
||||||
if(CONFIG_TINYUSB_NET_MODE_NCM)
|
|
||||||
list(APPEND srcs
|
|
||||||
tinyusb_net.c
|
|
||||||
)
|
|
||||||
endif() # CONFIG_TINYUSB_NET_MODE_NCM
|
|
||||||
|
|
||||||
idf_component_register(SRCS ${srcs}
|
|
||||||
INCLUDE_DIRS "include"
|
|
||||||
PRIV_INCLUDE_DIRS "include_private"
|
|
||||||
PRIV_REQUIRES usb
|
|
||||||
REQUIRES fatfs vfs
|
|
||||||
)
|
|
||||||
|
|
||||||
# Determine whether tinyusb is fetched from component registry or from local path
|
|
||||||
idf_build_get_property(build_components BUILD_COMPONENTS)
|
|
||||||
if(tinyusb IN_LIST build_components)
|
|
||||||
set(tinyusb_name tinyusb) # Local component
|
|
||||||
else()
|
|
||||||
set(tinyusb_name espressif__tinyusb) # Managed component
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Pass tusb_config.h from this component to TinyUSB
|
|
||||||
idf_component_get_property(tusb_lib ${tinyusb_name} COMPONENT_LIB)
|
|
||||||
target_include_directories(${tusb_lib} PRIVATE "include")
|
|
||||||
@ -1,272 +0,0 @@
|
|||||||
menu "TinyUSB Stack"
|
|
||||||
config TINYUSB_DEBUG_LEVEL
|
|
||||||
int "TinyUSB log level (0-3)"
|
|
||||||
default 1
|
|
||||||
range 0 3
|
|
||||||
help
|
|
||||||
Specify verbosity of TinyUSB log output.
|
|
||||||
|
|
||||||
choice TINYUSB_RHPORT
|
|
||||||
depends on IDF_TARGET_ESP32P4
|
|
||||||
prompt "TinyUSB PHY"
|
|
||||||
default TINYUSB_RHPORT_HS
|
|
||||||
help
|
|
||||||
Allows set the USB PHY Controller for TinyUSB: HS (USB OTG2.0 PHY for HighSpeed)
|
|
||||||
|
|
||||||
config TINYUSB_RHPORT_HS
|
|
||||||
bool "HS"
|
|
||||||
endchoice
|
|
||||||
|
|
||||||
menu "TinyUSB task configuration"
|
|
||||||
config TINYUSB_NO_DEFAULT_TASK
|
|
||||||
bool "Do not create a TinyUSB task"
|
|
||||||
default n
|
|
||||||
help
|
|
||||||
This option allows to not create the FreeRTOS task during the driver initialization.
|
|
||||||
User will have to handle TinyUSB events manually.
|
|
||||||
|
|
||||||
config TINYUSB_TASK_PRIORITY
|
|
||||||
int "TinyUSB task priority"
|
|
||||||
default 5
|
|
||||||
depends on !TINYUSB_NO_DEFAULT_TASK
|
|
||||||
help
|
|
||||||
Set the priority of the default TinyUSB main task.
|
|
||||||
|
|
||||||
config TINYUSB_TASK_STACK_SIZE
|
|
||||||
int "TinyUSB task stack size (bytes)"
|
|
||||||
default 4096
|
|
||||||
depends on !TINYUSB_NO_DEFAULT_TASK
|
|
||||||
help
|
|
||||||
Set the stack size of the default TinyUSB main task.
|
|
||||||
|
|
||||||
choice TINYUSB_TASK_AFFINITY
|
|
||||||
prompt "TinyUSB task affinity"
|
|
||||||
default TINYUSB_TASK_AFFINITY_NO_AFFINITY
|
|
||||||
depends on !TINYUSB_NO_DEFAULT_TASK
|
|
||||||
help
|
|
||||||
Allows setting TinyUSB tasks affinity, i.e. whether the task is pinned to
|
|
||||||
CPU0, pinned to CPU1, or allowed to run on any CPU.
|
|
||||||
|
|
||||||
config TINYUSB_TASK_AFFINITY_NO_AFFINITY
|
|
||||||
bool "No affinity"
|
|
||||||
config TINYUSB_TASK_AFFINITY_CPU0
|
|
||||||
bool "CPU0"
|
|
||||||
config TINYUSB_TASK_AFFINITY_CPU1
|
|
||||||
bool "CPU1"
|
|
||||||
depends on !FREERTOS_UNICORE
|
|
||||||
endchoice
|
|
||||||
|
|
||||||
config TINYUSB_TASK_AFFINITY
|
|
||||||
hex
|
|
||||||
default FREERTOS_NO_AFFINITY if TINYUSB_TASK_AFFINITY_NO_AFFINITY
|
|
||||||
default 0x0 if TINYUSB_TASK_AFFINITY_CPU0
|
|
||||||
default 0x1 if TINYUSB_TASK_AFFINITY_CPU1
|
|
||||||
|
|
||||||
config TINYUSB_INIT_IN_DEFAULT_TASK
|
|
||||||
bool "Initialize TinyUSB stack within the default TinyUSB task"
|
|
||||||
default n
|
|
||||||
depends on !TINYUSB_NO_DEFAULT_TASK
|
|
||||||
help
|
|
||||||
Run TinyUSB stack initialization just after starting the default TinyUSB task.
|
|
||||||
This is especially useful in multicore scenarios, when we need to pin the task
|
|
||||||
to a specific core and, at the same time initialize TinyUSB stack
|
|
||||||
(i.e. install interrupts) on the same core.
|
|
||||||
endmenu
|
|
||||||
|
|
||||||
menu "Descriptor configuration"
|
|
||||||
comment "You can provide your custom descriptors via tinyusb_driver_install()"
|
|
||||||
config TINYUSB_DESC_USE_ESPRESSIF_VID
|
|
||||||
bool "VID: Use Espressif's vendor ID"
|
|
||||||
default y
|
|
||||||
help
|
|
||||||
Enable this option, USB device will use Espressif's vendor ID as its VID.
|
|
||||||
This is helpful at product develop stage.
|
|
||||||
|
|
||||||
config TINYUSB_DESC_CUSTOM_VID
|
|
||||||
hex "VID: Custom vendor ID"
|
|
||||||
default 0x1234
|
|
||||||
depends on !TINYUSB_DESC_USE_ESPRESSIF_VID
|
|
||||||
help
|
|
||||||
Custom Vendor ID.
|
|
||||||
|
|
||||||
config TINYUSB_DESC_USE_DEFAULT_PID
|
|
||||||
bool "PID: Use a default PID assigned to TinyUSB"
|
|
||||||
default y
|
|
||||||
help
|
|
||||||
Default TinyUSB PID assigning uses values 0x4000...0x4007.
|
|
||||||
|
|
||||||
config TINYUSB_DESC_CUSTOM_PID
|
|
||||||
hex "PID: Custom product ID"
|
|
||||||
default 0x5678
|
|
||||||
depends on !TINYUSB_DESC_USE_DEFAULT_PID
|
|
||||||
help
|
|
||||||
Custom Product ID.
|
|
||||||
|
|
||||||
config TINYUSB_DESC_BCD_DEVICE
|
|
||||||
hex "bcdDevice"
|
|
||||||
default 0x0100
|
|
||||||
help
|
|
||||||
Version of the firmware of the USB device.
|
|
||||||
|
|
||||||
config TINYUSB_DESC_MANUFACTURER_STRING
|
|
||||||
string "Manufacturer name"
|
|
||||||
default "Espressif Systems"
|
|
||||||
help
|
|
||||||
Name of the manufacturer of the USB device.
|
|
||||||
|
|
||||||
config TINYUSB_DESC_PRODUCT_STRING
|
|
||||||
string "Product name"
|
|
||||||
default "Espressif Device"
|
|
||||||
help
|
|
||||||
Name of the USB device.
|
|
||||||
|
|
||||||
config TINYUSB_DESC_SERIAL_STRING
|
|
||||||
string "Serial string"
|
|
||||||
default "123456"
|
|
||||||
help
|
|
||||||
Serial number of the USB device.
|
|
||||||
|
|
||||||
config TINYUSB_DESC_CDC_STRING
|
|
||||||
depends on TINYUSB_CDC_ENABLED
|
|
||||||
string "CDC Device String"
|
|
||||||
default "Espressif CDC Device"
|
|
||||||
help
|
|
||||||
Name of the CDC device.
|
|
||||||
|
|
||||||
config TINYUSB_DESC_MSC_STRING
|
|
||||||
depends on TINYUSB_MSC_ENABLED
|
|
||||||
string "MSC Device String"
|
|
||||||
default "Espressif MSC Device"
|
|
||||||
help
|
|
||||||
Name of the MSC device.
|
|
||||||
endmenu # "Descriptor configuration"
|
|
||||||
|
|
||||||
menu "Massive Storage Class (MSC)"
|
|
||||||
config TINYUSB_MSC_ENABLED
|
|
||||||
bool "Enable TinyUSB MSC feature"
|
|
||||||
default n
|
|
||||||
help
|
|
||||||
Enable TinyUSB MSC feature.
|
|
||||||
|
|
||||||
config TINYUSB_MSC_BUFSIZE
|
|
||||||
depends on TINYUSB_MSC_ENABLED
|
|
||||||
int "MSC FIFO size"
|
|
||||||
default 512
|
|
||||||
range 64 10000
|
|
||||||
help
|
|
||||||
MSC FIFO size, in bytes.
|
|
||||||
|
|
||||||
config TINYUSB_MSC_MOUNT_PATH
|
|
||||||
depends on TINYUSB_MSC_ENABLED
|
|
||||||
string "Mount Path"
|
|
||||||
default "/data"
|
|
||||||
help
|
|
||||||
MSC Mount Path of storage.
|
|
||||||
endmenu # "Massive Storage Class"
|
|
||||||
|
|
||||||
menu "Communication Device Class (CDC)"
|
|
||||||
config TINYUSB_CDC_ENABLED
|
|
||||||
bool "Enable TinyUSB CDC feature"
|
|
||||||
default n
|
|
||||||
help
|
|
||||||
Enable TinyUSB CDC feature.
|
|
||||||
|
|
||||||
config TINYUSB_CDC_COUNT
|
|
||||||
int "CDC Channel Count"
|
|
||||||
default 1
|
|
||||||
range 1 2
|
|
||||||
depends on TINYUSB_CDC_ENABLED
|
|
||||||
help
|
|
||||||
Number of independent serial ports.
|
|
||||||
|
|
||||||
config TINYUSB_CDC_RX_BUFSIZE
|
|
||||||
depends on TINYUSB_CDC_ENABLED
|
|
||||||
int "CDC FIFO size of RX channel"
|
|
||||||
default 512
|
|
||||||
range 64 10000
|
|
||||||
help
|
|
||||||
CDC FIFO size of RX channel.
|
|
||||||
|
|
||||||
config TINYUSB_CDC_TX_BUFSIZE
|
|
||||||
depends on TINYUSB_CDC_ENABLED
|
|
||||||
int "CDC FIFO size of TX channel"
|
|
||||||
default 512
|
|
||||||
help
|
|
||||||
CDC FIFO size of TX channel.
|
|
||||||
endmenu # "Communication Device Class"
|
|
||||||
|
|
||||||
menu "Musical Instrument Digital Interface (MIDI)"
|
|
||||||
config TINYUSB_MIDI_COUNT
|
|
||||||
int "TinyUSB MIDI interfaces count"
|
|
||||||
default 0
|
|
||||||
range 0 2
|
|
||||||
help
|
|
||||||
Setting value greater than 0 will enable TinyUSB MIDI feature.
|
|
||||||
endmenu # "Musical Instrument Digital Interface (MIDI)"
|
|
||||||
|
|
||||||
menu "Human Interface Device Class (HID)"
|
|
||||||
config TINYUSB_HID_COUNT
|
|
||||||
int "TinyUSB HID interfaces count"
|
|
||||||
default 0
|
|
||||||
range 0 4
|
|
||||||
help
|
|
||||||
Setting value greater than 0 will enable TinyUSB HID feature.
|
|
||||||
endmenu # "HID Device Class (HID)"
|
|
||||||
|
|
||||||
menu "Device Firmware Upgrade (DFU)"
|
|
||||||
choice TINYUSB_DFU_MODE
|
|
||||||
prompt "DFU mode"
|
|
||||||
default TINYUSB_DFU_MODE_NONE
|
|
||||||
help
|
|
||||||
Select which DFU driver you want to use.
|
|
||||||
|
|
||||||
config TINYUSB_DFU_MODE_DFU
|
|
||||||
bool "DFU"
|
|
||||||
|
|
||||||
config TINYUSB_DFU_MODE_DFU_RUNTIME
|
|
||||||
bool "DFU Runtime"
|
|
||||||
|
|
||||||
config TINYUSB_DFU_MODE_NONE
|
|
||||||
bool "None"
|
|
||||||
endchoice
|
|
||||||
config TINYUSB_DFU_BUFSIZE
|
|
||||||
depends on TINYUSB_DFU_MODE_DFU
|
|
||||||
int "DFU XFER BUFFSIZE"
|
|
||||||
default 512
|
|
||||||
help
|
|
||||||
DFU XFER BUFFSIZE.
|
|
||||||
endmenu # Device Firmware Upgrade (DFU)
|
|
||||||
|
|
||||||
menu "Bluetooth Host Class (BTH)"
|
|
||||||
config TINYUSB_BTH_ENABLED
|
|
||||||
bool "Enable TinyUSB BTH feature"
|
|
||||||
default n
|
|
||||||
help
|
|
||||||
Enable TinyUSB BTH feature.
|
|
||||||
|
|
||||||
config TINYUSB_BTH_ISO_ALT_COUNT
|
|
||||||
depends on TINYUSB_BTH_ENABLED
|
|
||||||
int "BTH ISO ALT COUNT"
|
|
||||||
default 0
|
|
||||||
help
|
|
||||||
BTH ISO ALT COUNT.
|
|
||||||
endmenu # "Bluetooth Host Device Class"
|
|
||||||
|
|
||||||
menu "Network driver (ECM/NCM/RNDIS)"
|
|
||||||
choice TINYUSB_NET_MODE
|
|
||||||
prompt "Network mode"
|
|
||||||
default TINYUSB_NET_MODE_NONE
|
|
||||||
help
|
|
||||||
Select network driver you want to use.
|
|
||||||
|
|
||||||
config TINYUSB_NET_MODE_ECM_RNDIS
|
|
||||||
bool "ECM/RNDIS"
|
|
||||||
|
|
||||||
config TINYUSB_NET_MODE_NCM
|
|
||||||
bool "NCM"
|
|
||||||
|
|
||||||
config TINYUSB_NET_MODE_NONE
|
|
||||||
bool "None"
|
|
||||||
endchoice
|
|
||||||
endmenu # "Network driver (ECM/NCM/RNDIS)"
|
|
||||||
endmenu # "TinyUSB Stack"
|
|
||||||
@ -1,32 +0,0 @@
|
|||||||
# Espressif's additions to TinyUSB
|
|
||||||
|
|
||||||
[](https://components.espressif.com/components/espressif/esp_tinyusb)
|
|
||||||
|
|
||||||
This component adds features to TinyUSB that help users with integrating TinyUSB with their ESP-IDF application.
|
|
||||||
|
|
||||||
It contains:
|
|
||||||
* Configuration of USB device and string descriptors
|
|
||||||
* USB Serial Device (CDC-ACM) with optional Virtual File System support
|
|
||||||
* Input and output streams through USB Serial Device. This feature is available only when Virtual File System support is enabled.
|
|
||||||
* Other USB classes (MIDI, MSC, HID…) support directly via TinyUSB
|
|
||||||
* VBUS monitoring for self-powered devices
|
|
||||||
* SPI Flash or sd-card access via MSC USB device Class.
|
|
||||||
|
|
||||||
## Documentation and examples
|
|
||||||
You can find documentation in [ESP-IDF Programming Guide](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/api-reference/peripherals/usb_device.html).
|
|
||||||
|
|
||||||
You can find examples in [ESP-IDF on GitHub](https://github.com/espressif/esp-idf/tree/master/examples/peripherals/usb/device).
|
|
||||||
## How to use?
|
|
||||||
|
|
||||||
This component is distributed via [IDF component manager](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/tools/idf-component-manager.html). Just add `idf_component.yml` file to your main component with the following content:
|
|
||||||
|
|
||||||
``` yaml
|
|
||||||
## IDF Component Manager Manifest File
|
|
||||||
dependencies:
|
|
||||||
esp_tinyusb: "~1.0.0"
|
|
||||||
```
|
|
||||||
|
|
||||||
Or simply run:
|
|
||||||
```
|
|
||||||
idf.py add-dependency esp_tinyusb~1.0.0
|
|
||||||
```
|
|
||||||
@ -1,109 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include "esp_check.h"
|
|
||||||
#include "esp_err.h"
|
|
||||||
#include "esp_log.h"
|
|
||||||
#include "tusb.h"
|
|
||||||
#include "cdc.h"
|
|
||||||
|
|
||||||
#define CDC_INTF_NUM CFG_TUD_CDC // number of cdc blocks
|
|
||||||
static esp_tusb_cdc_t *cdc_obj[CDC_INTF_NUM] = {};
|
|
||||||
static const char *TAG = "tusb_cdc";
|
|
||||||
|
|
||||||
esp_tusb_cdc_t *tinyusb_cdc_get_intf(int itf_num)
|
|
||||||
{
|
|
||||||
if (itf_num >= CDC_INTF_NUM || itf_num < 0) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return cdc_obj[itf_num];
|
|
||||||
}
|
|
||||||
|
|
||||||
static esp_err_t cdc_obj_check(int itf, bool expected_inited, tusb_class_code_t expected_type)
|
|
||||||
{
|
|
||||||
esp_tusb_cdc_t *this_itf = tinyusb_cdc_get_intf(itf);
|
|
||||||
|
|
||||||
bool inited = (this_itf != NULL);
|
|
||||||
ESP_RETURN_ON_FALSE(expected_inited == inited, ESP_ERR_INVALID_STATE, TAG, "Wrong state of the interface. Expected state: %s", expected_inited ? "initialized" : "not initialized");
|
|
||||||
ESP_RETURN_ON_FALSE(!(inited && (expected_type != -1) && !(this_itf->type == expected_type)), ESP_ERR_INVALID_STATE, TAG, "Wrong type of the interface. Should be : 0x%x (tusb_class_code_t)", expected_type);
|
|
||||||
return ESP_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static esp_err_t tusb_cdc_comm_init(int itf)
|
|
||||||
{
|
|
||||||
ESP_RETURN_ON_ERROR(cdc_obj_check(itf, false, -1), TAG, "cdc_obj_check failed");
|
|
||||||
cdc_obj[itf] = calloc(1, sizeof(esp_tusb_cdc_t));
|
|
||||||
if (cdc_obj[itf] != NULL) {
|
|
||||||
cdc_obj[itf]->type = TUSB_CLASS_CDC;
|
|
||||||
ESP_LOGD(TAG, "CDC Comm class initialized");
|
|
||||||
return ESP_OK;
|
|
||||||
} else {
|
|
||||||
ESP_LOGE(TAG, "CDC Comm initialization error");
|
|
||||||
return ESP_FAIL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static esp_err_t tusb_cdc_deinit_comm(int itf)
|
|
||||||
{
|
|
||||||
ESP_RETURN_ON_ERROR(cdc_obj_check(itf, true, TUSB_CLASS_CDC), TAG, "cdc_obj_check failed");
|
|
||||||
free(cdc_obj[itf]);
|
|
||||||
cdc_obj[itf] = NULL;
|
|
||||||
return ESP_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static esp_err_t tusb_cdc_data_init(int itf)
|
|
||||||
{
|
|
||||||
ESP_RETURN_ON_ERROR(cdc_obj_check(itf, false, TUSB_CLASS_CDC_DATA), TAG, "cdc_obj_check failed");
|
|
||||||
cdc_obj[itf] = calloc(1, sizeof(esp_tusb_cdc_t));
|
|
||||||
if (cdc_obj[itf] != NULL) {
|
|
||||||
cdc_obj[itf]->type = TUSB_CLASS_CDC_DATA;
|
|
||||||
ESP_LOGD(TAG, "CDC Data class initialized");
|
|
||||||
return ESP_OK;
|
|
||||||
} else {
|
|
||||||
ESP_LOGE(TAG, "CDC Data initialization error");
|
|
||||||
return ESP_FAIL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static esp_err_t tusb_cdc_deinit_data(int itf)
|
|
||||||
{
|
|
||||||
ESP_RETURN_ON_ERROR(cdc_obj_check(itf, true, TUSB_CLASS_CDC_DATA), TAG, "cdc_obj_check failed");
|
|
||||||
free(cdc_obj[itf]);
|
|
||||||
cdc_obj[itf] = NULL;
|
|
||||||
return ESP_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
esp_err_t tinyusb_cdc_init(int itf, const tinyusb_config_cdc_t *cfg)
|
|
||||||
{
|
|
||||||
ESP_RETURN_ON_ERROR(cdc_obj_check(itf, false, -1), TAG, "cdc_obj_check failed");
|
|
||||||
|
|
||||||
ESP_LOGD(TAG, "Init CDC %d", itf);
|
|
||||||
if (cfg->cdc_class == TUSB_CLASS_CDC) {
|
|
||||||
ESP_RETURN_ON_ERROR(tusb_cdc_comm_init(itf), TAG, "tusb_cdc_comm_init failed");
|
|
||||||
cdc_obj[itf]->cdc_subclass.comm_subclass = cfg->cdc_subclass.comm_subclass;
|
|
||||||
} else {
|
|
||||||
ESP_RETURN_ON_ERROR(tusb_cdc_data_init(itf), TAG, "tusb_cdc_data_init failed");
|
|
||||||
cdc_obj[itf]->cdc_subclass.data_subclass = cfg->cdc_subclass.data_subclass;
|
|
||||||
}
|
|
||||||
cdc_obj[itf]->usb_dev = cfg->usb_dev;
|
|
||||||
return ESP_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
esp_err_t tinyusb_cdc_deinit(int itf)
|
|
||||||
{
|
|
||||||
ESP_RETURN_ON_ERROR(cdc_obj_check(itf, true, -1), TAG, "cdc_obj_check failed");
|
|
||||||
|
|
||||||
ESP_LOGD(TAG, "Deinit CDC %d", itf);
|
|
||||||
if (cdc_obj[itf]->type == TUSB_CLASS_CDC) {
|
|
||||||
ESP_RETURN_ON_ERROR(tusb_cdc_deinit_comm(itf), TAG, "tusb_cdc_deinit_comm failed");
|
|
||||||
} else if (cdc_obj[itf]->type == TUSB_CLASS_CDC_DATA) {
|
|
||||||
ESP_RETURN_ON_ERROR(tusb_cdc_deinit_data(itf), TAG, "tusb_cdc_deinit_data failed");
|
|
||||||
} else {
|
|
||||||
return ESP_ERR_INVALID_ARG;
|
|
||||||
}
|
|
||||||
return ESP_OK;
|
|
||||||
}
|
|
||||||
@ -1,294 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include "esp_log.h"
|
|
||||||
#include "esp_check.h"
|
|
||||||
#include "esp_err.h"
|
|
||||||
#include "descriptors_control.h"
|
|
||||||
#include "usb_descriptors.h"
|
|
||||||
|
|
||||||
#define MAX_DESC_BUF_SIZE 32 // Max length of string descriptor (can be extended, USB supports lengths up to 255 bytes)
|
|
||||||
|
|
||||||
static const char *TAG = "tusb_desc";
|
|
||||||
|
|
||||||
// =============================================================================
|
|
||||||
// STRUCTS
|
|
||||||
// =============================================================================
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Descriptor pointers for tinyusb descriptor requests callbacks
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
const tusb_desc_device_t *dev; /*!< Pointer to device descriptor */
|
|
||||||
union {
|
|
||||||
const uint8_t *cfg; /*!< Pointer to FullSpeed configuration descriptor when device one-speed only */
|
|
||||||
const uint8_t *fs_cfg; /*!< Pointer to FullSpeed configuration descriptor when device support HighSpeed */
|
|
||||||
};
|
|
||||||
#if (TUD_OPT_HIGH_SPEED)
|
|
||||||
const uint8_t *hs_cfg; /*!< Pointer to HighSpeed configuration descriptor */
|
|
||||||
const tusb_desc_device_qualifier_t *qualifier; /*!< Pointer to Qualifier descriptor */
|
|
||||||
uint8_t *other_speed; /*!< Pointer for other speed configuration descriptor */
|
|
||||||
#endif // TUD_OPT_HIGH_SPEED
|
|
||||||
const char *str[USB_STRING_DESCRIPTOR_ARRAY_SIZE]; /*!< Pointer to array of UTF-8 strings */
|
|
||||||
int str_count; /*!< Number of descriptors in str */
|
|
||||||
} tinyusb_descriptor_config_t;
|
|
||||||
|
|
||||||
static tinyusb_descriptor_config_t s_desc_cfg;
|
|
||||||
|
|
||||||
// =============================================================================
|
|
||||||
// CALLBACKS
|
|
||||||
// =============================================================================
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Invoked when received GET DEVICE DESCRIPTOR.
|
|
||||||
* Descriptor contents must exist long enough for transfer to complete
|
|
||||||
*
|
|
||||||
* @return Pointer to device descriptor
|
|
||||||
*/
|
|
||||||
uint8_t const *tud_descriptor_device_cb(void)
|
|
||||||
{
|
|
||||||
assert(s_desc_cfg.dev);
|
|
||||||
return (uint8_t const *)s_desc_cfg.dev;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Invoked when received GET CONFIGURATION DESCRIPTOR.
|
|
||||||
* Descriptor contents must exist long enough for transfer to complete
|
|
||||||
*
|
|
||||||
* @param[in] index Index of required configuration
|
|
||||||
* @return Pointer to configuration descriptor
|
|
||||||
*/
|
|
||||||
uint8_t const *tud_descriptor_configuration_cb(uint8_t index)
|
|
||||||
{
|
|
||||||
(void)index; // Unused, this driver supports only 1 configuration
|
|
||||||
assert(s_desc_cfg.cfg);
|
|
||||||
|
|
||||||
#if (TUD_OPT_HIGH_SPEED)
|
|
||||||
// HINT: cfg and fs_cfg are union, no need to assert(fs_cfg)
|
|
||||||
assert(s_desc_cfg.hs_cfg);
|
|
||||||
// Return configuration descriptor based on Host speed
|
|
||||||
return (TUSB_SPEED_HIGH == tud_speed_get())
|
|
||||||
? s_desc_cfg.hs_cfg
|
|
||||||
: s_desc_cfg.fs_cfg;
|
|
||||||
#else
|
|
||||||
return s_desc_cfg.cfg;
|
|
||||||
#endif // TUD_OPT_HIGH_SPEED
|
|
||||||
}
|
|
||||||
|
|
||||||
#if (TUD_OPT_HIGH_SPEED)
|
|
||||||
/**
|
|
||||||
* @brief Invoked when received GET DEVICE QUALIFIER DESCRIPTOR request
|
|
||||||
* Descriptor contents must exist long enough for transfer to complete
|
|
||||||
* If not highspeed capable stall this request
|
|
||||||
*/
|
|
||||||
uint8_t const *tud_descriptor_device_qualifier_cb(void)
|
|
||||||
{
|
|
||||||
assert(s_desc_cfg.qualifier);
|
|
||||||
return (uint8_t const *)s_desc_cfg.qualifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Invoked when received GET OTHER SPEED CONFIGURATION DESCRIPTOR request
|
|
||||||
* Descriptor contents must exist long enough for transfer to complete
|
|
||||||
* Configuration descriptor in the other speed e.g if high speed then this is for full speed and vice versa
|
|
||||||
*/
|
|
||||||
uint8_t const *tud_descriptor_other_speed_configuration_cb(uint8_t index)
|
|
||||||
{
|
|
||||||
assert(s_desc_cfg.other_speed);
|
|
||||||
|
|
||||||
const uint8_t *other_speed = (TUSB_SPEED_HIGH == tud_speed_get())
|
|
||||||
? s_desc_cfg.fs_cfg
|
|
||||||
: s_desc_cfg.hs_cfg;
|
|
||||||
|
|
||||||
memcpy(s_desc_cfg.other_speed,
|
|
||||||
other_speed,
|
|
||||||
((tusb_desc_configuration_t *)other_speed)->wTotalLength);
|
|
||||||
|
|
||||||
((tusb_desc_configuration_t *)s_desc_cfg.other_speed)->bDescriptorType = TUSB_DESC_OTHER_SPEED_CONFIG;
|
|
||||||
return s_desc_cfg.other_speed;
|
|
||||||
}
|
|
||||||
#endif // TUD_OPT_HIGH_SPEED
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Invoked when received GET STRING DESCRIPTOR request
|
|
||||||
*
|
|
||||||
* @param[in] index Index of required descriptor
|
|
||||||
* @param[in] langid Language of the descriptor
|
|
||||||
* @return Pointer to UTF-16 string descriptor
|
|
||||||
*/
|
|
||||||
uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid)
|
|
||||||
{
|
|
||||||
(void) langid; // Unused, this driver supports only one language in string descriptors
|
|
||||||
assert(s_desc_cfg.str);
|
|
||||||
uint8_t chr_count;
|
|
||||||
static uint16_t _desc_str[MAX_DESC_BUF_SIZE];
|
|
||||||
|
|
||||||
if (index == 0) {
|
|
||||||
memcpy(&_desc_str[1], s_desc_cfg.str[0], 2);
|
|
||||||
chr_count = 1;
|
|
||||||
} else {
|
|
||||||
if (index >= USB_STRING_DESCRIPTOR_ARRAY_SIZE) {
|
|
||||||
ESP_LOGW(TAG, "String index (%u) is out of bounds, check your string descriptor", index);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s_desc_cfg.str[index] == NULL) {
|
|
||||||
ESP_LOGW(TAG, "String index (%u) points to NULL, check your string descriptor", index);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *str = s_desc_cfg.str[index];
|
|
||||||
chr_count = strnlen(str, MAX_DESC_BUF_SIZE - 1); // Buffer len - header
|
|
||||||
|
|
||||||
// Convert ASCII string into UTF-16
|
|
||||||
for (uint8_t i = 0; i < chr_count; i++) {
|
|
||||||
_desc_str[1 + i] = str[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// First byte is length in bytes (including header), second byte is descriptor type (TUSB_DESC_STRING)
|
|
||||||
_desc_str[0] = (TUSB_DESC_STRING << 8 ) | (2 * chr_count + 2);
|
|
||||||
|
|
||||||
return _desc_str;
|
|
||||||
}
|
|
||||||
|
|
||||||
// =============================================================================
|
|
||||||
// Driver functions
|
|
||||||
// =============================================================================
|
|
||||||
esp_err_t tinyusb_set_descriptors(const tinyusb_config_t *config)
|
|
||||||
{
|
|
||||||
esp_err_t ret = ESP_FAIL;
|
|
||||||
assert(config);
|
|
||||||
const char **pstr_desc;
|
|
||||||
// Flush descriptors control struct
|
|
||||||
memset(&s_desc_cfg, 0x00, sizeof(tinyusb_descriptor_config_t));
|
|
||||||
// Parse configuration and save descriptors's pointer
|
|
||||||
// Select Device Descriptor
|
|
||||||
if (config->device_descriptor == NULL) {
|
|
||||||
ESP_LOGW(TAG, "No Device descriptor provided, using default.");
|
|
||||||
s_desc_cfg.dev = &descriptor_dev_default;
|
|
||||||
} else {
|
|
||||||
s_desc_cfg.dev = config->device_descriptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Select FullSpeed configuration descriptor
|
|
||||||
if (config->configuration_descriptor == NULL) {
|
|
||||||
// Default configuration descriptor is provided only for CDC, MSC and NCM classes
|
|
||||||
#if (CFG_TUD_HID > 0 || CFG_TUD_MIDI > 0 || CFG_TUD_CUSTOM_CLASS > 0 || CFG_TUD_ECM_RNDIS > 0 || CFG_TUD_DFU > 0 || CFG_TUD_DFU_RUNTIME > 0 || CFG_TUD_BTH > 0)
|
|
||||||
ESP_GOTO_ON_FALSE(config->configuration_descriptor, ESP_ERR_INVALID_ARG, fail, TAG, "Configuration descriptor must be provided for this device");
|
|
||||||
#else
|
|
||||||
ESP_LOGW(TAG, "No FullSpeed configuration descriptor provided, using default.");
|
|
||||||
s_desc_cfg.cfg = descriptor_fs_cfg_default;
|
|
||||||
#endif
|
|
||||||
} else {
|
|
||||||
s_desc_cfg.cfg = config->configuration_descriptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if (TUD_OPT_HIGH_SPEED)
|
|
||||||
// High Speed
|
|
||||||
if (config->hs_configuration_descriptor == NULL) {
|
|
||||||
// Default configuration descriptor is provided only for CDC, MSC and NCM classes
|
|
||||||
#if (CFG_TUD_HID > 0 || CFG_TUD_MIDI > 0 || CFG_TUD_CUSTOM_CLASS > 0 || CFG_TUD_ECM_RNDIS > 0 || CFG_TUD_DFU > 0 || CFG_TUD_DFU_RUNTIME > 0 || CFG_TUD_BTH > 0)
|
|
||||||
ESP_GOTO_ON_FALSE(config->hs_configuration_descriptor, ESP_ERR_INVALID_ARG, fail, TAG, "HighSpeed configuration descriptor must be provided for this device");
|
|
||||||
#else
|
|
||||||
ESP_LOGW(TAG, "No HighSpeed configuration descriptor provided, using default.");
|
|
||||||
s_desc_cfg.hs_cfg = descriptor_hs_cfg_default;
|
|
||||||
#endif
|
|
||||||
} else {
|
|
||||||
s_desc_cfg.hs_cfg = config->hs_configuration_descriptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
// HS and FS cfg desc should be equal length
|
|
||||||
ESP_GOTO_ON_FALSE(((tusb_desc_configuration_t *)s_desc_cfg.hs_cfg)->wTotalLength ==
|
|
||||||
((tusb_desc_configuration_t *)s_desc_cfg.fs_cfg)->wTotalLength,
|
|
||||||
ESP_ERR_INVALID_ARG, fail, TAG, "HighSpeed and FullSpeed configuration descriptors must be same length");
|
|
||||||
|
|
||||||
// Qualifier Descriptor
|
|
||||||
if (config->qualifier_descriptor == NULL) {
|
|
||||||
ESP_GOTO_ON_FALSE((s_desc_cfg.dev == &descriptor_dev_default), ESP_ERR_INVALID_ARG, fail, TAG, "Qualifier descriptor must be present (Device Descriptor not default).");
|
|
||||||
// Get default qualifier if device descriptor is default
|
|
||||||
ESP_LOGW(TAG, "No Qulifier descriptor provided, using default.");
|
|
||||||
s_desc_cfg.qualifier = &descriptor_qualifier_default;
|
|
||||||
} else {
|
|
||||||
s_desc_cfg.qualifier = config->qualifier_descriptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Other Speed buffer allocate
|
|
||||||
s_desc_cfg.other_speed = calloc(1, ((tusb_desc_configuration_t *)s_desc_cfg.hs_cfg)->wTotalLength);
|
|
||||||
ESP_GOTO_ON_FALSE(s_desc_cfg.other_speed, ESP_ERR_NO_MEM, fail, TAG, "Other speed memory allocation error");
|
|
||||||
#endif // TUD_OPT_HIGH_SPEED
|
|
||||||
|
|
||||||
// Select String Descriptors and count them
|
|
||||||
if (config->string_descriptor == NULL) {
|
|
||||||
ESP_LOGW(TAG, "No String descriptors provided, using default.");
|
|
||||||
pstr_desc = descriptor_str_default;
|
|
||||||
while (descriptor_str_default[++s_desc_cfg.str_count] != NULL);
|
|
||||||
} else {
|
|
||||||
pstr_desc = config->string_descriptor;
|
|
||||||
s_desc_cfg.str_count = (config->string_descriptor_count != 0)
|
|
||||||
? config->string_descriptor_count
|
|
||||||
: 8; // '8' is for backward compatibility with esp_tinyusb v1.0.0. Do NOT remove!
|
|
||||||
}
|
|
||||||
|
|
||||||
ESP_GOTO_ON_FALSE(s_desc_cfg.str_count <= USB_STRING_DESCRIPTOR_ARRAY_SIZE, ESP_ERR_NOT_SUPPORTED, fail, TAG, "String descriptors exceed limit");
|
|
||||||
memcpy(s_desc_cfg.str, pstr_desc, s_desc_cfg.str_count * sizeof(pstr_desc[0]));
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "\n"
|
|
||||||
"┌─────────────────────────────────┐\n"
|
|
||||||
"│ USB Device Descriptor Summary │\n"
|
|
||||||
"├───────────────────┬─────────────┤\n"
|
|
||||||
"│bDeviceClass │ %-4u │\n"
|
|
||||||
"├───────────────────┼─────────────┤\n"
|
|
||||||
"│bDeviceSubClass │ %-4u │\n"
|
|
||||||
"├───────────────────┼─────────────┤\n"
|
|
||||||
"│bDeviceProtocol │ %-4u │\n"
|
|
||||||
"├───────────────────┼─────────────┤\n"
|
|
||||||
"│bMaxPacketSize0 │ %-4u │\n"
|
|
||||||
"├───────────────────┼─────────────┤\n"
|
|
||||||
"│idVendor │ %-#10x │\n"
|
|
||||||
"├───────────────────┼─────────────┤\n"
|
|
||||||
"│idProduct │ %-#10x │\n"
|
|
||||||
"├───────────────────┼─────────────┤\n"
|
|
||||||
"│bcdDevice │ %-#10x │\n"
|
|
||||||
"├───────────────────┼─────────────┤\n"
|
|
||||||
"│iManufacturer │ %-#10x │\n"
|
|
||||||
"├───────────────────┼─────────────┤\n"
|
|
||||||
"│iProduct │ %-#10x │\n"
|
|
||||||
"├───────────────────┼─────────────┤\n"
|
|
||||||
"│iSerialNumber │ %-#10x │\n"
|
|
||||||
"├───────────────────┼─────────────┤\n"
|
|
||||||
"│bNumConfigurations │ %-#10x │\n"
|
|
||||||
"└───────────────────┴─────────────┘",
|
|
||||||
s_desc_cfg.dev->bDeviceClass, s_desc_cfg.dev->bDeviceSubClass,
|
|
||||||
s_desc_cfg.dev->bDeviceProtocol, s_desc_cfg.dev->bMaxPacketSize0,
|
|
||||||
s_desc_cfg.dev->idVendor, s_desc_cfg.dev->idProduct, s_desc_cfg.dev->bcdDevice,
|
|
||||||
s_desc_cfg.dev->iManufacturer, s_desc_cfg.dev->iProduct, s_desc_cfg.dev->iSerialNumber,
|
|
||||||
s_desc_cfg.dev->bNumConfigurations);
|
|
||||||
|
|
||||||
return ESP_OK;
|
|
||||||
|
|
||||||
fail:
|
|
||||||
#if (TUD_OPT_HIGH_SPEED)
|
|
||||||
free(s_desc_cfg.other_speed);
|
|
||||||
#endif // TUD_OPT_HIGH_SPEED
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void tinyusb_set_str_descriptor(const char *str, int str_idx)
|
|
||||||
{
|
|
||||||
assert(str_idx < USB_STRING_DESCRIPTOR_ARRAY_SIZE);
|
|
||||||
s_desc_cfg.str[str_idx] = str;
|
|
||||||
}
|
|
||||||
|
|
||||||
void tinyusb_free_descriptors(void)
|
|
||||||
{
|
|
||||||
#if (TUD_OPT_HIGH_SPEED)
|
|
||||||
assert(s_desc_cfg.other_speed);
|
|
||||||
free(s_desc_cfg.other_speed);
|
|
||||||
#endif // TUD_OPT_HIGH_SPEED
|
|
||||||
}
|
|
||||||
@ -1,14 +0,0 @@
|
|||||||
dependencies:
|
|
||||||
idf:
|
|
||||||
version: '>=5.0'
|
|
||||||
tinyusb:
|
|
||||||
public: true
|
|
||||||
version: '>=0.14.2'
|
|
||||||
description: Espressif's additions to TinyUSB
|
|
||||||
documentation: https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/api-reference/peripherals/usb_device.html
|
|
||||||
repository: git://github.com/espressif/esp-usb.git
|
|
||||||
repository_info:
|
|
||||||
commit_sha: 4b6a798d0bed444fff48147c8dcdbbd038e92892
|
|
||||||
path: device/esp_tinyusb
|
|
||||||
url: https://github.com/espressif/esp-usb/tree/master/device/esp_tinyusb
|
|
||||||
version: 1.4.4
|
|
||||||
@ -1,75 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include "esp_err.h"
|
|
||||||
#include "tusb.h"
|
|
||||||
#include "tinyusb_types.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Configuration structure of the TinyUSB core
|
|
||||||
*
|
|
||||||
* USB specification mandates self-powered devices to monitor USB VBUS to detect connection/disconnection events.
|
|
||||||
* If you want to use this feature, connected VBUS to any free GPIO through a voltage divider or voltage comparator.
|
|
||||||
* The voltage divider output should be (0.75 * Vdd) if VBUS is 4.4V (lowest valid voltage at device port).
|
|
||||||
* The comparator thresholds should be set with hysteresis: 4.35V (falling edge) and 4.75V (raising edge).
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
union {
|
|
||||||
const tusb_desc_device_t *device_descriptor; /*!< Pointer to a device descriptor. If set to NULL, the TinyUSB device will use a default device descriptor whose values are set in Kconfig */
|
|
||||||
const tusb_desc_device_t *descriptor __attribute__((deprecated)); /*!< Alias to `device_descriptor` for backward compatibility */
|
|
||||||
};
|
|
||||||
const char **string_descriptor; /*!< Pointer to array of string descriptors. If set to NULL, TinyUSB device will use a default string descriptors whose values are set in Kconfig */
|
|
||||||
int string_descriptor_count; /*!< Number of descriptors in above array */
|
|
||||||
bool external_phy; /*!< Should USB use an external PHY */
|
|
||||||
union {
|
|
||||||
struct {
|
|
||||||
const uint8_t *configuration_descriptor; /*!< Pointer to a configuration descriptor. If set to NULL, TinyUSB device will use a default configuration descriptor whose values are set in Kconfig */
|
|
||||||
};
|
|
||||||
#if (TUD_OPT_HIGH_SPEED)
|
|
||||||
struct {
|
|
||||||
const uint8_t *fs_configuration_descriptor; /*!< Pointer to a FullSpeed configuration descriptor. If set to NULL, TinyUSB device will use a default configuration descriptor whose values are set in Kconfig */
|
|
||||||
};
|
|
||||||
};
|
|
||||||
const uint8_t *hs_configuration_descriptor; /*!< Pointer to a HighSpeed configuration descriptor. If set to NULL, TinyUSB device will use a default configuration descriptor whose values are set in Kconfig */
|
|
||||||
const tusb_desc_device_qualifier_t *qualifier_descriptor; /*!< Pointer to a qualifier descriptor */
|
|
||||||
#else
|
|
||||||
};
|
|
||||||
#endif // TUD_OPT_HIGH_SPEED
|
|
||||||
bool self_powered; /*!< This is a self-powered USB device. USB VBUS must be monitored. */
|
|
||||||
int vbus_monitor_io; /*!< GPIO for VBUS monitoring. Ignored if not self_powered. */
|
|
||||||
} tinyusb_config_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This is an all-in-one helper function, including:
|
|
||||||
* 1. USB device driver initialization
|
|
||||||
* 2. Descriptors preparation
|
|
||||||
* 3. TinyUSB stack initialization
|
|
||||||
* 4. Creates and start a task to handle usb events
|
|
||||||
*
|
|
||||||
* @note Don't change Custom descriptor, but if it has to be done,
|
|
||||||
* Suggest to define as follows in order to match the Interface Association Descriptor (IAD):
|
|
||||||
* bDeviceClass = TUSB_CLASS_MISC,
|
|
||||||
* bDeviceSubClass = MISC_SUBCLASS_COMMON,
|
|
||||||
*
|
|
||||||
* @param config tinyusb stack specific configuration
|
|
||||||
* @retval ESP_ERR_INVALID_ARG Install driver and tinyusb stack failed because of invalid argument
|
|
||||||
* @retval ESP_FAIL Install driver and tinyusb stack failed because of internal error
|
|
||||||
* @retval ESP_OK Install driver and tinyusb stack successfully
|
|
||||||
*/
|
|
||||||
esp_err_t tinyusb_driver_install(const tinyusb_config_t *config);
|
|
||||||
|
|
||||||
esp_err_t tinyusb_driver_uninstall(void);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@ -1,99 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include "tinyusb_types.h"
|
|
||||||
#include "esp_err.h"
|
|
||||||
#include "sdkconfig.h"
|
|
||||||
|
|
||||||
#if (CONFIG_TINYUSB_NET_MODE_NONE != 1)
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief On receive callback type
|
|
||||||
*/
|
|
||||||
typedef esp_err_t (*tusb_net_rx_cb_t)(void *buffer, uint16_t len, void *ctx);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Free Tx buffer callback type
|
|
||||||
*/
|
|
||||||
typedef void (*tusb_net_free_tx_cb_t)(void *buffer, void *ctx);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief On init callback type
|
|
||||||
*/
|
|
||||||
typedef void (*tusb_net_init_cb_t)(void *ctx);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief ESP TinyUSB NCM driver configuration structure
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
uint8_t mac_addr[6]; /*!< MAC address. Must be 6 bytes long. */
|
|
||||||
tusb_net_rx_cb_t on_recv_callback; /*!< TinyUSB receive data callbeck */
|
|
||||||
tusb_net_free_tx_cb_t free_tx_buffer; /*!< User function for freeing the Tx buffer.
|
|
||||||
* - could be NULL, if user app is responsible for freeing the buffer
|
|
||||||
* - must be used in asynchronous send mode
|
|
||||||
* - is only called if the used tinyusb_net_send...() function returns ESP_OK
|
|
||||||
* - in sync mode means that the packet was accepted by TinyUSB
|
|
||||||
* - in async mode means that the packet was queued to be processed in TinyUSB task
|
|
||||||
*/
|
|
||||||
tusb_net_init_cb_t on_init_callback; /*!< TinyUSB init network callback */
|
|
||||||
void *user_context; /*!< User context to be passed to any of the callback */
|
|
||||||
} tinyusb_net_config_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Initialize TinyUSB NET driver
|
|
||||||
*
|
|
||||||
* @param[in] usb_dev USB device to use
|
|
||||||
* @param[in] cfg Configuration of the driver
|
|
||||||
* @return esp_err_t
|
|
||||||
*/
|
|
||||||
esp_err_t tinyusb_net_init(tinyusb_usbdev_t usb_dev, const tinyusb_net_config_t *cfg);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief TinyUSB NET driver send data synchronously
|
|
||||||
*
|
|
||||||
* @note It is possible to use sync and async send interchangeably.
|
|
||||||
* This function needs some synchronization primitives, so using sync mode (even once) uses more heap
|
|
||||||
*
|
|
||||||
* @param[in] buffer USB send data
|
|
||||||
* @param[in] len Send data len
|
|
||||||
* @param[in] buff_free_arg Pointer to be passed to the free_tx_buffer() callback
|
|
||||||
* @param[in] timeout Send data len
|
|
||||||
* @return ESP_OK on success == packet has been consumed by tusb and would be eventually freed
|
|
||||||
* by free_tx_buffer() callback (if non null)
|
|
||||||
* ESP_ERR_TIMEOUT on timeout
|
|
||||||
* ESP_ERR_INVALID_STATE if tusb not initialized, ESP_ERR_NO_MEM on alloc failure
|
|
||||||
*/
|
|
||||||
esp_err_t tinyusb_net_send_sync(void *buffer, uint16_t len, void *buff_free_arg, TickType_t timeout);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief TinyUSB NET driver send data asynchronously
|
|
||||||
*
|
|
||||||
* @note If using asynchronous sends, you must free the buffer using free_tx_buffer() callback.
|
|
||||||
* @note It is possible to use sync and async send interchangeably.
|
|
||||||
* @note Async flavor of the send is useful when the USB stack runs faster than the caller,
|
|
||||||
* since we have no control over the transmitted packets, if they get accepted or discarded.
|
|
||||||
*
|
|
||||||
* @param[in] buffer USB send data
|
|
||||||
* @param[in] len Send data len
|
|
||||||
* @param[in] buff_free_arg Pointer to be passed to the free_tx_buffer() callback
|
|
||||||
* @return ESP_OK on success == packet has been consumed by tusb and will be freed
|
|
||||||
* by free_tx_buffer() callback (if non null)
|
|
||||||
* ESP_ERR_INVALID_STATE if tusb not initialized
|
|
||||||
*/
|
|
||||||
esp_err_t tinyusb_net_send_async(void *buffer, uint16_t len, void *buff_free_arg);
|
|
||||||
|
|
||||||
#endif // (CONFIG_TINYUSB_NET_MODE_NONE != 1)
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define USB_ESPRESSIF_VID 0x303A
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
TINYUSB_USBDEV_0,
|
|
||||||
} tinyusb_usbdev_t;
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@ -1,206 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include "sdkconfig.h"
|
|
||||||
#include "esp_err.h"
|
|
||||||
|
|
||||||
#include "tinyusb_types.h"
|
|
||||||
#include "class/cdc/cdc.h"
|
|
||||||
|
|
||||||
#if (CONFIG_TINYUSB_CDC_ENABLED != 1)
|
|
||||||
#error "TinyUSB CDC driver must be enabled in menuconfig"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief CDC ports available to setup
|
|
||||||
*/
|
|
||||||
typedef enum {
|
|
||||||
TINYUSB_CDC_ACM_0 = 0x0,
|
|
||||||
TINYUSB_CDC_ACM_1,
|
|
||||||
TINYUSB_CDC_ACM_MAX
|
|
||||||
} tinyusb_cdcacm_itf_t;
|
|
||||||
|
|
||||||
/* Callbacks and events
|
|
||||||
********************************************************************* */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Data provided to the input of the `callback_rx_wanted_char` callback
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
char wanted_char; /*!< Wanted character */
|
|
||||||
} cdcacm_event_rx_wanted_char_data_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Data provided to the input of the `callback_line_state_changed` callback
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
bool dtr; /*!< Data Terminal Ready (DTR) line state */
|
|
||||||
bool rts; /*!< Request To Send (RTS) line state */
|
|
||||||
} cdcacm_event_line_state_changed_data_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Data provided to the input of the `line_coding_changed` callback
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
cdc_line_coding_t const *p_line_coding; /*!< New line coding value */
|
|
||||||
} cdcacm_event_line_coding_changed_data_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Types of CDC ACM events
|
|
||||||
*/
|
|
||||||
typedef enum {
|
|
||||||
CDC_EVENT_RX,
|
|
||||||
CDC_EVENT_RX_WANTED_CHAR,
|
|
||||||
CDC_EVENT_LINE_STATE_CHANGED,
|
|
||||||
CDC_EVENT_LINE_CODING_CHANGED
|
|
||||||
} cdcacm_event_type_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Describes an event passing to the input of a callbacks
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
cdcacm_event_type_t type; /*!< Event type */
|
|
||||||
union {
|
|
||||||
cdcacm_event_rx_wanted_char_data_t rx_wanted_char_data; /*!< Data input of the `callback_rx_wanted_char` callback */
|
|
||||||
cdcacm_event_line_state_changed_data_t line_state_changed_data; /*!< Data input of the `callback_line_state_changed` callback */
|
|
||||||
cdcacm_event_line_coding_changed_data_t line_coding_changed_data; /*!< Data input of the `line_coding_changed` callback */
|
|
||||||
};
|
|
||||||
} cdcacm_event_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief CDC-ACM callback type
|
|
||||||
*/
|
|
||||||
typedef void(*tusb_cdcacm_callback_t)(int itf, cdcacm_event_t *event);
|
|
||||||
|
|
||||||
/*********************************************************************** Callbacks and events*/
|
|
||||||
/* Other structs
|
|
||||||
********************************************************************* */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Configuration structure for CDC-ACM
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
tinyusb_usbdev_t usb_dev; /*!< Usb device to set up */
|
|
||||||
tinyusb_cdcacm_itf_t cdc_port; /*!< CDC port */
|
|
||||||
size_t rx_unread_buf_sz __attribute__((deprecated("This parameter is not used any more. Configure RX buffer in menuconfig.")));
|
|
||||||
tusb_cdcacm_callback_t callback_rx; /*!< Pointer to the function with the `tusb_cdcacm_callback_t` type that will be handled as a callback */
|
|
||||||
tusb_cdcacm_callback_t callback_rx_wanted_char; /*!< Pointer to the function with the `tusb_cdcacm_callback_t` type that will be handled as a callback */
|
|
||||||
tusb_cdcacm_callback_t callback_line_state_changed; /*!< Pointer to the function with the `tusb_cdcacm_callback_t` type that will be handled as a callback */
|
|
||||||
tusb_cdcacm_callback_t callback_line_coding_changed; /*!< Pointer to the function with the `tusb_cdcacm_callback_t` type that will be handled as a callback */
|
|
||||||
} tinyusb_config_cdcacm_t;
|
|
||||||
|
|
||||||
/*********************************************************************** Other structs*/
|
|
||||||
/* Public functions
|
|
||||||
********************************************************************* */
|
|
||||||
/**
|
|
||||||
* @brief Initialize CDC ACM. Initialization will be finished with
|
|
||||||
* the `tud_cdc_line_state_cb` callback
|
|
||||||
*
|
|
||||||
* @param[in] cfg Configuration structure
|
|
||||||
* @return esp_err_t
|
|
||||||
*/
|
|
||||||
esp_err_t tusb_cdc_acm_init(const tinyusb_config_cdcacm_t *cfg);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief De-initialize CDC ACM.
|
|
||||||
*
|
|
||||||
* @param[in] itf Index of CDC interface
|
|
||||||
* @return esp_err_t
|
|
||||||
*/
|
|
||||||
esp_err_t tusb_cdc_acm_deinit(int itf);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Register a callback invoking on CDC event. If the callback had been
|
|
||||||
* already registered, it will be overwritten
|
|
||||||
*
|
|
||||||
* @param[in] itf Index of CDC interface
|
|
||||||
* @param[in] event_type Type of registered event for a callback
|
|
||||||
* @param[in] callback Callback function
|
|
||||||
* @return esp_err_t - ESP_OK or ESP_ERR_INVALID_ARG
|
|
||||||
*/
|
|
||||||
esp_err_t tinyusb_cdcacm_register_callback(tinyusb_cdcacm_itf_t itf,
|
|
||||||
cdcacm_event_type_t event_type,
|
|
||||||
tusb_cdcacm_callback_t callback);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Unregister a callback invoking on CDC event
|
|
||||||
*
|
|
||||||
* @param[in] itf Index of CDC interface
|
|
||||||
* @param[in] event_type Type of registered event for a callback
|
|
||||||
* @return esp_err_t - ESP_OK or ESP_ERR_INVALID_ARG
|
|
||||||
*/
|
|
||||||
esp_err_t tinyusb_cdcacm_unregister_callback(tinyusb_cdcacm_itf_t itf, cdcacm_event_type_t event_type);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Sent one character to a write buffer
|
|
||||||
*
|
|
||||||
* @param[in] itf Index of CDC interface
|
|
||||||
* @param[in] ch Character to send
|
|
||||||
* @return size_t - amount of queued bytes
|
|
||||||
*/
|
|
||||||
size_t tinyusb_cdcacm_write_queue_char(tinyusb_cdcacm_itf_t itf, char ch);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Write data to write buffer
|
|
||||||
*
|
|
||||||
* @param[in] itf Index of CDC interface
|
|
||||||
* @param[in] in_buf Data
|
|
||||||
* @param[in] in_size Data size in bytes
|
|
||||||
* @return size_t - amount of queued bytes
|
|
||||||
*/
|
|
||||||
size_t tinyusb_cdcacm_write_queue(tinyusb_cdcacm_itf_t itf, const uint8_t *in_buf, size_t in_size);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Flush data in write buffer of CDC interface
|
|
||||||
*
|
|
||||||
* Use `tinyusb_cdcacm_write_queue` to add data to the buffer
|
|
||||||
*
|
|
||||||
* WARNING! TinyUSB can block output Endpoint for several RX callbacks, after will do additional flush
|
|
||||||
* after the each transfer. That can leads to the situation when you requested a flush, but it will fail until
|
|
||||||
* one of the next callbacks ends.
|
|
||||||
* SO USING OF THE FLUSH WITH TIMEOUTS IN CALLBACKS IS NOT RECOMMENDED - YOU CAN GET A LOCK FOR THE TIMEOUT
|
|
||||||
*
|
|
||||||
* @param[in] itf Index of CDC interface
|
|
||||||
* @param[in] timeout_ticks Transfer timeout. Set to zero for non-blocking mode
|
|
||||||
* @return - ESP_OK All data flushed
|
|
||||||
* - ESP_ERR_TIMEOUT Time out occurred in blocking mode
|
|
||||||
* - ESP_NOT_FINISHED The transfer is still in progress in non-blocking mode
|
|
||||||
*/
|
|
||||||
esp_err_t tinyusb_cdcacm_write_flush(tinyusb_cdcacm_itf_t itf, uint32_t timeout_ticks);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Receive data from CDC interface
|
|
||||||
*
|
|
||||||
* @param[in] itf Index of CDC interface
|
|
||||||
* @param[out] out_buf Data buffer
|
|
||||||
* @param[in] out_buf_sz Data buffer size in bytes
|
|
||||||
* @param[out] rx_data_size Number of bytes written to out_buf
|
|
||||||
* @return esp_err_t ESP_OK, ESP_FAIL or ESP_ERR_INVALID_STATE
|
|
||||||
*/
|
|
||||||
esp_err_t tinyusb_cdcacm_read(tinyusb_cdcacm_itf_t itf, uint8_t *out_buf, size_t out_buf_sz, size_t *rx_data_size);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Check if the CDC interface is initialized
|
|
||||||
*
|
|
||||||
* @param[in] itf Index of CDC interface
|
|
||||||
* @return - true Initialized
|
|
||||||
* - false Not Initialized
|
|
||||||
*/
|
|
||||||
bool tusb_cdc_acm_initialized(tinyusb_cdcacm_itf_t itf);
|
|
||||||
|
|
||||||
/*********************************************************************** Public functions*/
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@ -1,155 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: 2019 Ha Thach (tinyusb.org),
|
|
||||||
* SPDX-FileContributor: 2020 Espressif Systems (Shanghai) CO LTD
|
|
||||||
* SPDX-License-Identifier: MIT
|
|
||||||
*
|
|
||||||
* Copyright (c) 2019 Ha Thach (tinyusb.org),
|
|
||||||
* Additions Copyright (c) 2020, Espressif Systems (Shanghai) PTE LTD
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "tusb_option.h"
|
|
||||||
#include "sdkconfig.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_TINYUSB_CDC_ENABLED
|
|
||||||
# define CONFIG_TINYUSB_CDC_ENABLED 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_TINYUSB_CDC_COUNT
|
|
||||||
# define CONFIG_TINYUSB_CDC_COUNT 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_TINYUSB_MSC_ENABLED
|
|
||||||
# define CONFIG_TINYUSB_MSC_ENABLED 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_TINYUSB_HID_COUNT
|
|
||||||
# define CONFIG_TINYUSB_HID_COUNT 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_TINYUSB_MIDI_COUNT
|
|
||||||
# define CONFIG_TINYUSB_MIDI_COUNT 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_TINYUSB_CUSTOM_CLASS_ENABLED
|
|
||||||
# define CONFIG_TINYUSB_CUSTOM_CLASS_ENABLED 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_TINYUSB_NET_MODE_ECM_RNDIS
|
|
||||||
# define CONFIG_TINYUSB_NET_MODE_ECM_RNDIS 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_TINYUSB_NET_MODE_NCM
|
|
||||||
# define CONFIG_TINYUSB_NET_MODE_NCM 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_TINYUSB_DFU_MODE_DFU
|
|
||||||
# define CONFIG_TINYUSB_DFU_MODE_DFU 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_TINYUSB_DFU_MODE_DFU_RUNTIME
|
|
||||||
# define CONFIG_TINYUSB_DFU_MODE_DFU_RUNTIME 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_TINYUSB_BTH_ENABLED
|
|
||||||
# define CONFIG_TINYUSB_BTH_ENABLED 0
|
|
||||||
# define CONFIG_TINYUSB_BTH_ISO_ALT_COUNT 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_TINYUSB_DEBUG_LEVEL
|
|
||||||
# define CONFIG_TINYUSB_DEBUG_LEVEL 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_TINYUSB_RHPORT_HS
|
|
||||||
# define CFG_TUSB_RHPORT1_MODE OPT_MODE_DEVICE | OPT_MODE_HIGH_SPEED
|
|
||||||
#else
|
|
||||||
# define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE | OPT_MODE_FULL_SPEED
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define CFG_TUSB_OS OPT_OS_FREERTOS
|
|
||||||
|
|
||||||
/* USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment.
|
|
||||||
* Tinyusb use follows macros to declare transferring memory so that they can be put
|
|
||||||
* into those specific section.
|
|
||||||
* e.g
|
|
||||||
* - CFG_TUSB_MEM SECTION : __attribute__ (( section(".usb_ram") ))
|
|
||||||
* - CFG_TUSB_MEM_ALIGN : __attribute__ ((aligned(4)))
|
|
||||||
*/
|
|
||||||
#ifndef CFG_TUSB_MEM_SECTION
|
|
||||||
# define CFG_TUSB_MEM_SECTION
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CFG_TUSB_MEM_ALIGN
|
|
||||||
# define CFG_TUSB_MEM_ALIGN TU_ATTR_ALIGNED(4)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CFG_TUD_ENDPOINT0_SIZE
|
|
||||||
#define CFG_TUD_ENDPOINT0_SIZE 64
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Debug Level
|
|
||||||
#define CFG_TUSB_DEBUG CONFIG_TINYUSB_DEBUG_LEVEL
|
|
||||||
|
|
||||||
// CDC FIFO size of TX and RX
|
|
||||||
#define CFG_TUD_CDC_RX_BUFSIZE CONFIG_TINYUSB_CDC_RX_BUFSIZE
|
|
||||||
#define CFG_TUD_CDC_TX_BUFSIZE CONFIG_TINYUSB_CDC_TX_BUFSIZE
|
|
||||||
|
|
||||||
// MSC Buffer size of Device Mass storage
|
|
||||||
#define CFG_TUD_MSC_BUFSIZE CONFIG_TINYUSB_MSC_BUFSIZE
|
|
||||||
|
|
||||||
// MIDI macros
|
|
||||||
#define CFG_TUD_MIDI_EP_BUFSIZE 64
|
|
||||||
#define CFG_TUD_MIDI_EPSIZE CFG_TUD_MIDI_EP_BUFSIZE
|
|
||||||
#define CFG_TUD_MIDI_RX_BUFSIZE 64
|
|
||||||
#define CFG_TUD_MIDI_TX_BUFSIZE 64
|
|
||||||
|
|
||||||
// Vendor FIFO size of TX and RX
|
|
||||||
// If not configured vendor endpoints will not be buffered
|
|
||||||
#define CFG_TUD_VENDOR_RX_BUFSIZE 64
|
|
||||||
#define CFG_TUD_VENDOR_TX_BUFSIZE 64
|
|
||||||
|
|
||||||
// DFU macros
|
|
||||||
#define CFG_TUD_DFU_XFER_BUFSIZE CONFIG_TINYUSB_DFU_BUFSIZE
|
|
||||||
|
|
||||||
// Number of BTH ISO alternatives
|
|
||||||
#define CFG_TUD_BTH_ISO_ALT_COUNT CONFIG_TINYUSB_BTH_ISO_ALT_COUNT
|
|
||||||
|
|
||||||
// Enabled device class driver
|
|
||||||
#define CFG_TUD_CDC CONFIG_TINYUSB_CDC_COUNT
|
|
||||||
#define CFG_TUD_MSC CONFIG_TINYUSB_MSC_ENABLED
|
|
||||||
#define CFG_TUD_HID CONFIG_TINYUSB_HID_COUNT
|
|
||||||
#define CFG_TUD_MIDI CONFIG_TINYUSB_MIDI_COUNT
|
|
||||||
#define CFG_TUD_CUSTOM_CLASS CONFIG_TINYUSB_CUSTOM_CLASS_ENABLED
|
|
||||||
#define CFG_TUD_ECM_RNDIS CONFIG_TINYUSB_NET_MODE_ECM_RNDIS
|
|
||||||
#define CFG_TUD_NCM CONFIG_TINYUSB_NET_MODE_NCM
|
|
||||||
#define CFG_TUD_DFU CONFIG_TINYUSB_DFU_MODE_DFU
|
|
||||||
#define CFG_TUD_DFU_RUNTIME CONFIG_TINYUSB_DFU_MODE_DFU_RUNTIME
|
|
||||||
#define CFG_TUD_BTH CONFIG_TINYUSB_BTH_ENABLED
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@ -1,33 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "esp_err.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Redirect output to the USB serial
|
|
||||||
* @param cdc_intf - interface number of TinyUSB's CDC
|
|
||||||
*
|
|
||||||
* @return esp_err_t - ESP_OK, ESP_FAIL or an error code
|
|
||||||
*/
|
|
||||||
esp_err_t esp_tusb_init_console(int cdc_intf);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Switch log to the default output
|
|
||||||
* @param cdc_intf - interface number of TinyUSB's CDC
|
|
||||||
*
|
|
||||||
* @return esp_err_t
|
|
||||||
*/
|
|
||||||
esp_err_t esp_tusb_deinit_console(int cdc_intf);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@ -1,188 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
#include "esp_err.h"
|
|
||||||
#include "wear_levelling.h"
|
|
||||||
#include "esp_vfs_fat.h"
|
|
||||||
#if SOC_SDMMC_HOST_SUPPORTED
|
|
||||||
#include "driver/sdmmc_host.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Data provided to the input of the `callback_mount_changed` and `callback_premount_changed` callback
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
bool is_mounted; /*!< Flag if storage is mounted or not */
|
|
||||||
} tinyusb_msc_event_mount_changed_data_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Types of MSC events
|
|
||||||
*/
|
|
||||||
typedef enum {
|
|
||||||
TINYUSB_MSC_EVENT_MOUNT_CHANGED, /*!< Event type AFTER mount/unmount operation is successfully finished */
|
|
||||||
TINYUSB_MSC_EVENT_PREMOUNT_CHANGED /*!< Event type BEFORE mount/unmount operation is started */
|
|
||||||
} tinyusb_msc_event_type_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Describes an event passing to the input of a callbacks
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
tinyusb_msc_event_type_t type; /*!< Event type */
|
|
||||||
union {
|
|
||||||
tinyusb_msc_event_mount_changed_data_t mount_changed_data; /*!< Data input of the callback */
|
|
||||||
};
|
|
||||||
} tinyusb_msc_event_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief MSC callback that is delivered whenever a specific event occurs.
|
|
||||||
*/
|
|
||||||
typedef void(*tusb_msc_callback_t)(tinyusb_msc_event_t *event);
|
|
||||||
|
|
||||||
#if SOC_SDMMC_HOST_SUPPORTED
|
|
||||||
/**
|
|
||||||
* @brief Configuration structure for sdmmc initialization
|
|
||||||
*
|
|
||||||
* User configurable parameters that are used while
|
|
||||||
* initializing the sdmmc media.
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
sdmmc_card_t *card; /*!< Pointer to sdmmc card configuration structure */
|
|
||||||
tusb_msc_callback_t callback_mount_changed; /*!< Pointer to the function callback that will be delivered AFTER mount/unmount operation is successfully finished */
|
|
||||||
tusb_msc_callback_t callback_premount_changed; /*!< Pointer to the function callback that will be delivered BEFORE mount/unmount operation is started */
|
|
||||||
const esp_vfs_fat_mount_config_t mount_config; /*!< FATFS mount config */
|
|
||||||
} tinyusb_msc_sdmmc_config_t;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Configuration structure for spiflash initialization
|
|
||||||
*
|
|
||||||
* User configurable parameters that are used while
|
|
||||||
* initializing the SPI Flash media.
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
wl_handle_t wl_handle; /*!< Pointer to spiflash wera-levelling handle */
|
|
||||||
tusb_msc_callback_t callback_mount_changed; /*!< Pointer to the function callback that will be delivered AFTER mount/unmount operation is successfully finished */
|
|
||||||
tusb_msc_callback_t callback_premount_changed; /*!< Pointer to the function callback that will be delivered BEFORE mount/unmount operation is started */
|
|
||||||
const esp_vfs_fat_mount_config_t mount_config; /*!< FATFS mount config */
|
|
||||||
} tinyusb_msc_spiflash_config_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Register storage type spiflash with tinyusb driver
|
|
||||||
*
|
|
||||||
* @param config pointer to the spiflash configuration
|
|
||||||
* @return esp_err_t
|
|
||||||
* - ESP_OK, if success;
|
|
||||||
* - ESP_ERR_NO_MEM, if there was no memory to allocate storage components;
|
|
||||||
*/
|
|
||||||
esp_err_t tinyusb_msc_storage_init_spiflash(const tinyusb_msc_spiflash_config_t *config);
|
|
||||||
|
|
||||||
#if SOC_SDMMC_HOST_SUPPORTED
|
|
||||||
/**
|
|
||||||
* @brief Register storage type sd-card with tinyusb driver
|
|
||||||
*
|
|
||||||
* @param config pointer to the sd card configuration
|
|
||||||
* @return esp_err_t
|
|
||||||
* - ESP_OK, if success;
|
|
||||||
* - ESP_ERR_NO_MEM, if there was no memory to allocate storage components;
|
|
||||||
*/
|
|
||||||
esp_err_t tinyusb_msc_storage_init_sdmmc(const tinyusb_msc_sdmmc_config_t *config);
|
|
||||||
#endif
|
|
||||||
/**
|
|
||||||
* @brief Deregister storage with tinyusb driver and frees the memory
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void tinyusb_msc_storage_deinit(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Register a callback invoking on MSC event. If the callback had been
|
|
||||||
* already registered, it will be overwritten
|
|
||||||
*
|
|
||||||
* @param event_type - type of registered event for a callback
|
|
||||||
* @param callback - callback function
|
|
||||||
* @return esp_err_t - ESP_OK or ESP_ERR_INVALID_ARG
|
|
||||||
*/
|
|
||||||
esp_err_t tinyusb_msc_register_callback(tinyusb_msc_event_type_t event_type,
|
|
||||||
tusb_msc_callback_t callback);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Unregister a callback invoking on MSC event.
|
|
||||||
*
|
|
||||||
* @param event_type - type of registered event for a callback
|
|
||||||
* @return esp_err_t - ESP_OK or ESP_ERR_INVALID_ARG
|
|
||||||
*/
|
|
||||||
esp_err_t tinyusb_msc_unregister_callback(tinyusb_msc_event_type_t event_type);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Mount the storage partition locally on the firmware application.
|
|
||||||
*
|
|
||||||
* Get the available drive number. Register spi flash partition.
|
|
||||||
* Connect POSIX and C standard library IO function with FATFS.
|
|
||||||
* Mounts the partition.
|
|
||||||
* This API is used by the firmware application. If the storage partition is
|
|
||||||
* mounted by this API, host (PC) can't access the storage via MSC.
|
|
||||||
* When this function is called from the tinyusb callback functions, care must be taken
|
|
||||||
* so as to make sure that user callbacks must be completed within a
|
|
||||||
* specific time. Otherwise, MSC device may re-appear again on Host.
|
|
||||||
*
|
|
||||||
* @param base_path path prefix where FATFS should be registered
|
|
||||||
* @return esp_err_t
|
|
||||||
* - ESP_OK, if success;
|
|
||||||
* - ESP_ERR_NOT_FOUND if the maximum count of volumes is already mounted
|
|
||||||
* - ESP_ERR_NO_MEM if not enough memory or too many VFSes already registered;
|
|
||||||
*/
|
|
||||||
esp_err_t tinyusb_msc_storage_mount(const char *base_path);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Unmount the storage partition from the firmware application.
|
|
||||||
*
|
|
||||||
* Unmount the partition. Unregister diskio driver.
|
|
||||||
* Unregister the SPI flash partition.
|
|
||||||
* Finally, Un-register FATFS from VFS.
|
|
||||||
* After this function is called, storage device can be seen (recognized) by host (PC).
|
|
||||||
* When this function is called from the tinyusb callback functions, care must be taken
|
|
||||||
* so as to make sure that user callbacks must be completed within a specific time.
|
|
||||||
* Otherwise, MSC device may not appear on Host.
|
|
||||||
*
|
|
||||||
* @return esp_err_t
|
|
||||||
* - ESP_OK on success
|
|
||||||
* - ESP_ERR_INVALID_STATE if FATFS is not registered in VFS
|
|
||||||
*/
|
|
||||||
esp_err_t tinyusb_msc_storage_unmount(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Get number of sectors in storage media
|
|
||||||
*
|
|
||||||
* @return usable size, in bytes
|
|
||||||
*/
|
|
||||||
uint32_t tinyusb_msc_storage_get_sector_count(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Get sector size of storage media
|
|
||||||
*
|
|
||||||
* @return sector count
|
|
||||||
*/
|
|
||||||
uint32_t tinyusb_msc_storage_get_sector_size(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Get status if storage media is exposed over USB to Host
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
* - true, if the storage media is exposed to Host
|
|
||||||
* - false, if the stoarge media is mounted on application (not exposed to Host)
|
|
||||||
*/
|
|
||||||
bool tinyusb_msc_storage_in_use_by_usb_host(void);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "esp_err.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This helper function creates and starts a task which wraps `tud_task()`.
|
|
||||||
*
|
|
||||||
* The wrapper function basically wraps tud_task and some log.
|
|
||||||
* Default parameters: stack size and priority as configured, argument = NULL, not pinned to any core.
|
|
||||||
* If you have more requirements for this task, you can create your own task which calls tud_task as the last step.
|
|
||||||
*
|
|
||||||
* @retval ESP_OK run tinyusb main task successfully
|
|
||||||
* @retval ESP_FAIL run tinyusb main task failed of internal error or initialization within the task failed when TINYUSB_INIT_IN_DEFAULT_TASK=y
|
|
||||||
* @retval ESP_FAIL initialization within the task failed if CONFIG_TINYUSB_INIT_IN_DEFAULT_TASK is enabled
|
|
||||||
* @retval ESP_ERR_INVALID_STATE tinyusb main task has been created before
|
|
||||||
*/
|
|
||||||
esp_err_t tusb_run_task(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This helper function stops and destroys the task created by `tusb_run_task()`
|
|
||||||
*
|
|
||||||
* @retval ESP_OK stop and destroy tinyusb main task successfully
|
|
||||||
* @retval ESP_ERR_INVALID_STATE tinyusb main task hasn't been created yet
|
|
||||||
*/
|
|
||||||
esp_err_t tusb_stop_task(void);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@ -1,69 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "esp_err.h"
|
|
||||||
#include "esp_vfs_common.h" // For esp_line_endings_t definitions
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define VFS_TUSB_MAX_PATH 16
|
|
||||||
#define VFS_TUSB_PATH_DEFAULT "/dev/tusb_cdc"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Register TinyUSB CDC at VFS with path
|
|
||||||
*
|
|
||||||
* Know limitation:
|
|
||||||
* In case there are multiple CDC interfaces in the system, only one of them can be registered to VFS.
|
|
||||||
*
|
|
||||||
* @param[in] cdc_intf Interface number of TinyUSB's CDC
|
|
||||||
* @param[in] path Path where the CDC will be registered, `/dev/tusb_cdc` will be used if left NULL.
|
|
||||||
* @return esp_err_t ESP_OK or ESP_FAIL
|
|
||||||
*/
|
|
||||||
esp_err_t esp_vfs_tusb_cdc_register(int cdc_intf, char const *path);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Unregister TinyUSB CDC from VFS
|
|
||||||
*
|
|
||||||
* @param[in] path Path where the CDC will be unregistered if NULL will be used `/dev/tusb_cdc`
|
|
||||||
* @return esp_err_t ESP_OK or ESP_FAIL
|
|
||||||
*/
|
|
||||||
esp_err_t esp_vfs_tusb_cdc_unregister(char const *path);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Set the line endings to sent
|
|
||||||
*
|
|
||||||
* This specifies the conversion between newlines ('\n', LF) on stdout and line
|
|
||||||
* endings sent:
|
|
||||||
*
|
|
||||||
* - ESP_LINE_ENDINGS_CRLF: convert LF to CRLF
|
|
||||||
* - ESP_LINE_ENDINGS_CR: convert LF to CR
|
|
||||||
* - ESP_LINE_ENDINGS_LF: no modification
|
|
||||||
*
|
|
||||||
* @param[in] mode line endings to send
|
|
||||||
*/
|
|
||||||
void esp_vfs_tusb_cdc_set_tx_line_endings(esp_line_endings_t mode);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Set the line endings expected to be received
|
|
||||||
*
|
|
||||||
* This specifies the conversion between line endings received and
|
|
||||||
* newlines ('\n', LF) passed into stdin:
|
|
||||||
*
|
|
||||||
* - ESP_LINE_ENDINGS_CRLF: convert CRLF to LF
|
|
||||||
* - ESP_LINE_ENDINGS_CR: convert CR to LF
|
|
||||||
* - ESP_LINE_ENDINGS_LF: no modification
|
|
||||||
*
|
|
||||||
* @param[in] mode line endings expected
|
|
||||||
*/
|
|
||||||
void esp_vfs_tusb_cdc_set_rx_line_endings(esp_line_endings_t mode);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@ -1,82 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include "freertos/FreeRTOS.h"
|
|
||||||
#include "freertos/semphr.h"
|
|
||||||
#include "freertos/timers.h"
|
|
||||||
#include "tusb.h"
|
|
||||||
#include "tinyusb_types.h"
|
|
||||||
|
|
||||||
/* CDC classification
|
|
||||||
********************************************************************* */
|
|
||||||
typedef enum {
|
|
||||||
TINYUSB_CDC_DATA = 0x00,
|
|
||||||
} cdc_data_sublcass_type_t; // CDC120 specification
|
|
||||||
|
|
||||||
/* Note:other classification is represented in the file components\tinyusb\tinyusb\src\class\cdc\cdc.h */
|
|
||||||
|
|
||||||
/*********************************************************************** CDC classification*/
|
|
||||||
/* Structs
|
|
||||||
********************************************************************* */
|
|
||||||
typedef struct {
|
|
||||||
tinyusb_usbdev_t usb_dev; /*!< USB device to set up */
|
|
||||||
tusb_class_code_t cdc_class; /*!< CDC device class : Communications or Data device */
|
|
||||||
union {
|
|
||||||
cdc_comm_sublcass_type_t comm_subclass; /*!< Communications device subclasses: ACM, ECM, etc. */
|
|
||||||
cdc_data_sublcass_type_t data_subclass; /*!< Data device has only one subclass.*/
|
|
||||||
} cdc_subclass; /*!< CDC device subclass according to Class Definitions for Communications Devices the CDC v.1.20 */
|
|
||||||
} tinyusb_config_cdc_t; /*!< Main configuration structure of a CDC device */
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
tinyusb_usbdev_t usb_dev; /*!< USB device used for the instance */
|
|
||||||
tusb_class_code_t type;
|
|
||||||
union {
|
|
||||||
cdc_comm_sublcass_type_t comm_subclass; /*!< Communications device subclasses: ACM, ECM, etc. */
|
|
||||||
cdc_data_sublcass_type_t data_subclass; /*!< Data device has only one subclass.*/
|
|
||||||
} cdc_subclass; /*!< CDC device subclass according to Class Definitions for Communications Devices the CDC v.1.20 */
|
|
||||||
void *subclass_obj; /*!< Dynamically allocated subclass specific object */
|
|
||||||
} esp_tusb_cdc_t;
|
|
||||||
/*********************************************************************** Structs*/
|
|
||||||
/* Functions
|
|
||||||
********************************************************************* */
|
|
||||||
/**
|
|
||||||
* @brief Initializing CDC basic object
|
|
||||||
* @param itf - number of a CDC object
|
|
||||||
* @param cfg - CDC configuration structure
|
|
||||||
*
|
|
||||||
* @return esp_err_t ESP_OK or ESP_FAIL
|
|
||||||
*/
|
|
||||||
esp_err_t tinyusb_cdc_init(int itf, const tinyusb_config_cdc_t *cfg);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief De-initializing CDC. Clean its objects
|
|
||||||
* @param itf - number of a CDC object
|
|
||||||
* @return esp_err_t ESP_OK, ESP_ERR_INVALID_ARG, ESP_ERR_INVALID_STATE
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
esp_err_t tinyusb_cdc_deinit(int itf);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Return interface of a CDC device
|
|
||||||
*
|
|
||||||
* @param itf_num
|
|
||||||
* @return esp_tusb_cdc_t* pointer to the interface or (NULL) on error
|
|
||||||
*/
|
|
||||||
esp_tusb_cdc_t *tinyusb_cdc_get_intf(int itf_num);
|
|
||||||
/*********************************************************************** Functions*/
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@ -1,47 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "tinyusb.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define USB_STRING_DESCRIPTOR_ARRAY_SIZE 8 // Max 8 string descriptors for a device. LANGID, Manufacturer, Product, Serial number + 4 user defined
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Parse tinyusb configuration and prepare the device configuration pointer list to configure tinyusb driver
|
|
||||||
*
|
|
||||||
* @attention All descriptors passed to this function must exist for the duration of USB device lifetime
|
|
||||||
*
|
|
||||||
* @param[in] config tinyusb stack specific configuration
|
|
||||||
* @retval ESP_ERR_INVALID_ARG Default configuration descriptor is provided only for CDC, MSC and NCM classes
|
|
||||||
* @retval ESP_ERR_NO_MEM Memory allocation error
|
|
||||||
* @retval ESP_OK Descriptors configured without error
|
|
||||||
*/
|
|
||||||
esp_err_t tinyusb_set_descriptors(const tinyusb_config_t *config);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Set specific string descriptor
|
|
||||||
*
|
|
||||||
* @attention The descriptor passed to this function must exist for the duration of USB device lifetime
|
|
||||||
*
|
|
||||||
* @param[in] str UTF-8 string
|
|
||||||
* @param[in] str_idx String descriptor index
|
|
||||||
*/
|
|
||||||
void tinyusb_set_str_descriptor(const char *str, int str_idx);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Free memory allocated during tinyusb_set_descriptors
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void tinyusb_free_descriptors(void);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "tusb.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Device descriptor generated from Kconfig
|
|
||||||
*
|
|
||||||
* This descriptor is used by default.
|
|
||||||
* The user can provide their own device descriptor via tinyusb_driver_install() call
|
|
||||||
*/
|
|
||||||
extern const tusb_desc_device_t descriptor_dev_default;
|
|
||||||
|
|
||||||
#if (TUD_OPT_HIGH_SPEED)
|
|
||||||
/**
|
|
||||||
* @brief Qualifier Device descriptor generated from Kconfig
|
|
||||||
*
|
|
||||||
* This descriptor is used by default.
|
|
||||||
* The user can provide their own descriptor via tinyusb_driver_install() call
|
|
||||||
*/
|
|
||||||
extern const tusb_desc_device_qualifier_t descriptor_qualifier_default;
|
|
||||||
#endif // TUD_OPT_HIGH_SPEED
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Array of string descriptors generated from Kconfig
|
|
||||||
*
|
|
||||||
* This descriptor is used by default.
|
|
||||||
* The user can provide their own descriptor via tinyusb_driver_install() call
|
|
||||||
*/
|
|
||||||
extern const char *descriptor_str_default[];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief FullSpeed configuration descriptor generated from Kconfig
|
|
||||||
* This descriptor is used by default.
|
|
||||||
* The user can provide their own FullSpeed configuration descriptor via tinyusb_driver_install() call
|
|
||||||
*/
|
|
||||||
extern const uint8_t descriptor_fs_cfg_default[];
|
|
||||||
|
|
||||||
#if (TUD_OPT_HIGH_SPEED)
|
|
||||||
/**
|
|
||||||
* @brief HighSpeed Configuration descriptor generated from Kconfig
|
|
||||||
*
|
|
||||||
* This descriptor is used by default.
|
|
||||||
* The user can provide their own HighSpeed configuration descriptor via tinyusb_driver_install() call
|
|
||||||
*/
|
|
||||||
extern const uint8_t descriptor_hs_cfg_default[];
|
|
||||||
#endif // TUD_OPT_HIGH_SPEED
|
|
||||||
|
|
||||||
uint8_t tusb_get_mac_string_id(void);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@ -1,2 +0,0 @@
|
|||||||
supplier: 'Organization: Espressif Systems (Shanghai) CO LTD'
|
|
||||||
originator: 'Organization: Espressif Systems (Shanghai) CO LTD'
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.22)
|
|
||||||
project(libusb_test
|
|
||||||
LANGUAGES C
|
|
||||||
)
|
|
||||||
|
|
||||||
add_executable(libusb_test libusb_test.c)
|
|
||||||
target_link_libraries(libusb_test -lusb-1.0)
|
|
||||||
|
|
||||||
@ -1,121 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <libusb-1.0/libusb.h>
|
|
||||||
|
|
||||||
#define TINYUSB_VENDOR 0x303A
|
|
||||||
#define TINYUSB_PRODUCT 0x4002
|
|
||||||
|
|
||||||
#define DESC_TYPE_DEVICE_QUALIFIER 0x06
|
|
||||||
#define DESC_TYOE_OTHER_SPEED_CONFIG 0x07
|
|
||||||
|
|
||||||
// Buffer for descriptor data
|
|
||||||
unsigned char buffer[512] = { 0 };
|
|
||||||
|
|
||||||
// USB Other Speed Configuration Descriptor
|
|
||||||
typedef struct __attribute__ ((packed))
|
|
||||||
{
|
|
||||||
uint8_t bLength ; ///< Size of descriptor
|
|
||||||
uint8_t bDescriptorType ; ///< Other_speed_Configuration Type
|
|
||||||
uint16_t wTotalLength ; ///< Total length of data returned
|
|
||||||
|
|
||||||
uint8_t bNumInterfaces ; ///< Number of interfaces supported by this speed configuration
|
|
||||||
uint8_t bConfigurationValue ; ///< Value to use to select configuration
|
|
||||||
uint8_t iConfiguration ; ///< Index of string descriptor
|
|
||||||
uint8_t bmAttributes ; ///< Same as Configuration descriptor
|
|
||||||
uint8_t bMaxPower ; ///< Same as Configuration descriptor
|
|
||||||
} desc_other_speed_t;
|
|
||||||
|
|
||||||
// USB Device Qualifier Descriptor
|
|
||||||
typedef struct __attribute__ ((packed))
|
|
||||||
{
|
|
||||||
uint8_t bLength ; ///< Size of descriptor
|
|
||||||
uint8_t bDescriptorType ; ///< Device Qualifier Type
|
|
||||||
uint16_t bcdUSB ; ///< USB specification version number (e.g., 0200H for V2.00)
|
|
||||||
|
|
||||||
uint8_t bDeviceClass ; ///< Class Code
|
|
||||||
uint8_t bDeviceSubClass ; ///< SubClass Code
|
|
||||||
uint8_t bDeviceProtocol ; ///< Protocol Code
|
|
||||||
|
|
||||||
uint8_t bMaxPacketSize0 ; ///< Maximum packet size for other speed
|
|
||||||
uint8_t bNumConfigurations ; ///< Number of Other-speed Configurations
|
|
||||||
uint8_t bReserved ; ///< Reserved for future use, must be zero
|
|
||||||
} desc_device_qualifier_t;
|
|
||||||
|
|
||||||
// printf helpers
|
|
||||||
static void _print_device_qulifier_desc(unsigned char *buffer, int length);
|
|
||||||
static void _print_other_speed_desc(unsigned char *buffer, int length);
|
|
||||||
|
|
||||||
//
|
|
||||||
// MAIN
|
|
||||||
//
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
libusb_context *context = NULL;
|
|
||||||
int rc = 0;
|
|
||||||
|
|
||||||
rc = libusb_init(&context);
|
|
||||||
assert(rc == 0);
|
|
||||||
libusb_device_handle *dev_handle = libusb_open_device_with_vid_pid(context,
|
|
||||||
TINYUSB_VENDOR,
|
|
||||||
TINYUSB_PRODUCT);
|
|
||||||
|
|
||||||
if (dev_handle != NULL) {
|
|
||||||
printf("TinyUSB Device has been found\n");
|
|
||||||
|
|
||||||
// Test Qualifier Descriprtor
|
|
||||||
// 1. Get Qualifier Descriptor
|
|
||||||
// 2. print descriptor data
|
|
||||||
rc = libusb_get_descriptor(dev_handle, DESC_TYPE_DEVICE_QUALIFIER, 0, buffer, 512);
|
|
||||||
_print_device_qulifier_desc(buffer, rc);
|
|
||||||
|
|
||||||
// Test Other Speed Descriptor
|
|
||||||
// 1. Get Other Speed Descriptor
|
|
||||||
// 2. print descriptor data
|
|
||||||
rc = libusb_get_descriptor(dev_handle, DESC_TYOE_OTHER_SPEED_CONFIG, 0, buffer, 512);
|
|
||||||
_print_other_speed_desc(buffer, rc);
|
|
||||||
|
|
||||||
libusb_close(dev_handle);
|
|
||||||
} else {
|
|
||||||
printf("TinyUSB Device has NOT been found\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
libusb_exit(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// =============================================================================
|
|
||||||
static void _print_device_qulifier_desc(unsigned char *buffer, int length)
|
|
||||||
{
|
|
||||||
assert(buffer);
|
|
||||||
desc_device_qualifier_t *qualifier_desc = (desc_device_qualifier_t *) buffer;
|
|
||||||
printf("========= Device Qualifier ========== \n");
|
|
||||||
printf("\t bLength: %d \n", qualifier_desc->bLength);
|
|
||||||
printf("\t bDescriptorType: %d (%#x)\n", qualifier_desc->bDescriptorType, qualifier_desc->bDescriptorType);
|
|
||||||
printf("\t bcdUSB: %d (%#x) \n", qualifier_desc->bcdUSB, qualifier_desc->bcdUSB);
|
|
||||||
printf("\t bDeviceClass: %d (%#x) \n", qualifier_desc->bDeviceClass, qualifier_desc->bDeviceClass);
|
|
||||||
printf("\t bDeviceSubClass: %d \n", qualifier_desc->bDeviceSubClass);
|
|
||||||
printf("\t bDeviceProtocol: %d \n", qualifier_desc->bDeviceProtocol);
|
|
||||||
printf("\t bMaxPacketSize0: %d \n", qualifier_desc->bMaxPacketSize0);
|
|
||||||
printf("\t bNumConfigurations: %d \n", qualifier_desc->bNumConfigurations);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _print_other_speed_desc(unsigned char *buffer, int length)
|
|
||||||
{
|
|
||||||
assert(buffer);
|
|
||||||
desc_other_speed_t *other_speed = (desc_other_speed_t *) buffer;
|
|
||||||
printf("============ Other Speed ============ \n");
|
|
||||||
printf("\t bLength: %d \n", other_speed->bLength);
|
|
||||||
printf("\t bDescriptorType: %d (%#x) \n", other_speed->bDescriptorType, other_speed->bDescriptorType);
|
|
||||||
printf("\t wTotalLength: %d \n", other_speed->wTotalLength);
|
|
||||||
printf("\t bNumInterfaces: %d \n", other_speed->bNumInterfaces);
|
|
||||||
printf("\t bConfigurationValue: %d \n", other_speed->bConfigurationValue);
|
|
||||||
printf("\t iConfiguration: %d \n", other_speed->iConfiguration);
|
|
||||||
printf("\t bmAttributes: %d (%#x) \n", other_speed->bmAttributes, other_speed->bmAttributes);
|
|
||||||
printf("\t bMaxPower: %d (%#x) \n", other_speed->bMaxPower, other_speed->bMaxPower);
|
|
||||||
}
|
|
||||||
@ -1,11 +0,0 @@
|
|||||||
# 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.16)
|
|
||||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
|
||||||
|
|
||||||
# Set the components to include the tests for.
|
|
||||||
set(EXTRA_COMPONENT_DIRS
|
|
||||||
../
|
|
||||||
)
|
|
||||||
|
|
||||||
project(test_app_usb_device_esp_tinyusb)
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
| Supported Targets | ESP32-S2 | ESP32-S3 |
|
|
||||||
| ----------------- | -------- | -------- |
|
|
||||||
|
|
||||||
# USB: esp_tinyusb test application
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
include($ENV{IDF_PATH}/tools/cmake/version.cmake)
|
|
||||||
|
|
||||||
idf_component_register(SRC_DIRS .
|
|
||||||
INCLUDE_DIRS .
|
|
||||||
REQUIRES unity esp_tinyusb
|
|
||||||
WHOLE_ARCHIVE)
|
|
||||||
@ -1,7 +0,0 @@
|
|||||||
## IDF Component Manager Manifest File
|
|
||||||
dependencies:
|
|
||||||
espressif/esp_tinyusb:
|
|
||||||
version: "*"
|
|
||||||
override_path: "../../"
|
|
||||||
rules:
|
|
||||||
- if: "idf_version >= 5.0"
|
|
||||||
@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "unity.h"
|
|
||||||
#include "esp_heap_caps.h"
|
|
||||||
|
|
||||||
static size_t before_free_8bit;
|
|
||||||
static size_t before_free_32bit;
|
|
||||||
|
|
||||||
#define TEST_MEMORY_LEAK_THRESHOLD (-530)
|
|
||||||
static void check_leak(size_t before_free, size_t after_free, const char *type)
|
|
||||||
{
|
|
||||||
ssize_t delta = after_free - before_free;
|
|
||||||
printf("MALLOC_CAP_%s: Before %u bytes free, After %u bytes free (delta %d)\n", type, before_free, after_free, delta);
|
|
||||||
TEST_ASSERT_MESSAGE(delta >= TEST_MEMORY_LEAK_THRESHOLD, "memory leak");
|
|
||||||
}
|
|
||||||
|
|
||||||
void app_main(void)
|
|
||||||
{
|
|
||||||
// ____ ___ ___________________ __ __
|
|
||||||
// | | \/ _____/\______ \ _/ |_ ____ _______/ |_
|
|
||||||
// | | /\_____ \ | | _/ \ __\/ __ \ / ___/\ __\.
|
|
||||||
// | | / / \ | | \ | | \ ___/ \___ \ | |
|
|
||||||
// |______/ /_______ / |______ / |__| \___ >____ > |__|
|
|
||||||
// \/ \/ \/ \/
|
|
||||||
printf(" ____ ___ ___________________ __ __ \r\n");
|
|
||||||
printf("| | \\/ _____/\\______ \\ _/ |_ ____ _______/ |_ \r\n");
|
|
||||||
printf("| | /\\_____ \\ | | _/ \\ __\\/ __ \\ / ___/\\ __\\\r\n");
|
|
||||||
printf("| | / / \\ | | \\ | | \\ ___/ \\___ \\ | | \r\n");
|
|
||||||
printf("|______/ /_______ / |______ / |__| \\___ >____ > |__| \r\n");
|
|
||||||
printf(" \\/ \\/ \\/ \\/ \r\n");
|
|
||||||
|
|
||||||
UNITY_BEGIN();
|
|
||||||
unity_run_menu();
|
|
||||||
UNITY_END();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* setUp runs before every test */
|
|
||||||
void setUp(void)
|
|
||||||
{
|
|
||||||
before_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
|
|
||||||
before_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* tearDown runs after every test */
|
|
||||||
void tearDown(void)
|
|
||||||
{
|
|
||||||
size_t after_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
|
|
||||||
size_t after_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
|
|
||||||
check_leak(before_free_8bit, after_free_8bit, "8BIT");
|
|
||||||
check_leak(before_free_32bit, after_free_32bit, "32BIT");
|
|
||||||
}
|
|
||||||
@ -1,103 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "soc/soc_caps.h"
|
|
||||||
|
|
||||||
#if SOC_USB_OTG_SUPPORTED
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "esp_system.h"
|
|
||||||
#include "freertos/FreeRTOS.h"
|
|
||||||
#include "freertos/task.h"
|
|
||||||
#include "esp_log.h"
|
|
||||||
#include "esp_err.h"
|
|
||||||
#include "driver/gpio.h"
|
|
||||||
#include "esp_rom_gpio.h"
|
|
||||||
#include "soc/gpio_sig_map.h"
|
|
||||||
#include "unity.h"
|
|
||||||
#include "tinyusb.h"
|
|
||||||
#include "tusb_tasks.h"
|
|
||||||
|
|
||||||
#define DEVICE_DETACH_TEST_ROUNDS 10
|
|
||||||
#define DEVICE_DETACH_ROUND_DELAY_MS 1000
|
|
||||||
|
|
||||||
#if (CONFIG_IDF_TARGET_ESP32P4)
|
|
||||||
#define USB_SRP_BVALID_IN_IDX USB_SRP_BVALID_PAD_IN_IDX
|
|
||||||
#endif // CONFIG_IDF_TARGET_ESP32P4
|
|
||||||
|
|
||||||
/* TinyUSB descriptors
|
|
||||||
********************************************************************* */
|
|
||||||
#define TUSB_DESC_TOTAL_LEN (TUD_CONFIG_DESC_LEN)
|
|
||||||
|
|
||||||
static unsigned int dev_mounted = 0;
|
|
||||||
static unsigned int dev_umounted = 0;
|
|
||||||
|
|
||||||
static uint8_t const test_configuration_descriptor[] = {
|
|
||||||
// Config number, interface count, string index, total length, attribute, power in mA
|
|
||||||
TUD_CONFIG_DESCRIPTOR(1, 0, 0, TUSB_DESC_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_SELF_POWERED | TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
|
|
||||||
};
|
|
||||||
|
|
||||||
static const tusb_desc_device_t test_device_descriptor = {
|
|
||||||
.bLength = sizeof(test_device_descriptor),
|
|
||||||
.bDescriptorType = TUSB_DESC_DEVICE,
|
|
||||||
.bcdUSB = 0x0200,
|
|
||||||
.bDeviceClass = TUSB_CLASS_MISC,
|
|
||||||
.bDeviceSubClass = MISC_SUBCLASS_COMMON,
|
|
||||||
.bDeviceProtocol = MISC_PROTOCOL_IAD,
|
|
||||||
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
|
|
||||||
.idVendor = 0x303A, // This is Espressif VID. This needs to be changed according to Users / Customers
|
|
||||||
.idProduct = 0x4002,
|
|
||||||
.bcdDevice = 0x100,
|
|
||||||
.iManufacturer = 0x01,
|
|
||||||
.iProduct = 0x02,
|
|
||||||
.iSerialNumber = 0x03,
|
|
||||||
.bNumConfigurations = 0x01
|
|
||||||
};
|
|
||||||
|
|
||||||
void test_bvalid_sig_mount_cb(void)
|
|
||||||
{
|
|
||||||
dev_mounted++;
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_bvalid_sig_umount_cb(void)
|
|
||||||
{
|
|
||||||
dev_umounted++;
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("bvalid_signal", "[esp_tinyusb][usb_device]")
|
|
||||||
{
|
|
||||||
unsigned int rounds = DEVICE_DETACH_TEST_ROUNDS;
|
|
||||||
|
|
||||||
// Install TinyUSB driver
|
|
||||||
const tinyusb_config_t tusb_cfg = {
|
|
||||||
.external_phy = false,
|
|
||||||
.device_descriptor = &test_device_descriptor,
|
|
||||||
.configuration_descriptor = test_configuration_descriptor,
|
|
||||||
};
|
|
||||||
TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_install(&tusb_cfg));
|
|
||||||
|
|
||||||
dev_mounted = 0;
|
|
||||||
dev_umounted = 0;
|
|
||||||
|
|
||||||
while (rounds--) {
|
|
||||||
// LOW to emulate disconnect USB device
|
|
||||||
esp_rom_gpio_connect_in_signal(GPIO_MATRIX_CONST_ZERO_INPUT, USB_SRP_BVALID_IN_IDX, false);
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(DEVICE_DETACH_ROUND_DELAY_MS));
|
|
||||||
// HIGH to emulate connect USB device
|
|
||||||
esp_rom_gpio_connect_in_signal(GPIO_MATRIX_CONST_ONE_INPUT, USB_SRP_BVALID_IN_IDX, false);
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(DEVICE_DETACH_ROUND_DELAY_MS));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify
|
|
||||||
TEST_ASSERT_EQUAL(dev_umounted, dev_mounted);
|
|
||||||
TEST_ASSERT_EQUAL(DEVICE_DETACH_TEST_ROUNDS, dev_mounted);
|
|
||||||
|
|
||||||
// Cleanup
|
|
||||||
TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_uninstall());
|
|
||||||
TEST_ASSERT_EQUAL(ESP_OK, tusb_stop_task());
|
|
||||||
}
|
|
||||||
#endif // SOC_USB_OTG_SUPPORTED
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void test_bvalid_sig_mount_cb(void);
|
|
||||||
void test_bvalid_sig_umount_cb(void);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif //__cplusplus
|
|
||||||
@ -1,235 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "soc/soc_caps.h"
|
|
||||||
|
|
||||||
#if SOC_USB_OTG_SUPPORTED
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "esp_system.h"
|
|
||||||
#include "esp_err.h"
|
|
||||||
#include "freertos/FreeRTOS.h"
|
|
||||||
#include "freertos/task.h"
|
|
||||||
#include "freertos/semphr.h"
|
|
||||||
#include "esp_log.h"
|
|
||||||
#include "esp_err.h"
|
|
||||||
#include "driver/gpio.h"
|
|
||||||
#include "esp_rom_gpio.h"
|
|
||||||
#include "soc/gpio_sig_map.h"
|
|
||||||
#include "unity.h"
|
|
||||||
#include "tinyusb.h"
|
|
||||||
#include "tusb_tasks.h"
|
|
||||||
|
|
||||||
#define DEVICE_MOUNT_TIMEOUT_MS 5000
|
|
||||||
|
|
||||||
// ========================= TinyUSB descriptors ===============================
|
|
||||||
#define TUSB_DESC_TOTAL_LEN (TUD_CONFIG_DESC_LEN)
|
|
||||||
|
|
||||||
static uint8_t const test_fs_configuration_descriptor[] = {
|
|
||||||
// Config number, interface count, string index, total length, attribute, power in mA
|
|
||||||
TUD_CONFIG_DESCRIPTOR(1, 0, 0, TUSB_DESC_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_SELF_POWERED | TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
|
|
||||||
};
|
|
||||||
|
|
||||||
#if (TUD_OPT_HIGH_SPEED)
|
|
||||||
static uint8_t const test_hs_configuration_descriptor[] = {
|
|
||||||
// Config number, interface count, string index, total length, attribute, power in mA
|
|
||||||
TUD_CONFIG_DESCRIPTOR(1, 0, 0, TUSB_DESC_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_SELF_POWERED | TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
|
|
||||||
};
|
|
||||||
#endif // TUD_OPT_HIGH_SPEED
|
|
||||||
|
|
||||||
static const tusb_desc_device_t test_device_descriptor = {
|
|
||||||
.bLength = sizeof(test_device_descriptor),
|
|
||||||
.bDescriptorType = TUSB_DESC_DEVICE,
|
|
||||||
.bcdUSB = 0x0200,
|
|
||||||
.bDeviceClass = TUSB_CLASS_MISC,
|
|
||||||
.bDeviceSubClass = MISC_SUBCLASS_COMMON,
|
|
||||||
.bDeviceProtocol = MISC_PROTOCOL_IAD,
|
|
||||||
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
|
|
||||||
.idVendor = 0x303A, // This is Espressif VID. This needs to be changed according to Users / Customers
|
|
||||||
.idProduct = 0x4002,
|
|
||||||
.bcdDevice = 0x100,
|
|
||||||
.iManufacturer = 0x01,
|
|
||||||
.iProduct = 0x02,
|
|
||||||
.iSerialNumber = 0x03,
|
|
||||||
.bNumConfigurations = 0x01
|
|
||||||
};
|
|
||||||
|
|
||||||
// ========================== Private logic ====================================
|
|
||||||
SemaphoreHandle_t desc_config_device_mounted = NULL;
|
|
||||||
|
|
||||||
static bool __test_prep(void)
|
|
||||||
{
|
|
||||||
desc_config_device_mounted = xSemaphoreCreateBinary();
|
|
||||||
return (desc_config_device_mounted != NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static esp_err_t __test_wait_conn(void)
|
|
||||||
{
|
|
||||||
if (!desc_config_device_mounted) {
|
|
||||||
return ESP_ERR_INVALID_STATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ( xSemaphoreTake(desc_config_device_mounted, pdMS_TO_TICKS(DEVICE_MOUNT_TIMEOUT_MS))
|
|
||||||
? ESP_OK
|
|
||||||
: ESP_ERR_TIMEOUT );
|
|
||||||
}
|
|
||||||
|
|
||||||
static void __test_conn(void)
|
|
||||||
{
|
|
||||||
if (desc_config_device_mounted) {
|
|
||||||
xSemaphoreGive(desc_config_device_mounted);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void __test_free(void)
|
|
||||||
{
|
|
||||||
if (desc_config_device_mounted) {
|
|
||||||
vSemaphoreDelete(desc_config_device_mounted);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ========================== Callbacks ========================================
|
|
||||||
// Invoked when device is mounted
|
|
||||||
void test_descriptors_config_mount_cb(void)
|
|
||||||
{
|
|
||||||
__test_conn();
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_descriptors_config_umount_cb(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("descriptors_config_all_default", "[esp_tinyusb][usb_device]")
|
|
||||||
{
|
|
||||||
TEST_ASSERT_EQUAL(true, __test_prep());
|
|
||||||
// Install TinyUSB driver
|
|
||||||
const tinyusb_config_t tusb_cfg = {
|
|
||||||
.external_phy = false,
|
|
||||||
.device_descriptor = NULL,
|
|
||||||
.configuration_descriptor = NULL,
|
|
||||||
#if (TUD_OPT_HIGH_SPEED)
|
|
||||||
.hs_configuration_descriptor = NULL,
|
|
||||||
#endif // TUD_OPT_HIGH_SPEED
|
|
||||||
};
|
|
||||||
// Install
|
|
||||||
TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_install(&tusb_cfg));
|
|
||||||
// Wait for mounted callback
|
|
||||||
TEST_ASSERT_EQUAL(ESP_OK, __test_wait_conn());
|
|
||||||
// Cleanup
|
|
||||||
TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_uninstall());
|
|
||||||
TEST_ASSERT_EQUAL(ESP_OK, tusb_stop_task());
|
|
||||||
__test_free();
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("descriptors_config_device", "[esp_tinyusb][usb_device]")
|
|
||||||
{
|
|
||||||
TEST_ASSERT_EQUAL(true, __test_prep());
|
|
||||||
// Install TinyUSB driver
|
|
||||||
const tinyusb_config_t tusb_cfg = {
|
|
||||||
.external_phy = false,
|
|
||||||
.device_descriptor = &test_device_descriptor,
|
|
||||||
.configuration_descriptor = NULL,
|
|
||||||
#if (TUD_OPT_HIGH_SPEED)
|
|
||||||
.hs_configuration_descriptor = NULL,
|
|
||||||
#endif // TUD_OPT_HIGH_SPEED
|
|
||||||
};
|
|
||||||
// Install
|
|
||||||
TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_install(&tusb_cfg));
|
|
||||||
// Wait for mounted callback
|
|
||||||
TEST_ASSERT_EQUAL(ESP_OK, __test_wait_conn());
|
|
||||||
// Cleanup
|
|
||||||
TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_uninstall());
|
|
||||||
TEST_ASSERT_EQUAL(ESP_OK, tusb_stop_task());
|
|
||||||
__test_free();
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("descriptors_config_device_and_config", "[esp_tinyusb][usb_device]")
|
|
||||||
{
|
|
||||||
TEST_ASSERT_EQUAL(true, __test_prep());
|
|
||||||
// Install TinyUSB driver
|
|
||||||
const tinyusb_config_t tusb_cfg = {
|
|
||||||
.external_phy = false,
|
|
||||||
.device_descriptor = &test_device_descriptor,
|
|
||||||
.configuration_descriptor = test_fs_configuration_descriptor,
|
|
||||||
#if (TUD_OPT_HIGH_SPEED)
|
|
||||||
.hs_configuration_descriptor = NULL,
|
|
||||||
#endif // TUD_OPT_HIGH_SPEED
|
|
||||||
};
|
|
||||||
// Install
|
|
||||||
TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_install(&tusb_cfg));
|
|
||||||
// Wait for mounted callback
|
|
||||||
TEST_ASSERT_EQUAL(ESP_OK, __test_wait_conn());
|
|
||||||
// Cleanup
|
|
||||||
TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_uninstall());
|
|
||||||
TEST_ASSERT_EQUAL(ESP_OK, tusb_stop_task());
|
|
||||||
__test_free();
|
|
||||||
}
|
|
||||||
|
|
||||||
#if (TUD_OPT_HIGH_SPEED)
|
|
||||||
TEST_CASE("descriptors_config_device_and_fs_config_only", "[esp_tinyusb][usb_device]")
|
|
||||||
{
|
|
||||||
TEST_ASSERT_EQUAL(true, __test_prep());
|
|
||||||
// Install TinyUSB driver
|
|
||||||
const tinyusb_config_t tusb_cfg = {
|
|
||||||
.external_phy = false,
|
|
||||||
.device_descriptor = &test_device_descriptor,
|
|
||||||
.configuration_descriptor = test_fs_configuration_descriptor,
|
|
||||||
.hs_configuration_descriptor = NULL,
|
|
||||||
};
|
|
||||||
// Install
|
|
||||||
TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_install(&tusb_cfg));
|
|
||||||
// Wait for mounted callback
|
|
||||||
TEST_ASSERT_EQUAL(ESP_OK, __test_wait_conn());
|
|
||||||
// Cleanup
|
|
||||||
TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_uninstall());
|
|
||||||
TEST_ASSERT_EQUAL(ESP_OK, tusb_stop_task());
|
|
||||||
__test_free();
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("descriptors_config_device_and_hs_config_only", "[esp_tinyusb][usb_device]")
|
|
||||||
{
|
|
||||||
TEST_ASSERT_EQUAL(true, __test_prep());
|
|
||||||
// Install TinyUSB driver
|
|
||||||
const tinyusb_config_t tusb_cfg = {
|
|
||||||
.external_phy = false,
|
|
||||||
.device_descriptor = &test_device_descriptor,
|
|
||||||
.configuration_descriptor = NULL,
|
|
||||||
.hs_configuration_descriptor = test_hs_configuration_descriptor,
|
|
||||||
};
|
|
||||||
// Install
|
|
||||||
TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_install(&tusb_cfg));
|
|
||||||
// Wait for mounted callback
|
|
||||||
TEST_ASSERT_EQUAL(ESP_OK, __test_wait_conn());
|
|
||||||
// Cleanup
|
|
||||||
TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_uninstall());
|
|
||||||
TEST_ASSERT_EQUAL(ESP_OK, tusb_stop_task());
|
|
||||||
__test_free();
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("descriptors_config_all_configured", "[esp_tinyusb][usb_device]")
|
|
||||||
{
|
|
||||||
TEST_ASSERT_EQUAL(true, __test_prep());
|
|
||||||
// Install TinyUSB driver
|
|
||||||
const tinyusb_config_t tusb_cfg = {
|
|
||||||
.external_phy = false,
|
|
||||||
.device_descriptor = &test_device_descriptor,
|
|
||||||
.fs_configuration_descriptor = test_fs_configuration_descriptor,
|
|
||||||
.hs_configuration_descriptor = test_hs_configuration_descriptor,
|
|
||||||
};
|
|
||||||
// Install
|
|
||||||
TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_install(&tusb_cfg));
|
|
||||||
// Wait for mounted callback
|
|
||||||
TEST_ASSERT_EQUAL(ESP_OK, __test_wait_conn());
|
|
||||||
// Cleanup
|
|
||||||
TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_uninstall());
|
|
||||||
TEST_ASSERT_EQUAL(ESP_OK, tusb_stop_task());
|
|
||||||
__test_free();
|
|
||||||
}
|
|
||||||
#endif // TUD_OPT_HIGH_SPEED
|
|
||||||
|
|
||||||
#endif // SOC_USB_OTG_SUPPORTED
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void test_descriptors_config_mount_cb(void);
|
|
||||||
void test_descriptors_config_umount_cb(void);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif //__cplusplus
|
|
||||||
@ -1,132 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "soc/soc_caps.h"
|
|
||||||
#if SOC_USB_OTG_SUPPORTED
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "esp_system.h"
|
|
||||||
#include "freertos/FreeRTOS.h"
|
|
||||||
#include "freertos/task.h"
|
|
||||||
#include "esp_log.h"
|
|
||||||
#include "esp_err.h"
|
|
||||||
|
|
||||||
#include "unity.h"
|
|
||||||
#include "tinyusb.h"
|
|
||||||
#include "tusb_cdc_acm.h"
|
|
||||||
#include "vfs_tinyusb.h"
|
|
||||||
|
|
||||||
#define VFS_PATH "/dev/usb-cdc1"
|
|
||||||
|
|
||||||
// idf_component_register(WHOLE_ARCHIVE) backward compatibility to IDF_v4.4
|
|
||||||
void linker_hook(void) {};
|
|
||||||
|
|
||||||
static const tusb_desc_device_t cdc_device_descriptor = {
|
|
||||||
.bLength = sizeof(cdc_device_descriptor),
|
|
||||||
.bDescriptorType = TUSB_DESC_DEVICE,
|
|
||||||
.bcdUSB = 0x0200,
|
|
||||||
.bDeviceClass = TUSB_CLASS_MISC,
|
|
||||||
.bDeviceSubClass = MISC_SUBCLASS_COMMON,
|
|
||||||
.bDeviceProtocol = MISC_PROTOCOL_IAD,
|
|
||||||
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
|
|
||||||
.idVendor = USB_ESPRESSIF_VID,
|
|
||||||
.idProduct = 0x4002,
|
|
||||||
.bcdDevice = 0x0100,
|
|
||||||
.iManufacturer = 0x01,
|
|
||||||
.iProduct = 0x02,
|
|
||||||
.iSerialNumber = 0x03,
|
|
||||||
.bNumConfigurations = 0x01
|
|
||||||
};
|
|
||||||
|
|
||||||
static const uint16_t cdc_desc_config_len = TUD_CONFIG_DESC_LEN + CFG_TUD_CDC * TUD_CDC_DESC_LEN;
|
|
||||||
static const uint8_t cdc_desc_configuration[] = {
|
|
||||||
TUD_CONFIG_DESCRIPTOR(1, 4, 0, cdc_desc_config_len, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
|
|
||||||
TUD_CDC_DESCRIPTOR(0, 4, 0x81, 8, 0x02, 0x82, 64),
|
|
||||||
TUD_CDC_DESCRIPTOR(2, 4, 0x83, 8, 0x04, 0x84, 64),
|
|
||||||
};
|
|
||||||
|
|
||||||
static void tinyusb_cdc_rx_callback(int itf, cdcacm_event_t *event)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief TinyUSB CDC testcase
|
|
||||||
*
|
|
||||||
* This is not a 'standard' testcase, as it never exits. The testcase runs in a loop where it echoes back all the data received.
|
|
||||||
*
|
|
||||||
* - Init TinyUSB with standard CDC device and configuration descriptors
|
|
||||||
* - Init 2 CDC-ACM interfaces
|
|
||||||
* - Map CDC1 to Virtual File System
|
|
||||||
* - In a loop: Read data from CDC0 and CDC1. Echo received data back
|
|
||||||
*
|
|
||||||
* Note: CDC0 appends 'novfs' to echoed data, so the host (test runner) can easily determine which port is which.
|
|
||||||
*/
|
|
||||||
TEST_CASE("tinyusb_cdc", "[esp_tinyusb]")
|
|
||||||
{
|
|
||||||
// Install TinyUSB driver
|
|
||||||
const tinyusb_config_t tusb_cfg = {
|
|
||||||
.external_phy = false,
|
|
||||||
.device_descriptor = &cdc_device_descriptor,
|
|
||||||
.configuration_descriptor = cdc_desc_configuration
|
|
||||||
};
|
|
||||||
TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_install(&tusb_cfg));
|
|
||||||
|
|
||||||
tinyusb_config_cdcacm_t acm_cfg = {
|
|
||||||
.usb_dev = TINYUSB_USBDEV_0,
|
|
||||||
.cdc_port = TINYUSB_CDC_ACM_0,
|
|
||||||
.rx_unread_buf_sz = 64,
|
|
||||||
.callback_rx = &tinyusb_cdc_rx_callback,
|
|
||||||
.callback_rx_wanted_char = NULL,
|
|
||||||
.callback_line_state_changed = NULL,
|
|
||||||
.callback_line_coding_changed = NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
// Init CDC 0
|
|
||||||
TEST_ASSERT_FALSE(tusb_cdc_acm_initialized(TINYUSB_CDC_ACM_0));
|
|
||||||
TEST_ASSERT_EQUAL(ESP_OK, tusb_cdc_acm_init(&acm_cfg));
|
|
||||||
TEST_ASSERT_TRUE(tusb_cdc_acm_initialized(TINYUSB_CDC_ACM_0));
|
|
||||||
|
|
||||||
// Init CDC 1
|
|
||||||
acm_cfg.cdc_port = TINYUSB_CDC_ACM_1;
|
|
||||||
acm_cfg.callback_rx = NULL;
|
|
||||||
TEST_ASSERT_FALSE(tusb_cdc_acm_initialized(TINYUSB_CDC_ACM_1));
|
|
||||||
TEST_ASSERT_EQUAL(ESP_OK, tusb_cdc_acm_init(&acm_cfg));
|
|
||||||
TEST_ASSERT_TRUE(tusb_cdc_acm_initialized(TINYUSB_CDC_ACM_1));
|
|
||||||
|
|
||||||
// Install VFS to CDC 1
|
|
||||||
TEST_ASSERT_EQUAL(ESP_OK, esp_vfs_tusb_cdc_register(TINYUSB_CDC_ACM_1, VFS_PATH));
|
|
||||||
esp_vfs_tusb_cdc_set_rx_line_endings(ESP_LINE_ENDINGS_CRLF);
|
|
||||||
esp_vfs_tusb_cdc_set_tx_line_endings(ESP_LINE_ENDINGS_LF);
|
|
||||||
FILE *cdc = fopen(VFS_PATH, "r+");
|
|
||||||
TEST_ASSERT_NOT_NULL(cdc);
|
|
||||||
|
|
||||||
uint8_t buf[CONFIG_TINYUSB_CDC_RX_BUFSIZE + 1];
|
|
||||||
while (true) {
|
|
||||||
size_t b = fread(buf, 1, sizeof(buf), cdc);
|
|
||||||
if (b > 0) {
|
|
||||||
printf("Intf VFS, RX %d bytes\n", b);
|
|
||||||
//ESP_LOG_BUFFER_HEXDUMP("test", buf, b, ESP_LOG_INFO);
|
|
||||||
fwrite(buf, 1, b, cdc);
|
|
||||||
}
|
|
||||||
vTaskDelay(1);
|
|
||||||
|
|
||||||
size_t rx_size = 0;
|
|
||||||
int itf = 0;
|
|
||||||
ESP_ERROR_CHECK(tinyusb_cdcacm_read(itf, buf, CONFIG_TINYUSB_CDC_RX_BUFSIZE, &rx_size));
|
|
||||||
if (rx_size > 0) {
|
|
||||||
printf("Intf %d, RX %d bytes\n", itf, rx_size);
|
|
||||||
|
|
||||||
// Add 'novfs' to reply so the host can identify the port
|
|
||||||
strcpy((char *)&buf[rx_size - 2], "novfs\r\n");
|
|
||||||
tinyusb_cdcacm_write_queue(itf, buf, rx_size + sizeof("novfs") - 1);
|
|
||||||
|
|
||||||
tinyusb_cdcacm_write_flush(itf, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "tinyusb.h"
|
|
||||||
#include "tusb_tasks.h"
|
|
||||||
#include "test_bvalid_sig.h"
|
|
||||||
#include "test_descriptors_config.h"
|
|
||||||
|
|
||||||
// Invoked when device is mounted
|
|
||||||
void tud_mount_cb(void)
|
|
||||||
{
|
|
||||||
printf("%s\n", __FUNCTION__);
|
|
||||||
test_bvalid_sig_mount_cb();
|
|
||||||
test_descriptors_config_mount_cb();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Invoked when device is unmounted
|
|
||||||
void tud_umount_cb(void)
|
|
||||||
{
|
|
||||||
printf("%s\n", __FUNCTION__);
|
|
||||||
test_bvalid_sig_umount_cb();
|
|
||||||
test_descriptors_config_umount_cb();
|
|
||||||
}
|
|
||||||
@ -1,73 +0,0 @@
|
|||||||
# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
from pytest_embedded_idf.dut import IdfDut
|
|
||||||
from time import sleep
|
|
||||||
from serial import Serial
|
|
||||||
from serial.tools.list_ports import comports
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.esp32s2
|
|
||||||
@pytest.mark.esp32s3
|
|
||||||
@pytest.mark.usb_device
|
|
||||||
def test_usb_device_cdc(dut) -> None:
|
|
||||||
'''
|
|
||||||
Running the test locally:
|
|
||||||
1. Build the testa app for your DUT (ESP32-S2 or S3)
|
|
||||||
2. Connect you DUT to your test runner (local machine) with USB port and flashing port
|
|
||||||
3. Run `pytest --target esp32s3`
|
|
||||||
|
|
||||||
Test procedure:
|
|
||||||
1. Run the test on the DUT
|
|
||||||
2. Expect 2 Virtual COM Ports in the system
|
|
||||||
3. Open both comports and send some data. Expect echoed data
|
|
||||||
'''
|
|
||||||
dut.expect_exact('Press ENTER to see the list of tests.')
|
|
||||||
dut.write('[esp_tinyusb]')
|
|
||||||
dut.expect_exact('TinyUSB: TinyUSB Driver installed')
|
|
||||||
sleep(2) # Some time for the OS to enumerate our USB device
|
|
||||||
|
|
||||||
# Find devices with Espressif TinyUSB VID/PID
|
|
||||||
s = []
|
|
||||||
ports = comports()
|
|
||||||
for port, _, hwid in ports:
|
|
||||||
if '303A:4002' in hwid:
|
|
||||||
s.append(port)
|
|
||||||
|
|
||||||
if len(s) != 2:
|
|
||||||
raise Exception('TinyUSB COM port not found')
|
|
||||||
|
|
||||||
with Serial(s[0]) as cdc0:
|
|
||||||
with Serial(s[1]) as cdc1:
|
|
||||||
# Write dummy string and check for echo
|
|
||||||
cdc0.write('text\r\n'.encode())
|
|
||||||
res = cdc0.readline()
|
|
||||||
assert b'text' in res
|
|
||||||
if b'novfs' in res:
|
|
||||||
novfs_cdc = cdc0
|
|
||||||
vfs_cdc = cdc1
|
|
||||||
|
|
||||||
cdc1.write('text\r\n'.encode())
|
|
||||||
res = cdc1.readline()
|
|
||||||
assert b'text' in res
|
|
||||||
if b'novfs' in res:
|
|
||||||
novfs_cdc = cdc1
|
|
||||||
vfs_cdc = cdc0
|
|
||||||
|
|
||||||
# Write more than MPS, check that the transfer is not divided
|
|
||||||
novfs_cdc.write(bytes(100))
|
|
||||||
dut.expect_exact("Intf 0, RX 100 bytes")
|
|
||||||
|
|
||||||
# Write more than RX buffer, check correct reception
|
|
||||||
novfs_cdc.write(bytes(600))
|
|
||||||
transfer_len1 = int(dut.expect(r'Intf 0, RX (\d+) bytes')[1].decode())
|
|
||||||
transfer_len2 = int(dut.expect(r'Intf 0, RX (\d+) bytes')[1].decode())
|
|
||||||
assert transfer_len1 + transfer_len2 == 600
|
|
||||||
|
|
||||||
# The VFS is setup for CRLF RX and LF TX
|
|
||||||
vfs_cdc.write('text\r\n'.encode())
|
|
||||||
res = vfs_cdc.readline()
|
|
||||||
assert b'text\n' in res
|
|
||||||
|
|
||||||
return
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
from pytest_embedded_idf.dut import IdfDut
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.esp32s2
|
|
||||||
@pytest.mark.esp32s3
|
|
||||||
@pytest.mark.usb_device
|
|
||||||
def test_usb_device_esp_tinyusb(dut: IdfDut) -> None:
|
|
||||||
dut.run_all_single_board_cases(group='usb_device')
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user