2024-12-07 04:46 AM
Hello Everyone,
Mechanical engineer at heart, I'm still a noob when it comes to STM32 coding.
I'm trying to create a macropad (later this work might lead to a joystick) for a game I use (Starcitizen).
So far, i've managed to get the input for encoders, Hal effect sensors and switches, but i struggle on the main part, the communication with the computer (Windows PC) using custom HID.
I understand at least parts of the issue,
I get the decalration of the elements i sue as input, i understood that i have to declare a descriptor and a report for usb, but that is where i lack, too much files and data which are not easily comprehensible.
What I understood :
But that is almost all i can find.
I've used the ressources on the community and on the web, i'm almost sure all informations are inside but still i'm not able to find beginner level informations which could help on my specific needs, USB norms is quite low level coding and informations available are more on genral level and i don't know how to apply them to my needs.
do you have any hint on how to create the descriptor and report ?
thanks for your help.
2024-12-07 08:30 AM
Get HID class specification from usb.org.
2024-12-07 10:15 AM - edited 2024-12-07 10:18 AM
Thanks for your reply,
I already got them (at least Device Class Definition for Human Interface Devices HID V1.11), i think i understand which are the elements of the descriptor and the report, but how do you define the value which are described here..
For example, I got 10 buttons, two pots and one HAL sensor connected to the board, how do you define these elements in report and descriptors ? I do not understand what design 0x00 or 0x07......
I'm not a programmer, that is why i lack this knowledge which might be so common for you all.
2024-12-07 10:29 AM - edited 2024-12-07 10:30 AM
Get the usage tables document (https://usb.org/document-library/hid-usage-tables-15). The hardest part of your task is to decide how your device should be visible to the host.
And ignore the AI-generated stuff. ;)
2024-12-09 01:29 AM
So, if i understand, whatever the MCU, HID descriptor migh contain the same elements, and the specifics for ST is just in which files the data are stored ?
so now I think i have a little more understood my issues.
For the device descriptor, it "seems" to be the easiest parts and i think i'm ok with that one.
For the report descriptor on the contrary....
ok taking an example, I understand that each line define one element of the report, but what value for what line is what bugs me.. (the code under is extracted from a tutorial for a keyboard)
{
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x06, // USAGE (Keyboard)
0xa1, 0x01, // COLLECTION (Application)
0x05, 0x07, // USAGE_PAGE (Keyboard)
0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)
0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x01, // REPORT_SIZE (1)
0x95, 0x08, // REPORT_COUNT (8)
0x81, 0x02, // INPUT (Data,Var,Abs)
0x95, 0x01, // REPORT_COUNT (1)
0x75, 0x08, // REPORT_SIZE (8)
0x81, 0x03, // INPUT (Cnst,Var,Abs)
0x95, 0x05, // REPORT_COUNT (5)
0x75, 0x01, // REPORT_SIZE (1)
0x05, 0x08, // USAGE_PAGE (LEDs)
0x19, 0x01, // USAGE_MINIMUM (Num Lock)
0x29, 0x05, // USAGE_MAXIMUM (Kana)
0x91, 0x02, // OUTPUT (Data,Var,Abs)
0x95, 0x01, // REPORT_COUNT (1)
0x75, 0x03, // REPORT_SIZE (3)
0x91, 0x03, // OUTPUT (Cnst,Var,Abs)
0x95, 0x06, // REPORT_COUNT (6)
0x75, 0x08, // REPORT_SIZE (8)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x65, // LOGICAL_MAXIMUM (101)
0x05, 0x07, // USAGE_PAGE (Keyboard)
0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))
0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)
0x81, 0x00, // INPUT (Data,Ary,Abs)
0xc0 // END_COLLECTION
};
One more question, the size of the descriptor (defined in usbd_hid.h) tells that a keyboard length is 63 bytes, but why ?
I'll go back into my readings and thanks for your reply.
2024-12-10 12:56 AM
Total number of bytes in the descriptor array. You can count each byte from the descriptor: Summing these up gives 63 bytes.
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2024-12-15 12:16 AM - edited 2024-12-15 12:41 AM
Thanks for your answer FBL, I could not log in to than you before due to some ST community site issue..
Ok, what i had to understand is the structure is a sort of script and so the first column is the ID of the descriptor and the second is its value. (it took me some time to figure it out).
so, for my use, i need to create a custom Keyboard with 23 buttons with mini & maxi value of 0 & 1 and I tried to define it according to your informations and the HID usage table:
__ALIGN_BEGIN static uint8_t CUSTOM_HID_ReportDesc_FS[USBD_CUSTOM_HID_REPORT_DESC_SIZE] __ALIGN_END =
{
/* USER CODE BEGIN 0 */
0x05, 0x01, // UsagePage(Generic Desktop[0x0001])
0x09, 0x07, // UsageId(Keyboard[0x0007])
0xA1, 0x01, // Collection(Application)
0x85, 0x01, // ReportId(1)
0x05, 0x09, // UsagePage(Button[0x0009])
0x19, 0x01, // UsageIdMin(Button 1[0x0001])
0x29, 0x17, // UsageIdMax(Button 23[0x0017])
0x15, 0x00, // LogicalMinimum(0)
0x25, 0x01, // LogicalMaximum(1)
0x95, 0x05, // ReportCount(5)
0x75, 0x01, // ReportSize(1)
// usage page for other elements (leds or encoders)
0x81, 0x02, // Input(Data, Variable, Absolute, NoWrap, Linear, PreferredState, NoNullPosition, BitField)
0x95, 0x01, // ReportCount(1)
0x75, 0x06, // ReportSize(6)
0x81, 0x03, // Input(Constant, Variable, Absolute, NoWrap, Linear, PreferredState, NoNullPosition, BitField)
/* USER CODE END 0 */
0xC0 /* END_COLLECTION */
};
Are there any information missing or incorrectly written ?
Also, when i create the programm, i have this kind of error
do you know what could be the source ?
2024-12-18 12:38 PM
Hi all, for the last error, seems an issue with BOOT0 but do not seem to have any issue with the programm.
But, it do not solve my issue with the USB connexion which do not seem to be recognised by the PC.
Still on it