Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: uvchost FatFileSystem mbed HTTPServer NetServicesMin
Revision 1:7a4f2c038803, committed 2012-08-14
- Comitter:
- va009039
- Date:
- Tue Aug 14 03:42:12 2012 +0000
- Parent:
- 0:2b4ea8a138e5
- Commit message:
- supported LogitechC270 and Safari
Changed in this revision
--- a/WebcamHandler.cpp Wed Jun 06 11:47:06 2012 +0000
+++ b/WebcamHandler.cpp Tue Aug 14 03:42:12 2012 +0000
@@ -21,6 +21,7 @@
THE SOFTWARE.
*/
+#include "WebcamServerConfig.h"
#include "WebcamHandler.h"
//#define __DEBUG
@@ -29,6 +30,20 @@
#define _D(...) #__VA_ARGS__
+#if CAM_COUNT == 1
+const char* html_index = _D(
+<html>
+<head>
+<meta http-equiv="refresh" content="10">
+</head>
+<body>
+<a href="/cam.jpg"><img src="/cam.jpg" width="320" height="240"></a>
+</body>
+</html>
+);
+#endif
+
+#if CAM_COUNT == 2
const char* html_index = _D(
<html>
<head>
@@ -40,6 +55,7 @@
</body>
</html>
);
+#endif
#define CHUNK_SIZE 128
@@ -57,7 +73,7 @@
}
DBG_ASSERT(cam >= 0);
DBG_ASSERT(cam <= 1);
- m_buf = m_image[cam].buf;
+ m_buf = (char*)m_image[cam].buf;
m_buf_len = m_image[cam].len;
respHeaders()["Content-Type"] = "image/jpeg";
m_busy = true;
@@ -140,7 +156,7 @@
struct stimage WebcamHandler::m_image[] = {{NULL,0},{NULL,0}};
bool WebcamHandler::m_busy = false;
-void WebcamHandler::setImage(char* buf, int len, int cam)
+void WebcamHandler::setImage(uint8_t* buf, int len, int cam)
{
DBG_ASSERT(cam >= 0);
DBG_ASSERT(cam <= 1);
--- a/WebcamHandler.h Wed Jun 06 11:47:06 2012 +0000
+++ b/WebcamHandler.h Tue Aug 14 03:42:12 2012 +0000
@@ -28,7 +28,7 @@
#include "mbed.h"
struct stimage {
- char* buf;
+ uint8_t* buf;
int len;
};
@@ -37,7 +37,7 @@
public:
WebcamHandler(const char* rootPath, const char* path, TCPSocket* pTCPSocket);
virtual ~WebcamHandler(){}
- static void setImage(char* buf, int len, int cam = 0);
+ static void setImage(uint8_t* buf, int len, int cam = 0);
static bool busy() { return m_busy; }
//protected:
static inline HTTPRequestHandler* inst(const char* rootPath, const char* path, TCPSocket* pTCPSocket) { return new WebcamHandler(rootPath, path, pTCPSocket); } //if we ever could do static virtual functions, this would be one
--- a/WebcamInput.cpp Wed Jun 06 11:47:06 2012 +0000
+++ b/WebcamInput.cpp Tue Aug 14 03:42:12 2012 +0000
@@ -1,5 +1,7 @@
+#include "WebcamServerConfig.h"
#include "WebcamInput.h"
#include "WebcamHandler.h"
+#include "myjpeg.h"
//#define __DEBUG
#include "mydbg.h"
@@ -12,7 +14,8 @@
DBG("%p cam=%d\n", this, cam);
m_t.reset();
m_t.start();
- m_image_buf = new char[IMAGE_SIZE];
+ m_size = IMAGE_SIZE;
+ m_image_buf = new uint8_t[m_size];
DBG_ASSERT(m_image_buf);
}
@@ -52,6 +55,13 @@
m_image_buf[m_pos++] = data[i];
}
if (buf[1]&0x02) { // EOF
+#ifdef UVC_INSERT_DHT
+ myjpeg JPEG(m_image_buf, m_pos, m_size);
+ JPEG.analytics();
+ if (JPEG.DHT_pos == 0) {
+ m_pos = JPEG.insertDHT();
+ }
+#endif // UVC_INSERT_DHT
WebcamHandler::setImage(m_image_buf, m_pos, m_cam);
m_t.reset();
m_seq = 0;
--- a/WebcamInput.h Wed Jun 06 11:47:06 2012 +0000
+++ b/WebcamInput.h Tue Aug 14 03:42:12 2012 +0000
@@ -12,7 +12,8 @@
int m_seq;
uint8_t m_bfh;
int m_pos;
- char* m_image_buf;
+ int m_size;
+ uint8_t* m_image_buf;
Timer m_t;
int m_cam;
};
--- a/WebcamServer.cpp Wed Jun 06 11:47:06 2012 +0000
+++ b/WebcamServer.cpp Tue Aug 14 03:42:12 2012 +0000
@@ -3,6 +3,7 @@
#include "EthernetNetIf.h"
//#include "WIZ820ioNetIf.h"
#include "HTTPServer.h"
+#include "WebcamServerConfig.h"
#include "WebcamHandler.h"
#include "WebcamInput.h"
Serial pc(USBTX, USBRX);
@@ -12,12 +13,12 @@
EthernetNetIf eth;
//WIZ820ioNetIf eth;
-#define CAM_COUNT 2
uvc* Webcam[CAM_COUNT];
int main() {
pc.baud(921600);
+ printf("%s\n", __FILE__);
for(int i = 0; i < CAM_COUNT; i++) {
uvc* cam = new uvc(i);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/WebcamServerConfig.h Tue Aug 14 03:42:12 2012 +0000 @@ -0,0 +1,8 @@ +#ifndef WEBCAM_SERVER_CONFIG_H +#define WEBCAM_SERVER_CONFIG_H + +#define CAM_COUNT 1 + +#define UVC_INSERT_DHT + +#endif // WEBCAM_SERVER_CONFIG_H
--- a/usb/UsbBaseClass.cpp Wed Jun 06 11:47:06 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,38 +0,0 @@
-#include "UsbBaseClass.h"
-//#define __DEBUG
-#include "mydbg.h"
-
-UsbBaseClass::UsbBaseClass()
-{
- if (m_pHost == NULL) {
- m_pHost = new UsbHostMgr;
- DBG_ASSERT(m_pHost);
- m_pHost->init();
- }
- DBG("m_pHost=%p\n", m_pHost);
-}
-
-UsbErr UsbBaseClass::Usb_poll(int timeout, int timeout2)
-{
- DBG("%p %d %d\n", this, timeout, timeout2);
- Timer t;
- t.reset();
- t.start();
- Timer t2;
- t2.reset();
- t2.start();
- while(t.read_ms() < timeout) {
- UsbErr rc = m_pHost->poll();
- if (rc == USBERR_PROCESSING) {
- t2.reset();
- }
- if (t2.read_ms() > timeout2) {
- DBG("%p t=%d\n", this, t.read_ms());
- return USBERR_OK;
- }
- wait_ms(50);
- }
- return USBERR_PROCESSING;
-}
-
-UsbHostMgr* UsbBaseClass::m_pHost = NULL;
--- a/usb/UsbBaseClass.h Wed Jun 06 11:47:06 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,13 +0,0 @@
-#ifndef _USB_BASE_CLASS_H_
-#define _USB_BASE_CLASS_H_
-#include "UsbHostMgr.h"
-
-class UsbBaseClass {
-public:
- UsbBaseClass();
-protected:
- UsbErr Usb_poll(int timeout = 15000, int timeout2 = 2000);
- static UsbHostMgr* m_pHost;
-};
-
-#endif //_USB_BASE_CLASS_H_
--- a/usb/UsbDevice.cpp Wed Jun 06 11:47:06 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,400 +0,0 @@
-
-/*
-Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-#include "UsbDevice.h"
-//#define __DEBUG
-#include "mydbg.h"
-
-UsbDevice::UsbDevice( UsbHostMgr* pMgr, int hub, int port, int addr ) : m_pControlEp(NULL), /*m_controlEp( this, 0x00, false, USB_CONTROL, 8 ),*/
-m_pMgr(pMgr), m_connected(false), m_enumerated(false), m_hub(hub), m_port(port), m_addr(addr), m_refs(0),
-m_vid(0), m_pid(0)
-{
- m_DeviceClass = 0x00;
- m_InterfaceClass = 0x00;
-}
-
-UsbDevice::~UsbDevice()
-{
- DBG_ASSERT(0);
-
- if(m_pControlEp)
- delete m_pControlEp;
-}
-
-UsbErr UsbDevice::enumerate()
-{
- VERBOSE("Hub: %d Port: %d\n", m_hub, m_port);
- UsbErr rc;
- DBG("%p m_hub=%d m_port=%d\n", this, m_hub, m_port);
- DBG_ASSERT(m_pMgr);
- m_pMgr->resetPort(m_hub, m_port);
-
- wait_ms(400);
-
- uint8_t temp[8];
- DBG_ASSERT(m_pControlEp == NULL);
- m_pControlEp = new UsbEndpoint( this, 0x00, false, USB_CONTROL, sizeof(temp), 0 );
- DBG_ASSERT(m_pControlEp);
- //EDCtrl->Control = 8 << 16;/* Put max pkt size = 8 */
- /* Read first 8 bytes of device desc */
- DBG_ASSERT(sizeof(temp) >= 8);
- //rc = controlReceive(
- // USB_DEVICE_TO_HOST | USB_RECIPIENT_DEVICE, GET_DESCRIPTOR,
- // (USB_DESCRIPTOR_TYPE_DEVICE << 8) |(0), 0, temp, sizeof(temp));
- //DBG_ASSERT(rc == USBERR_OK);
- rc = GetDescriptor(USB_DESCRIPTOR_TYPE_DEVICE, 0, temp, sizeof(temp));
- if (rc != USBERR_OK) {
- DBG("rc=%d\n", rc);
- DBG_ASSERT(rc == USBERR_OK);
- return rc;
- }
- DBG_ASSERT(rc == USBERR_OK);
- DBG_BYTES("DeviceDescriptor first 8 bytes", temp, sizeof(temp));
- DBG_ASSERT(temp[0] == 18); // bLength
- DBG_ASSERT(temp[1] == 0x01); // bDescriptType
- if (rc)
- {
- DBG("RC=%d",rc);
- return (rc);
- }
- uint8_t bMaxPacketSize = temp[7];
- DBG_ASSERT(bMaxPacketSize >= 8);
- DBG("Got descriptor, max ep size is %d\n", bMaxPacketSize);
-
- m_pControlEp->updateSize(bMaxPacketSize); /* Get max pkt size of endpoint 0 */
- rc = controlSend(USB_HOST_TO_DEVICE | USB_RECIPIENT_DEVICE, SET_ADDRESS, m_addr, 0, NULL, 0); /* Set the device address to m_addr */
- DBG_ASSERT(rc == USBERR_OK);
- if (rc)
- {
- // PRINT_Err(rc);
- return (rc);
- }
- wait_ms(2);
- //EDCtrl->Control = (EDCtrl->Control) | 1; /* Modify control pipe with address 1 */
-
- //Update address
- m_pControlEp->updateAddr(m_addr);
- DBG("Ep addr is now %d", m_addr);
- /**/
-
- //rc = HOST_GET_DESCRIPTOR(USB_DESCRIPTOR_TYPE_DEVICE, 0, TDBuffer, 17); //Read full device descriptor
- //rc = controlReceive(USB_DEVICE_TO_HOST | USB_RECIPIENT_DEVICE, GET_DESCRIPTOR,
- // (USB_DESCRIPTOR_TYPE_DEVICE << 8)|(0), 0,
- // m_controlDataBuf, 17);
- uint8_t DeviceDesc[18];
- rc = GetDescriptor(USB_DESCRIPTOR_TYPE_DEVICE, 0, DeviceDesc, sizeof(DeviceDesc));
- DBG_ASSERT(rc == USBERR_OK);
- DBG_BYTES("DeviceDescriptor", DeviceDesc, sizeof(DeviceDesc));
- DBG_ASSERT(DeviceDesc[0] == 18);
- DBG_ASSERT(DeviceDesc[1] == 0x01);
- DBG_ASSERT(DeviceDesc[17] == 1); // bNumConfiguration
- if (rc)
- {
- //PRINT_Err(rc);
- return (rc);
- }
-
- /*
- rc = SerialCheckVidPid();
- if (rc != OK) {
- PRINT_Err(rc);
- return (rc);
- }
- */
- /**/
- m_DeviceClass = DeviceDesc[4];
- VERBOSE("DeviceClass: %02X\n", m_DeviceClass);
-
- m_vid = *((uint16_t*)&DeviceDesc[8]);
- m_pid = *((uint16_t*)&DeviceDesc[10]);
- VERBOSE("Vender: %04X\n", m_vid);
- VERBOSE("Product: %04X\n", m_pid);
- int iManufacture = DeviceDesc[14];
- if (iManufacture) {
- char str[64];
- rc = GetString(iManufacture, str, sizeof(str));
- DBG_ASSERT(rc == USBERR_OK);
- VERBOSE("Manufacture: %s\n", str);
- }
- int iProduct = DeviceDesc[15];
- if (iProduct) {
- char str[64];
- rc = GetString(iProduct, str, sizeof(str));
- DBG_ASSERT(rc == USBERR_OK);
- VERBOSE("Product: %s\n", str);
- }
- if (DeviceDesc[4] == 0x09) { // Hub
- return hub_init();
- }
-
- uint8_t ConfigDesc[9];
- int index = 0;
- rc = GetDescriptor(USB_DESCRIPTOR_TYPE_CONFIGURATION, index, ConfigDesc, sizeof(ConfigDesc));
- DBG_ASSERT(rc == USBERR_OK);
- DBG_BYTES("ConfigDescriptor 9bytes", ConfigDesc, sizeof(ConfigDesc));
- DBG_ASSERT(ConfigDesc[0] == 9);
- DBG_ASSERT(ConfigDesc[1] == 0x02);
- int wTotalLength = *((uint16_t*)&ConfigDesc[2]);
- DBG("TotalLength: %d\n", wTotalLength);
- int bConfigValue = ConfigDesc[5];
- DBG_ASSERT(bConfigValue == 1);
- DBG("ConfigValue: %d\n", bConfigValue);
- DBG("MaxPower: %d mA\n", ConfigDesc[8]*2);
-
- uint8_t* buf = new uint8_t[wTotalLength];
- rc = GetDescriptor(USB_DESCRIPTOR_TYPE_CONFIGURATION, index, buf, wTotalLength);
- DBG_ASSERT(rc == USBERR_OK);
- DBG_ASSERT(ConfigDesc[1] == 0x02);
- int pos = 0;
- while(pos < wTotalLength) {
- DBG_BYTES("", buf+pos, buf[pos]);
- if (buf[pos+1] == 4) { // interface ?
- m_InterfaceClass = buf[pos+5];
- VERBOSE("InterfaceClass: %02X\n", m_InterfaceClass);
- break;
- }
- pos += buf[pos];
- }
- delete[] buf;
-
- rc = setConfiguration(1);
- DBG_ASSERT(rc == USBERR_OK);
- if (rc)
- {
- // PRINT_Err(rc);
- return rc;
- }
- wait_ms(100);/* Some devices may require this delay */
-
- m_enumerated = true;
- return USBERR_OK;
-}
-
-bool UsbDevice::connected()
-{
- return m_connected;
-}
-
-bool UsbDevice::enumerated()
-{
- return m_enumerated;
-}
-
-int UsbDevice::getPid()
-{
- return m_pid;
-}
-
-int UsbDevice::getVid()
-{
- return m_vid;
-}
-#if 0
-UsbErr UsbDevice::getConfigurationDescriptor(int config, uint8_t** pBuf)
-{
- DBG_ASSERT(m_controlDataBuf);
- //For now olny one config
- *pBuf = m_controlDataBuf;
- return USBERR_OK;
-}
-
-UsbErr UsbDevice::getInterfaceDescriptor(int config, int item, uint8_t** pBuf)
-{
- DBG_ASSERT(m_controlDataBuf);
- byte* desc_ptr = m_controlDataBuf;
-
-/* if (desc_ptr[1] != USB_DESCRIPTOR_TYPE_CONFIGURATION)
- {
- return USBERR_BADCONFIG;
- }*/
- DBG_ASSERT(m_controlDataBuf);
- if(item>=m_controlDataBuf[4])//Interfaces count
- return USBERR_NOTFOUND;
-
- desc_ptr += desc_ptr[0];
-
- *pBuf = NULL;
-
- while (desc_ptr < m_controlDataBuf + *((uint16_t*)&m_controlDataBuf[2]))
- {
-
- switch (desc_ptr[1]) {
- case USB_DESCRIPTOR_TYPE_INTERFACE:
- if(desc_ptr[2] == item)
- {
- *pBuf = desc_ptr;
- return USBERR_OK;
- }
- desc_ptr += desc_ptr[0]; // Move to next descriptor start
- break;
- }
-
- }
-
- if(*pBuf == NULL)
- return USBERR_NOTFOUND;
-
- return USBERR_OK;
-}
-#endif
-
-UsbErr UsbDevice::setConfiguration(int config)
-{
- DBG("config=%d\n", config);
- DBG_ASSERT(config == 1);
- UsbErr rc = controlSend(
- USB_HOST_TO_DEVICE | USB_RECIPIENT_DEVICE, // 0x00
- SET_CONFIGURATION, config, 0, 0, 0);
- return rc;
-}
-
-UsbErr UsbDevice::controlSend(byte requestType, byte request, word value, word index, const byte* buf, int len)
-{
- UsbErr rc;
- fillControlBuf(requestType, request, value, index, len);
- DBG_ASSERT(m_pControlEp);
- m_pControlEp->setNextToken(TD_SETUP);
- rc = m_pControlEp->transfer(m_controlBuf, 8);
- while(m_pControlEp->status() == USBERR_PROCESSING);
- rc = (UsbErr) MIN(0, m_pControlEp->status());
- if(rc)
- return rc;
- if(len)
- {
- m_pControlEp->setNextToken(TD_OUT);
- rc = m_pControlEp->transfer((byte*)buf, len);
- while(m_pControlEp->status() == USBERR_PROCESSING);
- rc = (UsbErr) MIN(0, m_pControlEp->status());
- if(rc)
- return rc;
- }
- m_pControlEp->setNextToken(TD_IN);
- rc = m_pControlEp->transfer(NULL, 0);
- while(m_pControlEp->status() == USBERR_PROCESSING);
- rc = (UsbErr) MIN(0, m_pControlEp->status());
- if(rc)
- return rc;
- return USBERR_OK;
-}
-
-UsbErr UsbDevice::controlReceive(byte requestType, byte request, word value, word index, const byte* buf, int len)
-{
- DBG("buf=%p len=%d\n", buf, len);
- UsbErr rc;
- fillControlBuf(requestType, request, value, index, len);
- DBG_ASSERT(m_pControlEp);
- m_pControlEp->setNextToken(TD_SETUP);
- rc = m_pControlEp->transfer(m_controlBuf, 8);
- while(m_pControlEp->status() == USBERR_PROCESSING);
- rc = (UsbErr) MIN(0, m_pControlEp->status());
- if(rc)
- return rc;
- if(len)
- {
- m_pControlEp->setNextToken(TD_IN);
- rc = m_pControlEp->transfer( (byte*) buf, len);
- while(m_pControlEp->status() == USBERR_PROCESSING);
- rc = (UsbErr) MIN(0, m_pControlEp->status());
- if(rc)
- return rc;
- }
- m_pControlEp->setNextToken(TD_OUT);
- rc = m_pControlEp->transfer(NULL, 0);
- while(m_pControlEp->status() == USBERR_PROCESSING);
- rc = (UsbErr) MIN(0, m_pControlEp->status());
- if(rc)
- return rc;
- return USBERR_OK;
-}
-
-UsbErr UsbDevice::GetDescriptor(int type, int index, const byte* buf, int len)
-{
- DBG("type=%02X\n", type);
- return controlReceive(
- USB_DEVICE_TO_HOST | USB_RECIPIENT_DEVICE, GET_DESCRIPTOR,
- (type << 8) |(index), 0, buf, len);
-
-}
-
-UsbErr UsbDevice::GetString(int index, char* buf, int len)
-{
- DBG("index=%d buf=%p len=%d\n", index, buf, len);
- DBG_ASSERT(index >= 1);
- uint8_t temp[4];
- UsbErr rc;
- rc = GetDescriptor(USB_DESCRIPTOR_TYPE_STRING, 0, temp, sizeof(temp));
- DBG_ASSERT(rc == USBERR_OK);
- DBG_BYTES("LANG_ID", temp, sizeof(temp));
- DBG_ASSERT(temp[0] == 4);
- DBG_ASSERT(temp[1] == 0x03);
-
- rc = GetDescriptor(USB_DESCRIPTOR_TYPE_STRING, index, temp, 2);
- DBG_ASSERT(rc == USBERR_OK);
- DBG_BYTES("length check", temp, 2);
- if (temp[0] == 0x00 && temp[1] == 0x00) { // for pl2303
- if (len > 0) {
- strcpy(buf, "");
- }
- return rc;
- }
- DBG_ASSERT(temp[1] == 0x03);
- int temp_len = temp[0];
-
- uint8_t* temp_buf = new uint8_t[temp_len];
- DBG_ASSERT(temp_buf);
- rc = GetDescriptor(USB_DESCRIPTOR_TYPE_STRING, index, temp_buf, temp_len);
- DBG_ASSERT(rc == USBERR_OK);
- temp_len = temp_buf[0];
- DBG_HEX(temp_buf, temp_len);
- int i = 0;
- for(int pos = 2; pos < temp_len; pos+= 2) {
- buf[i++] = temp_buf[pos];
- DBG_ASSERT(i < len-1);
- }
- buf[i] = '\0';
- delete[] temp_buf;
- return rc;
-}
-
-UsbErr UsbDevice::SetInterfaceAlternate(int interface, int alternate)
-{
- UsbErr rc = controlSend(
- USB_HOST_TO_DEVICE | USB_RECIPIENT_INTERFACE,
- SET_INTERFACE, alternate, interface, NULL, 0);
- return rc;
-}
-
-void UsbDevice::fillControlBuf(byte requestType, byte request, word value, word index, int len)
-{
-#ifdef __BIG_ENDIAN
- #error "Must implement BE to LE conv here"
-#endif
- m_controlBuf[0] = requestType;
- m_controlBuf[1] = request;
- //We are in LE so it's fine
- *((word*)&m_controlBuf[2]) = value;
- *((word*)&m_controlBuf[4]) = index;
- *((word*)&m_controlBuf[6]) = (word) len;
-}
-
-
--- a/usb/UsbDevice.h Wed Jun 06 11:47:06 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,99 +0,0 @@
-
-/*
-Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-#ifndef USB_DEVICE_H
-#define USB_DEVICE_H
-
-#include "mbed.h"
-#include "UsbInc.h"
-#include "UsbEndpoint.h"
-#include "UsbHostMgr.h"
-
-class UsbHostMgr;
-class UsbEndpoint;
-
-class UsbDevice
-{
-protected:
- UsbDevice( UsbHostMgr* pMgr, int hub, int port, int addr );
- ~UsbDevice();
-
- UsbErr enumerate();
-
-public:
- bool connected();
- bool enumerated();
-
- int getPid();
- int getVid();
-
- //UsbErr getConfigurationDescriptor(int config, uint8_t** pBuf);
- //UsbErr getInterfaceDescriptor(int config, int item, uint8_t** pBuf);
-
- UsbErr setConfiguration(int config);
-
- UsbErr controlSend(byte requestType, byte request, word value, word index, const byte* buf, int len);
- UsbErr controlReceive(byte requestType, byte request, word value, word index, const byte* buf, int len);
- UsbErr GetDescriptor(int type, int index, const byte* buf, int len);
- UsbErr GetString(int index, char* buf, int len);
- UsbErr SetInterfaceAlternate(int interface, int alternate);
-
- uint8_t m_DeviceClass;
- uint8_t m_InterfaceClass;
-
-protected:
- void fillControlBuf(byte requestType, byte request, word value, word index, int len);
-private:
- friend class UsbEndpoint;
- friend class UsbHostMgr;
-
- UsbEndpoint* m_pControlEp;
-
- UsbHostMgr* m_pMgr;
-
- bool m_connected;
- bool m_enumerated;
-
- int m_hub;
- int m_port;
- int m_addr;
-
- int m_refs;
-
- uint16_t m_vid;
- uint16_t m_pid;
-
- byte m_controlBuf[8];//8
- //byte m_controlDataBuf[/*128*/256];
-
- UsbErr hub_init();
- UsbErr hub_poll();
- UsbErr hub_PortReset(int port);
- UsbErr SetPortFeature(int feature, int index);
- UsbErr ClearPortFeature(int feature, int index);
- UsbErr SetPortReset(int port);
- UsbErr GetPortStatus(int port, uint8_t* buf, int size);
- int m_hub_ports;
-};
-
-#endif
--- a/usb/UsbDevice2.cpp Wed Jun 06 11:47:06 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,133 +0,0 @@
-#include "UsbDevice.h"
-//#define __DEBUG
-#include "mydbg.h"
-
-#define PORT_RESET 4
-#define PORT_POWER 8
-#define C_PORT_CONNECTION 16
-#define C_PORT_RESET 20
-
-UsbErr UsbDevice::hub_init()
-{
- UsbErr rc;
- uint8_t buf[9];
- rc = controlReceive(
- USB_DEVICE_TO_HOST | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_DEVICE, // 0xa0
- GET_DESCRIPTOR,
- (USB_DESCRIPTOR_TYPE_HUB << 8), 0, buf, sizeof(buf));
- DBG_ASSERT(rc == USBERR_OK);
- DBG_ASSERT(buf[0] == 9);
- DBG_ASSERT(buf[1] == 0x29);
- DBG_BYTES("HUB DESCRIPTOR", buf, sizeof(buf));
-
- m_hub_ports = buf[2];
- VERBOSE("NbrPorts: %d\n", m_hub_ports);
- int PwrOn2PwrGood = buf[5];
- VERBOSE("PwrOn2PwrGood: %d %d ms\n", PwrOn2PwrGood, PwrOn2PwrGood*2);
- VERBOSE("HubContrCurrent: %d\n", buf[6]);
-
- rc = setConfiguration(1);
- DBG_ASSERT(rc == USBERR_OK);
-
- uint8_t status[4];
- rc = controlReceive(
- USB_DEVICE_TO_HOST | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_DEVICE, // 0xa0
- GET_STATUS,
- 0, 0, status, sizeof(status));
- DBG_ASSERT(rc == USBERR_OK);
- DBG_BYTES("HUB STATUS", status, sizeof(status));
-
- for(int i = 1; i <= m_hub_ports; i++) {
- rc = SetPortFeature(PORT_POWER, i);
- DBG("PORT_POWER port=%d rc=%d\n", i, rc);
- DBG_ASSERT(rc == USBERR_OK);
- if (rc != USBERR_OK) {
- return rc;
- }
- }
- wait_ms(PwrOn2PwrGood*2);
-
- m_enumerated = true;
- return USBERR_OK;
-}
-
-UsbErr UsbDevice::hub_poll()
-{
- DBG("%p m_hub=%d m_port=%d m_addr=%d\n", this, m_hub, m_port, m_addr);
- // check status
- for(int port = 1; port <= m_hub_ports; port++) {
- uint8_t status[4];
- UsbErr rc = GetPortStatus(port, status, sizeof(status));
- DBG_ASSERT(rc == USBERR_OK);
- DBG("port=%d\n", port);
- DBG_BYTES("STATUS", status, sizeof(status));
- if (status[2] & 0x01) { // Connect Status Change, has changed
- DBG_ASSERT(status[0] & 0x01);
- ClearPortFeature(C_PORT_CONNECTION, port);
- DBG_ASSERT(m_pMgr);
- m_pMgr->onUsbDeviceConnected(m_addr, port);
- return USBERR_PROCESSING;
- }
- }
- return USBERR_OK;
-}
-
-UsbErr UsbDevice::hub_PortReset(int port)
-{
- DBG("%p port=%d\n", this, port);
- DBG_ASSERT(port >= 1);
- SetPortReset(port);
- // wait reset
- for(int i = 0; i < 100; i++) {
- uint8_t status[4];
- UsbErr rc = GetPortStatus(port, status, sizeof(status));
- DBG_ASSERT(rc == USBERR_OK);
- DBG_BYTES("RESET", status, sizeof(status));
- if (status[2] & 0x10) { // Reset change , Reset complete
- return USBERR_OK;
- }
- wait_ms(5);
- }
- return USBERR_ERROR;
-}
-
-UsbErr UsbDevice::SetPortFeature(int feature, int index)
-{
- //DBG("feature=%d index=%d\n", feature, index);
- UsbErr rc;
- rc = controlSend(
- USB_HOST_TO_DEVICE | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_OTHER,
- SET_FEATURE, feature, index, 0, 0);
- return rc;
-}
-
-UsbErr UsbDevice::ClearPortFeature(int feature, int index)
-{
- UsbErr rc;
- rc = controlSend(
- USB_HOST_TO_DEVICE | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_OTHER,
- CLEAR_FEATURE, feature, index, 0, 0);
- return rc;
-}
-
-UsbErr UsbDevice::SetPortReset(int port)
-{
- //DBG("port=%d\n", port);
- UsbErr rc = SetPortFeature(PORT_RESET, port);
- DBG_ASSERT(rc == USBERR_OK);
- return rc;
-}
-
-UsbErr UsbDevice::GetPortStatus(int port, uint8_t* buf, int size)
-{
- DBG_ASSERT(size == 4);
- UsbErr rc;
- //return USBControlTransfer(device,
- //DEVICE_TO_HOST | REQUEST_TYPE_CLASS | RECIPIENT_OTHER,
- //GET_STATUS,0,port,(u8*)status,4);
-
- rc = controlReceive(
- USB_DEVICE_TO_HOST | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_OTHER,
- GET_STATUS, 0, port, buf, sizeof(buf));
- return rc;
-}
\ No newline at end of file
--- a/usb/UsbEndpoint.cpp Wed Jun 06 11:47:06 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,373 +0,0 @@
-
-/*
-Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-#include "UsbEndpoint.h"
-#include "UsbDevice.h"
-#include "usb_mem.h"
-#include "Usb_td.h"
-#include "netCfg.h"
-#if NET_USB
-
-//#define __DEBUG
-//#define __DEBUG3
-//#include "dbg/dbg.h"
-#include "mydbg.h"
-
-UsbEndpoint::UsbEndpoint( UsbDevice* pDevice, uint8_t ep, bool dir, UsbEndpointType type, uint16_t size, int addr /*= -1*/ )
-: m_pDevice(pDevice), m_result(true), m_status((int)USBERR_OK), m_len(0), m_pBufStartPtr(NULL),
- m_pCbItem(NULL), m_pCbMeth(NULL)
-{
- if (type == USB_ISO) {
- UsbEndpoint_iso(pDevice, ep, dir, type, size, addr);
- return;
- }
-
- m_pEd = (volatile HCED*)usb_get_ed();
- DBG_ASSERT(m_pEd);
- memset((void*)m_pEd, 0, sizeof(HCED));
-
- m_pTdHead = (volatile HCTD*)usb_get_td((uint32_t)this);
- DBG_ASSERT(m_pTdHead);
- m_pTdTail = (volatile HCTD*)usb_get_td((uint32_t)this);
- DBG_ASSERT(m_pTdTail);
- DBG("m_pEd =%p\n", m_pEd);
- DBG("m_pTdHead=%p\n", m_pTdHead);
- DBG("m_pTdTail=%p\n", m_pTdTail);
-
- if(addr == -1)
- addr = pDevice->m_addr;
-
- //Setup Ed
- //printf("\r\n--Ep Setup--\r\n");
- m_pEd->Control = addr | /* USB address */
- ((ep & 0x7F) << 7) | /* Endpoint address */
- (type!=USB_CONTROL?((dir?2:1) << 11):0) | /* direction : Out = 1, 2 = In */
- (size << 16); /* MaxPkt Size */
- DBG3("m_pEd->Control=%08X\n", m_pEd->Control);
- m_dir = dir;
- m_setup = false;
- m_type = type;
-
- m_pEd->TailTd = m_pEd->HeadTd = (uint32_t) m_pTdTail; //Empty TD list
-
- DBG("Before link\n");
-
- //printf("\r\n--Ep Reg--\r\n");
- //Append Ed to Ed list
- HCCA* hcca;
- //volatile HCED* nextEd;
- DBG("m_type=%d\n", m_type);
- switch( m_type )
- {
- case USB_CONTROL:
- m_pEd->Next = LPC_USB->HcControlHeadED;
- LPC_USB->HcControlHeadED = (uint32_t)m_pEd;
- return;
-
- case USB_BULK:
- m_pEd->Next = LPC_USB->HcBulkHeadED;
- LPC_USB->HcBulkHeadED = (uint32_t)m_pEd;
- return;
-
- case USB_INT:
- hcca = (HCCA*)usb_get_hcca();
- m_pEd->Next = hcca->IntTable[0];
- hcca->IntTable[0] = (uint32_t)m_pEd;
- return;
-
- default:
- DBG_ASSERT(0);
- }
-}
-
-
-UsbEndpoint::~UsbEndpoint()
-{
- DBG_ASSERT(0);
-
- m_pEd->Control |= ED_SKIP; //Skip this Ep in queue
-
- //Remove from queue
- volatile HCED* prevEd;
- HCCA* hcca;
- switch( m_type )
- {
- case USB_CONTROL:
- prevEd = (volatile HCED*) LPC_USB->HcControlHeadED;
- break;
- case USB_BULK:
- prevEd = (volatile HCED*) LPC_USB->HcBulkHeadED;
- break;
- case USB_INT:
- hcca = (HCCA*)usb_get_hcca();
- prevEd = (volatile HCED*)hcca->IntTable[0];
- break;
- default:
- DBG_ASSERT(0);
- }
- if( m_pEd == prevEd )
- {
- switch( m_type )
- {
- case USB_CONTROL:
- LPC_USB->HcControlHeadED = m_pEd->Next;
- break;
- case USB_BULK:
- LPC_USB->HcBulkHeadED = m_pEd->Next;
- break;
- case USB_INT:
- hcca = (HCCA*)usb_get_hcca();
- hcca->IntTable[0] = m_pEd->Next;
- break;
- default:
- DBG_ASSERT(0);
- }
- LPC_USB->HcBulkHeadED = m_pEd->Next;
- }
- else
- {
- while( prevEd->Next != (uint32_t) m_pEd )
- {
- prevEd = (volatile HCED*) prevEd->Next;
- }
- prevEd->Next = m_pEd->Next;
- }
-
- //
- usb_free_ed((volatile byte*)m_pEd);
-
- usb_free_td((volatile byte*)m_pTdHead);
- usb_free_td((volatile byte*)m_pTdTail);
-}
-
-void UsbEndpoint::setNextToken(uint32_t token) //Only for control Eps
-{
- switch(token)
- {
- case TD_SETUP:
- m_dir = false;
- m_setup = true;
- break;
- case TD_IN:
- m_dir = true;
- m_setup = false;
- break;
- case TD_OUT:
- m_dir = false;
- m_setup = false;
- break;
- }
-}
-
-UsbErr UsbEndpoint::transfer(volatile uint8_t* buf, uint32_t len)
-{
- DBG("buf=%p\n", buf);
- if(!m_result)
- return USBERR_BUSY; //The previous trasnfer is not completed
- //FIXME: We should be able to queue the next transfer, still needs to be implemented
-
- if( !m_pDevice->connected() )
- return USBERR_DISCONNECTED;
-
- m_result = false;
-
- volatile uint32_t token = (m_setup?TD_SETUP:(m_dir?TD_IN:TD_OUT));
-
- volatile uint32_t td_toggle;
- if (m_type == USB_CONTROL)
- {
- if (m_setup)
- {
- td_toggle = TD_TOGGLE_0;
- }
- else
- {
- td_toggle = TD_TOGGLE_1;
- }
- }
- else
- {
- td_toggle = 0;
- }
-
- //Swap Tds
- volatile HCTD* pTdSwap;
- pTdSwap = m_pTdTail;
- m_pTdTail = m_pTdHead;
- m_pTdHead = pTdSwap;
-
- m_pTdHead->Control = (TD_ROUNDING |
- token |
- TD_DELAY_INT(0) |//7
- td_toggle |
- TD_CC);
-
- m_pTdTail->Control = 0;
- m_pTdHead->CurrBufPtr = (uint32_t) buf;
- m_pBufStartPtr = buf;
- m_pTdTail->CurrBufPtr = 0;
- m_pTdHead->Next = (uint32_t) m_pTdTail;
- m_pTdTail->Next = 0;
- m_pTdHead->BufEnd = (uint32_t)(buf + (len - 1));
- m_pTdTail->BufEnd = 0;
-
- m_pEd->HeadTd = (uint32_t)m_pTdHead | ((m_pEd->HeadTd) & 0x00000002); //Carry bit
- m_pEd->TailTd = (uint32_t)m_pTdTail;
-
- //DBG("m_pEd->HeadTd = %08x\n", m_pEd->HeadTd);
-
- if(m_type == USB_CONTROL) {
- LPC_USB->HcCommandStatus = LPC_USB->HcCommandStatus | OR_CMD_STATUS_CLF;
- LPC_USB->HcControl = LPC_USB->HcControl | OR_CONTROL_CLE; //Enable control list
- } else if (m_type == USB_BULK) { //USB_BULK
- LPC_USB->HcCommandStatus = LPC_USB->HcCommandStatus | OR_CMD_STATUS_BLF;
- LPC_USB->HcControl = LPC_USB->HcControl | OR_CONTROL_BLE; //Enable bulk list
- } else if (m_type == USB_INT) { // USB_INT
- LPC_USB->HcControl = LPC_USB->HcControl | OR_CONTROL_PLE; //Enable Periodic
- } else { // USB_ISO
- DBG_ASSERT(0);
- }
-
- //m_done = false;
- m_len = len;
-
- return USBERR_PROCESSING;
-
-}
-
-int UsbEndpoint::status()
-{
- if( !m_pDevice->connected() )
- {
- if(!m_result)
- onCompletion();
- m_result = true;
- return (int)USBERR_DISCONNECTED;
- }
- else if( !m_result )
- {
- return (int)USBERR_PROCESSING;
- }
- /*else if( m_done )
- {
- return (int)USBERR_OK;
- }*/
- else
- {
- return m_status;
- }
-}
-
-void UsbEndpoint::updateAddr(int addr)
-{
- DBG("m_pEd->Control = %08x\n", m_pEd->Control);
- m_pEd->Control &= ~0x7F;
- m_pEd->Control |= addr;
- DBG("m_pEd->Control = %08x\n", m_pEd->Control);
-}
-
-void UsbEndpoint::updateSize(uint16_t size)
-{
- DBG("m_pEd->Control = %08x\n", m_pEd->Control);
- m_pEd->Control &= ~0x3FF0000;
- m_pEd->Control |= (size << 16);
- DBG("m_pEd->Control = %08x\n", m_pEd->Control);
-}
-
-#if 0 //For doc only
-template <class T>
-void UsbEndpoint::setOnCompletion( T* pCbItem, void (T::*pCbMeth)() )
-{
- m_pCbItem = (CDummy*) pCbItem;
- m_pCbMeth = (void (CDummy::*)()) pCbMeth;
-}
-#endif
-
-void UsbEndpoint::onCompletion()
-{
- DBG_ASSERT(m_type != USB_ISO);
- DBG_ASSERT(m_pTdHead);
- //DBG("Transfer completed\n");
- if( m_pTdHead->Control >> 28 )
- {
- DBG("TD Failed with condition code %01x\n", m_pTdHead->Control >> 28 );
- m_status = (int)USBERR_TDFAIL;
- }
- else if( m_pEd->HeadTd & 0x1 )
- {
- m_pEd->HeadTd = m_pEd->HeadTd & ~0x1;
- DBG("\r\nHALTED!!\r\n");
- m_status = (int)USBERR_HALTED;
- }
- else if( (m_pEd->HeadTd & ~0xF) == (uint32_t) m_pTdTail )
- {
- //Done
- int len;
- DBG("m_pEp=%p\n", m_pEd);
- DBG("m_pTdHead->CurrBufPtr=%08x\n", (uint32_t)m_pTdHead->CurrBufPtr);
- DBG("m_pBufStartPtr=%08x\n", (uint32_t) m_pBufStartPtr);
- if(m_pTdHead->CurrBufPtr)
- len = m_pTdHead->CurrBufPtr - (uint32_t) m_pBufStartPtr;
- else
- len = m_len;
- /*if(len == 0) //Packet transfered completely
- len = m_len;*/
- //m_done = true;
- DBG("Transfered %d bytes\n", len);
- m_status = len;
- }
- else
- {
- DBG("Unknown error...\n");
- m_status = (int)USBERR_ERROR;
- }
- m_result = true;
- if(m_pCbItem && m_pCbMeth)
- (m_pCbItem->*m_pCbMeth)();
-}
-
-
-
-void UsbEndpoint::sOnCompletion(uint32_t pTd)
-{
- HCTD* td = td_reverse((HCTD*)pTd);
- while(td) {
- HCTD* next = (HCTD*)td->Next;
- HCUTD* utd = (HCUTD*)td;
- UsbEndpoint* pEp = (UsbEndpoint*)utd->UsbEndpoint;
- DBG_ASSERT(pEp);
- if (usb_is_itd((byte*)td)) {
- HCITD* itd = (HCITD*)td;
- DBG_ASSERT(pEp->m_type == USB_ISO);
- pEp->queue_done_itd.push(itd);
- } else {
- DBG_ASSERT(pEp->m_pTdHead == td);
- if(pEp->m_pTdHead == td) { // found?
- pEp->onCompletion();
- }
- }
- td = next;
- }
-}
-
-#endif
--- a/usb/UsbEndpoint.h Wed Jun 06 11:47:06 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,100 +0,0 @@
-
-/*
-Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-#ifndef USB_ENDPOINT_H
-#define USB_ENDPOINT_H
-
-#include "mbed.h"
-#include "UsbInc.h"
-#include "Usb_td.h"
-
-class UsbDevice;
-
-enum UsbEndpointType
-{
- USB_CONTROL,
- USB_BULK,
- USB_INT,
- USB_ISO
-};
-
-class UsbEndpoint
-{
-public:
- UsbEndpoint( UsbDevice* pDevice, uint8_t ep, bool dir, UsbEndpointType type, uint16_t size, int addr = -1 );
- ~UsbEndpoint();
- void UsbEndpoint_iso(UsbDevice* pDevice, uint8_t ep, bool dir, UsbEndpointType type, uint16_t size, int addr);
-
- void setNextToken(uint32_t token); //Only for control Eps
-
- UsbErr transfer(volatile uint8_t* buf, uint32_t len);
- UsbErr transfer(uint16_t frame, int count, volatile uint8_t* buf, int len); // for isochronous
- int m_itdActive;
- tdqueue <HCITD*> queue_done_itd;
- int status(); //return UsbErr or transfered len
-
- void updateAddr(int addr);
- void updateSize(uint16_t size);
-
- //void setOnCompletion( void(*pCb)completed() );
- class CDummy;
- template <class T>
- void setOnCompletion( T* pCbItem, void (T::*pCbMeth)() )
- {
- m_pCbItem = (CDummy*) pCbItem;
- m_pCbMeth = (void (CDummy::*)()) pCbMeth;
- }
-
-//static void completed(){}
-
-protected:
- void onCompletion();
-public:
- static void sOnCompletion(uint32_t pTd);
-
-private:
- friend class UsbDevice;
-
- UsbDevice* m_pDevice;
-
- bool m_dir;
- bool m_setup;
- UsbEndpointType m_type;
-
- //bool m_done;
- volatile bool m_result;
- volatile int m_status;
-
- volatile uint32_t m_len;
-
- volatile uint8_t* m_pBufStartPtr;
-
- volatile HCED* m_pEd; //Ep descriptor
-
- volatile HCTD* m_pTdHead; //Head trf descriptor
- volatile HCTD* m_pTdTail; //Tail trf descriptor
-
- CDummy* m_pCbItem;
- void (CDummy::*m_pCbMeth)();
-};
-#endif
--- a/usb/UsbEndpoint2.cpp Wed Jun 06 11:47:06 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,132 +0,0 @@
-/*
-Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-#include "UsbEndpoint.h"
-#include "UsbDevice.h"
-#include "usb_mem.h"
-
-//#define __DEBUG
-//#define __DEBUG3
-//#include "dbg/dbg.h"
-#include "mydbg.h"
-
-void UsbEndpoint::UsbEndpoint_iso(UsbDevice* pDevice, uint8_t ep, bool dir, UsbEndpointType type, uint16_t size, int addr)
-{
- m_itdActive = 0;
- m_pEd = (volatile HCED*)usb_get_ed();
- DBG_ASSERT(m_pEd);
- memset((void*)m_pEd, 0, sizeof(HCED));
-
- m_pTdHead = NULL;
- m_pTdTail = NULL;
-
- volatile HCTD* itd = (volatile HCTD*)usb_get_itd((uint32_t)this);
- DBG_ASSERT(itd);
- memset((void*)itd, 0, sizeof(HCITD));
- DBG3("m_pEd =%p\n", m_pEd);
- DBG3("itd =%p\n", itd);
-
- if(addr == -1)
- addr = pDevice->m_addr;
-
- //Setup Ed
- //printf("\r\n--Ep Setup--\r\n");
- m_pEd->Control = addr | /* USB address */
- ((ep & 0x7F) << 7) | /* Endpoint address */
- ((dir?2:1) << 11) | /* direction : Out = 1, 2 = In */
- (1 << 15) | /* F Format */
- (size << 16); /* MaxPkt Size */
-
- DBG3("m_pEd->Control=%08X\n", m_pEd->Control);
-
- m_dir = dir;
- m_setup = false;
- m_type = type;
-
- m_pEd->TailTd = m_pEd->HeadTd = (uint32_t)itd; //Empty TD list
-
- DBG("Before link\n");
-
- //printf("\r\n--Ep Reg--\r\n");
- //Append Ed to Ed list
- HCCA* hcca = (HCCA*)usb_get_hcca();
- for(int i = 0; i < 32; i++) {
- if (hcca->IntTable[i] == 0) {
- hcca->IntTable[i] = (uint32_t)m_pEd;
- } else {
- volatile HCED* nextEd = (volatile HCED*)hcca->IntTable[i];
- while(nextEd->Next && nextEd->Next != (uint32_t)m_pEd) {
- nextEd = (volatile HCED*)nextEd->Next;
- }
- nextEd->Next = (uint32_t)m_pEd;
- }
- }
-}
-
-// for isochronous
-UsbErr UsbEndpoint::transfer(uint16_t frame, int count, volatile uint8_t* buf, int len)
-{
- DBG_ASSERT(count >= 1 && count <= 8);
- DBG_ASSERT(buf);
- DBG_ASSERT((len % count) == 0);
- HCITD *itd = (HCITD*)m_pEd->TailTd;
- DBG_ASSERT(itd);
- HCITD *new_itd = (HCITD*)usb_get_itd((uint32_t)this);
- DBG_ASSERT(new_itd);
- if (itd == NULL) {
- return USBERR_ERROR;
- }
- DBG("itd=%p\n", itd);
- DBG2("new_itd=%p\n", new_itd);
- int di = 0; //DelayInterrupt
- itd->Control = 0xe0000000 | // CC ConditionCode NOT ACCESSED
- ((count-1) << 24) | // FC FrameCount
- TD_DELAY_INT(di) | // DI DelayInterrupt
- frame; // SF StartingFrame
- itd->BufferPage0 = (uint32_t)buf;
- itd->BufferEnd = (uint32_t)buf+len-1;
- itd->Next = (uint32_t)new_itd;
- uint16_t offset[8];
- for(int i = 0; i < 8; i++) {
- uint32_t addr = (uint32_t)buf + i*(len/count);
- offset[i] = addr & 0x0fff;
- if ((addr&0xfffff000) == (itd->BufferEnd&0xfffff000)) {
- offset[i] |= 0x1000;
- }
- offset[i] |= 0xe000;
- }
- itd->OffsetPSW10 = (offset[1]<<16) | offset[0];
- itd->OffsetPSW32 = (offset[3]<<16) | offset[2];
- itd->OffsetPSW54 = (offset[5]<<16) | offset[4];
- itd->OffsetPSW76 = (offset[7]<<16) | offset[6];
- m_itdActive++;
- DBG2("itd->Control =%08X\n", itd->Control);
- DBG2("itd->BufferPage0=%08X\n", itd->BufferPage0);
- DBG2("itd->Next =%08X\n", itd->Next);
- DBG2("itd->BufferEnd =%08X\n", itd->BufferEnd);
- DBG2("itd->OffsetPSW10=%08X\n", itd->OffsetPSW10);
- DBG2("itd->OffsetPSW32=%08X\n", itd->OffsetPSW32);
- DBG2("itd->OffsetPSW54=%08X\n", itd->OffsetPSW54);
- DBG2("itd->OffsetPSW76=%08X\n", itd->OffsetPSW76);
- m_pEd->TailTd = (uint32_t)new_itd; // start!!!
- LPC_USB->HcControl |= OR_CONTROL_PLE; //Enable Periodic
- return USBERR_PROCESSING;
-}
--- a/usb/UsbHostMgr.cpp Wed Jun 06 11:47:06 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,395 +0,0 @@
-
-/*
-Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-#include "UsbHostMgr.h"
-#include "usb_mem.h"
-#include "Usb_td.h"
-#include "string.h" //For memcpy, memmove, memset
-#include "netCfg.h"
-#if NET_USB
-//#define __DEBUG
-//#define __DEBUG3
-//#include "dbg/dbg.h"
-#include "mydbg.h"
-
-// bits of the USB/OTG clock control register
-#define HOST_CLK_EN (1<<0)
-#define DEV_CLK_EN (1<<1)
-#define PORTSEL_CLK_EN (1<<3)
-#define AHB_CLK_EN (1<<4)
-
-// bits of the USB/OTG clock status register
-#define HOST_CLK_ON (1<<0)
-#define DEV_CLK_ON (1<<1)
-#define PORTSEL_CLK_ON (1<<3)
-#define AHB_CLK_ON (1<<4)
-
-// we need host clock, OTG/portsel clock and AHB clock
-#define CLOCK_MASK (HOST_CLK_EN | PORTSEL_CLK_EN | AHB_CLK_EN)
-
-static UsbHostMgr* pMgr = NULL;
-
-extern "C" void sUsbIrqhandler(void) __irq
-{
- DBG("\n+Int\n");
- if(pMgr)
- pMgr->UsbIrqhandler();
- DBG("\n-Int\n");
- return;
-}
-
-UsbHostMgr::UsbHostMgr() : m_lpDevices()
-{
- /*if(!pMgr)*/ //Assume singleton
- pMgr = this;
- usb_mem_init();
- for(int i = 0; i < USB_HOSTMGR_MAX_DEVS; i++) {
- m_lpDevices[i] = NULL;
- }
- m_pHcca = (HCCA*) usb_get_hcca();
- memset((void*)m_pHcca, 0, 0x100);
- m_hardware_init = false;
- DBG("Host manager at %p\n", this);
-
- test_td(); // TD test program
-}
-
-UsbHostMgr::~UsbHostMgr()
-{
- if(pMgr == this)
- pMgr = NULL;
-}
-
-UsbErr UsbHostMgr::init() //Initialize host
-{
- DBG("m_hardware_init=%d\n", m_hardware_init);
- if(m_hardware_init) {
- return USBERR_OK;
- }
-
- NVIC_DisableIRQ(USB_IRQn); /* Disable the USB interrupt source */
-
- LPC_SC->PCONP &= ~(1UL<<31); //Cut power
- wait(1);
-
-
- // turn on power for USB
- LPC_SC->PCONP |= (1UL<<31);
- // Enable USB host clock, port selection and AHB clock
- LPC_USB->USBClkCtrl |= CLOCK_MASK;
- // Wait for clocks to become available
- while ((LPC_USB->USBClkSt & CLOCK_MASK) != CLOCK_MASK)
- ;
-
- // it seems the bits[0:1] mean the following
- // 0: U1=device, U2=host
- // 1: U1=host, U2=host
- // 2: reserved
- // 3: U1=host, U2=device
- // NB: this register is only available if OTG clock (aka "port select") is enabled!!
- // since we don't care about port 2, set just bit 0 to 1 (U1=host)
- LPC_USB->OTGStCtrl |= 1;
-
- // now that we've configured the ports, we can turn off the portsel clock
- LPC_USB->USBClkCtrl &= ~PORTSEL_CLK_EN;
-
- // power pins are not connected on mbed, so we can skip them
- /* P1[18] = USB_UP_LED, 01 */
- /* P1[19] = /USB_PPWR, 10 */
- /* P1[22] = USB_PWRD, 10 */
- /* P1[27] = /USB_OVRCR, 10 */
- /*LPC_PINCON->PINSEL3 &= ~((3<<4) | (3<<6) | (3<<12) | (3<<22));
- LPC_PINCON->PINSEL3 |= ((1<<4)|(2<<6) | (2<<12) | (2<<22)); // 0x00802080
- */
-
- // configure USB D+/D- pins
- /* P0[29] = USB_D+, 01 */
- /* P0[30] = USB_D-, 01 */
- LPC_PINCON->PINSEL1 &= ~((3<<26) | (3<<28));
- LPC_PINCON->PINSEL1 |= ((1<<26)|(1<<28)); // 0x14000000
-
- DBG("Initializing Host Stack\n");
-
- wait_ms(100); /* Wait 50 ms before apply reset */
- LPC_USB->HcControl = 0; /* HARDWARE RESET */
- LPC_USB->HcControlHeadED = 0; /* Initialize Control list head to Zero */
- LPC_USB->HcBulkHeadED = 0; /* Initialize Bulk list head to Zero */
-
- /* SOFTWARE RESET */
- LPC_USB->HcCommandStatus = OR_CMD_STATUS_HCR;
- LPC_USB->HcFmInterval = DEFAULT_FMINTERVAL; /* Write Fm Interval and Largest Data Packet Counter */
- LPC_USB->HcPeriodicStart = FI*90/100;
-
- /* Put HC in operational state */
- LPC_USB->HcControl = (LPC_USB->HcControl & (~OR_CONTROL_HCFS)) | OR_CONTROL_HC_OPER;
- LPC_USB->HcRhStatus = OR_RH_STATUS_LPSC; /* Set Global Power */
-
- LPC_USB->HcHCCA = (uint32_t)(m_pHcca);
- LPC_USB->HcInterruptStatus |= LPC_USB->HcInterruptStatus; /* Clear Interrrupt Status */
-
-
- LPC_USB->HcInterruptEnable = OR_INTR_ENABLE_MIE |
- OR_INTR_ENABLE_WDH |
- OR_INTR_ENABLE_RHSC;
-
- NVIC_SetPriority(USB_IRQn, 0); /* highest priority */
- /* Enable the USB Interrupt */
- NVIC_SetVector(USB_IRQn, (uint32_t)(sUsbIrqhandler));
- LPC_USB->HcRhPortStatus1 = OR_RH_PORT_CSC;
- LPC_USB->HcRhPortStatus1 = OR_RH_PORT_PRSC;
-
-
- /* Check for any connected devices */
- //if (LPC_USB->HcRhPortStatus1 & OR_RH_PORT_CCS) //Root device connected
- //{
- // //Device connected
- // wait(1);
- // DBG("Device connected (%08x)\n", LPC_USB->HcRhPortStatus1);
- // onUsbDeviceConnected(0, 1); //Hub 0 (root hub), Port 1 (count starts at 1)
- //}
-
- DBG("Enabling IRQ\n");
- NVIC_EnableIRQ(USB_IRQn);
- DBG("End of host stack initialization\n");
- m_hardware_init = true;
- return USBERR_OK;
-}
-
-UsbErr UsbHostMgr::poll() //Enumerate connected devices, etc
-{
- /* Check for any connected devices */
- if (LPC_USB->HcRhPortStatus1 & OR_RH_PORT_CCS) //Root device connected
- {
- //Device connected
- wait(1);
- DBG("Device connected (%08x)\n", LPC_USB->HcRhPortStatus1);
- onUsbDeviceConnected(0, 1); //Hub 0 (root hub), Port 1 (count starts at 1)
- }
-
- for(int i = 0; i < USB_HOSTMGR_MAX_DEVS; i++)
- {
- UsbDevice* dev = m_lpDevices[i];
- if (dev == NULL) {
- continue;
- }
- DBG3("%d dev=%p %d %d addr=%d\n", i, dev, dev->m_connected, dev->m_enumerated, dev->m_addr);
- if(dev->m_connected) {
- if (!dev->m_enumerated) {
- dev->enumerate();
- return USBERR_PROCESSING;
- }
- }
- }
- for(int i = 0; i < USB_HOSTMGR_MAX_DEVS; i++) {
- UsbDevice* dev = m_lpDevices[i];
- if (dev == NULL) {
- continue;
- }
- if (dev->m_connected && dev->m_enumerated) {
- if (dev->m_DeviceClass == 0x09) { // HUB
- UsbErr rc = dev->hub_poll();
- if (rc == USBERR_PROCESSING) {
- return USBERR_PROCESSING;
- }
- }
- }
- }
- return USBERR_OK;
-}
-
-int UsbHostMgr::devicesCount()
-{
- int i;
- for(i = 0; i < USB_HOSTMGR_MAX_DEVS; i++)
- {
- if (m_lpDevices[i] == NULL) {
- return i;
- }
- }
- return i;
-}
-
-UsbDevice* UsbHostMgr::getDevice(int item)
-{
- UsbDevice* pDev = m_lpDevices[item];
- if(!pDev)
- return NULL;
-
- pDev->m_refs++;
- return pDev;
-}
-
-void UsbHostMgr::releaseDevice(UsbDevice* pDev)
-{
- DBG_ASSERT(0);
-
- pDev->m_refs--;
- if(pDev->m_refs > 0)
- return;
- //If refs count = 0, delete
- //Find & remove from list
- int i;
- for(i = 0; i < USB_HOSTMGR_MAX_DEVS; i++)
- {
- if (m_lpDevices[i] == pDev)
- break;
- }
- if(i!=USB_HOSTMGR_MAX_DEVS)
- memmove(&m_lpDevices[i], &m_lpDevices[i+1], sizeof(UsbDevice*) * (USB_HOSTMGR_MAX_DEVS - (i + 1))); //Safer than memcpy because of overlapping mem
- m_lpDevices[USB_HOSTMGR_MAX_DEVS - 1] = NULL;
- delete pDev;
-}
-
-void UsbHostMgr::UsbIrqhandler()
-{
- uint32_t int_status;
- uint32_t ie_status;
-
- int_status = LPC_USB->HcInterruptStatus; /* Read Interrupt Status */
- ie_status = LPC_USB->HcInterruptEnable; /* Read Interrupt enable status */
-
- if (!(int_status & ie_status))
- {
- return;
- }
- else
- {
- int_status = int_status & ie_status;
- if (int_status & OR_INTR_STATUS_RHSC) /* Root hub status change interrupt */
- {
- DBG("LPC_USB->HcRhPortStatus1 = %08x\n", LPC_USB->HcRhPortStatus1);
- if (LPC_USB->HcRhPortStatus1 & OR_RH_PORT_CSC)
- {
- if (LPC_USB->HcRhStatus & OR_RH_STATUS_DRWE)
- {
- /*
- * When DRWE is on, Connect Status Change
- * means a remote wakeup event.
- */
- //HOST_RhscIntr = 1;// JUST SOMETHING FOR A BREAKPOINT
- }
- else
- {
- /*
- * When DRWE is off, Connect Status Change
- * is NOT a remote wakeup event
- */
- if (LPC_USB->HcRhPortStatus1 & OR_RH_PORT_CCS) //Root device connected
- {
- //Device connected
- DBG("Device connected (%08x)\n", LPC_USB->HcRhPortStatus1);
- onUsbDeviceConnected(0, 1); //Hub 0 (root hub), Port 1 (count starts at 1)
- }
- else //Root device disconnected
- {
- //Device disconnected
- DBG("Device disconnected\n");
- onUsbDeviceDisconnected(0, 1);
- }
- //TODO: HUBS
- }
- LPC_USB->HcRhPortStatus1 = OR_RH_PORT_CSC;
- }
- if (LPC_USB->HcRhPortStatus1 & OR_RH_PORT_PRSC)
- {
- LPC_USB->HcRhPortStatus1 = OR_RH_PORT_PRSC;
- }
- }
- if (int_status & OR_INTR_STATUS_WDH) /* Writeback Done Head interrupt */
- {
- //UsbEndpoint::sOnCompletion((LPC_USB->HccaDoneHead) & 0xFE);
- if(m_pHcca->DoneHead)
- {
- UsbEndpoint::sOnCompletion(m_pHcca->DoneHead);
- m_pHcca->DoneHead = 0;
- LPC_USB->HcInterruptStatus = OR_INTR_STATUS_WDH;
- if(m_pHcca->DoneHead)
- DBG("??????????????????????????????\n\n\n");
- }
- else
- {
- //Probably an error
- int_status = LPC_USB->HcInterruptStatus;
- DBG("HcInterruptStatus = %08x\n", int_status);
- if (int_status & OR_INTR_STATUS_UE) //Unrecoverable error, disconnect devices and resume
- {
- onUsbDeviceDisconnected(0, 1);
- LPC_USB->HcInterruptStatus = OR_INTR_STATUS_UE;
- LPC_USB->HcCommandStatus = 0x01; //Host Controller Reset
- }
- }
- }
- LPC_USB->HcInterruptStatus = int_status; /* Clear interrupt status register */
- }
- return;
-}
-
-void UsbHostMgr::onUsbDeviceDisconnected(int hub, int port)
-{
- for(int i = 0; i < devicesCount(); i++)
- {
- if( (m_lpDevices[i]->m_hub == hub)
- && (m_lpDevices[i]->m_port == port) )
- {
- m_lpDevices[i]->m_connected = false;
- if(!m_lpDevices[i]->m_enumerated)
- {
- delete m_lpDevices[i];
- m_lpDevices[i] = NULL;
- }
- return;
- }
- }
-}
-
-void UsbHostMgr::resetPort(int hub, int port)
-{
- DBG3("hub=%d port=%d\n", hub, port);
- if(hub == 0) //Root hub
- {
- wait_ms(100); /* USB 2.0 spec says at least 50ms delay before port reset */
- LPC_USB->HcRhPortStatus1 = OR_RH_PORT_PRS; // Initiate port reset
- DBG("Before loop\n");
- while (LPC_USB->HcRhPortStatus1 & OR_RH_PORT_PRS)
- ;
- LPC_USB->HcRhPortStatus1 = OR_RH_PORT_PRSC; // ...and clear port reset signal
- DBG("After loop\n");
- wait_ms(200); /* Wait for 100 MS after port reset */
- }
- else
- {
- for(int i = 0; i < USB_HOSTMGR_MAX_DEVS; i++) {
- UsbDevice* dev = m_lpDevices[i];
- if (dev == NULL) {
- continue;
- }
- if (dev->m_addr == hub) {
- DBG("%d dev=%p\n", i, dev);
- dev->hub_PortReset(port);
- return;
- }
- }
- DBG_ASSERT(0);
- }
-}
-
-#endif
--- a/usb/UsbHostMgr.h Wed Jun 06 11:47:06 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,69 +0,0 @@
-/*
-Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-//Assigns addresses to connected devices...
-
-#ifndef USB_HOSTMGR_H
-#define USB_HOSTMGR_H
-
-#include "mbed.h"
-#include "UsbInc.h"
-#include "UsbDevice.h"
-
-#define USB_HOSTMGR_MAX_DEVS 8
-
-class UsbDevice;
-
-class UsbHostMgr //[0-2] inst
-{
-public:
- UsbHostMgr();
- ~UsbHostMgr();
-
- UsbErr init(); //Initialize host
-
- UsbErr poll(); //Enumerate connected devices, etc
-
- int devicesCount();
-
- UsbDevice* getDevice(int item);
- UsbDevice* getDeviceByClass(uint8_t IfClass, int count = 0);
- void releaseDevice(UsbDevice* pDev);
-
-
- void UsbIrqhandler();
-
-protected:
- void onUsbDeviceConnected(int hub, int port);
- void onUsbDeviceDisconnected(int hub, int port);
-
- friend class UsbDevice;
- void resetPort(int hub, int port);
-
-private:
-/* __align(8)*/ volatile HCCA* m_pHcca;
-
- UsbDevice* m_lpDevices[USB_HOSTMGR_MAX_DEVS];
- bool m_hardware_init;
-};
-
-#endif
--- a/usb/UsbHostMgr2.cpp Wed Jun 06 11:47:06 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,51 +0,0 @@
-#include "UsbHostMgr.h"
-//#define __DEBUG
-#include "mydbg.h"
-
-UsbDevice* UsbHostMgr::getDeviceByClass(uint8_t IfClass, int count)
-{
- DBG("IfClass=%02X count=%d\n", IfClass, count);
- for(int i = 0; i < USB_HOSTMGR_MAX_DEVS; i++) {
- UsbDevice* dev = m_lpDevices[i];
- if (dev) {
- if(dev->m_connected && dev->m_enumerated) {
- if (dev->m_InterfaceClass == IfClass) { // found
- if (count-- <= 0) {
- return dev;
- }
- }
- }
- }
- }
- return NULL;
-}
-
-void UsbHostMgr::onUsbDeviceConnected(int hub, int port)
-{
- DBG("%p hub=%d port=%d\n", this, hub, port);
- for(int i = 0; i < USB_HOSTMGR_MAX_DEVS; i++) {
- UsbDevice* dev = m_lpDevices[i];
- if (dev) {
- if (dev->m_hub == hub && dev->m_port == port) { // skip
- return;
- }
- }
- }
-
- int item = devicesCount();
- DBG_ASSERT(item < USB_HOSTMGR_MAX_DEVS);
- if( item == USB_HOSTMGR_MAX_DEVS )
- return; //List full...
- //Find a free address (not optimized, but not really important)
- int addr = 1;
- for(int i = 0; i < item; i++)
- {
- DBG_ASSERT(m_lpDevices[i]);
- addr = MAX( addr, m_lpDevices[i]->m_addr + 1 );
- }
- DBG("item=%d addr=%d\n", item, addr);
- UsbDevice* dev = new UsbDevice( this, hub, port, addr );
- DBG_ASSERT(dev);
- dev->m_connected = true;
- m_lpDevices[item] = dev;
-}
--- a/usb/UsbInc.h Wed Jun 06 11:47:06 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,227 +0,0 @@
-
-/*
-Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-#ifndef USB_INC_H
-#define USB_INC_H
-
-#include "mbed.h"
-
-#define MIN(a,b) ((a)<(b)?(a):(b))
-#define MAX(a,b) ((a)>(b)?(a):(b))
-
-//typedef int32_t RC;
-
-typedef uint8_t byte;
-typedef uint16_t word;
-
-enum UsbErr
-{
- __USBERR_MIN = -0xFFFF,
- USBERR_DISCONNECTED,
- USBERR_NOTFOUND,
- USBERR_BADCONFIG,
- USBERR_PROCESSING,
- USBERR_HALTED, //Transfer on an ep is stalled
- USBERR_BUSY,
- USBERR_TDFAIL,
- USBERR_ERROR,
- USBERR_OK = 0
-};
-
-
-/* From NXP's USBHostLite stack's usbhost_lpc17xx.h */
-/* Only the types names have been changed to avoid unecessary typedefs */
-
-
-/*
-**************************************************************************************************************
-* NXP USB Host Stack
-*
-* (c) Copyright 2008, NXP SemiConductors
-* (c) Copyright 2008, OnChip Technologies LLC
-* All Rights Reserved
-*
-* www.nxp.com
-* www.onchiptech.com
-*
-* File : usbhost_lpc17xx.h
-* Programmer(s) : Ravikanth.P
-* Version :
-*
-**************************************************************************************************************
-*/
-
-
-
-/*
-**************************************************************************************************************
-* OHCI OPERATIONAL REGISTER FIELD DEFINITIONS
-**************************************************************************************************************
-*/
-
- /* ------------------ HcControl Register --------------------- */
-#define OR_CONTROL_PLE 0x00000004
-#define OR_CONTROL_IE 0x00000008
-#define OR_CONTROL_CLE 0x00000010
-#define OR_CONTROL_BLE 0x00000020
-#define OR_CONTROL_HCFS 0x000000C0
-#define OR_CONTROL_HC_OPER 0x00000080
- /* ----------------- HcCommandStatus Register ----------------- */
-#define OR_CMD_STATUS_HCR 0x00000001
-#define OR_CMD_STATUS_CLF 0x00000002
-#define OR_CMD_STATUS_BLF 0x00000004
- /* --------------- HcInterruptStatus Register ----------------- */
-#define OR_INTR_STATUS_WDH 0x00000002
-#define OR_INTR_STATUS_RHSC 0x00000040
-#define OR_INTR_STATUS_UE 0x00000010
- /* --------------- HcInterruptEnable Register ----------------- */
-#define OR_INTR_ENABLE_WDH 0x00000002
-#define OR_INTR_ENABLE_RHSC 0x00000040
-#define OR_INTR_ENABLE_MIE 0x80000000
- /* ---------------- HcRhDescriptorA Register ------------------ */
-#define OR_RH_STATUS_LPSC 0x00010000
-#define OR_RH_STATUS_DRWE 0x00008000
- /* -------------- HcRhPortStatus[1:NDP] Register -------------- */
-#define OR_RH_PORT_CCS 0x00000001
-#define OR_RH_PORT_PRS 0x00000010
-#define OR_RH_PORT_CSC 0x00010000
-#define OR_RH_PORT_PRSC 0x00100000
-
-
-/*
-**************************************************************************************************************
-* FRAME INTERVAL
-**************************************************************************************************************
-*/
-
-#define FI 0x2EDF /* 12000 bits per frame (-1) */
-#define DEFAULT_FMINTERVAL ((((6 * (FI - 210)) / 7) << 16) | FI)
-
-/*
-**************************************************************************************************************
-* ENDPOINT DESCRIPTOR CONTROL FIELDS
-**************************************************************************************************************
-*/
-
-#define ED_SKIP (uint32_t) (0x00001000) /* Skip this ep in queue */
-
-/*
-**************************************************************************************************************
-* TRANSFER DESCRIPTOR CONTROL FIELDS
-**************************************************************************************************************
-*/
-
-#define TD_ROUNDING (uint32_t) (0x00040000) /* Buffer Rounding */
-#define TD_SETUP (uint32_t)(0) /* Direction of Setup Packet */
-#define TD_IN (uint32_t)(0x00100000) /* Direction In */
-#define TD_OUT (uint32_t)(0x00080000) /* Direction Out */
-#define TD_DELAY_INT(x) (uint32_t)((x) << 21) /* Delay Interrupt */
-#define TD_TOGGLE_0 (uint32_t)(0x02000000) /* Toggle 0 */
-#define TD_TOGGLE_1 (uint32_t)(0x03000000) /* Toggle 1 */
-#define TD_CC (uint32_t)(0xF0000000) /* Completion Code */
-
-#define ITD_SF (uint32_t)(0x0000FFFF) /* Starting Frame */
-#define ITD_FC (uint32_t)(0x07000000) /* FrameCount */
-
-/*
-**************************************************************************************************************
-* USB STANDARD REQUEST DEFINITIONS
-**************************************************************************************************************
-*/
-
-#define USB_DESCRIPTOR_TYPE_DEVICE 1
-#define USB_DESCRIPTOR_TYPE_CONFIGURATION 2
-#define USB_DESCRIPTOR_TYPE_STRING 3
-#define USB_DESCRIPTOR_TYPE_INTERFACE 4
-#define USB_DESCRIPTOR_TYPE_ENDPOINT 5
-#define USB_DESCRIPTOR_TYPE_HUB 0x29
- /* ----------- Control RequestType Fields ----------- */
-#define USB_DEVICE_TO_HOST 0x80
-#define USB_HOST_TO_DEVICE 0x00
-#define USB_REQUEST_TYPE_CLASS 0x20
-#define USB_RECIPIENT_DEVICE 0x00
-#define USB_RECIPIENT_INTERFACE 0x01
-#define USB_RECIPIENT_OTHER 0x03
-
- /* -------------- USB Standard Requests -------------- */
-#define GET_STATUS 0
-#define CLEAR_FEATURE 1
-#define SET_FEATURE 3
-#define SET_ADDRESS 5
-#define GET_DESCRIPTOR 6
-#define SET_CONFIGURATION 9
-#define SET_INTERFACE 11
-
-/*
-**************************************************************************************************************
-* TYPE DEFINITIONS
-**************************************************************************************************************
-*/
-
-typedef struct hcEd { /* ----------- HostController EndPoint Descriptor ------------- */
- volatile uint32_t Control; /* Endpoint descriptor control */
- volatile uint32_t TailTd; /* Physical address of tail in Transfer descriptor list */
- volatile uint32_t HeadTd; /* Physcial address of head in Transfer descriptor list */
- volatile uint32_t Next; /* Physical address of next Endpoint descriptor */
-} HCED;
-
-typedef struct hcTd { /* ------------ HostController Transfer Descriptor ------------ */
- volatile uint32_t Control; /* Transfer descriptor control */
- volatile uint32_t CurrBufPtr; /* Physical address of current buffer pointer */
- volatile uint32_t Next; /* Physical pointer to next Transfer Descriptor */
- volatile uint32_t BufEnd; /* Physical address of end of buffer */
-} HCTD;
-
-typedef struct hcItd { // HostController Isochronous Transfer Descriptor
- volatile uint32_t Control; // Transfer descriptor control
- volatile uint32_t BufferPage0; // Buffer Page 0
- volatile uint32_t Next; // Physical pointer to next Transfer Descriptor
- volatile uint32_t BufferEnd; // buffer End
- volatile uint32_t OffsetPSW10; // Offset1/PSW1 Offset0/PSW0
- volatile uint32_t OffsetPSW32; // Offset3/PSW3 Offset2/PSW2
- volatile uint32_t OffsetPSW54; // Offset5/PSW5 Offset4/PSW4
- volatile uint32_t OffsetPSW76; // Offset7/PSW7 Offset6/PSW6
-} HCITD;
-
-typedef struct hcUtd {
- union {
- HCTD hctd;
- HCITD hcitd;
- };
- volatile uint32_t type; // 1:TD, 2:ITD
- volatile uint32_t UsbEndpoint;
- volatile uint32_t reserve1;
- volatile uint32_t reserve2;
-} HCUTD;
-
-typedef struct hcca { /* ----------- Host Controller Communication Area ------------ */
- volatile uint32_t IntTable[32]; /* Interrupt Table */
- volatile uint32_t FrameNumber; /* Frame Number */
- volatile uint32_t DoneHead; /* Done Head */
- volatile uint8_t Reserved[116]; /* Reserved for future use */
- volatile uint8_t Unknown[4]; /* Unused */
-} HCCA;
-
-
-
-#endif
--- a/usb/Usb_td.cpp Wed Jun 06 11:47:06 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,240 +0,0 @@
-#include "mbed.h"
-#include "Usb_td.h"
-//#define __DEBUG
-#include "mydbg.h"
-
-#define __TEST
-
-#ifdef __TEST
-#include <queue>
-#endif
-
-template class tdqueue<HCTD*>;
-template class tdqueue<HCITD*>;
-
-HCTD* td_reverse(HCTD* td)
-{
- HCTD* result = NULL;
- HCTD* next;
- while(td) {
- next = (HCTD*)td->Next;
- td->Next = (uint32_t)result;
- result = td;
- td = next;
- }
- return result;
-}
-
-template <class T>
-tdqueue<T>::tdqueue():m_head(NULL),m_tail(NULL)
-{
-
-}
-
-template <class T>
-int tdqueue<T>::size()
-{
- int n = 0;
- T td = m_head;
- while(td) {
- td = (T)td->Next;
- n++;
- }
- return n;
-}
-
-template <class T>
-bool tdqueue<T>::empty()
-{
- return (m_head == NULL);
-}
-
-template <class T>
-T tdqueue<T>::front()
-{
- return m_head;
-}
-
-template <class T>
-void tdqueue<T>::pop()
-{
- T td = m_head;
- if (td) {
- m_head = (T)td->Next;
- }
- if (td == m_tail) {
- m_tail = NULL;
- }
-}
-
-template <class T>
-void tdqueue<T>::push(T td)
-{
- td->Next = NULL;
- if (m_tail) {
- m_tail->Next = (uint32_t)td;
- }
- m_tail = td;
- if (m_head == NULL) {
- m_head = td;
- }
-}
-
-#ifdef __TEST
-static void test_td_list()
-{
- tdqueue<HCTD*> list;
- HCTD* td1;
- HCTD* td2;
- HCTD* td3;
- HCTD* td4;
- // 0
- DBG_ASSERT(list.size() == 0);
- td1 = list.front();
- DBG_ASSERT(td1 == NULL);
- list.pop();
- td1 = list.front();
- DBG_ASSERT(td1 == NULL);
- // 1
- td1 = (HCTD*)usb_get_td(1);
- list.push(td1);
- DBG_ASSERT(list.size() == 1);
- td2 = list.front();
- DBG_ASSERT(td2 == td1);
- list.pop();
- td2 = list.front();
- DBG_ASSERT(td2 == NULL);
- DBG_ASSERT(list.size() == 0);
- usb_free_td((byte*)td1);
- // 2
- td1 = (HCTD*)usb_get_td(1);
- td2 = (HCTD*)usb_get_td(2);
- list.push(td1);
- list.push(td2);
- DBG_ASSERT(list.size() == 2);
- td3 = list.front();
- DBG_ASSERT(td3 == td1);
- list.pop();
- td3 = list.front();
- DBG_ASSERT(td3 == td2);
- list.pop();
- td3 = list.front();
- DBG_ASSERT(td3 == NULL);
- usb_free_td((byte*)td1);
- usb_free_td((byte*)td2);
- // 3
- td1 = (HCTD*)usb_get_td(1);
- td2 = (HCTD*)usb_get_td(2);
- td3 = (HCTD*)usb_get_td(3);
- list.push(td1);
- list.push(td2);
- list.push(td3);
- DBG_ASSERT(list.size() == 3);
- td4 = list.front();
- DBG_ASSERT(td4 == td1);
- list.pop();
- td4 = list.front();
- DBG_ASSERT(td4 == td2);
- list.pop();
- td4 = list.front();
- DBG_ASSERT(td4 == td3);
- list.pop();
- td4 = list.front();
- DBG_ASSERT(td4 == NULL);
- usb_free_td((byte*)td1);
- usb_free_td((byte*)td2);
- usb_free_td((byte*)td3);
- // n
- queue<HCTD*> queue;
- for(int n = 1; n <= 10; n++) {
- DBG_ASSERT(list.size() == queue.size());
- DBG_ASSERT(list.empty() == queue.empty());
- if (list.empty() || (rand()%10) > 5) {
- td1 = (HCTD*)usb_get_td(n);
- if (td1) {
- list.push(td1);
- queue.push(td1);
- }
- //DBG("+ %d %p\n", n, td1);
- } else {
- td1 = list.front();
- td2 = queue.front();
- if (td1 != td2) {
- //DBG("td1=%p td2=%p\n", td1, td2);
- }
- DBG_ASSERT(td1 == td2);
- if (td1) {
- list.pop();
- queue.pop();
- usb_free_td((byte*)td1);
- }
- //DBG("- %d %p\n", n, td1);
- }
- }
- while(!list.empty()) {
- td1 = list.front();
- list.pop();
- usb_free_td((byte*)td1);
- }
- //DBG_ASSERT(0);
-}
-
-static void test_td_reverse()
-{
-
- HCTD* td1;
- HCTD* td2;
- HCTD* td3;
- HCTD* td4;
- // 0
- td1 = NULL;
- td2 = td_reverse(td1);
- DBG_ASSERT(td2 == NULL);
- // 1
- td1 = (HCTD*)usb_get_td(1);
- DBG_ASSERT(td1);
- DBG_ASSERT(td1->Next == NULL);
- td2 = td_reverse(td1);
- DBG_ASSERT(td2 == td1);
- DBG_ASSERT(td2->Next == NULL);
- usb_free_td((byte*)td1);
- // 2
- td1 = (HCTD*)usb_get_td(1);
- DBG_ASSERT(td1);
- td2 = (HCTD*)usb_get_td(2);
- DBG_ASSERT(td2);
- td1->Next = (uint32_t)td2;
- td3 = td_reverse(td1);
- DBG_ASSERT(td3 == td2);
- DBG_ASSERT(td3->Next == (uint32_t)td1);
- DBG_ASSERT(td1->Next == NULL);
- usb_free_td((byte*)td1);
- usb_free_td((byte*)td2);
- // 3
- td1 = (HCTD*)usb_get_td(1);
- td2 = (HCTD*)usb_get_td(2);
- td3 = (HCTD*)usb_get_td(3);
- td1->Next = (uint32_t)td2;
- td2->Next = (uint32_t)td3;
- td4 = td_reverse(td1);
- DBG_ASSERT(td4 == td3);
- DBG_ASSERT(td3->Next == (uint32_t)td2);
- DBG_ASSERT(td2->Next == (uint32_t)td1);
- DBG_ASSERT(td1->Next == NULL);
- usb_free_td((byte*)td1);
- usb_free_td((byte*)td2);
- usb_free_td((byte*)td3);
-}
-
-void test_td()
-{
- test_td_reverse();
- test_td_list();
- DBG("Usb_td.cpp TD test done.\n");
-}
-#else //__TEST
-void test_td()
-{
-
-}
-#endif //__TEST
\ No newline at end of file
--- a/usb/Usb_td.h Wed Jun 06 11:47:06 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,23 +0,0 @@
-#ifndef USB_TD_H
-#define USB_TD_H
-#include "UsbInc.h"
-#include "usb_mem.h"
-
-template <class T>
-class tdqueue {
-public:
- tdqueue();
- int size();
- bool empty();
- T front();
- void pop();
- void push(T td);
-private:
- T m_head;
- T m_tail;
-};
-
-HCTD* td_reverse(HCTD* td);
-void test_td();
-
-#endif //USB_TD_H
--- a/usb/mydbg.h Wed Jun 06 11:47:06 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,34 +0,0 @@
-#ifndef _MYDBG_H_
-#define _MYDBG_H_
-#ifdef __DEBUG
-#include "Utils.h"
-#define DBG(...) do{fprintf(stderr,"[%s@%d] ",__PRETTY_FUNCTION__,__LINE__);fprintf(stderr,__VA_ARGS__);} while(0);
-#define DBG2(...) do{fprintf(stderr,"[%d] ",__LINE__);fprintf(stderr,__VA_ARGS__);} while(0);
-#define DBG_BYTES(A,B,C) do{printf("[%s@%d] ",__PRETTY_FUNCTION__,__LINE__);printfBytes(A,B,C);}while(0);
-#define DBG_HEX(A,B) do{printf("[%s@%d]\n",__PRETTY_FUNCTION__,__LINE__);printHex(A,B);}while(0);
-#define DBG_LED4(A) led4.write(A)
-#define DBG_PRINTF(...) do{fprintf(stderr,__VA_ARGS__);} while(0);
-#else //__DEBUG
-#define DBG(...) while(0);
-#define DBG2(...) while(0);
-#define DBG_BYTES(A,B,C) while(0);
-#define DBG_HEX(A,B) while(0);
-#define DBG_LED4(A) while(0);
-#define DBG_PRINTF(...) while(0);
-#endif //__DEBUG
-#ifdef __DEBUG3
-#define DBG3(...) do{fprintf(stderr,"[%s@%d] ",__PRETTY_FUNCTION__,__LINE__);fprintf(stderr,__VA_ARGS__);} while(0);
-
-#else //__DEBUG3
-#define DBG3(...) while(0);
-#endif //__DEBUG3
-
-#ifndef __NODEBUG
-#define DBG_ASSERT(A) while(!(A)){fprintf(stderr,"\n\n%s@%d %s ASSERT!\n\n",__PRETTY_FUNCTION__,__LINE__,#A);exit(1);};
-#else
-#define DBG_ASSERT(A) while(0);
-#endif
-
-#define VERBOSE(...) do{printf(__VA_ARGS__);} while(0);
-
-#endif //_MYDBG_H_
--- a/usb/netCfg.h Wed Jun 06 11:47:06 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -#ifndef NET_CFG_H -#define NET_GPRS 1 -#define NET_PPP 1 -#define NET_GPRS_MODULE 1 -#define NET_ETH 1 -#define NET_USB_SERIAL 1 -#define NET_CFG_H 1 -#define NET_UMTS 1 -#define NET_USB 1 -#define NET_LWIP_STACK 1 -#endif
--- a/usb/usb_mem.c Wed Jun 06 11:47:06 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,260 +0,0 @@
-
-/*
-Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-#include "mbed.h"
-//#define __DEBUG
-#include "mydbg.h"
-#include "usb_mem.h"
-#include "string.h" //For memcpy, memmove, memset
-//#include "netCfg.h"
-#include "UsbInc.h"
-
-//#if NET_USB
-
-#define EDS_COUNT 16
-#define TDS_COUNT 0
-#define ITDS_COUNT 0
-#define UTDS_COUNT 32
-#define BPS_COUNT 8
-
-#define HCCA_SIZE 0x100
-#define ED_SIZE 0x10
-#define TD_SIZE 0x10
-#define ITD_SIZE 0x20
-#define UTD_SIZE (32+16)
-#define BP_SIZE (128*8)
-
-#define TOTAL_SIZE (HCCA_SIZE + (EDS_COUNT*ED_SIZE) + (TDS_COUNT*TD_SIZE) + (ITDS_COUNT*ITD_SIZE))
-
-static volatile __align(256) byte usb_buf[TOTAL_SIZE] __attribute((section("AHBSRAM0"),aligned)); //256 bytes aligned!
-static volatile __align(32) uint8_t usb_utdBuf[UTDS_COUNT*UTD_SIZE] __attribute((section("AHBSRAM0"),aligned));
-
-static volatile byte* usb_hcca; //256 bytes aligned!
-
-static volatile byte* usb_edBuf; //4 bytes aligned!
-
-static byte usb_edBufAlloc[EDS_COUNT] __attribute((section("AHBSRAM0"),aligned));
-static uint8_t usb_utdBufAlloc[UTDS_COUNT] __attribute((section("AHBSRAM0"),aligned));
-static uint8_t usb_bpBufAlloc[BPS_COUNT] __attribute((section("AHBSRAM0"),aligned));
-static uint8_t usb_bpBuf[BP_SIZE*BPS_COUNT] __attribute((section("AHBSRAM0"),aligned));
-
-static void utd_init()
-{
- DBG_ASSERT(sizeof(HCTD) == 16);
- DBG_ASSERT(sizeof(HCITD) == 32);
- DBG_ASSERT(sizeof(HCUTD) == 48);
-
- DBG_ASSERT(((uint32_t)usb_utdBuf % 16) == 0);
- DBG_ASSERT(((uint32_t)usb_utdBuf % 32) == 0);
-
- DBG_ASSERT((uint32_t)usb_utdBufAlloc >= 0x2007c000);
- DBG_ASSERT((uint32_t)&usb_utdBufAlloc[UTDS_COUNT] <= 0x2007ffff);
-
- DBG_ASSERT((uint32_t)usb_utdBuf >= 0x2007c000);
- DBG_ASSERT((uint32_t)&usb_utdBuf[UTD_SIZE*UTDS_COUNT] <= 0x2007cfff);
-
- memset(usb_utdBufAlloc, 0x00, UTDS_COUNT);
-}
-
-static void pb_init()
-{
- memset(usb_bpBufAlloc, 0x00, BPS_COUNT);
-
- DBG_ASSERT((uint32_t)usb_bpBufAlloc >= 0x2007c000);
- DBG_ASSERT((uint32_t)&usb_bpBufAlloc[BPS_COUNT] <= 0x2007ffff);
- DBG_ASSERT((uint32_t)usb_bpBuf >= 0x2007c000);
- DBG_ASSERT((uint32_t)(&usb_bpBuf[BP_SIZE*BPS_COUNT]) <= 0x2007ffff);
-}
-
-void usb_mem_init()
-{
- usb_hcca = usb_buf;
- usb_edBuf = usb_buf + HCCA_SIZE;
- memset(usb_edBufAlloc, 0, EDS_COUNT);
-
- utd_init();
- pb_init();
-
- DBG("--- Memory Map --- \n");
- DBG("usb_hcca =%p\n", usb_hcca);
- DBG("usb_edBuf =%p\n", usb_edBuf);
- DBG("usb_utdBuf =%p\n", usb_utdBuf);
- DBG("usb_edBufAlloc =%p\n", usb_edBufAlloc);
- DBG("usb_utdBufAlloc=%p\n", usb_utdBufAlloc);
- DBG("usb_bpBufAlloc =%p\n", usb_bpBufAlloc);
- DBG("usb_bpBuf =%p\n", usb_bpBuf);
- DBG(" =%p\n", &usb_bpBuf[BP_SIZE*BPS_COUNT]);
- DBG_ASSERT(((uint32_t)usb_hcca % 256) == 0);
- DBG_ASSERT(((uint32_t)usb_edBuf % 16) == 0);
- DBG_ASSERT(((uint32_t)usb_utdBuf % 32) == 0);
-}
-
-volatile byte* usb_get_hcca()
-{
- return usb_hcca;
-}
-
-volatile byte* usb_get_ed()
-{
- int i;
- for(i = 0; i < EDS_COUNT; i++)
- {
- if( !usb_edBufAlloc[i] )
- {
- usb_edBufAlloc[i] = 1;
- return usb_edBuf + i*ED_SIZE;
- }
- }
- return NULL; //Could not alloc ED
-}
-
-static uint8_t* usb_get_utd(int al)
-{
- DBG_ASSERT(al == 16 || al == 32); // GTD or ITD
- if (al == 16) {
- for(int i = 1; i < UTDS_COUNT; i += 2) {
- if (usb_utdBufAlloc[i] == 0) {
- uint32_t p = (uint32_t)usb_utdBuf + i * UTD_SIZE;
- if ((p % al) == 0) {
- usb_utdBufAlloc[i] = 1;
- DBG_ASSERT((p % al) == 0);
- return (uint8_t*)p;
- }
- }
- }
- }
- for(int i = 0; i < UTDS_COUNT; i++) {
- if (usb_utdBufAlloc[i] == 0) {
- uint32_t p = (uint32_t)usb_utdBuf + i * UTD_SIZE;
- if ((p % al) == 0) {
- usb_utdBufAlloc[i] = 1;
- DBG_ASSERT((p % al) == 0);
- return (uint8_t*)p;
- }
- }
- }
- return NULL;
-}
-
-volatile byte* usb_get_td(uint32_t endpoint)
-{
- DBG_ASSERT(endpoint);
- uint8_t* td = usb_get_utd(16);
- if (td) {
- HCUTD* utd = (HCUTD*)td;
- memset(utd, 0x00, sizeof(HCTD));
- utd->type = 1;
- utd->UsbEndpoint = endpoint;
- }
- return td;
-}
-
-volatile byte* usb_get_itd(uint32_t endpoint)
-{
- DBG_ASSERT(endpoint);
- uint8_t* itd = usb_get_utd(32);
- if (itd) {
- HCUTD* utd = (HCUTD*)itd;
- memset(utd, 0x00, sizeof(HCITD));
- utd->type = 2;
- utd->UsbEndpoint = endpoint;
- }
- return itd;
-}
-
-volatile byte* usb_get_bp(int size)
-{
- DBG_ASSERT(size >= 128 && size <= BP_SIZE);
- if (size > BP_SIZE) {
- return NULL;
- }
- for(int i = 0; i < BPS_COUNT; i++)
- {
- if( !usb_bpBufAlloc[i] )
- {
- usb_bpBufAlloc[i] = 1;
- return usb_bpBuf + i*BP_SIZE;
- }
- }
- return NULL; //Could not alloc Buffer Page
-}
-
-int usb_bp_size()
-{
- return BP_SIZE;
-}
-
-void usb_free_ed(volatile byte* ed)
-{
- int i;
- i = (ed - usb_edBuf) / ED_SIZE;
- usb_edBufAlloc[i] = 0;
-}
-
-static void usb_free_utd(volatile uint8_t* utd)
-{
- DBG_ASSERT(utd >= usb_utdBuf);
- DBG_ASSERT(utd <= (usb_utdBuf+UTD_SIZE*(UTDS_COUNT-1)));
- DBG_ASSERT(((uint32_t)utd % 16) == 0);
- int i = (utd - usb_utdBuf) / UTD_SIZE;
- DBG_ASSERT(usb_utdBufAlloc[i] == 1);
- usb_utdBufAlloc[i] = 0;
-}
-
-void usb_free_td(volatile byte* td)
-{
- usb_free_utd(td);
- return;
-}
-
-void usb_free_itd(volatile byte* itd)
-{
- usb_free_utd(itd);
- return;
-}
-
-void usb_free_bp(volatile byte* bp)
-{
- DBG_ASSERT(bp >= usb_bpBuf);
- int i;
- i = (bp - usb_bpBuf) / BP_SIZE;
- DBG_ASSERT(usb_bpBufAlloc[i] == 1);
- usb_bpBufAlloc[i] = 0;
-}
-
-bool usb_is_td(volatile byte* td)
-{
- DBG_ASSERT(td);
- HCUTD* utd = (HCUTD*)td;
- DBG_ASSERT(utd->type != 0);
- return utd->type == 1;
-}
-
-bool usb_is_itd(volatile byte* itd)
-{
- DBG_ASSERT(itd);
- HCUTD* utd = (HCUTD*)itd;
- DBG_ASSERT(utd->type != 0);
- return utd->type == 2;
-}
-
-//#endif
--- a/usb/usb_mem.h Wed Jun 06 11:47:06 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,59 +0,0 @@
-/*
-Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-#ifndef USB_MEM_H
-#define USB_MEM_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef unsigned char byte;
-
-void usb_mem_init();
-
-volatile byte* usb_get_hcca();
-
-volatile byte* usb_get_ed();
-
-volatile byte* usb_get_td(uint32_t endpoint);
-volatile byte* usb_get_itd(uint32_t endpoint);
-
-volatile byte* usb_get_bp(int size);
-int usb_bp_size();
-
-void usb_free_ed(volatile byte* ed);
-
-void usb_free_td(volatile byte* td);
-
-void usb_free_itd(volatile byte* itd);
-
-void usb_free_bp(volatile byte* bp);
-
-bool usb_is_td(volatile byte* td);
-bool usb_is_itd(volatile byte* td);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
--- a/uvc/Utils.cpp Wed Jun 06 11:47:06 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,48 +0,0 @@
-
-
-#include "mbed.h"
-#include "Utils.h"
-
-void printfBytes(const char* s, const u8* data, int len)
-{
- printf("%s %d:",s,len);
- if (len > 256)
- len = 256;
- while (len-- > 0)
- printf(" %02X",*data++);
- printf("\n");
-}
-
-void printHexLine(const u8* d, int addr, int len)
-{
- printf("%04X ",addr);
- int i;
- for (i = 0; i < len; i++)
- printf("%02X ",d[i]);
- for (;i < 16; i++)
- printf(" ");
- char s[16+1];
- memset(s,0,sizeof(s));
- for (i = 0; i < len; i++)
- {
- int c = d[i];
- if (c < 0x20 || c > 0x7E)
- c = '.';
- s[i] = c;
- }
- printf("%s\n",s);
-}
-
-void printHex(const u8* d, int len)
-{
- int addr = 0;
- while (len)
- {
- int count = len;
- if (count > 16)
- count = 16;
- printHexLine(d+addr,addr,count);
- addr += 16;
- len -= count;
- }
-}
--- a/uvc/Utils.h Wed Jun 06 11:47:06 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,48 +0,0 @@
-#ifndef UTILS_H
-#define UTILS_H
-typedef unsigned char u8;
-typedef unsigned short u16;
-typedef unsigned long u32;
-
-//void DelayMS(int ms);
-
-void printfBytes(const char* label,const u8* data, int len);
-void printHex(const u8* d, int len);
-
-#ifndef min
-#define min(_a,_b) ((_a) < (_b) ? (_a) : (_b))
-#endif
-
-inline int LE16(const u8* d)
-{
- return d[0] | (d[1] << 8);
-}
-
-
-inline int LE24(const uint8_t* d) {
- return d[0] | (d[1]<<8) | (d[2] << 16);
-}
-
-inline int LE32(const uint8_t* d) {
- return d[0] |(d[1]<<8) | (d[2] << 16) |(d[3] << 24) ;
-}
-
-inline u32 BE32(const u8* d)
-{
- return (d[0] << 24) | (d[1] << 16) | (d[2] << 8) | d[3];
-}
-
-inline void BE32(u32 n, u8* d)
-{
- d[0] = (u8)(n >> 24);
- d[1] = (u8)(n >> 16);
- d[2] = (u8)(n >> 8);
- d[3] = (u8)n;
-}
-
-inline void BE16(u32 n, u8* d)
-{
- d[0] = (u8)(n >> 8);
- d[1] = (u8)n;
-}
-#endif //UTILS_H
\ No newline at end of file
--- a/uvc/myjpeg.cpp Wed Jun 06 11:47:06 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,252 +0,0 @@
-#include "mbed.h"
-//#define __DEBUG
-#include "mydbg.h"
-#include "myjpeg.h"
-
-static const uint8_t dht[] = {
-0xFF,0xC4,0x01,0xA2,0x00,0x00,0x01,0x05,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,
-0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,
-0x0B,0x01,0x00,0x03,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,
-0x00,0x00,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x10,0x00,
-0x02,0x01,0x03,0x03,0x02,0x04,0x03,0x05,0x05,0x04,0x04,0x00,0x00,0x01,0x7D,0x01,
-0x02,0x03,0x00,0x04,0x11,0x05,0x12,0x21,0x31,0x41,0x06,0x13,0x51,0x61,0x07,0x22,
-0x71,0x14,0x32,0x81,0x91,0xA1,0x08,0x23,0x42,0xB1,0xC1,0x15,0x52,0xD1,0xF0,0x24,
-0x33,0x62,0x72,0x82,0x09,0x0A,0x16,0x17,0x18,0x19,0x1A,0x25,0x26,0x27,0x28,0x29,
-0x2A,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,
-0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,
-0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,
-0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,
-0xA9,0xAA,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xC2,0xC3,0xC4,0xC5,0xC6,
-0xC7,0xC8,0xC9,0xCA,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xE1,0xE2,0xE3,
-0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,
-0xFA,0x11,0x00,0x02,0x01,0x02,0x04,0x04,0x03,0x04,0x07,0x05,0x04,0x04,0x00,0x01,
-0x02,0x77,0x00,0x01,0x02,0x03,0x11,0x04,0x05,0x21,0x31,0x06,0x12,0x41,0x51,0x07,
-0x61,0x71,0x13,0x22,0x32,0x81,0x08,0x14,0x42,0x91,0xA1,0xB1,0xC1,0x09,0x23,0x33,
-0x52,0xF0,0x15,0x62,0x72,0xD1,0x0A,0x16,0x24,0x34,0xE1,0x25,0xF1,0x17,0x18,0x19,
-0x1A,0x26,0x27,0x28,0x29,0x2A,0x35,0x36,0x37,0x38,0x39,0x3A,0x43,0x44,0x45,0x46,
-0x47,0x48,0x49,0x4A,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x63,0x64,0x65,0x66,
-0x67,0x68,0x69,0x6A,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x82,0x83,0x84,0x85,
-0x86,0x87,0x88,0x89,0x8A,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0xA2,0xA3,
-0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,
-0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,
-0xD9,0xDA,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xF2,0xF3,0xF4,0xF5,0xF6,
-0xF7,0xF8,0xF9,0xFA,
-};
-
-myjpeg::myjpeg(uint8_t* buf, int len, int capacity)
-{
- DBG_ASSERT(buf);
- DBG_ASSERT(len >= 0);
- m_buf = buf;
- m_len = len;
- m_capacity = capacity;
-}
-
-int myjpeg::getc()
-{
- if (m_pos >= m_len) {
- return -1;
- }
- return m_buf[m_pos++];
-}
-
-int myjpeg::getBE16()
-{
- int c1 = getc();
- if (c1 == (-1)) {
- return -1;
- }
- int c2 = getc();
- if (c2 == (-1)) {
- return -1;
- }
- return c1<<8|c2;
-}
-
-void myjpeg::analytics()
-{
- m_pos = 0;
- SOS_pos = 0;
- DHT_pos = 0;
- int skip;
- int lp;
- while(1) {
- int marker_pos = m_pos;
- int c = getc();
- if (c == (-1)) {
- break;
- }
- if (c != 0xff) {
- continue;
- }
- c = getc();
- if (c == (-1)) {
- break;
- }
- uint8_t marker = c;
- switch(marker) {
- case 0xd8:
- DBG("%04X SOI\n", marker_pos);
- skip = 0;
- break;
- case 0xd9:
- DBG("%04X EOI\n", marker_pos);
- skip = 0;
- break;
- case 0x00:
- skip = 0;
- break;
- case 0xc0:
- lp = getBE16();
- DBG("%04X SOF0 %d\n", marker_pos, lp);
- skip = lp - 2;
- break;
- case 0xc4:
- lp = getBE16();
- DBG("%04X DHT Lh: %d\n", marker_pos, lp);
- //DBG("Tc: %d\n", buf[pos+2]>>4);
- //DBG("Th: %d\n", buf[pos+2]&0xf);
- DHT_pos = marker_pos;
- skip = lp - 2;
- break;
- case 0xda:
- lp = getBE16();
- DBG("%04X SOS Ls: %d\n", marker_pos, lp);
- //DBG("Ns: %d\n", buf[pos+2]);
- //for(i = 1; i <= buf[pos+2]; i++) {
- // DBG("Cs%d: %d\n", i, buf[pos+3+(i-1)*2]);
- // DBG("Td%d: %d\n", i, buf[pos+4+(i-1)*2]>>4);
- // DBG("Ta%d: %d\n", i, buf[pos+4+(i-1)*2]&0xf);
- //}
- SOS_pos = marker_pos;
- skip = lp - 2;
- break;
- case 0xdb:
- lp = getBE16();
- DBG("%04X DQT %d\n", marker_pos, lp);
- skip = lp - 2;
- break;
- case 0xe0:
- lp = getBE16();
- DBG("%04X APP0 %d\n", marker_pos, lp);
- skip = lp - 2;
- break;
- default:
- DBG("%04X ??? %02X\n", marker_pos, marker);
- skip = 0;
- break;
- }
- while(skip-- > 0) {
- getc();
- }
- }
-}
-
-int myjpeg::insertDHT()
-{
- DBG("m_len=%d m_capacity=%d SOS=%d\n", m_len, m_capacity, SOS_pos);
- DBG_ASSERT(SOS_pos > 0);
- DBG_ASSERT(SOS_pos < m_len);
- DBG_ASSERT(m_len <= m_capacity);
- DBG_ASSERT(sizeof(dht) == 420);
-
- int num1 = m_len - SOS_pos;
- if (num1 > (m_capacity - SOS_pos - sizeof(dht))) {
- num1 = m_capacity - SOS_pos - sizeof(dht);
- }
- DBG("num1=%d\n", num1);
- DBG_ASSERT(SOS_pos+sizeof(dht)+num1 <= m_capacity);
- memmove(m_buf+SOS_pos+sizeof(dht), m_buf+SOS_pos, num1);
-
- int num2 = sizeof(dht);
- if (num2 > m_capacity - SOS_pos) {
- num2 = m_capacity - SOS_pos;
- }
- DBG("num2=%d\n", num2);
- DBG_ASSERT(SOS_pos+num2 <= m_capacity);
- memcpy(m_buf+SOS_pos, dht, num2);
- m_len += sizeof(dht);
- if (m_len > m_capacity) {
- m_len = m_capacity;
- }
- return m_len;
-}
-
-int fgetBE16(FILE* fp)
-{
- int c1 = fgetc(fp);
- if (c1 == EOF) {
- return -1;
- }
- int c2 = fgetc(fp);
- if (c2 == EOF) {
- return -1;
- }
- return c1<<8|c2;
-}
-
-void QcamCopy(const char* destination, const char* source)
-{
- FILE* fp;
- FILE* fp2;
- fp = fopen(source, "rb");
- if (fp == NULL) {
- return;
- }
- fp2 = fopen(destination, "wb");
- if (fp2 == NULL) {
- return;
- }
- int i,c1,c2;
- bool f_dht = false;
- bool f_lp = false;
- while(!feof(fp)){
- c1 = fgetc(fp);
- if (c1 != 0xff) {
- fputc(c1, fp2);
- continue;
- }
- c2 = fgetc(fp);
- switch(c2) {
- case 0xda: // SOS
- if (!f_dht) {
- for(i = 0; i < sizeof(dht); i++) {
- fputc(dht[i], fp2);
- }
- f_dht = true;
- }
- f_lp = true;
- break;
- case 0xc4: // DHT
- f_dht = true;
- f_lp = true;
- break;
- case 0xc0:
- case 0xdb:
- case 0xe0:
- f_lp = true;
- break;
- default:
- f_lp = false;
- break;
- }
- fputc(c1, fp2);
- fputc(c2, fp2); // marker
- if (f_lp) {
- c1 = fgetc(fp); // length
- c2 = fgetc(fp);
- fputc(c1, fp2);
- fputc(c2, fp2);
- int skip = c1<<8|c2;
- while(skip-- > 2) {
- int c = fgetc(fp);
- if (c == EOF) {
- break;
- }
- fputc(c, fp2);
- }
- }
- }
- fclose(fp);
- fclose(fp2);
-}
--- a/uvc/myjpeg.h Wed Jun 06 11:47:06 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,21 +0,0 @@
-#ifndef MYJPEG_H
-#define MYJPEG_H
-class myjpeg {
-public:
- myjpeg(uint8_t* buf, int len, int capacity);
- void analytics();
- int insertDHT();
- int SOS_pos;
- int DHT_pos;
-private:
- int getc();
- int getBE16();
- uint8_t* m_buf;
- int m_len;
- int m_pos;
- int m_capacity;
-};
-
-void QcamCopy(const char* destination, const char* source);
-
-#endif //MYJPEG_H
\ No newline at end of file
--- a/uvc/stcamcfg.h Wed Jun 06 11:47:06 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-#ifndef STCAMCFG_H
-#define STCAMCFG_H
-struct stcamcfg {
- uint16_t idVender;
- uint16_t idProduct;
- uint16_t width;
- uint16_t height;
- uint8_t payload;
- uint8_t bEndpointAddress;
- uint16_t wMaxPacketSize;
- uint8_t FormatIndex;
- uint8_t FrameIndex;
- uint32_t dwFrameInterval;
- uint8_t bInterface;
- uint8_t bAlternate;
- char *name;
- int iso_FrameCount;
- int iso_itdCount;
- // work area
- int _If;
- int _Ifalt;
- int _IfClass;
- int _IfSubClass;
-};
-#endif //STCAMCFG_H
\ No newline at end of file
--- a/uvc/usb_itd.cpp Wed Jun 06 11:47:06 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,117 +0,0 @@
-#include "mbed.h"
-#include "usb_itd.h"
-#define __DEBUG
-#include "mydbg.h"
-
-usb_itd::usb_itd(HCITD* itd)
-{
- DBG_ASSERT(itd);
- m_itd = itd;
-}
-
-bool usb_itd::Done()
-{
- int cc = (m_itd->Control >> 28);
- if (cc == 0xe || cc == 0xf) { // not accessed?
- return false;
- }
- if (m_itd->Next) {
- return false;
- }
- return true;
-}
-
-int usb_itd::ConditionCode()
-{
- int cc = (m_itd->Control >> 28);
- return cc;
-}
-
-uint16_t usb_itd::get_psw(int n)
-{
- DBG_ASSERT(n >= 0 && n <= 7);
- DBG_ASSERT(m_itd);
- uint16_t psw = 0;
- switch(n) {
- case 0: psw = m_itd->OffsetPSW10; break;
- case 1: psw = m_itd->OffsetPSW10 >> 16; break;
- case 2: psw = m_itd->OffsetPSW32; break;
- case 3: psw = m_itd->OffsetPSW32 >> 16; break;
- case 4: psw = m_itd->OffsetPSW54; break;
- case 5: psw = m_itd->OffsetPSW54 >> 16; break;
- case 6: psw = m_itd->OffsetPSW76; break;
- case 7: psw = m_itd->OffsetPSW76 >> 16; break;
- }
- return psw;
-}
-
-uint16_t usb_itd::StartingFrame()
-{
- return (m_itd->Control & ITD_SF);
-}
-
-int usb_itd::FrameCount()
-{
- DBG_ASSERT(m_itd);
- int fc = ((m_itd->Control & ITD_FC) >> 24) + 1;
- DBG_ASSERT(fc >= 1 && fc <= 8);
- return fc;
-}
-
-int usb_itd::PacketStatus(int n)
-{
- DBG_ASSERT(n >=0 && n <= 7);
- uint16_t psw = get_psw(n);
- int cc = (psw >> 12) & 0xf;
- return cc;
-}
-
-int usb_itd::Length(int n)
-{
- DBG_ASSERT(n >=0 && n <= 7);
- uint16_t psw = get_psw(n);
- int size = psw & 0x7ff;
- int cc = (psw >> 12) & 0xf;
- if (cc == 0xe || cc == 0xf) {
- return -1;
- }
- if (cc == 0 || cc == 9) {
- return size;
- }
- debug();
- return -1;
-}
-
-uint8_t* usb_itd::BufferPage(int n, int size)
-{
- DBG_ASSERT(n >=0 && n <= 7);
- DBG_ASSERT(size >= 128 && size <= 956);
- uint8_t* buf = (uint8_t*)m_itd->BufferPage0 + n * size;
- DBG_ASSERT((uint32_t)(buf+size-1) <= m_itd->BufferEnd);
- return buf;
-}
-
-void usb_itd::free()
-{
- DBG_ASSERT(m_itd);
- if (m_itd) {
- uint8_t* buf = (uint8_t*)m_itd->BufferPage0;
- DBG_ASSERT(buf);
- usb_free_bp(buf);
- usb_free_itd((byte*)m_itd);
- m_itd = NULL;
- }
-}
-
-void usb_itd::debug()
-{
- DBG("itd =%08X\n", m_itd);
- DBG("itd->Control =%08X\n", m_itd->Control);
- DBG("itd->BufferPage0=%08X\n", m_itd->BufferPage0);
- DBG("itd->Next =%08X\n", m_itd->Next);
- DBG("itd->BufferEnd =%08X\n", m_itd->BufferEnd);
- DBG("itd->OffsetPSW10=%08X\n", m_itd->OffsetPSW10);
- DBG("itd->OffsetPSW32=%08X\n", m_itd->OffsetPSW32);
- DBG("itd->OffsetPSW54=%08X\n", m_itd->OffsetPSW54);
- DBG("itd->OffsetPSW76=%08X\n", m_itd->OffsetPSW76);
-}
--- a/uvc/usb_itd.h Wed Jun 06 11:47:06 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,23 +0,0 @@
-#ifndef USB_ITD_H
-#define USB_ITD_H
-#include "UsbInc.h"
-#include "usb_mem.h"
-
-class usb_itd {
-public:
- usb_itd(HCITD* itd);
- bool Done();
- int ConditionCode();
- int FrameCount();
- int PacketStatus(int n);
- int Length(int n);
- uint8_t* BufferPage(int n, int size);
- uint16_t StartingFrame();
- void free();
- void debug();
-private:
- uint16_t get_psw(int n);
- HCITD* m_itd;
-};
-
-#endif //USB_ITD_H
\ No newline at end of file
--- a/uvc/usb_mjpeg.cpp Wed Jun 06 11:47:06 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,143 +0,0 @@
-#include "mbed.h"
-#include "usb_mjpeg.h"
-//#define __DEBUG
-#define __DEBUG2
-#include "mydbg.h"
-#include "Utils.h"
-#include "myjpeg.h"
-
-#ifdef __DEBUG
-extern DigitalOut led4;
-#endif // __DEBUG
-
-#define MJPEG_FID 0x01
-#define MJPEG_EOF 0x02
-#define MJPEG_PTS 0x04
-#define MJPEG_SCR 0x08
-#define MJPEG_STI 0x20
-#define MJPEG_ERR 0x40
-#define MJPEG_EOH 0x80
-
-
-usb_mjpeg::usb_mjpeg(uint8_t* buf, int size)
-{
- DBG_ASSERT(size >= 1024 && size <= 16000);
- m_size = size;
- m_seq = 0;
- m_buf = buf;
- ReportErrorFID = 0;
- ReportErrorPTS = 0;
-}
-
-usb_mjpeg::~usb_mjpeg()
-{
-
-}
-
-void usb_mjpeg::input(uint16_t frame, uint8_t* buf, int len)
-{
- uint8_t* StreamHeader = buf;
- DBG_ASSERT(buf);
- if (len > 12) {
- //DBG_PRINTF("%d %02X %d\n", frame, buf[1], len);
- //DBG_HEX(buf, len);
- DBG_ASSERT(StreamHeader[0] == 0x0c);
- //DBG_ASSERT(buf[1] == 0x8c || buf[1] == 0x8d);
- //DBG("bfh:%02X\n", buf[1]);
- }
- DBG_ASSERT(len >= 2);
-
- int hle = StreamHeader[0];
- uint8_t bfh = StreamHeader[1];
- DBG_ASSERT(len >= hle);
- DBG_ASSERT(hle == 12);
- uint8_t* data = buf + hle;
- int data_len = len - hle;
- if (m_seq == 0) {
- if (check_SOI(buf, len)) {
- DBG_PRINTF("%04X SOI\n", frame);
- DBG_BYTES("SOI", buf, 16);
- _open();
- m_bfh = bfh; // save FID
- if (bfh & MJPEG_PTS) {
- m_pts = LE32(StreamHeader+2); // save PTS
- }
- _wrtie(data, data_len);
- m_seq++;
- }
- } else if (m_seq == 1) {
- if (len > hle) {
- _wrtie(data, data_len);
- }
- if (check_EOI(buf, len)) {
- DBG_PRINTF("%04X EOI\n", frame);
- DBG_BYTES("EOI", buf, 12);
- _close();
- m_seq = 2; // done
- } else if ((m_bfh ^ bfh) & MJPEG_FID) {
- ReportErrorFID++;
- DBG("ReportErrorFID=%d\n", ReportErrorFID);
- m_seq = 0; // restart
- } else if ((bfh & MJPEG_PTS) && m_pts != LE32(StreamHeader+2)) {
- ReportErrorPTS++;
- DBG("ReportErrorPTS=%d\n", ReportErrorPTS);
- m_seq = 0; // restart
- }
- } else { // done
- }
- DBG_LED4(buf[1] & MJPEG_FID); // FID
-}
-
-int usb_mjpeg::status()
-{
- if (m_seq <= 1) {
- return USBERR_PROCESSING;
- }
- return m_pos;
-}
-
-bool usb_mjpeg::check_SOI(uint8_t* buf, int len)
-{
- if (len >= (12+2)) {
- if (buf[12] == 0xff && buf[13] == 0xd8) {
- return true;
- }
- }
- return false;
-}
-
-bool usb_mjpeg::check_EOI(uint8_t* buf, int len)
-{
- if (len >= 12) {
- if (buf[1] & MJPEG_EOF) {
- return true;
- }
- }
- return false;
-}
-
-void usb_mjpeg::_open()
-{
- m_pos = 0;
-}
-
-void usb_mjpeg::_wrtie(uint8_t* buf, int len)
-{
- if (m_buf == NULL) {
- return;
- }
- for(int i = 0; i < len && m_pos < m_size; i++) {
- m_buf[m_pos++] = buf[i];
- }
-}
-
-void usb_mjpeg::_close()
-{
- //DBG("m_pos=%d\n", m_pos);
- //DBG_HEX(m_buf, m_pos);
- myjpeg JPEG(m_buf, m_pos, m_size);
- JPEG.analytics();
- if (JPEG.DHT_pos == 0) {
- m_pos = JPEG.insertDHT();
- }
-}
--- a/uvc/usb_mjpeg.h Wed Jun 06 11:47:06 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,33 +0,0 @@
-#ifndef USB_MJPEG_H
-#define USB_MJPEG_H
-#include "UsbInc.h"
-
-class usb_stream {
-public:
- virtual void input(uint16_t frame, uint8_t* buf, int len) = 0;
-};
-
-class usb_mjpeg : public usb_stream {
-public:
- usb_mjpeg(uint8_t* buf = NULL, int size = 4800);
- ~usb_mjpeg();
- virtual void input(uint16_t frame, uint8_t* buf, int len);
- int status();
- uint16_t ReportErrorFID;
- uint16_t ReportErrorPTS;
-private:
- void _open();
- void _wrtie(uint8_t* buf, int len);
- void _close();
-
- uint8_t* m_buf;
- int m_pos;
- bool check_SOI(uint8_t* buf, int len);
- bool check_EOI(uint8_t* buf, int len);
- void analyticsJPEG(uint8_t* buf, int len);
- int m_seq;
- int m_size;
- uint8_t m_bfh;
- uint32_t m_pts;
-};
-#endif //USB_MJPEG_H
\ No newline at end of file
--- a/uvc/uvc.cpp Wed Jun 06 11:47:06 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,264 +0,0 @@
-#include "mbed.h"
-#include "uvc.h"
-
-//#define __DEBUG
-//#define __DEBUG3
-#include "mydbg.h"
-#include "usb_itd.h"
-
-uvc::uvc(int cam)
-{
- DBG("cam=%d\n", cam);
- DBG_ASSERT(cam >= 0);
- m_cam = cam;
- m_init = false;
- m_connect = false;
- m_int_seq = 0;
- m_iso_seq = 0;
- m_width = 0;
- m_height = 0;
- m_payload = PAYLOAD_MJPEG;
- m_FormatIndex = 0;
- m_FrameIndex = 0;
- m_FrameInterval = 0;
- m_PacketSize = 0;
- m_stream = NULL;
- for(int i = 0; i <= 15; i++) {
- ReportConditionCode[i] = 0;
- }
- clearOnResult();
-}
-
-uvc::~uvc()
-{
- clearOnResult();
-}
-
-int uvc::setup()
-{
- if (!m_init) {
- return _init();
- }
- return 0;
-}
-
-int uvc::get_jpeg(const char* path)
-{
- const int size = 4800;
- const int timeout = 5000;
- uint8_t* buf = new uint8_t[size];
- DBG_ASSERT(buf);
- if (buf == NULL) {
- return -1;
- }
- usb_mjpeg mjpeg(buf, size);
- attach(&mjpeg);
- Timer t;
- t.reset();
- t.start();
- while(t.read_ms() < timeout) {
- int stat = isochronous();
- if (mjpeg.status() >= 0) {
- break;
- }
- }
- detach();
- int len = mjpeg.status();
- if (len >= 0) {
- if (path != NULL) {
- FILE *fp = fopen(path, "wb");
- if (fp != NULL) {
- for(int i = 0; i < len; i++) {
- fputc(buf[i], fp);
- }
- fclose(fp);
- }
- }
- }
- delete[] buf;
- return len;
-}
-
-int uvc::get_jpeg(uint8_t* buf, int size)
-{
- //DBG("buf=%p size=%d\n", buf, size);
- const int timeout = 5000;
- usb_mjpeg mjpeg(buf, size);
- attach(&mjpeg);
- Timer t;
- t.reset();
- t.start();
- while(t.read_ms() < timeout) {
- int stat = isochronous();
- if (mjpeg.status() >= 0) {
- break;
- }
- }
- detach();
- int len = mjpeg.status();
- return len;
-}
-
-bool uvc::interrupt()
-{
- if (!m_init) {
- _init();
- }
- if (m_int_seq == 0) {
- int rc = m_pEpIntIn->transfer(m_int_buf, sizeof(m_int_buf));
- if (rc != USBERR_PROCESSING) {
- return false;
- }
- m_int_seq++;
- }
- int len = m_pEpIntIn->status();
- if (len > 0) {
- m_int_seq = 0;
- DBG_BYTES("interrupt", m_int_buf, len);
- return true;
- }
- return false;
-}
-
-#define CC_NOERROR 0x0
-#define CC_DATAOVERRUN 0x8
-#define CC_DATAUNDERRUN 0x9
-
-inline void DI()
-{
- NVIC_DisableIRQ(USB_IRQn);
-}
-
-inline void EI()
-{
- NVIC_EnableIRQ(USB_IRQn);
-}
-
-int uvc::isochronous()
-{
- if (m_iso_seq == 0) {
- uint16_t frame = LPC_USB->HcFmNumber;
- m_iso_frame = frame + 10; // 10msec
- DBG_ASSERT(m_pEpIsoIn->m_itdActive == 0);
- m_iso_seq++;
- }
- if (m_iso_seq == 1) {
- DBG_ASSERT(m_itdCount > 0 && m_itdCount <= 8);
- while(m_pEpIsoIn->m_itdActive < m_itdCount) {
- int len = m_PacketSize * m_FrameCount;
- uint8_t* buf = (uint8_t*)usb_get_bp(len);
- if (buf == NULL) {
- DBG("len=%d\n", len);
- DBG("m_itdCount=%d\n", m_itdCount);
- }
- DBG_ASSERT(buf);
- int rc = m_pEpIsoIn->transfer(m_iso_frame, m_FrameCount, buf, len);
- m_iso_frame += m_FrameCount;
- DBG_ASSERT(rc == USBERR_PROCESSING);
- }
- m_iso_seq++;
- }
- if (m_iso_seq == 2) {
- //DBG("frame:%04X\n", LPC_USB->HcFmNumber);
- while(1) {
- DI();
- bool empty = m_pEpIsoIn->queue_done_itd.empty();
- EI();
-
- if (empty) {
- break;
- }
-
- DI();
- HCITD* itd = m_pEpIsoIn->queue_done_itd.front();
- m_pEpIsoIn->queue_done_itd.pop();
- EI();
-
- m_pEpIsoIn->m_itdActive--;
- usb_itd iso_td(itd);
- //DBG("frame:%04X\n", LPC_USB->HcFmNumber);
- //DBG("itd->Control=%08X\n", itd->Control);
- int cc = iso_td.ConditionCode();
- DBG_ASSERT(cc >= 0 && cc <= 15);
- ReportConditionCode[cc]++;
- if (cc != CC_NOERROR) {
- DBG3("%04X ERR:%X\n", LPC_USB->HcFmNumber, cc);
- iso_td.free();
- m_iso_seq = 3;
- return -1;
- }
- uint16_t frame = iso_td.StartingFrame();
- int fc = iso_td.FrameCount();
- for(int i = 0; i < fc; i++) {
- int len = iso_td.Length(i);
- if (len > 0) {
- if (m_stream) {
- m_stream->input(frame+i, iso_td.BufferPage(i, m_PacketSize), len);
- }
- onResult(frame+i, iso_td.BufferPage(i, m_PacketSize), len);
- }
- }
- iso_td.free();
- }
- //DBG("frame:%04X\n", LPC_USB->HcFmNumber);
- m_iso_seq = 1;
- return m_pEpIsoIn->m_itdActive;
- }
- if (m_iso_seq == 3) { // cleanup
- DBG("m_pEpIsoIn->queue_done_itd.size() :%d\n", m_pEpIsoIn->queue_done_itd.size());
- while(1) {
- DI();
- bool empty = m_pEpIsoIn->queue_done_itd.empty();
- EI();
-
- if (empty) {
- break;
- }
-
- DI();
- HCITD* itd = m_pEpIsoIn->queue_done_itd.front();
- m_pEpIsoIn->queue_done_itd.pop();
- EI();
-
- m_pEpIsoIn->m_itdActive--;
- usb_itd iso_td(itd);
- iso_td.free();
- }
- if (m_pEpIsoIn->m_itdActive == 0) {
- m_iso_seq = 0;
- }
- }
- return m_pEpIsoIn->m_itdActive;
-}
-
-void uvc::attach(usb_stream* stream)
-{
- m_stream = stream;
-}
-
-void uvc::detach()
-{
- m_stream = NULL;
-}
-
-void uvc::onResult(uint16_t frame, uint8_t* buf, int len)
-{
- if(m_pCbItem && m_pCbMeth)
- (m_pCbItem->*m_pCbMeth)(frame, buf, len);
- else if(m_pCb)
- m_pCb(frame, buf, len);
-}
-
-void uvc::setOnResult( void (*pMethod)(uint16_t, uint8_t*, int) )
-{
- m_pCb = pMethod;
- m_pCbItem = NULL;
- m_pCbMeth = NULL;
-}
-
-void uvc::clearOnResult()
-{
- m_pCb = NULL;
- m_pCbItem = NULL;
- m_pCbMeth = NULL;
-}
--- a/uvc/uvc.h Wed Jun 06 11:47:06 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,102 +0,0 @@
-#ifndef UVC_H
-#define UVC_H
-#include "UsbBaseClass.h"
-#include "usb_mem.h"
-#include "usb_mjpeg.h"
-
-#define CLASS_VIDEO 0x0E
-
-#define SET_CUR 0x01
-#define GET_CUR 0x81
-#define GET_MIN 0x82
-#define GET_MAX 0x83
-#define GET_RES 0x84
-#define GET_LEN 0x85
-#define GET_INFO 0x86
-#define GET_DEF 0x87
-
-#define VS_PROBE_CONTROL 0x01
-#define VS_COMMIT_CONTROL 0x02
-
-#define PAYLOAD_UNDEF 0
-#define PAYLOAD_MJPEG 1
-#define PAYLOAD_YUY2 2
-
-class uvc : public UsbBaseClass {
-public:
- uvc(int cam = 0);
- ~uvc();
- int setup();
- int get_jpeg(const char* path);
- int get_jpeg(uint8_t* buf, int size);
- bool interrupt();
- int isochronous();
- void attach(usb_stream* stream);
- void detach();
- ///set format index
- void SetFormatIndex(int index = 1);
- ///set frame index
- void SetFrameIndex(int index = 1);
- ///set frame interval
- void SetFrameInterval(int val = 2000000);
- ///set packet size
- void SetPacketSize(int size = 128);
- ///set image size
- void SetImageSize(int width = 160, int height = 120);
- ///set payload MJPEG or YUY2
- void SetPayload(int payload); // MJPEG,YUV422(YUY2)
- UsbErr Control(int req, int cs, int index, uint8_t* buf, int size);
- ///Setups the result callback
- /**
- @param pMethod : callback function
- */
- void setOnResult( void (*pMethod)(uint16_t, uint8_t*, int) );
-
- ///Setups the result callback
- /**
- @param pItem : instance of class on which to execute the callback method
- @param pMethod : callback method
- */
- class CDummy;
- template<class T>
- void setOnResult( T* pItem, void (T::*pMethod)(uint16_t, uint8_t*, int) )
- {
- m_pCb = NULL;
- m_pCbItem = (CDummy*) pItem;
- m_pCbMeth = (void (CDummy::*)(uint16_t, uint8_t*, int)) pMethod;
- }
- void clearOnResult();
-
- void poll();
- void wait(float s);
- void wait_ms(int ms);
- uint16_t ReportConditionCode[16];
-protected:
- int _init();
- void _config(struct stcamcfg* cfg);
- void onResult(uint16_t frame, uint8_t* buf, int len);
- bool m_connect;
- bool m_init;
- int m_cam;
- UsbDevice* m_pDev;
- UsbEndpoint* m_pEpIntIn;
- UsbEndpoint* m_pEpIsoIn;
- int m_width;
- int m_height;
- int m_payload;
- int m_FormatIndex;
- int m_FrameIndex;
- int m_FrameInterval;
- int m_PacketSize;
- int m_FrameCount; // 1-8
- int m_itdCount;
- uint8_t m_int_buf[16];
- int m_int_seq;
- int m_iso_seq;
- uint16_t m_iso_frame;
- usb_stream* m_stream;
- CDummy* m_pCbItem;
- void (CDummy::*m_pCbMeth)(uint16_t, uint8_t*, int);
- void (*m_pCb)(uint16_t, uint8_t*, int);
-};
-#endif //UVC_H
\ No newline at end of file
--- a/uvc/uvccfg.cpp Wed Jun 06 11:47:06 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,401 +0,0 @@
-#include "mbed.h"
-#include "uvc.h"
-//#define __DEBUG
-#include "mydbg.h"
-#include "stcamcfg.h"
-#include "Utils.h"
-
-#define DESCRIPTOR_TYPE_DEVICE 1
-#define DESCRIPTOR_TYPE_CONFIGURATION 2
-#define DESCRIPTOR_TYPE_STRING 3
-#define DESCRIPTOR_TYPE_INTERFACE 4
-#define DESCRIPTOR_TYPE_ENDPOINT 5
-
-#define DESCRIPTOR_TYPE_INTERFACE_ASSOCIATION 0x0b
-
-#define DESCRIPTOR_TYPE_HID 0x21
-#define DESCRIPTOR_TYPE_REPORT 0x22
-#define DESCRIPTOR_TYPE_PHYSICAL 0x23
-#define DESCRIPTOR_TYPE_CS_INTERFACE 0x24
-#define DESCRIPTOR_TYPE_CS_ENDPOINT 0x25
-#define DESCRIPTOR_TYPE_HUB 0x29
-
-#define CLASS_AUDIO 0x02
-#define CLASS_HUB 0x09
-
-#define IF_EQ_THEN_PRINTF(A,B) if (A == B) {VERBOSE("%s\n", #A);
-#define ENDIF }
-
-#define AC_HEADER 0x01
-#define AC_INPUT_TERMINAL 0x02
-#define AC_OUTPUT_TERMINAL 0x03
-#define AC_FEATURE_UNIT 0x06
-
-// Input Terminal Types
-#define ITT_CAMERA 0x0201
-
-
-void _parserAudioControl(uint8_t* buf, int len) {
- int subtype = buf[2];
- IF_EQ_THEN_PRINTF(AC_HEADER, subtype)
- VERBOSE("ADC: %04x\n", LE16(buf+3));
- VERBOSE("TotalLength: %d\n", LE16(buf+5));
- VERBOSE("InCollection: %d\n", buf[7]);
- for (int n = 1; n <= buf[7]; n++) {
- VERBOSE("aInterfaceNr(%d): %d\n", n, buf[8+n-1]);
- }
- ENDIF
- IF_EQ_THEN_PRINTF(AC_INPUT_TERMINAL, subtype)
- VERBOSE("TerminalID: %d\n", buf[3]);
- VERBOSE("TerminalType: %04X\n", LE16(buf+4));
- VERBOSE("AssocTermianl: %d\n", buf[6]);
- VERBOSE("NrChannels: %d\n", buf[7]);
- ENDIF
- IF_EQ_THEN_PRINTF(AC_OUTPUT_TERMINAL, subtype)
- VERBOSE("TerminalID: %d\n", buf[3]);
- VERBOSE("TerminalType: %04X\n", LE16(buf+4));
- VERBOSE("AssocTermianl: %d\n", buf[6]);
- ENDIF
- IF_EQ_THEN_PRINTF(AC_FEATURE_UNIT, subtype)
- VERBOSE("UnitID: %d\n", buf[3]);
- VERBOSE("SourceID: %d\n", buf[4]);
- VERBOSE("ControlSize: %d\n", buf[5]);
- ENDIF
-}
-
-#define AS_GENERAL 0x01
-#define AS_FORMAT_TYPE 0x02
-
-void _parserAudioStream(uint8_t* buf, int len) {
- int subtype = buf[2];
- IF_EQ_THEN_PRINTF(AS_GENERAL, subtype)
- VERBOSE("TerminalLink: %d\n", buf[3]);
- VERBOSE("Delay: %d\n", buf[4]);
- VERBOSE("FormatTag: %04x\n", LE16(buf+5));
- ENDIF
- IF_EQ_THEN_PRINTF(AS_FORMAT_TYPE, subtype)
- VERBOSE("FormatType: %d\n", buf[3]);
- VERBOSE("NrChannels: %d\n", buf[4]);
- VERBOSE("SubFrameSize: %d\n", buf[5]);
- VERBOSE("BitResolution: %d\n", buf[6]);
- VERBOSE("SamFreqType: %d\n", buf[7]);
- VERBOSE("SamFreq(1): %d\n", LE24(buf+8));
- ENDIF
-}
-
-#define CC_VIDEO 0x0e
-
-#define SC_VIDEOCONTROL 0x01
-#define SC_VIDEOSTREAMING 0x02
-
-#define VC_HEADER 0x01
-#define VC_INPUT_TERMINAL 0x02
-#define VC_OUTPUT_TERMINAL 0x03
-#define VC_SELECTOR_UNIT 0x04
-#define VC_PROCESSING_UNIT 0x05
-#define VC_EXTENSION_UNIT 0x06
-
-void _parserVideoControl(uint8_t* buf, int len) {
- int subtype = buf[2];
- IF_EQ_THEN_PRINTF(VC_HEADER, subtype)
- VERBOSE("UVC: %04x\n", LE16(buf+3));
- VERBOSE("TotalLength: %d\n", LE16(buf+5));
- VERBOSE("ClockFrequency: %d\n", LE32(buf+7));
- VERBOSE("InCollection: %d\n", buf[11]);
- VERBOSE("aInterfaceNr(1): %d\n", buf[12]);
- ENDIF
- IF_EQ_THEN_PRINTF(VC_INPUT_TERMINAL, subtype)
- VERBOSE("TerminalID: %d\n", buf[3]);
- uint16_t tt = LE16(buf+4);
- VERBOSE("TerminalType: %04X\n", tt);
- VERBOSE("AssocTerminal: %d\n", buf[6]);
- VERBOSE("Terminal: %d\n", buf[7]);
- if (tt == ITT_CAMERA) { // camera
- int bControlSize = buf[14];
- VERBOSE("ControlSize: %d\n", bControlSize);
- for(int i = 0; i < bControlSize; i++) {
- uint8_t bControls = buf[15+i];
- VERBOSE("Controls(%d): %02X\n", i, bControls);
- }
- }
- ENDIF
- IF_EQ_THEN_PRINTF(VC_OUTPUT_TERMINAL, subtype)
- VERBOSE("TerminalID: %d\n", buf[3]);
- VERBOSE("TerminalType: %04X\n", LE16(buf+4));
- VERBOSE("AssocTerminal: %d\n", buf[6]);
- VERBOSE("SourceID: %d\n", buf[7]);
- VERBOSE("Terminal: %d\n", buf[8]);
- ENDIF
- IF_EQ_THEN_PRINTF(VC_SELECTOR_UNIT, subtype)
- VERBOSE("UnitID: %d\n", buf[3]);
- ENDIF
- IF_EQ_THEN_PRINTF(VC_PROCESSING_UNIT, subtype)
- VERBOSE("UnitID: %d\n", buf[3]);
- VERBOSE("SourceID: %d\n", buf[4]);
- VERBOSE("MaxMultiplier: %d\n", LE16(buf+5));
- VERBOSE("ControlSize: %d\n", buf[7]);
- int pos = 8;
- for (int n = 1; n <= buf[7]; n++) {
- VERBOSE("Controls(%d): %02X\n", n , buf[pos]);
- pos++;
- }
- VERBOSE("Processing: %d\n", buf[pos]);
- pos++;
- VERBOSE("VideoStanders: %02X\n", buf[pos]);
- ENDIF
- IF_EQ_THEN_PRINTF(VC_EXTENSION_UNIT, subtype)
- VERBOSE("UnitID: %d\n", buf[3]);
- ENDIF
-}
-
-#define VS_INPUT_HEADER 0x01
-#define VS_STILL_FRAME 0x03
-#define VS_FORMAT_UNCOMPRESSED 0x04
-#define VS_FRAME_UNCOMPRESSED 0x05
-#define VS_FORMAT_MJPEG 0x06
-#define VS_FRAME_MJPEG 0x07
-#define VS_COLOR_FORMAT 0x0d
-
-void _parserVideoStream(struct stcamcfg* cfg, uint8_t* buf, int len) {
- int subtype = buf[2];
- IF_EQ_THEN_PRINTF(VS_INPUT_HEADER, subtype)
- VERBOSE("NumFormats: %d\n", buf[3]);
- VERBOSE("TotalLength: %d\n", LE16(buf+4));
- VERBOSE("EndpointAddress: %02X\n", buf[6]);
- VERBOSE("Info: %02X\n", buf[7]);
- VERBOSE("TerminalLink: %d\n", buf[8]);
- VERBOSE("StillCaptureMethod: %d\n", buf[9]);
- VERBOSE("TriggerSupport: %d\n", buf[10]);
- VERBOSE("TriggerUsage: %d\n", buf[11]);
- VERBOSE("ControlSize: %d\n", buf[12]);
- int pos = 13;
- for (int n = 1; n <= buf[12]; n++) {
- VERBOSE("Controls(%d): %02X\n", n, buf[pos]);
- pos++;
- }
- cfg->bEndpointAddress = buf[6];
- ENDIF
- IF_EQ_THEN_PRINTF(VS_STILL_FRAME, subtype)
- VERBOSE("EndpointAdress: %02X\n", buf[3]);
- VERBOSE("NumImageSizePatterns: %d\n", buf[4]);
- int ptn = buf[4];
- int pos = 5;
- for (int n = 1; n <= ptn; n++) {
- VERBOSE("Width(%d): %d\n", n, LE16(buf+pos));
- VERBOSE("Height(%d): %d\n", n, LE16(buf+pos+2));
- pos += 4;
- }
- VERBOSE("NumCompressPtn: %d\n", buf[pos]);
- ptn = buf[pos++];
- for (int n = 1; n <= ptn; n++) {
- VERBOSE("Compress(%d): %d\n", n, buf[pos]);
- pos++;
- }
- ENDIF
- IF_EQ_THEN_PRINTF(VS_FORMAT_UNCOMPRESSED, subtype)
- VERBOSE("FormatIndex: %d\n", buf[3]);
- VERBOSE("NumFrameDescriptors: %d\n", buf[4]);
- uint32_t guid = LE32(buf+5);
- if (guid == 0x32595559) {
- VERBOSE("GUID: YUY2\n");
- } else if (guid == 0x3231564e) {
- VERBOSE("GUID: NV12\n");
- } else {
- VERBOSE("GUID: %08x\n", guid);
- }
- VERBOSE("DefaultFrameIndex: %d\n", buf[22]);
- if (cfg->payload == PAYLOAD_YUY2) {
- cfg->FormatIndex = buf[3];
- }
- ENDIF
- IF_EQ_THEN_PRINTF(VS_FRAME_UNCOMPRESSED, subtype)
- VERBOSE("FrameIndex: %d\n", buf[3]);
- VERBOSE("Capabilites: %d\n", buf[4]);
- VERBOSE("Width: %d\n", LE16(buf+5));
- VERBOSE("Height: %d\n", LE16(buf+7));
- VERBOSE("MinBitRate: %d\n", LE32(buf+9));
- VERBOSE("MaxBitRate: %d\n", LE32(buf+13));
- VERBOSE("MaxVideoFrameBufferSize: %d\n", LE32(buf+17));
- VERBOSE("DefaultFrameInterval: %d\n", LE32(buf+21));
- VERBOSE("FrameIntervalType: %d\n", buf[25]);
- int it = buf[25];
- uint32_t max_fi = 333333; // 30.0fps
- if (it == 0) {
- VERBOSE("FrameMinInterval: %d\n", buf[26]);
- VERBOSE("FrameMaxInterval: %d\n", buf[30]);
- VERBOSE("FrameIntervalStep: %d\n", buf[34]);
- } else {
- int pos = 26;
- for (int n = 1; n <= it; n++) {
- uint32_t fi = LE32(buf+pos);
- if (fi >= max_fi) {
- max_fi = fi;
- }
- float fps = 1e+7 / fi;
- VERBOSE("FrameInterval(%u): %d (%.1f fps)\n", n, fi, fps);
- pos += 4;
- }
- }
- if (cfg->payload == PAYLOAD_YUY2) {
- if (cfg->width == LE16(buf+5) && cfg->height == LE16(buf+7)) {
- cfg->FrameIndex = buf[3];
- }
- if (cfg->dwFrameInterval == 0) {
- cfg->dwFrameInterval = max_fi;
- }
- }
- ENDIF
- IF_EQ_THEN_PRINTF(VS_FORMAT_MJPEG, subtype)
- VERBOSE("FormatIndex: %d\n", buf[3]);
- VERBOSE("NumFrameDescriptors: %d\n", buf[4]);
- VERBOSE("Flags: %d\n", buf[5]);
- VERBOSE("DefaultFrameIndex: %d\n", buf[6]);
- if (cfg->payload == PAYLOAD_MJPEG) {
- cfg->FormatIndex = buf[3];
- }
- ENDIF
- IF_EQ_THEN_PRINTF(VS_FRAME_MJPEG, subtype)
- VERBOSE("FrameIndex: %d\n", buf[3]);
- VERBOSE("Capabilites: %d\n", buf[4]);
- VERBOSE("Width: %d\n", LE16(buf+5));
- VERBOSE("Height: %d\n", LE16(buf+7));
- VERBOSE("MinBitRate: %d\n", LE32(buf+9));
- VERBOSE("MaxBitRate: %d\n", LE32(buf+13));
- VERBOSE("MaxVideoFrameBufferSize: %d\n", LE32(buf+17));
- VERBOSE("DefaultFrameInterval: %d\n", LE32(buf+21));
- VERBOSE("FrameIntervalType: %d\n", buf[25]);
- int it = buf[25];
- uint32_t max_fi = 333333; // 30.0fps
- if (it == 0) {
- VERBOSE("FrameMinInterval: %d\n", buf[26]);
- VERBOSE("FrameMaxInterval: %d\n", buf[30]);
- VERBOSE("FrameIntervalStep: %d\n", buf[34]);
- } else {
- int pos = 26;
- for (int n = 1; n <= it; n++) {
- uint32_t fi = LE32(buf+pos);
- if (fi >= max_fi) {
- max_fi = fi;
- }
- float fps = 1e+7 / fi;
- VERBOSE("FrameInterval(%u): %d (%.1f fps)\n", n, fi, fps);
- pos += 4;
- }
- }
- if (cfg->payload == PAYLOAD_MJPEG) {
- if (cfg->width == LE16(buf+5) && cfg->height == LE16(buf+7)) {
- cfg->FrameIndex = buf[3];
- }
- if (cfg->dwFrameInterval == 0) {
- cfg->dwFrameInterval = max_fi;
- }
- }
- ENDIF
- IF_EQ_THEN_PRINTF(VS_COLOR_FORMAT, subtype)
- ENDIF
-}
-
-void _parserConfigurationDescriptor(struct stcamcfg* cfg, uint8_t* buf, int len) {
- //DBG("buf=%p len=%d\n", buf, len);
- //DBG_HEX(buf, len);
- int pos = 0;
- cfg->_IfClass = 0;
- cfg->_IfSubClass = 0;
- while (pos < len) {
- int type = buf[pos+1];
- //DBG_BYTES(TYPE_Str(type), buf+pos, buf[pos]);
- IF_EQ_THEN_PRINTF(DESCRIPTOR_TYPE_CONFIGURATION, type)
- VERBOSE("NumInterfaces: %d\n", buf[pos+4]);
- ENDIF
- IF_EQ_THEN_PRINTF(DESCRIPTOR_TYPE_INTERFACE_ASSOCIATION, type)
- VERBOSE("FirstInterface: %d\n", buf[pos+2]);
- VERBOSE("InterfaceCount: %d\n", buf[pos+3]);
- VERBOSE("FunctionClass: %02X\n", buf[pos+4]);
- VERBOSE("FunctionSubClass: %02X\n", buf[pos+5]);
- VERBOSE("FunctionProtocol: %02X\n", buf[pos+6]);
- VERBOSE("Function: %d\n", buf[pos+7]);
- ENDIF
- IF_EQ_THEN_PRINTF(DESCRIPTOR_TYPE_INTERFACE,type)
- VERBOSE("InterfaceNumber: %d\n", buf[pos+2]);
- VERBOSE("AlternateSetting: %d\n", buf[pos+3]);
- VERBOSE("NumEndpoint: %d\n", buf[pos+4]);
- VERBOSE("InterfaceClass: %02X\n", buf[pos+5]);
- VERBOSE("InterfaceSubClass: %02X\n", buf[pos+6]);
- VERBOSE("InterfaceProtocol: %02X\n", buf[pos+7]);
- VERBOSE("Interface: %d\n", buf[pos+8]);
- cfg->_If = buf[pos+2];
- cfg->_Ifalt = buf[pos+3];
- cfg->_IfClass = buf[pos+5];
- cfg->_IfSubClass = buf[pos+6];
- ENDIF
- IF_EQ_THEN_PRINTF(DESCRIPTOR_TYPE_ENDPOINT, type)
- VERBOSE("EndpointAddress: %02X\n", buf[pos+2]);
- VERBOSE("Attributes: %02X\n", buf[pos+3]);
- VERBOSE("MaxPacketSize: %d\n", LE16(buf+pos+4));
- VERBOSE("Interval: %d\n", buf[pos+6]);
- if (cfg->_IfClass == CC_VIDEO && cfg->_IfSubClass == SC_VIDEOSTREAMING) {
- if (cfg->bEndpointAddress == buf[pos+2]) {
- if (cfg->wMaxPacketSize == 0) {
- cfg->wMaxPacketSize = LE16(buf+pos+4);
- }
- if (cfg->wMaxPacketSize == LE16(buf+pos+4)) {
- cfg->bInterface = cfg->_If;
- cfg->bAlternate = cfg->_Ifalt;
- }
- }
- }
- ENDIF
- IF_EQ_THEN_PRINTF(DESCRIPTOR_TYPE_CS_INTERFACE, type)
- IF_EQ_THEN_PRINTF(CC_VIDEO, cfg->_IfClass)
- IF_EQ_THEN_PRINTF(SC_VIDEOCONTROL, cfg->_IfSubClass)
- _parserVideoControl(buf+pos, buf[pos]);
- ENDIF
- IF_EQ_THEN_PRINTF(SC_VIDEOSTREAMING, cfg->_IfSubClass)
- _parserVideoStream(cfg, buf+pos, buf[pos]);
- ENDIF
- ENDIF
- if (cfg->_IfClass == CLASS_AUDIO) {
- if (cfg->_IfSubClass == 0x01) {
- _parserAudioControl(buf+pos, buf[pos]);
- } else if (cfg->_IfSubClass == 0x02) {
- _parserAudioStream(buf+pos, buf[pos]);
- }
- }
- ENDIF
- IF_EQ_THEN_PRINTF(DESCRIPTOR_TYPE_HUB, type)
- ENDIF
- pos += buf[pos];
- }
-}
-
-void uvc::_config(struct stcamcfg* cfg)
-{
- DBG_ASSERT(cfg);
- int index = 0;
- uint8_t temp[4];
- int rc = m_pDev->GetDescriptor(USB_DESCRIPTOR_TYPE_CONFIGURATION, index, temp, sizeof(temp));
- DBG_ASSERT(rc == USBERR_OK);
- DBG_BYTES("Config Descriptor 4bytes", temp, sizeof(temp));
- DBG_ASSERT(temp[0] == 9);
- DBG_ASSERT(temp[1] == 0x02);
- int TotalLength = LE16(temp+2);
- DBG("TotalLength: %d\n", TotalLength);
-
- uint8_t* buf = new uint8_t[TotalLength];
- DBG_ASSERT(buf);
- rc = m_pDev->GetDescriptor(USB_DESCRIPTOR_TYPE_CONFIGURATION, index,
- buf, TotalLength);
- DBG_ASSERT(rc == USBERR_OK);
-
- _parserConfigurationDescriptor(cfg, buf, TotalLength);
-
- DBG("cfg->FrameIndex=%d\n", cfg->FrameIndex);
- DBG("cfg->dwFrameInterval=%u\n", cfg->dwFrameInterval);
-
- //DBG_ASSERT(cfg->FormatIndex >= 1);
- //DBG_ASSERT(cfg->FormatIndex <= 2);
- //DBG_ASSERT(cfg->FrameIndex >= 1);
- //DBG_ASSERT(cfg->FrameIndex <= 6);
-
- delete[] buf;
-}
--- a/uvc/uvcctl.cpp Wed Jun 06 11:47:06 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-#include "mbed.h"
-#include "uvc.h"
-#define __DEBUG
-#include "mydbg.h"
-
-UsbErr uvc::Control(int req, int cs, int index, uint8_t* buf, int size)
-{
- UsbErr rc;
- if (req == SET_CUR) {
- rc = m_pDev->controlSend(
- USB_HOST_TO_DEVICE | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_INTERFACE,
- req, cs<<8, index, buf, size);
- return rc;
- }
- rc = m_pDev->controlReceive(
- USB_DEVICE_TO_HOST | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_INTERFACE,
- req, cs<<8, index, buf, size);
- return rc;
-}
--- a/uvc/uvcini.cpp Wed Jun 06 11:47:06 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,263 +0,0 @@
-#include "mbed.h"
-#include "uvc.h"
-//#define __DEBUG
-#include "mydbg.h"
-#include "stcamcfg.h"
-
-const struct stcamcfg stcamcfg_table[] = {
-/*
-{0x045e, 0x074a,
-160,120,
-PAYLOAD_MJPEG,
-0x81, 128,
-1, 5, 2000000, // 160x120 5.0fps
-1, 1, "Microsoft LifeCam VX-700",
-8, 3,
-},*/
-/*
-{0x0c45, 0x62c0,
-160,120,
-PAYLOAD_MJPEG,
-0x81, 128,
-1, 5, 2000000, // 160x120 5.0fps
-1, 1, "UVCA130AF",
-8, 3,
-},*/
-
-{0x046d, 0x0994,
-160,120,
-PAYLOAD_MJPEG,
-0, 0,
-0, 0, 2000000, // 160x120 10.0fps
-0, 0, "Logitech QuickCam Orbit AF",
-0, 3,
-},
-{0x0000, 0x0000,
-160,120,
-PAYLOAD_MJPEG,
-0x00, 0,
-0, 0, 2000000,
-0, 0, "default",
-0, 3,
-},
-};
-
-inline void LE32(uint32_t n, uint8_t* d)
-{
- d[0] = (uint8_t)n;
- d[1] = (uint8_t)(n >> 8);
- d[2] = (uint8_t)(n >> 16);
- d[3] = (uint8_t)(n >> 24);
-}
-
-void uvc::SetFormatIndex(int index)
-{
- DBG_ASSERT(index >= 1);
- DBG_ASSERT(index <= 2);
- m_FormatIndex = index;
-}
-
-void uvc::SetFrameIndex(int index)
-{
- DBG_ASSERT(index >= 1);
- DBG_ASSERT(index <= 8);
- m_FrameIndex = index;
-}
-
-void uvc::SetFrameInterval(int val)
-{
- DBG_ASSERT(val >= 333333);
- DBG_ASSERT(val <= 10000000);
- m_FrameInterval = val;
-}
-
-void uvc::SetPacketSize(int size)
-{
- DBG_ASSERT(size >= 128);
- DBG_ASSERT(size <= 956);
- m_PacketSize = size;
-}
-
-void uvc::SetImageSize(int width, int height)
-{
- DBG_ASSERT(width >= 160);
- DBG_ASSERT(width <= 800);
- DBG_ASSERT(height >= 120);
- DBG_ASSERT(height <= 600);
- m_width = width;
- m_height = height;
-}
-
-void uvc::SetPayload(int payload)
-{
- DBG_ASSERT(payload == PAYLOAD_MJPEG || payload == PAYLOAD_YUY2);
- m_payload = payload;
-}
-
-void uvc::poll()
-{
- isochronous();
-}
-
-int uvc::_init()
-{
- m_init = true;
- UsbErr rc;
- for(int i = 0; i < 2; i++) {
- m_pDev = m_pHost->getDeviceByClass(CLASS_VIDEO, m_cam); // UVC
- if (m_pDev || i > 0) {
- break;
- }
- rc = Usb_poll();
- if (rc == USBERR_PROCESSING) {
- VERBOSE("%p USBERR_PROCESSING\n", this);
- return -1;
- }
- }
- DBG("m_pDev=%p\n", m_pDev);
- if (!m_pDev) {
- VERBOSE("%p UVC CAMERA(%d) NOT FOUND\n", this, m_cam);
- return -1;
- }
- DBG_ASSERT(m_pDev);
-
- struct stcamcfg cfg;
- for(int i = 0; ; i++) {
- cfg = stcamcfg_table[i];
- if (cfg.idVender == 0x0000) {
- DBG("not cam config\n");
- DBG("vid: %04X\n", m_pDev->getVid());
- DBG("pid: %04X\n", m_pDev->getPid());
- break;
- }
- if (cfg.idVender == m_pDev->getVid() && cfg.idProduct == m_pDev->getPid()) {
- DBG_ASSERT(cfg.name);
- DBG("found %s\n", cfg.name);
- break;
- }
- }
-
- if (m_width) {
- cfg.width = m_width;
- }
- if (m_height) {
- cfg.height = m_height;
- }
- if (m_payload != PAYLOAD_UNDEF) {
- cfg.payload = m_payload;
- }
- if (m_FormatIndex) {
- cfg.FormatIndex = m_FormatIndex;
- }
- if (m_FrameIndex) {
- cfg.FrameIndex = m_FrameIndex;
- }
- if (m_FrameInterval) {
- cfg.dwFrameInterval = m_FrameInterval;
- }
- if (m_PacketSize) {
- cfg.wMaxPacketSize = m_PacketSize;
- }
-
- _config(&cfg);
-
- if (cfg.payload == PAYLOAD_YUY2) {
- if (cfg.FormatIndex == 0) {
- VERBOSE("YUY2 FORMAT NOT FOUND\n");
- return -1;
- }
- }
-
- if (cfg.iso_FrameCount == 0) {
- int c = usb_bp_size() / cfg.wMaxPacketSize;
- if (c > 8) {
- c = 8;
- }
- cfg.iso_FrameCount = c;
- }
- DBG_ASSERT(cfg.iso_FrameCount >= 1);
- DBG_ASSERT(cfg.iso_FrameCount <= 8);
- DBG_ASSERT((cfg.iso_FrameCount * cfg.wMaxPacketSize) <= usb_bp_size());
- if (cfg.iso_itdCount == 0) {
- cfg.iso_itdCount = 3;
- }
- DBG_ASSERT(cfg.iso_itdCount >= 1);
- DBG("cfg.wMaxPacketSize=%d\n", cfg.wMaxPacketSize);
- DBG("cfg.iso_FrameCount=%d\n", cfg.iso_FrameCount);
- DBG("cfg.iso_itdCount=%d\n", cfg.iso_itdCount);
- DBG_ASSERT(cfg.iso_FrameCount >= 1 && cfg.iso_FrameCount <= 8);
- //m_pEpIntIn = new UsbEndpoint(m_pDev, 0x83, true, USB_INT, 16);
- //DBG_ASSERT(m_pEpIntIn);
-
- DBG_ASSERT(cfg.bEndpointAddress == 0x81);
- DBG_ASSERT(cfg.wMaxPacketSize >= 128);
- DBG_ASSERT(cfg.wMaxPacketSize <= 956);
- m_PacketSize = cfg.wMaxPacketSize;
- DBG_ASSERT(m_PacketSize);
- m_pEpIsoIn = new UsbEndpoint(m_pDev, cfg.bEndpointAddress, true, USB_ISO, m_PacketSize);
- DBG_ASSERT(m_pEpIsoIn);
-
- DBG_ASSERT(cfg.FormatIndex >= 1);
- DBG_ASSERT(cfg.FormatIndex <= 2);
- DBG_ASSERT(cfg.FrameIndex >= 1);
- DBG_ASSERT(cfg.FrameIndex <= 8);
- DBG_ASSERT(cfg.dwFrameInterval <= 10000000);
- DBG_ASSERT(cfg.dwFrameInterval >= 333333);
-
- uint8_t temp1[1];
- temp1[0] = 0x00;
- rc = Control(GET_INFO, VS_PROBE_CONTROL, 1, temp1, sizeof(temp1));
- DBG_ASSERT(rc == USBERR_OK);
- DBG_BYTES("GET_INFO Probe ", temp1, sizeof(temp1));
-
- uint8_t temp[34];
- rc = Control(GET_CUR, VS_PROBE_CONTROL, 1, temp, sizeof(temp));
- DBG_ASSERT(rc == USBERR_OK);
- DBG_BYTES("GET_CUR Probe ", temp, sizeof(temp));
-
- uint8_t param[34];
- memset(param, 0x00, sizeof(param));
- param[0] = 0x00;
- param[2] = cfg.FormatIndex;
- param[3] = cfg.FrameIndex; // 160x120
- LE32(cfg.dwFrameInterval, param+4); // Frame Interval
-
- DBG_BYTES("SET_CUR Probe ", param, sizeof(param));
- rc = Control(SET_CUR, VS_PROBE_CONTROL, 1, param, sizeof(param));
- DBG_ASSERT(rc == USBERR_OK);
-
- rc = Control(GET_CUR, VS_PROBE_CONTROL, 1, temp, sizeof(temp));
- DBG_ASSERT(rc == USBERR_OK);
- DBG_BYTES("GET_CUR Probe ", temp, sizeof(temp));
-
- rc = Control(GET_CUR, VS_COMMIT_CONTROL, 1, temp, sizeof(temp));
- DBG_ASSERT(rc == USBERR_OK);
- DBG_BYTES("GET_CUR Commit", temp, sizeof(temp));
-
- DBG_BYTES("SET_CUR Commit", param, sizeof(param));
- rc = Control(SET_CUR, VS_COMMIT_CONTROL, 1, param, sizeof(param));
- DBG_ASSERT(rc == USBERR_OK);
-
- //USBH_SET_INTERFACE(1, 1); // alt=1 size=128
- DBG_ASSERT(cfg.bInterface >= 1);
- DBG_ASSERT(cfg.bAlternate >= 1);
- DBG_ASSERT(cfg.bAlternate <= 6);
- //rc = m_pDev->controlSend(
- // USB_HOST_TO_DEVICE | USB_RECIPIENT_INTERFACE,
- // SET_INTERFACE, cfg.bAlternate, cfg.bInterface, NULL, 0);
- rc = m_pDev->SetInterfaceAlternate(cfg.bInterface, cfg.bAlternate);
- DBG_ASSERT(rc == USBERR_OK);
-
- DBG_ASSERT(cfg.iso_FrameCount >= 1);
- DBG_ASSERT(cfg.iso_FrameCount <= 8);
- m_FrameCount = cfg.iso_FrameCount;
- DBG_ASSERT(cfg.iso_itdCount >= 1);
- DBG_ASSERT(cfg.iso_itdCount <= 8);
- m_itdCount = cfg.iso_itdCount;
-
- LPC_USB->HcControl |= OR_CONTROL_PLE; // PeriodicListEnable
- LPC_USB->HcControl |= OR_CONTROL_IE; // IsochronousEnable
-
- m_connect = true;
- return 0;
-}
--- a/uvc/uvcsub.cpp Wed Jun 06 11:47:06 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,21 +0,0 @@
-#include "mbed.h"
-#include "uvc.h"
-
-void uvc::wait(float s)
-{
- Timer t;
- t.start();
- while(t.read() < s) {
- poll();
- }
-}
-
-void uvc::wait_ms(int ms)
-{
- Timer t;
- t.start();
- while(t.read_ms() < ms) {
- poll();
- }
-}
-
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/uvchost.lib Tue Aug 14 03:42:12 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/va009039/code/uvchost/#812d604caad4