|
|
View previous topic :: View next topic |
Author |
Message |
andreahmed
Joined: 09 Dec 2020 Posts: 13
|
USB Joystick PIC18F2458 |
Posted: Wed Dec 09, 2020 2:46 pm |
|
|
Hello,
I'm trying to write a USB Descriptor for Joystick with throttle and X,Y Axis.
But it never gets recognized as USB Joystick.
Please help
Code: |
const char USB_CLASS_SPECIFIC_DESC[] =
{
0x05, // 0
0x01, // USAGE_PAGE (Generic Desktop) ,1
0x15, //2
0x00, // LOGICAL_MINIMUM (0) ,3
0x09, //4
0x04, // USAGE (Joystick) ,5
0xa1, //6
0x01, // COLLECTION (Application) 7
0x85, // REPORT ID ,8
0x01, //ID 1 ,9
0x05, //10
0x02, // USAGE_PAGE (Simulation Controls),11
0x09, //12
0xbb, // USAGE (Throttle) ,13
0x15, //,14
0x81, // LOGICAL_MINIMUM (-127) ,15
0x25, //16
0x7f, // LOGICAL_MAXIMUM (127), 17
0x75, // 18
0x08, // REPORT_SIZE (8),19
0x95, //20
0x01, // REPORT_COUNT (1),21
0x81, //22
0x02, // INPUT (Data,Var,Abs),23
0x05, //24
0x01, // USAGE_PAGE (Generic Desktop) ,25
0x09, //26
0x01, // USAGE (Pointer) , 27
0xa1, //28
0x00, // COLLECTION (Physical), 29
0x09, //30
0x30, // USAGE (X),31
0x09, //32
0x31, // USAGE (Y),33
0x95, //34
0x02, // REPORT_COUNT (2),35
0x81, //36
0x02, // INPUT (Data,Var,Abs),37
0xc0, // END_COLLECTION,38
0x09, //39
0x39, // USAGE (Hat switch),40
0x15, //41
0x00, // LOGICAL_MINIMUM (0),42
0x25, //43
0x07, // LOGICAL_MAXIMUM (7),44
0x35, //45
0x00, // PHYSICAL_MINIMUM (0),46
0x46, //47
0x3B, //48
0x01, // PHYSICAL_MAXIMUM (315),49
0x65, //50
0x14, // UNIT (Eng Rot:Angular Pos),51
0x75, //52
0x08, // REPORT_SIZE (8),53
0x95, //54
0x01, // REPORT_COUNT (1),55
0x81, //56
0x02, // INPUT (Data,Var,Abs),57
0x05, //58
0x09, // USAGE_PAGE (Button),59
0x19, //60
0x01, // USAGE_MINIMUM (Button 1),61
0x29, //62
0x10, // USAGE_MAXIMUM (Button 16),63
0x15, //64
0x00, // LOGICAL_MINIMUM (0),65
0x25, //66
0x01, // LOGICAL_MAXIMUM (1),67
0x75, //68
0x01, // REPORT_SIZE (1),69
0x95, //70
0x10, // REPORT_COUNT (16),71
0x55, //72
0x00, // UNIT_EXPONENT (0),73
0x65, //74
0x00, // UNIT (None),75
0x81, //76
0x02, // INPUT (Data,Var,Abs),77
0xc0, // END_COLLECTION,78
};
|
++++++++++++++++++
Edited to remove most code from CCS driver file.
Per forum rules - don't post CCS drivers.
- Forum Moderator
++++++++++++++++++ |
|
|
andreahmed
Joined: 09 Dec 2020 Posts: 13
|
|
Posted: Thu Dec 10, 2020 3:10 am |
|
|
please help :( |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19511
|
|
Posted: Thu Dec 10, 2020 3:45 am |
|
|
The first big problem is going to be the VID/PID.
Windows now requires the vendor ID and product ID to match the device
being used. VID 461, is Primax, and I don't think they do a device 0x20.
So Windows is not going to recognise this as a joystick. For your own use
(though not for a product to sell), the solution is to find a device that
matches what you want to do, and use it's VID/PID.
ATMEL do a LUFA application demo that includes a joystick. VID 0x3EB
PID 0x2043.
The sources for this are available on GitHub, and you would need to match
it's descriptor for it to be recognised correctly.
Then the usb_task needs to be in the loop, not just once at the start.
Look at the kbmouse example for how the loop should work.
Then there needs to be a delay between selecting adc channels and
reading them. Either add one in your code, or enable one in the hardware
with the ADC_TAD_MUL setting. You currently select '0'.
There is a problem in sizing. You send 4 bytes. You need a 4 byte report.
Your descriptor is not for this.
The TX size should also increase for this.
The descriptor just looks wrong. You have a single byte for a throttle,
Then two bytes for pointers, then a hat switch. The report seems to
go very wrong at this point. I suspect Windows is refusing to accept this
is legal.
Simply and just do a count of four single byte positions (since this is
what you are sending). Get this working first, then start adding buttons
etc..
If you want us to help verify the descriptor, then you need to tell us
exactly what the device is going to do. What the analog axes 'are', how
many buttons, etc.. |
|
|
andreahmed
Joined: 09 Dec 2020 Posts: 13
|
|
Posted: Thu Dec 10, 2020 6:22 am |
|
|
Thanks so much for your help!
Here is the changes:
Code: |
#include "C:\Users\xgame\Desktop\New folder\main.h"
#include <pic18_usb.h>
#include <usb_desc_hid.h> //USB Configuration and Device descriptors for this UBS device
#include <usb.c> //handles usb setup tokens and get descriptor reports
void main() //handles usb setup tokens and get descriptor reports
{
char write[64];
setup_adc_ports(AN0_TO_AN9|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_16 | ADC_TAD_MUL_0 | ADC_TAD_MUL_2 | ADC_TAD_MUL_4 | ADC_TAD_MUL_6 | ADC_TAD_MUL_8 | ADC_TAD_MUL_12 );
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
//Setup_Oscillator parameter not selected from Intr Oscillotar Config tab
usb_init_cs();
while (TRUE)
{
usb_task();
// Lecture des entr?es analogiques
if (usb_enumerated())
{
set_adc_channel( 0);
write[0] = read_adc();
delay_us(40);
set_adc_channel( 1 );
delay_us(40);
write[1] = read_adc();
write[1] = write[0] -128 ;
set_adc_channel( 2 );
delay_us(40);
write[2] = read_adc();
write[2] = write[0] -128;
set_adc_channel( 3 );
delay_us(40);
write[3] = read_adc();
write[3] = write[0] -128;
usb_put_packet(1,write,4,USB_DTS_TOGGLE);
}
delay_ms(1);
}
}
|
I would like to add multiple throttle for example lets say 4
Here is the modified descriptor:
Code: |
const char USB_CLASS_SPECIFIC_DESC[] =
{
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x09, 0x04, // USAGE (Joystick)
0xA1, 0x01, // COLLECTION (Application)
0x05, 0x02, // USAGE_PAGE (Simulation Controls)
0x09, 0xBB, // USAGE (Throttle)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x26, 0xFF, 0x00, // LOGICAL_MAXIMUM (255)
0x75, 0x08, // REPORT_SIZE (8)
0x95, 0x01, // REPORT_COUNT (1)
0x81, 0x02, // INPUT (Data Var Abs)
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x01, // USAGE (Pointer)
0xA1, 0x00, // COLLECTION (Physical)
0x09, 0x30, // USAGE (X)
0x09, 0x31, // USAGE (Y)
0x95, 0x02, // REPORT_COUNT (2)
0x81, 0x02, // INPUT (Data Var Abs)}
0xC0, // END_COLLECTION
0x09, 0x39, // USAGE (Hat switch)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x03, // LOGICAL_MAXIMUM (3)
0x35, 0x00, // PHYSICAL_MINIMUM (0)
0x46, 0x0E, 0x01, // PHYSICAL_MAXIMUM (270)
0x65, 0x14, // UNIT (Eng Rot:Angular Pos)
0x75, 0x04, // REPORT_SIZE (4)
0x95, 0x01, // REPORT_COUNT (1)
0x81, 0x02, // INPUT (Data Var Abs)
0x05, 0x09, // USAGE_PAGE (Button)
0x19, 0x01, // USAGE_MINIMUM (Button 1)
0x29, 0x0A, // USAGE_MAXIMUM (Button 10)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x01, // REPORT_SIZE (1)
0x95, 0x0C, // REPORT_COUNT (12) 2 bits added to switch report count
// so bytes are even. Bytes must be even.
0x55, 0x00, // UNIT_EXPONENT (0)
0x65, 0x00, // UNIT (None)
0x81, 0x02, // INPUT (Data Var Abs)
0xC0 // END_COLLECTION
};
|
Many thanks for your quick response and reviewing my code.
++++++++++++++++++
Edited to remove most code from CCS driver file.
Per forum rules - don't post CCS drivers.
- Forum Moderator
++++++++++++++++++
Last edited by andreahmed on Thu Dec 10, 2020 6:47 am; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19511
|
|
Posted: Thu Dec 10, 2020 8:10 am |
|
|
The delays need to be between selecting the channel and taking the reading.... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19511
|
|
Posted: Thu Dec 10, 2020 8:12 am |
|
|
Pull this:
<https://www.usb.org/document-library/hid-descriptor-tool>
This is the tool from the USB ORG, to design and test descriptors.
Get your descriptor passed by this first. |
|
|
andreahmed
Joined: 09 Dec 2020 Posts: 13
|
|
Posted: Thu Dec 10, 2020 8:31 am |
|
|
I stayed two days 18 hours, please help |
|
|
andreahmed
Joined: 09 Dec 2020 Posts: 13
|
|
Posted: Thu Dec 10, 2020 8:33 am |
|
|
char ReportDescriptor[38] = {
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x09, 0x04, // USAGE (Joystick)
0xa1, 0x01, // COLLECTION (Application)
0x05, 0x02, // USAGE_PAGE (Simulation Controls)
0x09, 0xbb, // USAGE (Throttle)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255)
0x75, 0x08, // REPORT_SIZE (8)
0x95, 0x01, // REPORT_COUNT (1)
0x81, 0x02, // INPUT (Data,Var,Abs)
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x01, // USAGE (Pointer)
0xa1, 0x00, // COLLECTION (Physical)
0x09, 0x30, // USAGE (X)
0x09, 0x31, // USAGE (Y)
0x95, 0x02, // REPORT_COUNT (2)
0x81, 0x02, // INPUT (Data,Var,Abs)
0xc0 // END_COLLECTION
};
here is the designed one |
|
|
andreahmed
Joined: 09 Dec 2020 Posts: 13
|
|
Posted: Thu Dec 10, 2020 8:41 am |
|
|
here is modified descriptor as your suggestions
still doesn't work as joystick
Code: |
const char USB_CLASS_SPECIFIC_DESC[] =
{
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x09, 0x04, // USAGE (Joystick)
0xa1, 0x01, // COLLECTION (Application)
0x05, 0x02, // USAGE_PAGE (Simulation Controls)
0x09, 0xbb, // USAGE (Throttle)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255)
0x75, 0x08, // REPORT_SIZE (8)
0x95, 0x01, // REPORT_COUNT (1)
0x81, 0x02, // INPUT (Data,Var,Abs)
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x01, // USAGE (Pointer)
0xa1, 0x00, // COLLECTION (Physical)
0x09, 0x30, // USAGE (X)
0x09, 0x31, // USAGE (Y)
0x95, 0x02, // REPORT_COUNT (2)
0x81, 0x02, // INPUT (Data,Var,Abs)
0xc0 // END_COLLECTION
};
|
++++++++++++++++++
Edited to remove most code from CCS driver file.
Per forum rules - don't post CCS drivers.
- Forum Moderator
++++++++++++++++++ |
|
|
andreahmed
Joined: 09 Dec 2020 Posts: 13
|
|
Posted: Thu Dec 10, 2020 9:07 am |
|
|
I'm getting crazy, I tried EVERYTHING to make it recognize as joystick, it never does. please help |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19511
|
|
Posted: Thu Dec 10, 2020 11:31 am |
|
|
Use the tool I have already pointed you to and get the descriptor right.
However I do have to ask, have you actually tested your PIC with one of
the examples?. You don't show your clock setups, so your settings could
be wrong. |
|
|
andreahmed
Joined: 09 Dec 2020 Posts: 13
|
|
Posted: Thu Dec 10, 2020 11:50 am |
|
|
I used the tool, I showed you a descriptor that I want to use.
I fed up with this actually :( |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Thu Dec 10, 2020 12:31 pm |
|
|
Hmm...depending on what you want the PIC to do, it may be a lot easier to use a TTL<>USB module. Best $2 I've ever spent,allows me to prgram the PIC and not get frustrated with USB 'bloatware'. |
|
|
andreahmed
Joined: 09 Dec 2020 Posts: 13
|
|
Posted: Thu Dec 10, 2020 2:19 pm |
|
|
I made this descriptor
Code: | 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x09, 0x04, // USAGE (Joystick)
0xA1, 0x01, // COLLECTION (Application)
0x05, 0x02, // USAGE_PAGE (Simulation Controls)
0x09, 0xBB, // USAGE (Throttle)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x26, 0xFF, 0x00, // LOGICAL_MAXIMUM (255)
0x75, 0x08, // REPORT_SIZE (8)
0x95, 0x01, // REPORT_COUNT (1)
0x81, 0x02, // INPUT (Data Var Abs)
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x01, // USAGE (Pointer)
0xA1, 0x00, // COLLECTION (Physical)
0x09, 0x30, // USAGE (X)
0x09, 0x31, // USAGE (Y)
0x95, 0x02, // REPORT_COUNT (2)
0x81, 0x02, // INPUT (Data Var Abs)}
0xC0, // END_COLLECTION
0x09, 0x39, // USAGE (Hat switch)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x03, // LOGICAL_MAXIMUM (3)
0x35, 0x00, // PHYSICAL_MINIMUM (0)
0x46, 0x0E, 0x01, // PHYSICAL_MAXIMUM (270)
0x65, 0x14, // UNIT (Eng Rot:Angular Pos)
0x75, 0x04, // REPORT_SIZE (4)
0x95, 0x01, // REPORT_COUNT (1)
0x81, 0x02, // INPUT (Data Var Abs)
0x05, 0x09, // USAGE_PAGE (Button)
0x19, 0x01, // USAGE_MINIMUM (Button 1)
0x29, 0x0A, // USAGE_MAXIMUM (Button 10)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x01, // REPORT_SIZE (1)
0x95, 0x0C, // REPORT_COUNT (12) 2 bits added to switch report count
// so bytes are even. Bytes must be even.
0x55, 0x00, // UNIT_EXPONENT (0)
0x65, 0x00, // UNIT (None)
0x81, 0x02, // INPUT (Data Var Abs)
0xC0 // END_COLLECTION // End Collection |
It doesn't work at all.
But the usb_hid descriptor works, I don't know what's wrong with it. |
|
|
andreahmed
Joined: 09 Dec 2020 Posts: 13
|
|
Posted: Thu Dec 10, 2020 2:41 pm |
|
|
here is full code
Code: |
const char USB_CLASS_SPECIFIC_DESC[] =
{
0x05, // 0
0x01, // USAGE_PAGE (Generic Desktop) ,1
0x15, //2
0x00, // LOGICAL_MINIMUM (0) ,3
0x09, //4
0x04, // USAGE (Joystick) ,5
0xa1, //6
0x01, // COLLECTION (Application) 7
0x85, // REPORT ID ,8
0x01, //ID 1 ,9
0x05, //10
0x02, // USAGE_PAGE (Simulation Controls),11
0x09, //12
0xbb, // USAGE (Throttle) ,13
0x15, //,14
0x81, // LOGICAL_MINIMUM (-127) ,15
0x25, //16
0x7f, // LOGICAL_MAXIMUM (127), 17
0x75, // 18
0x08, // REPORT_SIZE (8),19
0x95, //20
0x01, // REPORT_COUNT (1),21
0x81, //22
0x02, // INPUT (Data,Var,Abs),23
0x05, //24
0x01, // USAGE_PAGE (Generic Desktop) ,25
0x09, //26
0x01, // USAGE (Pointer) , 27
0xa1, //28
0x00, // COLLECTION (Physical), 29
0x09, //30
0x30, // USAGE (X),31
0x09, //32
0x31, // USAGE (Y),33
0x95, //34
0x02, // REPORT_COUNT (2),35
0x81, //36
0x02, // INPUT (Data,Var,Abs),37
0xc0, // END_COLLECTION,38
0x09, //39
0x39, // USAGE (Hat switch),40
0x15, //41
0x00, // LOGICAL_MINIMUM (0),42
0x25, //43
0x07, // LOGICAL_MAXIMUM (7),44
0x35, //45
0x00, // PHYSICAL_MINIMUM (0),46
0x46, //47
0x3B, //48
0x01, // PHYSICAL_MAXIMUM (315),49
0x65, //50
0x14, // UNIT (Eng Rot:Angular Pos),51
0x75, //52
0x08, // REPORT_SIZE (8),53
0x95, //54
0x01, // REPORT_COUNT (1),55
0x81, //56
0x02, // INPUT (Data,Var,Abs),57
0x05, //58
0x09, // USAGE_PAGE (Button),59
0x19, //60
0x01, // USAGE_MINIMUM (Button 1),61
0x29, //62
0x10, // USAGE_MAXIMUM (Button 16),63
0x15, //64
0x00, // LOGICAL_MINIMUM (0),65
0x25, //66
0x01, // LOGICAL_MAXIMUM (1),67
0x75, //68
0x01, // REPORT_SIZE (1),69
0x95, //70
0x10, // REPORT_COUNT (16),71
0x55, //72
0x00, // UNIT_EXPONENT (0),73
0x65, //74
0x00, // UNIT (None),75
0x81, //76
0x02, // INPUT (Data,Var,Abs),77
0xc0, // END_COLLECTION,78
}; |
++++++++++++++++++
Edited to remove most code from CCS driver file.
Per forum rules - don't post CCS drivers.
- Forum Moderator
++++++++++++++++++ |
|
|
|
|
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
|