New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TW#13919] Bluetooth HID implementation progress? #782

Closed
huming2207 opened this Issue Jul 9, 2017 · 70 comments

Comments

Projects
None yet
@huming2207
Copy link

huming2207 commented Jul 9, 2017

Hi all,

I'm considering to build a bluetooth keyboard by myself later on with ESP32 as its microcontroller. But I can't find much details or documentations about those HID APIs. I did found a topic on Espressif forum saying "will implement it eventually". So...did you finish implementing those stuff?

Regards,
Jackson

@FayeY

This comment has been minimized.

Copy link
Collaborator

FayeY commented Jul 11, 2017

We are working on the Bluetooth HID now, it will be released in the ESP-IDF V3.0. Thanks for your interest in ESP32!

@huming2207

This comment has been minimized.

Copy link

huming2207 commented Jul 11, 2017

Okay got it, thanks. By the way, will it be released before November, 2017? @FayeY

@Yulong-espressif

This comment has been minimized.

Copy link
Contributor

Yulong-espressif commented Jul 11, 2017

@huming2207 do you means HID device or HID host, we will add the HID device soon, but we don't have plan to do the HID host now, Thanks, any other question please let me now.

@huming2207

This comment has been minimized.

Copy link

huming2207 commented Jul 11, 2017

@Yulong-espressif Hmm...should be HID device I think. I just would like to design a bluetooth mechanical keyboard by myself.

@Yulong-espressif

This comment has been minimized.

Copy link
Contributor

Yulong-espressif commented Jul 11, 2017

okey, we have the HID keyboard demo now, it will be very easy used for you. Thanks.

@huming2207

This comment has been minimized.

Copy link

huming2207 commented Jul 11, 2017

@Yulong-espressif Do you mean you've got a hardware HID keyboard demo, or just some code/libraries/documents etc?

@Yulong-espressif

This comment has been minimized.

Copy link
Contributor

Yulong-espressif commented Jul 11, 2017

@huming2207 we have the hardware HID keyboard demo now, not just the documents etc. Thanks.

@huming2207

This comment has been minimized.

Copy link

huming2207 commented Jul 11, 2017

@Yulong-espressif Ahhh nice...guess you will beat some HID chips like BCM20730 lol... By the way is there any links available? I've googled it and I can't find any further details about this hardware demo kit.

@FayeY FayeY changed the title Bluetooth HID implementation progress? [TW#13919] Bluetooth HID implementation progress? Jul 12, 2017

@6enno

This comment has been minimized.

Copy link

6enno commented Jul 22, 2017

@Yulong-espressif I am also in the process of developing an HID device using the ESP32. I can't seem to find any HID keyboard demo in the repository yet but I would be very happy if one was available. Is it possible to get a link or nudge in the right direction? The other examples have been extremely helpful.

@neilmendoza

This comment has been minimized.

Copy link

neilmendoza commented Aug 5, 2017

@Yulong-espressif Where would I find the keyboard demo code? Do you have any plans to create an example of a HID MIDI device? Thanks!

@Yulong-espressif

This comment has been minimized.

Copy link
Contributor

Yulong-espressif commented Aug 6, 2017

@neilmendoza We will pull the BLE keyboard demo to the github in the middle of this month.

@JeremyProffitt

This comment has been minimized.

Copy link

JeremyProffitt commented Aug 23, 2017

@Yulong-espressif just curious if there are any updates. Thanks!

@jujucables

This comment has been minimized.

Copy link

jujucables commented Sep 7, 2017

I would really really like an update for this! I so want to get a pcb with ESP32 inbuilt for a custom mechanical keyboard as well!

THANKS SO MUCH FOR YOUR EFFORTS! :)

@huming2207

This comment has been minimized.

Copy link

huming2207 commented Sep 7, 2017

@Yulong-espressif Hi, any updates?

@cartufer

This comment has been minimized.

Copy link

cartufer commented Sep 13, 2017

I too am waiting on "keyboard demo" as a key part of a project.

@mamert

This comment has been minimized.

Copy link

mamert commented Sep 20, 2017

@Yulong-espressif Hi, did you forget to push the keyboard demo?

@TianHao-Espressif

This comment has been minimized.

Copy link
Collaborator

TianHao-Espressif commented Sep 25, 2017

@mamert , sorry for HID demo delay. Because of the work priority, the HID demo is ready, but is still not in ESP-IDF.

@huming2207

This comment has been minimized.

Copy link

huming2207 commented Sep 25, 2017

@TianHao-Espressif @Yulong-espressif so...will it be available in December?

@mringwal

This comment has been minimized.

Copy link
Contributor

mringwal commented Sep 25, 2017

