<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>USB: sending an structure on InReport instead of BYTE typedef</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/23953/usb-sending-an-structure-on-inreport-instead-of-byte-typedef</link><description> 
I want to know how to modify the next function to send an
structure and no the typedef BYTE; 

 
USB_WriteEP(0x81,InReport, sizeof(InReport));
 

 
 
the structure is: 

 
typedef struct{
unsigned char Header;
RTC_TIME TStamp; // Timestamp Hs,Ms,Ss</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: USB: sending an structure on InReport instead of BYTE typedef</title><link>https://community.arm.com/thread/114262?ContentTypeID=1</link><pubDate>Wed, 17 Sep 2008 14:55:51 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:6ca2f053-4cc4-4166-95a4-ea1e5bc8577d</guid><dc:creator>Maximiliano Brarda</dc:creator><description>&lt;p&gt;&lt;p&gt;
Thank You for the options&lt;/p&gt;

&lt;p&gt;
The last one works fine, but the others are very interesting
too..&lt;/p&gt;

&lt;p&gt;
Thanks again ;)&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: USB: sending an structure on InReport instead of BYTE typedef</title><link>https://community.arm.com/thread/101082?ContentTypeID=1</link><pubDate>Sat, 13 Sep 2008 05:11:07 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:4757f67a-096e-40bc-bb9e-07e70559e555</guid><dc:creator>Tsuneo Chinzei</dc:creator><description>&lt;p&gt;&lt;p&gt;
Agree Per, it ensures the portability/ reusability of the
code.&lt;/p&gt;

&lt;p&gt;
Anyway, the bottom line is holding a precise description of each
byte of the packet, on a document.&lt;br /&gt;
The choice is at your own policy.&lt;/p&gt;

&lt;p&gt;
Tsuneo&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: USB: sending an structure on InReport instead of BYTE typedef</title><link>https://community.arm.com/thread/89273?ContentTypeID=1</link><pubDate>Sat, 13 Sep 2008 04:37:45 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:a8c0a193-72a5-4b6c-ba4e-b1b809c4af4f</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
The fourth alternative is to manually write code to repack the
struct into a raw array of bytes, according to a - by you -
predefined byte order.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: USB: sending an structure on InReport instead of BYTE typedef</title><link>https://community.arm.com/thread/52438?ContentTypeID=1</link><pubDate>Sat, 13 Sep 2008 04:24:23 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:2d043939-b8cd-4305-ab46-957fcb797c03</guid><dc:creator>Tsuneo Chinzei</dc:creator><description>&lt;p&gt;&lt;p&gt;
You can send any buffer, including structure, using
USB_WriteEP()&lt;/p&gt;

&lt;pre&gt;
typedef struct{
unsigned char   Header;
RTC_TIME TStamp;        // Timestamp Hs,Ms,Ss,mS.
unsigned char IMU[18];
}S_IMUPACKET;

S_IMUPACKET InReport_of_struct;

USB_WriteEP(0x81, &amp;amp;InReport_of_struct, sizeof(InReport_of_struct));
&lt;/pre&gt;

&lt;p&gt;
Of course, you have to declare this size of input report in the
report descriptor, if you are working on HID.&lt;/p&gt;

&lt;pre&gt;
#define INREPORT_SIZE    sizeof(InReport_of_struct)

/* HID Report Descriptor */
const BYTE HID_ReportDescriptor[] = {
  HID_UsagePageVendor( 0x00                                   ),
  HID_Usage(           0x01                                   ),
  HID_Collection(      HID_Application                        ),
    HID_LogicalMin(    0                                      ),
    HID_LogicalMaxS(   0xFF                                   ),
    HID_ReportSize(    8                                      ),  // bits
    HID_ReportCount(   INREPORT_SIZE                          ),  // bytes
    HID_Usage(         0x01                                   ),
    HID_Input(         HID_Data | HID_Variable | HID_Absolute ),
  HID_EndCollection,
};
&lt;/pre&gt;

&lt;p&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The problem lies in the handling of the word alignment and padding of
members of the structure.&lt;br /&gt;
On the firmware side, there are three strategy.&lt;/p&gt;

&lt;p&gt;
a) Apply &amp;#39;natural&amp;#39; alignment with padding, send it as is, convert
it on the host app side&lt;br /&gt;
b) Convert natural alignment to the packed one just before sending
the structure to the host&lt;br /&gt;
c) Apply packed one throughout the firmware.&lt;/p&gt;

&lt;p&gt;
I can&amp;#39;t tell which one is better for a) and b), though c) seems
too inefficient.&lt;br /&gt;
a) increases the required bandwidth of USB communication, but it is
trivial for HID.&lt;/p&gt;

&lt;p&gt;
Other than above packed structure, the problem lies in the
difference of the byte order for the compilers of the firmware and
host app.&lt;/p&gt;

&lt;p&gt;
Tsuneo&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>