mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-11-08 14:43:04 +08:00
Merge pull request #981 from enkiller/modify_usb_stack_
[usb]update usb stack
This commit is contained in:
21 files changed
+2744
-261
No files matched your search
@@ -313,12 +313,12 @@ typedef struct uiad_descriptor* uiad_desc_t;
|
||||
|
||||
struct uendpoint_descriptor
|
||||
{
|
||||
rt_uint8_t bLength;
|
||||
rt_uint8_t type;
|
||||
rt_uint8_t bEndpointAddress;
|
||||
rt_uint8_t bmAttributes;
|
||||
rt_uint8_t bLength;
|
||||
rt_uint8_t type;
|
||||
rt_uint8_t bEndpointAddress;
|
||||
rt_uint8_t bmAttributes;
|
||||
rt_uint16_t wMaxPacketSize;
|
||||
rt_uint8_t bInterval;
|
||||
rt_uint8_t bInterval;
|
||||
};
|
||||
typedef struct uendpoint_descriptor* uep_desc_t;
|
||||
|
||||
@@ -358,33 +358,38 @@ struct usb_qualifier_descriptor
|
||||
rt_uint8_t bRESERVED;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
#ifndef HID_SUB_DESCRIPTOR_MAX
|
||||
#define HID_SUB_DESCRIPTOR_MAX 1
|
||||
#endif
|
||||
struct uhid_descriptor
|
||||
{
|
||||
rt_uint8_t bLength;
|
||||
rt_uint8_t type;
|
||||
rt_uint8_t bLength;
|
||||
rt_uint8_t type;
|
||||
rt_uint16_t bcdHID;
|
||||
rt_uint8_t bCountryCode;
|
||||
rt_uint8_t bNumDescriptors;
|
||||
rt_uint8_t bCountryCode;
|
||||
rt_uint8_t bNumDescriptors;
|
||||
struct hid_descriptor_list
|
||||
{
|
||||
rt_uint8_t type;
|
||||
rt_uint16_t wLength;
|
||||
}Descriptor[1];
|
||||
}Descriptor[HID_SUB_DESCRIPTOR_MAX];
|
||||
};
|
||||
typedef struct uhid_descriptor* uhid_desc_t;
|
||||
|
||||
struct urequest
|
||||
{
|
||||
rt_uint8_t request_type;
|
||||
rt_uint8_t request;
|
||||
rt_uint16_t value;
|
||||
rt_uint16_t index;
|
||||
rt_uint16_t length;
|
||||
rt_uint8_t request_type;
|
||||
rt_uint8_t bRequest;
|
||||
rt_uint16_t wValue;
|
||||
rt_uint16_t wIndex;
|
||||
rt_uint16_t wLength;
|
||||
};
|
||||
typedef struct urequest* ureq_t;
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a, b) (a < b ? a : b)
|
||||
#endif
|
||||
#ifndef MAX
|
||||
#define MAX(a, b) (a > b ? a : b)
|
||||
#endif
|
||||
|
||||
|
||||
@@ -28,13 +28,13 @@
|
||||
#define __USB_DEVICE_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
#include "usb_common.h"
|
||||
#include "drivers/usb_common.h"
|
||||
|
||||
/* Vendor ID */
|
||||
#ifdef USB_VENDOR_ID
|
||||
#define _VENDOR_ID USB_VENDOR_ID
|
||||
#define _VENDOR_ID USB_VENDOR_ID
|
||||
#else
|
||||
#define _VENDOR_ID 0x0EFF
|
||||
#define _VENDOR_ID 0x0EFF
|
||||
#endif
|
||||
/* Product ID */
|
||||
#ifdef USB_PRODUCT_ID
|
||||
@@ -76,7 +76,7 @@ typedef enum
|
||||
/* request to read full count */
|
||||
UIO_REQUEST_READ_FULL,
|
||||
/* request to read any count */
|
||||
UIO_REQUEST_READ_MOST,
|
||||
UIO_REQUEST_READ_BEST,
|
||||
/* request to write full count */
|
||||
UIO_REQUEST_WRITE,
|
||||
}UIO_REQUEST_TYPE;
|
||||
@@ -99,11 +99,11 @@ struct udcd_ops
|
||||
|
||||
struct ep_id
|
||||
{
|
||||
rt_uint8_t addr;
|
||||
rt_uint8_t type;
|
||||
rt_uint8_t dir;
|
||||
rt_uint8_t maxpacket;
|
||||
rt_uint8_t status;
|
||||
rt_uint8_t addr;
|
||||
rt_uint8_t type;
|
||||
rt_uint8_t dir;
|
||||
rt_uint16_t maxpacket;
|
||||
rt_uint8_t status;
|
||||
};
|
||||
|
||||
typedef rt_err_t (*udep_handler_t)(struct ufunction* func, rt_size_t size);
|
||||
@@ -238,7 +238,7 @@ struct udev_msg
|
||||
udcd_t dcd;
|
||||
union
|
||||
{
|
||||
struct ep_msg ep_msg;
|
||||
struct ep_msg ep_msg;
|
||||
struct urequest setup;
|
||||
} content;
|
||||
};
|
||||
@@ -295,7 +295,7 @@ rt_err_t rt_usbd_ep0_clear_stall(udevice_t device);
|
||||
rt_err_t rt_usbd_ep0_setup_handler(udcd_t dcd, struct urequest* setup);
|
||||
rt_err_t rt_usbd_ep0_in_handler(udcd_t dcd);
|
||||
rt_err_t rt_usbd_ep0_out_handler(udcd_t dcd, rt_size_t size);
|
||||
rt_err_t rt_usbd_ep_in_handler(udcd_t dcd, rt_uint8_t address);
|
||||
rt_err_t rt_usbd_ep_in_handler(udcd_t dcd, rt_uint8_t address, rt_size_t size);
|
||||
rt_err_t rt_usbd_ep_out_handler(udcd_t dcd, rt_uint8_t address, rt_size_t size);
|
||||
rt_err_t rt_usbd_reset_handler(udcd_t dcd);
|
||||
rt_err_t rt_usbd_connect_handler(udcd_t dcd);
|
||||
|
||||
@@ -2,13 +2,12 @@
|
||||
import os
|
||||
from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
objs = []
|
||||
list = os.listdir(cwd)
|
||||
cwd = GetCurrentDir()
|
||||
objs = []
|
||||
list = os.listdir(cwd)
|
||||
|
||||
for d in list:
|
||||
path = os.path.join(cwd, d)
|
||||
if os.path.isfile(os.path.join(path, 'SConscript')):
|
||||
objs = objs + SConscript(os.path.join(d, 'SConscript'))
|
||||
|
||||
Return('objs')
|
||||
@@ -9,12 +9,15 @@ core/usbdevice.c
|
||||
|
||||
if GetDepend('RT_USB_DEVICE_CDC'):
|
||||
src += Glob('class/cdc_vcom.c')
|
||||
|
||||
if GetDepend('RT_USB_DEVICE_HID'):
|
||||
src += Glob('class/hid.c')
|
||||
|
||||
if GetDepend('RT_USB_DEVICE_MSTORAGE'):
|
||||
src += Glob('class/mstorage.c')
|
||||
|
||||
CPPPATH = [cwd]
|
||||
|
||||
group = DefineGroup('DeviceDrivers', src, depend = ['RT_USING_USB_DEVICE'], CPPPATH = CPPPATH)
|
||||
group = DefineGroup('rt_usbd', src, depend = ['RT_USING_USB_DEVICE'], CPPPATH = CPPPATH)
|
||||
|
||||
Return('group')
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* File : hid.h
|
||||
* COPYRIGHT (C) 2008 - 2016, RT-Thread Development Team
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017Äê3ÔÂ13ÈÕ Urey the first version
|
||||
*/
|
||||
#ifndef _USBDEVICE_CLASS_HID_H_
|
||||
#define _USBDEVICE_CLASS_HID_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define HID_DESCRIPTOR_TYPE 0x21
|
||||
#define HID_DESCRIPTOR_SIZE 0x09
|
||||
#define HID_OFF_HID_DESC 0x12
|
||||
|
||||
#define USB_HID_SUBCLASS_BOOT 0x01
|
||||
#define USB_HID_SUBCLASS_NOBOOT 0x00
|
||||
|
||||
#define USB_HID_PROTOCOL_NONE 0x00
|
||||
#define USB_HID_PROTOCOL_KEYBOARD 0x01
|
||||
#define USB_HID_PROTOCOL_MOUSE 0x02
|
||||
|
||||
|
||||
#define USB_HID_REQ_GET_REPORT 0x01
|
||||
#define USB_HID_REQ_GET_IDLE 0x02
|
||||
#define USB_HID_REQ_GET_PROTOCOL 0x03
|
||||
#define USB_HID_REQ_SET_REPORT 0x09
|
||||
#define USB_HID_REQ_SET_IDLE 0x0a
|
||||
#define USB_HID_REQ_SET_PROTOCOL 0x0b
|
||||
|
||||
#define MAX_REPORT_SIZE 8
|
||||
#define HID_RX_BUFSIZE 64
|
||||
|
||||
struct uhid_comm_descriptor
|
||||
{
|
||||
#ifdef RT_USB_DEVICE_COMPOSITE
|
||||
struct uiad_descriptor iad_desc;
|
||||
#endif
|
||||
struct uinterface_descriptor intf_desc;
|
||||
struct uhid_descriptor hid_desc;
|
||||
struct uendpoint_descriptor ep_in_desc;
|
||||
struct uendpoint_descriptor ep_out_desc;
|
||||
};
|
||||
typedef struct uhid_comm_descriptor* uhid_comm_desc_t;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _USBDEVICE_CLASS_HID_H_ */
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rtservice.h>
|
||||
#include <rtdevice.h>
|
||||
#include "drivers/usb_device.h"
|
||||
#include "mstorage.h"
|
||||
|
||||
#ifdef RT_USB_DEVICE_MSTORAGE
|
||||
@@ -112,6 +112,8 @@ static struct usb_qualifier_descriptor dev_qualifier =
|
||||
0,
|
||||
};
|
||||
|
||||
|
||||
|
||||
const static struct umass_descriptor _mass_desc =
|
||||
{
|
||||
USB_DESC_LENGTH_INTERFACE, //bLength;
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -89,27 +89,47 @@ rt_err_t rt_usb_device_init(void)
|
||||
cfg = rt_usbd_config_new();
|
||||
|
||||
#ifdef RT_USB_DEVICE_MSTORAGE
|
||||
/* create a mass storage function object */
|
||||
func = rt_usbd_function_mstorage_create(udevice);
|
||||
{
|
||||
extern ufunction_t rt_usbd_function_mstorage_create(udevice_t device);
|
||||
/* create a mass storage function object */
|
||||
func = rt_usbd_function_mstorage_create(udevice);
|
||||
|
||||
/* add the function to the configuration */
|
||||
rt_usbd_config_add_function(cfg, func);
|
||||
/* add the function to the configuration */
|
||||
rt_usbd_config_add_function(cfg, func);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef RT_USB_DEVICE_CDC
|
||||
/* create a cdc function object */
|
||||
func = rt_usbd_function_cdc_create(udevice);
|
||||
{
|
||||
extern ufunction_t rt_usbd_function_cdc_create(udevice_t device);
|
||||
/* create a cdc function object */
|
||||
func = rt_usbd_function_cdc_create(udevice);
|
||||
|
||||
/* add the function to the configuration */
|
||||
rt_usbd_config_add_function(cfg, func);
|
||||
/* add the function to the configuration */
|
||||
rt_usbd_config_add_function(cfg, func);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef RT_USB_DEVICE_HID
|
||||
{
|
||||
extern ufunction_t rt_usbd_function_hid_create(udevice_t device);
|
||||
/* create a cdc function object */
|
||||
func = rt_usbd_function_hid_create(udevice);
|
||||
|
||||
/* add the function to the configuration */
|
||||
rt_usbd_config_add_function(cfg, func);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef RT_USB_DEVICE_RNDIS
|
||||
/* create a rndis function object */
|
||||
func = rt_usbd_function_rndis_create(udevice);
|
||||
{
|
||||
extern ufunction_t rt_usbd_function_rndis_create(udevice_t device);
|
||||
/* create a rndis function object */
|
||||
func = rt_usbd_function_rndis_create(udevice);
|
||||
|
||||
/* add the function to the configuration */
|
||||
rt_usbd_config_add_function(cfg, func);
|
||||
/* add the function to the configuration */
|
||||
rt_usbd_config_add_function(cfg, func);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* set device descriptor to the device */
|
||||
@@ -131,5 +151,4 @@ rt_err_t rt_usb_device_init(void)
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -29,6 +29,6 @@ if GetDepend('RT_USBH_HID_KEYBOARD'):
|
||||
CPPPATH = [cwd, cwd + '/class', cwd + '/core', \
|
||||
cwd + '/include', cwd + '../../../include']
|
||||
|
||||
group = DefineGroup('DeviceDrivers', src, depend = ['RT_USING_USB_HOST'], CPPPATH = CPPPATH)
|
||||
group = DefineGroup('rt_usbh', src, depend = ['RT_USING_USBH'], CPPPATH = CPPPATH)
|
||||
|
||||
Return('group')
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* File : hid.h
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2011, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2011-12-12 Yi Qiu first version
|
||||
*/
|
||||
|
||||
#ifndef __HID_H__
|
||||
#define __HID_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
struct uhid
|
||||
{
|
||||
upipe_t pipe_in;
|
||||
rt_uint8_t buffer[8];
|
||||
uprotocal_t protocal;
|
||||
};
|
||||
typedef struct uhid uhid_t;
|
||||
|
||||
#define USB_REQ_GET_REPORT 0x01
|
||||
#define USB_REQ_GET_IDLE 0x02
|
||||
#define USB_REQ_GET_PROTOCOL 0x03
|
||||
#define USB_REQ_SET_REPORT 0x09
|
||||
#define USB_REQ_SET_IDLE 0x0a
|
||||
#define USB_REQ_SET_PROTOCOL 0x0b
|
||||
|
||||
#define USB_HID_KEYBOARD 1
|
||||
#define USB_HID_MOUSE 2
|
||||
|
||||
rt_err_t rt_usbh_hid_set_idle(struct uintf* intf, int duration, int report_id);
|
||||
rt_err_t rt_usbh_hid_get_report(struct uintf* intf, rt_uint8_t type, rt_uint8_t id, rt_uint8_t *buffer, rt_size_t size);
|
||||
rt_err_t rt_usbh_hid_set_report(struct uintf* intf, rt_uint8_t *buffer, rt_size_t size);
|
||||
rt_err_t rt_usbh_hid_set_protocal(struct uintf* intf, int protocol);
|
||||
rt_err_t rt_usbh_hid_get_report_descriptor(struct uintf* intf, rt_uint8_t *buffer, rt_size_t size);
|
||||
rt_err_t rt_usbh_hid_protocal_register(uprotocal_t protocal);
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* File : mass.h
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2011, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2011-12-12 Yi Qiu first version
|
||||
*/
|
||||
|
||||
#ifndef __MASS_H__
|
||||
#define __MASS_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
#include "dfs_fs.h"
|
||||
|
||||
#define MAX_PARTITION_COUNT 4
|
||||
#define SECTOR_SIZE 512
|
||||
|
||||
struct ustor_data
|
||||
{
|
||||
struct dfs_partition part;
|
||||
struct uintf* intf;
|
||||
int udisk_id;
|
||||
const char path;
|
||||
};
|
||||
|
||||
struct ustor
|
||||
{
|
||||
upipe_t pipe_in;
|
||||
upipe_t pipe_out;
|
||||
rt_uint32_t capicity[2];
|
||||
|
||||
struct rt_device dev[MAX_PARTITION_COUNT];
|
||||
rt_uint8_t dev_cnt;
|
||||
};
|
||||
typedef struct ustor* ustor_t;
|
||||
|
||||
rt_err_t rt_usbh_storage_get_max_lun(struct uintf* intf, rt_uint8_t* max_lun);
|
||||
rt_err_t rt_usbh_storage_reset(struct uintf* intf);
|
||||
rt_err_t rt_usbh_storage_read10(struct uintf* intf, rt_uint8_t *buffer,
|
||||
rt_uint32_t sector, rt_size_t count, int timeout);
|
||||
rt_err_t rt_usbh_storage_write10(struct uintf* intf, rt_uint8_t *buffer,
|
||||
rt_uint32_t sector, rt_size_t count, int timeout);
|
||||
rt_err_t rt_usbh_storage_request_sense(struct uintf* intf, rt_uint8_t* buffer);
|
||||
rt_err_t rt_usbh_storage_test_unit_ready(struct uintf* intf);
|
||||
rt_err_t rt_usbh_storage_inquiry(struct uintf* intf, rt_uint8_t* buffer);
|
||||
rt_err_t rt_usbh_storage_get_capacity(struct uintf* intf, rt_uint8_t* buffer);
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* File : ukbd.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2011, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2012-01-03 Yi Qiu first version
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <drivers/usb_host.h>
|
||||
#include "hid.h"
|
||||
|
||||
#if defined(RT_USBH_HID) && defined(RT_USBH_HID_KEYBOARD)
|
||||
|
||||
static struct uprotocal kbd_protocal;
|
||||
|
||||
static rt_err_t rt_usbh_hid_kbd_callback(void* arg)
|
||||
{
|
||||
int int1, int2;
|
||||
struct uhid* hid;
|
||||
|
||||
hid = (struct uhid*)arg;
|
||||
|
||||
int1 = *(rt_uint32_t*)hid->buffer;
|
||||
int2 = *(rt_uint32_t*)(&hid->buffer[4]);
|
||||
|
||||
if(int1 != 0 || int2 != 0)
|
||||
{
|
||||
RT_DEBUG_LOG(RT_DEBUG_USB, ("key down 0x%x, 0x%x\n", int1, int2));
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_err_t rt_usbh_hid_kbd_init(void* arg)
|
||||
{
|
||||
struct uintf* intf = (struct uintf*)arg;
|
||||
|
||||
RT_ASSERT(intf != RT_NULL);
|
||||
|
||||
rt_usbh_hid_set_protocal(intf, 0);
|
||||
|
||||
rt_usbh_hid_set_idle(intf, 10, 0);
|
||||
|
||||
//RT_DEBUG_LOG(RT_DEBUG_USB, ("start usb keyboard\n"));
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will define the hid keyboard protocal, it will be register to the protocal list.
|
||||
*
|
||||
* @return the keyboard protocal structure.
|
||||
*/
|
||||
uprotocal_t rt_usbh_hid_protocal_kbd(void)
|
||||
{
|
||||
kbd_protocal.pro_id = USB_HID_KEYBOARD;
|
||||
|
||||
kbd_protocal.init = rt_usbh_hid_kbd_init;
|
||||
kbd_protocal.callback = rt_usbh_hid_kbd_callback;
|
||||
|
||||
return &kbd_protocal;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* File : umouse.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2011, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2012-01-03 Yi Qiu first version
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <drivers/usb_host.h>
|
||||
#include "hid.h"
|
||||
#ifdef RT_USING_RTGUI
|
||||
#include <rtgui/event.h>
|
||||
#include <rtgui/rtgui_server.h>
|
||||
#include "drv_lcd.h"
|
||||
#endif
|
||||
#if defined(RT_USBH_HID) && defined(RT_USBH_HID_MOUSE)
|
||||
static struct uprotocal mouse_protocal;
|
||||
|
||||
#ifdef RT_USING_RTGUI
|
||||
#define LKEY_PRESS 0x01
|
||||
#define RKEY_PRESS 0x02
|
||||
#define MKEY_PRESS 0x04
|
||||
#define MOUSE_SCALING 0x02
|
||||
static rt_bool_t lkey_down=RT_FALSE;
|
||||
//static rt_bool_t rkey_down=RT_FALSE;
|
||||
//static rt_bool_t mkey_down=RT_FALSE;
|
||||
static struct rtgui_event_mouse emouse;
|
||||
#endif
|
||||
|
||||
static rt_err_t rt_usbh_hid_mouse_callback(void* arg)
|
||||
{
|
||||
struct uhid* hid;
|
||||
#ifdef RT_USING_RTGUI
|
||||
rt_uint16_t xoffset=0;
|
||||
rt_uint16_t yoffset=0;
|
||||
#endif
|
||||
hid = (struct uhid*)arg;
|
||||
|
||||
RT_DEBUG_LOG(RT_DEBUG_USB, ("hid 0x%x 0x%x\n",
|
||||
*(rt_uint32_t*)hid->buffer,
|
||||
*(rt_uint32_t*)(&hid->buffer[4])));
|
||||
#ifdef RT_USING_RTGUI
|
||||
if(hid->buffer[1]!=0)
|
||||
{
|
||||
if(hid->buffer[1]>127)
|
||||
{
|
||||
xoffset=(256-hid->buffer[1])*MOUSE_SCALING;
|
||||
if(emouse.x>xoffset)
|
||||
{
|
||||
emouse.x-=xoffset;
|
||||
}else
|
||||
{
|
||||
emouse.x=0;
|
||||
}
|
||||
}else
|
||||
{
|
||||
xoffset=(hid->buffer[1])*MOUSE_SCALING;
|
||||
if((emouse.x+xoffset)<480)
|
||||
{
|
||||
emouse.x+=xoffset;
|
||||
}else
|
||||
{
|
||||
emouse.x=480;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(hid->buffer[2]!=0)
|
||||
{
|
||||
|
||||
if(hid->buffer[2]>127)
|
||||
{
|
||||
yoffset=(256-hid->buffer[2])*MOUSE_SCALING;
|
||||
if(emouse.y>yoffset)
|
||||
{
|
||||
emouse.y-=yoffset;
|
||||
}else
|
||||
{
|
||||
emouse.y=0;
|
||||
}
|
||||
}else
|
||||
{
|
||||
yoffset=hid->buffer[2]*MOUSE_SCALING;
|
||||
if(emouse.y+yoffset<272)
|
||||
{
|
||||
emouse.y+=yoffset;
|
||||
}else
|
||||
{
|
||||
emouse.y=272;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(xoffset!=0||yoffset!=0)
|
||||
{
|
||||
cursor_set_position(emouse.x,emouse.y);
|
||||
}
|
||||
if(hid->buffer[0]&LKEY_PRESS)
|
||||
{
|
||||
if(lkey_down==RT_FALSE){
|
||||
// rt_kprintf("mouse left key press down\n");
|
||||
emouse.button = (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN);
|
||||
rtgui_server_post_event(&emouse.parent, sizeof(struct rtgui_event_mouse));
|
||||
lkey_down=RT_TRUE;
|
||||
}
|
||||
}else if(lkey_down==RT_TRUE)
|
||||
{
|
||||
// rt_kprintf("mouse left key press up\n");
|
||||
emouse.button = (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_UP);
|
||||
rtgui_server_post_event(&emouse.parent, sizeof(struct rtgui_event_mouse));
|
||||
lkey_down=RT_FALSE;
|
||||
}
|
||||
#endif
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_err_t rt_usbh_hid_mouse_init(void* arg)
|
||||
{
|
||||
struct uintf* intf = (struct uintf*)arg;
|
||||
|
||||
RT_ASSERT(intf != RT_NULL);
|
||||
|
||||
rt_usbh_hid_set_protocal(intf, 0);
|
||||
|
||||
rt_usbh_hid_set_idle(intf, 10, 0);
|
||||
|
||||
RT_DEBUG_LOG(RT_DEBUG_USB, ("start usb mouse\n"));
|
||||
#ifdef RT_USING_RTGUI
|
||||
RTGUI_EVENT_MOUSE_BUTTON_INIT(&emouse);
|
||||
emouse.wid = RT_NULL;
|
||||
cursor_display(RT_TRUE);
|
||||
#endif
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will define the hid mouse protocal, it will be register to the protocal list.
|
||||
*
|
||||
* @return the keyboard protocal structure.
|
||||
*/
|
||||
uprotocal_t rt_usbh_hid_protocal_mouse(void)
|
||||
{
|
||||
mouse_protocal.pro_id = USB_HID_MOUSE;
|
||||
|
||||
mouse_protocal.init = rt_usbh_hid_mouse_init;
|
||||
mouse_protocal.callback = rt_usbh_hid_mouse_callback;
|
||||
|
||||
return &mouse_protocal;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -234,10 +234,10 @@ rt_err_t rt_usbh_detach_instance(uinst_t device)
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will do USB_REQ_GET_DESCRIPTO' request for the usb device instance,
|
||||
* This function will do USB_REQ_GET_DESCRIPTO' bRequest for the usb device instance,
|
||||
*
|
||||
* @param device the usb device instance.
|
||||
* @param type the type of descriptor request.
|
||||
* @param type the type of descriptor bRequest.
|
||||
* @param buffer the data buffer to save requested data
|
||||
* @param nbytes the size of buffer
|
||||
*
|
||||
@@ -253,10 +253,10 @@ rt_err_t rt_usbh_get_descriptor(uinst_t device, rt_uint8_t type, void* buffer,
|
||||
|
||||
setup.request_type = USB_REQ_TYPE_DIR_IN | USB_REQ_TYPE_STANDARD |
|
||||
USB_REQ_TYPE_DEVICE;
|
||||
setup.request = USB_REQ_GET_DESCRIPTOR;
|
||||
setup.index = 0;
|
||||
setup.length = nbytes;
|
||||
setup.value = type << 8;
|
||||
setup.bRequest = USB_REQ_GET_DESCRIPTOR;
|
||||
setup.wIndex = 0;
|
||||
setup.wLength = nbytes;
|
||||
setup.wValue = type << 8;
|
||||
|
||||
if(rt_usb_hcd_control_xfer(device->hcd, device, &setup, buffer, nbytes,
|
||||
timeout) != nbytes) return -RT_EIO;
|
||||
@@ -281,10 +281,10 @@ rt_err_t rt_usbh_set_address(uinst_t device)
|
||||
|
||||
setup.request_type = USB_REQ_TYPE_DIR_OUT | USB_REQ_TYPE_STANDARD |
|
||||
USB_REQ_TYPE_DEVICE;
|
||||
setup.request = USB_REQ_SET_ADDRESS;
|
||||
setup.index = 0;
|
||||
setup.length = 0;
|
||||
setup.value = device->index;
|
||||
setup.bRequest = USB_REQ_SET_ADDRESS;
|
||||
setup.wIndex = 0;
|
||||
setup.wLength = 0;
|
||||
setup.wValue = device->index;
|
||||
|
||||
if(rt_usb_hcd_control_xfer(device->hcd, device, &setup, RT_NULL, 0,
|
||||
timeout) != 0) return -RT_EIO;
|
||||
@@ -314,10 +314,10 @@ rt_err_t rt_usbh_set_configure(uinst_t device, int config)
|
||||
|
||||
setup.request_type = USB_REQ_TYPE_DIR_OUT | USB_REQ_TYPE_STANDARD |
|
||||
USB_REQ_TYPE_DEVICE;
|
||||
setup.request = USB_REQ_SET_CONFIGURATION;
|
||||
setup.index = 0;
|
||||
setup.length = 0;
|
||||
setup.value = config;
|
||||
setup.bRequest = USB_REQ_SET_CONFIGURATION;
|
||||
setup.wIndex = 0;
|
||||
setup.wLength = 0;
|
||||
setup.wValue = config;
|
||||
|
||||
if(rt_usb_hcd_control_xfer(device->hcd, device, &setup, RT_NULL, 0,
|
||||
timeout) != 0) return -RT_EIO;
|
||||
@@ -343,10 +343,10 @@ rt_err_t rt_usbh_set_interface(uinst_t device, int intf)
|
||||
|
||||
setup.request_type = USB_REQ_TYPE_DIR_OUT | USB_REQ_TYPE_STANDARD |
|
||||
USB_REQ_TYPE_INTERFACE;
|
||||
setup.request = USB_REQ_SET_INTERFACE;
|
||||
setup.index = 0;
|
||||
setup.length = 0;
|
||||
setup.value = intf;
|
||||
setup.bRequest = USB_REQ_SET_INTERFACE;
|
||||
setup.wIndex = 0;
|
||||
setup.wLength = 0;
|
||||
setup.wValue = intf;
|
||||
|
||||
if(rt_usb_hcd_control_xfer(device->hcd, device, &setup, RT_NULL, 0,
|
||||
timeout) != 0) return -RT_EIO;
|
||||
@@ -372,10 +372,10 @@ rt_err_t rt_usbh_clear_feature(uinst_t device, int endpoint, int feature)
|
||||
|
||||
setup.request_type = USB_REQ_TYPE_DIR_OUT | USB_REQ_TYPE_STANDARD |
|
||||
USB_REQ_TYPE_ENDPOINT;
|
||||
setup.request = USB_REQ_CLEAR_FEATURE;
|
||||
setup.index = endpoint;
|
||||
setup.length = 0;
|
||||
setup.value = feature;
|
||||
setup.bRequest = USB_REQ_CLEAR_FEATURE;
|
||||
setup.wIndex = endpoint;
|
||||
setup.wLength = 0;
|
||||
setup.wValue = feature;
|
||||
|
||||
if(rt_usb_hcd_control_xfer(device->hcd, device, &setup, RT_NULL, 0,
|
||||
timeout) != 0) return -RT_EIO;
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rtservice.h>
|
||||
#include <rtdevice.h>
|
||||
#include <drivers/usb_host.h>
|
||||
|
||||
static rt_list_t _driver_list;
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ static struct rt_messagequeue *usb_mq;
|
||||
static struct uclass_driver hub_driver;
|
||||
|
||||
/**
|
||||
* This function will do USB_REQ_GET_DESCRIPTOR request for the device instance
|
||||
* This function will do USB_REQ_GET_DESCRIPTOR bRequest for the device instance
|
||||
* to get usb hub descriptor.
|
||||
*
|
||||
* @param intf the interface instance.
|
||||
@@ -51,10 +51,10 @@ rt_err_t rt_usbh_hub_get_descriptor(struct uinstance* device, rt_uint8_t *buffer
|
||||
|
||||
setup.request_type = USB_REQ_TYPE_DIR_IN | USB_REQ_TYPE_CLASS |
|
||||
USB_REQ_TYPE_DEVICE;
|
||||
setup.request = USB_REQ_GET_DESCRIPTOR;
|
||||
setup.index = 0;
|
||||
setup.length = nbytes;
|
||||
setup.value = USB_DESC_TYPE_HUB << 8;
|
||||
setup.bRequest = USB_REQ_GET_DESCRIPTOR;
|
||||
setup.wIndex = 0;
|
||||
setup.wLength = nbytes;
|
||||
setup.wValue = USB_DESC_TYPE_HUB << 8;
|
||||
|
||||
if(rt_usb_hcd_control_xfer(device->hcd, device, &setup, buffer, nbytes,
|
||||
timeout) == nbytes) return RT_EOK;
|
||||
@@ -62,7 +62,7 @@ rt_err_t rt_usbh_hub_get_descriptor(struct uinstance* device, rt_uint8_t *buffer
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will do USB_REQ_GET_STATUS request for the device instance
|
||||
* This function will do USB_REQ_GET_STATUS bRequest for the device instance
|
||||
* to get usb hub status.
|
||||
*
|
||||
* @param intf the interface instance.
|
||||
@@ -81,10 +81,10 @@ rt_err_t rt_usbh_hub_get_status(struct uinstance* device, rt_uint8_t* buffer)
|
||||
|
||||
setup.request_type = USB_REQ_TYPE_DIR_IN | USB_REQ_TYPE_CLASS |
|
||||
USB_REQ_TYPE_DEVICE;
|
||||
setup.request = USB_REQ_GET_STATUS;
|
||||
setup.index = 0;
|
||||
setup.length = length;
|
||||
setup.value = 0;
|
||||
setup.bRequest = USB_REQ_GET_STATUS;
|
||||
setup.wIndex = 0;
|
||||
setup.wLength = length;
|
||||
setup.wValue = 0;
|
||||
|
||||
if(rt_usb_hcd_control_xfer(device->hcd, device, &setup, buffer, length,
|
||||
timeout) == length) return RT_EOK;
|
||||
@@ -92,7 +92,7 @@ rt_err_t rt_usbh_hub_get_status(struct uinstance* device, rt_uint8_t* buffer)
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will do USB_REQ_GET_STATUS request for the device instance
|
||||
* This function will do USB_REQ_GET_STATUS bRequest for the device instance
|
||||
* to get hub port status.
|
||||
*
|
||||
* @param intf the interface instance.
|
||||
@@ -121,10 +121,10 @@ rt_err_t rt_usbh_hub_get_port_status(uhub_t hub, rt_uint16_t port,
|
||||
|
||||
setup.request_type = USB_REQ_TYPE_DIR_IN | USB_REQ_TYPE_CLASS |
|
||||
USB_REQ_TYPE_OTHER;
|
||||
setup.request = USB_REQ_GET_STATUS;
|
||||
setup.index = port;
|
||||
setup.length = 4;
|
||||
setup.value = 0;
|
||||
setup.bRequest = USB_REQ_GET_STATUS;
|
||||
setup.wIndex = port;
|
||||
setup.wLength = 4;
|
||||
setup.wValue = 0;
|
||||
|
||||
if(rt_usb_hcd_control_xfer(hub->hcd, hub->self, &setup, buffer,
|
||||
length, timeout) == timeout) return RT_EOK;
|
||||
@@ -132,7 +132,7 @@ rt_err_t rt_usbh_hub_get_port_status(uhub_t hub, rt_uint16_t port,
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will do USB_REQ_CLEAR_FEATURE request for the device instance
|
||||
* This function will do USB_REQ_CLEAR_FEATURE bRequest for the device instance
|
||||
* to clear feature of the hub port.
|
||||
*
|
||||
* @param intf the interface instance.
|
||||
@@ -160,10 +160,10 @@ rt_err_t rt_usbh_hub_clear_port_feature(uhub_t hub, rt_uint16_t port,
|
||||
|
||||
setup.request_type = USB_REQ_TYPE_DIR_OUT | USB_REQ_TYPE_CLASS |
|
||||
USB_REQ_TYPE_OTHER;
|
||||
setup.request = USB_REQ_CLEAR_FEATURE;
|
||||
setup.index = port;
|
||||
setup.length = 0;
|
||||
setup.value = feature;
|
||||
setup.bRequest = USB_REQ_CLEAR_FEATURE;
|
||||
setup.wIndex = port;
|
||||
setup.wLength = 0;
|
||||
setup.wValue = feature;
|
||||
|
||||
if(rt_usb_hcd_control_xfer(hub->hcd, hub->self, &setup, RT_NULL, 0,
|
||||
timeout) == 0) return RT_EOK;
|
||||
@@ -171,7 +171,7 @@ rt_err_t rt_usbh_hub_clear_port_feature(uhub_t hub, rt_uint16_t port,
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will do USB_REQ_SET_FEATURE request for the device instance
|
||||
* This function will do USB_REQ_SET_FEATURE bRequest for the device instance
|
||||
* to set feature of the hub port.
|
||||
*
|
||||
* @param intf the interface instance.
|
||||
@@ -199,10 +199,10 @@ rt_err_t rt_usbh_hub_set_port_feature(uhub_t hub, rt_uint16_t port,
|
||||
|
||||
setup.request_type = USB_REQ_TYPE_DIR_OUT | USB_REQ_TYPE_CLASS |
|
||||
USB_REQ_TYPE_OTHER;
|
||||
setup.request = USB_REQ_SET_FEATURE;
|
||||
setup.index = port;
|
||||
setup.length = 0;
|
||||
setup.value = feature;
|
||||
setup.bRequest = USB_REQ_SET_FEATURE;
|
||||
setup.wIndex = port;
|
||||
setup.wLength = 0;
|
||||
setup.wValue = feature;
|
||||
|
||||
if(rt_usb_hcd_control_xfer(hub->hcd, hub->self, &setup, RT_NULL, 0,
|
||||
timeout) == 0) return RT_EOK;
|
||||
@@ -561,7 +561,7 @@ static void rt_usbh_hub_thread_entry(void* parameter)
|
||||
if(rt_mq_recv(usb_mq, &msg, sizeof(struct uhost_msg), RT_WAITING_FOREVER)
|
||||
!= RT_EOK ) continue;
|
||||
|
||||
RT_DEBUG_LOG(RT_DEBUG_USB, ("msg type %d\n", msg.type));
|
||||
//RT_DEBUG_LOG(RT_DEBUG_USB, ("msg type %d\n", msg.type));
|
||||
|
||||
switch (msg.type)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user