Hamberthm / esp32-bt2ps2

Use a Bluetooth or BLE keyboard and mouse with your machine with a PS/2 port
MIT License
26 stars 6 forks source link

Mini keyboard accessory buttons not working #7

Closed TwinTurbine closed 1 month ago

TwinTurbine commented 4 months ago

Hi again!

As I couldn't get the code ported by @acepe to compile I decided to 'port' the v0.4 code to both the ESP32-S3 as well as the ESP32-C3 from scratch. The difference between the C3 and the S3 is minor, but now it seems to be working.

Anyways, using a mini BLE keyboard such as the Rii i4 there are a few buttons that the MCU doesn't react to. As far as i understand the mouse functionality hasn't been implemented yet but since the "shoulder buttons" of the keyboard are quite conveniently placed, would it be possible to assign a function to a button like that, such as "Enter/Return"? How could that be accomplished?

On the older firmware I seem to remember that the MCU would print when a button was depressed, but since v0.4? the terminal is completely silent except from status messages regarding connect/disconnect. Is it possible to reactivate that feedback again?

Kind regards, TT

Hamberthm commented 4 months ago

Hi there!

As I couldn't get the code ported by @acepe to compile I decided to 'port' the v0.4 code to both the ESP32-S3 as well as the ESP32-C3 from scratch. The difference between the C3 and the S3 is minor, but now it seems to be working.

Nice! Could you please provide a link to your fork? So I can permalink this issue on the readme as well so people with those variants can get an easier start.

On the older firmware I seem to remember that the MCU would print when a button was depressed, but since v0.4? the terminal is completely silent except from status messages regarding connect/disconnect. Is it possible to reactivate that feedback again?

Kind regards, TT

In main.cpp there are many logging/debug function calls that provide the info you need. More specifically, at line 379 you have what you are looking for:

https://github.com/Hamberthm/esp32-bt2ps2/blob/e4298b657bce084e72884f15ce24aac141fd48a8/main/main.cpp#L379

This call will echo the USB HID code received from the keyboard in the serial monitor, before passing it to the keyboard.keyHid_send() function to be translated to the PS2 protocol Control Code.

Yes, you're correct, for v0.4 I turned the verbosity level down to avoid spamming the serial console, as it is a pretty stable build. To be able to see this debug message, you need to elevate the ESP-IDF logging verbosity to "debug" level or higher. This is done via the ESP-IDF Project Configuration page. For more info Google "ESP-IDF project configuration on Visual Studio Code" (I think it was done by typing "config" on the search bar on top of VS Code, enter the Project Configuration page, then search for the verbosity setting) or look here.

Anyways, using a mini BLE keyboard such as the Rii i4 there are a few buttons that the MCU doesn't react to. As far as i understand the mouse functionality hasn't been implemented yet but since the "shoulder buttons" of the keyboard are quite conveniently placed, would it be possible to assign a function to a button like that, such as "Enter/Return"? How could that be accomplished?

The USB HID codes are not the same for the PS2 Control Codes. The most important function of this project is the one that translates the received USB code to the proper PS2 Control Code, before doing the transmission to the Host System. This fuction it's located at esp32-ps2dev.cpp file at line 1294:

https://github.com/Hamberthm/esp32-bt2ps2/blob/e4298b657bce084e72884f15ce24aac141fd48a8/main/esp32-ps2dev.cpp#L1294

To accomplish what you want, first you need to know what USB HID code your keyboard is sending when you press the desired shoulder button, for this use the "debug" verbosity logging level and watch the serial console as you press the button. Once you know the code, you need to map it to the PS2 Control Code you want in the above function by adding a "case:" statement in the function. PS2 is somewhat limited in the amount of control codes, in contrast to modern USB HID (for example, it lacks many modern multimedia codes).

Good luck, I'm here for any help I can provide. Sorry for the late response.

Cheers! Humberto

TwinTurbine commented 2 months ago

Hi there!

Thanks for the detailed ranswer on my last question and sorry in return for my delayed response. To start with I've never forked a project and therefore never committed any changes to a GitHub project before. But I will of course read up on how to do that. As of today I'm keeping the S3 and C3 versions separate as they required somewhat different changes. But I'm shure that can be handled easily in the same code with a few ifdef statements.

