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

	<title>Objective Development Forums</title>
	
	<link href="https://forums.obdev.at/index.php" />
	<updated>2012-01-21T15:26:52+02:00</updated>

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

		<entry>
		<author><name><![CDATA[Anonymous]]></name></author>
		<updated>2011-06-21T10:02:42+02:00</updated>

		<published>2011-06-21T10:02:42+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=5653&amp;p=18769#p18769</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=5653&amp;p=18769#p18769"/>
		<title type="html"><![CDATA[Re: HID keyboard atmega168p]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=5653&amp;p=18769#p18769"><![CDATA[
When a keyboard key is pressed, you send its code to the PC. Once sent, the code should be &quot;terminated&quot;, so the PC knows, that the key is released. So when the key is released, you should send to the PC 0x00 once in the keycode array index, that was used to send the key active.<p>Statistics: Posted by Guest — Tue Jun 21, 2011 10:02 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[subnex]]></name></author>
		<updated>2012-01-21T15:26:52+02:00 </updated>

		<published>2011-05-03T00:42:56+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=5653&amp;p=18357#p18357</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=5653&amp;p=18357#p18357"/>
		<title type="html"><![CDATA[HID keyboard atmega168p - Solved]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=5653&amp;p=18357#p18357"><![CDATA[
I am working on a HID keyboard on the atmega 168p running at 16 MHz.<br />So far, i've successfully transmittd keycommands to my computer, so that part is working.<br /><br />My problem is, that once i send a command, the avr just keeps transmitting the same command to the computer. I can't really figure out what is wrong.<br />My code is heavily inspired from the HID keyboard examples from the obdev.at site.<br /><br />My main looks like the following:<br /><br /><div class="codebox"><p>Code: </p><pre><code>#include &quot;common.h&quot;<br />#include &quot;keycodes.h&quot;<br /><br />#include &quot;avr/pgmspace.h&quot;<br />#include &quot;usbdrv/usbdrv.h&quot;<br />#include &quot;usbdrv/oddebug.h&quot;<br /><br />#define ReportDescriptor usbHidReportDescriptor<br /><br />PROGMEM<br />#include &quot;ir_keyboard_2.hid.h&quot; // reportdescriptor<br />#define STATIC_ASSERT(expr) extern char static_assert&#91; (!!(expr))*2 - 1&#93;<br /><br />STATIC_ASSERT(sizeof(usbHidReportDescriptor) == USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH);<br /><br />static uchar reportBuffer&#91;2&#93; = {0,0};<br />static uchar idleRate;<br />static uchar irKey = 0;<br />static uchar ir_key_pressed = 0;<br /><br />uchar irKeyLookup(uchar irkey){<br />  volatile uchar key = 0;<br />  switch(irkey){<br />  case 0x60: //prev<br />    key = 1;<br />    break;<br />  case 0xA0: // next<br />    key = 2;<br />    break;<br />  case 0x40: // stop<br />    key = 8;<br />    break;<br />  case 0x80: // play<br />    key = 4;<br />    break;<br />  default:<br />    key = 0;<br />    break;<br />  }<br />  return key;<br />}<br /><br />typedef enum{<br />  reportid_none = 0,<br />  reportid_key = 1<br />} report_id_t;<br /><br />static void buildReport(report_id_t id,  uchar key)<br />{<br />  reportBuffer&#91;0&#93; = id;<br />  if (id == reportid_key){<br />    reportBuffer&#91;1&#93; = key;<br />  }<br />}<br /><br />usbMsgLen_t usbFunctionSetup(uchar data&#91;8&#93;)<br />{<br />  usbRequest_t    *rq = (void *)data;<br /><br />  usbMsgPtr = reportBuffer;<br />  if((rq-&gt;bmRequestType &amp; USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS){    /* class request type */<br />    if(rq-&gt;bRequest == USBRQ_HID_GET_REPORT){ <br />      /* wValue: ReportType (highbyte), ReportID (lowbyte) */<br />      /* we only have one report type, so don't look at wValue */<br />      buildReport(rq-&gt;wValue.bytes&#91;0&#93;, ir_key_pressed);<br />      DBG1(0x50, &amp;rq-&gt;bRequest, 1);<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&#91;1&#93;;<br />    }<br />  }else{<br />    /* no vendor specific requests implemented */<br />  }<br />  return 0;<br />}<br /><br />/* ------------------------------------------------------------------------- */<br /><br /><br />int main(void){<br />  cli(); // Disable interrupts<br /><br />  usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */   <br />  usbInit();<br />  odDebugInit();<br />  IR_init();<br />   <br />  /* Port initiation*/<br />  bs(DDRC,3);<br />  bs(DDRC,4);<br />  bs(DDRC,5);<br />  PORTC &amp;= ~(1&lt;&lt;3);<br />  PORTC = ~PORTC;<br /><br />  /* Timer 0 initiation */<br />  TCCR0B = _BV(2) | _BV(0); // 16E6/(1024*256) = 61 ~ 16 ms<br /><br />  /* Variable initiation */<br />  char buf&#91;64&#93;;<br />  uchar idleCounter = 0;<br />  static report_id_t keyPressed = reportid_none;<br /><br />  _delay_ms(250);<br /><br />  usbDeviceConnect();<br /><br />  sei(); // Reenable interrupts<br /><br />  DBG1(0x00, 0, 0);       /* debug output: main starts */<br />    <br />  while(1){<br />    usbPoll(); // must be called at least every 50 ms<br />    bs(PORTC,5); // Clear the indicator led<br /><br />    if(IR_packetReady()){ // check for packets from remote<br />      irKey = IR_getCode();<br />      keyPressed = reportid_key;<br />    }<br /><br />    if(TIFR0 &amp; (1&lt;&lt;TOV0)){   // 16 ms timer<br />   <br />      TIFR0 = 1&lt;&lt;TOV0;<br />      if(idleRate != 0){<br />   if(idleCounter &gt; 4){<br />     idleCounter -= 5;   // 16 ms in units of 4 ms<br />   }else{<br />     idleCounter = idleRate;<br />     //            keyPressed = reportid_none;<br />   }<br />      }<br />    }<br /><br />    if(keyPressed &amp;&amp; usbInterruptIsReady()){<br />      DBG1(0x19, &amp;irKey,1); // debug output<br />      ir_key_pressed = irKeyLookup(irKey);<br />      buildReport(keyPressed , ir_key_pressed);<br />      usbSetInterrupt((void *)&amp;reportBuffer, sizeof(reportBuffer));<br />      keyPressed = reportid_none;<br />    }<br />  }<br />   <br />}<br /> </code></pre></div><p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=5201">subnex</a> — Tue May 03, 2011 12:42 am</p><hr />
]]></content>
	</entry>
	</feed>
