released 0.8.7 (new MMU layout, m5484LITE board working again)

This commit is contained in:
Markus Fröschle
2015-01-24 10:24:33 +00:00
parent f72b551170
commit ce6e8d58fd
284 changed files with 126529 additions and 0 deletions

1348
BaS_gcc/usb/usb.c Normal file

File diff suppressed because it is too large Load Diff

630
BaS_gcc/usb/usb_hub.c Normal file
View File

@@ -0,0 +1,630 @@
/*
* HUB "Driver"
* Probes device for being a hub and configure it
*/
#include <stdint.h>
#include "bas_string.h"
#include "bas_printf.h"
#include "util.h" /* for byte swap funcs */
#include "wait.h"
#include <stdarg.h>
#include "usb.h"
#include "usb_hub.h"
#define DEBUG_HUB
#ifdef DEBUG_HUB
#define dbg(format, arg...) do { xprintf("DEBUG: %s(): " format, __FUNCTION__, ##arg); } while (0)
#else
#define dbg(format, arg...) do { ; } while (0)
#endif /* DEBUG_HUB */
#define err(format, arg...) do { xprintf("DEBUG: %s(): " format, __FUNCTION__, ##arg); } while (0)
#define info(format, arg...) do { xprintf("DEBUG: %s(): " format, __FUNCTION__, ##arg); } while (0)
static struct usb_hub_device hub_dev[USB_MAX_BUS][USB_MAX_HUB];
static int usb_hub_index[USB_MAX_BUS];
int usb_get_hub_descriptor(struct usb_device *dev, void *data, int size)
{
return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
USB_REQ_GET_DESCRIPTOR, USB_DIR_IN | USB_RT_HUB, USB_DT_HUB << 8, 0, data, size, USB_CNTL_TIMEOUT);
}
int usb_clear_hub_feature(struct usb_device *dev, int feature)
{
return usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
USB_REQ_CLEAR_FEATURE, USB_RT_HUB, feature, 0, NULL, 0, USB_CNTL_TIMEOUT);
}
int usb_clear_port_feature(struct usb_device *dev, int port, int feature)
{
return usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
USB_REQ_CLEAR_FEATURE, USB_RT_PORT, feature, port, NULL, 0, USB_CNTL_TIMEOUT);
}
int usb_set_port_feature(struct usb_device *dev, int port, int feature)
{
return usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
USB_REQ_SET_FEATURE, USB_RT_PORT, feature, port, NULL, 0, USB_CNTL_TIMEOUT);
}
int usb_get_hub_status(struct usb_device *dev, void *data)
{
return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
USB_REQ_GET_STATUS, USB_DIR_IN | USB_RT_HUB, 0, 0, data, sizeof(struct usb_hub_status), USB_CNTL_TIMEOUT);
}
int usb_get_port_status(struct usb_device *dev, int port, void *data)
{
return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
USB_REQ_GET_STATUS, USB_DIR_IN | USB_RT_PORT, 0, port, data, sizeof(struct usb_hub_status), USB_CNTL_TIMEOUT);
}
static void usb_hub_power_on(struct usb_hub_device *hub)
{
int i;
struct usb_device *dev;
dev = hub->pusb_dev;
/* Enable power to the ports */
dbg("enabling power on all ports\r\n");
for (i = 0; i < dev->maxchild; i++)
{
usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_POWER);
dbg("port %d returns %lx\r\n", i + 1, dev->status);
wait(hub->desc.bPwrOn2PwrGood * 2 * 1000);
}
}
void usb_hub_reset(int bus_index)
{
usb_hub_index[bus_index] = 0;
}
struct usb_hub_device *usb_hub_allocate(void)
{
if (usb_hub_index[bus_index] < USB_MAX_HUB)
{
return &hub_dev[bus_index][usb_hub_index[bus_index]++];
}
dbg("ERROR: USB_MAX_HUB (%d) reached\r\n", USB_MAX_HUB);
return NULL;
}
#define MAX_TRIES 5
static inline char *portspeed(int portstatus)
{
if (portstatus & (1 << USB_PORT_FEAT_HIGHSPEED))
{
return "480 Mb/s";
}
else if (portstatus & (1 << USB_PORT_FEAT_LOWSPEED))
{
return "1.5 Mb/s";
}
else
{
return "12 Mb/s";
}
}
int hub_port_reset(struct usb_device *dev, int port, unsigned short *portstat)
{
int tries;
struct usb_port_status portsts;
unsigned short portstatus, portchange;
dbg("");
dbg("hub_port_reset: resetting port %d...\r\n", port + 1);
for (tries = 0; tries < MAX_TRIES; tries++)
{
usb_set_port_feature(dev, port + 1, USB_PORT_FEAT_RESET);
#ifdef USB_POLL_HUB
if (pxCurrentTCB != NULL)
vTaskDelay((200 * configTICK_RATE_HZ) / 1000);
else
#endif
wait(10 * 1000);
if (usb_get_port_status(dev, port + 1, &portsts) < 0)
{
dbg("get_port_status failed status %lX\r\n", dev->status);
return -1;
}
portstatus = swpw(portsts.wPortStatus);
portchange = swpw(portsts.wPortChange);
dbg("USB %d portstatus 0x%x, change 0x%x, %s\r\n", dev->usbnum, portstatus, portchange, portspeed(portstatus));
dbg("STAT_C_CONNECTION = %d STAT_CONNECTION = %d USB_PORT_STAT_ENABLE = %d\r\n",
(portchange & USB_PORT_STAT_C_CONNECTION) ? 1 : 0,
(portstatus & USB_PORT_STAT_CONNECTION) ? 1 : 0,
(portstatus & USB_PORT_STAT_ENABLE) ? 1 : 0);
if ((portchange & USB_PORT_STAT_C_CONNECTION) || !(portstatus & USB_PORT_STAT_CONNECTION))
{
return -1;
}
if (portstatus & USB_PORT_STAT_ENABLE)
{
break;
}
#ifdef USB_POLL_HUB
if (pxCurrentTCB != NULL)
vTaskDelay((200*configTICK_RATE_HZ)/1000);
else
#endif
wait(20 * 1000);
}
if (tries == MAX_TRIES)
{
dbg("USB %d, cannot enable port %d after %d retries, disabling port.\r\n", dev->usbnum, port + 1, MAX_TRIES);
dbg("Maybe the USB cable is bad?\r\n");
return -1;
}
usb_clear_port_feature(dev, port + 1, USB_PORT_FEAT_C_RESET);
*portstat = portstatus;
return 0;
}
void usb_hub_port_connect_change(struct usb_device *dev, int port)
{
struct usb_device *usb;
struct usb_port_status portsts;
unsigned short portstatus;
/* Check status */
if (usb_get_port_status(dev, port + 1, &portsts) < 0)
{
dbg("USB %d get_port_status failed\r\n", dev->usbnum);
return;
}
portstatus = swpw(portsts.wPortStatus);
#ifdef USB_DEBUG
{
unsigned short portchange;
portchange = swpw(portsts.wPortChange);
dbg("USB %d, portstatus %x, change %x, %s\r\n", dev->usbnum, portstatus, portchange, portspeed(portstatus));
}
#endif /* USB_DEBUG */
/* Clear the connection change status */
usb_clear_port_feature(dev, port + 1, USB_PORT_FEAT_C_CONNECTION);
/* Disconnect any existing devices under this port */
if (((!(portstatus & USB_PORT_STAT_CONNECTION))
&& (!(portstatus & USB_PORT_STAT_ENABLE))) || (dev->children[port]))
{
dbg("USB %d port %i disconnected\r\n", dev->usbnum, port + 1);
usb_disconnect(&dev->children[port]);
/* Return now if nothing is connected */
if (!(portstatus & USB_PORT_STAT_CONNECTION))
{
return;
}
}
#ifdef USB_POLL_HUB
if (pxCurrentTCB != NULL)
vTaskDelay((200*configTICK_RATE_HZ)/1000);
else
#endif
wait(2000);
/* Reset the port */
if (hub_port_reset(dev, port, &portstatus) < 0)
{
dbg("USB %d cannot reset port %i!?\r\n", dev->usbnum, port + 1);
return;
}
#ifdef USB_POLL_HUB
if (pxCurrentTCB != NULL)
vTaskDelay((200*configTICK_RATE_HZ)/1000);
else
#endif
wait(2000);
/* Allocate a new device struct for it */
usb = usb_alloc_new_device(dev->usbnum, dev->priv_hcd);
if (portstatus & USB_PORT_STAT_HIGH_SPEED)
{
usb->speed = USB_SPEED_HIGH;
}
else if (portstatus & USB_PORT_STAT_LOW_SPEED)
{
usb->speed = USB_SPEED_LOW;
}
else
{
usb->speed = USB_SPEED_FULL;
}
dbg("usb device = %p\r\n", usb);
dev->children[port] = usb;
usb->parent = dev;
/* Run it through the hoops (find a driver, etc) */
if (usb_new_device(usb))
{
/* Woops, disable the port */
dbg("USB %d hub: disabling port %d\r\n", dev->usbnum, port + 1);
usb_clear_port_feature(dev, port + 1, USB_PORT_FEAT_ENABLE);
}
#ifdef USB_POLL_HUB
else if (pxCurrentTCB != NULL)
{
usb_kbd_register(usb);
usb_mouse_register(usb);
#ifdef CONFIG_USB_STORAGE
usb_stor_register(usb);
#endif /* CONFIG_USB_STORAGE */
}
#endif
}
static void usb_hub_events(struct usb_device *dev)
{
int i;
struct usb_hub_device *hub = dev->hub;
if (hub == NULL)
{
return;
}
for (i = 0; i < dev->maxchild; i++)
{
struct usb_port_status portsts;
unsigned short portstatus, portchange;
if (usb_get_port_status(dev, i + 1, &portsts) < 0)
{
dbg("get_port_status failed\r\n");
continue;
}
portstatus = swpw(portsts.wPortStatus);
portchange = swpw(portsts.wPortChange);
dbg("USB %d Port %d Status %X Change %X\r\n", dev->usbnum, i + 1, portstatus, portchange);
if (portchange & USB_PORT_STAT_C_CONNECTION)
{
dbg("USB %d port %d connection change\r\n", dev->usbnum, i + 1);
usb_hub_port_connect_change(dev, i);
}
if (portchange & USB_PORT_STAT_C_ENABLE)
{
dbg("USB %d port %d enable change, status %x\r\n", dev->usbnum, i + 1, portstatus);
usb_clear_port_feature(dev, i + 1, USB_PORT_FEAT_C_ENABLE);
/*
* EM interference sometimes causes bad shielded USB
* devices to be shutdown by the hub, this hack enables
* them again. Works at least with mouse driver
*/
if (!(portstatus & USB_PORT_STAT_ENABLE) && (portstatus & USB_PORT_STAT_CONNECTION) && ((dev->children[i])))
{
dbg("USB %d already running port %i disabled by hub (EMI?), re-enabling...\r\n", dev->usbnum, i + 1);
usb_hub_port_connect_change(dev, i);
}
}
if (portstatus & USB_PORT_STAT_SUSPEND)
{
dbg("USB %d port %d suspend change\r\n", dev->usbnum, i + 1);
usb_clear_port_feature(dev, i + 1, USB_PORT_FEAT_SUSPEND);
}
if (portchange & USB_PORT_STAT_C_OVERCURRENT)
{
dbg("USB %d port %d over-current change\r\n", dev->usbnum, i + 1);
usb_clear_port_feature(dev, i + 1, USB_PORT_FEAT_C_OVER_CURRENT);
usb_hub_power_on(hub);
}
if (portchange & USB_PORT_STAT_C_RESET)
{
dbg("USB %d port %d reset change\r\n", dev->usbnum, i + 1);
usb_clear_port_feature(dev, i + 1, USB_PORT_FEAT_C_RESET);
}
} /* end for i all ports */
}
#ifdef USB_POLL_HUB
void usb_poll_hub_task(void *pvParameters)
{
int index_bus = 0;
portTickType timeout = configTICK_RATE_HZ/10;
if (pvParameters);
while(1)
{
if (xQueueAltReceive(queue_poll_hub, &index_bus, timeout) == pdPASS)
{
if ((index_bus >= 0) && (index_bus < USB_MAX_BUS) && (controller_priv[index_bus] != NULL))
{
dbg("USB %d event change\r\n", index_bus);
#ifdef CONFIG_USB_INTERRUPT_POLLING
*vblsem = 0;
#endif
usb_hub_events(&usb_dev[index_bus * USB_MAX_DEVICE]);
#ifdef CONFIG_USB_INTERRUPT_POLLING
*vblsem = 1;
#endif
}
}
else /* timeout */
{
int i;
#ifdef CONFIG_USB_INTERRUPT_POLLING
*vblsem = 0;
#endif
for (i = 0; i < USB_MAX_BUS ; i++)
{
if (controller_priv[i] != NULL)
usb_hub_events(&usb_dev[i * USB_MAX_DEVICE]);
}
#ifdef CONFIG_USB_INTERRUPT_POLLING
*vblsem = 1;
#endif
}
timeout = portMAX_DELAY;
}
}
#endif /* USB_POLL_HUB */
int usb_hub_configure(struct usb_device *dev)
{
unsigned char *buffer;
unsigned char *bitmap;
struct usb_hub_descriptor *descriptor;
int i;
struct usb_hub_device *hub;
/* "allocate" Hub device */
hub = usb_hub_allocate();
dev->hub = hub;
if (hub == NULL)
{
dbg("could not allocate hub\r\n");
return -1;
}
hub->pusb_dev = dev;
buffer = (unsigned char *) driver_mem_alloc(USB_BUFSIZ);
if (buffer == NULL)
{
dbg("driver_mem_alloc() failure\r\n");
return -1;
}
/* Get the the hub descriptor */
if (usb_get_hub_descriptor(dev, buffer, 4) < 0)
{
dbg("failed to get hub descriptor, giving up %lX\r\n", dev->status);
driver_mem_free(buffer);
return -1;
}
dbg("bLength:0x%02X bDescriptorType:0x%02X bNbrPorts:0x%02X\r\n", buffer[0], buffer[1], buffer[2]);
descriptor = (struct usb_hub_descriptor *)buffer;
/* silence compiler warning if USB_BUFSIZ is > 256 [= sizeof(char)] */
i = descriptor->bLength;
if (i > USB_BUFSIZ)
{
dbg("failed to get hub descriptor - too long: %d\r\n", descriptor->bLength);
driver_mem_free(buffer);
return -1;
}
if (usb_get_hub_descriptor(dev, buffer, descriptor->bLength) < 0)
{
dbg("failed to get hub descriptor 2nd giving up %lX\r\n", dev->status);
driver_mem_free(buffer);
return -1;
}
memcpy((unsigned char *) &hub->desc, buffer, descriptor->bLength);
/* adjust 16bit values */
hub->desc.wHubCharacteristics = swpw(descriptor->wHubCharacteristics);
/* set the bitmap */
bitmap = (unsigned char *) &hub->desc.DeviceRemovable[0];
/* devices not removable by default */
memset(bitmap, 0xff, (USB_MAXCHILDREN + 1 + 7) / 8);
bitmap = (unsigned char *) &hub->desc.PortPowerCtrlMask[0];
memset(bitmap, 0xff, (USB_MAXCHILDREN + 1 + 7) / 8); /* PowerMask = 1B */
for (i = 0; i < ((hub->desc.bNbrPorts + 1 + 7) / 8); i++)
{
hub->desc.DeviceRemovable[i] = descriptor->DeviceRemovable[i];
}
for (i = 0; i < ((hub->desc.bNbrPorts + 1 + 7) / 8); i++)
{
hub->desc.DeviceRemovable[i] = descriptor->PortPowerCtrlMask[i];
}
dev->maxchild = descriptor->bNbrPorts;
dbg("USB %d, %d ports detected\r\n", dev->usbnum, dev->maxchild);
if (dev->maxchild >= 10)
{
dev->maxchild = 10;
}
switch(hub->desc.wHubCharacteristics & HUB_CHAR_LPSM)
{
case 0x00: dbg("ganged power switching\r\n"); break;
case 0x01: dbg("individual port power switching\r\n"); break;
case 0x02:
case 0x03: dbg("unknown reserved power switching mode\r\n"); break;
}
if (hub->desc.wHubCharacteristics & HUB_CHAR_COMPOUND)
{
dbg("part of a compound device\r\n");
}
else
{
dbg("standalone hub\r\n");
}
switch(hub->desc.wHubCharacteristics & HUB_CHAR_OCPM)
{
case 0x00: dbg("global over-current protection\r\n"); break;
case 0x08: dbg("individual port over-current protection\r\n"); break;
case 0x10:
case 0x18: dbg("no over-current protection\r\n"); break;
}
dbg("power on to power good time: %dms\r\n", descriptor->bPwrOn2PwrGood * 2);
dbg("hub controller current requirement: %dmA\r\n", descriptor->bHubContrCurrent);
for (i = 0; i < dev->maxchild; i++)
{
dbg("USB %d port %d is%s removable\r\n",
dev->usbnum, i + 1,
hub->desc.DeviceRemovable[(i + 1) / 8] & (1 << ((i + 1) % 8)) ? " not" : "");
}
if (sizeof(struct usb_hub_status) > USB_BUFSIZ)
{
dbg("usb_hub_configure: failed to get Status - too long: %d\r\n", descriptor->bLength);
driver_mem_free(buffer);
return -1;
}
if (usb_get_hub_status(dev, buffer) < 0)
{
dbg("usb_hub_configure: failed to get Status %lX\r\n", dev->status);
driver_mem_free(buffer);
return -1;
}
#ifdef DEBUG_HUB
{
struct usb_hub_status *hubsts;
hubsts = (struct usb_hub_status *) buffer;
dbg("get_hub_status returned status %X, change %X\r\n",
swpw(hubsts->wHubStatus), swpw(hubsts->wHubChange));
dbg("local power source is %s\r\n",
(swpw(hubsts->wHubStatus) & HUB_STATUS_LOCAL_POWER) ? "lost (inactive)" : "good");
dbg("%sover-current condition exists\r\n",
(swpw(hubsts->wHubStatus) & HUB_STATUS_OVERCURRENT) ? "" : "no ");
}
#endif /* USB_DEBUG */
usb_hub_power_on(hub);
#ifdef USB_POLL_HUB
if ((queue_poll_hub == NULL) && (pxCurrentTCB != NULL))
{
queue_poll_hub = xQueueCreate(64, sizeof(int));
if (queue_poll_hub != NULL)
{
/* Create poll/event task */
if (xTaskCreate(usb_poll_hub_task, (void *)"USBHub", configMINIMAL_STACK_SIZE, NULL, 16, NULL) != pdPASS)
{
vQueueDelete(queue_poll_hub);
queue_poll_hub = NULL;
}
}
vTaskDelay(configTICK_RATE_HZ);
}
if (queue_poll_hub == NULL)
#endif
usb_hub_events(dev);
driver_mem_free(buffer);
return 0;
}
int usb_hub_probe(struct usb_device *dev, int ifnum)
{
struct usb_interface_descriptor *iface;
struct usb_endpoint_descriptor *ep;
int ret;
iface = &dev->config.if_desc[ifnum];
/* Is it a hub? */
if (iface->bInterfaceClass != USB_CLASS_HUB)
{
dbg("iface->bInterfaceClass != USB_CLASS_HUB (%d), %d instead\r\n", USB_CLASS_HUB, iface->bInterfaceClass);
return 0;
}
/*
* Some hubs have a subclass of 1, which AFAICT according to the
* specs is not defined, but it works
*/
if ((iface->bInterfaceSubClass != 0) && (iface->bInterfaceSubClass != 1))
{
dbg("iface->bInterfaceSubClass != {0, 1} (%d instead)\r\n", iface->bInterfaceSubClass);
return 0;
}
/* Multiple endpoints? What kind of mutant ninja-hub is this? */
if (iface->bNumEndpoints != 1)
{
dbg("iface->bNumEndpoints != 1 (%d instead)\r\n", iface->bNumEndpoints);
return 0;
}
ep = &iface->ep_desc[0];
/* Output endpoint? Curiousier and curiousier.. */
if (!(ep->bEndpointAddress & USB_DIR_IN))
{
dbg("!(ep->bEndpointAddress != USB_DIR_IN (0x%x instead)\r\n", ep->bEndpointAddress);
return 0;
}
/* If it's not an interrupt endpoint, we'd better punt! */
if ((ep->bmAttributes & 3) != 3)
{
return 0;
}
/* We found a hub */
dbg("USB %d hub found\r\n", dev->usbnum);
ret = usb_hub_configure(dev);
return ret;
}