However, I have now followed your instructions regarding mapping of more HID codes to existing scan codes but I havn't been lucky with that yet. I have recorded what USB HID codes are being received but I'm not shure how to proceed from here. Let me explain:

When depressing the letter "A" key I get the following:

D (34720) BTKeyboard: 00 00 04 00 00 00 00 00 D (34723) KEYS PASSED TO MAIN: : 04 00 00 00 00 00 D (34728) BTKeyboard: Down key: 4 D (34846) event: running post ESP_HIDH_EVENTS:2 with handler 0x4200befc and context 0x3fcad4c0 on loop 0x3fca7d78 0x4200befc: esp_ble_hidh_event_handler_wrapper at C:/Users/Project/esp/v5.2.1/esp-idf/components/esp_hid/src/ble_hidh.c:621

D (34847) BTKeyboard: 00 00 00 00 00 00 00 00 D (34851) KEYS PASSED TO MAIN: : 00 00 00 00 00 00 D (34856) BTKeyboard: Up key: 4

The software will interpret this command perfectly and print the letter "A". This goes of course for the other letters and numbers as well.

The keyboard I'm working with, a Rii i4, has a few special keys ("multimedia buttons") and only one of them seems to be mapped as of today. When pressing the "Menu" button, it corresponds to right-clicking the mouse in the current window. The debug session then prints the following:

D (149327) BTKeyboard: 00 00 65 00 00 00 00 00 D (149331) KEYS PASSED TO MAIN: : 65 00 00 00 00 00 D (149336) BTKeyboard: Down key: 65 D (149446) event: running post ESP_HIDH_EVENTS:2 with handler 0x4200befc and context 0x3fcad4c0 on loop 0x3fca7d78 0x4200befc: esp_ble_hidh_event_handler_wrapper at C:/Users/Project/esp/v5.2.1/esp-idf/components/esp_hid/src/ble_hidh.c:621

D (149447) BTKeyboard: 00 00 00 00 00 00 00 00 D (149451) KEYS PASSED TO MAIN: : 00 00 00 00 00 00 D (149456) BTKeyboard: Up key: 65

There are however a few unmapped buttons that will produce the following results (only the BTKeyboard result is included):

Volume - : BTKeyboard: ea 00
Volume + : BTKeyboard: e9 00
Mute :     BTKeyboard: e2 00
"Home" :   BTKeyboard: 23 02
"Undo" :   BTKeyboard: 24 02

There's also a scroll wheel with three functions as well as two shoulder push buttons on the keyboard generating the following output:

Scroll up :   BTKeyboard: 00 00 00 01
Scroll down : BTKeyboard: 00 00 00 ff
Scroll push:  BTKeyboard: 04 00 00 00
R-button :    BTKeyboard: 02 00 00 00
L-button :    BTKeyboard: 01 00 00 00

From here on I'm uncertain about how to proceed since the bt2ps2 doesn't seem to interpret the two-byte HID codes at all, and not all single-byte codes. Can I suppose that the two-byte commands share similarity with the mouse functionality that isn't fully implemented yet? A touch of the touchpad will also send two bytes, as far as I can see, but that will undoubtedly make the process go into an infinite loop. I will describe that further on in a separate issue as I don't know if that's a keyboard or software issue.

I will continue to investigate this but if you have any leads about how to handle these special buttons I will be more than happy to hear from you. Thanks!

Have a great day!

TwinTurbine commented 2 months ago

Thought I might attach the output from when the keyboard is connected as well, if that helps.

BDA:d1:00:45:ba:77:b8, Appearance: 0x03c0, Connection ID: 0
Name: i4, Manufacturer: , Serial Number:
PID: 0x022c, VID: 0x05ac, VERSION: 0x0001
Battery: Handle: 14, CCC Handle: 15
Report Maps: 1
  Report Map Length: 160
       MOUSE   INPUT REPORT, ID:  3, Length:   4, Permissions: 0x1a, Handle:  48, CCC Handle:  49
       MOUSE   INPUT   BOOT, ID:  3, Length:   3, Permissions: 0x1a, Handle:  45, CCC Handle:  46
     GENERIC   INPUT REPORT, ID:  6, Length:   0, Permissions: 0x12, Handle:  41, CCC Handle:  42
    KEYBOARD  OUTPUT REPORT, ID:  1, Length:   1, Permissions: 0x0e, Handle:  38, CCC Handle:   0
    KEYBOARD   INPUT REPORT, ID:  1, Length:   8, Permissions: 0x1a, Handle:  34, CCC Handle:  35
    CCONTROL   INPUT REPORT, ID:  2, Length:   2, Permissions: 0x1a, Handle:  30, CCC Handle:  31
    KEYBOARD  OUTPUT   BOOT, ID:  1, Length:   1, Permissions: 0x0e, Handle:  28, CCC Handle:   0
    KEYBOARD   INPUT   BOOT, ID:  1, Length:   8, Permissions: 0x1a, Handle:  25, CCC Handle:  26
  BLE: d1:00:45:ba:77:b8, RSSI: -55, USAGE: GENERIC, APPEARANCE: 0x03c1, ADDR_TYPE: 'RANDOM', NAME: i4

