Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions host/class/uac/usb_host_uac/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,45 @@
# Changelog for USB Host UAC

## 1.3.1
All notable changes to this component will be documented in this file.

1. Added support for ESP32-H4
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 1.3.0
## [1.3.2] - 2025-10-21

1. Added Linux target build for the UAC component, host tests (https://github.com/espressif/esp-usb/issues/143)
### Changed

## 1.2.0 2024-09-27
- uac_host_device_read() now waits for the full timeout duration until the required amount of data is read, preventing premature returns with partial data (https://github.com/espressif/esp-usb/issues/248)

### Breaking Changes:
## [1.3.1] - 2025-09-24

- Added support for ESP32-H4

## [1.3.0] - 2025-03-28

1. Changed the parameter type of `uac_host_device_set_volume_db` from uint32_t to int16_t
- Added Linux target build for the UAC component, host tests (https://github.com/espressif/esp-usb/issues/143)

## [1.2.0] - 2024-10-10

### Breaking Changes:

- Changed the parameter type of `uac_host_device_set_volume_db` from uint32_t to int16_t

### Improvements:

1. Support get current volume and mute status
- Support get current volume and mute status

### Bugfixes:

1. Fixed incorrect volume conversion. Using actual device volume range.
2. Fixed concurrency issues when suspend/stop during read/write
- Fixed incorrect volume conversion. Using actual device volume range.
- Fixed concurrency issues when suspend/stop during read/write

## 1.1.0
## [1.1.0] - 2024-07-08

### Improvements

- Added add `uac_host_device_open_with_vid_pid` to open connected audio devices with known VID and PID
- Print component version message `uac-host: Install Succeed, Version: 1.1.0` in `uac_host_install` function

## 1.0.0
## [1.0.0] - 2024-05-23

- Initial version
2 changes: 2 additions & 0 deletions host/class/uac/usb_host_uac/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# USB Host UAC Driver

[![Component Registry](https://components.espressif.com/components/espressif/usb_host_uac/badge.svg)](https://components.espressif.com/components/espressif/usb_host_uac)
![maintenance-status](https://img.shields.io/badge/maintenance-actively--developed-brightgreen.svg)
![changelog](https://img.shields.io/badge/Keep_a_Changelog-blue?logo=keepachangelog&logoColor=E05735)

This directory contains an implementation of a USB UAC Driver implemented on top of the [USB Host Library](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/api-reference/peripherals/usb_host.html).

Expand Down
2 changes: 1 addition & 1 deletion host/class/uac/usb_host_uac/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## IDF Component Manager Manifest File
version: "1.3.1"
version: "1.3.2"
description: USB Host UAC driver
url: https://github.com/espressif/esp-usb/tree/master/host/class/uac/usb_host_uac
dependencies:
Expand Down
65 changes: 47 additions & 18 deletions host/class/uac/usb_host_uac/uac_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,25 +276,58 @@ static esp_err_t _ring_buffer_push(RingbufHandle_t ringbuf_hdl, uint8_t *buf, si
static esp_err_t _ring_buffer_pop(RingbufHandle_t ringbuf_hdl, uint8_t *buf, size_t req_bytes, size_t *read_bytes, TickType_t ticks_to_wait)
{
assert(ringbuf_hdl && buf && read_bytes);
uint8_t *buf_rcv = xRingbufferReceiveUpTo(ringbuf_hdl, read_bytes, ticks_to_wait, req_bytes);

if (!buf_rcv) {
return ESP_FAIL;
/* Read up to req_bytes, blocking up to ticks_to_wait in total.
* xRingbufferReceiveUpTo may return fewer bytes than requested even if
* the caller asked for more, so loop until we've collected the full
* amount or the timeout expires. If nothing is read before timeout,
* return ESP_ERR_TIMEOUT. If some bytes were read and timeout expires, return
* ESP_OK with the actual number of bytes read.
*/
if (req_bytes == 0) {
*read_bytes = 0;
return ESP_OK;
}

memcpy(buf, buf_rcv, *read_bytes);
vRingbufferReturnItem(ringbuf_hdl, (void *)(buf_rcv));
size_t total_read = 0;
TickType_t start_ticks = xTaskGetTickCount();

size_t read_bytes2 = 0;
if (*read_bytes < req_bytes) {
buf_rcv = xRingbufferReceiveUpTo(ringbuf_hdl, &read_bytes2, 0, req_bytes - *read_bytes);
if (buf_rcv) {
memcpy(buf + *read_bytes, buf_rcv, read_bytes2);
*read_bytes += read_bytes2;
vRingbufferReturnItem(ringbuf_hdl, (void *)(buf_rcv));
while (total_read < req_bytes) {
size_t chunk_read = 0;
size_t want = req_bytes - total_read;

/* compute remaining ticks to wait */
TickType_t elapsed = xTaskGetTickCount() - start_ticks;
TickType_t remain = 0;
if (ticks_to_wait == portMAX_DELAY) {
remain = portMAX_DELAY;
} else if (elapsed >= ticks_to_wait) {
remain = 0;
} else {
remain = ticks_to_wait - elapsed;
}

uint8_t *buf_rcv = xRingbufferReceiveUpTo(ringbuf_hdl, &chunk_read, remain, want);

if (!buf_rcv) {
/* nothing available within remaining timeout */
break;
}

/* copy received chunk */
memcpy(buf + total_read, buf_rcv, chunk_read);
vRingbufferReturnItem(ringbuf_hdl, (void *)buf_rcv);
total_read += chunk_read;
if (chunk_read == 0) {
/* defensive: in case the chunk is zero length */
break;
}
}

if (total_read == 0) {
return ESP_ERR_TIMEOUT;
}

*read_bytes = total_read;
return ESP_OK;
}

Expand Down Expand Up @@ -2385,11 +2418,7 @@ esp_err_t uac_host_device_read(uac_host_device_handle_t uac_dev_handle, uint8_t
}
uac_host_interface_unlock(iface);

size_t data_len = _ring_buffer_get_len(iface->ringbuf);
if (data_len > size) {
data_len = size;
}
esp_err_t ret = _ring_buffer_pop(iface->ringbuf, data, data_len, (size_t *)bytes_read, timeout);
esp_err_t ret = _ring_buffer_pop(iface->ringbuf, data, size, (size_t *)bytes_read, timeout);

if (ESP_OK != ret) {
ESP_LOGD(TAG, "RX Ringbuffer read failed");
Expand Down
Loading