Bluetooth 4 HID Keyboard & Mouse Bridge

Just keeping up to date, I’ve written a firmware for Texas Instruments CC2540 Bluetooth Low Energy IC that sends keyboard & mouse reports to the host using a few UART commands that works similarly to Arduino Keyboard’s press() and release() commands, except it will send raw HID keycodes instead of printable characters. As for the mouse, a UART command with button states, X, Y, Z bytes can be used at the same time as well.
The firmware isn’t as good as if it is programmed by professional software engineers and if IAR Workbench was free so I can spend an infinite amount of time tweaking, but it does the job. The advantage to using a CC2540 with my firmware means you can turn any cheap eBay HM-10 serial Bluetooth module into a HID Bluetooth keyboard & mouse bridge! The disadvantage would be that to write a new firmware, you would need to use IAR Embedded Workbench for 8051 which is free for 30 days or cost $3k if you buy it. However, for just flashing, IAR is not needed. So as an end-user, there are essentially no disadvantages.

The  UART commands are sent to the CC2540 via UART at 57600bps with 8 data bits and no parity. They must end with a carriage return (0x0D, ‘\r’) or a line termination character (0x0A, ‘\n’), or both. The commands include:

  • KU(keycode): a key is released with the keycode (keycode)
  • KD(keycode): a key is pressed with the keycode (keycode)
  • M(status)(X)(Y)(Z): sending buttons and mouse coordinates
  • KUPDATE: send report to host

(___) are 8-byte characters, and you don’t send the brackets, just the value inside the brackets. The (keycode) used are from USB HID usage table 1.12 in the keyboard section. Since I haven’t made a full keyboard board, the module will ask the host for pin, which is 000000. There is also another firmware that advertise the device with containing a keyboard so the user must use the keyboard to enter the pin, but a test board is needed thus this has not been tested.

Here is a pretty 3D render of the board I’ve whipped up.
It uses a MSP430 to handle the keyboard scanning and TrackPoint polling. The entire top left portion of the board is dedicated to power management. Battery used can be of any types in the range of 3V-5V. If the battery is a rechargeable Li-Po or Li-Ion single cell, the Micro USB can be used to recharge it. There are 2 LEDs (Green and Yellow) indicating if external power is present and whether the battery is being charged.
On this board, the battery connector used is a JST-PH 2.0mm 2-pin right angle connector. It is used for many battery packs for Remote Controlled toys though I have found that there is also 1.5mm, 1.25mm and 2.5mm. It just happens that the 2.0mm is cheap and available.
Beep beep boop, forgot to include a link to the released source code and binaries. Here it is:

9 thoughts on “Bluetooth 4 HID Keyboard & Mouse Bridge

  1. hello..
    I have tested HM-10 having CC2541 IC on it. It is programmed well with Texas Instruments SmartRF Flash Programmer with both HM-10_CC2541_KeyboardOnly.hex and HM-10_CC2541_DisplayOnly.hex .
    But can’t see the device when I search it on my PCs or phone. (I have tested with new Toshiba PC also,)

    1. Does it advertise the device as keyboard?
    2. or any special procedure to pair device?
    3. Any important settings when programming the .Hex?
    4. Does it show on mobile phones which are having Bluetooth 4?

    Best Regards,
    Lasantha Prasad

  2. Hey Lasantha,

    1. It advertise itself as keyboard and mouse device
    2. You need to start sending a report to the host like a key or mouse movement before the host can detect the device. Due to the 30-day trial, I didn’t have much time to find a solution to this.
    3. No important settings
    4. It requires devices with Bluetooth 4.0 to work.

  3. Thank you very much for your quick reply.

    Tested again, same result.
    I am using FTDI Serial to USB TTL devcie to send command to HM-10.

    IAR 8051 installed as 30 days Trial and try to build the source, following errors were appeared. searched everywhere for solution..

    Error[Pe020]: identifier “bStatus_t” is undefined C:\Texas Instruments\BLE-CC254x-1.4.0\Projects\ble\Profiles\HidDev\hiddev.h 398
    Error[Pe020]: identifier “bStatus_t” is undefined C:\Texas Instruments\BLE-CC254x-1.4.0\Projects\ble\Profiles\HidDev\hiddev.h 413
    Error[Pe020]: identifier “gattAttribute_t” is undefined C:\Texas Instruments\BLE-CC254x-1.4.0\Projects\ble\Profiles\HidDev\hiddev.h 442
    Error[Pe020]: identifier “bStatus_t” is undefined C:\Texas Instruments\BLE-CC254x-1.4.0\Projects\ble\Profiles\HidDev\hiddev.h 458
    Error[Pe020]: identifier “gattAttribute_t” is undefined C:\Texas Instruments\BLE-CC254x-1.4.0\Projects\ble\Profiles\HidDev\hiddev.h 458
    Warning[Pe177]: function “KBD_Report_isEmpty” was declared but never referenced C:\Texas Instruments\BLE-CC254x-1.4.0\Projects\ble\cc2540_hidKbdM\Source\KBD_Report.c 138
    Error while running C/C++ Compiler

    Lasantha Prasad

    1. Sorry I can’t help you much with this. IAR 8051 no longer allows me to compile anything as my trial has expired. Are you sure you placed the project into BLE-CC254x-1.4.0\Projects\ble\?

    2. This is a rather weird error. I just installed IAR on my laptop and I got the same error. I haven’t tested the compiled firmware on a module but here’s a workaround to suppress the error. In hiddev.h, include bcomdef.h and gatt.h.

      Screenshot of workaround

  4. Hi,
    I have the same issue. Programming the hex files onto the HM-10 works well. Device is not visibile afterwards.
    After a lot of testing I found out, that the Module is visible for about 1 second after powering it up then it disapears agian.
    Would be great if you can help me.

    1. Last year it worked well on my Nexus 7 Android 4.1-4.2. but ever since 4.3.x update, I’ve found that the device does not remain visible for long and can’t be discovered by other devices.

      I’m planning to fix the problem sometime later during this year using the new TI BLE stack and also get all the new features.

      1. Thanks for your information. It would be great if you can do the adaptions as soon as possible 🙂
        If we can enforce your work anyhow, please let us know.

      2. Hi Mick, I moved to another state for a job a month ago and forgot bring my CC-Debugger and development board with me, so I can’t do any development work. Sorry about that.

        I’ll probably get back when I go home for holiday or something.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s