Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Azure RTOS USBX audio class 2.0 #9

Closed
ayedm1 opened this issue Mar 22, 2021 · 6 comments
Closed

Azure RTOS USBX audio class 2.0 #9

ayedm1 opened this issue Mar 22, 2021 · 6 comments

Comments

@ayedm1
Copy link
Contributor

ayedm1 commented Mar 22, 2021

Hi All,

I’m Currently working on an USBx audio application with an stm32H743i. I have some point for support & enhancement .

I found a mistake when registering audio class in MS website https://docs.microsoft.com/fr-fr/azure/rtos/usbx/usbx-device-stack-supplemental-2#usb-device-audio-class

image

Support.

issue
I can’t enumerate my audio2.0 device.

Enhance
In “ux_device_class_audio20_control_process.c” file it’s possible to set WRES in applicative side by user when host request FU_VOLUME_CONTROL?

image

For feature unit control selectors macros in “ux_device_class_audio20.h” it is possible to change it like Audio device Class Specification.

For Example change UX_DEVICE_CLASS_AUDIO20_FU_MUTE_CONTROL 0x01 to 0x03

image

Screenshot from audio20 spec sheet 59

image

Regards,
Mohamed

@xiaocq2001
Copy link
Contributor

  1. About document, thanks for reporting this, we will update that.
  2. About enumerate, it seems host stopped the process (since there seems no error in trace log), maybe their is some issue in descriptors or request returns that host is not compatible.
    Following is example descriptor, initializing and request handling for USB Audio 2.0 speaker:
#define D3(d) ((UCHAR)((d) >> 24))
#define D2(d) ((UCHAR)((d) >> 16))
#define D1(d) ((UCHAR)((d) >> 8))
#define D0(d) ((UCHAR)((d) >> 0))
/* --------------------------------------- Device Descriptor  */
/* 0  bLength, bDescriptorType                                */ 18,   0x01,
/* 2  bcdUSB                                                  */ D0(0x200),D1(0x200),
/* 4  bDeviceClass, bDeviceSubClass, bDeviceProtocol          */ 0x00, 0x00, 0x00,
/* 7  bMaxPacketSize0                                         */ 0x08,
/* 8  idVendor, idProduct                                     */ 0x84, 0x84, 0x03, 0x00,
/* 12 bcdDevice                                               */ D0(0x200),D1(0x200),
/* 14 iManufacturer, iProduct, iSerialNumber                  */ 0,    0,    0,
/* 17 bNumConfigurations                                      */ 1,

/* ----------------------------- Device Qualifier Descriptor  */
/* 0 bLength, bDescriptorType                                 */ 10,                 0x06,
/* 2 bcdUSB                                                   */ D0(0x200),D1(0x200),
/* 4 bDeviceClass, bDeviceSubClass, bDeviceProtocol           */ 0x00,               0x00, 0x00,
/* 7 bMaxPacketSize0                                          */ 8,
/* 8 bNumConfigurations                                       */ 1,
/* 9 bReserved                                                */ 0,

/* -------------------------------- Configuration Descriptor  *//* 9+8+73+55=145 */
/* 0 bLength, bDescriptorType                                 */ 9,    0x02,
/* 2 wTotalLength                                             */ D0(145),D1(145),
/* 4 bNumInterfaces, bConfigurationValue                      */ 2,    1,
/* 6 iConfiguration                                           */ 0,
/* 7 bmAttributes, bMaxPower                                  */ 0x80, 50,

/* ------------------------ Interface Association Descriptor  */
/* 0 bLength, bDescriptorType                                 */ 8,    0x0B,
/* 2 bFirstInterface, bInterfaceCount                         */ 0,    2,
/* 4 bFunctionClass, bFunctionSubClass, bFunctionProtocol     */ 0x01, 0x00, 0x20,
/* 7 iFunction                                                */ 0,

