![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
LogitechC270 webcam class driver alpha version
Fork of USBHostMSD_HelloWorld by
USBHostC270/BaseUvc.cpp@12:ea4badc78215, 2013-03-20 (annotated)
- Committer:
- va009039
- Date:
- Wed Mar 20 14:28:39 2013 +0000
- Revision:
- 12:ea4badc78215
- Parent:
- 11:6a8eef89eb22
support detach
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 10:387c49b2fc7e | 1 | // BaseUvc.cpp |
va009039 | 9:fecabade834a | 2 | #include "USBHostConf.h" |
va009039 | 9:fecabade834a | 3 | #include "USBHost.h" |
va009039 | 12:ea4badc78215 | 4 | #include "USBIsochronous.h" |
va009039 | 9:fecabade834a | 5 | #include "BaseUvc.h" |
va009039 | 9:fecabade834a | 6 | |
va009039 | 9:fecabade834a | 7 | void BaseUvc::poll(int millisec) |
va009039 | 9:fecabade834a | 8 | { |
va009039 | 10:387c49b2fc7e | 9 | HCITD* itd = m_isoEp->isochronousReceive(millisec); |
va009039 | 9:fecabade834a | 10 | if (itd) { |
va009039 | 9:fecabade834a | 11 | uint8_t cc = itd->ConditionCode(); |
va009039 | 9:fecabade834a | 12 | report_cc_count[cc]++; |
va009039 | 9:fecabade834a | 13 | if (cc == 0) { |
va009039 | 9:fecabade834a | 14 | uint16_t frame = itd->StartingFrame(); |
va009039 | 9:fecabade834a | 15 | int fc = itd->FrameCount(); |
va009039 | 9:fecabade834a | 16 | uint8_t* buf = const_cast<uint8_t*>(itd->buf); |
va009039 | 9:fecabade834a | 17 | int mps = m_isoEp->m_PacketSize; |
va009039 | 9:fecabade834a | 18 | for(int i = 0; i < fc; i++) { |
va009039 | 9:fecabade834a | 19 | uint16_t psw = itd->OffsetPSW[i]; |
va009039 | 9:fecabade834a | 20 | cc = psw>>12; |
va009039 | 9:fecabade834a | 21 | if (cc == 0 || cc == 9) { |
va009039 | 9:fecabade834a | 22 | int len = psw & 0x7ff; |
va009039 | 9:fecabade834a | 23 | onResult(frame, buf, len); |
va009039 | 9:fecabade834a | 24 | } |
va009039 | 9:fecabade834a | 25 | report_ps_cc_count[cc]++; |
va009039 | 9:fecabade834a | 26 | buf += mps; |
va009039 | 9:fecabade834a | 27 | frame++; |
va009039 | 9:fecabade834a | 28 | } |
va009039 | 9:fecabade834a | 29 | } |
va009039 | 9:fecabade834a | 30 | delete itd; |
va009039 | 9:fecabade834a | 31 | } |
va009039 | 9:fecabade834a | 32 | } |
va009039 | 9:fecabade834a | 33 | |
va009039 | 10:387c49b2fc7e | 34 | USB_TYPE BaseUvc::Control(int req, int cs, int index, uint8_t* buf, int size) |
va009039 | 10:387c49b2fc7e | 35 | { |
va009039 | 10:387c49b2fc7e | 36 | if (req == SET_CUR) { |
va009039 | 10:387c49b2fc7e | 37 | return host->controlWrite(dev, |
va009039 | 10:387c49b2fc7e | 38 | USB_HOST_TO_DEVICE | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_INTERFACE, |
va009039 | 10:387c49b2fc7e | 39 | req, cs<<8, index, buf, size); |
va009039 | 10:387c49b2fc7e | 40 | } |
va009039 | 10:387c49b2fc7e | 41 | return host->controlRead(dev, |
va009039 | 10:387c49b2fc7e | 42 | USB_DEVICE_TO_HOST | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_INTERFACE, |
va009039 | 10:387c49b2fc7e | 43 | req, cs<<8, index, buf, size); |
va009039 | 10:387c49b2fc7e | 44 | } |
va009039 | 10:387c49b2fc7e | 45 | |
va009039 | 10:387c49b2fc7e | 46 | USB_TYPE BaseUvc::setInterfaceAlternate(uint8_t intf, uint8_t alt) |
va009039 | 10:387c49b2fc7e | 47 | { |
va009039 | 10:387c49b2fc7e | 48 | return host->controlWrite(dev, USB_HOST_TO_DEVICE | USB_RECIPIENT_INTERFACE, |
va009039 | 10:387c49b2fc7e | 49 | SET_INTERFACE, alt, intf, NULL, 0); |
va009039 | 10:387c49b2fc7e | 50 | } |
va009039 | 10:387c49b2fc7e | 51 | |
va009039 | 9:fecabade834a | 52 | void BaseUvc::onResult(uint16_t frame, uint8_t* buf, int len) |
va009039 | 9:fecabade834a | 53 | { |
va009039 | 9:fecabade834a | 54 | if(m_pCbItem && m_pCbMeth) |
va009039 | 9:fecabade834a | 55 | (m_pCbItem->*m_pCbMeth)(frame, buf, len); |
va009039 | 9:fecabade834a | 56 | else if(m_pCb) |
va009039 | 9:fecabade834a | 57 | m_pCb(frame, buf, len); |
va009039 | 9:fecabade834a | 58 | } |
va009039 | 9:fecabade834a | 59 | |
va009039 | 9:fecabade834a | 60 | void BaseUvc::setOnResult( void (*pMethod)(uint16_t, uint8_t*, int) ) |
va009039 | 9:fecabade834a | 61 | { |
va009039 | 9:fecabade834a | 62 | m_pCb = pMethod; |
va009039 | 9:fecabade834a | 63 | m_pCbItem = NULL; |
va009039 | 9:fecabade834a | 64 | m_pCbMeth = NULL; |
va009039 | 9:fecabade834a | 65 | } |
va009039 | 9:fecabade834a | 66 | |
va009039 | 9:fecabade834a | 67 | void BaseUvc::clearOnResult() |
va009039 | 9:fecabade834a | 68 | { |
va009039 | 9:fecabade834a | 69 | m_pCb = NULL; |
va009039 | 9:fecabade834a | 70 | m_pCbItem = NULL; |
va009039 | 9:fecabade834a | 71 | m_pCbMeth = NULL; |
va009039 | 9:fecabade834a | 72 | } |
va009039 | 9:fecabade834a | 73 | |
va009039 | 9:fecabade834a | 74 |