[WIP] USB Host support (working)

Search This thread

Renate

Recognized Contributor / Inactive Recognized Dev
I did get the USB GPS puck to work on /dev/ttyUSB0 after I set it to 9600 baud first on my Windows system. I can cat valid NMEA data out of it. Unfortunately, Google Maps comes up with a suggestion to set "My Location" in Settings. I haven't discovered yet what do to about that. Am I missing some provider or something?

I'm surprised that there has not been more interest/response from my app and the "Magic" button. There is a technical problem with the Nook that it addresses and it should have helped people who couldn't get USB to work. I was waiting to hear some feedback before I let the cat out of the bag.
 

ApokrifX

Senior Member
May 23, 2011
468
50
I'm surprised that there has not been more interest/response from my app and the "Magic" button. There is a technical problem with the Nook that it addresses and it should have helped people who couldn't get USB to work. I was waiting to hear some feedback before I let the cat out of the bag.
Renate,
I’d love to give it a try, but I have neither [OTG] USB cable nor USB "gender-changer" nor USB "modified powered" hub.
If there is a "low budget" solution under $10, it’ll be great "for the rest of us".
That’s why I was looking at micro USB Y cables, but I have a feeling, they supply +5 and GND only and no any data wires… :(
Although, shouldn’t be a problem to DIY. ;)
 

Renate

Recognized Contributor / Inactive Recognized Dev
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.
 

Attachments

  • hub.png
    hub.png
    3.5 KB · Views: 692

cceerrtt

Senior Member
Sep 14, 2010
147
24
Back to the GPS thing, I've got the data coming in, but apparently I've got no LocationProvider's installed.

What do you see in logcat? I have the backup of my 2.1 android phone so I can get some apps from this backup but can't find any LocationProvider, just:

/system/app:
HtcLocationPicker.apk
HtcLocationService.apk
/system/lib/libgps.so
 

Renate

Recognized Contributor / Inactive Recognized Dev
@mali100: Thanks, but the serial port and the puck work fine.

Code:
$GPGSV,3,1,12,14,49,286,45,27,17,45,27,9,38,48,28,22,75,290,0*77

Yes, it's getting my lat/long, I just didn't paste it!

The LocationManager is working fine because I can do this:

Code:
      LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
      List<String> list = lm.getAllProviders();

The providers aren't there because the list is empty.

I've gone far enough into this to know that I don't have any installed.
They would be in /data/misc/location/gps/
There was a suggestion to copy the files off the emulator! But they weren't there.
 

Dagon.Alex

Member
Feb 8, 2012
26
7
Don't people want to have keyboards on their Nooks?
What for? As a proof of concept it is cool, but I can not see any reason I would need a hardware keyboard for my device. Readers(tablets) main feature is its compactness, so why would I want to connect it to keyboard which is bigger then device itself?

Another thing is flash drives support. It`s cool to be able to view any work/study documents on flash just when I need it (Assuming that I take my nook almost everywhere and reading on all the occasions).
 

Renate

Recognized Contributor / Inactive Recognized Dev
I guess that the eye-opener thing around here is that everybody has specific desires to personalize their Nook.

@Dagon.Alex: With about 4 GB of spare space on my Nook SD card I never thought of using a USB flash drive on it. I just tried it. It works fine.

Code:
mount -o rw,remount rootfs /
mkdir /usb
mount -t vfat /dev/block/uba1 /usb

Right now I have my Nook connected to a hub with the keyboard, a GPS puck and a flash drive. The GPS data is there, I'm just working on getting a NMEA LocationProvider working. It's also charging. That makes a nice docking station. I can connect a mouse, but it only generates DPAD commands.

@Googie2149: You can try without it being an OTG cable, but as long as you are going to bother to get one it might as well be OTG. It's not clear now if the interrupt from grounding it or the status is used. In any case, it could be.

To all: See, the thing is, getting this to work without so-called "Magic" is a statistical thing based on the Nook, the cabling and the phase of the moon. For some they may have never gotten it to connect, for others they have never had a problem. I'm just interested in how many of each type. This probably has relevancy to other devices also.
 

mali100

Senior Member
Jun 3, 2007
209
140
Don't people want to have keyboards on their Nooks?
Maybe you should post your tool in this forum http://www.mobileread.com/forums/showthread.php?t=159007 , they surely are interested in this.

For me your actual tool isn't needed, I never had problems connecting devices. But I would love to get the new version. From the screenshot I assume that it is possible to deactivate charging when connected as usb-device? That would be awesome, it would allow me to connect the nook to my tablet, which supports usb-host only for low-power devices and disables the nook because it tries to charge.
 

Renate

Recognized Contributor / Inactive Recognized Dev
Now, I'm getting all confused.
I went back to what I believe is the Nook 1.1 uImage.
Is this the original?

Linux version 2.6.29-omap1 (build@dhabuildimage16) (gcc version 4.3.2 (Sourcery G++ Lite 2008q3-72)) #1 PREEMPT Sat Oct 29 00:45:49 PDT 2011

I can get the original kernel to handle keyboard without using any root access or application?
 

Renate

Recognized Contributor / Inactive Recognized Dev
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.
 
Last edited:

durn_it

Member
Mar 14, 2009
9
1
What to do with init binary

I just realised that there were 3 files in the zip file provided by verygreen. I know what to do with the other two, but what should I do with the init binary?
 

Renate

Recognized Contributor / Inactive Recognized Dev
For those who did get a USB keyboard working there are two map files which could be updated to something sane.

/system/usr/keylayout/qwerty.kl maps scan codes to key codes.
/system/usr/keychars/qwerty.kcm.bin maps key codes to Unicode.

qwerty.kl is commented text and you can add your own F1-12 keys, etc.
qwerty.kcm.bin is binary and you probably don't need to edit it.

Hint:
Shift-Alt A-I-N-Q-U are composing accents.
Alt E-L-Y are Euro, Pound, Yen
Alt C-S are c cedilla, eszet
 

Attachments

  • qwerty.zip
    1.5 KB · Views: 140

darkguy2008

Senior Member
Apr 30, 2011
672
240
Heredia
Damn, this is AWESOME. It's mainly the fact why I just ordered one: price & usb-host support =) (WIP but it seems it's working :D).

I've got a small question though - would it be possible to install a 3G modem on it? or plug my android device to it and enable 3G tethering? if not - but it seems possible - I'm up to helping all with this feature :D
 

Renate

Recognized Contributor / Inactive Recognized Dev
qwerty.kl as posted has Escape=Back, and Application key=Menu.
(App key= key between Windows and Ctrl on the right.)

Yes, you can assign the F keys or the multimedia keys any way you like.

Warning: If you edit it, a syntax error in qwerty.kl will cause it to ignore the rest.
 
  • Like
Reactions: mrWax

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