/* ------------------------------------ Interface Descriptor  *//* 0 Control (9+64=73) */
/* 0 bLength, bDescriptorType                                 */ 9,    0x04,
/* 2 bInterfaceNumber, bAlternateSetting                      */ 0,    0,
/* 4 bNumEndpoints                                            */ 0,
/* 5 bInterfaceClass, bInterfaceSubClass, bInterfaceProtocol  */ 0x01, 0x01, 0x20,
/* 8 iInterface                                               */ 0,
/* ---------------- Audio 2.0 AC Interface Header Descriptor *//* (9+8+17+18+12=64) */
/* 0 bLength, bDescriptorType, bDescriptorSubtype            */ 9,                   0x24, 0x01,
/* 3 bcdADC, bCategory                                       */ D0(0x200),D1(0x200), 0x08,
/* 6 wTotalLength                                            */ D0(64),D1(64),
/* 8 bmControls                                              */ 0x00,
/* -------------------- Audio 2.0 AC Clock Source Descriptor */
/* 0 bLength, bDescriptorType, bDescriptorSubtype            */ 8,    0x24, 0x0A,
/* 3 bClockID, bmAttributes, bmControls                      */ 0x10, 0x05, 0x01,
/* 6 bAssocTerminal, iClockSource                            */ 0x00, 0,
/* ------------------- Audio 2.0 AC Input Terminal Descriptor */
/* 0  bLength, bDescriptorType, bDescriptorSubtype            */ 17,   0x24,                   0x02,
/* 3  bTerminalID, wTerminalType                              */ 0x04, D0(0x0101),D1(0x0101),
/* 6  bAssocTerminal, bCSourceID                              */ 0x00, 0x10,
/* 8  bNrChannels, bmChannelConfig                            */ UX_DEMO_NB_CHANNEL, D0(0),D1(0),D2(0),D3(0),
/* 13 iChannelNames, bmControls, iTerminal                    */ 0,    D0(0),D1(0),            0,
/* --------------------- Audio 2.0 AC Feature Unit Descriptor */
/* 0  bLength, bDescriptorType, bDescriptorSubtype            */ 18,   0x24, 0x06,
/* 3  bUnitID, bSourceID                                      */ 0x05, 0x04,
/* 5  bmaControls(0), bmaControls(...) ...                    */ D0(0xF),D1(0xF),D2(0xF),D3(0xF), D0(0),D1(0),D2(0),D3(0), D0(0),D1(0),D2(0),D3(0),
/* .  iFeature                                                */ 0,
/* ------------------ Audio 2.0 AC Output Terminal Descriptor */
/* 0  bLength, bDescriptorType, bDescriptorSubtype            */ 12,          0x24,                 0x03,
/* 3  bTerminalID, wTerminalType                              */ 0x06,        D0(0x0301),D1(0x0301),
/* 6  bAssocTerminal, bSourceID, bCSourceID                   */ 0x00,        0x05,                 0x10,
/* 9  bmControls, iTerminal                                   */ D0(0),D1(0), 0,

/* ------------------------------------ Interface Descriptor  *//* 1 Stream OUT (9+9+16+6+7+8=55) */
/* 0 bLength, bDescriptorType                                 */ 9,    0x04,
/* 2 bInterfaceNumber, bAlternateSetting                      */ 1,    0,
/* 4 bNumEndpoints                                            */ 0,
/* 5 bInterfaceClass, bInterfaceSubClass, bInterfaceProtocol  */ 0x01, 0x02, 0x20,
/* 8 iInterface                                               */ 0,
/* ------------------------------------ Interface Descriptor  */
/* 0 bLength, bDescriptorType                                 */ 9,    0x04,
/* 2 bInterfaceNumber, bAlternateSetting                      */ 1,    1,
/* 4 bNumEndpoints                                            */ 1,
/* 5 bInterfaceClass, bInterfaceSubClass, bInterfaceProtocol  */ 0x01, 0x02, 0x20,
/* 8 iInterface                                               */ 0,
/* ------------------------ Audio 2.0 AS Interface Descriptor */
/* 0  bLength, bDescriptorType, bDescriptorSubtype            */ 16,  0x24, 0x01,
/* 3  bTerminalLink, bmControls                               */ 0x04,0x00,
/* 5  bFormatType, bmFormats                                  */ 0x01,D0(1),D1(1),D2(1),D3(1),
/* 10 bNrChannels, bmChannelConfig                            */ UX_DEMO_NB_CHANNEL,   D0(0),D1(0),D2(0),D3(0),
/* 15 iChannelNames                                           */ 0,
/* ---------------------- Audio 2.0 AS Format Type Descriptor */
/* 0  bLength, bDescriptorType, bDescriptorSubtype            */ 6,    0x24, 0x02,
/* 3  bFormatType, bSubslotSize, bBitResolution               */ 0x01, UX_DEMO_SAMPLE_SIZE,    16,
/* ------------------------------------- Endpoint Descriptor */
/* 0  bLength, bDescriptorType                                */ 7,               0x05,
/* 2  bEndpointAddress, bmAttributes                          */ 0x02,            0x0D,
/* 4  wMaxPacketSize, bInterval                               */ D0(UX_DEMO_MAX_FRAME_SIZE),D1(UX_DEMO_MAX_FRAME_SIZE), 4,
/* ---------- Audio 2.0 AS ISO Audio Data Endpoint Descriptor */
/* 0  bLength, bDescriptorType, bDescriptorSubtype            */ 8,    0x25,      0x01,
/* 3  bmAttributes, bmControls                                */ 0x00, 0x00,
/* 5  bLockDelayUnits, wLockDelay                             */ 0x00, D0(0),D1(0),
    /* Initialize audio 2.0 control values.  */
    audio_control[0].ux_device_class_audio20_control_cs_id                = 0x10;
    audio_control[0].ux_device_class_audio20_control_sampling_frequency   = UX_DEMO_SAMPLING_FREQUENCY;
    audio_control[0].ux_device_class_audio20_control_fu_id                = 0x05;
    audio_control[0].ux_device_class_audio20_control_mute[0]              = 0;
    audio_control[0].ux_device_class_audio20_control_volume_min[0]        = UX_DEMO_VOLUME_MIN;
    audio_control[0].ux_device_class_audio20_control_volume_max[0]        = UX_DEMO_VOLUME_MAX;
    /* audio_control[0].ux_device_class_audio20_control_volume_res[0]        = UX_DEMO_VOLUME_RES; */
    audio_control[0].ux_device_class_audio20_control_volume[0]            = UX_DEMO_VOLUME_DEFAULT;

    /* Set the parameters for Audio streams.  */
    audio_stream_parameter[0].ux_device_class_audio_stream_parameter_callbacks.ux_device_class_audio_stream_change     = demo_audio_read_change;
    audio_stream_parameter[0].ux_device_class_audio_stream_parameter_callbacks.ux_device_class_audio_stream_frame_done = demo_audio_read_done;
    audio_stream_parameter[0].ux_device_class_audio_stream_parameter_max_frame_buffer_nb   = UX_DEMO_FRAME_BUFFER_NB;
    audio_stream_parameter[0].ux_device_class_audio_stream_parameter_max_frame_buffer_size = UX_DEMO_MAX_FRAME_SIZE;
    audio_stream_parameter[0].ux_device_class_audio_stream_parameter_thread_entry = ux_device_class_audio_read_thread_entry;

    /* Set the parameters for Audio device.  */
    audio_parameter.ux_device_class_audio_parameter_streams_nb  = 1;
    audio_parameter.ux_device_class_audio_parameter_streams     = audio_stream_parameter;
    audio_parameter.ux_device_class_audio_parameter_callbacks.ux_slave_class_audio_instance_activate   = demo_audio_instance_activate;
    audio_parameter.ux_device_class_audio_parameter_callbacks.ux_slave_class_audio_instance_deactivate = demo_audio_instance_deactivate;
    audio_parameter.ux_device_class_audio_parameter_callbacks.ux_device_class_audio_control_process    = demo_audio20_request_process;

    /* Initialize the device Audio class. This class owns both interfaces starting with 0. */
     status =  ux_device_stack_class_register(_ux_system_slave_class_audio_name, ux_device_class_audio_entry,
                                              1, 0, &audio_parameter);
    if(status!=UX_SUCCESS)
        return;
