Can a camera act as a USB host? - General Discussion and Assistance - CHDK Forum

Can a camera act as a USB host?

  • 6 Replies
  • 5581 Views
Can a camera act as a USB host?
« on: 10 / June / 2012, 04:05:49 »
Advertisements
Having experimented with the USB remote feature and PTP, I can't help wondering if there is any way to use the camera as a USB host rather than a slave. For example, could it be possible to interface with a USB mouse connected directly across pins 2 and 3 without going via a PC (obviously powered through pins 1 and 4 by another 5V source), and write an appropriate driver to control it?

I found this post http://chdk.setepontos.com/index.php?topic=903.0 from 4 years ago when this wasn't possible, but this was in the days before PTP so has anyone found anything in the disassembled original firmware that could make this possible?

I'm guessing this probably isn't given that nobody's done it and that USB's quite complicated compared with serial/parallel etc., but it would be really fantastic if it was!

*

Offline zeno

  • *****
  • 891
Re: Can a camera act as a USB host?
« Reply #1 on: 10 / June / 2012, 04:30:35 »
The size of the code stack needed to be a USB host rules it out for cameras (which would require lots more memory just to support a feature that very few would find a use for).
A570, S100, Ixus 127
Author of ASSIST, STICK, WASP, ACID, SDMInst, LICKS, WICKS, MacBoot, UBDB, CFGEdit

Re: Can a camera act as a USB host?
« Reply #2 on: 10 / June / 2012, 05:00:50 »
Ah OK, thanks, I knew there must be a reason why it hadn't been implemented.

*

Offline reyalp

  • ******
  • 14126
Re: Can a camera act as a USB host?
« Reply #3 on: 10 / June / 2012, 15:09:51 »
The size of the code stack needed to be a USB host rules it out for cameras (which would require lots more memory just to support a feature that very few would find a use for).
I'm not sure this is correct. The cameras have a lot more resources than the first USB supporting PCs, and many small embedded systems can implement host functionality. However, Canon has no requirement for the camera to operate as a host, so clearly they wouldn't implement it.

Beyond that, my understanding is that hardware required for host operation is different. This is why Android added the custom "USB accessory" mode for devices incapable of acting as a host. Google certainly wouldn't have bothered to implement this if adding host support to existing devices was just a driver upgrade. From http://developer.android.com/guide/topics/usb/index.html
Quote
Support for USB host and accessory modes are ultimately dependant on the device's hardware, regardless of platform level.
There is no reason for Canon to implement host capable hardware on their cameras.

Note, implementing support for Android USB accessories should at least be theoretically possible, but we currently only hook the camera stack at the PTP level, not low level USB.
Don't forget what the H stands for.

Re: Can a camera act as a USB host?
« Reply #4 on: 10 / June / 2012, 16:30:36 »
Thank you reyalp for your very informative response. So it looks as if that sort of functionality won't be possible to implement.

However if Android USB "accessories" which do their own processing are possible, would this mean for example that something like this - http://chemicaloliver.net/arduino/getting-nmea-data-from-an-inforad-gps-speed-camera-detector/ - a GPS unit which delivers data periodically via USB - could potentially be hooked up to the camera? That is if low-level USB support were added.

Are hooks for low-level USB likely to be found in the disassembled firmware, or is it more complicated than this?

*

Offline reyalp

  • ******
  • 14126
Re: Can a camera act as a USB host?
« Reply #5 on: 10 / June / 2012, 17:04:04 »
However if Android USB "accessories" which do their own processing are possible, would this mean for example that something like this - http://chemicaloliver.net/arduino/getting-nmea-data-from-an-inforad-gps-speed-camera-detector/ - a GPS unit which delivers data periodically via USB - could potentially be hooked up to the camera? That is if low-level USB support were added.
If the device acts as host, then it is theoretically possible. The device you linked isn't USB at all, let alone host capable. In general, a GPS device isn't going to be a host, even if it is USB capable, and AFAIK there is no "GPS host that sends data to device" standard, so you'd still require new custom code on both ends.

Regarding Android accessories, they are a host that uses a custom protocol created by the Android team. Theoretically, you could probably implement the device side of this on the camera, but the main reason I brought it up is because it's a clear way of showing that host support isn't just a software/driver issue.
Quote
Are hooks for low-level USB likely to be found in the disassembled firmware, or is it more complicated than this?
The code must be in the firmware, but making a fully functioning implementation would probably involve a lot of work. I know I've seen bits and pieces of it and I'm sure other CHDK developers have, but AFAIK no one has reverse engineered it to the point of doing anything useful. Our USB communication extension is built on PTP because that's what seemed easiest.

In practice, you'd be much better off using a device that already has host support and using the existing PTP extension to transfer your data. Implementing PTP code on the host will be much simpler than reverse engineering the USB stack on the camera. Or if you just want GPS, buy a camera like the sx230 or sx260 that already has GPS built in. The cost of these cameras is far less than the value of programmer time required to implement almost any alternative solution... even if your programmer only gets minimum wage!

A user has successfully implemented the CHDK PTP extension with an Arduino host, see http://chdk.setepontos.com/index.php?topic=6969.0

I'm sure there are plenty of GPS devices that you can easily connect to an Arduino. This will surely be much less work than implementing a USB driver on the camera. There are also small, cheap SBCs like http://www.raspberrypi.org/ which would let you use the existing PTP client software with minimal modification.
Don't forget what the H stands for.

Re: Can a camera act as a USB host?
« Reply #6 on: 11 / June / 2012, 14:02:56 »
Quote
The device you linked isn't USB at all, let alone host capable.

I mistakenly believed that it was a host device - since it does not control the PC it is connected to it's obvious now thinking about it why it's not.

Quote
In practice, you'd be much better off using a device that already has host support and using the existing PTP extension to transfer your data. Implementing PTP code on the host will be much simpler than reverse engineering the USB stack on the camera.

PTP does seem to be the best solution for USB operations given its speed and stability, which is impressive given it's reverse-engineered. The live view functionality in your ptp-live build is a particularly great feature.

Quote
A user has successfully implemented the CHDK PTP extension with an Arduino host, see http://chdk.setepontos.com/index.php?topic=6969.0

I will read that thread carefully and see what I can get working with the Arduino.

Quote
I'm sure there are plenty of GPS devices that you can easily connect to an Arduino. This will surely be much less work than implementing a USB driver on the camera. There are also small, cheap SBCs like http://www.raspberrypi.org/ which would let you use the existing PTP client software with minimal modification.

I suppose one reason I was wanting the camera to be a host was because a full-blown PC in between the two devices would be impractical, but an Arduino or Raspberry Pi doing the processing could be really neat given their small size and allow a lot more, e.g. interfacing with other inputs and outputs. It would also be a lot less difficult than trying to basically program a USB controller from scratch!

Thanks for replying to my post - you've answered a lot of my questions and now I've got some interesting ideas to try out.

 

Related Topics


SimplePortal © 2008-2014, SimplePortal