<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
	<link rel="self" type="application/atom+xml" href="https://forums.obdev.at/app.php/feed/topic/10493" />

	<title>Objective Development Forums</title>
	
	<link href="https://forums.obdev.at/index.php" />
	<updated>2016-06-27T17:36:45+02:00</updated>

	<author><name><![CDATA[Objective Development Forums]]></name></author>
	<id>https://forums.obdev.at/app.php/feed/topic/10493</id>

		<entry>
		<author><name><![CDATA[sriharir_91]]></name></author>
		<updated>2016-06-27T17:36:45+02:00</updated>

		<published>2016-06-27T17:36:45+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=10493&amp;p=31297#p31297</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=10493&amp;p=31297#p31297"/>
		<title type="html"><![CDATA[V USB HID data logger]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=10493&amp;p=31297#p31297"><![CDATA[
Hi, I have been trying to build a HID keyboard device that types out sensor values. But before that I wanted my device to type out random values onto a notepad. I used to Easylogger code as reference to construct my device descriptor (After a lot of trials I got the following descriptor to work) but it doesnt print out anything on the notepad. Despite a lot of googling, I haven't been able to understand fully what the usbfunctionsetup() does exactly (I checked the usbconfig.h, Maybe I am not experienced in embedded systems yet to understand it). Kindly help. the code is below:<br /><br /><div class="codebox"><p>Code: </p><pre><code>PROGMEM const char usbHidReportDescriptor&#91;USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH&#93; = <br />{<br />    0x05, 0x01,                    //    USAGE_PAGE (Generic Desktop)<br />    0x09, 0x06,                    //   USAGE (Keyboard)<br />    0xa1, 0x01,                    //   COLLECTION (Application)<br />    0x05, 0x07,                    //   USAGE_PAGE (Keyboard)<br />    0x19, 0xe0,                    //   USAGE_MINIMUM (Keyboard LeftControl)<br />    0x29, 0xe7,                    //   USAGE_MAXIMUM (Keyboard Right GUI)<br />    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)<br />    0x25, 0x01,                    //   LOGICAL_MAXIMUM (1)<br />    0x75, 0x01,                    //   REPORT_SIZE (1)<br />    0x95, 0x08,                    //   REPORT_COUNT (8)<br />    0x81, 0x02,                    //   INPUT (Data,Var,Abs)<br />    0x95, 0x01,                    //   REPORT_COUNT (1)<br />    0x75, 0x08,                    //   REPORT_SIZE (8)<br />    0x25, 0x65,                    //   LOGICAL_MAXIMUM (101)<br />    0x19, 0x00,                    //   USAGE_MINIMUM (Reserved (no event indicated))<br />    0x29, 0x65,                    //   USAGE_MAXIMUM (Keyboard Application)<br />    0x81, 0x00,                    //   INPUT (Data,Ary,Abs)<br />    0xc0                           //    END_COLLECTION<br />};<br />//Buffer for logs<br />struct LOG_ENTRY<br />{<br />    unsigned char hour;<br />    unsigned char minute;<br />    unsigned char second;<br />    unsigned char day;<br />    unsigned char month;<br />    unsigned char year;<br />    unsigned char percentage;<br />}logs&#91;50&#93;;<br /> <br />void buff_log()<br />{<br />            int j;<br />            for(j=0;j&lt;50;j++)<br />            {<br />                logs&#91;j&#93;.hour=0xff;<br />                logs&#91;j&#93;.minute=0xff;<br />                logs&#91;j&#93;.second=0xff;<br />                logs&#91;j&#93;.day=0xff;<br />                logs&#91;j&#93;.month=0xff;<br />                logs&#91;j&#93;.year=0xff;<br />                logs&#91;j&#93;.percentage=0xff;<br />        }<br />        /*    <br />        }//End of if() block<br />    }//end of while() polling loop<br />    */<br />}//End of buff_log()<br /> <br />static void buildReport(int i, int j)<br />{    <br />    memset(reportBuffer,'\0',sizeof(reportBuffer));<br />    if(j==0) {reportBuffer&#91;0&#93;=logs&#91;i&#93;.hour;}            else if(j==1) { reportBuffer&#91;1&#93;=logs&#91;i&#93;.minute; }<br />    else if(j==2) { reportBuffer&#91;1&#93;=logs&#91;i&#93;.second; }    else if(j==3) { reportBuffer&#91;1&#93;=logs&#91;i&#93;.day; }<br />    else if(j==4) { reportBuffer&#91;1&#93;=logs&#91;i&#93;.month; }    else if(j==5) { reportBuffer&#91;1&#93;=logs&#91;i&#93;.year; }<br />    else if(j==6) { reportBuffer&#91;1&#93;=logs&#91;i&#93;.percentage; }        else if(j==7) { reportBuffer&#91;1&#93;=0; }<br />}<br /> <br />USB_PUBLIC uchar usbFunctionSetup(uchar data&#91;8&#93;) <br />{<br />    usbRequest_t *rq = (void *)data;                    //Casting the data to correct type<br />        <br />        usbMsgPtr =  reportBuffer;<br />        <br />        if((rq-&gt;bmRequestType &amp; USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS)<br />        {                                                // class request type<br />            if(rq-&gt;bRequest == USBRQ_HID_GET_REPORT)    // wValue: ReportType (highbyte), ReportID (lowbyte) <br />            {  <br />                buildReport(0,0);                            // we only have one report type, so don't look at wValue<br />                return sizeof(reportBuffer);            // The entire buffer has to be sent at one shot. <br />            }<br />                <br />            else if(rq-&gt;bRequest == USBRQ_HID_GET_IDLE)<br />            {<br />                usbMsgPtr = &amp;idleRate;<br />                return 1;<br />            }<br />            <br />            else if(rq-&gt;bRequest == USBRQ_HID_SET_IDLE)<br />            {<br />                idleRate = rq-&gt;wValue.bytes&#91;1&#93;;<br />            }<br />        }<br />        <br />        else<br />        {<br />            /* no vendor specific requests implemented */<br />        }<br />       <br />    return 0;                                            //Since data is in static RAM, we don't need usbFunctionWrite() <br />}<br /> <br />int main(void)<br />{<br />    int j=0;<br />/******************************************* Initialization***************************************/    <br />    io_init();<br />    buff_log();                //To retrieve logs from the main controller unit<br />    odDebugInit();<br />    <br />    usbDeviceDisconnect();    //Enforce enumeration by disconnecting and connecting for the first time<br />    <br />    for(j=0;j&lt;20;j++)        // 300 ms disconnect - Comment during simulation<br />    {    <br />        _delay_ms(15);<br />    }<br />    <br />    usbDeviceConnect();<br />    wdt_enable(WDTO_1S);    //Enable the watchdog timer<br />    usbInit();<br />    sei();<br />/*******************************************Loop forever*******************************************/    <br />    <br />    while(1)<br />    {    <br />        wdt_reset();                    //Reset the watchdog timer<br />        usbPoll();<br />             <br />        if(usbInterruptIsReady()&amp;&amp;i&lt;50)        // we can send another data<br />        { <br />                <br />            for(j=0;j&lt;8;j++)    <br />            {<br />                buildReport(i,j);<br />                usbSetInterrupt(reportBuffer, sizeof(reportBuffer));<br />            }<br />            i++;                <br />        }<br />        <br />    }//End of while(1) Infinite loop<br />/*************************************************************************************************/    <br />return 0;<br />}//End of main()<br /></code></pre></div><p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=22095">sriharir_91</a> — Mon Jun 27, 2016 5:36 pm</p><hr />
]]></content>
	</entry>
	</feed>
