Skip to content

Commit 26e3caf

Browse files
refactor(uac_host): Suspend/Resume public API terminology
- Replaced suspend/resume with pause/unpuase terminology - Preparation for suspend/resume support
1 parent cb5670d commit 26e3caf

File tree

6 files changed

+52
-46
lines changed

6 files changed

+52
-46
lines changed

host/class/uac/usb_host_uac/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this component will be documented in this file.
44

55
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).
66

7+
## [unreleased]
8+
9+
### Changed
10+
11+
- Changed API terminology from suspend/resume to pause/unpause as pre-requisite for root port suspend/resume feature
12+
713
## [1.3.3] - 2025-11-27
814

915
### Changed

host/class/uac/usb_host_uac/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ The following steps outline the typical API call pattern of the UAC Class Driver
2424
06. To enable/disable data streaming with specific audio format use:
2525
- `uac_host_device_start()`
2626
- `uac_host_device_stop()`
27-
07. To suspend/resume data streaming use:
28-
- `uac_host_device_suspend()`
29-
- `uac_host_device_resume()`
27+
07. To pause/unpause data streaming use:
28+
- `uac_host_device_pause()`
29+
- `uac_host_device_unpause()`
3030
08. To control the volume/mute use:
3131
- `uac_host_device_set_mute()`
3232
09. To control the volume use:

