fix: usbaudio set_cur cmd set volume
This commit is contained in:
+10
-2
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "tusb.h"
|
||||
#include "bsp/board_api.h"
|
||||
#include "config.h"
|
||||
|
||||
uint8_t mute[2]; // 0: SPEAKER(0x02) 1: MIC(0x05)
|
||||
float volume[2] = {1.0f}; // 0: SPEAKER(0x02) 1: MIC(0x05)
|
||||
@@ -66,6 +67,11 @@ static bool audio10_set_req_entity(tusb_control_request_t const *p_request, uint
|
||||
TU_VERIFY(p_request->wLength == 2);
|
||||
|
||||
volume[index] = static_cast<float>(tu_unaligned_read16(pBuff)) / 256;
|
||||
if (entityID == UAC1_ENTITY_SPK_FEATURE_UNIT) {
|
||||
auto config = get_config();
|
||||
config.speaker_volume = volume[index];
|
||||
set_config(config);
|
||||
}
|
||||
|
||||
TU_LOG2(" Set Volume: %d dB of entity: %u\r\n", volume[index], entityID);
|
||||
return true;
|
||||
@@ -103,8 +109,10 @@ static bool audio10_get_req_entity(uint8_t rhport, tusb_control_request_t const
|
||||
switch (p_request->bRequest) {
|
||||
case AUDIO10_CS_REQ_GET_CUR:
|
||||
TU_LOG2(" Get Volume of entity: %u\r\n", entityID); {
|
||||
int16_t vol = volume[index];
|
||||
vol = vol * 256; // convert to 1/256 dB units
|
||||
if (entityID == UAC1_ENTITY_SPK_FEATURE_UNIT) {
|
||||
volume[index] = get_config().speaker_volume;
|
||||
}
|
||||
int16_t vol = volume[index] * 256; // convert to 1/256 dB units
|
||||
return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &vol, sizeof(vol));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user