[WIP] USB Host support (working)

Search This thread

digiflash

Member
Oct 17, 2007
26
16
I tried everthing. Restore + New root..
I didn't get the usb host to work. Replacing the uimage and uramdisk doens't work.
Are there any steps I have forgotten?

Help would be apprechiated :)
 
Last edited:

verygreen

Senior Member
Feb 13, 2011
1,305
2,637
TN
linuxhacker.ru
@Googie2149: Any standard USB cable will work as well as any other.
The ID pin on the micro USB connector on the Nook is not going anywhere so a special OTG cable is not required.

I loaded in the new uImage and uRamdisk and things act more consistently, but I still can't get a keyboard to work.

Neither of the two utilities out there seem to work correctly for me. I do have su installed. I have had more success with simple commands

Code:
echo host > /sys/devices/platform/musb_hdrc/mode
echo peripheral > /sys/devices/platform/musb_hdrc/mode
cat /sys/devices/platform/musb_hdrc/mode

One thing is clear; the Nook adheres to the USB standard for supplying power, that is, it supplies it for 100 millisecs and if the peripheral signals back correctly it continues to supply it. Issuing a host command cause the red LED to flash for about a 1/10 of a second. Supplying power on the red wire is not necessary for host communication.

My setup has a powered hub and a cable with the red lead not carried through. I can issue a host command but it never seems to communicate. The status reads back "a_wait_vrise".

Does anybody have any insight into the FSM to say what is going on?
My recent testing seem to indicate that you must enable host, then disable host, then enable it again and then it will work.
 

cybermaus

Senior Member
Dec 6, 2008
1,240
479
Earth
www.campingtiveden.se

digiflash

Member
Oct 17, 2007
26
16
Did you install the app?

Yes. I also tried it through the shell.
But my problems start before that step.
If I use the 2 usbhost-binaries with TouchNooter 2.1.31 my Nook isn't rooted anymore. The superuser-app won't work for me.
Using the switcher-app only shows a message that my kernel isn't able to switch due to my lost su-abilities.
After restoring and flashing other files (e.g. SalsichaNooter) my Nook works perfect.
 
Last edited:

Renate

Recognized Contributor / Inactive Recognized Dev
My recent testing seem to indicate that you must enable host, then disable host, then enable it again and then it will work.

I can switch back and forth until the cows come home and it doesn't seem to make a difference.

None of the applications for switching seem to work correctly or enumerate the USB bus.

What do you get when the USB is working and you do a:
Code:
cat /sys/devices/platform/musb_hdrc/mode

You can also read the power status here, but the LED already tells you that.
Code:
cat /sys/devices/platform/i2c_omap.1/i2c-adapter/i2c-1/1-0048/twl4030_usb/vbus
 

mali100

Senior Member
Jun 3, 2007
209
140
Today I got my OTG-cable and the host mode works here.
What I have to do is plug in the otg cable without a keyboard connected, then use the USB Host Mode switch app to enable the host mode, and then connect the keyboard.
If I don't follow this sequence, it doesn't work. For example if I try to enable the host mode without the otg cable plugged in, it doesn't work, and the led stays off.
 

Renate

Recognized Contributor / Inactive Recognized Dev
That's interesting that you say that an OTG cable works.
Elsewhere it's reported that the OTG ID pin is not connected in the NST.
Wrong! See later posts.

It's hard to check that since there is no easy way to probe that pin.
An OTG cable grounds that pin, but doesn't bring it out to where it could be measured.

It's still not clear if you can get host mode to work without the LED being on.
Powering would not be essential using a powered hub.

I still can't get anything to work here.
I can get the red LED on with a host command when it's first plugged into a charger.

Maybe su isn't working? It's there, but how do I check it? Neither of the switch applications seem to work.

Could you tell me what this does when you are connected to a keyboard?
Code:
cat /sys/devices/platform/musb_hdrc/mode
 
Last edited:

mali100

Senior Member
Jun 3, 2007
209
140
Could you tell me what this does when you are connected to a keyboard?
Code:
cat /sys/devices/platform/musb_hdrc/mode
When the host mode is switched off:
b_idle
plugging in the otg cable:
b_idle
switching on host mode:
a_wait_vrise and the led is green
plugging in the keyboard into the otg cable:
a_host and the text on the button for switching to host mode changes to "ON" (led stays green)

If I don't plug in the otg cable first it stays on a_wait_vrise even after plugging in the otg + keyboard

