<?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/10383" />

	<title>Objective Development Forums</title>
	
	<link href="https://forums.obdev.at/index.php" />
	<updated>2016-04-19T20:16:02+02:00</updated>

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

		<entry>
		<author><name><![CDATA[Anonymous]]></name></author>
		<updated>2016-04-19T20:16:02+02:00</updated>

		<published>2016-04-19T20:16:02+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=10383&amp;p=31093#p31093</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=10383&amp;p=31093#p31093"/>
		<title type="html"><![CDATA[using usbPoll and usbSetInterrupt]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=10383&amp;p=31093#p31093"><![CDATA[
I'm pretty new to the VUSB library and the USB.. making a Wireless HID mouse <br /><br />I'm .unable to program the RX ATmega8 properly .. which has the USB Connection<br /><br />i'm reieving data on UART of ATMega8 through Polling and sending the data into report buffer .. but nothing is happening .. <br />Some times it gets disconnected too...<br /><br />Can anyone suggest a better way of using the library's usbPoll() and setInterrupt() functions ..<br /><br />CODE:<br /><br />/*<br />* HID VUSB WIRELESS MOUSE.c<br />*<br />* Created: 4/16/2016 3:52:10 PM<br />* Author : Akash<br />*/<br /><br />//////////////////////////////////////////////////////////////////////////<br />//Defines<br />//////////////////////////////////////////////////////////////////////////<br />#defineF_CPU16000000UL<br />#definetrue0x01<br />#definefalse0x00<br />#defineucharunsigned char<br />#define uintunsigned int<br /><br />#define START_SYNC_BYTE0b10101010<br />#define END_SYNC_BYTE0b01010101<br /><br />#define RECIEVE_BUFF_MAX 4<br />//////////////////////////////////////////////////////////////////////////<br /><br />#include &lt;avr/io.h&gt;<br />#include &lt;avr/wdt.h&gt;<br />#include &lt;avr/interrupt.h&gt;<br />#include &lt;stdbool.h&gt;<br />#include &lt;util/delay.h&gt;<br /><br />#include &quot;uart/UART.h&quot;<br />#include &quot;usbdrv/usbdrv.h&quot;<br /><br />//////////////////////////////////////////////////////////////////////////<br />//GLOBAL VARIABLES<br />//////////////////////////////////////////////////////////////////////////<br />uint recieveBuffer[RECIEVE_BUFF_MAX];<br />bool TransmissionComplete = false;<br />uchar i=0;<br />//////////////////////////////////////////////////////////////////////////<br /><br /><br /><br />PROGMEM const char usbHidReportDescriptor[52] =<br />{ /* USB report descriptor, size must match usbconfig.h */<br />0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)<br />0x09, 0x02,                    // USAGE (Mouse)<br />0xa1, 0x01,                    // COLLECTION (Application)<br />0x09, 0x01,                    //   USAGE (Pointer)<br />0xA1, 0x00,                    //   COLLECTION (Physical)<br />0x05, 0x09,                    //     USAGE_PAGE (Button)<br />0x19, 0x01,                    //     USAGE_MINIMUM<br />0x29, 0x03,                    //     USAGE_MAXIMUM<br />0x15, 0x00,                    //     LOGICAL_MINIMUM (0)<br />0x25, 0x01,                    //     LOGICAL_MAXIMUM (1)<br />0x95, 0x03,                    //     REPORT_COUNT (3)<br />0x75, 0x01,                    //     REPORT_SIZE (1)<br />0x81, 0x02,                    //     INPUT (Data,Var,Abs)<br />0x95, 0x01,                    //     REPORT_COUNT (1)<br />0x75, 0x05,                    //     REPORT_SIZE (5)<br />0x81, 0x03,                    //     INPUT (Const,Var,Abs)<br />0x05, 0x01,                    //     USAGE_PAGE (Generic Desktop)<br />0x09, 0x30,                    //     USAGE (X)<br />0x09, 0x31,                    //     USAGE (Y)<br />0x09, 0x38,                    //     USAGE (Wheel)<br />0x15, 0x81,                    //     LOGICAL_MINIMUM (-127)<br />0x25, 0x7F,                    //     LOGICAL_MAXIMUM (127)<br />0x75, 0x08,                    //     REPORT_SIZE (8)<br />0x95, 0x03,                    //     REPORT_COUNT (3)<br />0x81, 0x06,                    //     INPUT (Data,Var,Rel)<br />0xC0,                          //   END_COLLECTION<br />0xC0,                          // END COLLECTION<br />};<br /><br />typedef struct{<br />uchar   buttonMask;<br />char    dx;<br />char    dy;<br />char    dWheel;<br />}report_t;<br /><br /><br />static report_t reportBuffer;<br />static uchar    idleRate;<br /><br />usbMsgLen_t usbFunctionSetup(uchar data[8])<br />{<br />usbRequest_t    *rq = (void *)data;<br /><br />/* The following requests are never used. But since they are required by<br />* the specification, we implement them in this example.<br />*/<br />if((rq-&gt;bmRequestType &amp; USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS){    /* class request type */<br />if(rq-&gt;bRequest == USBRQ_HID_GET_REPORT){  /* wValue: ReportType (highbyte), ReportID (lowbyte) */<br />/* we only have one report type, so don't look at wValue */<br />usbMsgPtr = (void *)&amp;reportBuffer;<br />return sizeof(reportBuffer);<br />}else if(rq-&gt;bRequest == USBRQ_HID_GET_IDLE){<br />usbMsgPtr = &amp;idleRate;<br />return 1;<br />}else if(rq-&gt;bRequest == USBRQ_HID_SET_IDLE){<br />idleRate = rq-&gt;wValue.bytes[1];<br />}<br />}<br />else{<br />/* no vendor specific requests implemented */<br />}<br />return 0;   /* default for not implemented requests: return no data back to host */<br />}<br /><br /><br /><br />int main(void)<br />{<br />wdt_enable(WDTO_1S);<br /><br />DDRC=0xff;<br /><br />//Initializing to Reciever at 9600 bps<br />UART_Init(9600 , false , true , true);<br /><br />for(i=0;i&lt;RECIEVE_BUFF_MAX;i++){<br />recieveBuffer[i]= 0;}<br /><br />usbInit();<br /><br />usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */<br />while(--i)<br />{             /* fake USB disconnect for &gt; 250 ms */<br />wdt_reset();<br />_delay_ms(1);<br />}<br />usbDeviceConnect();<br /><br /><br />sei();<br /><br />while(1)<br />{<br />wdt_reset();<br /><br />usbPoll();<br /><br />RecieveUARTdata();<br /><br />if(TransmissionComplete &amp;&amp; usbInterruptIsReady()){<br />usbSetInterrupt( recieveBuffer , sizeof(reportBuffer) );<br />}<br />}<br />return 0;<br />}<br /><br />void ResetValues(){<br />recieveBuffer[0] = 0;<br />recieveBuffer[1] = 0;<br />recieveBuffer[2] = 0;<br />recieveBuffer[3] = 0;<br />}<br /><br />void SetHIDReport( uint *recieveBuffer )<br />{<br />reportBuffer.dx= recieveBuffer[0];<br />reportBuffer.dy= recieveBuffer[1];<br />reportBuffer.buttonMask = recieveBuffer[2];<br />reportBuffer.dWheel= recieveBuffer[3];<br />}<br /><br />void ClearHIDReport( )<br />{<br />reportBuffer.dx= 0;<br />reportBuffer.dy= 0;<br />reportBuffer.buttonMask = 0;<br />reportBuffer.dWheel= 0;<br />}<br /><br />void RecieveUARTdata(){<br />//Get the data if available by checking the RXC in UCSRA<br />if ( UCSRA &amp; (1&lt;&lt;RXC) )<br />{<br />//Get the data<br />uchar data = UDR;<br />if (data==START_SYNC_BYTE)<br />{<br />i=0;<br />}<br />else<br />{<br />if (data != END_SYNC_BYTE )<br />{<br />recieveBuffer[i] = data;<br />i++;<br />if(i==RECIEVE_BUFF_MAX ){<br />PORTC ^= 0xff;<br />TransmissionComplete = true;<br />i=0;<br />}<br />}<br />else i=0;<br />}<br /><br />}<br />}<br /><br />Here is another question:<br /> so USbPOll() must be called every 5ms?<br />how do i do that ..  can i use a Timer ? if so how to make sure the Timer interrupt and the USB interrupt dont coincide..<p>Statistics: Posted by Guest — Tue Apr 19, 2016 8:16 pm</p><hr />
]]></content>
	</entry>
	</feed>