@huming2207 @mamert @cartufer Hi! You can run BTstack instead of Bluedroid on the ESP32 (https://github.com/bluekitchen/btstack/tree/master/port/esp32) and it comes with a Classic HID Keyboard demo. There's also an HID-over-GATT/BLE demo in the develop branch (and mouse demos).

@FayeY FayeY closed this Oct 23, 2017

@6enno

This comment has been minimized.

Copy link

6enno commented Oct 31, 2017

Why is this closed @FayeY? Did I miss an update? Is the bluetooth HID demo available for ESP32 without using bluekitchen? I am already using BK as an interim solution however it is slow (and a bit crashy for my particular operation) I am reluctant to spend time fixing it because I am waiting for this version to come through. My product is intended to be commercially available (eventually) and therefore the licencing for BK is not ideal.

@cartufer

This comment has been minimized.

Copy link

cartufer commented Oct 31, 2017

I too am still waiting.

@FayeY

This comment has been minimized.

Copy link
Collaborator

FayeY commented Nov 1, 2017

Sorry, my mistake. We will provide a patch recently. Sorry for the inconvenience.

@FayeY FayeY reopened this Nov 1, 2017

@mringwal

This comment has been minimized.

Copy link
Contributor

mringwal commented Nov 1, 2017

Hi @6enno Could you tell us a bit more about your experience with BTstack. It should neither be slow nor crashy.

By default, full logging, incl. HCI data is activated and this will slow down everything, but it's there for development only. You can disable logging in app_main() by commenting the call to hci_dump_open().

BTstack is not thread-safe. If you call it from a different thread, it will not work. If you have all Bluetooth code on the main thread, it should not crash. Please provide some test code for further investigation.

@6enno

This comment has been minimized.

Copy link

6enno commented Nov 1, 2017

Hi @mringwal
Reading back my message, it sounded harsh and I should apologize. I know that Bluekitchen/BTstack is great solution and commend you guys on your innovative and active development.

I didn't mean to suggest that BTStack itself was crashy and I am aware of the synchronization limits however my particular application involves a lot of high frequency interrupts and context switching between several threads. This will require me to time particular activities and make very specific modifications to the BT code.

Because this product is being developed with the view of going commercial, it will be difficult for me to navigate the licencing which is not free for commercial use as is the Apache licence for the overall esp-idf.

Also, thanks for the tip on disabling the HCI data, that should speed things up a little in the mean time however I am still reluctant to spend much time on a module that will need to be replaced.

Thanks for everyone's quick responses and help!

@Yulong-espressif

This comment has been minimized.

Copy link
Contributor

Yulong-espressif commented Nov 3, 2017

@huming2207 @6enno The BLE HID device is ready now, But will be release in the next version, if you are in a hurry, I can send you the demo.

@jmarcelino

This comment has been minimized.

Copy link

jmarcelino commented Nov 3, 2017

@Yulong-espressif can you send me demo too jmarcelino@pycom.io or post it somewhere. Thanks :)

@6enno

This comment has been minimized.

Copy link

6enno commented Nov 3, 2017

Thanks @Yulong-espressif ! that would be fantastic. em: ben.norquay@gmail.com

@Yulong-espressif

This comment has been minimized.

Copy link
Contributor

Yulong-espressif commented Nov 16, 2017

@FilbertWong I have't used it to control the PC directly, when you want to control the PC, I think you should buy a BLE dongle. For example, TI's CC2540 dongle can be controlled by the BLE PC keyboard and mouse functions.

@benjaminaigner

This comment has been minimized.

Copy link

benjaminaigner commented Nov 16, 2017

@FilbertWong
I use this demo controlling an Android 7 phone as well as a Linux PC (BT Dongle: CSR8510 A10, no built-in BLE). It works for mouse and keyboard on both devices.
I will release an extended demo soon, as replacment for all of the BT HID modules (like Adafruit EZ-Keys), and post the link here.
Including text to keystroke translation with ~20 different keyboard layouts (ASCII and Unicode/UTF8) :-)

@Yulong-espressif

There is still one problem with this demo:
If a device disconnects (out of range, BT switched off,...), I receive:

E (3184811) BT: bta_gattc_conn_cback() - cif=3 connected=0 conn_id=3 reason=0x001f
E (3184811) BT: hidd_event_callback(), ESP_HIDD_EVENT_BLE_DISCONNECT
E (3184821) BT: hidd_event_callback(), ESP_HIDD_EVENT_BLE_DISCONNECT

But there is no ESP_HIDD_EVENT_BLE_CONNECT fired, even if the host is connected again -> no HID reports are sent.
Do you have any suggestion? Maybe a missing event handler?

Thank you very much for this demo, this was a major step for me!

@benjaminaigner

This comment has been minimized.

Copy link

benjaminaigner commented Nov 16, 2017

I pushed my project to this repo:
https://github.com/asterics/esp32_mouse_keyboard

@FilbertWong

This comment has been minimized.

Copy link

FilbertWong commented Nov 17, 2017

@benjaminaigner : Thanks a lots for sharing. So I have to install the dongle's driver and plug it into PC to use, so it's no any different from another Bluetooth/Wireless mice on the market right? I just wonder if there is any ways to salvage the built-in BLE to cut down the 3rd party device :)

@FilbertWong

This comment has been minimized.

Copy link

FilbertWong commented Nov 17, 2017

@benjaminaigner : Fortunately, I update the bluetooth driver of my PC, and it can pair with my "esp32 mouse" successfully now.

