espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.69k stars 7.29k forks source link

[TW#13919] Bluetooth HID implementation progress? (IDFGH-6354) #782

Closed huming2207 closed 6 years ago

huming2207 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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

Yulong-espressif commented 7 years ago

@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 commented 7 years ago

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

Yulong-espressif commented 7 years ago

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

huming2207 commented 7 years ago

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

Yulong-espressif commented 7 years ago

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

huming2207 commented 7 years ago

@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.

6enno commented 7 years ago

@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 commented 7 years ago

@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 commented 7 years ago

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

JeremyProffitt commented 7 years ago

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

jujucables commented 7 years ago

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 commented 7 years ago

@Yulong-espressif Hi, any updates?

cartufer commented 7 years ago

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

mamert commented 7 years ago

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

TianHao-Yoursmake commented 7 years ago

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

huming2207 commented 7 years ago

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

mringwal commented 7 years ago

@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).

6enno commented 7 years ago

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 commented 7 years ago

I too am still waiting.

FayeY commented 7 years ago

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

mringwal commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

@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 commented 7 years ago

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

6enno commented 7 years ago

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

vikoneal commented 7 years ago

@Yulong-espressif It would be great to have it since I am currently developing a project that involves HID and I am really close to the deadline. My email is deletsidi@gmail.com. Thanks a lot!!

zoutepopcorn commented 7 years ago

@Yulong-espressif can you please send me the example?

zoutepopcorn @ hotmail .com

Thanks

Yulong-espressif commented 7 years ago

@zoutepopcorn @vikoneal @6enno @jmarcelino Have sent the HID demo to your e-mail, please have a check, any question, don't hesitate to let me know.

kat-kai commented 7 years ago

@Yulong-espressif Could you send me the demo? My email is kat.kai.kat@gmail.com. Thanks!!

7evin commented 7 years ago

@Yulong-espressif I'm late to the party, but i'd love to check this out too. 7evinmcg@gmail.com

JeremyProffitt commented 7 years ago

Can someone send it to me as well? proffitt.jeremy@gmail.com Thanks!!!

huming2207 commented 7 years ago

@Yulong-espressif Sorry mate I'm a bit busy these days. Could you please send the email to huming2207@gmail.com? Thanks!

Yulong-espressif commented 7 years ago

ble_hid_device_demo.zip

Yulong-espressif commented 7 years ago

@huming2207 @JeremyProffitt Please download it directly.

kat-kai commented 7 years ago

Hi @Yulong-espressif, thank you very much for your quick response!

benjaminaigner commented 6 years ago

@Yulong-espressif

Hi, thx for the demo! I really would like to use BLE-HID with the ESP32 (opens up a LOT of possibilities). Unfortunately, I cannot run the demo, no sign of advertising. But the GPIO ISR is working as expected. so no crash.

Any hints? Or should I wait until it is released officially in the IDF?

Best wishes, Benjamin

rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:5772
load:0x40078000,len:0
load:0x40078000,len:13756
entry 0x4007901c
I (46) boot: Detected ESP32
I (31) boot: ESP-IDF v3.0-dev-1137-gd78ba789-dirty 2nd stage bootloader
I (31) boot: compile time 10:48:05
I (43) boot: Enabling RNG early entropy source...
I (43) boot: SPI Speed      : 80MHz
I (43) boot: SPI Mode       : DIO
I (46) boot: SPI Flash Size : 4MB
I (50) boot: Partition Table:
I (54) boot: ## Label            Usage          Type ST Offset   Length
I (61) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (68) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (76) boot:  2 factory          factory app      00 00 00010000 00100000
I (83) boot: End of partition table
I (87) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x3b154 (242004) map
I (166) esp_image: segment 1: paddr=0x0004b17c vaddr=0x3ffc0000 size=0x023a4 (  9124) load
I (169) esp_image: segment 2: paddr=0x0004d528 vaddr=0x40080000 size=0x00400 (  1024) load
0x40080000: _WindowOverflow4 at /home/beni/sync/Projects/FH/esp/esp-idf/components/freertos/./xtensa_vectors.S:1685

I (173) esp_image: segment 3: paddr=0x0004d930 vaddr=0x40080400 size=0x026e0 (  9952) load
I (185) esp_image: segment 4: paddr=0x00050018 vaddr=0x400d0018 size=0x8bff0 (573424) map
0x400d0018: _flash_cache_start at ??:?

I (355) esp_image: segment 5: paddr=0x000dc010 vaddr=0x40082ae0 size=0x0f458 ( 62552) load
0x40082ae0: spi_flash_erase_range at /home/beni/sync/Projects/FH/esp/esp-idf/components/spi_flash/./flash_ops.c:206

I (378) esp_image: segment 6: paddr=0x000eb470 vaddr=0x400c0000 size=0x00000 (     0) load
I (388) boot: Loaded app from partition at offset 0x10000
I (388) boot: Disabling RNG early entropy source...
I (390) cpu_start: Pro cpu up.
I (393) cpu_start: Single core mode
I (398) heap_init: Initializing. RAM available for dynamic allocation:
I (405) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
I (411) heap_init: At 3FFCF928 len 000106D8 (65 KiB): DRAM
I (417) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM
I (423) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (430) heap_init: At 40091F38 len 0000E0C8 (56 KiB): IRAM
I (436) cpu_start: Pro cpu start user code
I (117) cpu_start: Starting scheduler on PRO CPU.
I (127) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (437) phy: phy_version: 366.0, ba9923d, Oct 31 2017, 18:06:17, 1, 0
E (467) BT: esp_hidd_prf_cb_hdl(), start added the hid service to the stack database. incl_handle = 40
E (477) BT: hid svc handle = 2d
I (477) gpio: GPIO[18]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (487) gpio: GPIO[19]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (497) gpio: GPIO[21]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:1 
I (507) gpio: GPIO[27]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:1 
GPIO[27] intr, val: 0
GPIO[27] intr, val: 0
mringwal commented 6 years ago

Hi @benjaminaigner. BTstack has added HOG demos for keyboard and mouse a while ago, feel free to give them a try.

Yulong-espressif commented 6 years ago

@benjaminaigner LOG you provide from the point of view, did not find any problems. So what equipment do you use to scan? Is it a smart phone?

benjaminaigner commented 6 years ago

@Yulong-espressif : I used a Smartphone with nrfconnect app (much more sophisticated data view).

benjaminaigner commented 6 years ago

@Yulong-espressif It was a defective Sparkfun ESP32 :-(... Everything OK, but it seems to be a faulty RF frontend (nothing received)

@mringwal Thanks for the hint, I give BTSTack always a try!

FilbertWong commented 6 years ago

@Yulong-espressif First of all, thanks for your sharing demo. I have run the demo and try connecting to my android phone and basically it can control my phone's speaker volume. Then, I tried modified the demo to make it becomes a ble hid mouse function. Currently, I can control the mouse pointer on my phone but my Windows 10 PC cannot (of course, my PC has got built-in Bluetooth 4.0 le). The situation is that the message shows "driver error" when I tried pairing to PC. Do you have any ideas or suggestions for the issue I'm facing? Any third party app or somethings I can install to my PC to solve this issue?

Yulong-espressif commented 6 years ago

@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 commented 6 years ago

@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 commented 6 years ago

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

FilbertWong commented 6 years ago

@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 commented 6 years ago

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

FilbertWong commented 6 years ago

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 commented 6 years ago

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.