PineCube

From PINE64
Revision as of 21:54, 3 June 2022 by Disctanger (talk | contribs) (→‎PineCube as a webcam: Few additional comments for "PineCube as a webcam" section)
Jump to navigation Jump to search

PineCube as a webcam

The PineCube can be powered by the host and communicate as a peripheral. First, you'll need to a dual USB-A (male) cable to plug it into your computer. Note that the Micro-USB port can be used only for power because the data lines are not connected.

Pinecube webcam1.jpg Pinecube webcam2.jpg

USB as an Ethernet gadget:

Goal: To achieve fast (low latency) wired network connection via USB-A port of PineCube. PineCube will be shown as a network device when connected to a computer via USB-A port. You can set up the computer to be in the same network as PineCube and connect to PineCube via SSH and/or Stream Videos from it.

1. Additional patch to PineCube device tree disable ehci0 and ohci0, enabling usb_otg device instead and setting dr_mode to otg. If otg is not working for you, try setting dr_mode to peripheral. On Armbian there is no need for disabling ehci0 and ohci0. Device tree can be edited via armbian-config tool on Armbian OS. (armbian-config -> System -> DTC)

sample DTC on Armbian:
               -----
               
               usb@1c19000 {
                       compatible = "allwinner,sun8i-h3-musb";
                       reg = <0x1c19000 0x400>;
                       clocks = <0x03 0x1d>;
                       resets = <0x03 0x11>;
                       interrupts = <0x00 0x47 0x04>;
                       interrupt-names = "mc";
                       phys = <0x0e 0x00>;
                       phy-names = "usb";
                       extcon = <0x0e 0x00>;
                       status = "okay";
                       dr_mode = "otg";
                       phandle = <0x2c>;
               };
               
               -----

2. Load necessary kernel modules. You can skip this step if you use Armbian OS because necessary modules are already loaded by default (Detailed instructions for sunxi and ethernet gadget: https://linux-sunxi.org/USB_Gadget/Ethernet)

modprobe sunxi
modprobe configfs
modprobe libcomposite
modprobe u_ether
modprobe usb_f_rndis

3. Add sunxi and g_ether to /etc/modules to get them to load on startup

/etc/modules:
sunxi
g_ether

4. Configure the g_ether device to start with a stable MAC address

/etc/modprobe.d/g_ether.conf:
options g_ether host_addr=f6:11:fd:ed:ec:6e

5. Set a static IP address for usb0 on startup with network manager

/etc/network/interfaces:
  auto usb0
  iface usb0 inet static
      address 192.168.10.2
      netmask 255.255.255.0

6. Boot the PineCube plugging it into a computer 7. Configure the USB ethernet device on the computer to be in the same subnet as the pinecube

Sample setting:
network setting: Manual
address: 192.168.10.5
netmask: 255.255.255.0
gateway: 192.168.10.2

8. Done. You can use above methods to stream video through this USB ethernet connection. Bandwith and response time is much faster compared to usual network methods

USB as a Webcam (UVC) gadget (Work In Progress):

Goal: Make PineCube behave almost as same as like normal Webcam. When you connect PineCube to a computer it will be shown as a webcam device. No need for an additional set up you can use it straight after plugging the PineCube to a computer. USB-A port is for data transfer between PineCube and computer/phone. Micro-USB port is for power.

Action Plan (by Newton688):

-Attempt to load the uvc_gadget (usb_f_uvc) or g_webcam
-Look at this project to see if it can bridge UVC gadget output with the v4l from the OV5650 camera sensor
 https://github.com/wlhe/uvc-gadget

Progress report so far (by Disctanger):

Unfortunately, could not get UVC gadget working on the device so far. USB Gadget wiki page (https://linux-sunxi.org/USB_Gadget) also missing UVC section.
Getting almost the same error in both (g_webcam and configfs) methods at the final stage of enabling UVC gadget:

g_webcam error:
```
[ 1741.996382] g_webcam gadget: uvc: uvc_function_bind()
[ 1741.996423] g_webcam gadget: uvc: Unable to allocate streaming EP
[ 1741.996468] udc musb-hdrc.2.auto: failed to start g_webcam: -22
```

configfs error:
```
[ 2035.636565] configfs-gadget gadget: uvc: uvc_function_bind()
[ 2035.636608] configfs-gadget gadget: uvc: Unable to allocate streaming EP
[ 2035.636647] udc musb-hdrc.2.auto: failed to start g1: -22
```