Author Topic: Control Reads of specific data records  (Read 5316 times)

Doug D.

  • Member
  • ***
  • Posts: 16
Control Reads of specific data records
« on: July 30, 2018, 03:50:26 pm »
Jan,

I'm designing a Full-Speed USB 2.0 HID device which stores data in a 256-record, C-structure array.  The USB host application must provide the device with an index into its array, and then the device will send that record to the host.

I'm favoring using control transfers because the requests will be sporadic, and because I don't want to read records out of their requested sequence.  The report size is the same for all records in the array, but I'd rather not have 256 different report descriptors.

What is the best way to do this?  Figure 3-2 in the 3rd edition of USB Complete depicts Control Read transfers.  The Setup Transaction shows that the host sends 8 bytes of data to the device.  Can I use one of those data bytes to send the array index to the device for that transfer?

If not, I may have to do it in two transfers.  First I'd send the device the array index in one transfer, and then do a Control Read (Feature?) of the desired record in a second transfer.  If I do it this way, is there a chance that the first transfer might not complete, leaving me to read the wrong record in the second transfer?





Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Control Reads of specific data records
« Reply #1 on: July 30, 2018, 10:17:43 pm »
In the Setup stage, the data packet specifies the request number, whether or not the transfer has a Data stage, and if so, in which direction the data will travel.

To request a specific sequence number, issue a Control Write transfer containing the sequence number, then a Control Read transfer to get the requested data. The application can request the Control Read transfer after the Control Write succeeds.


Doug D.

  • Member
  • ***
  • Posts: 16
Re: Control Reads of specific data records
« Reply #2 on: July 31, 2018, 10:58:20 am »
Thanks for pointing me in the right direction.  I will wait until the Control Write succeeds before requesting the record.  Which of your Example HID applications would be better for waiting on a Control Write like this--the Filestream ReadAsync/WriteAsync approach, or the ReadFile/WriteFile approach?

In a 2012 post, you once recommended using Feature reports for any data you want to send via control transfers only.  I also need to exchange about a dozen other data reports of different sizes (but all under 64 bytes) via control transfers.  Would it be better to use "HidD_GetInputReport" and "HidD_SetOutputReport" Control Input and Output transfers, or to use "HidD_GetFeature" and "HidD_SetFeature" Control Feature transfers?

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Control Reads of specific data records
« Reply #3 on: August 02, 2018, 07:19:40 pm »
Use these

HidD_GetFeature Read a Feature report.
HidD_GetInputReport Read an Input report using a control transfer.
HidD_SetFeature Send a Feature report.
HidD_SetOutputReport Send an Output report using a control transfer.

The only difference is that Input/Output reports also have the option to send/receive using interrupt transfers.

Doug D.

  • Member
  • ***
  • Posts: 16
Re: Control Reads of specific data records
« Reply #4 on: August 03, 2018, 11:23:36 am »
Okay.  I had missed that (Table 13-3) in your book, which shows that ReadFile and WriteFile (assuming there is an Interrupt OUT endpoint) are for interrupt transfers only.  I'll probably use Input/Output reports instead of Feature reports though, because of the different sizes of my reports.

Thanks again for your help!

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Control Reads of specific data records
« Reply #5 on: August 03, 2018, 10:00:33 pm »
You're welcome!