[WIP] USB Host support (working)

Search This thread

Renate

Recognized Contributor / Inactive Recognized Dev

The charge pump on the NST that makes +5V for the USB is pretty tiny.
It really can't power very well those $10 USB audio adapters.
I think that I measured them at about 50mA or more?

When faced with any strangeness on USB off a device, try using a good powered hub in between.

In other news: There is no wired connection internally to the ID pin on the USB connector of the new Nook Glow plus.
I'm looking for a way to switch the controller into host mode manually.
 
  • Like
Reactions: UncaughtError

nmyshkin

Recognized Contributor
Nov 21, 2013
1,982
522
Hey guys! First of all I want to say a big Thanks to Renate and to all of you guys.

I have a lot of fun with my NST, and just for fun (c) I decided to play with audio usb (C-media).
Everything is OK, but (sadly) sound is "clicking" 90% of the time, sometimes (randomly) sound is clean and clicks (very silent) appear if I type something in terminal (I have sshd on Nook). I dunno about the reason, I've tried anything: killing mediaserver, killing some heavy aps, reconnecting usb card...

You didn't say how you enabled USB Audio on your NST. There are a lot of details, easy to miss one or two. If you didn't use @pinguy1982's CWM method, you might want to give it a try. It worked well for me. If you use NoRefresh, however, the kernal he used is not compatible with it. Also, there are a few details he left out for complete microphone recording capabilities, but the audio playback works great (at least on my NST). If you need/want the full mic stuff I can help you with that.

phone.apk in system/apps is required for the android media volume control to function correctly.
 

UncaughtError

New member
Jun 7, 2016
3
0
The charge pump on the NST that makes +5V for the USB is pretty tiny.
It really can't power very well those $10 USB audio adapters.
I think that I measured them at about 50mA or more?

When faced with any strangeness on USB off a device, try using a good powered hub in between.

In other news: There is no wired connection internally to the ID pin on the USB connector of the new Nook Glow plus.
I'm looking for a way to switch the controller into host mode manually.

I just ordered another one "10 bucks adapter" for a test.
And I just wondering why clicks appear randomly, I can unplug the adapter, then plug it again and clicks disappears, hmm. This drives me crazy:p

---------- Post added at 06:13 PM ---------- Previous post was at 06:06 PM ----------

You didn't say how you enabled USB Audio on your NST. There are a lot of details, easy to miss one or two. If you didn't use @pinguy1982's CWM method, you might want to give it a try. It worked well for me. If you use NoRefresh, however, the kernal he used is not compatible with it. Also, there are a few details he left out for complete microphone recording capabilities, but the audio playback works great (at least on my NST). If you need/want the full mic stuff I can help you with that.

phone.apk in system/apps is required for the android media volume control to function correctly.

Oh. I've used pinguy1982's kernel/ramdisk and userspace stuff (alsa tools) from Google Drive https://docs.google.com/uc?id=0B21a8VVM4QfGZ0lSUmRPNGNOWW8&export=download.
Hm, I thought that kernel, ramdisk and alsa utils would be enough for usb audio, I will try CWM then.

What adapter did you use? Did you try to plug it directly into Nook (I mean, maybe I have a power issue and usb hub is the only way)...
And about mic - no, I want playback only.

Thanks
 

nmyshkin

Recognized Contributor
Nov 21, 2013
1,982
522
Oh. I've used pinguy1982's kernel/ramdisk and userspace stuff (alsa tools) from Google Drive https://docs.google.com/uc?id=0B21a8VVM4QfGZ0lSUmRPNGNOWW8&export=download.
Hm, I thought that kernel, ramdisk and alsa utils would be enough for usb audio, I will try CWM then.

What adapter did you use? Did you try to plug it directly into Nook (I mean, maybe I have a power issue and usb hub is the only way)...
And about mic - no, I want playback only.

Thanks

It's probably six of one, half-dozen of the other if you used @pinguy1982's stuff, but the CWM is certainly easy. Supposedly he did some work on the audio to clean it up. That's the package that's in the CWM but it's probably also what you worked with.

I have two different adapters. One is the Sabrent device with the onboard volume controls and lots of LEDs. The other says "SYBA" on the card that came with it and has no onboard volume controls and no LEDs. That's the one I use all the time but both work for me. Internally they are probably identical except for the LEDs and buttons. I do not use a powered hub with either.

I'm not going to say that it's super-duper HiFi, but I think my NST sounds pretty good. We use it every Sunday morning to listen to a time-shifted NPR program from an adjacent State (plugged into a set of old amplified computer speakers) and I've used it to background listen to Pandora or TuneIn when trying to get through something like "On the Origin of Species". Keeps me awake :)

It seems unlikely that the "clicking" you are experiencing could be due to your OTG cable, but I mention that just to throw another potential variable in the mix. I initially had one heck of a time with the whole USB host business and it turned out to be a bad OTG cable. In my case it was the standard-size USB socket which was not deep enough to allow good contact with the adapter's plug. Once I had a good cable, everything worked like a charm. I've never had any flakiness with it at all.
 
  • Like
Reactions: UncaughtError

digixmax

Senior Member
Jan 17, 2011
2,129
682
Last edited:
  • Like
Reactions: UncaughtError

UncaughtError

New member
Jun 7, 2016
3
0
Hey, guys!
So, I made some "research" and the problem was in the old usb adapter, somehow it randomly produces some "clicks". With the new adapter (almost) everything is perfect!

