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

	<title>Objective Development Forums</title>
	
	<link href="https://forums.obdev.at/index.php" />
	<updated>2013-04-19T09:07:47+02:00</updated>

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

		<entry>
		<author><name><![CDATA[Anonymous]]></name></author>
		<updated>2013-04-19T09:07:47+02:00</updated>

		<published>2013-04-19T09:07:47+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=5740&amp;p=25146#p25146</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=5740&amp;p=25146#p25146"/>
		<title type="html"><![CDATA[Re: HID mouse touchscreen]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=5740&amp;p=25146#p25146"><![CDATA[
I want to make your project<br />will you please give me the hardware setup for this..<br />the c file which you have posted over here is perfect for this project..?<p>Statistics: Posted by Guest — Fri Apr 19, 2013 9:07 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[mn6500]]></name></author>
		<updated>2011-06-12T10:07:26+02:00</updated>

		<published>2011-06-12T10:07:26+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=5740&amp;p=18719#p18719</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=5740&amp;p=18719#p18719"/>
		<title type="html"><![CDATA[HID mouse touchscreen]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=5740&amp;p=18719#p18719"><![CDATA[
Hi all<br /> I want to make a touchpad HID mouse my micro is mega16 and crystal is also 16 MHz. i run HID-mouse (v-sub example) without any problems, but for a/d and my touch  have problems. Have you please guide , thanks . this is my program :<br /><br />/* Name: main.c<br /> * Project: hid-mouse, a very simple HID example<br /> * Author: Christian Starkjohann<br /> * Creation Date: 2008-04-07<br /> * Tabsize: 4<br /> * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH<br /> * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)<br /> * This Revision: $Id: main.c 692 2008-11-07 15:07:40Z cs $<br /> <br /> * Project: USB Touchscreen Mouse<br /> * Author: M.N<br /> <br /> <br /> <br /> * External 16MHz crystal. Fuse bits: LFuse 0xdf, HFuse 0xde<br /> <br /> <br /> */<br /><br />/*<br />This example should run on most AVRs with only little changes. No special<br />hardware resources except INT0 are used. You may have to change usbconfig.h for<br />different I/O pins for USB. Please note that USB D+ must be the INT0 pin, or<br />at least be connected to INT0 as well.<br /><br />We use VID/PID 0x046D/0xC00E which is taken from a Logitech mouse. Don't<br />publish any hardware using these IDs! This is for demonstration only!<br />*/<br /><br />#include &lt;stdlib.h&gt;<br />#include &lt;stdio.h&gt;<br />#include &lt;avr/io.h&gt;<br />#include &lt;avr/wdt.h&gt;<br />#include &lt;avr/interrupt.h&gt;  /* for sei() */<br />#include &lt;util/delay.h&gt;     /* for _delay_ms() */<br /><br />#include &lt;avr/pgmspace.h&gt;   /* required by usbdrv.h */<br />#include &quot;usbdrv.h&quot;<br />#include &quot;oddebug.h&quot;        /* This is also an example for using debug macros */<br /><br />#define sbi(var, mask)   ((var) |= (uint8_t)(1 &lt;&lt; mask))<br />#define cbi(var, mask)   ((var) &amp;= (uint8_t)~(1 &lt;&lt; mask))<br /><br />#define BUFFER 5        //how many samples to take from the ADC before moving the mouse<br />#define LOWACCURACY 1   //if values are higher than this move mouse<br />#define HIGHACCURACY 100 //if values are lower than this move mouse<br />#define SCALE 1         //speed of mouse<br /> <br />#define XDIFF (x_buffer[0]-x_buffer[BUFFER-1])<br />#define YDIFF (y_buffer[0]-y_buffer[BUFFER-1])<br /><br />void read_x(void);<br />void read_y(void);<br />void timerinit(void);<br />void timerpoll(void);<br />void calc(void);<br /><br />//Global Vars<br />//======================<br />uint16_t  l;// xlow register<br />uint16_t  h;// xhigh register<br />uint16_t  l1;// ylow register<br />uint16_t  h1;// yhigh register<br />int16_t  x_buffer[BUFFER + 1];<br />int16_t  y_buffer[BUFFER + 1];<br />char timerflag;<br />int i = 0;<br />char movex;<br />char movey;<br /><br />/* ------------------------------------------------------------------------- */<br />/* ----------------------------- USB interface ----------------------------- */<br />/* ------------------------------------------------------------------------- */<br /><br />PROGMEM char usbHidReportDescriptor[52] = { /* 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 />/* This is the same report descriptor as seen in a Logitech mouse. The data<br /> * described by this descriptor consists of 4 bytes:<br /> *      .  .  .  .  . B2 B1 B0 .... one byte with mouse button states<br /> *     X7 X6 X5 X4 X3 X2 X1 X0 .... 8 bit signed relative coordinate x<br /> *     Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 .... 8 bit signed relative coordinate y<br /> *     W7 W6 W5 W4 W3 W2 W1 W0 .... 8 bit signed relative coordinate wheel<br /> */<br />typedef struct{<br />    uchar   buttonMask;<br />    char    dx;<br />    char    dy;<br />    char    dWheel;<br />}report_t;<br /><br />static report_t reportBuffer;<br />static uchar    idleRate;   /* repeat rate for keyboards, never used for mice */<br /><br />void calc(void)<br />{<br />timerpoll();<br /><br />if(timerflag == 1) //if the timer overflow bit gets enabled<br />{<br />read_x();<br />read_y();<br />x_buffer[i] = h;<br />y_buffer[i] = h1;<br />timerflag = 0;<br />++i;<br />}<br /><br />if(i == BUFFER + 1)<br />{<br /><br />//char xshifted = (YDIFF&gt;&gt;2); //turns the 10bit ADC to a signed 8bit integer<br />//if (YDIFF&lt;0) xshifted *= -1;<br /><br /><br />char xshifted = ((XDIFF&gt;&gt;3)|((XDIFF&amp;0x8000)&gt;&gt;8)); //turns the 10bit ADC to a signed 8bit integer<br />char yshifted = ((YDIFF&gt;&gt;3)|((YDIFF&amp;0x8000)&gt;&gt;8));<br /><br />if((abs(xshifted) &gt; LOWACCURACY) &amp;&amp; (abs(xshifted) &lt; HIGHACCURACY))<br />{<br />movex = SCALE * xshifted;<br />}<br />else movex = 0;<br /><br />if((abs(yshifted) &gt; LOWACCURACY) &amp;&amp; (abs(yshifted) &lt; HIGHACCURACY))<br />{<br />movey = -SCALE * yshifted;<br />}<br />else movey = 0;<br /><br />if(h &gt; 1000) movex = 0;//keeps the mouse cursor still if there is no touch<br />if(h1 &gt; 1000) movey = 0;<br /><br />i = 0;<br />}<br />}<br /><br />static void moveMouse(void)<br />{<br />reportBuffer.dx = movex;<br />reportBuffer.dy = movey;<br />}<br /><br />void read_x(void)<br />{<br />//DDRA = 0b00010010; // Output on PA4(5V) and PA1(GND), Input on PA4(ADC)<br />//sbi(PORTA, 4); //pull PA4 to 5V<br />//cbi(PORTA, 1); //pull PA1 to GND<br /><br />//_delay_us(100); //wait for capacitance in screen to charge<br /><br />//ADMUX = (1 &lt;&lt; MUX1);//ADC2<br />//ADCSRA = (1 &lt;&lt; ADEN)|(1 &lt;&lt; ADSC)|(1&lt;&lt;ADPS2)|(1&lt;&lt;ADPS1);<br /><br />//while(ADCSRA &amp; (1 &lt;&lt; ADSC));<br />//l = ADCL;<br />//h = ADCH &amp; 0x03;<br />//h = h &lt;&lt; 8;<br />//h = h + l;<br /><br />int Xadc=0;<br />float y,x;//y[10],x[10];//,sum_y=0,sum_x=0;<br />//char i=0;<br /><br /><br />//for(i=0;i&lt;1;i++)<br /> //{<br />  //y sense<br />  DDRA = 0b00001010;<br />  PORTA = 0b00001000;<br />  _delay_us(150);<br />  ADMUX &amp;= 0xF8;<br />  ADCSRA |= 0x40;<br />  while((ADCSRA &amp; 0x10)==0);<br />   ADCSRA |= 0x10;<br />  Xadc = ADCW;<br />  //for vcc=4.5v<br />  //y[i] = (4.5*Xadc)/1024;<br />  y = Xadc ;<br />  Xadc = 0x00;<br />  ADCL = 0x00;<br />  ADCH = 0x00;<br />  ADCSRA &amp;= 0xBF;<br />  ADMUX &amp;= 0xE0;<br />  <br />  //x sense<br />  DDRA = 0b00000101;<br />  PORTA = 0b00000001;<br />  _delay_us(150);<br />  ADMUX |= 0x41;<br />  ADCSRA |=0x40;<br />  while((ADCSRA &amp; 0x10)==0);<br />   ADCSRA |= 0x10;<br />  Xadc = ADCW;<br />  //for vcc=4.5v<br />  //x[i] = (4.5*Xadc)/1024;<br />  x = Xadc;<br />  Xadc = 0x00;<br />  ADCW = 0x00;<br />  ADCSRA &amp;= 0xBF;<br />  ADMUX &amp;= 0xE0;<br />  <br />  //delay_ms(10);<br /> //}<br /> <br /><br />   //for(i=0;i&lt;1;i++)<br />   //{<br />   //  sum_y += y[i];<br />   //  sum_x += x[i];<br />   //}<br />   //sum_y /= 1;<br />   //sum_x /= 1;<br />   h = x;<br />   h1 = y;<br />}<br /><br />void read_y(void)<br />{<br />//DDRA = 0b00001100; // Output on PA2(5V) and PA3(GND), Input on PA4(ADC)<br />//sbi(PORTA, 2); //pull PA2 to 5V<br />//cbi(PORTA, 3); //pull PA3 to GND<br /><br />//_delay_us(100); //wait for capacitance in screen to charge<br /><br />//ADMUX = (1 &lt;&lt; MUX2);//ADC4<br />//ADCSRA = (1 &lt;&lt; ADEN)|(1 &lt;&lt; ADSC)|(1&lt;&lt;ADPS2)|(1&lt;&lt;ADPS1);<br /><br />//while(ADCSRA &amp; (1 &lt;&lt; ADSC));<br />//l1 = ADCL;<br />//h1 = ADCH &amp; 0x03;<br />//h1 = h1 &lt;&lt; 8;<br />//h1 = h1 + l1;<br />}<br /><br />void timerinit(void)<br />{<br />TCCR0 = 0x01;   // select clock: 16M/1k -&gt; overflow rate = 16M/256k = 62.5 Hz<br />}<br /><br />void timerpoll(void)<br />{<br />if(TIFR &amp; (1 &lt;&lt; TOV0))<br />{<br />        TIFR = (1 &lt;&lt; TOV0); /* clear overflow */<br />timerflag = 1;<br />    }<br />}<br />/* ------------------------------------------------------------------------- */<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 />        DBG1(0x50, &amp;rq-&gt;bRequest, 1);   /* debug output: print our request */<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 />    }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 />uchar   i;<br /><br />    wdt_enable(WDTO_1S);<br />    /* Even if you don't use the watchdog, turn it off here. On newer devices,<br />     * the status of the watchdog (on/off, period) is PRESERVED OVER RESET!<br />     */<br />    DBG1(0x00, 0, 0);       /* debug output: main starts */<br />    /* RESET status: all port bits are inputs without pull-up.<br />     * That's the way we need D+ and D-. Therefore we don't need any<br />     * additional hardware initialization.<br />     */<br />    odDebugInit();<br />    usbInit();<br />    usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */<br />    i = 0;<br />    while(--i){             /* fake USB disconnect for &gt; 250 ms */<br />        wdt_reset();<br />        _delay_ms(1);<br />    }<br />    usbDeviceConnect();<br />timerinit();<br />    sei();<br />    DBG1(0x01, 0, 0);       /* debug output: main loop starts */<br />    for(;;){                /* main event loop */<br />        DBG1(0x02, 0, 0);   /* debug output: main loop iterates */<br />        wdt_reset();<br />        usbPoll();<br />        if(usbInterruptIsReady()){<br />            /* called after every poll of the interrupt endpoint */<br />calc();<br />moveMouse();<br />            //DBG1(0x03, 0, 0);   /* debug output: interrupt report prepared */<br />            usbSetInterrupt((void *)&amp;reportBuffer, sizeof(reportBuffer));<br />        }<br /><br />    }<br />    return 0;<br />}<br /><br />/* ------------------------------------------------------------------------- */<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=5312">mn6500</a> — Sun Jun 12, 2011 10:07 am</p><hr />
]]></content>
	</entry>
	</feed>