host/class/uac/usb_host_uac/examples/audio_player/main/main.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,11 @@ static void mic_palyback_done_cb(void)
199199
{
200200
vTaskDelay(pdMS_TO_TICKS(1000)); // wait for a while before resuming recording
201201
if (s_mic_dev_handle != NULL) {
202-
if (uac_host_device_resume(s_mic_dev_handle) == ESP_OK) {
202+
if (uac_host_device_unpause(s_mic_dev_handle) == ESP_OK) {
203203
s_mic_recording = true;
204204
s_mic_record_wr = 0;
205205
} else {
206-
ESP_LOGE(TAG, "Failed to resume MIC device");
206+
ESP_LOGE(TAG, "Failed to unpause MIC device");
207207
}
208208
}
209209
}
@@ -396,16 +396,16 @@ static void uac_lib_task(void *arg)
396396
if (s_mic_record_wr >= s_mic_record_buf_size) {
397397
if (s_spk_dev_handle != NULL) {
398398
s_mic_recording = false;
399-
// Suspend microphone streaming before playback
400-
uac_host_device_suspend(s_mic_dev_handle);
399+
// Pause microphone streaming before playback
400+
uac_host_device_pause(s_mic_dev_handle);
401401
// Prepare playback of the recorded PCM
402402
player_config_t player_config = {
403403
.pcm_ptr = s_mic_record_buf,
404404
.pcm_size = s_mic_record_buf_size,
405405
.complete_cb = mic_palyback_done_cb,
406406
};
407407
if (start_pcm_playback(&player_config) != ESP_OK) {
408-
uac_host_device_resume(s_mic_dev_handle);
408+
uac_host_device_unpause(s_mic_dev_handle);
409409
s_mic_recording = true;
410410
s_mic_record_wr = 0;
411411
}

host/class/uac/usb_host_uac/include/usb/uac_host.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ extern "C" {
3131
/**
3232
* @brief Flags to control stream work flow
3333
*
34-
* FLAG_STREAM_SUSPEND_AFTER_START: do not start stream transfer during start, only claim interface and prepare memory
35-
* @note User should call uac_host_device_resume to start stream transfer when needed
34+
* FLAG_STREAM_PAUSE_AFTER_START: do not start stream transfer during start, only claim interface and prepare memory
35+
* @note User should call uac_host_device_unpause to start stream transfer when needed
3636
*/
37-
#define FLAG_STREAM_SUSPEND_AFTER_START (1 << 0)
37+
#define FLAG_STREAM_PAUSE_AFTER_START (1 << 0)
3838

3939
typedef struct uac_interface *uac_host_device_handle_t; /*!< Logic Device Handle. Handle to a particular UAC interface */
4040

@@ -303,7 +303,7 @@ esp_err_t uac_host_handle_events(TickType_t timeout);
303303
/**
304304
* @brief Start a UAC stream with specific stream configuration (channels, bit resolution, sample frequency)
305305
*
306-
* @note set flags FLAG_STREAM_SUSPEND_AFTER_START to suspend stream after start
306+
* @note set flags FLAG_STREAM_PAUSE_AFTER_START to pause stream after start
307307
*
308308
* @param[in] uac_dev_handle UAC device handle
309309
* @param[in] stream_config Pointer to UAC stream configuration structure
@@ -318,26 +318,26 @@ esp_err_t uac_host_handle_events(TickType_t timeout);
318318
esp_err_t uac_host_device_start(uac_host_device_handle_t uac_dev_handle, const uac_host_stream_config_t *stream_config);
319319

320320
/**
321-
* @brief Suspend a UAC stream
321+
* @brief Pause a UAC stream
322322
*
323323
* @param[in] uac_dev_handle UAC device handle
324324
* @return esp_err_t
325325
* - ESP_OK on success
326326
* - ESP_ERR_INVALID_ARG if the device handle is invalid
327327
* - ESP_ERR_INVALID_STATE if the device is not in the right state
328328
*/
329-
esp_err_t uac_host_device_suspend(uac_host_device_handle_t uac_dev_handle);
329+
esp_err_t uac_host_device_pause(uac_host_device_handle_t uac_dev_handle);
330330

331331
/**
332-
* @brief Resume a UAC stream with same stream configuration
332+
* @brief Unpause a UAC stream with same stream configuration
333333
*
334334
* @param[in] uac_dev_handle UAC device handle
335335
* @return esp_err_t
336336
* - ESP_OK on success
337337
* - ESP_ERR_INVALID_ARG if the device handle is invalid
338338
* - ESP_ERR_INVALID_STATE if the device is not in the right state
339339
*/
340-
esp_err_t uac_host_device_resume(uac_host_device_handle_t uac_dev_handle);
340+
esp_err_t uac_host_device_unpause(uac_host_device_handle_t uac_dev_handle);
341341

342342
/**
343343
* @brief Stop a UAC stream, stream resources will be released

host/class/uac/usb_host_uac/test_app/main/test_host_uac.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ TEST_CASE("test uac tx writing", "[uac_host][tx]")
602602
.channels = spk_alt_params.channels,
603603
.bit_resolution = spk_alt_params.bit_resolution,
604604
.sample_freq = spk_alt_params.sample_freq[0],
605-
.flags = FLAG_STREAM_SUSPEND_AFTER_START,
605+
.flags = FLAG_STREAM_PAUSE_AFTER_START,
606606
};
607607
TEST_ASSERT_EQUAL(ESP_OK, uac_host_device_start(uac_device_handle, &stream_config));
608608

@@ -669,7 +669,7 @@ TEST_CASE("test uac tx writing", "[uac_host][tx]")
669669
TEST_ASSERT_EQUAL(ESP_OK, uac_host_device_get_volume(uac_device_handle, &actual_volume));
670670
volume = actual_volume;
671671
printf("Volume: %d \n", volume);
672-
TEST_ASSERT_EQUAL(ESP_OK, uac_host_device_resume(uac_device_handle));
672+
TEST_ASSERT_EQUAL(ESP_OK, uac_host_device_unpause(uac_device_handle));
673673
TEST_ASSERT_EQUAL(ESP_OK, uac_host_device_write(uac_device_handle, (uint8_t *)tx_buffer, tx_size, 0));
674674

675675
uint8_t test_counter = 0;
@@ -779,7 +779,7 @@ TEST_CASE("test uac tx rx loopback", "[uac_host][tx][rx]")
779779
.channels = mic_alt_params.channels,
780780
.bit_resolution = mic_alt_params.bit_resolution,
781781
.sample_freq = mic_alt_params.sample_freq[0],
782-
.flags = FLAG_STREAM_SUSPEND_AFTER_START,
782+
.flags = FLAG_STREAM_PAUSE_AFTER_START,
783783
};
784784

785785
uint8_t actual_volume = 0;
@@ -831,8 +831,8 @@ TEST_CASE("test uac tx rx loopback", "[uac_host][tx][rx]")
831831
uint32_t test_counter = 0;
832832
event_queue_t evt_queue = {0};
833833
while (1) {
834-
TEST_ASSERT_EQUAL(ESP_OK, uac_host_device_resume(mic_device_handle));
835-
TEST_ASSERT_EQUAL(ESP_OK, uac_host_device_resume(spk_device_handle));
834+
TEST_ASSERT_EQUAL(ESP_OK, uac_host_device_unpause(mic_device_handle));
835+
TEST_ASSERT_EQUAL(ESP_OK, uac_host_device_unpause(spk_device_handle));
836836
while (1) {
837837
if (xQueueReceive(s_event_queue, &evt_queue, portMAX_DELAY)) {
838838
TEST_ASSERT_EQUAL(UAC_DEVICE_EVENT, evt_queue.event_group);
@@ -885,8 +885,8 @@ TEST_CASE("test uac tx rx loopback", "[uac_host][tx][rx]")
885885
if (++test_counter >= test_times) {
886886
goto exit_rx;
887887
}
888-
TEST_ASSERT_EQUAL(ESP_OK, uac_host_device_suspend(mic_device_handle));
889-
TEST_ASSERT_EQUAL(ESP_OK, uac_host_device_suspend(spk_device_handle));
888+
TEST_ASSERT_EQUAL(ESP_OK, uac_host_device_pause(mic_device_handle));
889+
TEST_ASSERT_EQUAL(ESP_OK, uac_host_device_pause(spk_device_handle));
890890
time_counter = 0;
891891
vTaskDelay(100);
892892
}
@@ -938,7 +938,7 @@ TEST_CASE("test uac tx rx loopback with disconnect", "[uac_host][tx][rx][hot-plu
938938
.channels = mic_alt_params.channels,
939939
.bit_resolution = mic_alt_params.bit_resolution,
940940
.sample_freq = mic_alt_params.sample_freq[0],
941-
.flags = FLAG_STREAM_SUSPEND_AFTER_START,
941+
.flags = FLAG_STREAM_PAUSE_AFTER_START,
942942
};
943943
TEST_ASSERT_EQUAL(ESP_OK, uac_host_device_start(mic_device_handle, &stream_config));
944944
TEST_ASSERT_EQUAL(ESP_OK, uac_host_device_set_mute(mic_device_handle, 0));
@@ -979,8 +979,8 @@ TEST_CASE("test uac tx rx loopback with disconnect", "[uac_host][tx][rx][hot-plu
979979
uint32_t test_counter = 0;
980980
event_queue_t evt_queue = {0};
981981
while (1) {
982-
TEST_ASSERT_EQUAL(ESP_OK, uac_host_device_resume(mic_device_handle));
983-
TEST_ASSERT_EQUAL(ESP_OK, uac_host_device_resume(spk_device_handle));
982+
TEST_ASSERT_EQUAL(ESP_OK, uac_host_device_unpause(mic_device_handle));
983+
TEST_ASSERT_EQUAL(ESP_OK, uac_host_device_unpause(spk_device_handle));
984984
while (1) {
985985
if (xQueueReceive(s_event_queue, &evt_queue, portMAX_DELAY)) {
986986
TEST_ASSERT_EQUAL(UAC_DEVICE_EVENT, evt_queue.event_group);
@@ -1033,8 +1033,8 @@ TEST_CASE("test uac tx rx loopback with disconnect", "[uac_host][tx][rx][hot-plu
10331033
if (++test_counter >= test_times) {
10341034
goto exit_rx;
10351035
}
1036-
TEST_ASSERT_EQUAL(ESP_OK, uac_host_device_suspend(mic_device_handle));
1037-
TEST_ASSERT_EQUAL(ESP_OK, uac_host_device_suspend(spk_device_handle));
1036+
TEST_ASSERT_EQUAL(ESP_OK, uac_host_device_pause(mic_device_handle));
1037+
TEST_ASSERT_EQUAL(ESP_OK, uac_host_device_pause(spk_device_handle));
10381038
time_counter = 0;
10391039
vTaskDelay(100);
10401040
}

host/class/uac/usb_host_uac/uac_host.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ typedef struct uac_host_device {
124124
typedef enum {
125125
UAC_INTERFACE_STATE_NOT_INITIALIZED = 0x00, /*!< UAC Interface not initialized */
126126
UAC_INTERFACE_STATE_IDLE, /*!< UAC Interface has been opened but not started */
127-
UAC_INTERFACE_STATE_READY, /*!< UAC Interface has started but stream is suspended */
127+
UAC_INTERFACE_STATE_READY, /*!< UAC Interface has started but stream is paused */
128128
UAC_INTERFACE_STATE_ACTIVE, /*!< UAC Interface is streaming */
129-
UAC_INTERFACE_STATE_SUSPENDING, /*!< UAC Interface is suspending */
129+
UAC_INTERFACE_STATE_PAUSING, /*!< UAC Interface is pausing */
130130
} uac_iface_state_t;
131131

132132
/**
@@ -1332,19 +1332,19 @@ static void stream_tx_xfer_done(usb_transfer_t *out_xfer)
13321332
}
13331333

13341334
/**
1335-
* @brief Suspend active interface, the interface will be in READY state
1335+
* @brief Pause active interface, the interface will be in READY state
13361336
*
13371337
* @param[in] iface Pointer to Interface structure
13381338
* @return esp_err_t
13391339
*/
1340-
static esp_err_t uac_host_interface_suspend(uac_iface_t *iface)
1340+
static esp_err_t uac_host_interface_pause(uac_iface_t *iface)
13411341
{
13421342
UAC_RETURN_ON_INVALID_ARG(iface);
13431343
UAC_RETURN_ON_INVALID_ARG(iface->parent);
13441344
UAC_RETURN_ON_INVALID_ARG(iface->free_xfer_list);
13451345
UAC_RETURN_ON_FALSE(is_interface_in_list(iface), ESP_ERR_NOT_FOUND, "Interface handle not found");
13461346
UAC_RETURN_ON_FALSE((UAC_INTERFACE_STATE_ACTIVE == iface->state), ESP_ERR_INVALID_STATE, "Interface wrong state");
1347-
iface->state = UAC_INTERFACE_STATE_SUSPENDING;
1347+
iface->state = UAC_INTERFACE_STATE_PAUSING;
13481348

13491349
// Set Interface alternate setting to 0
13501350
usb_setup_packet_t usb_request;
@@ -1355,9 +1355,9 @@ static esp_err_t uac_host_interface_suspend(uac_iface_t *iface)
13551355
memcpy(&uac_request, &usb_request, sizeof(usb_setup_packet_t));
13561356
esp_err_t ret = uac_cs_request_set(iface->parent, &uac_request);
13571357
if (ret != ESP_OK) {
1358-
ESP_LOGW(TAG, "Suspend Interface %d-%d Failed", iface->dev_info.iface_num, 0);
1358+
ESP_LOGW(TAG, "Pause Interface %d-%d Failed", iface->dev_info.iface_num, 0);
13591359
} else {
1360-
ESP_LOGI(TAG, "Suspend Interface %d-%d", iface->dev_info.iface_num, 0);
1360+
ESP_LOGI(TAG, "Pause Interface %d-%d", iface->dev_info.iface_num, 0);
13611361
}
13621362

13631363
uint8_t ep_addr = iface->iface_alt[iface->cur_alt].ep_addr;
@@ -1382,12 +1382,12 @@ static esp_err_t uac_host_interface_suspend(uac_iface_t *iface)
13821382
}
13831383

13841384
/**
1385-
* @brief Resume suspended interface, the interface will be in ACTIVE state
1385+
* @brief Unpause paused interface, the interface will be in ACTIVE state
13861386
*
13871387
* @param[in] iface Pointer to Interface structure
13881388
* @return esp_err_t
13891389
*/
1390-
static esp_err_t uac_host_interface_resume(uac_iface_t *iface)
1390+
static esp_err_t uac_host_interface_unpause(uac_iface_t *iface)
13911391
{
13921392
UAC_RETURN_ON_INVALID_ARG(iface);
13931393
UAC_RETURN_ON_INVALID_ARG(iface->parent);
@@ -1403,7 +1403,7 @@ static esp_err_t uac_host_interface_resume(uac_iface_t *iface)
14031403
uac_cs_request_t uac_request = {0};
14041404
memcpy(&uac_request, &usb_request, sizeof(usb_setup_packet_t));
14051405
UAC_RETURN_ON_ERROR(uac_cs_request_set(iface->parent, &uac_request), "Unable to set Interface alternate");
1406-
ESP_LOGI(TAG, "Resume Interface %d-%d", iface->dev_info.iface_num, iface->cur_alt + 1);
1406+
ESP_LOGI(TAG, "Unpause Interface %d-%d", iface->dev_info.iface_num, iface->cur_alt + 1);
14071407
// Set endpoint frequency control
14081408
if (iface->iface_alt[iface->cur_alt].freq_ctrl_supported) {
14091409
ESP_LOGI(TAG, "Set EP %d frequency %"PRIu32, iface->iface_alt[iface->cur_alt].ep_addr & USB_B_ENDPOINT_ADDRESS_EP_NUM_MASK, iface->iface_alt[iface->cur_alt].cur_sampling_freq);
@@ -2201,7 +2201,7 @@ esp_err_t uac_host_device_close(uac_host_device_handle_t uac_dev_handle)
22012201

22022202
UAC_RETURN_ON_ERROR(uac_host_interface_try_lock(uac_iface, DEFAULT_CTRL_XFER_TIMEOUT_MS), "UAC Interface is busy by other task");
22032203
if (UAC_INTERFACE_STATE_ACTIVE == uac_iface->state) {
2204-
UAC_GOTO_ON_ERROR(uac_host_interface_suspend(uac_iface), "Unable to disable UAC Interface");
2204+
UAC_GOTO_ON_ERROR(uac_host_interface_pause(uac_iface), "Unable to disable UAC Interface");
22052205
}
22062206

22072207
if (UAC_INTERFACE_STATE_READY == uac_iface->state) {
@@ -2372,8 +2372,8 @@ esp_err_t uac_host_device_start(uac_host_device_handle_t uac_dev_handle, const u
23722372
UAC_GOTO_ON_ERROR(uac_host_interface_claim_and_prepare_transfer(iface), "Unable to claim Interface");
23732373
iface_claimed = true;
23742374

2375-
if (!(iface->flags & FLAG_STREAM_SUSPEND_AFTER_START)) {
2376-
UAC_GOTO_ON_ERROR(uac_host_interface_resume(iface), "Unable to enable UAC Interface");
2375+
if (!(iface->flags & FLAG_STREAM_PAUSE_AFTER_START)) {
2376+
UAC_GOTO_ON_ERROR(uac_host_interface_unpause(iface), "Unable to enable UAC Interface");
23772377
}
23782378
uac_host_interface_unlock(iface);
23792379
return ESP_OK;
@@ -2386,7 +2386,7 @@ esp_err_t uac_host_device_start(uac_host_device_handle_t uac_dev_handle, const u
23862386
return ret;
23872387
}
23882388

2389-
esp_err_t uac_host_device_suspend(uac_host_device_handle_t uac_dev_handle)
2389+
esp_err_t uac_host_device_pause(uac_host_device_handle_t uac_dev_handle)
23902390
{
23912391
uac_iface_t *iface = get_iface_by_handle(uac_dev_handle);
23922392
UAC_RETURN_ON_INVALID_ARG(iface);
@@ -2398,7 +2398,7 @@ esp_err_t uac_host_device_suspend(uac_host_device_handle_t uac_dev_handle)
23982398
}
23992399
esp_err_t ret = ESP_OK;
24002400
UAC_GOTO_ON_FALSE((UAC_INTERFACE_STATE_ACTIVE == iface->state), ESP_ERR_INVALID_STATE, "device not active");
2401-
UAC_GOTO_ON_ERROR(uac_host_interface_suspend(iface), "Unable to disable UAC Interface");
2401+
UAC_GOTO_ON_ERROR(uac_host_interface_pause(iface), "Unable to disable UAC Interface");
24022402

24032403
uac_host_interface_unlock(iface);
24042404
return ESP_OK;
@@ -2408,7 +2408,7 @@ esp_err_t uac_host_device_suspend(uac_host_device_handle_t uac_dev_handle)
24082408
return ret;
24092409
}
24102410

2411-
esp_err_t uac_host_device_resume(uac_host_device_handle_t uac_dev_handle)
2411+
esp_err_t uac_host_device_unpause(uac_host_device_handle_t uac_dev_handle)
24122412
{
24132413
uac_iface_t *iface = get_iface_by_handle(uac_dev_handle);
24142414
UAC_RETURN_ON_INVALID_ARG(iface);
@@ -2421,7 +2421,7 @@ esp_err_t uac_host_device_resume(uac_host_device_handle_t uac_dev_handle)
24212421

24222422
esp_err_t ret = ESP_OK;
24232423
UAC_GOTO_ON_FALSE((UAC_INTERFACE_STATE_READY == iface->state), ESP_ERR_INVALID_STATE, "device not ready");
2424-
UAC_GOTO_ON_ERROR(uac_host_interface_resume(iface), "Unable to enable UAC Interface");
2424+
UAC_GOTO_ON_ERROR(uac_host_interface_unpause(iface), "Unable to enable UAC Interface");
24252425

24262426
uac_host_interface_unlock(iface);
24272427
return ESP_OK;
@@ -2439,7 +2439,7 @@ esp_err_t uac_host_device_stop(uac_host_device_handle_t uac_dev_handle)
24392439
esp_err_t ret = ESP_OK;
24402440
UAC_RETURN_ON_ERROR(uac_host_interface_try_lock(iface, DEFAULT_CTRL_XFER_TIMEOUT_MS), "Unable to lock UAC Interface");
24412441
if (UAC_INTERFACE_STATE_ACTIVE == iface->state) {
2442-
UAC_GOTO_ON_ERROR(uac_host_interface_suspend(iface), "Unable to disable UAC Interface");
2442+
UAC_GOTO_ON_ERROR(uac_host_interface_pause(iface), "Unable to disable UAC Interface");
24432443
}
24442444

24452445
if (UAC_INTERFACE_STATE_READY == iface->state) {

0 commit comments

Comments
 (0)