This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LAUNCHXL-CC2640R2: Create HID BLE mouse

Part Number: LAUNCHXL-CC2640R2
Other Parts Discussed in Thread: CC2541

Hi! 

I'm trying to use LAUNCHXL-CC2640R2 with hid_emu_kbd_cc2640r2lp_app as an HID mouse. I used the original code and it worked fine, when the buttons are pressed on the board the device writes "a" or "b" on the pc/smartphone. So I enable the compiler variable USE_HID_MOUSE and then changed the place where hid keyboard reports are called then I putted hid mouse reports there, just like the code below:

/*********************************************************************
 * @fn      HidEmuKbd_handleKeys
 *
 * @brief   Handles all key events for this device.
 *
 * @param   keys - bit field for key events. Valid entries:
 *                 KEY_UP
 *                 KEY_RIGHT
 *
 * @return  none
 */
static void HidEmuKbd_handleKeys(uint8_t keys)
{
  if (keys & KEY_LEFT)
  {
    // Key Press.
    //HidEmuKbd_sendReport(KEY_LEFT_HID_BINDING);

      HidEmuKbd_sendMouseReport(-2);// Cursor moves to the left
    // Key Release.
    // NB: releasing a key press will not propagate a signal to this function,
    // so a "key release" is reported immediately afterwards here.
    //HidEmuKbd_sendReport(KEY_NONE);
  }

  if (keys & KEY_RIGHT)
  {
    // Key Press.
      HidEmuKbd_sendMouseReport(2);//Cursor moves to the right
    //HidEmuKbd_sendReport(KEY_RIGHT_HID_BINDING);

    // Key Release
    // NB: releasing a key press will not propagate a signal to this function,
    // so a "key release" is reported immediately afterwards here.
    //HidEmuKbd_sendReport(KEY_NONE);
  }
}

#ifdef USE_HID_MOUSE
/*********************************************************************
 * @fn      HidEmuKbd_sendMouseReport
 *
 * @brief   Build and send a HID mouse report.
 *
 * @param   buttons - Mouse button code
 *
 * @return  none
 */
static void HidEmuKbd_sendMouseReport(uint8_t buttons)
{
  uint8_t buf[HID_MOUSE_IN_RPT_LEN];

  buf[0] = 0;   // Buttons
  buf[1] = buttons;         // X
  buf[2] = 0;         // Y
  buf[3] = 0;         // Wheel
  buf[4] = 0;         // AC Pan

  HidDev_Report(HID_RPT_ID_MOUSE_IN, HID_REPORT_TYPE_INPUT,
                HID_MOUSE_IN_RPT_LEN, buf);
}
#endif // USE_HID_MOUSE

So I was expecting that when my board was paired it would create a mouse cursor on the central device and when the buttons were pressed the cursor would move to the corresponding directions, but nothing happens.

Regards,

Bruno.

  • Hi Bruno,

    I have not tried the HID Mouse. But you need to send HID Commands not 2 or -2. Not sure what are the HID commands for cursor movement. But for the HID mouse buttons are below which can be found at hiddev.h

    #define HID_MOUSE_BUTTON_LEFT 253
    #define HID_MOUSE_BUTTON_MIDDLE 254
    #define HID_MOUSE_BUTTON_RIGHT 255

    -kel

  • Hi!

    Markel Robregado said:
    But you need to send HID Commands

    Well, I don't think it is the case, I was working in a similar project with CC2541 and I was using this function just like the code a sent, I'm not sure but I was thinking if there is something else I need to do to make HID mouse descriptor work. 

    Markel Robregado said:
    But for the HID mouse buttons are below

    I tried this changes, but they didn't take any effect.

    Thanks!

  • Bruno,

    I will assign an expert that will be able to help you. What SDK are you using?

    -Luis

  • HI Bruno,

    I have a few questions that will help us get to a solution as quickly as possible. What version of the SDK are you using? What kind of device is your central? What operating system is the central running (Windows, Android, ect)?

    Regards,

    Jan

  • Hi!

    Jan Iglesias Morales said:
    What version of the SDK are you using?

    I'm using Simple CC2640R2 SDK version 1.50.0.58 with Simple CC2640R2 SDK BLE example Pack version 1.50.0.62 (The project I'm using is from this last one , but it needs the first one to work, as you know)

    Jan Iglesias Morales said:
    What kind of device is your central? What operating system is the central running (Windows, Android, ect)?

    I'm using with two central devices, one is the PC (Windows operating system) and the other is a Samsumg Smartphone with Android.

    Regards, 

    Bruno.

  • Hi Bruno,

    The provided example is configured to primarily send key presses. It may be modified to send mouse movements, but it would require several changes to the code and general logic of the program. The sendMouseReport function would have to be changed to take the vertical and horizontal mouse movements as its inputs. The sendMouseReport function would likely have to be called periodically to keep the cursor in motion. I believe you are going down the right track with the modifications you have already provided. I suggest looking into the HID over GATT Bluetooth specification as well as the HID mouse resources for more information. I believe they will provide you with a great starting point to make the necessary modifications.

    Regards,

    Jan