Simple USBHost WebCam for EA LPC4088 QSB/LPC1768 test program
Dependencies: LPC4088-USBHost mbed
EA LPC4088 QSB/LPC1768をUSBホストにしてWebカメラからJPEG画像を読み取るテストプログラムです。
The usage is the same as KL46Z-USBHostC270_example.
使い方はKL46Z-USBHostC270_exampleと同じです。
動作確認: Logitech C270,Logitech Q200R(Qcam Orbit AF)
LPC4088-USBHostC270/BaseUvc.cpp@1:1bb68ef9aa77, 2014-04-25 (annotated)
- Committer:
- va009039
- Date:
- Fri Apr 25 05:55:06 2014 +0000
- Revision:
- 1:1bb68ef9aa77
- Parent:
- 0:c972ee42b455
update LPC4088-USBHost library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 0:c972ee42b455 | 1 | // BaseUvc.cpp |
va009039 | 0:c972ee42b455 | 2 | #include "USBHostConf.h" |
va009039 | 0:c972ee42b455 | 3 | #include "USBHost.h" |
va009039 | 0:c972ee42b455 | 4 | #include "BaseUvc.h" |
va009039 | 0:c972ee42b455 | 5 | |
va009039 | 0:c972ee42b455 | 6 | void BaseUvc::poll(int millisec) { |
va009039 | 0:c972ee42b455 | 7 | HCITD* itd = m_isoEp->isochronousReceive(millisec); |
va009039 | 0:c972ee42b455 | 8 | if (itd) { |
va009039 | 0:c972ee42b455 | 9 | uint8_t cc = itd->ConditionCode(); |
va009039 | 0:c972ee42b455 | 10 | report_cc_count[cc]++; |
va009039 | 0:c972ee42b455 | 11 | if (cc == 0) { |
va009039 | 0:c972ee42b455 | 12 | uint16_t frame = itd->StartingFrame(); |
va009039 | 0:c972ee42b455 | 13 | int fc = itd->FrameCount(); |
va009039 | 0:c972ee42b455 | 14 | uint8_t* buf = const_cast<uint8_t*>(itd->buf); |
va009039 | 0:c972ee42b455 | 15 | int mps = m_isoEp->getSize(); |
va009039 | 0:c972ee42b455 | 16 | for(int i = 0; i < fc; i++) { |
va009039 | 0:c972ee42b455 | 17 | uint16_t psw = itd->OffsetPSW[i]; |
va009039 | 0:c972ee42b455 | 18 | cc = psw>>12; |
va009039 | 0:c972ee42b455 | 19 | if (cc == 0 || cc == 9) { |
va009039 | 0:c972ee42b455 | 20 | int len = psw & 0x7ff; |
va009039 | 0:c972ee42b455 | 21 | onResult(frame, buf, len); |
va009039 | 0:c972ee42b455 | 22 | } |
va009039 | 0:c972ee42b455 | 23 | report_ps_cc_count[cc]++; |
va009039 | 0:c972ee42b455 | 24 | buf += mps; |
va009039 | 0:c972ee42b455 | 25 | frame++; |
va009039 | 0:c972ee42b455 | 26 | } |
va009039 | 0:c972ee42b455 | 27 | } |
va009039 | 0:c972ee42b455 | 28 | delete itd; |
va009039 | 0:c972ee42b455 | 29 | } |
va009039 | 0:c972ee42b455 | 30 | } |
va009039 | 0:c972ee42b455 | 31 | |
va009039 | 0:c972ee42b455 | 32 | USB_TYPE BaseUvc::Control(int req, int cs, int index, uint8_t* buf, int size) |
va009039 | 0:c972ee42b455 | 33 | { |
va009039 | 0:c972ee42b455 | 34 | if (req == SET_CUR) { |
va009039 | 0:c972ee42b455 | 35 | return host->controlWrite(dev, |
va009039 | 0:c972ee42b455 | 36 | USB_HOST_TO_DEVICE | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_INTERFACE, |
va009039 | 0:c972ee42b455 | 37 | req, cs<<8, index, buf, size); |
va009039 | 0:c972ee42b455 | 38 | } |
va009039 | 0:c972ee42b455 | 39 | return host->controlRead(dev, |
va009039 | 0:c972ee42b455 | 40 | USB_DEVICE_TO_HOST | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_INTERFACE, |
va009039 | 0:c972ee42b455 | 41 | req, cs<<8, index, buf, size); |
va009039 | 0:c972ee42b455 | 42 | } |
va009039 | 0:c972ee42b455 | 43 | |
va009039 | 0:c972ee42b455 | 44 | USB_TYPE BaseUvc::setInterfaceAlternate(uint8_t intf, uint8_t alt) |
va009039 | 0:c972ee42b455 | 45 | { |
va009039 | 0:c972ee42b455 | 46 | return host->controlWrite(dev, USB_HOST_TO_DEVICE | USB_RECIPIENT_INTERFACE, |
va009039 | 0:c972ee42b455 | 47 | SET_INTERFACE, alt, intf, NULL, 0); |
va009039 | 0:c972ee42b455 | 48 | } |
va009039 | 0:c972ee42b455 | 49 | |
va009039 | 0:c972ee42b455 | 50 | void BaseUvc::onResult(uint16_t frame, uint8_t* buf, int len) |
va009039 | 0:c972ee42b455 | 51 | { |
va009039 | 0:c972ee42b455 | 52 | if(m_pCbItem && m_pCbMeth) |
va009039 | 0:c972ee42b455 | 53 | (m_pCbItem->*m_pCbMeth)(frame, buf, len); |
va009039 | 0:c972ee42b455 | 54 | else if(m_pCb) |
va009039 | 0:c972ee42b455 | 55 | m_pCb(frame, buf, len); |
va009039 | 0:c972ee42b455 | 56 | } |
va009039 | 0:c972ee42b455 | 57 | |
va009039 | 0:c972ee42b455 | 58 | void BaseUvc::setOnResult( void (*pMethod)(uint16_t, uint8_t*, int) ) { |
va009039 | 0:c972ee42b455 | 59 | m_pCb = pMethod; |
va009039 | 0:c972ee42b455 | 60 | m_pCbItem = NULL; |
va009039 | 0:c972ee42b455 | 61 | m_pCbMeth = NULL; |
va009039 | 0:c972ee42b455 | 62 | } |
va009039 | 0:c972ee42b455 | 63 | |
va009039 | 0:c972ee42b455 | 64 | void BaseUvc::clearOnResult() { |
va009039 | 0:c972ee42b455 | 65 | m_pCb = NULL; |
va009039 | 0:c972ee42b455 | 66 | m_pCbItem = NULL; |
va009039 | 0:c972ee42b455 | 67 | m_pCbMeth = NULL; |
va009039 | 0:c972ee42b455 | 68 | } |
va009039 | 0:c972ee42b455 | 69 | |
va009039 | 0:c972ee42b455 | 70 |