UX_DEVICE_CLASS_AUDIO20_CONTROL         audio_control[1];
UINT    demo_audio20_request_process(UX_DEVICE_CLASS_AUDIO *audio, UX_SLAVE_TRANSFER *transfer)
{

UINT                                    status;
UX_DEVICE_CLASS_AUDIO20_CONTROL_GROUP   group = {1, audio_control};


    /* Handle request and update control values.
       Note here only mute and volume for master channel is supported.
     */
    status = ux_device_class_audio20_control_process(audio, transfer, &group);
    if (status == UX_SUCCESS)
    {
        /* Request handled, check changes */
        switch(audio_control[0].ux_device_class_audio20_control_changed)
        {
        case UX_DEVICE_CLASS_AUDIO20_CONTROL_MUTE_CHANGED:
            tx_event_flags_set(&demo_play_events, UX_DEMO_EVENT_MUTE, TX_OR);
            break;
        case UX_DEVICE_CLASS_AUDIO20_CONTROL_VOLUME_CHANGED:
            tx_event_flags_set(&demo_play_events, UX_DEMO_EVENT_VOLUME, TX_OR);
            break;
        default:
            break;
        }
    }
    return(status);
}
  1. Thanks for the suggestion to support wRES, we will add that in our basic request handling function. Note that since their are so many audio entities we are not able to do support for all of them, you can do request handling in demo_audio20_request_process anyway, to have specific things supported.
  2. UX_DEVICE_CLASS_AUDIO20_FU_MUTE_CONTROL is actually for Control Selectors in Table A-23, Section A.17.7 but NOT bmaControls bits, the bmaControls bits are not defined.

@ayedm1
Copy link
Contributor Author

ayedm1 commented Mar 25, 2021

Hi CQ Xiao,

Thank you for this feedback. Can you please share with me this macro value to test if i have the same Behaviour :).

UX_DEMO_FRAME_BUFFER_NB,
UX_DEMO_MAX_FRAME_SIZE,
UX_DEMO_SAMPLE_SIZE

Regards
Mohamed

@xiaocq2001
Copy link
Contributor

#define UX_DEMO_SAMPLING_FREQUENCY          AUDIO_FREQUENCY_44K /* from ST BSP */
#define UX_DEMO_NB_CHANNEL                  2
#define UX_DEMO_SAMPLE_SIZE                 2
#define UX_DEMO_SUBFRAME_SIZE               (UX_DEMO_SAMPLE_SIZE * UX_DEMO_NB_CHANNEL)
#define UX_DEMO_FRAME_NB_SUBS               (UX_DEMO_SAMPLING_FREQUENCY / 1000)
#define UX_DEMO_FRAME_SIZE                  (UX_DEMO_FRAME_NB_SUBS * UX_DEMO_SUBFRAME_SIZE)

#define UX_DEMO_MAX_FRAME_SIZE              256
#define UX_DEMO_FRAME_BUFFER_NB             2

#define UX_DEMO_VOLUME_MIN                  -32767
#define UX_DEMO_VOLUME_MAX                  32767
#define UX_DEMO_VOLUME_RES                  1
#define UX_DEMO_VOLUME_DEFAULT              0

@yuxin-azrtos
Copy link
Contributor

@ayedm1 any updates?

@ayedm1
Copy link
Contributor Author

ayedm1 commented Apr 14, 2021

Hi @yuxin-azrtos, for me enumeration is OK. I will continue to dev my app now.

@yuxin-azrtos
Copy link
Contributor

@ayedm1 Thanks! Let us know if you have additional questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants