Skip to content

Commit 40e383f

Browse files
committed
Merge branch 'feat/usb_4g_through_rndis' into 'master'
feat(rndis): add usb rndis example See merge request ae_group/esp-iot-solution!1205
2 parents c588f96 + 3019bb7 commit 40e383f

File tree

76 files changed

+4534
-203
lines changed

Some content is hidden

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

76 files changed

+4534
-203
lines changed

.github/workflows/upload_component.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ jobs:
5656
components/extended_vfs;
5757
components/gprof;
5858
components/i2c_bus;
59+
components/iot_eth;
5960
components/ir/ir_learn;
6061
components/keyboard_button;
6162
components/knob;
@@ -95,6 +96,7 @@ jobs:
9596
components/usb/iot_usbh_modem;
9697
components/usb/usb_device_uac;
9798
components/usb/usb_device_uvc;
99+
components/usb/iot_usbh_rndis;
98100
components/usb/usb_stream;
99101
components/utilities/adc_tp_calibration;
100102
components/utilities/xz;

.gitlab/ci/build.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,19 @@ build_example_usb_host_usb_msc_ota:
969969
variables:
970970
EXAMPLE_DIR: examples/usb/host/usb_msc_ota
971971

972+
build_example_usb_host_usb_rndis_4g_module:
973+
extends:
974+
- .build_examples_template
975+
- .rules:build:example_usb_host_usb_rndis_4g_module
976+
parallel:
977+
matrix:
978+
- IMAGE: espressif/idf:release-v5.1
979+
- IMAGE: espressif/idf:release-v5.2
980+
- IMAGE: espressif/idf:release-v5.3
981+
- IMAGE: espressif/idf:release-v5.4
982+
variables:
983+
EXAMPLE_DIR: examples/usb/host/usb_rndis_4g_module
984+
972985
build_example_usb_otg_usb_host_device_mode_manual_switch:
973986
extends:
974987
- .build_examples_template
@@ -1597,6 +1610,14 @@ build_components_usb_esp_msc_ota_test_apps:
15971610
IMAGE: espressif/idf:release-v5.1
15981611
EXAMPLE_DIR: components/usb/esp_msc_ota/test_apps
15991612

1613+
build_components_usb_iot_usbh_rndis_test_apps:
1614+
extends:
1615+
- .build_examples_template
1616+
- .rules:build:components_usb_iot_usbh_rndis_test_apps
1617+
- .build_idf_version_greater_equal_v5_0
1618+
variables:
1619+
EXAMPLE_DIR: components/usb/iot_usbh_rndis/test_apps
1620+
16001621
build_components_usb_usb_stream_test_apps:
16011622
extends:
16021623
- .build_examples_template

.gitlab/ci/rules.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,20 @@
315315
- "components/usb/iot_usbh_modem/**/*"
316316
- "tools/cmake_utilities/package_manager.cmake"
317317

318+
.patterns-components_usb_usb_host_rndis_test_apps: &patterns-components_usb_usb_host_rndis_test_apps
319+
- "components/usb/usb_host_rndis/test_apps/**/*"
320+
- "tools/cmake_utilities/package_manager.cmake"
321+
318322
.patterns-components_usb_usb_device_uac: &patterns-components_usb_usb_device_uac
319323
- "components/usb/usb_device_uac/**/*"
320324

321325
.patterns-components_usb_usb_device_uvc: &patterns-components_usb_usb_device_uvc
322326
- "components/usb/usb_device_uvc/**/*"
323327

328+
.patterns-components_usb_iot_usbh_rndis: &patterns-components_usb_iot_usbh_rndis
329+
- "components/usb/iot_usbh_rndis/**/*"
330+
- "tools/cmake_utilities/package_manager.cmake"
331+
324332
.patterns-components_usb_usb_stream: &patterns-components_usb_usb_stream
325333
- "components/usb/usb_stream/**/*"
326334
- "tools/cmake_utilities/package_manager.cmake"
@@ -343,6 +351,10 @@
343351
- "components/i2c_bus/**/*"
344352
- "tools/cmake_utilities/package_manager.cmake"
345353

