Skip to content

Commit

Permalink
samples: subsys: usb: audio: Add volume control case
Browse files Browse the repository at this point in the history
Add sample code for getting volume to headset sample and
headphone_microphone sample

Signed-off-by: Saw Xu <Saw1993@126.com>
  • Loading branch information
SawXu committed Aug 15, 2023
1 parent aac7c8f commit 4c96dfe
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions samples/subsys/usb/audio/headphones_microphone/app.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
7 changes: 7 additions & 0 deletions samples/subsys/usb/audio/headphones_microphone/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 5 additions & 0 deletions samples/subsys/usb/audio/headset/app.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
};
};
7 changes: 7 additions & 0 deletions samples/subsys/usb/audio/headset/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 4c96dfe

Please sign in to comment.