CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PIC18F2550 - HID Mouse Absolute Coordinates

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
elyon



Joined: 21 Mar 2017
Posts: 9
Location: Italy

View user's profile Send private message Send e-mail

PIC18F2550 - HID Mouse Absolute Coordinates
PostPosted: Tue Mar 21, 2017 11:28 am     Reply with quote

Hi all!! Very Happy
I'm a newbie in the world of CCS and PICs.
First of all, sorry for my bad english.
I'm here because I'm trying to use a PIC18F2550 as a mouse using the absolute coordinates to move the pointer to a specific position of the screen.

Elsewhere, I've read about the change of usb descriptor to do what I want, but in my ignorance I'm not sure about what I'm doing.

In my code, I connect my PIC to a device that, with SPI communication, send some words to it and, when it recognize them, it use two of this as the value of X and Y to move the pointer.

Searching, I've found a project here http://projectproto.blogspot.it/2009/11/pic18f2550-usb-hid-mouse.html
that use this function
Code:
usb_put_packet(1, out_data, 4, USB_DTS_TOGGLE);

to move the pointer.
You can find the function in "usb_hw_layer.h"

These are my includes
Code:
#include <pic18_usb.h>
#include <usb_desc_mouse.h>
#include <usb.c>


And this is how I changed "usb_desc_mouse.h" like suggested where I read how to change it (I have change only USB_CLASS_SPECIFIC_DESC[]):
Code:
const char USB_CLASS_SPECIFIC_DESC[] =
   {
      0x05, 0x01,       // usage page (generic desktop Choose the usage page "mouse" is on
      0x09, 0x02,       // usage (mouse) Device is a mouse
      0xA1, 0x01,       // collection (application) This collection encompasses the report format
      0x09, 0x01,       // usage (pointer) Choose the key code usage page
      0xA1, 0x00,       // collection (physical) Physical collection
      0x05, 0x09,       // usage page (buttons) Choose the “button” usage page
      0x19, 0x01,       // usage minimum (1) There are three buttons
      0x29, 0x03,       // usage maximum (3)
      0x15, 0x00,       // logical minimum (0) Each button is represented by one bit
      0x25, 0x01,       // logical maximum (1)
      0x95, 0x03,       // report count (3) Three reports, one bit each
      0x75, 0x01,       // report size (1)
      0x81, 0x02,       // input (data, variable, absolute) Defined bits above are data bits
      0x95, 0x01,       // report count (1) One report, five bits in length
      0x75, 0x05,       // report size (5)
      0x81, 0x01,       // input (constant) Bit stuff to fill byte
      0x05, 0x01,       // usage page (generic desktop) Choose the usage pare “X” and “Y” are on
      0x09, 0x30,       // usage (X) X direction of pointer
      0x09, 0x31,       // usage (Y) Y direction of pointer
      0x35, 0x00,       // Physical minimum  = 0
      0x46, 0xFF,0x03,  //  Physical maximum = 1023
      0x15, 0x00,       // Logical Minimum = 0
      0x26, 0xFF,0x03,  //  Logical Maximum = 1023
      0x75, 0x08,       // report size (8) Two reports, eight bits each
      0x95, 0x02,       // report count (3) 0x03
      0x81, 0x02,       // input (data, variable, relative) 0x06 Defined bits above are data bits
      0xC0,             // end collection End physical collection
      0xC0              // end collection End application collection
   };


In particular, I added
Code:
0x35, 0x00,       // Physical minimum  = 0
0x46, 0xFF,0x03,  //  Physical maximum = 1023

to define the physical resolution of my screen, and changed
Code:
0x15, 0x00,       // Logical Minimum = 0
0x26, 0xFF,0x03,  //  Logical Maximum = 1023

Following also the HID Usage Table found here http://www.usb.org/developers/hidpage/Hut1_12v2.pdf

Now, I did things of which I know nothing, but could you tell me if I'm doing the right things and if the function
Code:
usb_put_packet(1, out_data, 4, USB_DTS_TOGGLE);
is the right choice to realize my project?

Thank you very much for every help that you can give me Smile
elyon



Joined: 21 Mar 2017
Posts: 9
Location: Italy

View user's profile Send private message Send e-mail

PostPosted: Wed Mar 29, 2017 1:39 am     Reply with quote

no one? Confused
_________________
Think. Believe. Dream. Dare
- W. E. Disney -
Ttelmah



Joined: 11 Mar 2010
Posts: 19221

View user's profile Send private message

PostPosted: Wed Mar 29, 2017 5:50 am     Reply with quote

You need to change quite a lot of other stuff.
You've made your message larger, so the packet also has to grow.

Historically the standard mouse packet, is 'buttons', X, Y, wheel., with just one byte for each. You are sending 2 bytes for X and Y now...

Have a look at this MicroChip thread where another poster was doing the same thing:

<http://www.microchip.com/forums/m413261.aspx>

Also look for touchscreen examples online, which do exactly this.
elyon



Joined: 21 Mar 2017
Posts: 9
Location: Italy

View user's profile Send private message Send e-mail

PostPosted: Thu Mar 30, 2017 3:41 am     Reply with quote

Ttelmah wrote:
You need to change quite a lot of other stuff.
You've made your message larger, so the packet also has to grow.

Historically the standard mouse packet, is 'buttons', X, Y, wheel., with just one byte for each. You are sending 2 bytes for X and Y now...


Hi Ttelmah! Thanks for the reply.
Yes, historically mouse has 3 "buttons" but in my case I don't need the wheel, so I haven't use it in my descriptor or in report size (report count is for only for 2 fields and report size is of 8 bit).
I'm not sure about this second configuration (8 bit) because, from the SPI, my PIC receive 16 bit for X and Y, so I have to change it from 8 bit (0x08) to 16 (0x10), I think.....

Anyway, I have already read the post you have linked, but there are many things that I don't find in my code, maybe because they use MPLAB compiler?
_________________
Think. Believe. Dream. Dare
- W. E. Disney -
Ttelmah



Joined: 11 Mar 2010
Posts: 19221

View user's profile Send private message

PostPosted: Thu Mar 30, 2017 3:53 am     Reply with quote

As I said, go and look at the thread I pointed you to, and search on touchscreen descriptors.

Your descriptor has a report size of 8 bits, for values that you are allowing to go to 1023.....
elyon



Joined: 21 Mar 2017
Posts: 9
Location: Italy

View user's profile Send private message Send e-mail

PostPosted: Fri Mar 31, 2017 4:37 am     Reply with quote

oook. Thank you very much Wink
_________________
Think. Believe. Dream. Dare
- W. E. Disney -
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group