Regards

Hamberthm commented 2 months ago

Hi again! Thanks for reaching back.

First of all, maybe a read to issue #10 will help you understand what's happening here.

The code only works with HID reports that comply to the "BOOT" standard compatibility type. That is, an 8-byte length report where the first byte is the modifier key, then a blank (ignored) byte, and 6 more key bytes. In your keyboard's report map, that would be ONLY the last type:

KEYBOARD INPUT BOOT, ID: 1, Length: 8, Permissions: 0x1a, Handle: 25, CCC Handle: 26

The "menu" key seems to be sending this kind of report and sending a normal HID 0x65 code that maps to PS/2's menu key, so you can map it to whatever you want in this line:

https://github.com/Hamberthm/esp32-bt2ps2/blob/e4298b657bce084e72884f15ce24aac141fd48a8/main/esp32-ps2dev.cpp#L1585

case 0x65:
  key = scancodes::Key::K_MENU;
  break;

Now for the other keys, the KB is sending a totally different report with clearly is the following type, as seen in the report map:

CCONTROL INPUT REPORT, ID: 2, Length: 2, Permissions: 0x1a, Handle: 30, CCC Handle: 31

The code only allows for input reports of usage "KEYBOARD" (not CCONTROL) and report ID's of type 1 (usually the BOOT reports are of ID 1). The event of other types are filtered in the callback function before being sent to the push_key() function:

https://github.com/Hamberthm/esp32-bt2ps2/blob/e4298b657bce084e72884f15ce24aac141fd48a8/main/bt_keyboard.cpp#L1057

We need to adapt the code to accept your CCONTROL type reports and pass them as keys to MAIN.cpp. I can come up with a personalized patch similar to what I did in Issue#10. Please stand by!

TwinTurbine commented 2 months ago

Hi!

