USB HID play/pause working one way

Technical questions regarding the XTC tools and programming with XMOS.
en2senpai
Junior Member
Posts: 6
Joined: Mon Jul 19, 2021 7:32 am

USB HID play/pause working one way

Post by en2senpai »

Greetings,

Im currently working on USB Audio HID functionality of my device, and i've faced some strange behavior.

A PLAY/PAUSE functionality is working only one way (when the song is stopped - HID functionality will trigger it to start playing, but when the song is being played - HID functionality will NOT stop it as expected).

Do I need to report my changes more than one in a row ?

Here is my code snippet to test all needed functionalities (every 1000 requests from Host, device is simulating a HID action). Is this a proper way to handle this ?

Code: Select all

void UserReadHIDButtons(unsigned char hidData[])
{
    static int index = 0;

    index += 1;

    if (index == 1000)
    {
        hidData[0] = 0x02; // next track
    }
    else if (index == 2000)
    {
        hidData[0] = 0x04; // previous track
    }
    else if (index == 3000)
    {
        hidData[0] = 0x01; // play-pause
    }
    else if (index == 4000)
    {
        index = 0;
    }
}
Edit.
To test this, im using Tidal desktop app on Windows 10. Maybe this is a Tidal related issue ?
usb2.0
Member++
Posts: 17
Joined: Sat Dec 16, 2023 11:44 pm

Post by usb2.0 »

3 years and no one has replied to this. I have the same issue. I am trying to get HID to work with play/pause.
0x02 and 0x04 work for next and previous, but those are not the real HID codes. I don't understand why they would do this, but the authors of the code chose to abstract the HID codes away so they just use some gray code to select the real codes:
/* Write HID Report Data into hidData array
*
* Bits are as follows:
* 0: Play/Pause
* 1: Scan Next Track
* 2: Scan Prev Track
* 3: Volume Up
* 4: Volume Down
* 5: Mute
*/

That would be fine except that it doesn't work! And there is no obvious place to go to fix it ourselves... 0x01 only plays. It won't pause after the song has started playing.
usb2.0
Member++
Posts: 17
Joined: Sat Dec 16, 2023 11:44 pm

Post by usb2.0 »

sw_usb_audio\app_usb_aud_xk_316_mc\src\hid_report_descriptor.h

line 113
for play/pause:
.item.data = { 0xCD, 0x00 },
User avatar
Ross
Verified
XCore Legend
Posts: 1154
Joined: Thu Dec 10, 2009 9:20 pm
Location: Bristol, UK

Post by Ross »

In the code the original post refers to (6.15 I assume) It's not really abstracted using "grey codes", you're building up the packet sent back to the host matching the report descriptor. the command is actually just set to play by the looks of it (https://github.com/xmos/sc_usb_audio/bl ... ors.h#L549) . It should be changed to play/pause if you want that functionality but he code should be changed to guard against not sending multiple play/pause events on a single button press.

In the later codebases the implementation has been changed heavily.
Technical Director @ XMOS. Opinions expressed are my own
User avatar
Ross
Verified
XCore Legend
Posts: 1154
Joined: Thu Dec 10, 2009 9:20 pm
Location: Bristol, UK

Post by Ross »

usb2.0 wrote: Sat Jun 01, 2024 8:18 am sw_usb_audio\app_usb_aud_xk_316_mc\src\hid_report_descriptor.h

line 113
for play/pause:
.item.data = { 0xCD, 0x00 },
În future please provide permalinks to github repos when possible, otherwise its pretty hard to know what versions etc you're talking about.
Technical Director @ XMOS. Opinions expressed are my own
usb2.0
Member++
Posts: 17
Joined: Sat Dec 16, 2023 11:44 pm

Post by usb2.0 »

Hi Ross,

I am using sw_usb_audio version 7.3.1
The link you posted is not working.

What version are you referring to having the implementation changed? I see version 8.0 has been released now. It only has 1 known issue:
Known Issues
Currently this application uses the internal Application PLL to generate fixed master clock frequencies only. Therefore syncing to any external stream is not possible (i.e. ADAT/SPDIF Rx)