Skip to content

Commit

Permalink
Merge branch 'fix/usb_bridge_build' into 'master'
Browse files Browse the repository at this point in the history
fix(usb_bridge): fix build on idf master

See merge request ae_group/esp-dev-kits!242
  • Loading branch information
lijunru-hub committed Oct 22, 2024
2 parents df8ec4a + f7de6f3 commit f9e5aa6
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 54 deletions.
7 changes: 6 additions & 1 deletion .gitlab/ci/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,13 @@ build_esp32_s3_usb_bridge:
extends:
- .build_examples_template
- .rules:build:esp32_s3_usb_bridge
parallel:
matrix:
- IMAGE: espressif/idf:release-v5.0
- IMAGE: espressif/idf:release-v5.1
- IMAGE: espressif/idf:release-v5.2
- IMAGE: espressif/idf:release-v5.3
variables:
IMAGE: espressif/idf:release-v5.0
EXAMPLE_DIR: esp32-s3-usb-bridge/examples/usb_wireless_bridge

build_esp32_s3_usb_otg:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
idf_component_register(SRC_DIRS "." "espnow" "src"
INCLUDE_DIRS "." "espnow" "include" "public_include"
REQUIRES "tinyusb" "driver" "esp_timer" "ws2812_led"
REQUIRES "tinyusb" "driver" "esp_timer" "ws2812_led" "usb"
LDFRAGMENTS "noflash.lf")

idf_component_get_property(tusb_lib espressif__tinyusb COMPONENT_LIB)
Expand Down
22 changes: 11 additions & 11 deletions esp32-s3-usb-bridge/examples/usb_wireless_bridge/main/espnow/ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
#include "espnow_storage.h"
#include "espnow_ctrl.h"

#define ESPNOW_BIND_LIST_MAX_SIZE 1
#define BIND_LIST_MAX_SIZE 1

typedef struct {
int8_t rssi;
uint32_t timestamp;
size_t size;
espnow_ctrl_bind_info_t data[ESPNOW_BIND_LIST_MAX_SIZE];
espnow_ctrl_bind_info_t data[BIND_LIST_MAX_SIZE];
} espnow_bindlist_t;

static espnow_bindlist_t g_bindlist = {0};
static const char* TAG = "espnow_ctrl";
static const char *TAG = "espnow_ctrl";

static bool _ctrl_responder_is_bindlist(const uint8_t *mac, espnow_attribute_t initiator_attribute)
{
Expand Down Expand Up @@ -53,7 +53,7 @@ esp_err_t ctrl_responder_get_bindlist(espnow_ctrl_bind_info_t *list, size_t *siz

esp_err_t ctrl_responder_set_bindlist(const espnow_ctrl_bind_info_t *info)
{
if (g_bindlist.size >= ESPNOW_BIND_LIST_MAX_SIZE) {
if (g_bindlist.size >= BIND_LIST_MAX_SIZE) {
return ESP_FAIL;
}

Expand Down Expand Up @@ -88,7 +88,7 @@ esp_err_t ctrl_responder_remove_bindlist(const espnow_ctrl_bind_info_t *info)
}

static esp_err_t _ctrl_responder_bind_process(uint8_t *src_addr, void *data,
size_t size, wifi_pkt_rx_ctrl_t *rx_ctrl)
size_t size, wifi_pkt_rx_ctrl_t *rx_ctrl)
{
ESP_PARAM_CHECK(src_addr);
ESP_PARAM_CHECK(data);
Expand All @@ -98,26 +98,26 @@ static esp_err_t _ctrl_responder_bind_process(uint8_t *src_addr, void *data,
espnow_ctrl_data_t *ctrl_data = (espnow_ctrl_data_t *)data;
if (ctrl_data->responder_value_b) {
ESP_LOGD(TAG, "bind, esp_log_timestamp: %"PRIu32", timestamp: %"PRIu32", rssi: %d, rssi: %d",
esp_log_timestamp(), g_bindlist.timestamp, rx_ctrl->rssi, g_bindlist.rssi);
esp_log_timestamp(), g_bindlist.timestamp, rx_ctrl->rssi, g_bindlist.rssi);

if (esp_log_timestamp() < g_bindlist.timestamp && rx_ctrl->rssi > g_bindlist.rssi) {
ESP_LOGD("control_func", "addr: "MACSTR", initiator_type: %d, initiator_value: %d",
MAC2STR(src_addr), ctrl_data->initiator_attribute >> 8, ctrl_data->initiator_attribute & 0xff);
MAC2STR(src_addr), ctrl_data->initiator_attribute >> 8, ctrl_data->initiator_attribute & 0xff);

if (!_ctrl_responder_is_bindlist(src_addr, ctrl_data->initiator_attribute) && g_bindlist.size < ESPNOW_BIND_LIST_MAX_SIZE) {
if (!_ctrl_responder_is_bindlist(src_addr, ctrl_data->initiator_attribute) && g_bindlist.size < BIND_LIST_MAX_SIZE) {
g_bindlist.data[g_bindlist.size].initiator_attribute = ctrl_data->initiator_attribute;
memcpy(g_bindlist.data[g_bindlist.size].mac, src_addr, 6);

esp_event_post(ESP_EVENT_ESPNOW, ESP_EVENT_ESPNOW_CTRL_BIND,
g_bindlist.data + g_bindlist.size, sizeof(espnow_ctrl_bind_info_t), 0);
g_bindlist.data + g_bindlist.size, sizeof(espnow_ctrl_bind_info_t), 0);

g_bindlist.size++;
espnow_storage_set("bindlist", &g_bindlist, sizeof(g_bindlist));
}
}
} else {
if (_ctrl_responder_is_bindlist(src_addr, ctrl_data->initiator_attribute)) {
ESP_LOGD(TAG,"unbind, addr: "MACSTR", esp_log_timestamp: %"PRIu32", timestamp: %"PRIu32", rssi: %d, rssi: %d", MAC2STR(src_addr),
ESP_LOGD(TAG, "unbind, addr: "MACSTR", esp_log_timestamp: %"PRIu32", timestamp: %"PRIu32", rssi: %d, rssi: %d", MAC2STR(src_addr),
esp_log_timestamp(), g_bindlist.timestamp, rx_ctrl->rssi, g_bindlist.rssi);

for (int i = 0; i < g_bindlist.size; ++i) {
Expand Down Expand Up @@ -159,4 +159,4 @@ esp_err_t ctrl_responder_bind_window_set(uint32_t wait_ms, int8_t rssi)
g_bindlist.timestamp = esp_log_timestamp() + wait_ms;
g_bindlist.rssi = rssi;
return ESP_OK;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ dependencies:
espressif/esp-serial-flasher: "~0.0.7"
espressif/button: "~3.1.3"
espressif/led_indicator: "~0.4.0"
espressif/esp-now: "~2.3.0"
espressif/tinyusb: "^0.14.1"
espressif/esp-now: "~2.5.0"
espressif/tinyusb: "^0.15.0"
idf:
version: ">=5.0"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
/* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -7,7 +7,7 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "tusb.h"
#include "hal/usb_hal.h"
#include "esp_private/usb_phy.h"
#include "soc/usb_periph.h"
#include "tusb.h"
#include "esp_log.h"
Expand Down Expand Up @@ -37,7 +37,7 @@ enum {
ITF_NUM_TOTAL
};

static const char* TAG = "app_tusb";
static const char *TAG = "app_tusb";

static const tusb_desc_device_t descriptor_config = {
.bLength = sizeof(descriptor_config),
Expand Down Expand Up @@ -166,30 +166,6 @@ uint16_t const *tud_descriptor_string_cb(const uint8_t index, const uint16_t lan
return _desc_str;
}

static void configure_pins(usb_hal_context_t *usb)
{
/* usb_periph_iopins currently configures USB_OTG as USB Device.
* Introduce additional parameters in usb_hal_context_t when adding support
* for USB Host.
*/
for (const usb_iopin_dsc_t *iopin = usb_periph_iopins; iopin->pin != -1; ++iopin) {
if ((usb->use_external_phy) || (iopin->ext_phy_only == 0)) {
gpio_pad_select_gpio(iopin->pin);
if (iopin->is_output) {
gpio_matrix_out(iopin->pin, iopin->func, false, false);
} else {
gpio_matrix_in(iopin->pin, iopin->func, false);
gpio_pad_input_enable(iopin->pin);
}
gpio_pad_unhold(iopin->pin);
}
}
if (!usb->use_external_phy) {
gpio_set_drive_capability(USBPHY_DM_NUM, GPIO_DRIVE_CAP_3);
gpio_set_drive_capability(USBPHY_DP_NUM, GPIO_DRIVE_CAP_3);
}
}

static void tusb_device_task(void *pvParameters)
{
while (1) {
Expand All @@ -204,12 +180,15 @@ void app_tusb_init(void)
periph_module_reset(PERIPH_USB_MODULE);
periph_module_enable(PERIPH_USB_MODULE);

usb_hal_context_t hal = {
.use_external_phy = false
// Configure USB PHY
usb_phy_handle_t phy_hdl;
usb_phy_config_t phy_conf = {
.controller = USB_PHY_CTRL_OTG,
.otg_mode = USB_OTG_MODE_DEVICE,
.target = USB_PHY_TARGET_INT,
};
usb_hal_init(&hal);
configure_pins(&hal);
usb_new_phy(&phy_conf, &phy_hdl);
tusb_init();

xTaskCreate(tusb_device_task, "tusb_device_task", 4 * 1024, NULL, 5, NULL);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
CONFIG_IDF_TARGET="esp32s3"
CONFIG_FREERTOS_HZ=1000
CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0=n
CONFIG_ESP32S2_INSTRUCTION_CACHE_16KB=y
CONFIG_ESP32S2_DATA_CACHE_16KB=y
CONFIG_ESP32S2_DEFAULT_CPU_FREQ_240=y
CONFIG_ESP32S2_DEFAULT_CPU_FREQ_MHZ=240

CONFIG_WS2812_LED_GPIO=48
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CONFIG_IDF_TARGET="esp32s3"
CONFIG_ESP32S3_INSTRUCTION_CACHE_16KB=y
CONFIG_ESP32S3_DATA_CACHE_32KB=y
CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240=y
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CONFIG_WS2812_LED_GPIO=42
CONFIG_WS2812_LED_GPIO=42
23 changes: 22 additions & 1 deletion tools/build_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def get_cmake_apps(
build_log_filename='build_log.txt',
size_json_filename='size.json',
check_warnings=True,
preserve=True,
default_build_targets=default_build_targets,
manifest_files=[
str(Path(PROJECT_ROOT)/'.build-rules.yml'),
Expand All @@ -70,6 +69,18 @@ def get_cmake_apps(
def main(args): # type: (argparse.Namespace) -> None
default_build_targets = args.default_build_targets.split(',') if args.default_build_targets else None
apps = get_cmake_apps(args.paths, args.target, args.config, default_build_targets)
if args.find:
if args.output:
os.makedirs(os.path.dirname(os.path.realpath(args.output)), exist_ok=True)
with open(args.output, 'w') as fw:
for app in apps:
fw.write(app.to_json() + '\n')
else:
for app in apps:
print(app)

sys.exit(0)

if args.exclude_apps:
apps_to_build = [app for app in apps if app.name not in args.exclude_apps]
else:
Expand All @@ -90,6 +101,7 @@ def main(args): # type: (argparse.Namespace) -> None
keep_going=True,
ignore_warning_strs=IGNORE_WARNINGS,
copy_sdkconfig=True,
no_preserve=False,
)

sys.exit(ret_code)
Expand Down Expand Up @@ -146,6 +158,15 @@ def main(args): # type: (argparse.Namespace) -> None
action='count', default=0,
help='Show verbose log message',
)
parser.add_argument(
'--find',
action='store_true',
help='Find the buildable applications. If enable this option, build options will be ignored.',
)
parser.add_argument(
'-o', '--output',
help='Print the found apps to the specified file instead of stdout'
)

arguments = parser.parse_args()
if not arguments.paths:
Expand Down

0 comments on commit f9e5aa6

Please sign in to comment.