1389
BaS_gcc/usb/usb_kbd.c Normal file

File diff suppressed because it is too large Load Diff

301
BaS_gcc/usb/usb_mouse.c Normal file
View File

@@ -0,0 +1,301 @@
/*
*
* See file CREDITS for list of people who contributed to this
* project.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*/
#include <stdint.h>
#include "bas_printf.h"
#include "usb.h"
#include "exceptions.h"
#include "driver_mem.h"
#define DEBUG_USBMOUSE
#ifdef DEBUG_USBMOUSE
#define dbg(format, arg...) do { xprintf("DEBUG: %s(): " format, __FUNCTION__, ##arg); } while (0)
#else
#define dbg(format, arg...) do { ; } while (0)
#endif /* DEBUG_USBMOUSE */
#define err(format, arg...) do { xprintf("ERROR: %s(): " format, __FUNCTION__, ##arg); } while (0)
extern void ltoa(char *buf, long n, unsigned long base);
extern void call_mousevec(unsigned char *data, void (**mousevec)(void *));
//extern void call_ikbdvec(unsigned char code, _IOREC *iorec, void (**ikbdvec)());
static unsigned char *new;
static unsigned char old[8];
static int mouse_installed;
/* forward declaration */
static int usb_mouse_probe(struct usb_device *dev, unsigned int ifnum);
/* deregistering the mouse */
int usb_mouse_deregister(struct usb_device *dev)
{
dev->irq_handle = NULL;
if (new != NULL)
{
driver_mem_free(new);
new = NULL;
}
mouse_installed = 0;
dbg("USB MOUSE deregister\r\n");
return 1;
}
/* registering the mouse */
int usb_mouse_register(struct usb_device *dev)
{
if (!mouse_installed && (dev->devnum != -1) && (usb_mouse_probe(dev, 0) == 1))
{
/* Ok, we found a mouse */
dbg("USB MOUSE found (USB: %d, devnum: %d)\r\n", dev->usbnum, dev->devnum);
mouse_installed = 1;
dev->deregister = usb_mouse_deregister;
return 1;
}
/* no USB Mouse found */
return -1;
}
/* search for mouse and register it if found */
int drv_usb_mouse_init(void)
{
int i;
int j;
/*
* check if mouse is already initialized
*/
if (mouse_installed)
{
xprintf("USB mouse already initialized\r\n");
return -1;
}
/* scan all USB Devices */
for (j = 0; j < USB_MAX_BUS; j++)
{
for (i = 0; i < USB_MAX_DEVICE; i++)
{
struct usb_device *dev = usb_get_dev_index(i, j); /* get device */
if (dev == NULL)
{
break;
}
xprintf("Try to register usb device %d,%d as mouse\r\n", i, j);
if (usb_mouse_register(dev) > 0)
return 1;
}
}
/* no USB Mouse found */
return -1;
}
/**************************************************************************
* Low Level drivers
*/
static void usb_kbd_send_code(unsigned char code)
{
dbg("FIXME: usb_kbd_send_code 0x%x not implemented\r\n", code);
}
/* Interrupt service routine */
static int usb_mouse_irq(struct usb_device *dev)
{
#ifdef CONFIG_USB_INTERRUPT_POLLING
int level;
#endif
int i, change = 0;
if ((dev->irq_status != 0) || (dev->irq_act_len < 3) || (dev->irq_act_len > 8))
{
dbg("USB MOUSE error %lX, len %d\r\n", dev->irq_status, dev->irq_act_len);
return 1;
}
for (i = 0; i < dev->irq_act_len; i++)
{
if (new[i] != old[i])
{
change = 1;
break;
}
}
if (change)
{
char wheel = 0, buttons, old_buttons;
dbg("USB MOUSE len:%d %02X %02X %02X %02X %02X %02X\r\n", dev->irq_act_len, new[0], new[1], new[2], new[3], new[4], new[5]);
#ifdef CONFIG_USB_INTERRUPT_POLLING
level = set_ipl(7); /* mask interrupts */
#endif
if ((dev->irq_act_len >= 6) && (new[0] == 1)) /* report-ID */
{
buttons = new[1];
old_buttons = old[1];
new[0] = ((new[1] & 1) << 1) + ((new[1] & 2) >> 1) + 0xF8;
new[1] = new[2];
new[2] = new[3];
wheel = new[4];
}
else /* boot report */
{
buttons = new[0];
old_buttons = old[0];
new[0] = ((new[0] & 1) << 1) + ((new[0] & 2) >> 1) + 0xF8;
if (dev->irq_act_len >= 3)
wheel = new[3];
}
if ((buttons ^ old_buttons) & 4) /* 3rd button */
{
if (buttons & 4)
{
usb_kbd_send_code(0x72); /* ENTER */
usb_kbd_send_code(0xF2);
}
}
if (wheel != 0) /* actually like Eiffel */
{
#define REPEAT_WHEEL 3
int i;
if (wheel > 0)
{
for (i = 0; i < REPEAT_WHEEL; i++)
{
usb_kbd_send_code(0x48); /* UP */
usb_kbd_send_code(0xC8);
}
}
else
{
for (i = 0; i < REPEAT_WHEEL; i++)
{
usb_kbd_send_code(0x50); /* DOWN */
usb_kbd_send_code(0xD0);
}
}
}
xprintf("FIXME: call_mousevec(new, mousevec) not implemented\r\n");
//if(mousevec != NULL)
//call_mousevec(new, mousevec);
#ifdef CONFIG_USB_INTERRUPT_POLLING
set_ipl(level);
#endif
old[0] = new[0];
old[1] = new[1];
old[2] = new[2];
old[3] = new[3];
old[4] = new[4];
old[5] = new[5];
}
return 1; /* install IRQ Handler again */
}
/* probes the USB device dev for mouse type */
static int usb_mouse_probe(struct usb_device *dev, unsigned int ifnum)
{
struct usb_interface_descriptor *iface;
struct usb_endpoint_descriptor *ep;
int pipe;
int maxp;
#ifdef _NOT_USED_
if (dev->descriptor.bNumConfigurations != 1)
{
dbg("dev->descriptor.bNumConfigurations != 1\r\n");
return 0;
}
#endif
iface = &dev->config.if_desc[ifnum];
if (iface->bInterfaceClass != USB_CLASS_HID)
{
dbg("iface->bInterfaceClass != USB_CLASS_HID (%d instead)\r\n", iface->bInterfaceClass);
return 0;
}
if (iface->bInterfaceSubClass != USB_SUB_HID_BOOT)
{
dbg("iface->bInterfaceSubClass != USB_SUB_HID_BOOT (%d instead)\r\n", iface->bInterfaceSubClass);
return 0;
}
if (iface->bInterfaceProtocol != USB_PROT_HID_MOUSE)
{
dbg("iface->bInterfaceProtocol != USB_PROT_HID_MOUSE (%d)\r\n", iface->bInterfaceProtocol);
return 0;
}
if (iface->bNumEndpoints != 1)
{
dbg("iface->bNumEndpoints != 1\r\n");
return 0;
}
ep = &iface->ep_desc[0];
if (!(ep->bEndpointAddress & 0x80))
{
dbg("! ep->bEndpointAddress & 0x80\r\n");
return 0;
}
if ((ep->bmAttributes & 3) != 3)
{
dbg("ep->bmAttributes & 3 != 3\r\n");
return 0;
}
new = (unsigned char *) driver_mem_alloc(8);
if (new == NULL)
{
dbg("new == NULL\r\n");
return 0;
}
dbg("USB MOUSE found set protocol...\r\n");
/* ok, we found a USB Mouse, install it */
pipe = usb_rcvintpipe(dev, ep->bEndpointAddress);
maxp = usb_maxpacket(dev, pipe);
// if(maxp < 6)
// usb_set_protocol(dev, iface->bInterfaceNumber, 0); /* boot */
// else
usb_set_protocol(dev, iface->bInterfaceNumber, 1); /* report */
dbg("USB MOUSE found set idle...\r\n");
usb_set_idle(dev, iface->bInterfaceNumber, 0, 0); /* report infinite */
memset(&new[0], 0, 8);
memset(&old[0], 0, 8);
dev->irq_handle = usb_mouse_irq;
dbg("USB MOUSE enable interrupt pipe (maxp: %d)...\r\n", maxp);
usb_submit_int_msg(dev, pipe, &new[0], maxp > 8 ? 8 : maxp, ep->bInterval);
return 1;
}