354+
.patterns-components_iot_eth: &patterns-components_iot_eth
355+
- "components/iot_eth/**/*"
356+
- "tools/cmake_utilities/package_manager.cmake"
357+
346358
.patterns-components_sensors_power_monitor_ina236: &patterns-components_sensors_power_monitor_ina236
347359
- "components/sensors/power_monitor/ina236/**/*"
348360
- "tools/cmake_utilities/package_manager.cmake"
@@ -630,6 +642,9 @@
630642
.patterns-example_usb_host_usb_msc_ota: &patterns-example_usb_host_usb_msc_ota
631643
- "examples/usb/host/usb_msc_ota/**/*"
632644

645+
.patterns-example_usb_host_usb_rndis_4g_module: &patterns-example_usb_host_usb_rndis_4g_module
646+
- "examples/usb/host/usb_rndis_4g_module/**/*"
647+
633648
.patterns-example_usb_otg_usb_host_device_mode_manual_switch: &patterns-example_usb_otg_usb_host_device_mode_manual_switch
634649
- "examples/usb/otg/usb_host_device_mode_manual_switch/**/*"
635650

@@ -1602,6 +1617,22 @@
16021617
- <<: *if-dev-push
16031618
changes: *patterns-example_usb_host_usb_msc_ota
16041619

1620+
.rules:build:example_usb_host_usb_rndis_4g_module:
1621+
rules:
1622+
- <<: *if-protected
1623+
- <<: *if-label-build
1624+
- <<: *if-trigger-job
1625+
- <<: *if-dev-push
1626+
changes: *patterns-build_system
1627+
- <<: *if-dev-push
1628+
changes: *patterns-components_usb_iot_usbh_cdc
1629+
- <<: *if-dev-push
1630+
changes: *patterns-components_usb_iot_usbh_rndis
1631+
- <<: *if-dev-push
1632+
changes: *patterns-components_iot_eth
1633+
- <<: *if-dev-push
1634+
changes: *patterns-example_usb_host_usb_rndis_4g_module
1635+
16051636
.rules:build:example_usb_otg_usb_host_device_mode_manual_switch:
16061637
rules:
16071638
- <<: *if-protected
@@ -2451,6 +2482,32 @@
24512482
- <<: *if-dev-push
24522483
changes: *patterns-components_touch_touch_slider_sensor
24532484

2485+
.rules:build:components_usb_usb_host_rndis_test_apps:
2486+
rules:
2487+
- <<: *if-protected
2488+
- <<: *if-label-build
2489+
- <<: *if-label-target_test
2490+
- <<: *if-trigger-job
2491+
- <<: *if-dev-push
2492+
changes: *patterns-build_system
2493+
- <<: *if-dev-push
2494+
changes: *patterns-components_usb_usb_host_rndis_test_apps
2495+
- <<: *if-dev-push
2496+
changes: *patterns-components_usb_iot_usbh_cdc
2497+
2498+
.rules:build:components_usb_iot_usbh_rndis_test_apps:
2499+
rules:
2500+
- <<: *if-protected
2501+
- <<: *if-label-build
2502+
- <<: *if-label-target_test
2503+
- <<: *if-trigger-job
2504+
- <<: *if-dev-push
2505+
changes: *patterns-build_system
2506+
- <<: *if-dev-push
2507+
changes: *patterns-components_usb_iot_usbh_rndis
2508+
- <<: *if-dev-push
2509+
changes: *patterns-components_usb_iot_usbh_cdc
2510+
24542511
.rules:build:components_usb_esp_msc_ota_test_apps:
24552512
rules:
24562513
- <<: *if-protected

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,11 @@ The registered components in ESP-IoT-Solution are listed below:
108108
| [hdc2010](https://components.espressif.com/components/espressif/hdc2010) | [![Component Registry](https://components.espressif.com/components/espressif/hdc2010/badge.svg)](https://components.espressif.com/components/espressif/hdc2010) |
109109
| [i2c_bus](https://components.espressif.com/components/espressif/i2c_bus) | [![Component Registry](https://components.espressif.com/components/espressif/i2c_bus/badge.svg)](https://components.espressif.com/components/espressif/i2c_bus) |
110110
| [ina236](https://components.espressif.com/components/espressif/ina236) | [![Component Registry](https://components.espressif.com/components/espressif/ina236/badge.svg)](https://components.espressif.com/components/espressif/ina236) |
111+
| [iot_eth](https://components.espressif.com/components/espressif/iot_eth) | [![Component Registry](https://components.espressif.com/components/espressif/iot_eth/badge.svg)](https://components.espressif.com/components/espressif/iot_eth) |
111112
| [iot_usbh](https://components.espressif.com/components/espressif/iot_usbh) | [![Component Registry](https://components.espressif.com/components/espressif/iot_usbh/badge.svg)](https://components.espressif.com/components/espressif/iot_usbh) |
112113
| [iot_usbh_cdc](https://components.espressif.com/components/espressif/iot_usbh_cdc) | [![Component Registry](https://components.espressif.com/components/espressif/iot_usbh_cdc/badge.svg)](https://components.espressif.com/components/espressif/iot_usbh_cdc) |
113114
| [iot_usbh_modem](https://components.espressif.com/components/espressif/iot_usbh_modem) | [![Component Registry](https://components.espressif.com/components/espressif/iot_usbh_modem/badge.svg)](https://components.espressif.com/components/espressif/iot_usbh_modem) |
115+
| [iot_usbh_rndis](https://components.espressif.com/components/espressif/iot_usbh_rndis) | [![Component Registry](https://components.espressif.com/components/espressif/iot_usbh_rndis/badge.svg)](https://components.espressif.com/components/espressif/iot_usbh_rndis) |
114116
| [ir_learn](https://components.espressif.com/components/espressif/ir_learn) | [![Component Registry](https://components.espressif.com/components/espressif/ir_learn/badge.svg)](https://components.espressif.com/components/espressif/ir_learn) |
115117
| [keyboard_button](https://components.espressif.com/components/espressif/keyboard_button) | [![Component Registry](https://components.espressif.com/components/espressif/keyboard_button/badge.svg)](https://components.espressif.com/components/espressif/keyboard_button) |
116118
| [knob](https://components.espressif.com/components/espressif/knob) | [![Component Registry](https://components.espressif.com/components/espressif/knob/badge.svg)](https://components.espressif.com/components/espressif/knob) |

README_CN.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,11 @@ ESP-IoT-Solution 中注册的组件如下:
108108
| [hdc2010](https://components.espressif.com/components/espressif/hdc2010) | [![Component Registry](https://components.espressif.com/components/espressif/hdc2010/badge.svg)](https://components.espressif.com/components/espressif/hdc2010) |
109109
| [i2c_bus](https://components.espressif.com/components/espressif/i2c_bus) | [![Component Registry](https://components.espressif.com/components/espressif/i2c_bus/badge.svg)](https://components.espressif.com/components/espressif/i2c_bus) |
110110
| [ina236](https://components.espressif.com/components/espressif/ina236) | [![Component Registry](https://components.espressif.com/components/espressif/ina236/badge.svg)](https://components.espressif.com/components/espressif/ina236) |
111+
| [iot_eth](https://components.espressif.com/components/espressif/iot_eth) | [![Component Registry](https://components.espressif.com/components/espressif/iot_eth/badge.svg)](https://components.espressif.com/components/espressif/iot_eth) |
111112
| [iot_usbh](https://components.espressif.com/components/espressif/iot_usbh) | [![Component Registry](https://components.espressif.com/components/espressif/iot_usbh/badge.svg)](https://components.espressif.com/components/espressif/iot_usbh) |
112113
| [iot_usbh_cdc](https://components.espressif.com/components/espressif/iot_usbh_cdc) | [![Component Registry](https://components.espressif.com/components/espressif/iot_usbh_cdc/badge.svg)](https://components.espressif.com/components/espressif/iot_usbh_cdc) |
113114
| [iot_usbh_modem](https://components.espressif.com/components/espressif/iot_usbh_modem) | [![Component Registry](https://components.espressif.com/components/espressif/iot_usbh_modem/badge.svg)](https://components.espressif.com/components/espressif/iot_usbh_modem) |
115+
| [iot_usbh_rndis](https://components.espressif.com/components/espressif/iot_usbh_rndis) | [![Component Registry](https://components.espressif.com/components/espressif/iot_usbh_rndis/badge.svg)](https://components.espressif.com/components/espressif/iot_usbh_rndis) |
114116
| [ir_learn](https://components.espressif.com/components/espressif/ir_learn) | [![Component Registry](https://components.espressif.com/components/espressif/ir_learn/badge.svg)](https://components.espressif.com/components/espressif/ir_learn) |
115117
| [keyboard_button](https://components.espressif.com/components/espressif/keyboard_button) | [![Component Registry](https://components.espressif.com/components/espressif/keyboard_button/badge.svg)](https://components.espressif.com/components/espressif/keyboard_button) |
116118
| [knob](https://components.espressif.com/components/espressif/knob) | [![Component Registry](https://components.espressif.com/components/espressif/knob/badge.svg)](https://components.espressif.com/components/espressif/knob) |

components/.build-rules.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ components/usb/esp_msc_ota/test_apps:
3333
enable:
3434
- if: IDF_TARGET in ["esp32s3"]
3535

36+
components/usb/iot_usbh_rndis/test_apps:
37+
enable:
38+
- if: SOC_USB_OTG_SUPPORTED == 1
39+
3640
components/usb/usb_stream/test_apps:
3741
enable:
3842
- if: IDF_TARGET in ["esp32s2","esp32s3"]

components/iot_eth/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# ChangeLog
2+
3+
## v0.1.0 - 2025-04-22
4+
5+
* publish official version

components/iot_eth/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
idf_component_register(SRCS "iot_eth.c" "iot_eth_netif_glue.c"
2+
INCLUDE_DIRS "include" "interface"
3+
REQUIRES esp_netif)
4+
5+
include(package_manager)
6+
cu_pkg_define_version(${CMAKE_CURRENT_LIST_DIR})

components/iot_eth/idf_component.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: "0.1.0"
2+
description: Ethernet interface driver for cellular modems and USB-to-Ethernet adapters
3+
url: https://github.com/espressif/esp-iot-solution/tree/master/components/iot_eth
4+
repository: https://github.com/espressif/esp-iot-solution.git
5+
documentation: https://docs.espressif.com/projects/esp-iot-solution/en/latest/solution/4g/iot_eth.html
6+
issues: https://github.com/espressif/esp-iot-solution/issues
7+
examples:
8+
- path: ../../examples/usb/host/usb_rndis_4g_module
9+
dependencies:
10+
idf: ">=4.4"
11+
cmake_utilities: "*"
12+
sbom:
13+
supplier: 'Organization: Espressif Systems (Shanghai) CO LTD'
14+
originator: 'Organization: Espressif Systems (Shanghai) CO LTD'

components/iot_eth/include/iot_eth.h

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#pragma once
7+
8+
#include "esp_err.h"
9+
#include "esp_event.h"
10+
#include "iot_eth_interface.h"
11+
12+
#ifdef __cplusplus
13+
extern "C" {
14+
#endif
15+
16+
/**
17+
* @brief iot_eth event declarations
18+
*
19+
*/
20+
typedef enum {
21+
IOT_ETH_EVENT_START, /*!< IOT_ETH driver start */
22+
IOT_ETH_EVENT_STOP, /*!< IOT_ETH driver stop */
23+
IOT_ETH_EVENT_CONNECTED, /*!< IOT_ETH got a valid link */
24+
IOT_ETH_EVENT_DISCONNECTED, /*!< IOT_ETH lost a valid link */
25+
} iot_eth_event_t;
26+
27+
/**
28+
* @brief iot_eth event base declaration
29+
*
30+
*/
31+
/** @cond **/
32+
ESP_EVENT_DECLARE_BASE(IOT_ETH_EVENT);
33+
/** @endcond **/
34+
35+
/**
36+
* @brief Ethernet handle type
37+
*
38+
* This is a handle to an Ethernet instance, used for managing Ethernet operations.
39+
*/
40+
typedef void *iot_eth_handle_t;
41+
42+
/**
43+
* @brief Static input callback function type
44+
*
45+
* This type defines a function pointer for a static input callback.
46+
* It takes an Ethernet handle, a pointer to data, the length of the data,
47+
* and a user data pointer as arguments.
48+
*/
49+
typedef esp_err_t (*static_input_cb_t)(iot_eth_handle_t handle, uint8_t *data, size_t len, void *user_data);
50+
51+
/**
52+
* @brief Ethernet configuration structure
53+
*
54+
* This structure holds the configuration for initializing an Ethernet instance.
55+
*/
56+
typedef struct {
57+
iot_eth_driver_t *driver; /*!< Pointer to the Ethernet driver */
58+
static_input_cb_t stack_input; /*!< Function pointer for stack input */
59+
void *user_data; /*!< User data for callbacks */
60+
} iot_eth_config_t;
61+
62+
/*
63+
* @brief Install Ethernet driver
64+
*
65+
* This function initializes the Ethernet driver and network interface.
66+
*
67+
* @param config Ethernet configuration
68+
* @param handle Pointer to the Ethernet handle
69+
*
70+
* @return
71+
* - ESP_OK on success
72+
* - ESP_ERR_INVALID_ARG if arguments are invalid
73+
* - ESP_ERR_NO_MEM if memory allocation fails
74+
* - Other error codes from initialization functions
75+
*/
76+
esp_err_t iot_eth_install(iot_eth_config_t *config, iot_eth_handle_t *handle);
77+
78+
/*
79+
* @brief Uninstall Ethernet driver
80+
*
81+
* This function deinitializes the Ethernet driver and frees resources.
82+
*
83+
* @param handle Ethernet handle
84+
*
85+
* @return
86+
* - ESP_OK on success
87+
* - Error code from driver deinitialization
88+
*/
89+
esp_err_t iot_eth_uninstall(iot_eth_handle_t handle);
90+
91+
/*
92+
* @brief Start Ethernet driver
93+
*
94+
* This function starts the Ethernet driver.
95+
*
96+
* @param handle Ethernet handle
97+
*
98+
* @return
99+
* - ESP_OK on success
100+
* - Error code from driver start function
101+
*/
102+
esp_err_t iot_eth_start(iot_eth_handle_t handle);
103+
104+
/*
105+
* @brief Stop Ethernet driver
106+
*
107+
* This function stops the Ethernet driver.
108+
*
109+
* @param handle Ethernet handle
110+
*
111+
* @return
112+
* - ESP_OK on success
113+
* - Error code from driver stop function
114+
*/
115+
esp_err_t iot_eth_stop(iot_eth_handle_t handle);
116+
117+
/*
118+
* @brief Transmit data over Ethernet
119+
*
120+
* This function sends data through the Ethernet driver.
121+
*
122+
* @param handle Ethernet handle
123+
* @param data Pointer to the data to be sent
124+
* @param len Length of the data to be sent
125+
*
126+
* @return
127+
* - ESP_OK on success
128+
* - ESP_ERR_INVALID_ARG if arguments are invalid
129+
* - ESP_ERR_INVALID_STATE if Ethernet link is down
130+
*/
131+
esp_err_t iot_eth_transmit(iot_eth_handle_t handle, void *data, size_t len);
132+
133+
/*
134+
* @brief Get Ethernet MAC address
135+
*
136+
* This function retrieves the MAC address of the Ethernet interface.
137+
*
138+
* @param handle Ethernet handle
139+
* @param mac Pointer to the MAC address buffer
140+
*
141+
* @return
142+
* - ESP_OK on success
143+
* - Error code from driver get address function
144+
*/
145+
esp_err_t iot_eth_get_addr(iot_eth_handle_t handle, uint8_t *mac);
146+
147+
/*
148+
* @brief Update the input path for Ethernet data
149+
*
150+
* This function updates the stack input callback function and user data pointer
151+
* that will be used when receiving Ethernet packets.
152+
*
153+
* @param[in] handle Ethernet handle
154+
* @param[in] stack_input Function pointer for stack input callback
155+
* @param[in] user_data User data to be passed to stack input callback
156+
*
157+
* @return
158+
* - ESP_OK: Successfully updated input path
159+
* - ESP_ERR_INVALID_ARG: Invalid handle argument
160+
*/
161+
esp_err_t iot_eth_update_input_path(iot_eth_handle_t handle, static_input_cb_t stack_input, void *user_data);
162+
163+
#ifdef __cplusplus
164+
}
165+
#endif

0 commit comments

Comments
 (0)