I use the apk from this post for switching http://xdaforums.com/showpost.php?p=21818624&postcount=16
 
Last edited:
  • Like
Reactions: Renate

Renate

Recognized Contributor / Inactive Recognized Dev
Ok, a razor blade and a bit of hacking on a spare micro USB cable proves it:

The NST does support the OTG pin detect (despite statements made elsewhere).
The signal runs around 1 V and should be grounded to enable host mode.
Without grounding the pin you can not get things working.

I got the green light to come on! I got a_host! I got the keyboard to work!

If you feel adventurous you can try a razor blade on a plug.
Solder a jumper and you're there.
Or buy an OTG adaptor.
 
  • Like
Reactions: andrewed

verygreen

Senior Member
Feb 13, 2011
1,305
2,637
TN
linuxhacker.ru
Ok, a razor blade and a bit of hacking on a spare micro USB cable proves it:

The NST does support the OTG pin detect (despite statements made elsewhere).
The signal runs around 1 V and should be grounded to enable host mode.
Without grounding the pin you can not get things working.

I got the green light to come on! I got a_host! I got the keyboard to work!

If you feel adventurous you can try a razor blade on a plug.
Solder a jumper and you're there.
Or buy an OTG adaptor.
Hm, interesting. I know that in the Nook Color the id pin is not routed.

Additionally there is no interrupt when you short the ID pin (or at least I never observed anything that would suggest the interrupt coming.)

I just did a bit of testing and indeed seems the id pin is important. That's good to know.
Need to play with some code to try and only supply vbus if otg cable is used, and if it works, we would be able to do away with the app altogether.
 
  • Like
Reactions: andrewed and ros87

mali100

Senior Member
Jun 3, 2007
209
140
Hi verygreen,
For me it works only if I follow exactly this sequence:
-connect OTG-cable without the keyboard
-enable host mode
-connect keyboard to the otg-cable
Do you have any idea why?
 

verygreen

Senior Member
Feb 13, 2011
1,305
2,637
TN
linuxhacker.ru
Hi verygreen,
For me it works only if I follow exactly this sequence:
-connect OTG-cable without the keyboard
-enable host mode
-connect keyboard to the otg-cable
Do you have any idea why?
Try this:
Connect the cable with the keyboard.
enable host mode (see the green light turning on briefly and then turning off all by itself)
after the green light is off, turn off host mode
wait a second
turn on host mode again.

Works for me in this way.
 
Last edited:

toxicdog

Senior Member
Jun 26, 2007
74
10
Sopron
www.toxicdog.hu
It can't seem to work for me.

My nook is rooted.

When I try to echo host to the mode file, it succeeds, but when I try to 'cat mode', it stays 'b_idle' or 'b_peripeherial'.

The switcher app is not working as well: it says nothing, and the button does nothing. I mean, I can press it, but nothing happens, it says 'Click to enable USB Host Mode', no matter how many times I click it.

Did I install the two binaries the wrong way?
 

verygreen

Senior Member
Feb 13, 2011
1,305
2,637
TN
linuxhacker.ru
It can't seem to work for me.

My nook is rooted.

When I try to echo host to the mode file, it succeeds, but when I try to 'cat mode', it stays 'b_idle' or 'b_peripeherial'.

The switcher app is not working as well: it says nothing, and the button does nothing. I mean, I can press it, but nothing happens, it says 'Click to enable USB Host Mode', no matter how many times I click it.

Did I install the two binaries the wrong way?

So, when you do cat /proc/version , does it show that it was built by green@...
 

Renate

Recognized Contributor / Inactive Recognized Dev
It can't seem to work for me.

The switcher apps are dependent upon superuser.apk and su.

To troubleshoot, you can stick with the ADB commands.

Host mode needs the new uRamdisk and uImage copied into the boot partition.

You need to have a OTG cable plugged in when you issue a host command.
(OTG is a special cable that will say USB OTG cable.)

And finally, entering host mode is very erratic. Sometimes it will just do the 100 millisecond flash, other times it will lock into host mode.
 

mali100

Senior Member
Jun 3, 2007
209
140
Try this:
Connect the cable with the keyboard.
enable host mode (see the green light turning on briefly and then turning off all by itself)
after the green light is off, turn off host mode
wait a second
turn on host mode again.

Works for me in this way.
I can confirm that this works also for me. Still a bit tricky but useable. Thanks
 

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