I am planning to modify a wired keyboard to use a wireless connection, using the HID Relay project (YT, GitHub) as the communication method, along with a LiPo battery, with accompanying charger and booster (for simplicity's sake, I will refer to the charger/battery/booster/HID Relay combo as just HID Relay from now on).
Thing is, I still wish to use the keyboard using just a cable, in case of a low battery or the device where I want to use it doesn't have Bluetooth capability.
All those components will be inside the keyboard, with just the USB female connector and the switch being exposed.
1st version (Works partially)
My idea is to, instead of using an USB switching IC, just route the power line between a direct connection to the keyboard and the power input of the HID Relay, along with a option to just charge the battery.
I read from this article that power can be joined by using diodes.
Here is a (rather crappy, sorry) diagram for it: (The HID Relay was condensed as a component for simplicity's sake)
My questions are:
1) Is this schematic correct? As in, is there something placed improperly?
2) On the 3rd position (Charge and Bluetooth enabled), in case of plugging the cable to a device that can interact with the keyboard, how can be the data pins from that source can be suppressed?
Here's what SW1 will do:
Position 1) Direct mode - pass 5V directly to the keyboard. In circuit 2, powers the IC to pass the data pins through.
Position 2) OFF / Charge only - Only the battery charging IC will receive 5V from the input USB port.
Position 3) BT mode - Allows for battery charging, while connecting the internal battery to the booster circuit (the 2nd connection set on SW1) that in this case, powers the HID Relay circuit.
Thanks in advance.
UPDATE: This version would not work in the case of, while using BT mode, a usb connection to a PC would interfere in the data lines shared by the HID Relay
2nd version (not tested yet)
Here's a version using a switch IC:
Another thing: I would prefer to not use a switching IC because they would be the only component not available locally.
This version is not tested as I don't have the IC in hand
3rd Version (UPDATE: Does not work)
Instead of the USB-specific IC, this version uses a 74HC157 selector IC, which is more accessible to me.
Sadly this version does not work, as the IC data lines are not bidirectional.
4th Version (Works as intended)
After checking the problem with version 3's data direction, I tried to use a combination of a inverter and an analog switch ICs (that I had lying around) to block the unwanted case of the external USB data lines interfering while the HID Relay was active. This seems to work perfectly.
Also, the physical switch used (3 positions, 6 terminals) guarantees that the VBUS line is cut while changing modes.
As the ICs are just what I had at the moment, the inverter IC could be any that have at least 2 channels.