Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 01 Nov 2012 20:38:59 +0900 (JST)
From:      SAITOU Toshihide <toshi@ruby.ocn.ne.jp>
To:        freebsd-usb@freebsd.org
Subject:   Re: isochronous transfer for UVC camera
Message-ID:  <20121101.203859.193678837.toshi@ruby.ocn.ne.jp>
In-Reply-To: <20121030.231917.104031274.toshi@ruby.ocn.ne.jp>
References:  <20121030.223138.71086080.toshi@ruby.ocn.ne.jp> <201210301446.43464.hselasky@c2i.net> <20121030.231917.104031274.toshi@ruby.ocn.ne.jp>

next in thread | previous in thread | raw e-mail | index | archive | help
In message: <20121030.231917.104031274.toshi@ruby.ocn.ne.jp>
            SAITOU Toshihide <toshi@ruby.ocn.ne.jp> writes:
> In message: <201210301446.43464.hselasky@c2i.net>
>             Hans Petter Selasky <hselasky@c2i.net> writes:
>> On Tuesday 30 October 2012 14:31:38 SAITOU Toshihide wrote:
>>> Is this true about these functions below?
>> 
>> Alternate setting is supported, though if the interface does not exist or has 
>> already the programmed alternate setting, it will simply do nothing.
> 
> I have no idea... 
> 
> I will build the kernel tomorrow to remove the ugen driver which is
> deactivated in the code though.

Ugen is not separable and not related.

Now I have got the data from UVC cam, \(^-^)/ not yet
examine though.

Thank you HPS for your useful information.


#include <stdio.h>
#include <stdlib.h>
#include <libusb.h>

#define VID     0x0458
#define PID     0x7081

#define ConfVal    1            // Configuration Value
#define IfNum      1            // Interface Number
#define AltIfNum   1            // Alternate Interface Number

#define PKT_LEN        0xc00
#define PKTS_PER_XFER  0x80

#define TIMEOUT 10              // 10 ms


static void cb(struct libusb_transfer *xfer)
{
        printf("\nReceived.\n");      // xfer->buffer
        libusb_submit_transfer(xfer); // repeat
}


int main( int argc, char **argv)
{
    	libusb_context *ctx = NULL;
    	libusb_device *dev = NULL;
        libusb_device_handle *handle;
        struct libusb_config_descriptor *confDesc;
        int numInterfaces;

        uint8_t buf[64];
    	int i;


        // get cam device
    	libusb_init(&ctx);
        handle = libusb_open_device_with_vid_pid(ctx, VID, PID);
        dev = libusb_get_device(handle);

        // if kernel driver is active, detach a kernel driver.
        libusb_get_config_descriptor(dev, ConfVal, &confDesc);
        numInterfaces = (int)confDesc->bNumInterfaces;
        for (i=0; i<numInterfaces; i++)
        {
                if (libusb_kernel_driver_active(handle, i) == 1)
                {
                        printf("Detaching kernel driver for interface %d.\n", i);
                        if (libusb_detach_kernel_driver(handle, i) != 0)
                        {
                                fprintf(stderr, "detach failed.\n");
                        }
                }
        }


        // set the active configuration.
        libusb_set_configuration(handle, ConfVal);

        // claim an interface in a given libusb_handle.
        libusb_claim_interface(handle, 0);

        // negotiate parameters here.

        // claim an interface in a given libusb_handle.
        libusb_claim_interface(handle, IfNum);

        // activate an alternate setting for an interface.
        libusb_set_interface_alt_setting(handle, IfNum, AltIfNum);

        // do an isochronous transfer.

        struct libusb_transfer *xfer = libusb_alloc_transfer(PKTS_PER_XFER);
        uint8_t *data = malloc(PKT_LEN*PKTS_PER_XFER);

        libusb_fill_iso_transfer(
                xfer, handle, 0x82, // Interface 1 Alt 1 Endpoint 0 Address 0x82
                data, PKT_LEN*PKTS_PER_XFER, PKTS_PER_XFER,
                cb, NULL, TIMEOUT);

	libusb_set_iso_packet_lengths(xfer, PKT_LEN);

        // submit transfer.
        libusb_submit_transfer(xfer);

        while (1) {
                libusb_handle_events(ctx);
        }
}

---
SAITOU Toshihide



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20121101.203859.193678837.toshi>