Closed the-st0rm closed 6 years ago
First, there is a kernel patch - this is dark magic, without which nothing will work. This patch adds two new devices to your Android system, /dev/hidg0 for keyboard, and /dev/hidg1 for mouse. If you want to add HID joystick for example, you need to modify hid_function_bind_config() and hid_function_init(), and another struct ghid_device_android_joystick, with proper USB descriptor. The best way to get USB descriptor is to buy USB analyzer, and copy data from existing USB joystick. You can also read USB specification: http://en.wikipedia.org/wiki/USB_human_interface_device_class
Then you need Android application, which will write data to these devices. It doesn't matter if it's written in C or Java, as long as it writes valid data to these files. Keyboard/mouse protocol description is here: https://github.com/pelya/android-keyboard-gadget#how-it-works My Android app is written in C++ and uses SDL library. gfx.cpp contains low-level graphics functions, gui.cpp is a GUI widgets implementation, flash-kernel.cpp is for flashing kernel on Nexus 7, input.cpp is for opening device files and writing data to them, main.cpp is, well, main(), touchpad.cpp is the touchpad implementation, and scancodes.cpp contains keyboard scancode table.
On Mon, Nov 10, 2014 at 12:45 PM, the-st0rm notifications@github.com wrote:
What should I read exactly to understand what you have coded entirely. I need something like a walkthough of your code to understand what is this function and why it is used etc etc, so that I can develop on top of that.
Best Regards
— Reply to this email directly or view it on GitHub https://github.com/pelya/android-keyboard-gadget/issues/12.
I understand this big picture and I am ok with the Android application that writes the data to the devices. My only problem is with the kernel patch. Understanding what is happening actually. what happened when I just connect my phone to the PC what function gets called first and how the data is sent to the USB ... and what is the difference between the hid_function_bind_config() and hid_function_init() .. I don't want you to answer all these stuff, I just want you to direct me to the source you read so that you managed to write all that code. Got me ? BTW, Thank you so much for your effor and your quick respones. You are amazing dude I really appreciate it everything you do.
I do not know all details myself, because the kernel is huge, I only know how my code works.
First, I've read this documemt, it contains half-baked example of what I needed:
https://github.com/torvalds/linux/blob/master/Documentation/usb/gadget_hid.txt
Then I've scanbed through Android USB gadget implementation, where functions are added and removed dynamically:
HID gadget already has it's own driver, I needed only to provide USB HID descriptor:
Then I fixed compilation errors, run, debugged crashes, usual stuff. On Nov 10, 2014 2:51 PM, "the-st0rm" notifications@github.com wrote:
I understand this big picture and I am ok with the Android application that writes the data to the devices. My only problem is with the kernel patch. Understanding what is happening actually. what happened when I just connect my phone to the PC what function gets called first and how the data is sent to the USB ... and what is the difference between the hid_function_bind_config() and hid_function_init() .. I don't want you to answer all these stuff, I just want you to direct me to the source you read so that you managed to write all that code. Got me ? BTW, Thank you so much for your effor and your quick respones. You are amazing dude I really appreciate it everything you do.
— Reply to this email directly or view it on GitHub https://github.com/pelya/android-keyboard-gadget/issues/12#issuecomment-62380006 .
Question has been answered, therefore closing.
What should I read exactly to understand what you have coded entirely. I need something like a walkthough of your code to understand what is this function and why it is used etc etc, so that I can develop on top of that.
Best Regards