cancel
Showing results for 
Search instead for 
Did you mean: 

Custom HID Device (Joystick)

MHovi.1
Associate II

Hi there,

I have an old joystick which i want to convert to a custom hid device, the stick has three shiftin registers (cd4201) which i am reading using spi1. I know these shift register are being read cause i am sending it to serialport3 (just for debugging)and read values in docklight.

I have set up mu nucleo F413ZH as a custom hid device and my computer is detecting it as hid game device. I have generated my own report descriptor and is 65 byte long.

Following some tutorials spread over the net i cant get it to work.

By not work i think my data is not being send by using the USBD_CUSTOM_HID_SendReport.

I have set my EPIN and EPOUT to 64 bytes as recommended in various topics. But nothing is happening . But when i set my EPIN to 2 bytes and EPOUT 64 byte buttons in my device manger flashing randomly. And Axis values are all over the place.

My code is not fully done jet, for now I just want to see if my buttons are working in my device manager.​

I have added some code

Report descriptor

__ALIGN_BEGIN static uint8_t CUSTOM_HID_ReportDesc_FS[USBD_CUSTOM_HID_REPORT_DESC_SIZE] __ALIGN_END =
{
		 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)
				    0x16, 0x01, 0x80,              //   LOGICAL_MINIMUM (-32767)
				    0x26, 0xff, 0x7f,              //   LOGICAL_MAXIMUM (32767)
				    0x75, 0x10,                    //   REPORT_SIZE (16)
				    0x95, 0x01,                    //   REPORT_COUNT (1)
				    0x81, 0x06,                    //   INPUT (Data,Var,Rel)
				    0x05, 0x01,                    //   USAGE_PAGE (Generic Desktop)
				    0x09, 0x30,                    //   USAGE (X)
				    0x09, 0x31,                    //   USAGE (Y)
				    0x09, 0x33,                    //   USAGE (Rx)
				    0x09, 0x34,                    //   USAGE (Ry)
				    0x16, 0x01, 0x80,              //   LOGICAL_MINIMUM (-32767)
				    0x26, 0xff, 0x7f,              //   LOGICAL_MAXIMUM (32767)
				    0x75, 0x10,                    //   REPORT_SIZE (16)
				    0x95, 0x04,                    //   REPORT_COUNT (4)
				    0x81, 0x02,                    //   INPUT (Data,Var,Abs)
				    0x05, 0x01,                    //   USAGE_PAGE (Generic Desktop)
				    0x05, 0x09,                    //   USAGE_PAGE (Button)
				    0x19, 0x01,                    //   USAGE_MINIMUM (Button 1)
				    0x29, 0x20,                    //   USAGE_MAXIMUM (Button 32)
				    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
				    0x25, 0x01,                    //   LOGICAL_MAXIMUM (1)
				    0x95, 0x20,                    //   REPORT_COUNT (32)
				    0x75, 0x01,                    //   REPORT_SIZE (1)
				    0x81, 0x02,                    // INPUT (Data,Var,Abs)
  /* USER CODE BEGIN 0 */
  //0x00,
  /* USER CODE END 0 */
  0xC0    /*     END_COLLECTION	             */
};

usbd_config.h

#define USBD_MAX_NUM_INTERFACES     1U
/*---------- -----------*/
#define USBD_MAX_NUM_CONFIGURATION     1U
/*---------- -----------*/
#define USBD_MAX_STR_DESC_SIZ     512U
/*---------- -----------*/
#define USBD_DEBUG_LEVEL     0U
/*---------- -----------*/
#define USBD_LPM_ENABLED     0U
/*---------- -----------*/
#define USBD_SELF_POWERED     1U
/*---------- -----------*/
#define USBD_CUSTOMHID_OUTREPORT_BUF_SIZE     65//byte
/*---------- -----------*/
#define USBD_CUSTOM_HID_REPORT_DESC_SIZE     65//byte
/*---------- -----------*/
#define CUSTOM_HID_FS_BINTERVAL     0x1U
 
/****************************************/
/* #define for FS and HS identification */
#define DEVICE_FS 		0
#define DEVICE_HS 		1

USBD_customhid.h

#define CUSTOM_HID_EPIN_ADDR                         0x81U
#define CUSTOM_HID_EPIN_SIZE                         0x02U //0x02 original
 
#define CUSTOM_HID_EPOUT_ADDR                        0x01U
#define CUSTOM_HID_EPOUT_SIZE                        0x40U //0x02 original
 
#define USB_CUSTOM_HID_CONFIG_DESC_SIZ               41U
#define USB_CUSTOM_HID_DESC_SIZ                      9U
 
#ifndef CUSTOM_HID_HS_BINTERVAL
#define CUSTOM_HID_HS_BINTERVAL                      0x05U
#endif /* CUSTOM_HID_HS_BINTERVAL */
 
#ifndef CUSTOM_HID_FS_BINTERVAL
#define CUSTOM_HID_FS_BINTERVAL                      0x01U
#endif /* CUSTOM_HID_FS_BINTERVAL */
 
#ifndef USBD_CUSTOMHID_OUTREPORT_BUF_SIZE
#define USBD_CUSTOMHID_OUTREPORT_BUF_SIZE            0x41U  //byte
#endif /* USBD_CUSTOMHID_OUTREPORT_BUF_SIZE */
 
#ifndef USBD_CUSTOM_HID_REPORT_DESC_SIZE
#define USBD_CUSTOM_HID_REPORT_DESC_SIZE             0x41 //byte// original 163U
#endif /* USBD_CUSTOM_HID_REPORT_DESC_SIZE */
 
#define CUSTOM_HID_DESCRIPTOR_TYPE                   0x21U
#define CUSTOM_HID_REPORT_DESC                       0x22U
 
#define CUSTOM_HID_REQ_SET_PROTOCOL                  0x0BU
#define CUSTOM_HID_REQ_GET_PROTOCOL                  0x03U
 
#define CUSTOM_HID_REQ_SET_IDLE                      0x0AU
#define CUSTOM_HID_REQ_GET_IDLE                      0x02U
 
#define CUSTOM_HID_REQ_SET_REPORT                    0x09U
#define CUSTOM_HID_REQ_GET_REPORT                    0x01U
/**
  * @}
  */

Hope some can help out or point me in the right direction,

Thanks in advance

0 REPLIES 0