From 0f84261d21a5223e5005bb33175e7bf4d1e2d334 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Fri, 28 Jul 2023 14:58:44 +0200 Subject: [PATCH] composite: Make the audio endpoints/interfaces optional There's now a HAVE_AUDIO #define in usb_descriptors.h, and it's disabled by default for now. --- composite/audio.c | 9 +++++++++ composite/usb_descriptors.c | 9 +++++++++ composite/usb_descriptors.h | 4 ++++ 3 files changed, 22 insertions(+) diff --git a/composite/audio.c b/composite/audio.c index ea09902..cef6bfc 100644 --- a/composite/audio.c +++ b/composite/audio.c @@ -7,6 +7,8 @@ #include "usb_descriptors.h" #include "class/audio/audio_device.h" +#ifdef HAVE_AUDIO + /* could also be 16kHz for AMR-WB calls? */ #define AUDIO_SAMPLE_RATE 8000 @@ -328,4 +330,11 @@ bool tud_audio_set_itf_close_EP_cb(uint8_t rhport, tusb_control_request_t const return true; } +#else /* HAVE_AUDIO */ +int audio_init(void) +{ + return 0; +} + +#endif /* HAVE_AUDIO */ diff --git a/composite/usb_descriptors.c b/composite/usb_descriptors.c index 2809cc6..864d9ec 100644 --- a/composite/usb_descriptors.c +++ b/composite/usb_descriptors.c @@ -40,16 +40,23 @@ uint8_t const* tud_descriptor_device_cb(void) /* Configuration Descriptor */ +#ifdef HAVE_AUDIO #define CONFIG_TOTAL_LEN \ (TUD_CONFIG_DESC_LEN + TUD_CARDEM_DESCRIPTOR_LEN + TUD_AUDIO_PHONE_MONO_DESCRIPTOR_LEN) +#else +#define CONFIG_TOTAL_LEN \ + (TUD_CONFIG_DESC_LEN + TUD_CARDEM_DESCRIPTOR_LEN) +#endif static uint8_t const desc_config[] = { // Config number, interface count, string index, total length, attribute, power in mA TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100), TUD_CARDEM_DESCRIPTOR(ITF_NUM_CARDEM, 4, /*epout*/ 0x01, /*epin*/ 0x81, /*epirq*/ 0x82), +#ifdef HAVE_AUDIO // interface number, string index, epout, epin, epsize, epfb TUD_AUDIO_PHONE_MONO_DESCRIPTOR(ITF_NUM_AUDIO_CTRL, 5, 0x02, 0x83, CFG_TUD_AUDIO_EP_SZ, 0x84), +#endif }; /* Invoked when received GET CONFIGURATION DESCRIPTOR */ @@ -66,7 +73,9 @@ char const *string_desc_arr[] = { "pico-pcm-cardem", /* 2: Product */ "12345", /* 3: Serial, should use chip ID */ "SIMtrace2 compatible card-emulation", /* 4: CARDEM */ +#ifdef HAVE_AUDIO "Cellular Modem PCM Audio", /* 5: Audio Interface */ +#endif }; static uint16_t _desc_str[32]; diff --git a/composite/usb_descriptors.h b/composite/usb_descriptors.h index b0af903..4ec3f5d 100644 --- a/composite/usb_descriptors.h +++ b/composite/usb_descriptors.h @@ -1,5 +1,7 @@ #pragma once +//#define HAVE_AUDIO + /* TODO: put into tinyusb */ #define AUDIO_TERM_TYPE_PH_PHONE_LINE 0x0501 @@ -90,8 +92,10 @@ /* Interface numbers */ enum { ITF_NUM_CARDEM = 0, +#ifdef HAVE_AUDIO ITF_NUM_AUDIO_CTRL, ITF_NUM_AUDIO_STREAM_OUT, ITF_NUM_AUDIO_STREAM_IN, +#endif ITF_NUM_TOTAL };