Skip to content

Commit c5df728

Browse files
committed
feat(usb-otg): Finish the USB-OTG RX/TX support
1 parent ac03ab8 commit c5df728

Some content is hidden

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

47 files changed

+31735
-945
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ set(srcs
2323
src/security.c
2424
src/uart.c
2525
src/usb_serial_jtag.c
26-
src/usb_cdc.c
26+
src/usb_otg.c
2727
)
2828

2929
if(STUB_LOG_ENABLED IN_LIST STUB_COMPILE_DEFS)

include/esp-stub-lib/usb_cdc.h

Lines changed: 0 additions & 88 deletions
This file was deleted.

include/esp-stub-lib/usb_otg.h

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0 OR MIT
5+
*/
6+
7+
#pragma once
8+
9+
#include <stdint.h>
10+
#include <stdbool.h>
11+
12+
#ifdef __cplusplus
13+
extern "C" {
14+
#endif // __cplusplus
15+
16+
/**
17+
* @brief Check if USB-OTG is currently being used for communication
18+
*
19+
* This function checks if the ROM has initialized USB-OTG as the communication
20+
* interface instead of UART.
21+
*
22+
* @return true if USB-OTG is active, false otherwise
23+
*/
24+
bool stub_lib_usb_otg_is_active(void);
25+
26+
/**
27+
* @brief Initialize USB-OTG for communication
28+
*
29+
* This function sets up USB-OTG interrupts and the RX callback function.
30+
* It should be called after ROM initialization if USB-OTG is detected.
31+
*
32+
* @param intr_num Interrupt number
33+
* @param rx_callback Callback function to be called when data is received
34+
* The callback receives a single byte as parameter
35+
*/
36+
void stub_lib_usb_otg_rominit_intr_attach(int intr_num, void (*rx_callback)(uint8_t));
37+
38+
/**
39+
* @brief Transmit a single byte over USB-OTG
40+
*
41+
* @param c Byte to transmit
42+
* @return 0 if successful, non-zero if error occurred
43+
*/
44+
uint8_t stub_lib_usb_otg_tx_one_char(uint8_t c);
45+
46+
/**
47+
* @brief Flush any buffered USB-OTG transmit data
48+
*/
49+
void stub_lib_usb_otg_tx_flush(void);
50+
51+
/**
52+
* @brief Enable or disable USB-OTG RX interrupts
53+
*
54+
* @param enable true to enable, false to disable
55+
*/
56+
void stub_lib_usb_otg_rx_async_enable(bool enable);
57+
58+
/**
59+
* @brief Check if USB-OTG reset was requested via RTS line
60+
*
61+
* This function checks if the host has requested a reset by toggling RTS.
62+
* If reset is requested, the function returns true and should be followed
63+
* by calling stub_lib_usb_otg_handle_reset().
64+
*
65+
* @return true if reset was requested, false otherwise
66+
*/
67+
bool stub_lib_usb_otg_is_reset_requested(void);
68+
69+
/**
70+
* @brief Handle USB-OTG reset request
71+
*
72+
* This function performs the necessary cleanup and prepares for reset.
73+
* It should be called when stub_lib_usb_otg_is_reset_requested() returns true.
74+
*/
75+
void stub_lib_usb_otg_handle_reset(void);
76+
77+
#ifdef __cplusplus
78+
}
79+
#endif // __cplusplus

src/target/base/include/target/usb_cdc.h

Lines changed: 0 additions & 76 deletions
This file was deleted.

src/target/base/include/target/usb_cdc_common.h

Lines changed: 0 additions & 126 deletions
This file was deleted.

0 commit comments

Comments
 (0)