DEVELOPERS BLOG

Peripheral Discovery and USB Host Mode

BlackBerry Peripheral

There are good hosts, bad hosts and those who cannot be a host. Miss Manners is a good host. The Griswolds, despite their efforts, are bad hosts.

But more to the point of this blog: BlackBerry 10 running on the right hardware makes an awesome host!

Why the right hardware?

Z10, Q5 and Q10 are not host capable – the Z30 is the first BlackBerry 10 device featuring USB host capabilities.

How Can I Use Host Mode?

Grab yourself a USB OTG cable. It fits into the USB Micro-B socket on your device, and has a Type A female connector on the other end.

The OTG cable signals to the device that it can enter host mode. We are only using OTG for this signaling, not OTG protocol.

How Much Power Can I Get?

You can draw up to 500mA before you get cut off. I recommend using a powered hub (or accessory) if you want your device battery to last. The Z30 does not support self-charging while it is in host mode.

What Can I Use?

The USB standards define classes for different peripherals. Ignoring hubs, here are some of the classes supported in 10.2.0:

BlackBerry Peripheral Chart

HID: You can plug in a keyboard and mouse. This, combined with the HDMI port, makes your Z30 a desktop replacement. You can also use Microsoft’s Xbox360 controller. If the game uses the Game Pad API, it should work.

Serial: Serial is useful for accessories and hobbyists. With serial, you can send an arbitrary sequence of bytes to your peripheral.

We added a good list of non-serial-classed devices in 10.2.0 that actually implement serial:

BlackBerry Peripheral Chart_2

Release 10.2.1 will let you use a generic serial device as well, such as Arduino Uno R3.

Mass Storage

If you plug your memory stick into your BlackBerry 10 device you can copy files to and from it. If your digital camera supports a mass storage (or file) mode, you can copy files from it as well.

Vendor-Defined

USB peripheral manufacturers have the ability to say that their device does not fit one of the defined classes. If your device has a single end point, it’s going to be available for communication with BlackBerry 10.

Please note: All of the information above is current as of 10.2.0!

Notable Missing Classes

When you plug in a non-supported device, not much is going happen. Here are some common classes that we do not currently support:

Printer: We do not currently support the printer class. Some printers use serial; if you have a serial classed printer, you will be able to connect to and share data with it from your own code.

Audio: We do not currently support audio devices.

MTM: If you want to get files off your digital camera, it will have to be in file mode.

Random Generic Custom Driver: We do not allow you to write or install your own driver for your own class.

Peripheral Discovery

The peripheral discovery [PD] API was introduced with the intent of letting you discover peripherals!

At this time, peripheral discovery will let you listen for Serial and Vendor-Defined devices being connected. You should always query what the PD API supports before using features from it.

Put another way: PD will not let you know when a keyboard is connected – it’s not one of the two currently supported classes.

Demo and Sample

Jam804 at BlackBerry Live Asia 2013 showed peripheral discovery and USB host mode. The Cascades and Arduino code behind one of those demos is available here.

If you want to see it in action, here’s a short video:

Hey! You’re using an Arduino after telling us some of them don’t work yet!

I know. I’m sorry. If you cannot wait until 10.2.1 hits the streets, you can still use a 5V FTDI cable and connect it directly to the TX/RX on the board.

I’m looking forward to hearing how you’ve used the host capabilities of your Z30 in the comments!

About robwilliamsjnrrim