samples: subsys: usb: audio: Add volume control case

Add sample code for getting volume to headset sample and
headphone_microphone sample

Signed-off-by: Saw Xu <Saw1993@126.com>
This commit is contained in:
Saw Xu 2023-08-15 11:12:09 +08:00 committed by Carles Cufí
commit 8951bab7e7
4 changed files with 24 additions and 0 deletions

View file

@ -10,6 +10,11 @@
feature-mute;
channel-l;
channel-r;
feature-volume;
volume-max = <0x0500>;
volume-min = <0xBA00>;
volume-res = <0x100>;
};
mic_0 {
compatible = "usb-audio-mic";

View file

@ -45,10 +45,17 @@ static void data_received(const struct device *dev,
static void feature_update(const struct device *dev,
const struct usb_audio_fu_evt *evt)
{
int16_t volume = 0;
LOG_DBG("Control selector %d for channel %d updated",
evt->cs, evt->channel);
switch (evt->cs) {
case USB_AUDIO_FU_MUTE_CONTROL:
break;
case USB_AUDIO_FU_VOLUME_CONTROL:
volume = *((int16_t *)(evt->val));
LOG_INF("set volume: %d", volume);
break;
default:
break;
}

View file

@ -14,5 +14,10 @@
hp-feature-mute;
hp-channel-l;
hp-channel-r;
hp-feature-volume;
volume-max = <0x0500>;
volume-min = <0xBA00>;
volume-res = <0x100>;
};
};

View file

@ -43,10 +43,17 @@ static void data_received(const struct device *dev,
static void feature_update(const struct device *dev,
const struct usb_audio_fu_evt *evt)
{
int16_t volume = 0;
LOG_DBG("Control selector %d for channel %d updated",
evt->cs, evt->channel);
switch (evt->cs) {
case USB_AUDIO_FU_MUTE_CONTROL:
break;
case USB_AUDIO_FU_VOLUME_CONTROL:
volume = *((int16_t *)(evt->val));
LOG_INF("set volume: %d", volume);
break;
default:
break;
}