• Hi there !

    I'll be writing the hc-05->RN42 guide the coming week ( with screenshots ;p )

    on another subject, I uncovered dust from a STM32F3DISCOVERY yesterday & this time, took enough time to experiment with CubeMX-generated & modded stuff as well as flashing the thing.
    ( the goal is to familiarize myself enough with the stm32 environment without messing with one of my Espruino boards ;) ).
    I succefully flashed a mouse HID & a keyboard+media HID to it, but for some reason, I can't get the GamePad HID to work as intended: it's detected as such, but I still have a byte-related trouble with the buttons ( the joysticks works fine ).

    Thing is: I'm still wondering why the heck is doing so, since after multiple readings of the following code, I see no errors ? :|
    Shouldn't it work if "sizeof(struct gamepadHID_t)" equals to "HID_EPIN_SIZE" ?

    /* ==== main.c ==== */
    /* USER CODE BEGIN 1 */
    struct gamepadHID_t
      {
        //uint16_t buttons;
        uint8_t buttons1;
        uint8_t buttons2;
        int8_t left_x;
        int8_t left_y;
        int8_t right_x;
        int8_t right_y;
      };
      struct gamepadHID_t gamepadHID;
      //gamepadHID.buttons = 0b0000000000000000;
      gamepadHID.buttons1 = 0b00000000;
      gamepadHID.buttons2 = 0b00000000;
      gamepadHID.left_x = 0b00000000;
      gamepadHID.left_y = 0b00000000;
      gamepadHID.right_x = 0b00000000;
      gamepadHID.right_y = 0b00000000;
    /* USER CODE END 1 */
    
    /* USER CODE BEGIN 3 */
    //gamepadHID.buttons = 0x55AA;
      //gamepadHID.buttons = 0b0000000011111111; // works ?!
      //gamepadHID.buttons = 0b0000000111111111; // also works ?!!
      //gamepadHID.buttons = 0b0111111111111111; // also works ..
      //gamepadHID.buttons = 0b1111111111111111;
      //gamepadHID.buttons1 = 0x55;
      //gamepadHID.buttons2 = 0xAA;
      //gamepadHID.buttons1 = 0b11111111;
      //gamepadHID.buttons2 = 0b11111111;
      gamepadHID.buttons1 = 0b01111111;
      gamepadHID.buttons2 = 0b01111111;
      gamepadHID.left_x = 127;
      gamepadHID.left_y = 127;
      gamepadHID.right_x = -127;
      gamepadHID.right_y = -127;
      //USBD_HID_SendReport(&hUsbDeviceFS, &gamepadHID, sizeof(struct gamepadHID_t));
      //USBD_HID_SendReport(&hUsbDeviceFS, &gamepadHID, sizeof(struct gamepadHID_t)+2);
      //USBD_HID_SendReport(&hUsbDeviceFS, &gamepadHID, 8);
      //USBD_HID_SendReport(&hUsbDeviceFS, &gamepadHID, sizeof(struct gamepadHID_t)+1);
      //HAL_Delay(30);
      //gamepadHID.buttons = 0;
      USBD_HID_SendReport(&hUsbDeviceFS, &gamepadHID, sizeof(struct gamepadHID_t));
      //HAL_Delay(30);
      //unsigned char data[HID_DATA_IN_PACKET_SIZE] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
      //unsigned char data[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
      //uint8_t data[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
      //uint8_t data[6] = { 0x00, 0x00, 127, 127, 127, 127}; // works with below T
      //uint8_t data[6] = { 127, 00, 127, 127, 127, 127}; // nope
      //USBD_HID_SendReport(data, 6);
      //USBD_HID_SendReport(&hUsbDeviceFS, &data, sizeof(data)); // "T" works, but 'implicit declaration' ..
    /* USER CODE END 3 */
    
    /* ==== usb_hid.h ==== */
    /** @defgroup USBD_HID_Exported_Defines
      * @{
      */
    [#define](http://forum.espruino.com/sear­ch/?q=%23define) HID_EPIN_ADDR                 0x81
    [#define](http://forum.espruino.com/sear­ch/?q=%23define) HID_EPIN_SIZE                 0x06 /* max report size - for GamePad */
    // ( .. )
    [#define](http://forum.espruino.com/sear­ch/?q=%23define) HID_CUSTOM_REPORT_DESC_SIZE    46 /* GamePad HID report size */
    
    /* ==== usb_hid.c ==== */
    // TEF Edit: change 'bInterfaceSubClass' to 0 ( gamepad does not respect boot specifications )
    //                & 'nInterfaceProtocol' to 5 ( gamepad )
    __ALIGN_BEGIN static uint8_t USBD_HID_CfgDesc[USB_HID_CONFIG_DESC_SIZ­]  __ALIGN_END =
    {
    // ( .. )
    0x00,         /*bInterfaceSubClass : 1=BOOT, 0=no boot*/
    0x05,         /*nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse, 5=gamepad */
    // ( .. )
    // custom descriptor for GamePad
    __ALIGN_BEGIN static uint8_t HID_CUSTOM_ReportDesc[HID_CUSTOM_REPORT_­DESC_SIZE]  __ALIGN_END = {
      // 46 bytes
      0x05,   0x01,      // USAGE_PAGE (Generic Desktop)
      0x09,   0x05,      // USAGE (Game Pad) - Hut1_12v2.pdf p28 of 128
      0xA1,   0x01,      // COLLECTION (Application)
    
      0xA1,   0x00,      //   COLLECTION (Physical)
      0x05,   0x09,      //     USAGE_PAGE (Button)
      0x19,   0x01,      //     USAGE_MINIMUM (Button 1)
      0x29,   0x10,      //     USAGE_MAXIMUM (Button 16)
    
      0x15,   0x00,      //     LOGICAL_MINIMUM (0)
      0x25,   0x01,      //     LOGICAL_MAXIMUM (1)
      0x95,   0x10,      //     REPORT_COUNT (16)
      0x75,   0x01,      //     REPORT_SIZE (1)
    
      0x81,   0x02,      //     INPUT (Data,Var,Abs)
    
      0x05,   0x01,      //     USAGE_PAGE (Generic Desktop)
      0x09,   0x30,      //     USAGE (X)
      0x09,   0x31,      //     USAGE (Y)
      0x09,   0x32,      //     USAGE (Z) - Hut1_12v2.pdf p26 = represents R X-axis
      0x09,   0x33,      //     USAGE (Rx) - Hut1_12v2.pdf p26 = represents R Y-axis
    
      0x15,   0x81,      //     LOGICAL_MINIMUM (-127)
      0x25,   0x7F,      //     LOGICAL_MAXIMUM (127)
      0x75,   0x08,      //     REPORT_SIZE (8)
      0x95,   0x04,      //     REPORT_COUNT (4)
    
      0x81,   0x06,      //     INPUT (Data,Var,Abs) - absolute for joysticks ( != rel for mouse )
      0xC0,              //   END_COLLECTION
    
      0xc0               // END_COLLECTION
    };
    
    

    Once the above is fixed, one of the next steps is porting the Xbox360 controller code to it ( and then continue digging how to use an existing controller for the handshake part .. ).

    As a side note, I tried but coouldn't get Espruino on the board ?
    I used the Espruino_1V92 & Espruino_1V92.3 firmwares ( it seems 1V99 isn't available on the repos for the STM32F3DISCOVERY )
    ( I took not of the need for unplugging & replugging the 'USB USER' plug, but no /dev/tty<..> ever appear on my mac :/ )
    The cli commands I used are the following:

    // to flash any firmware generated from a 'make' call on CubeMX-generated files
    st-flash --format ihex write ./build/stm32f3discovery_hidTest1.hex
    // to flash Espruino firmware ? :|
    st-flash erase // to clean stuff
    st-flash write ./espruino_1v92/espruino_1v92.3_stm32f3d­iscovery.bin 0x08000000
    
About

Avatar for stephaneAG @stephaneAG started