forked from len0rd/rockbox
Cosmetic changes only - tab, whitespace and brace policing
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14484 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
a6d52a8305
commit
03745f4ed3
13 changed files with 558 additions and 555 deletions
|
@ -118,14 +118,15 @@ timer_expired(struct timer * timer)
|
||||||
/* gets called by usb_stack_init() to register
|
/* gets called by usb_stack_init() to register
|
||||||
* this arcotg device conrtollder driver in the
|
* this arcotg device conrtollder driver in the
|
||||||
* stack. */
|
* stack. */
|
||||||
void usb_dcd_init(void) {
|
void usb_dcd_init(void)
|
||||||
|
{
|
||||||
usb_controller_register(&arcotg_dcd);
|
usb_controller_register(&arcotg_dcd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void usb_arcotg_dcd_init(void) {
|
void usb_arcotg_dcd_init(void)
|
||||||
|
{
|
||||||
struct timer t;
|
struct timer t;
|
||||||
int i, ep_num = 0;
|
int i, ep_num = 0;
|
||||||
|
|
||||||
|
@ -180,35 +181,36 @@ void usb_arcotg_dcd_init(void) {
|
||||||
/* put controller in device mode */
|
/* put controller in device mode */
|
||||||
UDC_USBMODE |= USB_MODE_CTRL_MODE_DEVICE;
|
UDC_USBMODE |= USB_MODE_CTRL_MODE_DEVICE;
|
||||||
|
|
||||||
/* init queue heads */
|
/* init queue heads */
|
||||||
qh_init(0, USB_RECV, USB_ENDPOINT_XFER_CONTROL, USB_MAX_CTRL_PAYLOAD, 0, 0);
|
qh_init(0, USB_RECV, USB_ENDPOINT_XFER_CONTROL, USB_MAX_CTRL_PAYLOAD, 0, 0);
|
||||||
qh_init(0, USB_SEND, USB_ENDPOINT_XFER_CONTROL, USB_MAX_CTRL_PAYLOAD, 0, 0);
|
qh_init(0, USB_SEND, USB_ENDPOINT_XFER_CONTROL, USB_MAX_CTRL_PAYLOAD, 0, 0);
|
||||||
|
|
||||||
UDC_ENDPOINTLISTADDR = (unsigned int)dev_qh;
|
UDC_ENDPOINTLISTADDR = (unsigned int)dev_qh;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usb_arcotg_dcd_shutdown(void) {
|
void usb_arcotg_dcd_shutdown(void)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void usb_arcotg_dcd_start(void) {
|
void usb_arcotg_dcd_start(void)
|
||||||
|
{
|
||||||
logf("start");
|
logf("start");
|
||||||
|
|
||||||
if (arcotg_dcd.device_driver != NULL) {
|
if (arcotg_dcd.device_driver != NULL) {
|
||||||
logf("YEEEEEEESSSSSSS");
|
logf("YEEEEEEESSSSSSS");
|
||||||
} else {
|
} else {
|
||||||
logf("NOOOOOO");
|
logf("NOOOOOO");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* clear stopped bit */
|
/* clear stopped bit */
|
||||||
dcd_controller.stopped = false;
|
dcd_controller.stopped = false;
|
||||||
|
|
||||||
UDC_USBCMD |= USB_CMD_RUN;
|
UDC_USBCMD |= USB_CMD_RUN;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usb_arcotg_dcd_stop(void) {
|
void usb_arcotg_dcd_stop(void)
|
||||||
|
{
|
||||||
logf("stop");
|
logf("stop");
|
||||||
|
|
||||||
/* set stopped bit */
|
/* set stopped bit */
|
||||||
|
@ -217,8 +219,8 @@ void usb_arcotg_dcd_stop(void) {
|
||||||
UDC_USBCMD &= ~USB_CMD_RUN;
|
UDC_USBCMD &= ~USB_CMD_RUN;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usb_arcotg_dcd_irq(void) {
|
void usb_arcotg_dcd_irq(void)
|
||||||
|
{
|
||||||
if (dcd_controller.stopped == true) {
|
if (dcd_controller.stopped == true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -241,10 +243,10 @@ void usb_arcotg_dcd_irq(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (UDC_ENDPTCOMPLETE) {
|
if (UDC_ENDPTCOMPLETE) {
|
||||||
UDC_ENDPTCOMPLETE = UDC_ENDPTCOMPLETE;
|
UDC_ENDPTCOMPLETE = UDC_ENDPTCOMPLETE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (UDC_USBSTS & USB_STS_PORT_CHANGE) {
|
if (UDC_USBSTS & USB_STS_PORT_CHANGE) {
|
||||||
port_change_int();
|
port_change_int();
|
||||||
}
|
}
|
||||||
|
@ -269,12 +271,12 @@ void usb_arcotg_dcd_irq(void) {
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
/* interrupt handlers */
|
/* interrupt handlers */
|
||||||
|
|
||||||
static void setup_received_int(struct usb_ctrlrequest* request) {
|
static void setup_received_int(struct usb_ctrlrequest* request)
|
||||||
|
{
|
||||||
int error = 0;
|
int error = 0;
|
||||||
uint8_t address = 0;
|
uint8_t address = 0;
|
||||||
int handled = 0; /* set to zero if we do not handle the message, */
|
int handled = 0; /* set to zero if we do not handle the message, */
|
||||||
/* and should pass it to the driver */
|
/* and should pass it to the driver */
|
||||||
|
|
||||||
logf("setup_int");
|
logf("setup_int");
|
||||||
into_usb_ctrlrequest(request);
|
into_usb_ctrlrequest(request);
|
||||||
|
@ -324,16 +326,16 @@ static void setup_received_int(struct usb_ctrlrequest* request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (handled == 0) {
|
if (handled == 0) {
|
||||||
handled = 1; /* dont pass it to driver */
|
handled = 1; /* dont pass it to driver */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
if (rc == 0) {
|
if (rc == 0) {
|
||||||
/* send status only if _arcotg_ep_set_halt success */
|
/* send status only if _arcotg_ep_set_halt success */
|
||||||
if (ep0_prime_status(udc, EP_DIR_IN))
|
if (ep0_prime_status(udc, EP_DIR_IN))
|
||||||
Ep0Stall(udc);
|
Ep0Stall(udc);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,8 +360,8 @@ static void setup_received_int(struct usb_ctrlrequest* request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void port_change_int(void) {
|
static void port_change_int(void)
|
||||||
|
{
|
||||||
//logf("port_change_int");
|
//logf("port_change_int");
|
||||||
uint32_t tmp;
|
uint32_t tmp;
|
||||||
enum usb_device_speed speed = USB_SPEED_UNKNOWN;
|
enum usb_device_speed speed = USB_SPEED_UNKNOWN;
|
||||||
|
@ -386,7 +388,7 @@ static void port_change_int(void) {
|
||||||
|
|
||||||
/* update speed */
|
/* update speed */
|
||||||
arcotg_dcd.speed = speed;
|
arcotg_dcd.speed = speed;
|
||||||
|
|
||||||
/* update USB state */
|
/* update USB state */
|
||||||
if (!dcd_controller.resume_state) {
|
if (!dcd_controller.resume_state) {
|
||||||
dcd_controller.usb_state = USB_STATE_DEFAULT;
|
dcd_controller.usb_state = USB_STATE_DEFAULT;
|
||||||
|
@ -398,8 +400,8 @@ static void port_change_int(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void suspend_int(void) {
|
static void suspend_int(void)
|
||||||
|
{
|
||||||
//logf("suspend_int");
|
//logf("suspend_int");
|
||||||
dcd_controller.resume_state = dcd_controller.usb_state;
|
dcd_controller.resume_state = dcd_controller.usb_state;
|
||||||
dcd_controller.usb_state = USB_STATE_SUSPENDED;
|
dcd_controller.usb_state = USB_STATE_SUSPENDED;
|
||||||
|
@ -410,8 +412,8 @@ static void suspend_int(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void resume_int(void) {
|
static void resume_int(void)
|
||||||
|
{
|
||||||
//logf("resume_int");
|
//logf("resume_int");
|
||||||
dcd_controller.usb_state = dcd_controller.resume_state;
|
dcd_controller.usb_state = dcd_controller.resume_state;
|
||||||
dcd_controller.resume_state = USB_STATE_NOTATTACHED;
|
dcd_controller.resume_state = USB_STATE_NOTATTACHED;
|
||||||
|
@ -422,8 +424,8 @@ static void resume_int(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void reset_int(void) {
|
static void reset_int(void)
|
||||||
|
{
|
||||||
//logf("reset_int");
|
//logf("reset_int");
|
||||||
struct timer t;
|
struct timer t;
|
||||||
|
|
||||||
|
@ -459,12 +461,12 @@ static void reset_int(void) {
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
/* usb controller ops */
|
/* usb controller ops */
|
||||||
|
|
||||||
int usb_arcotg_dcd_enable(struct usb_ep* ep) {
|
int usb_arcotg_dcd_enable(struct usb_ep* ep)
|
||||||
|
{
|
||||||
unsigned short max = 0;
|
unsigned short max = 0;
|
||||||
unsigned char mult = 0, zlt = 0;
|
unsigned char mult = 0, zlt = 0;
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
char *val = NULL; /* for debug */
|
char *val = NULL; /* for debug */
|
||||||
|
|
||||||
/* catch bogus parameter */
|
/* catch bogus parameter */
|
||||||
if (!ep) {
|
if (!ep) {
|
||||||
|
@ -496,105 +498,105 @@ int usb_arcotg_dcd_enable(struct usb_ep* ep) {
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
switch (ep->desc->bmAttributes & 0x03) {
|
switch (ep->desc->bmAttributes & 0x03) {
|
||||||
case USB_ENDPOINT_XFER_BULK:
|
case USB_ENDPOINT_XFER_BULK:
|
||||||
if (strstr(ep->ep.name, "-iso") || strstr(ep->ep.name, "-int")) {
|
if (strstr(ep->ep.name, "-iso") || strstr(ep->ep.name, "-int")) {
|
||||||
goto en_done;
|
goto en_done;
|
||||||
}
|
}
|
||||||
mult = 0;
|
mult = 0;
|
||||||
zlt = 1;
|
zlt = 1;
|
||||||
|
|
||||||
switch (arcotg_dcd.speed) {
|
switch (arcotg_dcd.speed) {
|
||||||
case USB_SPEED_HIGH:
|
case USB_SPEED_HIGH:
|
||||||
if ((max == 128) || (max == 256) || (max == 512)) {
|
if ((max == 128) || (max == 256) || (max == 512)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
switch (max) {
|
switch (max) {
|
||||||
case 4:
|
case 4:
|
||||||
case 8:
|
case 8:
|
||||||
case 16:
|
case 16:
|
||||||
case 32:
|
case 32:
|
||||||
case 64:
|
case 64:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
+ case USB_SPEED_LOW:
|
+ case USB_SPEED_LOW:
|
||||||
+ goto en_done;
|
+ goto en_done;
|
||||||
+ }
|
+ }
|
||||||
+ }
|
+ }
|
||||||
+ break;
|
+ break;
|
||||||
+ case USB_ENDPOINT_XFER_INT:
|
+ case USB_ENDPOINT_XFER_INT:
|
||||||
+ if (strstr(ep->ep.name, "-iso")) /* bulk is ok */
|
+ if (strstr(ep->ep.name, "-iso")) /* bulk is ok */
|
||||||
+ goto en_done;
|
+ goto en_done;
|
||||||
+ mult = 0;
|
+ mult = 0;
|
||||||
+ zlt = 1;
|
+ zlt = 1;
|
||||||
+ switch (udc->gadget.speed) {
|
+ switch (udc->gadget.speed) {
|
||||||
+ case USB_SPEED_HIGH:
|
+ case USB_SPEED_HIGH:
|
||||||
+ if (max <= 1024)
|
+ if (max <= 1024)
|
||||||
+ break;
|
+ break;
|
||||||
+ case USB_SPEED_FULL:
|
+ case USB_SPEED_FULL:
|
||||||
+ if (max <= 64)
|
+ if (max <= 64)
|
||||||
+ break;
|
+ break;
|
||||||
+ default:
|
+ default:
|
||||||
+ if (max <= 8)
|
+ if (max <= 8)
|
||||||
+ break;
|
+ break;
|
||||||
+ goto en_done;
|
+ goto en_done;
|
||||||
+ }
|
+ }
|
||||||
+ break;
|
+ break;
|
||||||
+ case USB_ENDPOINT_XFER_ISOC:
|
+ case USB_ENDPOINT_XFER_ISOC:
|
||||||
+ if (strstr(ep->ep.name, "-bulk") || strstr(ep->ep.name, "-int"))
|
+ if (strstr(ep->ep.name, "-bulk") || strstr(ep->ep.name, "-int"))
|
||||||
+ goto en_done;
|
+ goto en_done;
|
||||||
+ mult = (unsigned char)
|
+ mult = (unsigned char)
|
||||||
+ (1 + ((le16_to_cpu(desc->wMaxPacketSize) >> 11) & 0x03));
|
+ (1 + ((le16_to_cpu(desc->wMaxPacketSize) >> 11) & 0x03));
|
||||||
+ zlt = 0;
|
+ zlt = 0;
|
||||||
+ switch (udc->gadget.speed) {
|
+ switch (udc->gadget.speed) {
|
||||||
+ case USB_SPEED_HIGH:
|
+ case USB_SPEED_HIGH:
|
||||||
+ if (max <= 1024)
|
+ if (max <= 1024)
|
||||||
+ break;
|
+ break;
|
||||||
+ case USB_SPEED_FULL:
|
+ case USB_SPEED_FULL:
|
||||||
+ if (max <= 1023)
|
+ if (max <= 1023)
|
||||||
+ break;
|
+ break;
|
||||||
+ default:
|
+ default:
|
||||||
+ goto en_done;
|
+ goto en_done;
|
||||||
+ }
|
+ }
|
||||||
+ break;
|
+ break;
|
||||||
+ case USB_ENDPOINT_XFER_CONTROL:
|
+ case USB_ENDPOINT_XFER_CONTROL:
|
||||||
+ if (strstr(ep->ep.name, "-iso") || strstr(ep->ep.name, "-int"))
|
+ if (strstr(ep->ep.name, "-iso") || strstr(ep->ep.name, "-int"))
|
||||||
+ goto en_done;
|
+ goto en_done;
|
||||||
+ mult = 0;
|
+ mult = 0;
|
||||||
+ zlt = 1;
|
+ zlt = 1;
|
||||||
+ switch (udc->gadget.speed) {
|
+ switch (udc->gadget.speed) {
|
||||||
+ case USB_SPEED_HIGH:
|
+ case USB_SPEED_HIGH:
|
||||||
+ case USB_SPEED_FULL:
|
+ case USB_SPEED_FULL:
|
||||||
+ switch (max) {
|
+ switch (max) {
|
||||||
+ case 1:
|
+ case 1:
|
||||||
+ case 2:
|
+ case 2:
|
||||||
+ case 4:
|
+ case 4:
|
||||||
+ case 8:
|
+ case 8:
|
||||||
+ case 16:
|
+ case 16:
|
||||||
+ case 32:
|
+ case 32:
|
||||||
+ case 64:
|
+ case 64:
|
||||||
+ break;
|
+ break;
|
||||||
+ default:
|
+ default:
|
||||||
+ goto en_done;
|
+ goto en_done;
|
||||||
+ }
|
+ }
|
||||||
+ case USB_SPEED_LOW:
|
+ case USB_SPEED_LOW:
|
||||||
+ switch (max) {
|
+ switch (max) {
|
||||||
+ case 1:
|
+ case 1:
|
||||||
+ case 2:
|
+ case 2:
|
||||||
+ case 4:
|
+ case 4:
|
||||||
+ case 8:
|
+ case 8:
|
||||||
+ break;
|
+ break;
|
||||||
+ default:
|
+ default:
|
||||||
+ goto en_done;
|
+ goto en_done;
|
||||||
+ }
|
+ }
|
||||||
+ default:
|
+ default:
|
||||||
+ goto en_done;
|
+ goto en_done;
|
||||||
+ }
|
+ }
|
||||||
+ break;
|
+ break;
|
||||||
+
|
+
|
||||||
+ default:
|
+ default:
|
||||||
+ goto en_done;
|
+ goto en_done;
|
||||||
+ }
|
+ }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* here initialize variable of ep */
|
/* here initialize variable of ep */
|
||||||
|
@ -643,8 +645,8 @@ int usb_arcotg_dcd_enable(struct usb_ep* ep) {
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
int usb_arcotg_dcd_set_halt(struct usb_ep* ep, bool halt) {
|
int usb_arcotg_dcd_set_halt(struct usb_ep* ep, bool halt)
|
||||||
|
{
|
||||||
int status = -EOPNOTSUPP; /* operation not supported */
|
int status = -EOPNOTSUPP; /* operation not supported */
|
||||||
unsigned char dir = 0;
|
unsigned char dir = 0;
|
||||||
unsigned int tmp_epctrl = 0;
|
unsigned int tmp_epctrl = 0;
|
||||||
|
@ -688,8 +690,8 @@ out:
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
int usb_arcotg_dcd_send(struct usb_ep* ep, struct usb_response* res) {
|
int usb_arcotg_dcd_send(struct usb_ep* ep, struct usb_response* res)
|
||||||
|
{
|
||||||
char* ptr;
|
char* ptr;
|
||||||
int todo, error, size, done = 0;
|
int todo, error, size, done = 0;
|
||||||
int index = 1; /* use as default ep0 tx qh and td */
|
int index = 1; /* use as default ep0 tx qh and td */
|
||||||
|
@ -750,8 +752,8 @@ int usb_arcotg_dcd_send(struct usb_ep* ep, struct usb_response* res) {
|
||||||
return done;
|
return done;
|
||||||
}
|
}
|
||||||
|
|
||||||
int usb_arcotg_dcd_receive(struct usb_ep* ep, struct usb_response* res) {
|
int usb_arcotg_dcd_receive(struct usb_ep* ep, struct usb_response* res)
|
||||||
|
{
|
||||||
char* ptr;
|
char* ptr;
|
||||||
int todo, error, size, done = 0;
|
int todo, error, size, done = 0;
|
||||||
int index = 0; /* use as default ep0 rx qh and td */
|
int index = 0; /* use as default ep0 rx qh and td */
|
||||||
|
@ -812,9 +814,9 @@ int usb_arcotg_dcd_receive(struct usb_ep* ep, struct usb_response* res) {
|
||||||
/* lifecylce */
|
/* lifecylce */
|
||||||
|
|
||||||
static void qh_init(unsigned char ep_num, unsigned char dir, unsigned char ep_type,
|
static void qh_init(unsigned char ep_num, unsigned char dir, unsigned char ep_type,
|
||||||
unsigned int max_pkt_len, unsigned int zlt, unsigned char mult) {
|
unsigned int max_pkt_len, unsigned int zlt, unsigned char mult)
|
||||||
|
{
|
||||||
struct dqh *qh = &dev_qh[2 * ep_num + dir];
|
struct dqh *qh = &dev_qh[2 * ep_num + dir];
|
||||||
uint32_t tmp = 0;
|
uint32_t tmp = 0;
|
||||||
memset(qh, 0, sizeof(struct dqh));
|
memset(qh, 0, sizeof(struct dqh));
|
||||||
|
|
||||||
|
@ -856,8 +858,8 @@ static void qh_init(unsigned char ep_num, unsigned char dir, unsigned char ep_ty
|
||||||
logf("qh: init %d", (2 * ep_num + dir));
|
logf("qh: init %d", (2 * ep_num + dir));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void td_init(struct dtd* td, void* buffer, uint32_t todo) {
|
static void td_init(struct dtd* td, void* buffer, uint32_t todo)
|
||||||
|
{
|
||||||
/* see 32.14.5.2 Building a Transfer Descriptor */
|
/* see 32.14.5.2 Building a Transfer Descriptor */
|
||||||
|
|
||||||
/* init first 7 dwords with 0 */
|
/* init first 7 dwords with 0 */
|
||||||
|
@ -878,8 +880,8 @@ static void td_init(struct dtd* td, void* buffer, uint32_t todo) {
|
||||||
td->buf_ptr0 = (uint32_t)buffer;
|
td->buf_ptr0 = (uint32_t)buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ep_setup(unsigned char ep_num, unsigned char dir, unsigned char ep_type) {
|
static void ep_setup(unsigned char ep_num, unsigned char dir, unsigned char ep_type)
|
||||||
|
{
|
||||||
unsigned int tmp_epctrl = 0;
|
unsigned int tmp_epctrl = 0;
|
||||||
struct timer t;
|
struct timer t;
|
||||||
|
|
||||||
|
@ -901,23 +903,23 @@ static void ep_setup(unsigned char ep_num, unsigned char dir, unsigned char ep_t
|
||||||
}
|
}
|
||||||
|
|
||||||
UDC_ENDPTCTRL(ep_num) = tmp_epctrl;
|
UDC_ENDPTCTRL(ep_num) = tmp_epctrl;
|
||||||
|
|
||||||
/* wait for the write reg to finish */
|
/* wait for the write reg to finish */
|
||||||
|
|
||||||
timer_set(&t, SETUP_TIMER);
|
timer_set(&t, SETUP_TIMER);
|
||||||
while (!(UDC_ENDPTCTRL(ep_num) & (tmp_epctrl & (EPCTRL_TX_ENABLE | EPCTRL_RX_ENABLE)))) {
|
while (!(UDC_ENDPTCTRL(ep_num) & (tmp_epctrl & (EPCTRL_TX_ENABLE | EPCTRL_RX_ENABLE)))) {
|
||||||
if (timer_expired(&t)) {
|
if (timer_expired(&t)) {
|
||||||
logf("TIMEOUT: enable ep");
|
logf("TIMEOUT: enable ep");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
/* helpers for sending/receiving */
|
/* helpers for sending/receiving */
|
||||||
|
|
||||||
static int td_enqueue(struct dtd* td, struct dqh* qh, unsigned int mask) {
|
static int td_enqueue(struct dtd* td, struct dqh* qh, unsigned int mask)
|
||||||
|
{
|
||||||
struct timer t;
|
struct timer t;
|
||||||
|
|
||||||
qh->dtd_ovrl.next_dtd = (unsigned int)td;
|
qh->dtd_ovrl.next_dtd = (unsigned int)td;
|
||||||
|
@ -940,8 +942,8 @@ static int td_enqueue(struct dtd* td, struct dqh* qh, unsigned int mask) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int td_wait(struct dtd* td, unsigned int mask) {
|
static int td_wait(struct dtd* td, unsigned int mask)
|
||||||
|
{
|
||||||
struct timer t;
|
struct timer t;
|
||||||
timer_set(&t, TRANSFER_TIMER);
|
timer_set(&t, TRANSFER_TIMER);
|
||||||
|
|
||||||
|
@ -960,8 +962,8 @@ static int td_wait(struct dtd* td, unsigned int mask) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int usb_ack(struct usb_ctrlrequest * s, int error) {
|
static int usb_ack(struct usb_ctrlrequest * s, int error)
|
||||||
|
{
|
||||||
if (error) {
|
if (error) {
|
||||||
logf("STALLing ep0");
|
logf("STALLing ep0");
|
||||||
UDC_ENDPTCTRL0 |= 1 << 16; /* stall */
|
UDC_ENDPTCTRL0 |= 1 << 16; /* stall */
|
||||||
|
|
|
@ -42,8 +42,8 @@
|
||||||
|
|
||||||
#define ep_is_in(EP) (((EP)->desc->bEndpointAddress & USB_DIR_IN)==USB_DIR_IN)
|
#define ep_is_in(EP) (((EP)->desc->bEndpointAddress & USB_DIR_IN)==USB_DIR_IN)
|
||||||
|
|
||||||
#define EP_DIR_IN 1
|
#define EP_DIR_IN 1
|
||||||
#define EP_DIR_OUT 0
|
#define EP_DIR_OUT 0
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
|
@ -150,7 +150,7 @@ bool usb_detect(void)
|
||||||
if ((usbstatus1 == true) && (prev_usbstatus1 == false)) {
|
if ((usbstatus1 == true) && (prev_usbstatus1 == false)) {
|
||||||
usb_stack_start();
|
usb_stack_start();
|
||||||
} else if ((usbstatus1 == false) && (prev_usbstatus1 == true)) {
|
} else if ((usbstatus1 == false) && (prev_usbstatus1 == true)) {
|
||||||
usb_stack_stop();
|
usb_stack_stop();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if ((usbstatus1 == true) && (prev_usbstatus1 == false)) {
|
if ((usbstatus1 == true) && (prev_usbstatus1 == false)) {
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
#define USBSTACK_CAPS 0
|
#define USBSTACK_CAPS 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define CONTROLLER_DEVICE (1 << 0)
|
#define CONTROLLER_DEVICE (1 << 0)
|
||||||
#define CONTROLLER_HOST (1 << 1)
|
#define CONTROLLER_HOST (1 << 1)
|
||||||
|
|
||||||
#endif /*_USBSTACK_CONFIG_H_*/
|
#endif /*_USBSTACK_CONFIG_H_*/
|
||||||
|
|
|
@ -38,7 +38,7 @@ struct usb_response {
|
||||||
struct usb_ep {
|
struct usb_ep {
|
||||||
const char name[15];
|
const char name[15];
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
uint32_t ep_num; /* which endpoint? */
|
uint32_t ep_num; /* which endpoint? */
|
||||||
uint32_t pipe_num; /* which pipe? */
|
uint32_t pipe_num; /* which pipe? */
|
||||||
uint32_t maxpacket;
|
uint32_t maxpacket;
|
||||||
bool claimed;
|
bool claimed;
|
||||||
|
|
|
@ -23,58 +23,58 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "usbstack/core.h"
|
#include "usbstack/core.h"
|
||||||
|
|
||||||
static int usb_descriptor_fillbuf(void* buf, unsigned buflen, struct usb_descriptor_header** src) {
|
static int usb_descriptor_fillbuf(void* buf, unsigned buflen, struct usb_descriptor_header** src)
|
||||||
|
{
|
||||||
uint8_t* dest = buf;
|
uint8_t* dest = buf;
|
||||||
|
|
||||||
if (!src) {
|
if (!src) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* fill buffer from src[] until null descriptor ptr */
|
/* fill buffer from src[] until null descriptor ptr */
|
||||||
for (; 0 != *src; src++) {
|
for (; 0 != *src; src++) {
|
||||||
unsigned len = (*src)->bLength;
|
unsigned len = (*src)->bLength;
|
||||||
|
|
||||||
logf("len: %d", len);
|
logf("len: %d", len);
|
||||||
|
|
||||||
if (len > buflen)
|
if (len > buflen)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
memcpy(dest, *src, len);
|
memcpy(dest, *src, len);
|
||||||
buflen -= len;
|
buflen -= len;
|
||||||
dest += len;
|
dest += len;
|
||||||
}
|
}
|
||||||
return dest - (uint8_t *)buf;
|
return dest - (uint8_t *)buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
int usb_stack_configdesc(const struct usb_config_descriptor* config, void* buf, unsigned length, struct usb_descriptor_header** desc) {
|
int usb_stack_configdesc(const struct usb_config_descriptor* config, void* buf, unsigned length, struct usb_descriptor_header** desc)
|
||||||
|
{
|
||||||
struct usb_config_descriptor* cp = buf;
|
struct usb_config_descriptor* cp = buf;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
if (length < USB_DT_CONFIG_SIZE || !desc) {
|
if (length < USB_DT_CONFIG_SIZE || !desc) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* config descriptor first */
|
|
||||||
*cp = *config;
|
|
||||||
|
|
||||||
/* then interface/endpoint/class/vendor/... */
|
/* config descriptor first */
|
||||||
len = usb_descriptor_fillbuf(USB_DT_CONFIG_SIZE + (uint8_t*)buf, length - USB_DT_CONFIG_SIZE, desc);
|
*cp = *config;
|
||||||
|
|
||||||
if (len < 0) {
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|
||||||
len += USB_DT_CONFIG_SIZE;
|
|
||||||
if (len > 0xffff) {
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* patch up the config descriptor */
|
/* then interface/endpoint/class/vendor/... */
|
||||||
cp->bLength = USB_DT_CONFIG_SIZE;
|
len = usb_descriptor_fillbuf(USB_DT_CONFIG_SIZE + (uint8_t*)buf, length - USB_DT_CONFIG_SIZE, desc);
|
||||||
cp->bDescriptorType = USB_DT_CONFIG;
|
|
||||||
cp->wTotalLength = len;
|
if (len < 0) {
|
||||||
cp->bmAttributes |= USB_CONFIG_ATT_ONE;
|
return len;
|
||||||
|
}
|
||||||
return len;
|
|
||||||
|
len += USB_DT_CONFIG_SIZE;
|
||||||
|
if (len > 0xffff) {
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* patch up the config descriptor */
|
||||||
|
cp->bLength = USB_DT_CONFIG_SIZE;
|
||||||
|
cp->bDescriptorType = USB_DT_CONFIG;
|
||||||
|
cp->wTotalLength = len;
|
||||||
|
cp->bmAttributes |= USB_CONFIG_ATT_ONE;
|
||||||
|
|
||||||
|
return len;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,26 +39,26 @@ static void bind_device_driver(struct usb_device_driver* driver);
|
||||||
/**
|
/**
|
||||||
* Initialize usb stack.
|
* Initialize usb stack.
|
||||||
*/
|
*/
|
||||||
void usb_stack_init(void) {
|
void usb_stack_init(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
logf("usb_stack_init");
|
||||||
|
|
||||||
int i;
|
|
||||||
logf("usb_stack_init");
|
|
||||||
|
|
||||||
/* init datastructures */
|
/* init datastructures */
|
||||||
usbcore.controller[0] = NULL;
|
usbcore.controller[0] = NULL;
|
||||||
usbcore.controller[1] = NULL;
|
usbcore.controller[1] = NULL;
|
||||||
usbcore.active_controller = NULL;
|
usbcore.active_controller = NULL;
|
||||||
usbcore.device_driver = NULL;
|
usbcore.device_driver = NULL;
|
||||||
usbcore.running = false;
|
usbcore.running = false;
|
||||||
|
|
||||||
memset(&device_driver_names, 0, USB_STACK_MAX_SETTINGS_NAME);
|
memset(&device_driver_names, 0, USB_STACK_MAX_SETTINGS_NAME);
|
||||||
|
|
||||||
/* init arrays */
|
/* init arrays */
|
||||||
for (i = 0; i < NUM_DRIVERS; i++) {
|
for (i = 0; i < NUM_DRIVERS; i++) {
|
||||||
usbcore.device_drivers[i] = NULL;
|
usbcore.device_drivers[i] = NULL;
|
||||||
usbcore.host_drivers[i] = NULL;
|
usbcore.host_drivers[i] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* init controllers */
|
/* init controllers */
|
||||||
#if (USBSTACK_CAPS & CONTROLLER_DEVICE)
|
#if (USBSTACK_CAPS & CONTROLLER_DEVICE)
|
||||||
usb_dcd_init();
|
usb_dcd_init();
|
||||||
|
@ -77,31 +77,31 @@ void usb_stack_init(void) {
|
||||||
* Start processing of usb stack. This function init
|
* Start processing of usb stack. This function init
|
||||||
* active usb controller.
|
* active usb controller.
|
||||||
*/
|
*/
|
||||||
void usb_stack_start(void) {
|
void usb_stack_start(void)
|
||||||
|
{
|
||||||
|
/* are we allready running? */
|
||||||
|
if (usbcore.running) {
|
||||||
|
logf("allready running!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (usbcore.active_controller == NULL) {
|
||||||
|
logf("no active controller!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* are we allready running? */
|
|
||||||
if (usbcore.running) {
|
|
||||||
logf("allready running!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (usbcore.active_controller == NULL) {
|
|
||||||
logf("no active controller!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* forward to controller */
|
/* forward to controller */
|
||||||
logf("starting controller");
|
logf("starting controller");
|
||||||
usbcore.active_controller->start();
|
usbcore.active_controller->start();
|
||||||
usbcore.running = true;
|
usbcore.running = true;
|
||||||
|
|
||||||
/* look if started controller is a device controller
|
/* look if started controller is a device controller
|
||||||
* and if it has a device driver bind to it */
|
* and if it has a device driver bind to it */
|
||||||
logf("check for auto bind");
|
logf("check for auto bind");
|
||||||
if (usbcore.active_controller->type == DEVICE) {
|
if (usbcore.active_controller->type == DEVICE) {
|
||||||
if (usbcore.active_controller->device_driver == NULL && usbcore.device_driver != NULL) {
|
if (usbcore.active_controller->device_driver == NULL && usbcore.device_driver != NULL) {
|
||||||
/* bind driver */
|
/* bind driver */
|
||||||
logf("binding...");
|
logf("binding...");
|
||||||
bind_device_driver(usbcore.device_driver);
|
bind_device_driver(usbcore.device_driver);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,15 +111,15 @@ void usb_stack_start(void) {
|
||||||
* Stop processing of usb stack. This function shutsdown
|
* Stop processing of usb stack. This function shutsdown
|
||||||
* active usb controller.
|
* active usb controller.
|
||||||
*/
|
*/
|
||||||
void usb_stack_stop(void) {
|
void usb_stack_stop(void)
|
||||||
|
{
|
||||||
|
/* are we allready stopped? */
|
||||||
|
if (usbcore.running == false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* are we allready stopped? */
|
|
||||||
if (usbcore.running == false) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* forward to controller */
|
/* forward to controller */
|
||||||
usbcore.active_controller->stop();
|
usbcore.active_controller->stop();
|
||||||
usbcore.running = false;
|
usbcore.running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,8 +127,8 @@ void usb_stack_stop(void) {
|
||||||
* Gets called by upper layers to indicate that there is
|
* Gets called by upper layers to indicate that there is
|
||||||
* an interrupt waiting for the controller.
|
* an interrupt waiting for the controller.
|
||||||
*/
|
*/
|
||||||
void usb_stack_irq(void) {
|
void usb_stack_irq(void)
|
||||||
|
{
|
||||||
/* simply notify usb controller */
|
/* simply notify usb controller */
|
||||||
if (usbcore.active_controller != NULL && usbcore.active_controller->irq != NULL) {
|
if (usbcore.active_controller != NULL && usbcore.active_controller->irq != NULL) {
|
||||||
usbcore.active_controller->irq();
|
usbcore.active_controller->irq();
|
||||||
|
@ -140,7 +140,8 @@ void usb_stack_irq(void) {
|
||||||
* to call for maintanence. We need to check if a new device has connected,
|
* to call for maintanence. We need to check if a new device has connected,
|
||||||
* find suitable drivers for new devices.
|
* find suitable drivers for new devices.
|
||||||
*/
|
*/
|
||||||
void usb_stack_work(void) {
|
void usb_stack_work(void)
|
||||||
|
{
|
||||||
/* TODO will be used with host device controllers
|
/* TODO will be used with host device controllers
|
||||||
* and needs to be called in a loop (thread) */
|
* and needs to be called in a loop (thread) */
|
||||||
}
|
}
|
||||||
|
@ -153,8 +154,8 @@ void usb_stack_work(void) {
|
||||||
* @param ctrl pointer to controller to register.
|
* @param ctrl pointer to controller to register.
|
||||||
* @return 0 on success else a defined error code.
|
* @return 0 on success else a defined error code.
|
||||||
*/
|
*/
|
||||||
int usb_controller_register(struct usb_controller* ctrl) {
|
int usb_controller_register(struct usb_controller* ctrl)
|
||||||
|
{
|
||||||
if (ctrl == NULL) {
|
if (ctrl == NULL) {
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -220,21 +221,21 @@ int usb_controller_unregister(struct usb_controller* ctrl) {
|
||||||
*
|
*
|
||||||
* @param type of controller to activate.
|
* @param type of controller to activate.
|
||||||
*/
|
*/
|
||||||
void usb_controller_select(int type) {
|
void usb_controller_select(int type)
|
||||||
|
{
|
||||||
struct usb_controller* new = NULL;
|
struct usb_controller* new = NULL;
|
||||||
|
|
||||||
/* check if a controller of the wanted type is already loaded */
|
/* check if a controller of the wanted type is already loaded */
|
||||||
if (usbcore.active_controller != NULL && (int)usbcore.active_controller->type == type) {
|
if (usbcore.active_controller != NULL && (int)usbcore.active_controller->type == type) {
|
||||||
logf("controller already set");
|
logf("controller already set");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
logf("usb_controller_select");
|
logf("usb_controller_select");
|
||||||
logf(" -> type: %d", type);
|
logf(" -> type: %d", type);
|
||||||
|
|
||||||
|
usbcore.mode = type;
|
||||||
|
|
||||||
usbcore.mode = type;
|
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case DEVICE:
|
case DEVICE:
|
||||||
new = usbcore.controller[0];
|
new = usbcore.controller[0];
|
||||||
|
@ -246,20 +247,20 @@ void usb_controller_select(int type) {
|
||||||
|
|
||||||
/* if there is only one controller, stop here */
|
/* if there is only one controller, stop here */
|
||||||
if (new == NULL) {
|
if (new == NULL) {
|
||||||
logf("no suitable cntrl found");
|
logf("no suitable cntrl found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* shutdown current used controller */
|
/* shutdown current used controller */
|
||||||
if (usbcore.active_controller != NULL) {
|
if (usbcore.active_controller != NULL) {
|
||||||
logf("shuting down old one");
|
logf("shuting down old one");
|
||||||
usbcore.active_controller->shutdown();
|
usbcore.active_controller->shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set and init new controller */
|
/* set and init new controller */
|
||||||
usbcore.active_controller = new;
|
usbcore.active_controller = new;
|
||||||
logf("init controller");
|
logf("init controller");
|
||||||
usbcore.active_controller->init();
|
usbcore.active_controller->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
int usb_stack_get_mode(void) {
|
int usb_stack_get_mode(void) {
|
||||||
|
@ -272,10 +273,10 @@ int usb_stack_get_mode(void) {
|
||||||
* @param driver pointer to an usb_device_driver struct.
|
* @param driver pointer to an usb_device_driver struct.
|
||||||
* @return 0 on success, else a defined error code.
|
* @return 0 on success, else a defined error code.
|
||||||
*/
|
*/
|
||||||
int usb_device_driver_register(struct usb_device_driver* driver) {
|
int usb_device_driver_register(struct usb_device_driver* driver)
|
||||||
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (driver == NULL) {
|
if (driver == NULL) {
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -284,109 +285,109 @@ int usb_device_driver_register(struct usb_device_driver* driver) {
|
||||||
logf("usb_stack: register usb driver");
|
logf("usb_stack: register usb driver");
|
||||||
for (i = 0; i < NUM_DRIVERS; i++) {
|
for (i = 0; i < NUM_DRIVERS; i++) {
|
||||||
if (usbcore.device_drivers[i] == NULL) {
|
if (usbcore.device_drivers[i] == NULL) {
|
||||||
usbcore.device_drivers[i] = driver;
|
usbcore.device_drivers[i] = driver;
|
||||||
update_driver_names(device_driver_names);
|
update_driver_names(device_driver_names);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
update_driver_names(device_driver_names);
|
update_driver_names(device_driver_names);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int usb_device_driver_bind(const char* name) {
|
int usb_device_driver_bind(const char* name) {
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
struct usb_device_driver *tmp = NULL;
|
struct usb_device_driver *tmp = NULL;
|
||||||
struct usb_device_driver *driver = NULL;
|
struct usb_device_driver *driver = NULL;
|
||||||
|
|
||||||
if (name == NULL) {
|
if (name == NULL) {
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* look for driver */
|
/* look for driver */
|
||||||
logf("looking for driver %s", name);
|
logf("looking for driver %s", name);
|
||||||
for (i = 0; i < NUM_DRIVERS; i++) {
|
for (i = 0; i < NUM_DRIVERS; i++) {
|
||||||
tmp = usbcore.device_drivers[i];
|
tmp = usbcore.device_drivers[i];
|
||||||
if (tmp != NULL && strcmp(name, tmp->name) == 0) {
|
if (tmp != NULL && strcmp(name, tmp->name) == 0) {
|
||||||
driver = tmp;
|
driver = tmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (driver == NULL) {
|
if (driver == NULL) {
|
||||||
logf("no driver found");
|
logf("no driver found");
|
||||||
return ENODRIVERFOUND;
|
return ENODRIVERFOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* look if there is an usb controller loaded */
|
/* look if there is an usb controller loaded */
|
||||||
if (usbcore.active_controller == NULL) {
|
if (usbcore.active_controller == NULL) {
|
||||||
/* safe choosen driver and set it when controller starts */
|
/* safe choosen driver and set it when controller starts */
|
||||||
usbcore.device_driver = driver;
|
usbcore.device_driver = driver;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
/* we need to have an active dcd controller */
|
/* we need to have an active dcd controller */
|
||||||
if (usbcore.active_controller->type != DEVICE) {
|
if (usbcore.active_controller->type != DEVICE) {
|
||||||
logf("wrong type");
|
logf("wrong type");
|
||||||
return EWRONGCONTROLLERTYPE;
|
return EWRONGCONTROLLERTYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* bind driver to controller */
|
/* bind driver to controller */
|
||||||
bind_device_driver(driver);
|
bind_device_driver(driver);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usb_device_driver_unbind(void) {
|
void usb_device_driver_unbind(void) {
|
||||||
|
|
||||||
logf("usb_device_driver_unbind");
|
logf("usb_device_driver_unbind");
|
||||||
if (usbcore.active_controller->device_driver != NULL) {
|
if (usbcore.active_controller->device_driver != NULL) {
|
||||||
usbcore.active_controller->device_driver->unbind();
|
usbcore.active_controller->device_driver->unbind();
|
||||||
usbcore.active_controller->device_driver = NULL;
|
usbcore.active_controller->device_driver = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
usbcore.device_driver = NULL;
|
usbcore.device_driver = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void update_driver_names(unsigned char* result) {
|
static void update_driver_names(unsigned char* result) {
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
unsigned char terminator = ',';
|
unsigned char terminator = ',';
|
||||||
struct usb_device_driver* dd = NULL;
|
struct usb_device_driver* dd = NULL;
|
||||||
|
|
||||||
/* reset buffer, iterate through drivers and add to char array */
|
/* reset buffer, iterate through drivers and add to char array */
|
||||||
memset(result, 0, USB_STACK_MAX_SETTINGS_NAME);
|
memset(result, 0, USB_STACK_MAX_SETTINGS_NAME);
|
||||||
for (i = 0; i < NUM_DRIVERS; i++) {
|
for (i = 0; i < NUM_DRIVERS; i++) {
|
||||||
int len;
|
int len;
|
||||||
dd = usbcore.device_drivers[i];
|
dd = usbcore.device_drivers[i];
|
||||||
|
|
||||||
if (dd != NULL) {
|
if (dd != NULL) {
|
||||||
len = strlen(dd->name);
|
len = strlen(dd->name);
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
memcpy(result + pos, &terminator, 1);
|
memcpy(result + pos, &terminator, 1);
|
||||||
pos++;
|
pos++;
|
||||||
}
|
}
|
||||||
memcpy(result + pos, dd->name, len);
|
memcpy(result + pos, dd->name, len);
|
||||||
pos += len;
|
pos += len;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bind_device_driver(struct usb_device_driver* driver) {
|
static void bind_device_driver(struct usb_device_driver* driver) {
|
||||||
|
|
||||||
/* look if there is an old driver */
|
/* look if there is an old driver */
|
||||||
if (usbcore.active_controller->device_driver != NULL) {
|
if (usbcore.active_controller->device_driver != NULL) {
|
||||||
usbcore.active_controller->device_driver->unbind();
|
usbcore.active_controller->device_driver->unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* bind driver to controller */
|
/* bind driver to controller */
|
||||||
usbcore.active_controller->device_driver = driver;
|
usbcore.active_controller->device_driver = driver;
|
||||||
|
|
||||||
/* init dirver */
|
/* init dirver */
|
||||||
driver->bind(usbcore.active_controller->controller_ops);
|
driver->bind(usbcore.active_controller->controller_ops);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,27 +25,27 @@
|
||||||
*
|
*
|
||||||
* Naming Convention for Endpoint Names
|
* Naming Convention for Endpoint Names
|
||||||
*
|
*
|
||||||
* - ep1, ep2, ... address is fixed, not direction or type
|
* - ep1, ep2, ... address is fixed, not direction or type
|
||||||
* - ep1in, ep2out, ... address and direction are fixed, not type
|
* - ep1in, ep2out, ... address and direction are fixed, not type
|
||||||
* - ep1-bulk, ep2-bulk, ... address and type are fixed, not direction
|
* - ep1-bulk, ep2-bulk, ... address and type are fixed, not direction
|
||||||
* - ep1in-bulk, ep2out-iso, ... all three are fixed
|
* - ep1in-bulk, ep2out-iso, ... all three are fixed
|
||||||
* - ep-* ... no functionality restrictions
|
* - ep-* ... no functionality restrictions
|
||||||
*
|
*
|
||||||
* Type suffixes are "-bulk", "-iso", or "-int". Numbers are decimal.
|
* Type suffixes are "-bulk", "-iso", or "-int". Numbers are decimal.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static int ep_matches(struct usb_ep* ep, struct usb_endpoint_descriptor* desc);
|
static int ep_matches(struct usb_ep* ep, struct usb_endpoint_descriptor* desc);
|
||||||
|
|
||||||
void usb_ep_autoconfig_reset(void) {
|
void usb_ep_autoconfig_reset(void)
|
||||||
|
{
|
||||||
struct usb_ep* ep = NULL;
|
struct usb_ep* ep = NULL;
|
||||||
if (usbcore.active_controller == NULL) {
|
if (usbcore.active_controller == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
logf("resetting endpoints");
|
logf("resetting endpoints");
|
||||||
list_for_each_entry(ep, &usbcore.active_controller->endpoints.list, list) {
|
list_for_each_entry(ep, &usbcore.active_controller->endpoints.list, list) {
|
||||||
logf("reset %s", ep->name);
|
logf("reset %s", ep->name);
|
||||||
ep->claimed = false;
|
ep->claimed = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,48 +55,48 @@ void usb_ep_autoconfig_reset(void) {
|
||||||
* @param desc usb descritpro to use for seraching.
|
* @param desc usb descritpro to use for seraching.
|
||||||
* @return NULL or a valid endpoint.
|
* @return NULL or a valid endpoint.
|
||||||
*/
|
*/
|
||||||
struct usb_ep* usb_ep_autoconfig(struct usb_endpoint_descriptor* desc) {
|
struct usb_ep* usb_ep_autoconfig(struct usb_endpoint_descriptor* desc)
|
||||||
|
{
|
||||||
struct usb_ep* ep = NULL;
|
struct usb_ep* ep = NULL;
|
||||||
if (usbcore.active_controller == NULL) {
|
if (usbcore.active_controller == NULL) {
|
||||||
logf("active controller NULL");
|
logf("active controller NULL");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
list_for_each_entry(ep, &usbcore.active_controller->endpoints.list, list) {
|
list_for_each_entry(ep, &usbcore.active_controller->endpoints.list, list) {
|
||||||
if (ep_matches (ep, desc)) {
|
if (ep_matches (ep, desc)) {
|
||||||
return ep;
|
return ep;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ep_matches(struct usb_ep* ep, struct usb_endpoint_descriptor* desc) {
|
static int ep_matches(struct usb_ep* ep, struct usb_endpoint_descriptor* desc)
|
||||||
|
{
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
const char* tmp;
|
const char* tmp;
|
||||||
uint16_t max;
|
uint16_t max;
|
||||||
|
|
||||||
/* endpoint already claimed? */
|
/* endpoint already claimed? */
|
||||||
if (ep->claimed) {
|
if (ep->claimed) {
|
||||||
logf("!! claimed !!");
|
logf("!! claimed !!");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* only support ep0 for portable CONTROL traffic */
|
/* only support ep0 for portable CONTROL traffic */
|
||||||
type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
|
type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
|
||||||
if (type == USB_ENDPOINT_XFER_CONTROL) {
|
if (type == USB_ENDPOINT_XFER_CONTROL) {
|
||||||
logf("type == control");
|
logf("type == control");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* some other naming convention */
|
/* some other naming convention */
|
||||||
if (ep->name[0] != 'e') {
|
if (ep->name[0] != 'e') {
|
||||||
logf("wrong name");
|
logf("wrong name");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* type-restriction: "-iso", "-bulk", or "-int".
|
/* type-restriction: "-iso", "-bulk", or "-int".
|
||||||
* direction-restriction: "in", "out".
|
* direction-restriction: "in", "out".
|
||||||
*/
|
*/
|
||||||
|
@ -111,20 +111,20 @@ static int ep_matches(struct usb_ep* ep, struct usb_endpoint_descriptor* desc) {
|
||||||
if (tmp[2] == 's') { // == "-iso"
|
if (tmp[2] == 's') { // == "-iso"
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case USB_ENDPOINT_XFER_BULK:
|
case USB_ENDPOINT_XFER_BULK:
|
||||||
if (tmp[1] != 'b') { // != "-bulk"
|
if (tmp[1] != 'b') { // != "-bulk"
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case USB_ENDPOINT_XFER_ISOC:
|
case USB_ENDPOINT_XFER_ISOC:
|
||||||
if (tmp[2] != 's') { // != "-iso"
|
if (tmp[2] != 's') { // != "-iso"
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tmp = ep->name + strlen (ep->name);
|
tmp = ep->name + strlen (ep->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* direction-restriction: "..in-..", "out-.." */
|
/* direction-restriction: "..in-..", "out-.." */
|
||||||
tmp--;
|
tmp--;
|
||||||
|
@ -132,7 +132,7 @@ static int ep_matches(struct usb_ep* ep, struct usb_endpoint_descriptor* desc) {
|
||||||
if (desc->bEndpointAddress & USB_DIR_IN) {
|
if (desc->bEndpointAddress & USB_DIR_IN) {
|
||||||
if ('n' != *tmp) {
|
if ('n' != *tmp) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ('t' != *tmp) {
|
if ('t' != *tmp) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -147,40 +147,40 @@ static int ep_matches(struct usb_ep* ep, struct usb_endpoint_descriptor* desc) {
|
||||||
* the usb spec fixes high speed bulk maxpacket at 512 bytes.
|
* the usb spec fixes high speed bulk maxpacket at 512 bytes.
|
||||||
*/
|
*/
|
||||||
max = 0x7ff & desc->wMaxPacketSize;
|
max = 0x7ff & desc->wMaxPacketSize;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case USB_ENDPOINT_XFER_INT:
|
case USB_ENDPOINT_XFER_INT:
|
||||||
/* INT: limit 64 bytes full speed, 1024 high speed */
|
/* INT: limit 64 bytes full speed, 1024 high speed */
|
||||||
if ((usbcore.active_controller->speed != USB_SPEED_HIGH) && (max > 64)) {
|
if ((usbcore.active_controller->speed != USB_SPEED_HIGH) && (max > 64)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* FALLTHROUGH */
|
/* FALLTHROUGH */
|
||||||
|
|
||||||
case USB_ENDPOINT_XFER_ISOC:
|
case USB_ENDPOINT_XFER_ISOC:
|
||||||
if ((usbcore.active_controller->speed != USB_SPEED_HIGH) && (max > 1023)) {
|
if ((usbcore.active_controller->speed != USB_SPEED_HIGH) && (max > 1023)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* MATCH!! */
|
/* MATCH!! */
|
||||||
|
|
||||||
/* report address */
|
/* report address */
|
||||||
desc->bEndpointAddress |= ep->ep_num;
|
desc->bEndpointAddress |= ep->ep_num;
|
||||||
|
|
||||||
/* report (variable) full speed bulk maxpacket */
|
/* report (variable) full speed bulk maxpacket */
|
||||||
if (type == USB_ENDPOINT_XFER_BULK) {
|
if (type == USB_ENDPOINT_XFER_BULK) {
|
||||||
int size = max;
|
int size = max;
|
||||||
|
|
||||||
/* min() doesn't work on bitfields with gcc-3.5 */
|
/* min() doesn't work on bitfields with gcc-3.5 */
|
||||||
if (size > 64) {
|
if (size > 64) {
|
||||||
size = 64;
|
size = 64;
|
||||||
}
|
}
|
||||||
desc->wMaxPacketSize = size;
|
desc->wMaxPacketSize = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* save desc in endpoint */
|
/* save desc in endpoint */
|
||||||
ep->desc = desc;
|
ep->desc = desc;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,98 +20,98 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "usbstack/core.h"
|
#include "usbstack/core.h"
|
||||||
|
|
||||||
void into_usb_ctrlrequest(struct usb_ctrlrequest* request) {
|
void into_usb_ctrlrequest(struct usb_ctrlrequest* request)
|
||||||
|
{
|
||||||
|
char* type = "";
|
||||||
|
char* req = "";
|
||||||
|
char* extra = 0;
|
||||||
|
|
||||||
char* type = "";
|
logf("-usb request-");
|
||||||
char* req = "";
|
|
||||||
char* extra = 0;
|
|
||||||
|
|
||||||
logf("-usb request-");
|
|
||||||
/* check if packet is okay */
|
/* check if packet is okay */
|
||||||
if (request->bRequestType == 0 &&
|
if (request->bRequestType == 0 &&
|
||||||
request->bRequest == 0 &&
|
request->bRequest == 0 &&
|
||||||
request->wValue == 0 &&
|
request->wValue == 0 &&
|
||||||
request->wIndex == 0 &&
|
request->wIndex == 0 &&
|
||||||
request->wLength == 0) {
|
request->wLength == 0) {
|
||||||
logf(" -> INVALID <-");
|
logf(" -> INVALID <-");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (request->bRequestType & USB_TYPE_MASK) {
|
switch (request->bRequestType & USB_TYPE_MASK) {
|
||||||
case USB_TYPE_STANDARD:
|
case USB_TYPE_STANDARD:
|
||||||
type = "standard";
|
type = "standard";
|
||||||
|
|
||||||
switch (request->bRequest) {
|
switch (request->bRequest) {
|
||||||
case USB_REQ_GET_STATUS:
|
case USB_REQ_GET_STATUS:
|
||||||
req = "get status";
|
req = "get status";
|
||||||
break;
|
break;
|
||||||
case USB_REQ_CLEAR_FEATURE:
|
case USB_REQ_CLEAR_FEATURE:
|
||||||
req = "clear feature";
|
req = "clear feature";
|
||||||
break;
|
break;
|
||||||
case USB_REQ_SET_FEATURE:
|
case USB_REQ_SET_FEATURE:
|
||||||
req = "set feature";
|
req = "set feature";
|
||||||
break;
|
break;
|
||||||
case USB_REQ_SET_ADDRESS:
|
case USB_REQ_SET_ADDRESS:
|
||||||
req = "set address";
|
req = "set address";
|
||||||
break;
|
break;
|
||||||
case USB_REQ_GET_DESCRIPTOR:
|
case USB_REQ_GET_DESCRIPTOR:
|
||||||
req = "get descriptor";
|
req = "get descriptor";
|
||||||
|
|
||||||
switch (request->wValue >> 8) {
|
switch (request->wValue >> 8) {
|
||||||
case USB_DT_DEVICE:
|
case USB_DT_DEVICE:
|
||||||
extra = "get device descriptor";
|
extra = "get device descriptor";
|
||||||
break;
|
break;
|
||||||
case USB_DT_DEVICE_QUALIFIER:
|
case USB_DT_DEVICE_QUALIFIER:
|
||||||
extra = "get device qualifier";
|
extra = "get device qualifier";
|
||||||
break;
|
break;
|
||||||
case USB_DT_OTHER_SPEED_CONFIG:
|
case USB_DT_OTHER_SPEED_CONFIG:
|
||||||
extra = "get other-speed config descriptor";
|
extra = "get other-speed config descriptor";
|
||||||
case USB_DT_CONFIG:
|
case USB_DT_CONFIG:
|
||||||
extra = "get configuration descriptor";
|
extra = "get configuration descriptor";
|
||||||
break;
|
break;
|
||||||
case USB_DT_STRING:
|
case USB_DT_STRING:
|
||||||
extra = "get string descriptor";
|
extra = "get string descriptor";
|
||||||
break;
|
break;
|
||||||
case USB_DT_DEBUG:
|
case USB_DT_DEBUG:
|
||||||
extra = "debug";
|
extra = "debug";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case USB_REQ_SET_DESCRIPTOR:
|
case USB_REQ_SET_DESCRIPTOR:
|
||||||
req = "set descriptor";
|
req = "set descriptor";
|
||||||
break;
|
break;
|
||||||
case USB_REQ_GET_CONFIGURATION:
|
case USB_REQ_GET_CONFIGURATION:
|
||||||
req = "get configuration";
|
req = "get configuration";
|
||||||
break;
|
break;
|
||||||
case USB_REQ_SET_CONFIGURATION:
|
case USB_REQ_SET_CONFIGURATION:
|
||||||
req = "set configuration";
|
req = "set configuration";
|
||||||
break;
|
break;
|
||||||
case USB_REQ_GET_INTERFACE:
|
case USB_REQ_GET_INTERFACE:
|
||||||
req = "get interface";
|
req = "get interface";
|
||||||
break;
|
break;
|
||||||
case USB_REQ_SET_INTERFACE:
|
case USB_REQ_SET_INTERFACE:
|
||||||
req = "set interface";
|
req = "set interface";
|
||||||
break;
|
break;
|
||||||
case USB_REQ_SYNCH_FRAME:
|
case USB_REQ_SYNCH_FRAME:
|
||||||
req = "sync frame";
|
req = "sync frame";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
req = "unkown";
|
req = "unkown";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case USB_TYPE_CLASS:
|
case USB_TYPE_CLASS:
|
||||||
type = "class";
|
type = "class";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_TYPE_VENDOR:
|
case USB_TYPE_VENDOR:
|
||||||
type = "vendor";
|
type = "vendor";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
logf(" -b 0x%x", request->bRequestType);
|
logf(" -b 0x%x", request->bRequestType);
|
||||||
logf(" -b 0x%x", request->bRequest);
|
logf(" -b 0x%x", request->bRequest);
|
||||||
logf(" -b 0x%x", request->wValue);
|
logf(" -b 0x%x", request->wValue);
|
||||||
|
@ -120,6 +120,6 @@ void into_usb_ctrlrequest(struct usb_ctrlrequest* request) {
|
||||||
logf(" -> t: %s", type);
|
logf(" -> t: %s", type);
|
||||||
logf(" -> r: %s", req);
|
logf(" -> r: %s", req);
|
||||||
if (extra != 0) {
|
if (extra != 0) {
|
||||||
logf(" -> e: %s", extra);
|
logf(" -> e: %s", extra);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ struct usb_config_descriptor;
|
||||||
struct usb_descriptor_header;
|
struct usb_descriptor_header;
|
||||||
|
|
||||||
int usb_stack_configdesc(const struct usb_config_descriptor* config,
|
int usb_stack_configdesc(const struct usb_config_descriptor* config,
|
||||||
void* buf, unsigned length,
|
void* buf, unsigned length,
|
||||||
struct usb_descriptor_header** desc);
|
struct usb_descriptor_header** desc);
|
||||||
|
|
||||||
#endif /*_USBSTACK_DEVICE_H_*/
|
#endif /*_USBSTACK_DEVICE_H_*/
|
||||||
|
|
|
@ -128,69 +128,69 @@ static int set_config(int config);
|
||||||
|
|
||||||
|
|
||||||
struct device {
|
struct device {
|
||||||
struct usb_ep* in;
|
struct usb_ep* in;
|
||||||
struct usb_ep* out;
|
struct usb_ep* out;
|
||||||
uint32_t used_config;
|
uint32_t used_config;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct device dev;
|
static struct device dev;
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void usb_serial_driver_init(void) {
|
void usb_serial_driver_init(void)
|
||||||
|
{
|
||||||
logf("usb serial: register");
|
logf("usb serial: register");
|
||||||
usb_device_driver_register(&usb_serial_driver);
|
usb_device_driver_register(&usb_serial_driver);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void usb_serial_driver_bind(void* controler_ops) {
|
void usb_serial_driver_bind(void* controler_ops)
|
||||||
|
{
|
||||||
logf("usb serial: bind");
|
logf("usb serial: bind");
|
||||||
ops = controler_ops;
|
ops = controler_ops;
|
||||||
|
|
||||||
/* serach and asign endpoints */
|
/* serach and asign endpoints */
|
||||||
usb_ep_autoconfig_reset();
|
usb_ep_autoconfig_reset();
|
||||||
|
|
||||||
dev.in = usb_ep_autoconfig(&serial_fullspeed_in_desc);
|
dev.in = usb_ep_autoconfig(&serial_fullspeed_in_desc);
|
||||||
if (!dev.in) {
|
if (!dev.in) {
|
||||||
goto autoconf_fail;
|
goto autoconf_fail;
|
||||||
}
|
}
|
||||||
dev.in->claimed = true;
|
dev.in->claimed = true;
|
||||||
logf("usb serial: in: %s", dev.in->name);
|
logf("usb serial: in: %s", dev.in->name);
|
||||||
|
|
||||||
dev.out = usb_ep_autoconfig(&serial_fullspeed_out_desc);
|
dev.out = usb_ep_autoconfig(&serial_fullspeed_out_desc);
|
||||||
if (!dev.out) {
|
if (!dev.out) {
|
||||||
goto autoconf_fail;
|
goto autoconf_fail;
|
||||||
}
|
}
|
||||||
dev.out->claimed = true;
|
dev.out->claimed = true;
|
||||||
logf("usb serial: out: %s", dev.out->name);
|
logf("usb serial: out: %s", dev.out->name);
|
||||||
|
|
||||||
|
/* update device decsriptor */
|
||||||
|
serial_device_desc.bMaxPacketSize0 = ops->ep0->maxpacket;
|
||||||
|
|
||||||
|
/* update qualifie descriptor */
|
||||||
|
serial_qualifier_desc.bMaxPacketSize0 = ops->ep0->maxpacket;
|
||||||
|
|
||||||
|
/* update debug descriptor */
|
||||||
|
serial_debug_desc.bDebugInEndpoint = dev.in->ep_num;
|
||||||
|
serial_debug_desc.bDebugOutEndpoint = dev.out->ep_num;
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
/* update device decsriptor */
|
|
||||||
serial_device_desc.bMaxPacketSize0 = ops->ep0->maxpacket;
|
|
||||||
|
|
||||||
/* update qualifie descriptor */
|
|
||||||
serial_qualifier_desc.bMaxPacketSize0 = ops->ep0->maxpacket;
|
|
||||||
|
|
||||||
/* update debug descriptor */
|
|
||||||
serial_debug_desc.bDebugInEndpoint = dev.in->ep_num;
|
|
||||||
serial_debug_desc.bDebugOutEndpoint = dev.out->ep_num;
|
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
autoconf_fail:
|
autoconf_fail:
|
||||||
logf("failed to find endpoiunts");
|
logf("failed to find endpoiunts");
|
||||||
}
|
}
|
||||||
|
|
||||||
int usb_serial_driver_request(struct usb_ctrlrequest* request) {
|
int usb_serial_driver_request(struct usb_ctrlrequest* request)
|
||||||
|
{
|
||||||
int ret = -EOPNOTSUPP;
|
int ret = -EOPNOTSUPP;
|
||||||
logf("usb serial: request");
|
logf("usb serial: request");
|
||||||
|
|
||||||
res.length = 0;
|
res.length = 0;
|
||||||
res.buf = NULL;
|
res.buf = NULL;
|
||||||
|
|
||||||
switch (request->bRequestType & USB_TYPE_MASK) {
|
switch (request->bRequestType & USB_TYPE_MASK) {
|
||||||
case USB_TYPE_STANDARD:
|
case USB_TYPE_STANDARD:
|
||||||
|
|
||||||
|
@ -205,26 +205,26 @@ int usb_serial_driver_request(struct usb_ctrlrequest* request) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_DT_DEVICE_QUALIFIER:
|
case USB_DT_DEVICE_QUALIFIER:
|
||||||
logf("usb serial: sending qualifier dec");
|
logf("usb serial: sending qualifier dec");
|
||||||
ret = MIN(sizeof(struct usb_qualifier_descriptor), request->wLength);
|
ret = MIN(sizeof(struct usb_qualifier_descriptor), request->wLength);
|
||||||
res.buf = &serial_qualifier_desc;
|
res.buf = &serial_qualifier_desc;
|
||||||
|
|
||||||
case USB_DT_CONFIG:
|
case USB_DT_CONFIG:
|
||||||
logf("usb serial: sending config desc");
|
logf("usb serial: sending config desc");
|
||||||
|
|
||||||
ret = config_buf(buf, request->wValue >> 8, request->wValue & 0xff);
|
ret = config_buf(buf, request->wValue >> 8, request->wValue & 0xff);
|
||||||
if (ret >= 0) {
|
if (ret >= 0) {
|
||||||
logf("%d, vs %d", request->wLength, ret);
|
logf("%d, vs %d", request->wLength, ret);
|
||||||
ret = MIN(request->wLength, (uint16_t)ret);
|
ret = MIN(request->wLength, (uint16_t)ret);
|
||||||
}
|
}
|
||||||
res.buf = buf;
|
res.buf = buf;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_DT_DEBUG:
|
case USB_DT_DEBUG:
|
||||||
logf("usb serial: sending debug desc");
|
logf("usb serial: sending debug desc");
|
||||||
ret = MIN(sizeof(struct usb_debug_descriptor), request->wLength);
|
ret = MIN(sizeof(struct usb_debug_descriptor), request->wLength);
|
||||||
res.buf = &serial_debug_desc;
|
res.buf = &serial_debug_desc;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -232,9 +232,9 @@ int usb_serial_driver_request(struct usb_ctrlrequest* request) {
|
||||||
logf("usb serial: set configuration %d", request->wValue);
|
logf("usb serial: set configuration %d", request->wValue);
|
||||||
ret = set_config(request->wValue);
|
ret = set_config(request->wValue);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_REQ_GET_CONFIGURATION:
|
case USB_REQ_GET_CONFIGURATION:
|
||||||
logf("usb serial: get configuration");
|
logf("usb serial: get configuration");
|
||||||
ret = 1;
|
ret = 1;
|
||||||
res.buf = &dev.used_config;
|
res.buf = &dev.used_config;
|
||||||
break;
|
break;
|
||||||
|
@ -245,56 +245,56 @@ int usb_serial_driver_request(struct usb_ctrlrequest* request) {
|
||||||
res.length = ret;
|
res.length = ret;
|
||||||
ret = ops->send(NULL, &res);
|
ret = ops->send(NULL, &res);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usb_serial_driver_speed(enum usb_device_speed speed) {
|
void usb_serial_driver_speed(enum usb_device_speed speed)
|
||||||
|
{
|
||||||
switch (speed) {
|
switch (speed) {
|
||||||
case USB_SPEED_LOW:
|
case USB_SPEED_LOW:
|
||||||
case USB_SPEED_FULL:
|
case USB_SPEED_FULL:
|
||||||
logf("usb serial: using fullspeed");
|
logf("usb serial: using fullspeed");
|
||||||
break;
|
break;
|
||||||
case USB_SPEED_HIGH:
|
case USB_SPEED_HIGH:
|
||||||
logf("usb serial: using highspeed");
|
logf("usb serial: using highspeed");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
logf("speed: hmm");
|
logf("speed: hmm");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
/* helper functions */
|
/* helper functions */
|
||||||
|
|
||||||
static int config_buf(uint8_t *buf, uint8_t type, unsigned index) {
|
static int config_buf(uint8_t *buf, uint8_t type, unsigned index)
|
||||||
|
{
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
/* TODO check index*/
|
/* TODO check index*/
|
||||||
|
|
||||||
len = usb_stack_configdesc(&serial_bulk_config_desc, buf, BUFFER_SIZE, serial_bulk_fullspeed_function);
|
len = usb_stack_configdesc(&serial_bulk_config_desc, buf, BUFFER_SIZE, serial_bulk_fullspeed_function);
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
((struct usb_config_descriptor *)buf)->bDescriptorType = type;
|
((struct usb_config_descriptor *)buf)->bDescriptorType = type;
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int set_config(int config) {
|
static int set_config(int config)
|
||||||
|
{
|
||||||
|
/* TODO check config*/
|
||||||
|
|
||||||
/* TODO check config*/
|
|
||||||
|
|
||||||
/* enable endpoints */
|
/* enable endpoints */
|
||||||
logf("setup %s", dev.in->name);
|
logf("setup %s", dev.in->name);
|
||||||
ops->enable(dev.in);
|
ops->enable(dev.in);
|
||||||
logf("setup %s", dev.out->name);
|
logf("setup %s", dev.out->name);
|
||||||
ops->enable(dev.out);
|
ops->enable(dev.out);
|
||||||
|
|
||||||
/* store config */
|
/* store config */
|
||||||
logf("using config %d", config);
|
logf("using config %d", config);
|
||||||
dev.used_config = config;
|
dev.used_config = config;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,8 +128,8 @@ static int set_config(int config);
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void usb_storage_driver_init(void) {
|
void usb_storage_driver_init(void)
|
||||||
|
{
|
||||||
logf("usb storage: register");
|
logf("usb storage: register");
|
||||||
usb_device_driver_register(&usb_storage_driver);
|
usb_device_driver_register(&usb_storage_driver);
|
||||||
}
|
}
|
||||||
|
@ -137,41 +137,41 @@ void usb_storage_driver_init(void) {
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
/* device driver ops */
|
/* device driver ops */
|
||||||
|
|
||||||
void usb_storage_driver_bind(void* controler_ops) {
|
void usb_storage_driver_bind(void* controler_ops)
|
||||||
|
{
|
||||||
ops = controler_ops;
|
ops = controler_ops;
|
||||||
|
|
||||||
/* serach and asign endpoints */
|
/* serach and asign endpoints */
|
||||||
usb_ep_autoconfig_reset();
|
usb_ep_autoconfig_reset();
|
||||||
|
|
||||||
dev.in = usb_ep_autoconfig(&storage_bulk_in_desc);
|
dev.in = usb_ep_autoconfig(&storage_bulk_in_desc);
|
||||||
if (!dev.in) {
|
if (!dev.in) {
|
||||||
goto autoconf_fail;
|
goto autoconf_fail;
|
||||||
}
|
}
|
||||||
dev.in->claimed = true;
|
dev.in->claimed = true;
|
||||||
logf("usb storage: in: %s", dev.in->name);
|
logf("usb storage: in: %s", dev.in->name);
|
||||||
|
|
||||||
dev.out = usb_ep_autoconfig(&storage_bulk_out_desc);
|
dev.out = usb_ep_autoconfig(&storage_bulk_out_desc);
|
||||||
if (!dev.out) {
|
if (!dev.out) {
|
||||||
goto autoconf_fail;
|
goto autoconf_fail;
|
||||||
}
|
}
|
||||||
dev.out->claimed = true;
|
dev.out->claimed = true;
|
||||||
logf("usb storage: out: %s", dev.out->name);
|
logf("usb storage: out: %s", dev.out->name);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
autoconf_fail:
|
autoconf_fail:
|
||||||
logf("failed to find endpoints");
|
logf("failed to find endpoints");
|
||||||
}
|
}
|
||||||
|
|
||||||
int usb_storage_driver_request(struct usb_ctrlrequest* request) {
|
int usb_storage_driver_request(struct usb_ctrlrequest* request)
|
||||||
|
{
|
||||||
int ret = -EOPNOTSUPP;
|
int ret = -EOPNOTSUPP;
|
||||||
logf("usb storage: request");
|
logf("usb storage: request");
|
||||||
|
|
||||||
res.length = 0;
|
res.length = 0;
|
||||||
res.buf = NULL;
|
res.buf = NULL;
|
||||||
|
|
||||||
switch (request->bRequestType & USB_TYPE_MASK) {
|
switch (request->bRequestType & USB_TYPE_MASK) {
|
||||||
case USB_TYPE_STANDARD:
|
case USB_TYPE_STANDARD:
|
||||||
|
|
||||||
|
@ -187,12 +187,12 @@ int usb_storage_driver_request(struct usb_ctrlrequest* request) {
|
||||||
|
|
||||||
case USB_DT_CONFIG:
|
case USB_DT_CONFIG:
|
||||||
logf("usb storage: sending config desc");
|
logf("usb storage: sending config desc");
|
||||||
|
|
||||||
ret = config_buf(buf, request->wValue >> 8, request->wValue & 0xff);
|
ret = config_buf(buf, request->wValue >> 8, request->wValue & 0xff);
|
||||||
if (ret >= 0) {
|
if (ret >= 0) {
|
||||||
logf("%d, vs %d", request->wLength, ret);
|
logf("%d, vs %d", request->wLength, ret);
|
||||||
ret = MIN(request->wLength, (uint16_t)ret);
|
ret = MIN(request->wLength, (uint16_t)ret);
|
||||||
}
|
}
|
||||||
res.buf = buf;
|
res.buf = buf;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -202,68 +202,68 @@ int usb_storage_driver_request(struct usb_ctrlrequest* request) {
|
||||||
logf("usb storage: set configuration %d", request->wValue);
|
logf("usb storage: set configuration %d", request->wValue);
|
||||||
ret = set_config(request->wValue);
|
ret = set_config(request->wValue);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_REQ_SET_INTERFACE:
|
case USB_REQ_SET_INTERFACE:
|
||||||
logf("usb storage: set interface");
|
logf("usb storage: set interface");
|
||||||
ret = 0;
|
ret = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case USB_TYPE_CLASS:
|
case USB_TYPE_CLASS:
|
||||||
|
|
||||||
switch (request->bRequest) {
|
switch (request->bRequest) {
|
||||||
case USB_BULK_RESET_REQUEST:
|
case USB_BULK_RESET_REQUEST:
|
||||||
logf("usb storage: bulk reset");
|
logf("usb storage: bulk reset");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_BULK_GET_MAX_LUN_REQUEST:
|
case USB_BULK_GET_MAX_LUN_REQUEST:
|
||||||
logf("usb storage: get max lun");
|
logf("usb storage: get max lun");
|
||||||
/* we support no LUNs (Logical Unit Number) */
|
/* we support no LUNs (Logical Unit Number) */
|
||||||
buf[0] = 0;
|
buf[0] = 0;
|
||||||
ret = 1;
|
ret = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret >= 0) {
|
if (ret >= 0) {
|
||||||
res.length = ret;
|
res.length = ret;
|
||||||
ret = ops->send(NULL, &res);
|
ret = ops->send(NULL, &res);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
/* S/GET CONFIGURATION helpers */
|
/* S/GET CONFIGURATION helpers */
|
||||||
|
|
||||||
static int config_buf(uint8_t *buf, uint8_t type, unsigned index) {
|
static int config_buf(uint8_t *buf, uint8_t type, unsigned index)
|
||||||
|
{
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
/* only one configuration */
|
/* only one configuration */
|
||||||
if (index != 0) {
|
if (index != 0) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = usb_stack_configdesc(&storage_config_desc, buf, BUFFER_SIZE, storage_fullspeed_function);
|
len = usb_stack_configdesc(&storage_config_desc, buf, BUFFER_SIZE, storage_fullspeed_function);
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
((struct usb_config_descriptor *)buf)->bDescriptorType = type;
|
((struct usb_config_descriptor *)buf)->bDescriptorType = type;
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int set_config(int config) {
|
static int set_config(int config)
|
||||||
|
{
|
||||||
/* enable endpoints */
|
/* enable endpoints */
|
||||||
logf("setup %s", dev.in->name);
|
logf("setup %s", dev.in->name);
|
||||||
ops->enable(dev.in);
|
ops->enable(dev.in);
|
||||||
logf("setup %s", dev.out->name);
|
logf("setup %s", dev.out->name);
|
||||||
ops->enable(dev.out);
|
ops->enable(dev.out);
|
||||||
|
|
||||||
/* setup buffers */
|
/* setup buffers */
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
*/
|
*/
|
||||||
struct usb_host_driver {
|
struct usb_host_driver {
|
||||||
const char* name;
|
const char* name;
|
||||||
void* data; /* used to store controller specific ops struct */
|
void* data; /* used to store controller specific ops struct */
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /*_USBSTACK_HOST_H_*/
|
#endif /*_USBSTACK_HOST_H_*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue