summaryrefslogtreecommitdiff
path: root/examples/device
diff options
context:
space:
mode:
authorZixun LI <[email protected]>2025-12-02 11:34:43 +0100
committerZixun LI <[email protected]>2025-12-02 11:34:43 +0100
commit4bfd22eb23b4e9864c9a93897f63134de8b2911a (patch)
tree74b97fa3081c2309b3eaf02214bee9abd79488cb /examples/device
parentad34b92f0ee7242fcacef1137dc075dcd0c97b2a (diff)
parent7ee288bc223db393d68c7bdb09bf7c05ffd2eb03 (diff)
Merge remote-tracking branch 'tinyusb/master' into dwc2_cfg
Diffstat (limited to 'examples/device')
-rw-r--r--examples/device/audio_test_multi_rate/src/usb_descriptors.c4
-rw-r--r--examples/device/cdc_dual_ports/src/usb_descriptors.c4
-rw-r--r--examples/device/cdc_msc/prj.conf1
-rw-r--r--examples/device/cdc_msc/src/main.c1
-rw-r--r--examples/device/msc_dual_lun/prj.conf1
-rwxr-xr-xexamples/device/uac2_speaker_fb/src/audio_debug.py13
-rw-r--r--examples/device/uac2_speaker_fb/src/usb_descriptors.c4
-rw-r--r--examples/device/video_capture/src/usb_descriptors.c4
-rw-r--r--examples/device/video_capture_2ch/src/usb_descriptors.c4
-rw-r--r--examples/device/webusb_serial/src/main.c57
10 files changed, 43 insertions, 50 deletions
diff --git a/examples/device/audio_test_multi_rate/src/usb_descriptors.c b/examples/device/audio_test_multi_rate/src/usb_descriptors.c
index 471eb4f2e..505936fdb 100644
--- a/examples/device/audio_test_multi_rate/src/usb_descriptors.c
+++ b/examples/device/audio_test_multi_rate/src/usb_descriptors.c
@@ -119,8 +119,8 @@ TU_VERIFY_STATIC(sizeof(desc2_uac2_configuration) == CONFIG_UAC2_TOTAL_LEN, "Inc
// device qualifier is mostly similar to device descriptor since we don't change configuration based on speed
tusb_desc_device_qualifier_t const desc_device_qualifier = {
- .bLength = sizeof(tusb_desc_device_t),
- .bDescriptorType = TUSB_DESC_DEVICE,
+ .bLength = sizeof(tusb_desc_device_qualifier_t),
+ .bDescriptorType = TUSB_DESC_DEVICE_QUALIFIER,
.bcdUSB = 0x0200,
.bDeviceClass = TUSB_CLASS_MISC,
diff --git a/examples/device/cdc_dual_ports/src/usb_descriptors.c b/examples/device/cdc_dual_ports/src/usb_descriptors.c
index dd0aefaea..e6011c35a 100644
--- a/examples/device/cdc_dual_ports/src/usb_descriptors.c
+++ b/examples/device/cdc_dual_ports/src/usb_descriptors.c
@@ -153,8 +153,8 @@ static uint8_t const desc_hs_configuration[] = {
// device qualifier is mostly similar to device descriptor since we don't change configuration based on speed
static tusb_desc_device_qualifier_t const desc_device_qualifier = {
- .bLength = sizeof(tusb_desc_device_t),
- .bDescriptorType = TUSB_DESC_DEVICE,
+ .bLength = sizeof(tusb_desc_device_qualifier_t),
+ .bDescriptorType = TUSB_DESC_DEVICE_QUALIFIER,
.bcdUSB = USB_BCD,
.bDeviceClass = TUSB_CLASS_MISC,
diff --git a/examples/device/cdc_msc/prj.conf b/examples/device/cdc_msc/prj.conf
index 2f5139d9d..9e86a118d 100644
--- a/examples/device/cdc_msc/prj.conf
+++ b/examples/device/cdc_msc/prj.conf
@@ -3,4 +3,3 @@ CONFIG_FPU=y
CONFIG_NO_OPTIMIZATIONS=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_NRFX_POWER=y
-CONFIG_NRFX_UARTE0=y
diff --git a/examples/device/cdc_msc/src/main.c b/examples/device/cdc_msc/src/main.c
index e4a205533..06a4f732f 100644
--- a/examples/device/cdc_msc/src/main.c
+++ b/examples/device/cdc_msc/src/main.c
@@ -124,6 +124,7 @@ void cdc_task(void) {
if ((btn_prev == 0u) && (btn != 0u)) {
uart_state.dsr ^= 1;
+ uart_state.dcd ^= 1;
tud_cdc_notify_uart_state(&uart_state);
}
btn_prev = btn;
diff --git a/examples/device/msc_dual_lun/prj.conf b/examples/device/msc_dual_lun/prj.conf
index 2f5139d9d..9e86a118d 100644
--- a/examples/device/msc_dual_lun/prj.conf
+++ b/examples/device/msc_dual_lun/prj.conf
@@ -3,4 +3,3 @@ CONFIG_FPU=y
CONFIG_NO_OPTIMIZATIONS=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_NRFX_POWER=y
-CONFIG_NRFX_UARTE0=y
diff --git a/examples/device/uac2_speaker_fb/src/audio_debug.py b/examples/device/uac2_speaker_fb/src/audio_debug.py
index 05b49baf6..1c6035a44 100755
--- a/examples/device/uac2_speaker_fb/src/audio_debug.py
+++ b/examples/device/uac2_speaker_fb/src/audio_debug.py
@@ -2,13 +2,15 @@
# Install python3 HID package https://pypi.org/project/hid/
# Install python3 matplotlib package https://pypi.org/project/matplotlib/
-from ctypes import *
+from ctypes import Structure, c_uint32, c_uint8, c_int8, c_int16, c_uint16
+import signal
try:
import hid
import matplotlib.pyplot as plt
import matplotlib.animation as animation
except:
print("Missing import, please try 'pip install hid matplotlib' or consult your OS's python package manager.")
+ exit(1)
# Example must be compiled with CFG_AUDIO_DEBUG=1
VID = 0xcafe
@@ -29,6 +31,7 @@ class audio_debug_info_t (Structure):
dev = hid.Device(VID, PID)
if dev:
+ signal.signal(signal.SIGINT, signal.SIG_DFL)
# Create figure for plotting
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
@@ -61,10 +64,10 @@ if dev:
ax.set_ylim(bottom=0, top=info.fifo_size)
# Format plot
- plt.title('FIFO information')
- plt.grid()
+ ax.set_title('FIFO information')
+ ax.grid(True)
print(f'Sample rate:{info.sample_rate} | Alt settings:{info.alt_settings} | Volume:{info.volume[:]}')
- ani = animation.FuncAnimation(fig, animate, interval=10)
- plt.show()
+ ani = animation.FuncAnimation(fig, animate, interval=10, cache_frame_data=False) # type: ignore
+ plt.show(block=True)
diff --git a/examples/device/uac2_speaker_fb/src/usb_descriptors.c b/examples/device/uac2_speaker_fb/src/usb_descriptors.c
index 697e51483..c5a161a1e 100644
--- a/examples/device/uac2_speaker_fb/src/usb_descriptors.c
+++ b/examples/device/uac2_speaker_fb/src/usb_descriptors.c
@@ -174,8 +174,8 @@ TU_VERIFY_STATIC(sizeof(desc_uac2_configuration) == CONFIG_UAC2_TOTAL_LEN, "Inco
// device qualifier is mostly similar to device descriptor since we don't change configuration based on speed
tusb_desc_device_qualifier_t const desc_device_qualifier = {
- .bLength = sizeof(tusb_desc_device_t),
- .bDescriptorType = TUSB_DESC_DEVICE,
+ .bLength = sizeof(tusb_desc_device_qualifier_t),
+ .bDescriptorType = TUSB_DESC_DEVICE_QUALIFIER,
.bcdUSB = 0x0200,
.bDeviceClass = TUSB_CLASS_MISC,
diff --git a/examples/device/video_capture/src/usb_descriptors.c b/examples/device/video_capture/src/usb_descriptors.c
index 114dd5722..b3382c82d 100644
--- a/examples/device/video_capture/src/usb_descriptors.c
+++ b/examples/device/video_capture/src/usb_descriptors.c
@@ -385,8 +385,8 @@ static uint8_t * get_hs_configuration_desc(void) {
// device qualifier is mostly similar to device descriptor since we don't change configuration based on speed
static tusb_desc_device_qualifier_t const desc_device_qualifier = {
- .bLength = sizeof(tusb_desc_device_t),
- .bDescriptorType = TUSB_DESC_DEVICE,
+ .bLength = sizeof(tusb_desc_device_qualifier_t),
+ .bDescriptorType = TUSB_DESC_DEVICE_QUALIFIER,
.bcdUSB = USB_BCD,
.bDeviceClass = TUSB_CLASS_MISC,
diff --git a/examples/device/video_capture_2ch/src/usb_descriptors.c b/examples/device/video_capture_2ch/src/usb_descriptors.c
index 024d16e07..8dc986da6 100644
--- a/examples/device/video_capture_2ch/src/usb_descriptors.c
+++ b/examples/device/video_capture_2ch/src/usb_descriptors.c
@@ -552,8 +552,8 @@ static uint8_t * get_hs_configuration_desc(void) {
// device qualifier is mostly similar to device descriptor since we don't change configuration based on speed
static tusb_desc_device_qualifier_t const desc_device_qualifier = {
- .bLength = sizeof(tusb_desc_device_t),
- .bDescriptorType = TUSB_DESC_DEVICE,
+ .bLength = sizeof(tusb_desc_device_qualifier_t),
+ .bDescriptorType = TUSB_DESC_DEVICE_QUALIFIER,
.bcdUSB = USB_BCD,
.bDeviceClass = TUSB_CLASS_MISC,
diff --git a/examples/device/webusb_serial/src/main.c b/examples/device/webusb_serial/src/main.c
index 0c2acd94e..50794bdba 100644
--- a/examples/device/webusb_serial/src/main.c
+++ b/examples/device/webusb_serial/src/main.c
@@ -101,7 +101,7 @@ int main(void) {
while (1) {
tud_task(); // tinyusb device task
- cdc_task();
+ tud_cdc_write_flush();
led_blinking_task();
}
}
@@ -116,13 +116,7 @@ static void echo_all(const uint8_t buf[], uint32_t count) {
// echo to cdc
if (tud_cdc_connected()) {
- for (uint32_t i = 0; i < count; i++) {
- tud_cdc_write_char(buf[i]);
- if (buf[i] == '\r') {
- tud_cdc_write_char('\n');
- }
- }
- tud_cdc_write_flush();
+ tud_cdc_write(buf, count);
}
}
@@ -162,7 +156,9 @@ void tud_resume_cb(void) {
// return false to stall control endpoint (e.g unsupported request)
bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const* request) {
// nothing to with DATA & ACK stage
- if (stage != CONTROL_STAGE_SETUP) return true;
+ if (stage != CONTROL_STAGE_SETUP) {
+ return true;
+ }
switch (request->bmRequestType_bit.type) {
case TUSB_REQ_TYPE_VENDOR:
@@ -215,33 +211,21 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ
return false;
}
-void tud_vendor_rx_cb(uint8_t itf, uint8_t const* buffer, uint16_t bufsize) {
- (void) itf;
+void tud_vendor_rx_cb(uint8_t idx, const uint8_t *buffer, uint32_t bufsize) {
+ (void)idx;
+ (void)buffer;
+ (void)bufsize;
- echo_all(buffer, bufsize);
-
- // if using RX buffered is enabled, we need to flush the buffer to make room for new data
- #if CFG_TUD_VENDOR_RX_BUFSIZE > 0
- tud_vendor_read_flush();
- #endif
+ while (tud_vendor_available()) {
+ uint8_t buf[64];
+ const uint32_t count = tud_vendor_read(buf, sizeof(buf));
+ echo_all(buf, count);
+ }
}
//--------------------------------------------------------------------+
// USB CDC
//--------------------------------------------------------------------+
-void cdc_task(void) {
- if (tud_cdc_connected()) {
- // connected and there are data available
- if (tud_cdc_available()) {
- uint8_t buf[64];
-
- uint32_t count = tud_cdc_read(buf, sizeof(buf));
-
- // echo back to both web serial and cdc
- echo_all(buf, count);
- }
- }
-}
// Invoked when cdc when line state changed e.g connected/disconnected
void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) {
@@ -255,8 +239,13 @@ void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) {
}
// Invoked when CDC interface received data from host
-void tud_cdc_rx_cb(uint8_t itf) {
- (void)itf;
+void tud_cdc_rx_cb(uint8_t idx) {
+ (void)idx;
+ while (tud_cdc_available()) {
+ uint8_t buf[64];
+ const uint32_t count = tud_cdc_read(buf, sizeof(buf));
+ echo_all(buf, count); // echo back to both web serial and cdc
+ }
}
//--------------------------------------------------------------------+
@@ -267,7 +256,9 @@ void led_blinking_task(void) {
static bool led_state = false;
// Blink every interval ms
- if (board_millis() - start_ms < blink_interval_ms) return; // not enough time
+ if (board_millis() - start_ms < blink_interval_ms) {
+ return; // not enough time
+ }
start_ms += blink_interval_ms;
board_led_write(led_state);