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

	<title>Objective Development Forums</title>
	
	<link href="https://forums.obdev.at/index.php" />
	<updated>2014-09-07T13:08:26+02:00</updated>

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

		<entry>
		<author><name><![CDATA[Anonymous]]></name></author>
		<updated>2014-09-07T13:08:26+02:00</updated>

		<published>2014-09-07T13:08:26+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=9300&amp;p=28115#p28115</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=9300&amp;p=28115#p28115"/>
		<title type="html"><![CDATA[Re: multiply keypresses in USBkeyboard]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=9300&amp;p=28115#p28115"><![CDATA[
Argh... never mind. The code is fine, I had a floating GPIO somewhere that messed it up.<br /><br />Its working now <img class="smilies" src="./../../../images/smilies/icon_smile.gif" alt=":)" title="Smile" /><p>Statistics: Posted by Guest — Sun Sep 07, 2014 1:08 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Anonymous]]></name></author>
		<updated>2014-09-07T13:01:03+02:00</updated>

		<published>2014-09-07T13:01:03+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=9300&amp;p=28114#p28114</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=9300&amp;p=28114#p28114"/>
		<title type="html"><![CDATA[Re: multiply keypresses in USBkeyboard]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=9300&amp;p=28114#p28114"><![CDATA[
Okay after using an USB analyzer this gets even more confusing.<br /><br />When I press two buttons on the custom controller that equal the keys 'A' and 'D' then the device sends this:<br />00 00 04 07 00 00 00 00<br /><br />In my eyes that's correct: No modifier, 2nd byte is null, first key is 04 (a), second key is 07 (d), all other keys are null.<br /><br />What am I missing?<p>Statistics: Posted by Guest — Sun Sep 07, 2014 1:01 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Anonymous]]></name></author>
		<updated>2014-09-07T11:41:41+02:00</updated>

		<published>2014-09-07T11:41:41+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=9300&amp;p=28113#p28113</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=9300&amp;p=28113#p28113"/>
		<title type="html"><![CDATA[multiply keypresses in USBkeyboard]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=9300&amp;p=28113#p28113"><![CDATA[
Hi all,<br /><br />I've successfully taken the keyboard example code and modified it to run on an ATTiny2313 with keys being read through shiftregisters instead of connecting them directly to IO pins.<br /><br />What I'm struggling with however is to send multiple pressed keys to the computer in a single report. I've checked the code for the C64 keyboard and although the code is very different from mine I don't see something I'm missing. My software doesn't work with modifier keys though since I'm not implementing a full keyboard but a custom game panel. <br /><br />Any hints would be greatly appreciated...<br /><br />Trying to keep the pasted code short here, let me know if you want me to post the whole script&#058;<br /><br /><div class="codebox"><p>Code: </p><pre><code>#define KEYCODE_NUM 6<br />typedef struct {<br />    uint8_t modifier;<br />    uint8_t reserved;<br />    uint8_t keycode&#91;KEYCODE_NUM&#93;;<br />} keyboard_report_t;<br /><br />static keyboard_report_t keyboard_report; // sent to PC<br /><br />#define KEY_A                      4<br />#define KEY_B                      5<br />#define KEY_C                      6<br />#define KEY_D                      7<br />#define KEY_E                      8<br />#define KEY_F                      9<br />#define KEY_G                   10<br />#define KEY_H                   11<br />// &#91;...&#93;<br /><br />#define NUMBER_OF_BUTTONS 8<br />// data type to use for storing the shift register data - make sure the datatype has &gt;= bits than NUMBER_OF_BUTTONS<br />#define KEYS_DATATYPE uint8_t<br /><br />uchar buttonCodes&#91;NUMBER_OF_BUTTONS&#93; = {KEY_A, KEY_B, KEY_C, KEY_D, KEY_E, KEY_F, KEY_G, KEY_H};<br /><br />#define STATE_WAIT 0<br />#define STATE_SEND_KEY 1<br />#define STATE_RELEASE_KEY 2<br />uchar state       = STATE_WAIT;<br /><br />// this reads the shift registers and fills the report buffer for USB directly to save some bytes<br />void readShiftRegisters() {<br />    uchar i;<br />    uchar offset = 0;<br />   <br />    // Trigger a parallel load to latch the state of the data lines<br />    PORT_SHIFTREG &amp;= ~(1 &lt;&lt; PIN_SHLD);<br />    // the SN74HCT165N is fast enough so we don't need a delay, this saves a few bytes<br />    //_delay_us(PULSE_WIDTH_USEC);<br />    PORT_SHIFTREG |= (1 &lt;&lt; PIN_SHLD);<br /><br />    // Loop to read each bit value from the serial out line of the shift register<br />    // we forge the keyboard report directly, to safe some memory<br />    for (i = 0; i &lt; NUMBER_OF_BUTTONS; i++) {<br />        if (PORT_IN_SHIFTREG &amp; (1 &lt;&lt; PIN_QH) &amp;&amp; offset &lt; KEYCODE_NUM) {<br />            state       = STATE_SEND_KEY;<br />            keyboard_report.keycode&#91;offset&#93; = buttonCodes&#91;i&#93;;<br />            offset++;<br />        }<br /><br />        // Pulse the clock (rising edge shifts the next bit).<br />        PORT_SHIFTREG |= (1 &lt;&lt; PIN_CLK);<br />        // the SN74HCT165N is fast enough so we don't need a delay, this saves a few bytes<br />        //_delay_us(PULSE_WIDTH_USEC);<br />        PORT_SHIFTREG &amp;= ~(1 &lt;&lt; PIN_CLK);<br />    }<br />}<br /><br />int main() {<br />    // ...<br />    while (1) {<br />        wdt_reset(); // keep the watchdog happy<br />        usbPoll();<br />      <br />        // clear the USB report<br />        for (i = 0; i&lt;sizeof (keyboard_report); i++) {<br />            ((uchar *) &amp; keyboard_report)&#91;i&#93; = 0;<br />        }     <br />        keyboard_report.modifier = 0;<br /><br />        // this fills the keyboard register directly<br />        readShiftRegisters();<br />   <br />        // characters are sent when messageState == STATE_SEND<br />        if (usbInterruptIsReady() &amp;&amp; state != STATE_WAIT) {<br />            // we need this simple state-machine to send a single empty report (for &quot;keyUp&quot;) when all buttons are unpressed<br />            switch (state) {<br />                case STATE_SEND_KEY:<br />                    state = STATE_RELEASE_KEY;<br />                    break;<br />                case STATE_RELEASE_KEY:<br />                default:<br />                    state = STATE_WAIT;<br />            }<br /><br />            usbSetInterrupt((void *) &amp;keyboard_report, sizeof (keyboard_report));<br />        }<br />    }<br /><br />    return 0;<br />}<br /></code></pre></div><br /><br />Thanks a lot for any hints <img class="smilies" src="./../../../images/smilies/icon_smile.gif" alt=":)" title="Smile" /><p>Statistics: Posted by Guest — Sun Sep 07, 2014 11:41 am</p><hr />
]]></content>
	</entry>
	</feed>
