Simple USBHost WebCam for EA LPC4088 QSB/LPC1768 test program

Dependencies:   LPC4088-USBHost mbed

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