BaseUsbHost example program
Dependencies: BaseUsbHost FATFileSystem mbed mbed-rtos
LifeCamVX700.cpp
00001 // LifeCamVX700.cpp 2013/1/25 00002 #include "mbed.h" 00003 #include "rtos.h" 00004 #include "BaseUsbHost.h" 00005 //#define DEBUG 00006 #include "BaseUsbHostDebug.h" 00007 #define TEST 00008 #include "BaseUsbHostTest.h" 00009 #include "LifeCamVX700.h" 00010 00011 LifeCamVX700::LifeCamVX700(int frameIndex, uint32_t interval, ControlEp* ctlEp) 00012 { 00013 uint8_t buf[26]; 00014 00015 if (ctlEp == NULL) { // root hub 00016 DBG_OHCI(LPC_USB->HcRhPortStatus1); 00017 TEST_ASSERT_FALSE(LPC_USB->HcRhPortStatus1 & 0x200); 00018 ctlEp = new ControlEp(); 00019 TEST_ASSERT_TRUE(ctlEp); 00020 } 00021 bool r = check(ctlEp); 00022 TEST_ASSERT(r); 00023 m_ctlEp = ctlEp; 00024 00025 int addr = m_ctlEp->GetAddr(); 00026 m_isoEp = new IsochronousEp(addr, VX700_EN, VX700_MPS); 00027 TEST_ASSERT_TRUE(m_isoEp); 00028 00029 memset(buf, 0, 26); 00030 buf[2] = VX700_MJPEG; 00031 buf[3] = frameIndex; 00032 *reinterpret_cast<uint32_t*>(buf+4) = interval; 00033 00034 DBG_BYTES("SET_CUR Commit", buf, 26); 00035 int rc = Control(SET_CUR, VS_COMMIT_CONTROL, 1, buf, 26); 00036 TEST_ASSERT(rc == USB_OK); 00037 00038 rc = Control(GET_CUR, VS_COMMIT_CONTROL, 1, buf, 26); 00039 TEST_ASSERT(rc == USB_OK); 00040 TEST_ASSERT_EQUAL(buf[2], VX700_MJPEG); 00041 TEST_ASSERT_EQUAL(buf[3], frameIndex); 00042 TEST_ASSERT_EQUAL(*reinterpret_cast<uint32_t*>(buf+4), interval); 00043 DBG_BYTES("GET_CUR Commit", buf, 26); 00044 00045 rc = m_ctlEp->SetConfiguration(1); 00046 TEST_ASSERT_EQUAL(rc, USB_OK); 00047 00048 int value; 00049 rc = m_ctlEp->GetConfiguration(&value); 00050 TEST_ASSERT_EQUAL(rc, USB_OK); 00051 DBG("config: %d\n", value); 00052 TEST_ASSERT_EQUAL(value, 1); 00053 00054 rc = m_ctlEp->SetInterfaceAlternate(1, VX700_IF_ALT); // alt=1 packet size = 192 00055 TEST_ASSERT_EQUAL(rc, USB_OK); 00056 00057 rc = m_ctlEp->GetInterface(1, &value); 00058 TEST_ASSERT_EQUAL(rc, USB_OK); 00059 DBG("alt: %d\n", value); 00060 TEST_ASSERT_EQUAL(value, 1); 00061 00062 for(int i = 0; i < 16; i++) { 00063 report_cc_count[i] = 0; 00064 report_ps_cc_count[i] = 0; 00065 } 00066 00067 LPC_USB->HcControl |= OR_CONTROL_PLE; // PeriodicListEnable 00068 LPC_USB->HcControl |= OR_CONTROL_IE; // IsochronousEnable 00069 } 00070 00071 bool LifeCamVX700::check(ControlEp* ctlEp) 00072 { 00073 if (ctlEp == NULL) { 00074 return false; 00075 } 00076 uint8_t buf[18]; 00077 int r = ctlEp->GetDescriptor(1, 0, buf, 8); 00078 if (r != USB_OK) { 00079 return false; 00080 } 00081 DBG_HEX(buf, 8); 00082 const uint8_t desc[] = {0x12,0x01,0x00,0x02,0xef,0x02,0x01,0x40}; 00083 if (memcmp(buf, desc, sizeof(desc)) != 0) { 00084 return false; 00085 } 00086 r = ctlEp->GetDescriptor(1, 0, buf, 18); 00087 if (r != USB_OK) { 00088 return false; 00089 } 00090 DBG_HEX(buf, 18); 00091 uint16_t vid = *reinterpret_cast<uint16_t*>(buf+8); 00092 uint16_t pid = *reinterpret_cast<uint16_t*>(buf+10); 00093 DBG("VID PID: %04X %04X\n", vid, pid); 00094 if (vid == VX700_VID && pid == VX700_PID) { 00095 return true; 00096 } 00097 return false; 00098 } 00099
Generated on Wed Jul 13 2022 00:00:06 by 1.7.2