📄 uh3.c
字号:
/*
UH3.C: UH124 user interface library Level 3.
(C) Copyright TransDimension, Inc. All rights reserved.
Modification history
====================
18Aug2000 Original Release
*/
#include "types.h"
#include "usb.h"
#include "uh2.h"
#include "enr.h"
#include "err.h"
static U8 (*abort)() = NULL;
/* get device descriptor */
I16 UH_DevDesc(U8 dev, U8 *buf)
{
static U8 setup[] = {
RT_XFER_IN | RT_RECP_DEV | RT_TYPE_STD, /* bmRequestType */
GET_DESCRIPTOR, /* bRequest */
0, DEVICE, /* wValue */
0, 0, /* wIndex */
0, 0 /* wLength */
};
setup[SP_wLengthLSB] = (dev) ? DD_SIZE : 8;
return(UH_XferCtl(dev, EP0, setup, buf, abort));
}
/* get configutation descriptor */
I16 UH_DevConf(U8 dev, U8 index, U8 *buf)
{
static U8 setup[] = {
RT_XFER_IN | RT_RECP_DEV | RT_TYPE_STD, /* bmRequestType */
GET_DESCRIPTOR, /* bRequest */
0, CONFIGURATION, /* wValue */
0, 0, /* wIndex */
00, 04 /* wLength */
};
setup[SP_wValueLSB] = index;
return(UH_XferCtl(dev, EP0, setup, buf, abort));
}
/* set device address */
I16 UH_DevAddr(U8 dev)
{
static U8 setup[] = {
RT_RECP_DEV | RT_TYPE_STD, /* bmRequestType */
SET_ADDRESS, /* bRequest */
0, 0, /* wValue */
0, 0, /* wIndex */
0, 0 /* wLength */
};
setup[SP_wValueLSB] = dev & 0x7f;
return(UH_XferCtl(DEV0, EP0, setup, NULL, abort));
}
/* set device configuration */
I16 UH_SetConf(U8 dev, U8 conf)
{
static U8 setup[] = {
RT_RECP_DEV | RT_TYPE_STD, /* bmRequestType */
SET_CONFIGURATION, /* bRequest */
0, 0, /* wValue */
0, 0, /* wIndex */
0, 0 /* wLength */
};
setup[SP_wValueLSB] = conf;
return(UH_XferCtl(dev, EP0, setup, NULL, abort));
}
/* get device configuration */
I16 UH_GetConf(U8 dev, U8 *conf)
{
static U8 setup[] = {
RT_XFER_IN | RT_RECP_DEV | RT_TYPE_STD, /* bmRequestType */
GET_CONFIGURATION, /* bRequest */
0, 0, /* wValue */
0, 0, /* wIndex */
CF_SIZE, 0 /* wLength */
};
return(UH_XferCtl(dev, EP0, setup, conf, abort));
}
/* get device status */
I16 UH_DevStatus(U8 dev, U8 *buf)
{
static U8 setup[] = {
RT_XFER_IN | RT_TYPE_STD | RT_RECP_DEV, /* bmRequestType */
GET_STATUS, /* bRequest */
0, 0, /* wValue */
0, 0, /* wIndex */
ST_SIZE, 0 /* wLength */
};
return(UH_XferCtl(dev, EP0, setup, buf, abort));
}
/* get interface status */
I16 UH_IntfStatus(U8 dev, U8 intf, U8 *buf)
{
I16 r;
static U8 setup[] = {
RT_XFER_IN | RT_TYPE_STD | RT_RECP_ITF, /* bmRequestType */
GET_STATUS, /* bRequest */
0, 0, /* wValue */
0, 0, /* wIndex */
ST_SIZE, 0 /* wLength */
};
setup[SP_wIndexLSB] = intf;
return(UH_XferCtl(dev, EP0, setup, buf, abort));
}
/* get ep status */
I16 UH_EpStatus(U8 dev, U8 ep, I16 dir, U8 *buf)
{
ENR *enr;
static U8 setup[] = {
RT_XFER_IN | RT_TYPE_STD | RT_RECP_EPT, /* bmRequestType */
GET_STATUS, /* bRequest */
0, 0, /* wValue */
0, 0, /* wIndex */
ST_SIZE, 0 /* wLength */
};
if (!(enr = UH_EnrGet(dev, ep, dir)))
return(ERR_DEVEP);
setup[SP_wIndexLSB] = ep | enr->mode & ENR_DIR;
return(UH_XferCtl(dev, EP0, setup, buf, abort));
}
/* set/clear device feature */
I16 UH_DevFeature(U8 op, U8 dev, U8 feature)
{
static U8 setup[] = {
RT_TYPE_STD | RT_RECP_DEV, /* bmRequestType */
0, /* bRequest */
0, 0, /* wValue */
0, 0, /* wIndex */
0, 0 /* wLength */
};
setup[SP_bRequest] = (op) ? SET_FEATURE : CLEAR_FEATURE;
setup[SP_wValueLSB] = feature;
return(UH_XferCtl(dev, EP0, setup, NULL, abort));
}
/* set/clear interface feature */
I16 UH_IntfFeature(U8 op, U8 dev, U8 intf, U8 feature)
{
I16 r;
static U8 setup[] = {
RT_TYPE_STD | RT_RECP_ITF, /* bmRequestType */
0, /* bRequest */
0, 0, /* wValue */
0, 0, /* wIndex */
0, 0 /* wLength */
};
setup[SP_bRequest] = (op) ? SET_FEATURE : CLEAR_FEATURE;
setup[SP_wIndexLSB] = intf;
setup[SP_wValueLSB] = feature;
return(UH_XferCtl(dev, EP0, setup, NULL, abort));
}
/* set/clear end point feature */
I16 UH_EpFeature(U8 op, U8 dev, U8 ep, I16 dir, U8 feature)
{
ENR *enr;
static U8 setup[] = {
RT_TYPE_STD | RT_RECP_EPT, /* bmRequestType */
0, /* bRequest */
0, 0, /* wValue */
0, 0, /* wIndex */
0, 0 /* wLength */
};
if (!(enr = UH_EnrGet(dev, ep, dir)))
return(ERR_DEVEP);
setup[SP_bRequest] = (op) ? SET_FEATURE : CLEAR_FEATURE;
setup[SP_wIndexLSB] = ep | enr->mode & ENR_DIR;
setup[SP_wValueLSB] = feature;
return(UH_XferCtl(dev, EP0, setup, NULL, abort));
}
/* set interface */
I16 UH_SetIntf(U8 dev, U8 intf, U8 alter)
{
static U8 setup[] = {
RT_TYPE_STD | RT_RECP_ITF, /* bmRequestType */
SET_INTERFACE, /* bRequest */
0, 0, /* wValue */
0, 0, /* wIndex */
0, 0 /* wLength */
};
setup[SP_wIndexLSB] = intf;
setup[SP_wValueLSB] = alter;
return(UH_XferCtl(dev, EP0, setup, NULL, abort));
}
/* get interface */
I16 UH_GetIntf(U8 dev, U8 intf, U8 *buf)
{
static U8 setup[] = {
RT_XFER_IN | RT_TYPE_STD | RT_RECP_ITF, /* bmRequestType */
GET_INTERFACE, /* bRequest */
0, 0, /* wValue */
0, 0, /* wIndex */
IF_SIZE, 0 /* wLength */
};
setup[SP_wIndexLSB] = intf;
return(UH_XferCtl(dev, EP0, setup, buf, abort));
}
/* synch frame for iso xfer */
I16 UH_SyncFrame(U8 dev, U8 ep, U16 frame)
{
static U8 setup[] = {
RT_XFER_OUT, RT_TYPE_STD | RT_RECP_EPT, /* bmRequestType */
SYNCH_FRAME, /* bRequest */
0, 0, /* wValue */
0, 0, /* wIndex */
IF_SIZE, 0 /* wLength */
};
U8 buf[FR_SIZE];
setup[SP_wIndexLSB] = ep;
buf[0] = (frame >> 8) & 0xff;
buf[1] = frame & 0xff;
return(UH_XferCtl(dev, EP0, setup, buf, abort));
}
/* get hub descriptor */
I16 UH_HubDesc(U8 hub, U8 *buf)
{
/* hub desc size set for hub of less than 8 ports !! */
static U8 setup[] = {
RT_XFER_IN | RT_TYPE_CLS | RT_RECP_DEV, /* bmRequestType */
GET_DESCRIPTOR, /* bRequest */
0, HUB, /* wValue */
0, 0, /* wIndex */
HD_SIZE+2, 0 /* wLength */
};
return(UH_XferCtl(hub, EP0, setup, buf, abort));
}
/* set/clear hub/port feature */
I16 UH_PortFeature(U8 op, U8 hub, U8 port, U8 feature)
{
static U8 setup[] = {
0, /* bmRequestType */
0, /* bRequest */
0, 0, /* wValue */
0, 0, /* wIndex */
0, 0 /* wLength */
};
setup[SP_bRequest] = (op) ? SET_FEATURE : CLEAR_FEATURE;
setup[SP_bmRequestType] = RT_TYPE_CLS |
((port) ? RT_RECP_OTR : RT_RECP_DEV);
setup[SP_wIndexLSB] = port;
setup[SP_wValueLSB] = feature;
return(UH_XferCtl(hub, EP0, setup, NULL, abort));
}
/* get hub/port status */
I16 UH_PortStatus(U8 hub, U8 port, U8 *buf)
{
static U8 setup[] = {
0, /* bmRequestType */
GET_STATUS, /* bRequest */
0, 0, /* wValue */
0, 0, /* wIndex */
PS_SIZE, 0 /* wLength */
};
setup[SP_bmRequestType] = RT_XFER_IN | RT_TYPE_CLS;
setup[SP_bmRequestType] |= (port) ? RT_RECP_OTR : RT_RECP_DEV;
setup[SP_wIndexLSB] = port;
return(UH_XferCtl(hub, EP0, setup, buf, abort));
}
/* get bus state */
I16 UH_BusState(U8 hub, U8 port, U8 *buf)
{
static U8 setup[] = {
RT_XFER_IN | RT_TYPE_CLS | RT_RECP_OTR, /* bmRequestType */
GET_STATUS, /* bRequest */
0, 0, /* wValue */
0, 0, /* wIndex */
BS_SIZE, 0 /* wLength */
};
setup[SP_wIndexLSB] = port;
return(UH_XferCtl(hub, EP0, setup, buf, abort));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -