Index: firmware/export/config-e200.h =================================================================== --- firmware/export/config-e200.h (revision 20668) +++ firmware/export/config-e200.h (working copy) @@ -178,6 +178,9 @@ #define USB_VENDOR_ID 0x0781 #define USB_PRODUCT_ID 0x7421 +#define USB_HID +#define USB_SERIAL + /* Virtual LED (icon) */ #define CONFIG_LED LED_VIRTUAL Index: firmware/SOURCES =================================================================== --- firmware/SOURCES (revision 20668) +++ firmware/SOURCES (working copy) @@ -260,6 +260,7 @@ usbstack/usb_storage.c usbstack/usb_serial.c usbstack/usb_charging_only.c +usbstack/usb_hid.c #if CONFIG_USBOTG == USBOTG_ARC target/arm/usb-drv-arc.c #elif CONFIG_USBOTG == USBOTG_ISP1583 Index: firmware/usbstack/usb_hid.c =================================================================== --- firmware/usbstack/usb_hid.c (revision 0) +++ firmware/usbstack/usb_hid.c (revision 0) @@ -0,0 +1,193 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 by Tomer Shalev + * + * 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 software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include "string.h" +#include "system.h" +#include "usb_core.h" +#include "usb_drv.h" +#include "kernel.h" +#include "usb_hid.h" + +//#define LOGF_ENABLE +#include "logf.h" + +#ifdef USB_HID + +/* serial interface */ +static struct usb_interface_descriptor __attribute__((aligned(2))) + interface_descriptor = +{ + .bLength = sizeof(struct usb_interface_descriptor), + .bDescriptorType = USB_DT_INTERFACE, + .bInterfaceNumber = 0, + .bAlternateSetting = 0, + .bNumEndpoints = 2, + .bInterfaceClass = USB_CLASS_HID, + .bInterfaceSubClass = 0, + .bInterfaceProtocol = 0, + .iInterface = 0 +}; + + +static struct usb_endpoint_descriptor __attribute__((aligned(2))) endpoint_descriptor = +{ + .bLength = sizeof(struct usb_endpoint_descriptor), + .bDescriptorType = USB_DT_ENDPOINT, + .bEndpointAddress = 0, + .bmAttributes = USB_ENDPOINT_XFER_INT, + .wMaxPacketSize = 0, + .bInterval = 0 +}; + +#define BUFFER_SIZE 512 +static unsigned char send_buffer[BUFFER_SIZE] + USB_DEVBSS_ATTR __attribute__((aligned(32))); +static unsigned char receive_buffer[32] + USB_DEVBSS_ATTR __attribute__((aligned(32))); + +static bool active = false; + +static int ep_in, ep_out; +static int usb_interface; + +int usb_hid_request_endpoints(struct usb_class_driver *drv) +{ + ep_in = usb_core_request_endpoint(USB_DIR_IN, drv); + if (ep_in < 0) + return -1; + + ep_out = usb_core_request_endpoint(USB_DIR_OUT, drv); + if (ep_out < 0) + { + usb_core_release_endpoint(ep_in); + return -1; + } + + return 0; +} + +int usb_hid_set_first_interface(int interface) +{ + usb_interface = interface; + + return interface + 1; +} + + +int usb_hid_get_config_descriptor(unsigned char *dest,int max_packet_size) +{ + unsigned char *orig_dest = dest; + + endpoint_descriptor.wMaxPacketSize = max_packet_size; + interface_descriptor.bInterfaceNumber = usb_interface; + + memcpy(dest, &interface_descriptor, sizeof(struct usb_interface_descriptor)); + dest += sizeof(struct usb_interface_descriptor); + + endpoint_descriptor.bEndpointAddress = ep_in; + memcpy(dest, &endpoint_descriptor, sizeof(struct usb_endpoint_descriptor)); + dest += sizeof(struct usb_endpoint_descriptor); + + endpoint_descriptor.bEndpointAddress = ep_out; + memcpy(dest, &endpoint_descriptor, sizeof(struct usb_endpoint_descriptor)); + dest += sizeof(struct usb_endpoint_descriptor); + + return (dest - orig_dest); +} + +/* called by usb_core_control_request() */ +bool usb_hid_control_request(struct usb_ctrlrequest* req) +{ + bool handled = false; + + switch (req->bRequest) { + default: + logf("hid: unhandeld req %d", req->bRequest); + } + return handled; +} + +void usb_hid_init_connection(void) +{ + logf("hid: init connection"); + + /* prime rx endpoint */ + usb_drv_recv(ep_out, receive_buffer, sizeof receive_buffer); + + active = true; +} + +/* called by usb_code_init() */ +void usb_hid_init(void) +{ + logf("hid: init"); + active = true; +} + +void usb_hid_disconnect(void) +{ + logf("hid: disconnect"); + + active = false; +} + +void usb_hid_send(unsigned char *data, int length) +{ + (void)data; + (void)(length); + + logf("hid: send %d bytes: \"%s\"", length, data); + + if(!active) + return; + + if(length <= 0) + return; +} + +/* called by usb_core_transfer_complete() */ +void usb_hid_transfer_complete(int ep,int dir, int status, int length) +{ + (void)ep; + (void)length; + + logf("hid: transfer complete. ep %d, dir %d, status %d ,length %d", + ep, dir, status, length); + + switch (dir) { + case USB_DIR_OUT: + logf("serial: %s", receive_buffer); + /* Data received. TODO : Do something with it ? */ + + /* Get the next bit */ + usb_drv_recv(ep_out, receive_buffer, sizeof receive_buffer); + break; + + case USB_DIR_IN: + /* Data sent out. Update circular buffer */ + if(status == 0) + { + } + + break; + } +} + +#endif /*USB_HID*/ Index: firmware/usbstack/usb_hid.h =================================================================== --- firmware/usbstack/usb_hid.h (revision 0) +++ firmware/usbstack/usb_hid.h (revision 0) @@ -0,0 +1,38 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: usb_hid.h 18703 2008-10-03 22:43:16Z gevaerts $ + * + * Copyright (C) 2007 by Christian Gmeiner + * + * 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 software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#ifndef USB_HID_H +#define USB_HID_H + +#include "usb_ch9.h" + +int usb_hid_request_endpoints(struct usb_class_driver *drv); +int usb_hid_set_first_interface(int interface); +int usb_hid_get_config_descriptor(unsigned char *dest, int max_packet_size); +void usb_hid_init_connection(void); +void usb_hid_init(void); +void usb_hid_disconnect(void); +void usb_hid_transfer_complete(int ep, int dir, int status, int length); +bool usb_hid_control_request(struct usb_ctrlrequest *req); + +void usb_hid_send(unsigned char *data,int length); + +#endif +