UserReadHIDButtons : read port fails Topic is solved

Technical questions regarding the XTC tools and programming with XMOS.
bonelli
Member++
Posts: 19
Joined: Wed Feb 03, 2021 9:06 pm

Post by bonelli »

Finally, the following code is working, but is it clean and safe ?

params is a 9 bits concatenation of my two 4 bits ports connected to the switches + 1 mode bit.

Code: Select all

void UserReadHIDButtons(unsigned char hidData[],  streaming chanend c_params) // Called every 4ms - Tile 1
{
    unsigned int params = 0;

    select{
       case c_params :> params:
          printf("UserReadHIDButtons : params=0x%X\n", params);
          break;

       default:
          break;
    }

 ...


View Solution
bonelli
Member++
Posts: 19
Joined: Wed Feb 03, 2021 9:06 pm

Post by bonelli »

oups, this is working quite fine but not perfectly.

Code: Select all

#define HID_CONTROL_NEXT  0x02
#define HID_CONTROL_PLAYPAUSE   0x01
#define HID_CONTROL_PREV            0x04
#define HID_CONTROL_VOLUP          0x08
#define HID_CONTROL_VOLDN         0x10
#define HID_CONTROL_MUTE           0x20
All are working excepted HID_CONTROL_PLAYPAUSE.
- If the song is paused, HID_CONTROL_PLAYPAUSE resumes the song, as expected
- But if the song is played, HID_CONTROL_PLAYPAUSE restarts the song from the beginning

This time, not sure if the problem is not on the windows side...
User avatar
fabriceo
XCore Addict
Posts: 186
Joined: Mon Jan 08, 2018 4:14 pm

Post by fabriceo »

When you send a data or token over a channel, the underlying controller will send 3 bytes before that as part of the protocol.
Then a pipeline is created between the sender and the receiver (called link or Xlink).
Then the data is/are sent.
When the transmission is finished, you are supposed to send a CT_END token which will close the transmission and release the pipeline for other client tasks.
there are only 4 possible pipeline/xlink between 2 tiles. So normally it is important to release them quickly so that another task could use them.
With a streaming channel, this is the same protocole but the pipeline is kept "locked" all the time between the sender/receiver and then there is less overhead in the protocol so you can have faster streams, and by definition you do not need to send the CT_END token.
User avatar
Ross
XCore Expert
Posts: 968
Joined: Thu Dec 10, 2009 9:20 pm
Location: Bristol, UK

Post by Ross »

bonelli wrote: Sun Jun 11, 2023 9:10 pm oups, this is working quite fine but not perfectly.

Code: Select all

#define HID_CONTROL_NEXT  0x02
#define HID_CONTROL_PLAYPAUSE   0x01
#define HID_CONTROL_PREV            0x04
#define HID_CONTROL_VOLUP          0x08
#define HID_CONTROL_VOLDN         0x10
#define HID_CONTROL_MUTE           0x20
All are working excepted HID_CONTROL_PLAYPAUSE.
- If the song is paused, HID_CONTROL_PLAYPAUSE resumes the song, as expected
- But if the song is played, HID_CONTROL_PLAYPAUSE restarts the song from the beginning

This time, not sure if the problem is not on the windows side...
What version of the USB Audio code are you based off? Seems that the HID usage is set to "play" rather than "play/pause"
bonelli
Member++
Posts: 19
Joined: Wed Feb 03, 2021 9:06 pm

Post by bonelli »

fabriceo wrote: Mon Jun 12, 2023 7:15 am When you send a data or token over a channel...
Thank you very much fabriceo for this clarification! :)
Ross wrote: Mon Jun 12, 2023 12:26 pm What version of the USB Audio code are you based off? Seems that the HID usage is set to "play" rather than "play/pause"
v6.15.2. It looks to be the latest version.