@FilbertWong

This comment has been minimized.

Copy link

FilbertWong commented Nov 20, 2017

Hi All, anyone tried running Bluetooth and Wifi functions in the same time? I have a "esp32_mouse" as Bluetooth LE HID's one and I use Wifi to do file transfer system. And, I can run successfully one by one on my esp32 wrover kit. But when I tried running them in parallel, the board will reboot. Any ideas about this issue?

@chegewara

This comment has been minimized.

Copy link

chegewara commented Nov 20, 2017

I can guess its low heap amount problem. My advice is to change settings in menuconfig->wifi to lowest, mbedtls from 16kB to 512B, and add esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT); in app_main, if you are using only BLE. Thats some start.

@FilbertWong

This comment has been minimized.

Copy link

FilbertWong commented Nov 20, 2017

@chegewara : I used esp_idf 2.0 to compile my project but I couldn't find the function esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT); Then I switch to esp_if_master one to use this function but my BLE HID mouse doesn't work for me any more. It keeps show the error (please see the attached)
user code done

@chegewara

This comment has been minimized.

Copy link

chegewara commented Nov 20, 2017

Yours factory partition is too small. Look at message at 533 ms.

@FilbertWong

This comment has been minimized.

Copy link

FilbertWong commented Nov 21, 2017

@chegewara : Can I expend the size of this partition?

@chegewara

This comment has been minimized.

Copy link

chegewara commented Nov 21, 2017

@FilbertWong Of course you can. Are you using arduino ide or esp-idf?

http://esp-idf.readthedocs.io/en/latest/api-guides/partition-tables.html

@FilbertWong

This comment has been minimized.

Copy link

FilbertWong commented Nov 21, 2017

@chegewara : I use esp-idf. Could you show me how to expand it?

@chegewara

This comment has been minimized.

Copy link

chegewara commented Nov 21, 2017

You need to change settings in menuconfig. And create csv file, by default its partitions.csv.
This is example partitions.csv content:

# Espressif ESP32 Partition Table
# Name,   Type, SubType, Offset,  Size
nvs,      data, nvs,     0x9000,  0x6000
phy_init, data, phy,     0xf000,  0x1000
factory,  app,  factory, 0x10000, 1M

You need only change size of factory partition, lets say 2M will be good.

Now options:
from cli run make menuconfig and change this option:
Partition Table->Custom
All other option in this submenu can be default.

@FilbertWong

This comment has been minimized.

Copy link

FilbertWong commented Nov 21, 2017

@chegewara : thank you so much :)

@FayeY FayeY closed this Nov 21, 2017

@Sagigamil

This comment has been minimized.

Copy link

Sagigamil commented Nov 25, 2017

I'm looking for a HID host for a few days, someone have an example code to show me?

@mringwal

This comment has been minimized.

Copy link
Contributor

mringwal commented Nov 27, 2017

@Sagigamil The HID Host need to find the HID Device somehow (with Classic, doing an Inquiry and looking for devices) and then do an SDP query to get the L2CAP PSMs for HID Interrupt & Control and then open these. HID Reports can be received then (more or less).

For LE, it's similar, just using GATT operations instead of the SDP query.
We don't have ready code for BTstack for this either yet.

@mringwal

This comment has been minimized.

Copy link
Contributor

mringwal commented Nov 27, 2017

@Sagigamil I've added an HID Host example to BTstack's develop branch that connects to a known device, gets the PSMs from SDP and opens the HID channels. You're receiving HID reports now. To properly use them, you'd need an HID parser still, but maybe the current version might already help.

https://github.com/bluekitchen/btstack/blob/develop/example/hid_host_demo.c

@chegewara

This comment has been minimized.

Copy link

chegewara commented Dec 18, 2017

@Sagigamil are you still looking for hid example?

@Sagigamil

This comment has been minimized.

Copy link

Sagigamil commented Dec 18, 2017

@chegewara no, thank you!
the issue can close :)

@chegewara

This comment has been minimized.

Copy link

chegewara commented Dec 18, 2017

@Sagigamil it is already closed, just asking because im ending implementing GenericHID class

@Sagigamil

This comment has been minimized.

Copy link

Sagigamil commented Dec 18, 2017

@chegewara I would be happy to receive the source code

@chegewara

This comment has been minimized.

Copy link

chegewara commented Dec 18, 2017

i will make PR here https://github.com/nkolban/esp32-snippets in 1-2 days

@Sagigamil

This comment has been minimized.

Copy link

Sagigamil commented Dec 18, 2017

@chegewara OK, thank you very much!

@chegewara

This comment has been minimized.

@chegewara

This comment has been minimized.

Copy link

chegewara commented Dec 19, 2017

@ghost

This comment has been minimized.

Copy link

ghost commented Jan 16, 2018

Can esp32 be used as a HID host?

@chegewara

This comment has been minimized.

Copy link

chegewara commented Jan 16, 2018

As far as i understand hid and esp32 bluetooth the answer is yes, but you have to write your own driver with parser.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment