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

	<title>Objective Development Forums</title>
	
	<link href="https://forums.obdev.at/index.php" />
	<updated>2009-01-29T20:14:02+02:00</updated>

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

		<entry>
		<author><name><![CDATA[mschumann]]></name></author>
		<updated>2009-01-29T20:14:02+02:00</updated>

		<published>2009-01-29T20:14:02+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=2173&amp;p=7715#p7715</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=2173&amp;p=7715#p7715"/>
		<title type="html"><![CDATA[ATMEGA 32, LibUSB Win32 and Delphi - Access Denied]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=2173&amp;p=7715#p7715"><![CDATA[
Using an ATMEGA32 at 16MHz I implemented (g)LCD, DCF77 and RC5 for an HTPC Controller. Everything works quite well but the Host USB side gets stuck after transferring some or more remote control codes. LibUSB then delivers -5 (access denied as far as I found out). I use LibUSB for Windows 32 and Libusb.pas (delphi 7). I suspect the rc5 code from <!-- m --><a class="postlink" href="http://www.roboternetz.de/wissen/index.php/RC5-Decoder_f%C3%BCr_ATMega">http://www.roboternetz.de/wissen/index. ... BCr_ATMega</a><!-- m --> to interfer with the usbdrv. Of course rc5 uses a different hardware interrupt. <br /><br />The effect is reproducable if the remote control goes into repeating a key thats held down but sometimes it works quite a while. I tried using the Jedi VCL components for HID devices to avoid LibUSB but they just wouldnt receive anything although they perfectly connect to the device.<br /><br />These are the key routines, any help is very appreciated since I am relatively new to usb. Thanks in advance!<br /><br />// USB globale Variablen<br />static uchar usbrec[128];<br />static int8_t usbcmd[4] = {0,0,0,0};<br />static uchar bytesRemaining, currentPosition;<br /><br /><br />usbMsgLen_t usbFunctionSetup(uchar data[8]) {<br /><br />usbRequest_t    *rq = (void *)data;<br /><br />    // HID-Class Request<br />    if ((rq-&gt;bmRequestType &amp; USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS) {  <br />        <br />if (rq-&gt;bRequest == USBRQ_HID_GET_REPORT) {  <br /><br />if (usbcmd[3]!=0) {<br />usbMsgPtr = usbcmd;<br />usbcmd[3]=0; // Gesendet markieren<br />return sizeof(usbcmd);<br />} else {<br />                // Da libsub Probleme hat mit 0 Byte Reports<br />                usbcmd[0]=0;<br />usbMsgPtr = usbcmd;<br />return sizeof(usbcmd);<br />}<br /><br />        } else if(rq-&gt;bRequest == USBRQ_HID_SET_REPORT) {<br /><br />// Empfangen geht über usbFunctionWrite()<br />currentPosition = 0;               <br />// Puffer leeren<br />for (uchar i=0; i&lt;sizeof(usbrec); i++) <br />usbrec[i] = 0;<br />bytesRemaining = rq-&gt;wLength.word;  <br />// Länge begrenzen<br />if(bytesRemaining &gt; sizeof(usbrec)) <br />bytesRemaining = sizeof(usbrec);<br />            // Empfangen macht usbFunctionWrite()<br />return USB_NO_MSG;        <br />}<br />    }<br />    return 0;<br />}<br /><br /><br />// Daten vom Host empfangen und im Puffer übertragen<br />uchar usbFunctionWrite(uchar *data, uchar len)<br />{<br />    if(len &gt; bytesRemaining)                <br />        len = bytesRemaining;               <br />    bytesRemaining -= len;<br />for(uchar i = 0; i &lt; len; i++) <br />        usbrec[currentPosition++] = data[i];<br />if (bytesRemaining == 0) {<br />           // todo<br />   return 1;<br />       } else<br />return 0;<br />}<br /><br />and this is the device descriptor (stolen from the hiddata example):<br /><br />PROGMEM char usbHidReportDescriptor[22] = {    /* USB report descriptor */<br />    0x06, 0x00, 0xff,              // USAGE_PAGE (Generic Desktop)<br />    0x09, 0x01,                    // USAGE (Vendor Usage 1)<br />    0xa1, 0x01,                    // COLLECTION (Application)<br />    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)<br />    0x26, 0xff, 0x00,              //   LOGICAL_MAXIMUM (255)<br />    0x75, 0x20,                    //   REPORT_SIZE (8)<br />    0x95, 0x80,                    //   REPORT_COUNT (128)<br />    0x09, 0x00,                    //   USAGE (Undefined)<br />    0xb2, 0x02, 0x01,              //   FEATURE (Data,Var,Abs,Buf)<br />    0xc0                           // END_COLLECTION<br />};<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=1744">mschumann</a> — Thu Jan 29, 2009 8:14 pm</p><hr />
]]></content>
	</entry>
	</feed>
