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

USB GamePad with PIC18F4550
Goto page Previous  1, 2, 3, 4, 5  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
temtronic



Joined: 01 Jul 2010
Posts: 8525
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Mar 21, 2022 2:51 pm     Reply with quote

have you got the CCS supplied examples to work ?
manusoftar



Joined: 19 Mar 2022
Posts: 46

View user's profile Send private message

PostPosted: Mon Mar 21, 2022 2:56 pm     Reply with quote

Well, I tried one of em once, but since none of those examples are about a gamepad or joystick... I mean, who the heck is now a day developing an interface for a freaking USB keyboard or mouse??...

In any case, I tried several, alleged working examples of joystick that I found and wasn't able to make any of those work, I either get an error code 10 and a yellow exclamation point on the device manager, or I get that working but the darn thing does not get all the descriptors...

This is a report generated with Thesycon USB Descriptor Decoder

Quote:

Information for device USB\Vendor_1234_Product_AB01:

------------------------------
Connection Information:
------------------------------
Device current bus speed: LowSpeed
Device address: 0x0000
Current configuration value: 0x01
Number of open pipes: 0


------------------------------
Device Descriptor:
------------------------------
0x12 bLength
0x01 bDescriptorType
0x0200 bcdUSB
0x00 bDeviceClass
0x00 bDeviceSubClass
0x00 bDeviceProtocol
0x08 bMaxPacketSize0 (8 bytes)
0x1234 idVendor
0xAB01 idProduct
0x0001 bcdDevice
0x01 iManufacturer
0x02 iProduct
0x00 iSerialNumber
0x01 bNumConfigurations

Configuration descriptor and all subsequent descriptors are not available. Error code: 0x00000057

Microsoft OS Descriptor is not available. Error code: 0x00000057


--------------------------------
String Descriptor Table
--------------------------------
Index LANGID String
0x00 0x0000
0x01 0x0000 Request failed with 0x00000057
0x02 0x0000 Request failed with 0x00000057

------------------------------

Connection path for device:
Virtual Usb Hub
Root Hub
USB\Vendor_1234_Product_AB01 Port: 1

Running on: Windows 10 or greater (Build Version 19043)

Brought to you by TDD v2.17.0, Feb 23 2021, 14:04:02
temtronic



Joined: 01 Jul 2010
Posts: 8525
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Mar 21, 2022 7:43 pm     Reply with quote

Maybe post a link to one of the examples that doesn't work, as well as whatever 'Windows' program you're using so that others can try and see what happens.
If you're running Windows, there's several layers of permissions you have to deal with
manusoftar



Joined: 19 Mar 2022
Posts: 46

View user's profile Send private message

PostPosted: Mon Mar 21, 2022 8:10 pm     Reply with quote

I am using CCS of course and Proteus 8 on a virtual machine running Windows 10 x86 because there is some compatibility issue with x64 OS's.

To be honest I can't confirm any of the examples do work as those are not gamepad or joystick examples and those are the only ones that would require the calibration page that is not working in my case.

I'm not sure why, but all the official examples/guides are about mouse/keyboard but none about joystick/gamepad, and the other example source files like ex_usb_hid.c just wont even compile.


I have read over and over again my header file and sincerely I just can't understand why my device isn't sending the whole config to the OS, I checked my header against other example headers that are being said to work and I don't find any noticeable difference besides the class specific descriptor which obviously is not exactly like mine.

I would really appreciate if someone can take a look at my source and let me know why on earth is it not working.
Jerson



Joined: 31 Jul 2009
Posts: 115
Location: Bombay, India

View user's profile Send private message Visit poster's website

PostPosted: Mon Mar 21, 2022 8:40 pm     Reply with quote

Considering the changes you know you made to the device specific descriptors, can you check that you have changed the lengths to match in the usb.h file? There could be a mismatch you may have overlooked and the machine will not read anymore than it is told by the LEN variables in the descriptor.

Simple example could be

#DEFINE USB_DESC_DEVICE_LEN 66
manusoftar



Joined: 19 Mar 2022
Posts: 46

View user's profile Send private message

PostPosted: Mon Mar 21, 2022 8:50 pm     Reply with quote

I didn't touch the usb.h file at all... I will check if I can find something there that can explain what is happening to me.

It's a pity to read so many people stating that they managed to make several USB joysticks or gamepads with complete success but won't share their source codes for others like us to understand how the heck to do it...
Jerson



Joined: 31 Jul 2009
Posts: 115
Location: Bombay, India

View user's profile Send private message Visit poster's website

PostPosted: Mon Mar 21, 2022 9:01 pm     Reply with quote

Unfortunately, all I have worked on are keyboard and mice across PIC and PSoC devices. It was not easy to get things working correctly for quite a while.
manusoftar



Joined: 19 Mar 2022
Posts: 46

View user's profile Send private message

PostPosted: Mon Mar 21, 2022 9:12 pm     Reply with quote

Just to note, I haven seen a single example (including those alleged working joystick/gamepad which have not worked for me) where the usb.h was modified at all.

