testing n-Bed with a Logitech C270 camera

Dependencies:   USBHost mbed

Fork of USBHostC270_example by Norimasa Okamoto

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers BaseUvc.cpp Source File

BaseUvc.cpp

00001 // BaseUvc.cpp
00002 #include "USBHostConf.h"
00003 #include "USBHost.h"
00004 #include "USBIsochronous.h"
00005 #include "BaseUvc.h"
00006 
00007 void BaseUvc::poll(int millisec)
00008 {
00009     HCITD* itd = m_isoEp->isochronousReceive(millisec);
00010     if (itd) {
00011         uint8_t cc = itd->ConditionCode();
00012         report_cc_count[cc]++;
00013         if (cc == 0) {
00014             uint16_t frame = itd->StartingFrame();
00015             int fc = itd->FrameCount();
00016             uint8_t* buf = const_cast<uint8_t*>(itd->buf); 
00017             int mps = m_isoEp->m_PacketSize;
00018             for(int i = 0; i < fc; i++) {
00019                 uint16_t psw = itd->OffsetPSW[i];
00020                 cc = psw>>12;
00021                 if (cc == 0 || cc == 9) {
00022                     int len = psw & 0x7ff;
00023                     onResult(frame, buf, len);
00024                }
00025                report_ps_cc_count[cc]++;
00026                buf += mps;
00027                frame++;
00028             }
00029         }
00030         delete itd;
00031     }
00032 }
00033 
00034 USB_TYPE BaseUvc::Control(int req, int cs, int index, uint8_t* buf, int size)
00035 {
00036     if (req == SET_CUR) {    
00037         return host->controlWrite(dev,
00038                     USB_HOST_TO_DEVICE | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_INTERFACE, 
00039                     req, cs<<8, index, buf, size);
00040     }
00041     return host->controlRead(dev,
00042                 USB_DEVICE_TO_HOST | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_INTERFACE, 
00043                 req, cs<<8, index, buf, size);
00044 }
00045 
00046 USB_TYPE BaseUvc::setInterfaceAlternate(uint8_t intf, uint8_t alt)
00047 {
00048     return host->controlWrite(dev, USB_HOST_TO_DEVICE | USB_RECIPIENT_INTERFACE,
00049                                    SET_INTERFACE, alt, intf, NULL, 0);
00050 }
00051 
00052 void BaseUvc::onResult(uint16_t frame, uint8_t* buf, int len)
00053 {
00054   if(m_pCbItem && m_pCbMeth)
00055     (m_pCbItem->*m_pCbMeth)(frame, buf, len);
00056   else if(m_pCb)
00057     m_pCb(frame, buf, len);
00058 }
00059 
00060 void BaseUvc::setOnResult( void (*pMethod)(uint16_t, uint8_t*, int) )
00061 {
00062     m_pCb = pMethod;
00063     m_pCbItem = NULL;
00064     m_pCbMeth = NULL;
00065 }
00066     
00067 void BaseUvc::clearOnResult()
00068 {
00069     m_pCb = NULL;
00070     m_pCbItem = NULL;
00071     m_pCbMeth = NULL;
00072 }
00073 
00074