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

	<title>Objective Development Forums</title>
	
	<link href="https://forums.obdev.at/index.php" />
	<updated>2010-03-22T23:11:42+02:00</updated>

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

		<entry>
		<author><name><![CDATA[gknigh_t]]></name></author>
		<updated>2010-03-22T23:11:42+02:00</updated>

		<published>2010-03-22T23:11:42+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=4036&amp;p=13808#p13808</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=4036&amp;p=13808#p13808"/>
		<title type="html"><![CDATA[V-USB on ATMega162/12MHz - Basic Keyboard Functionality]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=4036&amp;p=13808#p13808"><![CDATA[
Hello,<br /><br />I've taken the most basic example of HID Keyboard example from V-USB to frankenstein together the most basic of interface panels.<br />Think of it as a LCD with function keys around it.  The ATMega162 keyscans the user defined buttons and the V-USB soft-core sends USB messaging to a Windows PC who thinks its a keyboard.<br /><br />The V-USB keyboard functionality works great with messaging being sent and received by the PC.  Some of the keys tell the MCU to bit-bang serial data off to the LCD to do things like brightness/contrast and so forth.  Inside the for(;;) where the USB stuff resides, there is a keyscan routine that scans rows/colums to determine what buttons you pressed and acts accordingly.<br /><br />The problem is this, if pressing key 1 returns 0x31 saying ascii '7' V-USB transmits it.  If you press a key that has to invoke a function that has to toggle an IO to emulate serial data, its like it gets skipped over completely.<br /><br /><div class="codebox"><p>Code: </p><pre><code>main.c {<br /><br />vusb_preemble();<br />for(;;){<br />      wdt_reset();<br />      usbPoll();<br />        <br />      //BlinkFault();<br />      key = keyPressed();<br />        if(lastKey != key)<br />      {<br />            lastKey = key;<br />            keyDidChange = 1;<br />        }<br />        if(TIFR &amp; (1&lt;&lt;TOV0))<br />      {   // 22 ms timer <br />            TIFR = 1&lt;&lt;TOV0;<br />            if(idleRate != 0)<br />         {<br />                if(idleCounter &gt; 4)<br />            {<br />                    idleCounter -= 5;   // 22 ms in units of 4 ms<br />                }<br />            else<br />            {<br />                    idleCounter = idleRate;<br />                    keyDidChange = 1;<br />                }<br />            }<br />        }<br />        if(keyDidChange &amp;&amp; usbInterruptIsReady())<br />      {<br />            keyDidChange = 0;<br />            // use last key and not current key status in order to avoid lost<br />            // changes in key status.<br />            buildReport(lastKey);<br />            usbSetInterrupt(reportBuffer, sizeof(reportBuffer));<br />        } */<br /><br />}<br />}<br /></code></pre></div><br />vusb_preenble contains things like the 300ms disconnect, odDebugInit, usbInit(), sei(), DBG1(0x00,0,0) and so on.<br />A snipped of keypressed is shown below.<br /><br /><div class="codebox"><p>Code: </p><pre><code>static uchar keyPressed(void)<br />{<br />   uchar  ch = 0;<br /><br />   // First Column<br />   output_low(PORTD, KEYPIN1);<br />   output_high(PORTB, KEYPIN7);<br />   output_high(PORTB, KEYPIN8);<br />   output_high(PORTB, KEYPIN9);<br />   NOP;<br />   NOP;<br />   NOP;<br />   NOP;<br />   NOP;<br />   NOP;<br />   NOP;<br />   if (sw_is_pressed(PIND,KEYPIN2)) { ch = KEY_A; }   // SW02: 'TEST'<br />   if (sw_is_pressed(PIND,KEYPIN3)) { ch = KEY_B; }   // SW04: '2'<br />   if (sw_is_pressed(PIND,KEYPIN4)) { TogglePD0(); }   // SW05: '3'<br />   if (sw_is_pressed(PINB,KEYPIN10)) { ch = KEY_D; }   // SW07: '5'<br />   if (sw_is_pressed(PINA,KEYPIN11)) { ch = KEY_E; }   // SW08: '6'<br />   if (sw_is_pressed(PINA,KEYPIN12)) { ch = KEY_F; }   // SW10: '8'<br />   if (sw_is_pressed(PINA,KEYPIN13)) { ch = KEY_G; }   // SW11: '9'<br />return ch;<br />}<br /></code></pre></div><br /><br />The function TogglePD0() can be something simple like blink an LED or use a simple bit-bang example for faking serial data.<br />It is totally bypassed.  The function was tested separately before being included.<br /><br />Comments welcome!<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=3294">gknigh_t</a> — Mon Mar 22, 2010 11:11 pm</p><hr />
]]></content>
	</entry>
	</feed>
