[WIP] USB Host support (working)

Search This thread

case-sensitive

Senior Member
Nov 4, 2010
344
33
Ok, here's the new version.

If you are using unpowered devices or an unmodified hub:
  1. Hit the "Off" button.
  2. Plug in.
  3. Hit the "Host" button.

If you are using a modified hub:
  1. Plug in.
  2. Play with the charging settings if you feel like it.

When you are done:
  1. Unplug.
  2. Hit the "Peripheral" button.
  3. Hit the "Off" button.
  4. Hit the "Auto" button.

Thanks for making this!

I just tried it on my rooted NST; sadly it didn't work. Specifically, I I connected my usb keyboard to the NST using a microusb-to-usb convert http://www.amazon.com/Micro-USB-Mal...YMU6/ref=sr_1_1?ie=UTF8&qid=1330748930&sr=8-1 and then follow your instruction for "unpowered device", but the NST did not respond to the keyboard. The converter is almost certainly not an OTG one; could that be the problem?

I also tried to connect a micro sdcard to the NST (via a cardreader), again using your instruction for unpowered devices; ES file manager did not see the micro sdcard card, and the LED on the usb carder did not turn on (probably because there's not enough power to run the micro sdcard?).

I would *love* to be able to use a keyboard and to hook up a usb stick to my NST, so thanks for making this app. Any suggestions on fixing mine are most welcome!
 

Renate

Recognized Contributor / Inactive Recognized Dev
@case-sensitive: Nope, you need an OTG. Take a razor blade to your little adaptor and try to see if you can ground the ID pin.

The mechanism where the Nook figures out exactly what is plugged into its USB connector is a bit complicated. It could be a a computer, a peripheral or a charger. Any of these could be charging at different rates and either end could be host. Throw in a few bugs in the driver and it's no wonder that the Nook occasionally gets confused what is going on.

One of the first problems was getting the Vbus (the charge pump) going. verygreen found a way to kickstart it with their driver.

The next problem was the question of an OTG cable or not. I was misled my the source code because it said "presume that it's an OTG cable". That presumption came after it had received an interrupt already from an OTG cable. In short, you need an OTG cable (with this driver).

There were cases of people getting this to work and people not getting it to work. When the Nook tries to start host mode it switches on vbus (the charge pump) and then waits to see if the voltage actually goes up. The driver appears to be incomplete in that it sets no timeout for waiting for this to happen. Without a timeout if the voltage doesn't rise you get the dreaded "a_wait_vrise". There is no reason that the driver should be in this state for more than a fraction of a second.

So why doesn't the voltage rise? Well, it tries. The problem is that the Texas Instruments TPS65921B IC inside the Nook that monitors the Vbus signal has a voltage threshold of 4.4-4.6 Volts. On my Nook we were seeing the Vbus rise to 4.46 Volts. For some people that was enough to say "Vbus valid", for others it didn't quite get there. (Note: Just to confuse things, if the voltage did rise high enough but there is no device connected the status will misleadingly say "a_wait_vrise" when the state is probably "a_idle".)

The actual problem was that the charger circuit in the Nook was trying to charge itself off the ~4.5 Volts that it was generating itself. That's really picking yourself up by your bootstraps. It doesn't work. The solution is to make sure that the charging circuit is off. The "Off" button in my application does that. You should be now getting 5.0 Volts.

Using a back-powering hub obviates all that. It gives (through an OTG adaptor) an OTG ID ground, it gives you your Vbus voltage. What more could you need?

I just checked using a thumb drive directly (without a hub). I couldn't seem to get it to mount by itself. The power was fine (4.92 Volts), the USB was happy (in host mode), but the LED on the thumb didn't go on. This needs further investigation. It works fine plugged into a hub.

If you have an OTG adaptor plugged in all by itself, you should be able to get the Nook LED to turn solidly on and off with the "Peripheral"/"Host" buttons on my application. Plugging in any device into the adaptor (without disturbing the OTG adaptor to Nook connection) should allow it to switch from "a_idle" to "a_host". Disconnecting the device from the OTG adaptor will cause it to flash "a_wait_bcon" for a second before settling into "a_idle" again.

So, in summary, to get it to work:
  • You must use an OTG adaptor or cable.
  • You may do either or both of these:
    • Use verygreen's uImage and uRamdisk to get the driver to work correctly. Use my application to make sure that the charging circuit is off and to see what's going on.
    • Use a back-powering hub (as posted above) to force things to go. My application is helpful in allowing you to actually charge the Nook.
 

staylo

Member
May 10, 2011
28
4
Great work! Using mali100's kernel I was able to get a battery powered GPS (iBlue 747) connected and accessible via /dev/ttyUSB0 very quickly, after modifying the USB cable into an OTG cable (shorting the ID pin to ground)

My main concern at the moment is that this GPS is usually charged over USB. When connected I see the battery voltage readout drop by ~0.1V and hear a high-pitched noise from the GPS (presumably a switching DC-DC converter) so I suspect the GPS is trying to draw some current from the Nook. Any suggestions on how best to tackle this problem?
 

Renate

Recognized Contributor / Inactive Recognized Dev
Good work!

You might try connecting the GPS to the Nook with the red wire connection broken. That way each end is responsible for its own power. It should work.

I got my old Microsoft USB GPS puck to work. It spits out data and I can read it, but I haven't got the LocationProvider bit to work. It's on my big list of things to do.
 

staylo

Member
May 10, 2011
28
4
Thanks, that was a good idea. Unfortunately the BT747 (probably) appears to drop the USB connection when Vbus is not connected, presumably as a power saving measure. I experimented with various resistances between the Vbus lines of the two devices, but I had to use 140 ohm before the BT747 would consistently connect.. (showing 3.1V on Vbus on the BT747 side) - that's a lot of wasted power :) So it seems like it's time to look for a low power USB GPS mouse!
 

durn_it

Member
Mar 14, 2009
9
1
OTG cable works!

However when I restart the NST it no longer works - I have to reboot using the TouchNooter image with verygreen's binaries. Any ideas on how to make it persistent?
 
  • Like
Reactions: Renate

Renate

Recognized Contributor / Inactive Recognized Dev
Here's a new version of my application.
It's no major change, just a few little things.
It will indicate how many "keyboards" are attached.
A multimedia keyboard is actually two USB devices, a qwerty and a multimedia controller.

As always, this reports what the system sees, not what is actually there.
 
Last edited:
  • Like
Reactions: andrewed and mrWax

Renate

Recognized Contributor / Inactive Recognized Dev
Oh, yeah... Here is my totally amazing IME (Input Method Editor).
It's called "Null keyboard". It does... nothing.
Select it as your input method and then when you go to edit a text field nothing happens.
Of course at that point you can just type on your USB keyboard without having 1/2 your screen blocked.
Note: Using the keymap files posted earlier, the Ctrl keys pop up an IME selection dialog.

Oh, if you don't have settings to enable this you can do:

Code:
adb pull /data/data/com.android.providers.settings/databases/settings.db settings.db

sqlite3 settings.db
update secure set value='com.android.inputmethod.latin/.LatinIME:com.temblast.nullkbd/.NullKeyboard' where name='enabled_input_methods';
.q

adb push settings.db /data/data/com.android.providers.settings/databases/settings.db

Oh, ok, a new doo-dad thrown in:
If you have the Null keyboard set as your IME and you go to edit a field somewhere and your keyboard is disconnected
it will popup the "Select Input Method" dialog.
This will rescue you when you left it on Null keyboard and went out without a keyboard.
 
Last edited:

ros87

Senior Member
Oct 12, 2010
312
164
Bodø
There might be a possible danger to this (host mode)

I left my NST in sleep mode with the host mode kernel a couple of weeks ago.

When I picked it up today it was completely dead, and it won't charge, the charge led just goes green instantly when connected to the charger..

It's been sitting on the charger for a couple of hours now, led is green but there's nothing I can to do wake it up.

My suspicion (I might be wrong tho) is that that playing with host mode might allow for the battery to be completely drained if left unused for a long time.
Normally there are logic that will prevent the battery from draining entirely as that is usually very bad for this type of battery..

-Roger
 

Renate

Recognized Contributor / Inactive Recognized Dev
When I picked it up today it was completely dead, and it won't charge...

Oops. That doesn't sound good.

I've found my Nook in the "too dead to turn on" state, but never too dead to charge.

If it were me, I'd pop the Nook open, disconnect the battery and see if it will do anything with the charger connected. Supposedly the power management chip is designed to work with a dead or missing battery, but it's hard to tell how the thing is wired.

If that doesn't work, I'd connect the battery through a 10 ohm or so resistor to a 5 volt supply and try to put some charge back on it.

My next investigation was to be where/what is sucking down the battery.
 

ros87

Senior Member
Oct 12, 2010
312
164
Bodø
This doesn't affect it. Because overcharging can cause it to explode, battery management is handled by a chip separate from USB, ARM, etc.

p.s. protip: Logic is singular; use "is logic."

No better things to do, you have, hmm?

---------- Post added at 02:52 PM ---------- Previous post was at 02:46 PM ----------

If it were me, I'd pop the Nook open, disconnect the battery and see if it will do anything with the charger connected. Supposedly the power management chip is designed to work with a dead or missing battery, but it's hard to tell how the thing is wired.

My next investigation was to be where/what is sucking down the battery.

Yep, that's what I did.
With the battery disconnected the led still turned green when connected to the charger.
Re-connecting the battery while it was on the charger fixed it.

I've had the NST go empty on me a hundred times simply by leaving it in a semi booted state, but I've never seen this behavior before..
 
Last edited:
  • Like
Reactions: Renate

ros87

Senior Member
Oct 12, 2010
312
164
Bodø
Hmm

It's still not behaving properly, the battery has been at 100% for a long time now but the led doesn't turn green..

I'll try to go back to stock a little later today and see if that helps.
 

mrWax

Senior Member
Jan 31, 2012
147
24
Magnifing glass for macro photo

I made my own OTG cable. I probably should put in a switch so that I can test with and without the ID pin being grounded. I should drop by a Radio Shack.

If you have a spare micro USB cable, you can make your own.
Just take a razor blade and start carefully scraping off the plastic.
You'll see that there are probably three solder pads on one side and two on the other.
The pad you want is the pad that is not connected already, of course, the empty one on the two side.
As you look at your Nook, this pad will be on the bottom left side of your connector.
As you twist it around, it will be on your right side if the connector is pointing away from you.
Just get a tiny wire and solder it between the pad and the shell.
Wrap it up with tape and you are done.

(I'd take a photo, but my camera can't really do macro.)

To make a powered hub, open up a cheap hub, look for the big diode, trace it back to make sure it goes to the input USB jack. Replace this diode with a jumper. Put a big warning sticker on the top of the hub that it back-powers. See the schematic:

If any of this sounds above your level, don't do it!

Back to the GPS thing, I've got the data coming in, but apparently I've got no LocationProvider's installed.

maybe you could use magnifing glass for macro-photo. anyway there is tutorial on http://www.youtube.com/watch?v=COkLEJGo6vo
 
  • Like
Reactions: Renate

Renate

Recognized Contributor / Inactive Recognized Dev
That's a nice tutorial. I presumed there had to be a video somewhere.

Still, I've not seen one for the back-powering USB hub modification.

If you need an OTG adapter (micro USB OTG male to full-sized USB female)
you can get a cheap short cable adapter from Amazon for about 3-1/2 dollars including shipping.
I just received a couple that I ordered and they work fine and I can now retire my homebrew version.
(Don't mind that the link's description says Samsung Galaxy. It's OTG and it works.)

2155-2QpyML._SS400_.jpg

USB OTG cable on Amazon
 
Last edited:
  • Like
Reactions: DeanGibson

Top Liked Posts

  • There are no posts matching your filters.
  • 18
    Hello!

    I have been asked into looking for usb host support for nook touch. The hardware appears to be pretty similar to Nook Color, so there were no troubles in that area.


    The kernel used by B&N for the Nook Touch is somewhat older than .32 kernel used for Nook Color, so the patch itself required some massage. Surprisingly B&N kernel already has usb host support compiled in, so you don't even need to change anything in kernel config, just apply the patch.

    Just like in Nook Color, the id pin in the usb receptacle is not connected anywhere, so a special app is needed to switch the host mode on and off. The Nook Color usbhost switcher should work: https://github.com/verygreen/Nook-Color-usbhost-switcher though I cannot compile it for eclair, so I guess that needs some more massage and help here would be appreciated.

    Meanwhile you can simply switch the mode from adb, type
    Code:
    echo host > /sys/devices/platform/musb_hdrc/mode
    to enable usb host mode and type
    Code:
    echo peripheral > /sys/devices/platform/musb_hdrc/mode
    to disable it.
    The LED at the bottom that usually indicates charging status will light up in usb host mode even if the power is not connected.

    The upside is you don't need a special OTG cable and can just use gender changer on your existing nook cable if you so desire.

    Now, problems ;)
    • I have not tracked why yet, but self powered mode only works when you try to enable it first with external power plugged in first.
    • The user-friendly tool for usbhost mode switching needs to be compiled for eclair
    • The self-powered mode is very faint. Keeps up with my keyboard, but not even with a simple usb hub.
    • Battery drain is significant, though not sure what part of it is attributed to the usbhost mode and what to adb over wifi
    • Eclair init is buggy so input devices are unusable without a patch, see commit 6405c6953fa02d41d9f6377f4cdb947604f481c4 in google tree to sytem/core/init. I am attaching recompiled init binary that works.

    Attachments: binary.zip contains:
    • uImage - prebuilt 1.1 kernel with the patch
    • uRamdisk - root ramdisk with fixed init, adb over wifi
    • init - just recompiled init binary for those who might need it
    usbhost_patch.zip - just the patch itself in it's current form.

    THANKS TO:
    andrewed, who asked me to do this and also provided me with a device. He is on a quest to touchtype on e-paper with a USB physical keyboard, all described here: Project: E-Paper Tablet (typable!)
    7
    This is chinese for me again, sorry...

    Ni hao ma?

    Ok, no problem.

    Here is the official (interim, hacked) way to get your Nook to be an MP3 player.

    1. Root
    2. Install mali100's uImage with USB host mode and audio drivers
    3. Install superuser.apk and su
    4. Install UsbMode-1.4.apk (see below)
    5. Install AudioCtl-1.0.apk (see below)
    6. Create the text file /system/etc/asound.conf as shown here
    7. Plug in USB audio adapter through a special OTG cable adapter
    8. Using UsbMode, set in host mode
    9. Run AudioCtl, it should make beeping noises
    10. Go to your file manager and select a suitable song to play
    11. Goto step #10

    AudioCtl is very much a version 1.0
    It is necessary to use now as a workaround due to problems with mediaserver.
    You only need to run it once after each time of turning on the USB audio adapter.
    In the future, AudioCtl will have useful features.

    Note: Ignore all that stuff about ps, kill, mediaserver, etc. AudioCtl obviates all that.
    5
    USB Host Mode Swicth for Nook Simple Touch

    Attached is a Nook Simple Touch version of verygreens USB Host Mode switching app.

    Requires properly installed "su" in /system/bin

    Let me know if there are problems.
    5
    Ok, here's a summary.
    Depending on what you want to do not all of this may be required.

    For basic playback
    For basic recording or Skype
    • Modify /system/lib/hw/libaudio.so
      Code:
      [00009188] B1 F5 FA 54 => 70 BD 00 BF
      [000091EC] 6C 33 => 00 05
    • Patch /system/framework/framework.jar with AudioRecord.smali using mergesmali, in signature, in Nook121patch
    For recording directly through ALSA
    • Recorder.apk, in signature
    • Modify /system/etc/permissions
      Code:
         <permission name="android.permission.WRITE_EXTERNAL_STORAGE" >
             <group gid="sdcard_rw" />
             [b]<group gid="audio" />[/b]
         </permission>
    Jeez, it seems like a lot.
    4
    Is it possible to change the keyboard layout?

    Of course.

    There are two levels of processing turning a key press into a character.
    The first is mapping of the scan code into a key code.
    The second is mapping the key code and meta keys (shift, alt, etc) into a character.

    The first mapping is done using files like /system/usr/keylayout/qwerty.kl
    The second mapping is done using files like /system/usr/keychars/qwerty.kcm.bin
    The first file is conveniently in plain text, the second is a simple binary file.

    If you are simply swapping keys around you only need to change the .kl file
    If you want to make it so that shift 4 is Euro instead of dollar you need to change the kcm.bin file.

    You can just edit the .kl file. Before:
    Code:
      key  21  Y
    After:
    Code:
      key  21  Z
    This would make the key layout more "German-like" by making the center key in the top alpha row be considered the 'Z' key.

    The .kcm.bin are compiled files from source.
    I haven't looked into where the compiler comes from, I just modify the stock kcm.bin by hand.

    The file is broken down into 16 byte chunks with a 16 byte header.
    Here is the chunk for C (on my modified version):
    Code:
    000100 1F 00 00 00 43 00 32 00 63 00 43 00 E7 00 C7 00
    This means:
    • This chunk is about KEYCODE_C (0x1f) (uses Android key codes)
    • The visual for this key is 'C' (0x0043)
    • On a numeric keypad this would dial a 2 (0x0032) as in ABC on a phone
    • The unshifted UTF-16 value is 'c' (0x0063)
    • The shifted UTF-16 value is 'C' (0x0043)
    • The alt modified UTF-16 value 'ç' (0x00e7)
    • The alt-shift modified UTF-16 value is 'Ç' (0x00c7)

    You can also use alt combos for combining diacritics:
    • 0x0300 grave accent
    • 0x0301 acute accent
    • 0x0302 circumflex accent
    • 0x0303 tilde accent
    • 0x0308 umlaut accent

    To replace these files on your Nook, you will need to remount your system as R/W:
    Code:
    mount -o rw,remount /dev/block/mmcblk0p5 /system

    You can get fancier if you want to have some USB keyboards US and some Belgian.

    I await my shipment of Belgian chocolates. :D