WIth reference to the other issue ( #11 ) we have been discussing I'm wondering if it would be possible to adapt the code to accept some limited set of MOUSE reports as well? I might be asking for too much now but I would like to be able to map the scroll wheel of the mouse to Pg Up and Pg Dn since the mini keyboard doesn't contain these keys.

It's still of interest to have the CCONTROL buttons working as well but the scroll wheel and "mouse" buttons would be more useful, at least to me. The touch pad can be omitted, at least for now, unless it's "all or nothing". My wish is just to repurpose buttons and scroll wheel (MOUSE/CCONTROL) to normal keyboard button presses. What is your assessment of the feasability of this?

Hamberthm commented 2 months ago

Hi!

Yes, we can.

I was working in this issue during the week, and I discovered the PS2 module of the code supports multimedia keys with no problem, we just need to accept and pass the CCONTROL codes to main module.

Unfortunately, during testing I came across a major bug on the HIDH code (coming from ESPRESSIF themselves) where the multimedia keys on my K380 keyboard are not being registered correctly and are not even being passed to the callback function like yours are.

I have to diagnose it further and/or report this to ESPRESSIF for a fix. HIDH (HID HOST) code is very fresh from them and we are prone to things like this.

The K380 is the only BT keyboard with multimedia keys I have so until I can solve this I need you to wait a little. I want to make this universal so we can add multimedia key support to the project, and so I don't make a blind patch for you.

If you're interested, bug is the same as this one but it gives me it only with multimedia keys: https://github.com/espressif/esp-idf/issues/8318

Will keep you informed!

TwinTurbine commented 2 months ago

Hello!

Thanks for the fast feedback! I'm in the unfortunate position of not having a K380 keyboard on the other hand so I might not be able of much help there. But since the K380 seems to be an "OS-adaptive keyboard" with automagical detection of the current OS, does it make any difference if you force the keyboard into one or another of the two modes?

According to the manual this can be performed by pressing "fn + I" or "fn + P" for three seconds respectively to switch between the different modes. Unless you've already ruled this out it might be worth trying at least. :-)

https://www.logitech.com/index.cfm?seo=en-gb/manuals/k380-setup-guide&

Hamberthm commented 2 months ago

Yup! Already tried those mode changes. Thanks!!

I made a new issue on IDF #14259. I think I can get it locally patched, as soon as I have it sorted I will add multimedia/CCONTROL keys to the project.

TwinTurbine commented 2 months ago

Great, I hope this can be somewhat easily fixed. I wonder if the Logitech engineers will look into this as well? All this is quite intriguing since I thought these protocols where quite "standardized" and that it wouldn't be possible to deviate from them without instant problems... :-D

Hamberthm commented 2 months ago

Hi!

We are already negotiating a workaround patch with Espressif. Logitech is informed as well. In any case, I already patched the issue locally in my stack so we can go on!

I'm no master in this and I've been learning and reading a lot about USB HID, this is the protocol that gets transported over Bluetooth or cable and what we are working with.

To successfully add multimedia/accessory keys support to the project, first I need to know how each keyboard encodes and sends these keys over the transport protocol. For the normal keys, this is trivial because it is highly standardized and described in the HID Usage Tables document, and this is how the project works so far.

Instead, for multimedia keys, it depends on the keyboard Vendor decision on how the keys will be reported, as the HID specification allows for custom formats. (https://stackoverflow.com/questions/57793525/unusual-usb-hid-reports)

In the case of your keyboard, it seems to send Custom Control Usage Codes directly. Instead, my Logitech K380 sends a 2-byte report with each Bit on those bytes representing a particular multimedia key that can be set (1) or unset (0).

So, how do I identify wich format is the keyboard using so I can make the project universal? The instructions come in the form of a HID descriptor that the keyboard sends on each connection event. Then, Espressif's HIDH stack translates this descriptor so to make the familiar Report Map we already know.

The HID Descriptor includes instructions on how to interpret each report and, for example in my K380 case, how each bit relates directly to a multimedia key:

0x05, 0x0C, // Usage Page (Consumer) 0x09, 0x01, // Usage (Consumer Control) 0xA1, 0x01, // Collection (Application) 0x85, 0x02, // Report ID (2) 0x15, 0x00, // Logical Minimum (0) 0x25, 0x01, // Logical Maximum (1) 0x75, 0x01, // Report Size (1) 0x95, 0x0D, // Report Count (13) 0x0A, 0x24, 0x02, // Usage (AC Back) 0x09, 0x40, // Usage (Menu) 0x0A, 0x23, 0x02, // Usage (AC Home) 0x0A, 0xAE, 0x01, // Usage (AL Keyboard Layout) 0x0A, 0x21, 0x02, // Usage (AC Search) 0x09, 0xB6, // Usage (Scan Previous Track) 0x09, 0xCD, // Usage (Play/Pause) 0x09, 0xB5, // Usage (Scan Next Track) 0x09, 0xE2, // Usage (Mute) 0x09, 0xEA, // Usage (Volume Decrement) 0x09, 0xE9, // Usage (Volume Increment) 0x09, 0x30, // Usage (Power) 0x09, 0x40, // Usage (Menu) 0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position) 0x95, 0x01, // Report Count (1) 0x75, 0x03, // Report Size (3) 0x81, 0x03, // Input (Const,Var,Abs,No Wrap,Linear,Preferred State,No Null Position) 0xC0, // End Collection

This is a parsed chunk of the descriptor where the keyboard tells the Host System "I'm sending a 13-bit report, and each bit corresponds to these Usage Codes (multimedia keys). Oh, and there is also a 3-bit padding chunk so we can round up to 16 bits (the 2 byte report the keyboard finally sends).

So, where's the problem? Espressif DOESN"T parse these instructions and totally discards them, as I discovered by digging in the HIDH stack code. I need to parse the descriptor myself to be able to use these mappings.


It would be really helpful if you can share a copy of the Raw Descriptor data your Rii4 is sending, so I can work with it to make a robust parser. I added a couple of debug lines in my HIDH stack so it would spit the descriptor in raw form just before the map gets parsed by the stack:

D (13591) BLE_HIDH: Device descriptor RAW dump: D (13593) BLE_HIDH: 05 01 09 06 a1 01 85 01 05 07 19 e0 29 e7 15 00 D (13593) BLE_HIDH: 25 01 75 01 95 08 81 02 95 01 75 08 81 01 95 05 D (13599) BLE_HIDH: 75 01 05 08 19 01 29 05 91 02 95 01 75 03 91 01 D (13606) BLE_HIDH: 95 06 75 08 15 00 26 ff 00 05 07 19 00 2a ff 00 D (13612) BLE_HIDH: 81 00 c0 05 01 09 02 a1 01 85 02 09 01 a1 00 05 D (13618) BLE_HIDH: 09 19 01 29 08 15 00 25 01 95 08 75 01 81 02 05 D (13624) BLE_HIDH: 01 16 01 f8 26 ff 07 75 0c 95 02 09 30 09 31 81 D (13631) BLE_HIDH: 06 15 81 25 7f 75 08 95 01 09 38 81 06 05 0c 0a D (13637) BLE_HIDH: 38 02 95 01 81 06 c0 c0 05 0c 09 01 a1 01 85 03 D (13644) BLE_HIDH: 19 00 2a 9c 02 15 00 26 9c 02 75 10 95 01 81 00 D (13651) BLE_HIDH: c0 05 01 09 80 a1 01 85 04 1a 81 00 2a 83 00 15 D (13656) BLE_HIDH: 00 25 01 75 01 95 03 81 02 95 05 81 01 c0 05 01 D (13663) BLE_HIDH: 09 06 a1 01 85 08 05 07 95 90 75 01 15 00 25 01 D (13669) BLE_HIDH: 19 04 29 94 81 02 c0

Here's the build binary with included flash tool. Use FLASH.BAT, it is set to program on COM3, if your WROOM is using another COM port you can edit the .BAT file (right click, edit).

https://1drv.ms/u/s!AlKre4_rNmpJiO06mvjtyg04xExK7w?e=SYnMFR

I might as well make a custom mod just for you, it will most possibly only work with your Rii4, since we know the codes it already sends. Later on I'll pass you a patch for bt_keyboard.cpp so the codes get sent to main module.

TwinTurbine commented 2 months ago

Hi!

Wow, you've really gone above and beyond with this! Great to hear that you've managed to come to these conclusions as well as a possible way forward.

Below you can find what you are asking for (hopefully). This is for the Rii i4:

D (22824) BLE_HIDH: Device descriptor RAW dump: 
D (22825) BLE_HIDH: 05 01 09 06 a1 01 85 01 05 07 19 e0 29 e7 15 00 
D (22825) BLE_HIDH: 25 01 75 01 95 08 81 02 95 01 75 08 81 01 95 05 
D (22831) BLE_HIDH: 75 01 05 08 19 01 29 05 91 02 95 01 75 03 91 01 
D (22838) BLE_HIDH: 95 06 75 08 15 00 26 a4 00 05 07 19 00 2a a4 00 
D (22844) BLE_HIDH: 81 00 05 0c 09 00 15 80 25 7f 75 08 95 08 b1 02 
D (22851) BLE_HIDH: c0 05 0c 09 01 a1 01 85 02 75 10 95 01 15 01 26 
D (22857) BLE_HIDH: 8c 02 19 01 2a 8c 02 81 00 c0 05 01 09 02 a1 01 
D (22863) BLE_HIDH: 85 03 09 01 a1 00 05 09 19 01 29 03 15 00 25 01 
D (22870) BLE_HIDH: 75 01 95 03 81 02 75 05 95 01 81 01 05 01 09 30 
D (22876) BLE_HIDH: 09 31 09 38 15 81 25 7f 75 08 95 03 81 06 c0 c0 
D (22884) event: running post ESP_HIDH_EVENTS:0 with handler 0x400dafc0 and context 0x3ffd6e74 on loop 0x3ffd6f30
BDA:d1:03:45:ba:77:b8, Appearance: 0x03c0, Connection ID: 0
Name: i4, Manufacturer: , Serial Number: 
PID: 0x022c, VID: 0x05ac, VERSION: 0x0001
Battery: Handle: 14, CCC Handle: 15
Report Maps: 1
  Report Map Length: 160
  BLE: d1:03:45:ba:77:b8,        MOUSE   INPUT REPORT, ID:  3, Length:   4, Permissions: 0x1a, Handle:  48, CCC Handle:  49
       MOUSE   INPUT   BOOT, ID:  3, Length:   3, Permissions: 0x1a, Handle:  45, CCC Handle:  46
     GENERIC   INPUT REPORT, ID:  6, Length:   0, Permissions: 0x12, Handle:  41, CCC Handle:  42
    KEYBOARD  OUTPUT REPORT, ID:  1, Length:   1, Permissions: 0x0e, Handle:  38, CCC Handle:   0
    KEYBOARD   INPUT REPORT, ID:  1, Length:   8, Permissions: 0x1a, Handle:  34, CCC Handle:  35
    CCONTROL   INPUT REPORT, ID:  2, Length:   2, Permissions: 0x1a, Handle:  30, CCC Handle:  31
    KEYBOARD  OUTPUT   BOOT, ID:  1, Length:   1, Permissions: 0x0e, Handle:  28, CCC Handle:   0
    KEYBOARD   INPUT   BOOT, ID:  1, Length:   8, Permissions: 0x1a, Handle:  25, CCC Handle:  26
RSSI: -56, USAGE: GENERIC, APPEARANCE: 0x03c1, ADDR_TYPE: 'RANDOM', NAME: i4 

I don't know if it's of any use to you but below you can find the corresponding information for another mini keyboard, the Fosmon Mini Bluetooth keyboard. https://www.fosmon.com/portable-lightweight-mini-wireless-bluetooth-keyboard-controller-qwerty-keypad

D (78940) BT_HIDH: Device descriptor RAW dump: 
D (78940) BT_HIDH: 05 01 09 06 a1 01 85 01 75 01 95 08 05 07 19 e0 
D (78943) BT_HIDH: 29 e7 15 00 25 01 81 02 95 01 75 08 81 03 95 05 
D (78949) BT_HIDH: 75 01 05 08 19 01 29 05 91 02 95 01 75 03 91 03 
D (78955) BT_HIDH: 95 06 75 08 15 00 26 ff 00 05 07 19 00 29 ff 81 
D (78962) BT_HIDH: 00 c0 05 0c 09 01 a1 01 85 02 15 00 25 01 75 01 
D (78968) BT_HIDH: 95 18 0a 94 01 0a 92 01 0a 83 01 0a 23 02 0a 8a 
D (78974) BT_HIDH: 01 0a 2a 02 0a 21 02 0a 24 02 0a 25 02 0a 26 02 
D (78981) BT_HIDH: 0a 27 02 09 b6 09 b5 09 b7 09 cd 09 e9 09 ea 09 
D (78987) BT_HIDH: e2 09 b8 0a b1 01 09 30 09 6f 09 70 09 40 81 02 
D (78993) BT_HIDH: 95 01 75 00 81 03 c0 05 0c 09 01 a1 01 85 03 05 
D (79000) BT_HIDH: 01 09 06 a1 02 05 06 09 20 15 00 26 ff 00 75 08 
D (79006) BT_HIDH: 95 01 81 02 c0 c0 05 01 09 80 a1 01 85 04 15 00 
D (79012) BT_HIDH: 25 01 75 01 95 01 09 82 81 02 95 01 75 07 81 03 
D (79019) BT_HIDH: c0 05 01 09 02 a1 01 85 0a 09 01 a1 00 05 09 19 
D (79025) BT_HIDH: 01 29 05 15 00 25 01 75 01 95 05 81 02 75 03 95 
D (79031) BT_HIDH: 01 81 01 05 01 09 30 09 31 16 01 80 26 ff 7f 75 
D (79038) BT_HIDH: 10 95 02 81 06 09 38 16 01 80 26 ff 7f 75 10 95 
D (79044) BT_HIDH: 01 81 06 05 0c 0a 38 02 16 01 80 26 ff 7f 75 10 
D (79050) BT_HIDH: 95 01 81 06 c0 c0 
D (79058) event: running post ESP_HIDH_EVENTS:0 with handler 0x400dc904 and context 0x3ffd6e88 on loop 0x3ffd6f14
BDA:dc:2c:26:12:a2:fa, Status: OK, Connected: YES, Handle: 0, Usage: KEYBOARD
Name: , Manufacturer: , Serial Number: 
PID: 0x022c, VID: 0x05ac, VERSION: 0x011b
Report Map Length: 294
     MOUSE   INPUT   BOOT, ID:  10, Length:   3
     MOUSE   INPUT REPORT, ID:  10, Length:   9
   GENERIC   INPUT REPORT, ID:   4, Length:   1
  CCONTROL   INPUT REPORT, ID:   3, Length:   1
  CCONTROL   INPUT REPORT, ID:   2, Length:   3
  KEYBOARD  OUTPUT   BOOT, ID:   1, Length:   1
  KEYBOARD  OUTPUT REPORT, ID:   1, Length:   1
  KEYBOARD   INPUT   BOOT, ID:   1, Length:   8
  KEYBOARD   INPUT REPORT, ID:   1, Length:   8

I hope that this information can be of use for you and feel free to request any other data/logs that is required to get forward with this project.

Regards

Hamberthm commented 2 months ago

Hi again!

Alright, first of all, thanks a lot for the report maps and all the logs you provided. It helped me a lot!

Good news, I've implemented support for multimedia (CCONTROL) keys!

It was harder than I thought, so there are changes on nearly all the files.

There's a new function called keyHid_send_CCONTROL() on the bottom of file esp32-ps2dev.cpp. This is the file that controls the mappings and the one you can tweak for mapping your multimedia keys to whatever PS/2 Scan Code you want:

void PS2Keyboard::keyHid_send_CCONTROL(uint16_t btkey, bool keyDown) { scancodes::Key key; switch (btkey) { case 0xCD: key = scancodes::Key::K_MEDIA_PLAY_PAUSE; break; case 0xE9: key = scancodes::Key::K_MEDIA_VOLUME_UP; break;

(...) etc

You can even make macros/key combinations for a single multimedia key by placing your custom code inside the corresponding 'case' on the switch statement. If you need help with this, let me know.

Here you have the new v0.5 candidate source code and a compiled binary for fast flashing and testing (Use FLASH.BAT). Pins are set to 22 and 23 like the code on the repository!

Binary with flasher: https://1drv.ms/u/s!AlKre4_rNmpJiO06mvjtyg04xExK7w?e=XfPOVz Source: https://1drv.ms/u/s!AlKre4_rNmpJiPIjbqgqmQaozdPbtw?e=tK98xB

Let me know how it goes. The compiled binary is set to DEBUG level messages, that would be enough so you can see if your multimedia keys are coming by.

About the wheel/mouse buttons implementation, that is a completely different Report (MOUSE instead of CCONTROL) and will be implemented alongside Mouse support in the future. First I want to make sure multimedia/CCONTROL keys are working fine.

Cheers!

Humberto

TwinTurbine commented 1 month ago

Good morning!

A big thank you for really digging into this. I must say that I'm really amazed with your work! I've just tried out the binary that you supplied and it seems to work perfectly as expected when pressning the multimedia keys. A touch of the touch pad will still set off the looping but that doesn't seem to be an issue unless DEBUG is active.

My next step is to customize the code with the appropriate key mappings. And I'm really excited to do that! I'll reply again with the results.

Have a great day!

MuadDib007 commented 1 month ago

Hi All,

I just started using this project for my old PIII. Really happy with it so far! Tested the v0.5 firmware and I see the mouse and ccontrol commands comming in over the serial port.

Looking forward to the mouse support.

Hamberthm commented 1 month ago

Hi @TwinTurbine and @MuadDib007 !

I'm currently finishing mouse support, you can expect a release before the end of the week.

Beware of the beta source I posted above, as some keys like 'C' may not work in that build.

Explanation is here: https://github.com/Hamberthm/esp32-bt2ps2/issues/10#issuecomment-2303587971

As I said, expect a big release with this bug fixed and mouse support!

Cheers! Humberto

TwinTurbine commented 1 month ago

Wow, that's amazing! I'm really impressed of your work and how this project has evolved. Really looking forward to try it out!

Hamberthm commented 1 month ago

Alright @TwinTurbine and @MuadDib007 , v0.6 is out to try!

Posted here: https://github.com/Hamberthm/esp32-bt2ps2/discussions/14

I'll delay main release on the repository so I can see how it goes for you.

Closing this one since support for multimedia keys is now up. Feel free to reopen or make new issues as needed.

Cheers!