Thanks to your tips, now I have sound control with side buttons (Phone.apk in /system/apps/ and "Nook Touch Mod Manager" for redefining keys).
The one little problem is that I need to kill mediaserver or reboot Nook to make adapter work properly with media players (like ES or MortPlayer), the funny part is that alsa_aplay works well when ES doesn't :p

Also, I will try to flash CWM on these weekend.
 

Attachments

  • my_photo-9.jpg
    my_photo-9.jpg
    157.7 KB · Views: 106
  • my_photo-8.jpg
    my_photo-8.jpg
    147 KB · Views: 110

nmyshkin

Recognized Contributor
Nov 21, 2013
1,982
522
Hey, guys!
So, I made some "research" and the problem was in the old usb adapter, somehow it randomly produces some "clicks". With the new adapter (almost) everything is perfect!

Thanks to your tips, now I have sound control with side buttons (Phone.apk in /system/apps/ and "Nook Touch Mod Manager" for redefining keys).
The one little problem is that I need to kill mediaserver or reboot Nook to make adapter work properly with media players (like ES or MortPlayer), the funny part is that alsa_aplay works well when ES doesn't :p

Also, I will try to flash CWM on these weekend.

Good job! If you want to avoid the mediaserver dance, you can try out my one-touch toggle app for USB Audio. The first time you touch it USB Host is turned on and mediaserver killed. The next time you touch it, USB Host is terminated and everything is back to normal. This should work for all audio applications (at least it has worked for me with MX Player, ES File Explorer audio player, TuneIn Radio, Pandora, news videos from the BBC News app---basically everything I've tried).
 
  • Like
Reactions: UncaughtError

naa42

New member
Jan 11, 2017
2
0
Hi!
Thank you for your work.
I use rooted Nook Simple Touch since 2011 and I was not aware of USB Host support.
Recently I've bought an OTG cable, installed Mali's kernel and ramdisk, USB Mode Utility and on the first try keyboard worked.
But since then I'm not able to make it work consistently.
When I press "Host" button I get only short green blink. State is a_wait_vrise, Vbus drive: Vbus off, Vbus sense: off.
USB devices does not work.
If I press "Host" many times repeatedly, I can get solid green light and can charge something of my nook, but keyboard or mouse are not recognized.
But couple of times in several hours of attempts my keyboard worked.

How can I debug this problem?

I do not see anything useful in dmesg or logcat output.
In dmesg I see: "forced usb vbus state change 1" when enabling USB Host and "forced usb vbus state change 0" when disabling.
When I get solid green I see "regulator regulator.5: enabling charger".

--
naa
 

nmyshkin

Recognized Contributor
Nov 21, 2013
1,982
522
Hi!
Thank you for your work.
I use rooted Nook Simple Touch since 2011 and I was not aware of USB Host support.
Recently I've bought an OTG cable, installed Mali's kernel and ramdisk, USB Mode Utility and on the first try keyboard worked.
But since then I'm not able to make it work consistently.
When I press "Host" button I get only short green blink. State is a_wait_vrise, Vbus drive: Vbus off, Vbus sense: off.
USB devices does not work.
If I press "Host" many times repeatedly, I can get solid green light and can charge something of my nook, but keyboard or mouse are not recognized.
But couple of times in several hours of attempts my keyboard worked.

How can I debug this problem?

I do not see anything useful in dmesg or logcat output.
In dmesg I see: "forced usb vbus state change 1" when enabling USB Host and "forced usb vbus state change 0" when disabling.
When I get solid green I see "regulator regulator.5: enabling charger".

--
naa
I had a lot of trouble with this on the first go-round. In my case it turned out to be a dodgy OTG cable. There's a lot of variation in how far the metal part extends and therefore how secure the contact is. A different cable solved my issues with all devices. Not saying that's your issue, but it's something to keep in mind.
 
  • Like
Reactions: naa42

naa42

New member
Jan 11, 2017
2
0
I had a lot of trouble with this on the first go-round. In my case it turned out to be a dodgy OTG cable. There's a lot of variation in how far the metal part extends and therefore how secure the contact is. A different cable solved my issues with all devices. Not saying that's your issue, but it's something to keep in mind.

Thank you!
That was my problem exactly. I bought another OTG cable and it worked like a charm.
 

hurrn

Member
Jan 14, 2008
9
0
working german qwertz usb keyboard files here

hello, thanks renate and all for hacking into the nook which allows a programming noob like me
to use a 20$ ereader from ebay
as a very very eyestrain-avoiding, totally cool really useful typewriter
(with an old massive mechanical keyboard and fastmode, maybe i add a solar cell and/or powerbank)

i edited the keyboard config files so that an external keyboard with german qwertz layout with Ä Ö Ü etc an different keybindings can be used (alle tasten funktionieren, bis auf eine am numpad, was eher ziemlich wurscht ist)

just download the attached zip, extract, put the files on a sd card, put it in the nook,

use the "es file explorer" app
(full root acess needed: start es file explorer,
open menu on the left, scrool down, activate slider "root explorer" confirm superuser request,
tap on "root explorer", a menu opens, choose "mount r/w", switch all partitions to "rw" )

or use adb if you are familiar with it, i am not

an move the files as follows:
qwerty.kl to /system/usr/keylayout/
and
qwerty.kcm.bin to system/usr/keychars/
confirm overwrite and reboot.
 
Last edited:

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