Modifying what you suggested brought even more problems than before so I had to revert those changes.

I'm starting to believe this may be some kind of bug on the CCS libraries themselves as I read my files over and over and compared with the USB documentation and everything seems to be right and yet, for some reason, my devices doesn't seem to send the complete information to the PC in order for it to recognize all it's features.

I will write an email to the official support and see what they have to say about this.
Ttelmah



Joined: 11 Mar 2010
Posts: 18053

View user's profile Send private message

PostPosted: Mon Mar 21, 2022 11:40 pm     Reply with quote

Oner big comment to make here.
Simulators largely don't work.
I can take fully working code, and run it in the simulator and it fails.
I can take code working in the simulator, put it into a real chip, and it
doesn't work.
Honestly, trying to develop using a simulator, is a waste of time.
This is why the working joystick examples don't work.
temtronic



Joined: 01 Jul 2010
Posts: 8525
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Mar 22, 2022 5:21 am     Reply with quote

I agree 100% with Mr. T, PROTEUS is well known to NOT 'simulate' PICS properly. Hasn't worked for years,full of 'bugs'.
To make things worse you're running a 'virtual Windows 10' machine ? That can't possibly work 100%. Yeesh, W10 'magically' added some black pixel 'shading' the other day on this PC.took 2 dayze to debug that .
Honestly the BEST way to 'play with PICs' is to get real chips and a dedicated 'tower' running a known good version of Windows( I run W7U-64 bit )

I re read the original post... I get ...

13 switches and 2 analog data (10 bits each)

That could be 6 bytes of data broken down as follows 1st byt, 8 switches, 2nd byte , 5 switches, 3rd X rslt g 8, 4th rslt 2, 5th Y rslt 8, 6th y rlst2.

Not too sure what 'magic' goes on in they TTL<>USB modules but they work and do NOT require the USB driver that the 4550 does.The drive fills about 1/4-/13rd of codespace if I recall. That may impact on how large a program you can actually have . I know I had 4550 samples when they came out and ran into that problem..went to USB modules, still use them today.
Ttelmah



Joined: 11 Mar 2010
Posts: 18053

View user's profile Send private message

PostPosted: Tue Mar 22, 2022 6:51 am     Reply with quote

He probably wants something to be used to play a particular game. So it'll
have to appear as an HID gamepad, not as a CDC device.
It should really be quite easy, but he has to understand that USB descriptors
are complex. Not something with a one line solution. Needs to actually study
how these work, what the parts are and how these interact with one another.
He is not being helped by trying to use the simulator. On a scale of 1..10 of
useful tools I rate the ones I have tried at about -5. They do work for their
own examples. However for 99% of other stuff the faults make them useless.
temtronic



Joined: 01 Jul 2010
Posts: 8525
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Mar 22, 2022 7:31 am     Reply with quote

hmm hadn't thought about the 'used for a game' thing...

A clever programmer could cut PC code to receive the CDC data and convert into HID data and link that into the game program. I've done similar 'translations' using DELPHI years ago...

I was just thinking of a fast and easy way to get 6 bytes transferred INTO the PC.

The big issue is not using real hardware, so real program can't be tested in the real world.

That's a pretty high rating for PROTEUS BTW Shocked
manusoftar



Joined: 19 Mar 2022
Posts: 46

View user's profile Send private message

PostPosted: Wed Mar 23, 2022 9:13 am     Reply with quote

Guys, sorry for not answering back, for some reason I didn't receive further notifications.

Well, I contacted CCS technical support, gave them my code and they tried it on their hardware and confirmed that it works as expected (using an actual PIC rather than simulation), they even sent me back a dump of the descriptors as they shown on a PC running Windows 10 so Ttelmah, you were right, the simulation of Proteus for these matters just suck... Wink

