BaseUsbHost example program
Dependencies: BaseUsbHost FATFileSystem mbed mbed-rtos
Diff: LifeCamVX700/LifeCamVX700.cpp
- Revision:
- 4:41ff237a64ec
- Child:
- 5:495f7536897b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LifeCamVX700/LifeCamVX700.cpp Sun Jan 06 11:49:30 2013 +0000 @@ -0,0 +1,99 @@ +// LifeCamVX700.cpp 2012/12/10 +#include "mbed.h" +#include "rtos.h" +#include "BaseUsbHost.h" +#define DEBUG +#include "BaseUsbHostDebug.h" +#define TEST +#include "BaseUsbHostTest.h" +#include "LifeCamVX700.h" + +LifeCamVX700::LifeCamVX700(int frameIndex, uint32_t interval, ControlEp* ctlEp) +{ + uint8_t buf[26]; + + if (ctlEp == NULL) { // root hub + DBG_OHCI(LPC_USB->HcRhPortStatus1); + TEST_ASSERT_FALSE(LPC_USB->HcRhPortStatus1 & 0x200); + ctlEp = new ControlEp(); + TEST_ASSERT_TRUE(ctlEp); + } + bool r = check(ctlEp); + TEST_ASSERT(r); + m_ctlEp = ctlEp; + + int addr = m_ctlEp->GetAddr(); + m_isoEp = new IsochronousEp(addr, VX700_EN, VX700_MPS); + TEST_ASSERT_TRUE(m_isoEp); + + memset(buf, 0, 26); + buf[2] = VX700_MJPEG; + buf[3] = frameIndex; + *reinterpret_cast<uint32_t*>(buf+4) = interval; + + DBG_BYTES("SET_CUR Commit", buf, 26); + int rc = Control(SET_CUR, VS_COMMIT_CONTROL, 1, buf, 26); + TEST_ASSERT(rc == USB_OK); + + rc = Control(GET_CUR, VS_COMMIT_CONTROL, 1, buf, 26); + TEST_ASSERT(rc == USB_OK); + TEST_ASSERT_EQUAL(buf[2], VX700_MJPEG); + TEST_ASSERT_EQUAL(buf[3], frameIndex); + TEST_ASSERT_EQUAL(*reinterpret_cast<uint32_t*>(buf+4), interval); + DBG_BYTES("GET_CUR Commit", buf, 26); + + rc = m_ctlEp->SetConfiguration(1); + TEST_ASSERT_EQUAL(rc, USB_OK); + + int value; + rc = m_ctlEp->GetConfiguration(&value); + TEST_ASSERT_EQUAL(rc, USB_OK); + DBG("config: %d\n", value); + TEST_ASSERT_EQUAL(value, 1); + + rc = m_ctlEp->SetInterfaceAlternate(1, VX700_IF_ALT); // alt=1 packet size = 192 + TEST_ASSERT_EQUAL(rc, USB_OK); + + rc = m_ctlEp->GetInterface(1, &value); + TEST_ASSERT_EQUAL(rc, USB_OK); + DBG("alt: %d\n", value); + TEST_ASSERT_EQUAL(value, 1); + + for(int i = 0; i < 16; i++) { + report_cc_count[i] = 0; + report_ps_cc_count[i] = 0; + } + + LPC_USB->HcControl |= OR_CONTROL_PLE; // PeriodicListEnable + LPC_USB->HcControl |= OR_CONTROL_IE; // IsochronousEnable +} + +bool LifeCamVX700::check(ControlEp* ctlEp) +{ + if (ctlEp == NULL) { + return false; + } + uint8_t buf[18]; + int r = ctlEp->GetDescriptor(1, 0, buf, 8); + if (r != USB_OK) { + return false; + } + DBG_HEX(buf, 8); + const uint8_t desc[] = {0x12,0x01,0x00,0x02,0xef,0x02,0x01,0x40}; + if (memcmp(buf, desc, sizeof(desc)) != 0) { + return false; + } + r = ctlEp->GetDescriptor(1, 0, buf, 18); + if (r != USB_OK) { + return false; + } + DBG_HEX(buf, 18); + uint16_t vid = *reinterpret_cast<uint16_t*>(buf+8); + uint16_t pid = *reinterpret_cast<uint16_t*>(buf+10); + DBG("VID PID: %04X %04X\n", vid, pid); + if (vid == VX700_VID && pid == VX700_PID) { + return true; + } + return false; +} +