Just in case you are interested, here is the descriptor dump they sent me (they used a different PIC because they didn't have a 18f4550 at hand)

Quote:

Information for device USB Gamepad (VID=0x1234 PID=0xAB01):

------------------------------
Connection Information:
------------------------------
Device current bus speed: FullSpeed
Device supports USB 1.1 specification
Device supports USB 2.0 specification
Device address: 0x0003
Current configuration value: 0x01
Number of open pipes: 2


------------------------------
Device Descriptor:
------------------------------
0x12 bLength
0x01 bDescriptorType
0x0200 bcdUSB
0x00 bDeviceClass
0x00 bDeviceSubClass
0x00 bDeviceProtocol
0x08 bMaxPacketSize0 (8 bytes)
0x1234 idVendor
0xAB01 idProduct
0x0001 bcdDevice
0x01 iManufacturer "DIC"
0x02 iProduct "USB Gamepad"
0x00 iSerialNumber
0x01 bNumConfigurations


-------------------------
Configuration Descriptor:
-------------------------
0x09 bLength
0x02 bDescriptorType
0x0029 wTotalLength (41 bytes)
0x01 bNumInterfaces
0x01 bConfigurationValue
0x00 iConfiguration
0x80 bmAttributes (Bus-powered Device)
0xFA bMaxPower (500 mA)

Interface Descriptor:
------------------------------
0x09 bLength
0x04 bDescriptorType
0x00 bInterfaceNumber
0x00 bAlternateSetting
0x02 bNumEndPoints
0x03 bInterfaceClass (Human Interface Device Class)
0x00 bInterfaceSubClass
0x00 bInterfaceProtocol
0x00 iInterface

HID Descriptor:
------------------------------
0x09 bLength
0x21 bDescriptorType
0x0100 bcdHID
0x00 bCountryCode
0x01 bNumDescriptors
0x22 bDescriptorType (Report descriptor)
0x0042 bDescriptorLength

Endpoint Descriptor:
------------------------------
0x07 bLength
0x05 bDescriptorType
0x81 bEndpointAddress (IN endpoint 1)
0x03 bmAttributes (Transfer: Interrupt / Synch: None / Usage: Data)
0x0005 wMaxPacketSize (1 x 5 bytes)
0x01 bInterval (1 frames)

Endpoint Descriptor:
------------------------------
0x07 bLength
0x05 bDescriptorType
0x01 bEndpointAddress (OUT endpoint 1)
0x03 bmAttributes (Transfer: Interrupt / Synch: None / Usage: Data)
0x0003 wMaxPacketSize (1 x 3 bytes)
0x0A bInterval (10 frames)

Microsoft OS Descriptor:
------------------------------
0x00 bLength
0x00 bDescriptorType
Hex dump:


--------------------------------
String Descriptor Table
--------------------------------
Index LANGID String
0x00 0x0000 0x0409
0x01 0x0409 "DIC"
0x02 0x0409 "USB Gamepad"

------------------------------

Connection path for device:
Intel(R) 8 Series/C220 Series USB Enhanced Host Controller #2 - 8C2D
Root Hub
Generic USB Hub
USB Gamepad (VID=0x1234 PID=0xAB01) Port: 2

Running on: Windows 10 or greater (Build Version 19043)

Brought to you by TDD v2.17.0, Feb 23 2021, 14:04:02
manusoftar



Joined: 19 Mar 2022
Posts: 46

View user's profile Send private message

PostPosted: Wed Mar 23, 2022 9:27 am     Reply with quote

Ttelmah wrote:
He probably wants something to be used to play a particular game. So it'll
have to appear as an HID gamepad, not as a CDC device.
It should really be quite easy, but he has to understand that USB descriptors
are complex. Not something with a one line solution. Needs to actually study
how these work, what the parts are and how these interact with one another.
He is not being helped by trying to use the simulator. On a scale of 1..10 of
useful tools I rate the ones I have tried at about -5. They do work for their
own examples. However for 99% of other stuff the faults make them useless.


Yes, you are right, what I'm trying to make is an Arcade (or console) gamepad, it will have a stick and buttons just like the old arcade machines had plus an analog stick.

The reasons why I didn't use a commercial interface are the following:

1.- The only one I could find that supports analog sticks is currently out of stock
2.- It does not support all the buttons I want
3.- I really like doing these stuff on myself, it's like a personal challenge, even though I'm a SOFTWARE engineer and not an ELECTRONIC engineer, I love electronic and circuit design, specially with programmable IC's like PIC's

On behalf of my descriptor, I did read as much as I could find, but the truth is that there is no single, quite clear, documentation, guide, tutorial, etc. I haven't found a single full example of somebody doing an HID Gamepad or Joystick (yes I found partial examples like the post you referred me before).

There is a lot of documentation on how to create your own descriptors, yet, the official tool is unnecessarily complicated. It could have been way more user friendly, like, it could provide an GUI where you just put what is the usage you expect from your interface (Keyboard, Mouse, Joystick, Gamepad, Camera, Headphones, Microphone, etc) and ask you for it's specifications like, let's say you want to create an interface for a Joystick, it should ask you how many buttons you want on it, how many analog axes, if you want a hat switch or not (and if you want it, how many microswitches it will have 4/8) and just create the freaking thing, rather than having you to figure out exactly which piece of descriptor to place on each part. Not to mention if your joystick is meant to have vibration/force feedback, if it is wireless and you want to be able to control the battery status from the PC, etc.

In any case, my descriptor proved to be properly formed, the problem was Proteus and it's poor simulation, this Friday I will finally get the actual IC's and a Pickit3 programmer and some other stuff (a couple multiplexers, current regulators, etc) so I will be able to test my code on the ACTUAL hardware.

In any case I appreciate the time you dedicated to try and help me, and you really helped, specially with that part of changing the variable where the length of the descriptor is stored which was causing an error code 10.

Thank you very much. If I can help you in any other thing you are more than welcome to PM me. Wink
newguy



Joined: 24 Jun 2004
Posts: 1804

View user's profile Send private message

PostPosted: Wed Mar 23, 2022 10:12 am     Reply with quote

Suggestion: once you get it working throw it in the code library section of this forum. You yourself said it was frustrating that were no clear examples of working code....
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3, 4, 5  Next
Page 2 of 5

 
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