00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef _USB_HOST_ENUM_H_
00020 #define _USB_HOST_ENUM_H_
00021
00022
00023
00024
00025 #include "modules/usb/usb_task.h"
00026
00027
00028
00029 #ifndef SIZEOF_DATA_STAGE
00030 #error SIZEOF_DATA_STAGE should be defined in conf_usb.h
00031 #endif
00032
00033 #if (SIZEOF_DATA_STAGE<0xFF)
00034 #define T_DESC_OFFSET U8
00035 #else
00036 #define T_DESC_OFFSET U16
00037 #endif
00038
00039 #ifndef MAX_EP_PER_INTERFACE
00040 #define MAX_EP_PER_INTERFACE 4
00041 #endif
00042
00043 #define BIT_SELF_POWERED 6 // offset
00044 #define BIT_REMOTE_WAKEUP 5 // offset
00045
00046 #define BIT_SRP_SUPPORT 0 // offset
00047 #define BIT_HNP_SUPPORT 1 // offset
00048
00049
00050
00051
00054
00056 typedef struct
00057 {
00058 U8 bmRequestType;
00059 U8 bRequest;
00060 U16 wValue;
00061 U16 wIndex;
00062 U16 wLength;
00063 U8 uncomplete_read;
00064 } S_usb_setup_data;
00065
00066
00067 typedef struct
00068 {
00069 U8 interface_nb;
00070 U8 altset_nb;
00071 U16 class;
00072 U16 subclass;
00073 U16 protocol;
00074 U8 nb_ep;
00075 U8 ep_addr[MAX_EP_PER_INTERFACE];
00076 } S_interface;
00077
00078 extern S_usb_setup_data usb_request;
00079 extern U8 data_stage[SIZEOF_DATA_STAGE];
00080 extern U8 device_status;
00081
00082 #define REQUEST_TYPE_POS 0
00083 #define REQUEST_POS 1
00084 #define VALUE_HIGH_POS 2
00085 #define VALUE_LOW_POS 3
00086 #define INDEX_HIGH_POS 4
00087 #define INDEX_LOW_POS 5
00088 #define LENGTH_HIGH_POS 6
00089 #define LENGTH_LOW_POS 7
00090 #define UNCOMPLETE_READ_POS 8
00091 #define DATA_ADDR_HIGH_POS 9
00092 #define DATA_ADDR_LOW_POS 10
00093
00094 #define CONTROL_GOOD 0
00095 #define CONTROL_DATA_TOGGLE 0x01
00096 #define CONTROL_DATA_PID 0x02
00097 #define CONTROL_PID 0x04
00098 #define CONTROL_TIMEOUT 0x08
00099 #define CONTROL_CRC16 0x10
00100 #define CONTROL_STALL 0x20
00101 #define CONTROL_NO_DEVICE 0x40
00102
00103
00105 #define OFFSET_FIELD_MAXPACKETSIZE 7
00106 #define OFFSET_FIELD_MSB_VID 9
00107 #define OFFSET_FIELD_LSB_VID 8
00108 #define OFFSET_FIELD_MSB_PID 11
00109 #define OFFSET_FIELD_LSB_PID 10
00110
00111 #define OFFSET_DESCRIPTOR_LENGHT 0
00112 #define OFFSET_FIELD_DESCRIPTOR_TYPE 1
00113 #define OFFSET_FIELD_TOTAL_LENGHT 2
00114 #define OFFSET_FIELD_BMATTRIBUTES 7
00115 #define OFFSET_FIELD_MAXPOWER 8
00116
00117 #define OFFSET_FIELD_OTG_FEATURES 2
00118
00120 #define OFFSET_FIELD_NB_INTERFACE 4
00121 #define OFFSET_FIELD_CLASS 5
00122 #define OFFSET_FIELD_SUB_CLASS 6
00123 #define OFFSET_FIELD_PROTOCOL 7
00124
00125 #define OFFSET_FIELD_INTERFACE_NB 2
00126 #define OFFSET_FIELD_ALT 3
00127 #define OFFSET_FIELS_NB_OF_EP 4
00128
00129 #define OFFSET_FIELD_EP_ADDR 2
00130 #define OFFSET_FIELD_EP_TYPE 3
00131 #define OFFSET_FIELD_EP_SIZE 4
00132 #define OFFSET_FIELD_EP_INTERVAL 6
00133
00135 #define OFFSET_DEV_DESC_CLASS 4 // offset for the CLASS field in the Device Descriptor
00136 #define HUB_CLASS_CODE 9 // value of Hub CLASS
00137
00138
00139 #define HOST_FALSE 0
00140 #define HOST_TRUE 1
00141
00142 U8 host_send_control(U8*);
00143
00153 #define host_clear_endpoint_feature(ep) (usb_request.bmRequestType = 0x02,\
00154 usb_request.bRequest = CLEAR_FEATURE,\
00155 usb_request.wValue = FEATURE_ENDPOINT_HALT << 8,\
00156 usb_request.wIndex = ep,\
00157 usb_request.wLength = 0,\
00158 usb_request.uncomplete_read = FALSE,\
00159 host_send_control(data_stage))
00160
00169 #define host_get_configuration() (usb_request.bmRequestType = 0x80,\
00170 usb_request.bRequest = GET_CONFIGURATION,\
00171 usb_request.wValue = 0,\
00172 usb_request.wIndex = 0,\
00173 usb_request.wLength = 1,\
00174 usb_request.uncomplete_read = FALSE,\
00175 host_send_control(data_stage))
00176
00185 #define host_set_configuration(cfg_nb) (usb_request.bmRequestType = 0x00,\
00186 usb_request.bRequest = SET_CONFIGURATION,\
00187 usb_request.wValue = cfg_nb,\
00188 usb_request.wIndex = 0,\
00189 usb_request.wLength = 0,\
00190 usb_request.uncomplete_read = FALSE,\
00191 host_send_control(data_stage))
00192
00203 #define host_set_interface(interface_nb,alt_setting) (usb_request.bmRequestType = 0x00,\
00204 usb_request.bRequest = SET_INTERFACE,\
00205 usb_request.wValue = alt_setting,\
00206 usb_request.wIndex = interface_nb,\
00207 usb_request.wLength = 0,\
00208 usb_request.uncomplete_read = FALSE,\
00209 host_send_control(data_stage))
00210
00224 #define host_get_device_descriptor_uncomplete() (usb_request.bmRequestType = 0x80,\
00225 usb_request.bRequest = GET_DESCRIPTOR,\
00226 usb_request.wValue = DEVICE_DESCRIPTOR << 8,\
00227 usb_request.wIndex = 0,\
00228 usb_request.wLength = 64,\
00229 usb_request.uncomplete_read = TRUE,\
00230 host_send_control(data_stage))
00231
00244 #define host_get_device_descriptor() (usb_request.bmRequestType = 0x80,\
00245 usb_request.bRequest = GET_DESCRIPTOR,\
00246 usb_request.wValue = DEVICE_DESCRIPTOR << 8,\
00247 usb_request.wIndex = 0,\
00248 usb_request.wLength = 18,\
00249 usb_request.uncomplete_read = FALSE,\
00250 host_send_control(data_stage))
00251
00263 #define host_get_configuration_descriptor() (usb_request.bmRequestType = 0x80,\
00264 usb_request.bRequest = GET_DESCRIPTOR,\
00265 usb_request.wValue = CONFIGURATION_DESCRIPTOR << 8,\
00266 usb_request.wIndex = 0,\
00267 usb_request.wLength = 255,\
00268 usb_request.uncomplete_read = FALSE,\
00269 host_send_control(data_stage))
00270
00271 #define host_get_descriptor_uncomplete() (usb_request.bmRequestType = 0x80,\
00272 usb_request.bRequest = GET_DESCRIPTOR,\
00273 usb_request.wValue = 0,\
00274 usb_request.wIndex = 0,\
00275 usb_request.wLength = 64,\
00276 usb_request.uncomplete_read = FALSE,\
00277 host_send_control(data_stage))
00278
00289 #define host_set_address(addr) (usb_request.bmRequestType = 0x00,\
00290 usb_request.bRequest = SET_ADDRESS,\
00291 usb_request.wValue = (U16)addr,\
00292 usb_request.wIndex = 0,\
00293 usb_request.wLength = 0,\
00294 usb_request.uncomplete_read = FALSE,\
00295 host_send_control(data_stage))
00296
00306 #define host_set_feature_remote_wakeup() (usb_request.bmRequestType = 0x00,\
00307 usb_request.bRequest = SET_FEATURE,\
00308 usb_request.wValue = 1,\
00309 usb_request.wIndex = 1,\
00310 usb_request.wLength = 0,\
00311 usb_request.uncomplete_read = FALSE,\
00312 host_send_control(data_stage))
00313
00314 #if (USB_OTG_FEATURE == ENABLED)
00315
00324 #define host_set_feature_a_hnp_support() (usb_request.bmRequestType = 0x00,\
00325 usb_request.bRequest = SET_FEATURE,\
00326 usb_request.wValue = 4,\
00327 usb_request.wIndex = 0,\
00328 usb_request.wLength = 0,\
00329 usb_request.uncomplete_read = FALSE,\
00330 host_send_control(data_stage))
00331
00341 #define host_set_feature_b_hnp_enable() (usb_request.bmRequestType = 0x00,\
00342 usb_request.bRequest = SET_FEATURE,\
00343 usb_request.wValue = 3,\
00344 usb_request.wIndex = 0,\
00345 usb_request.wLength = 0,\
00346 usb_request.uncomplete_read = FALSE,\
00347 host_send_control(data_stage))
00348 #endif
00349
00350
00362 #define host_ms_get_max_lun() (usb_request.bmRequestType = 0xA1,\
00363 usb_request.bRequest = MS_GET_MAX_LUN,\
00364 usb_request.wValue = 0,\
00365 usb_request.wIndex = 0,\
00366 usb_request.wLength = 1,\
00367 usb_request.uncomplete_read = FALSE,\
00368 host_send_control(data_stage))
00369
00380 #define Get_VID() (device_VID)
00381
00392 #define Get_PID() (device_PID)
00393
00404 #define Get_maxpower() (maxpower)
00405
00413 #define Get_class(s_interface) (interface_supported[s_interface].class)
00414
00422 #define Get_subclass(s_interface) (interface_supported[s_interface].subclass)
00423
00431 #define Get_protocol(s_interface) (interface_supported[s_interface].protocol)
00432
00442 #define Get_ep_addr(s_interface,n_ep) (interface_supported[s_interface].ep_addr[n_ep])
00443
00452 #define Get_nb_ep(s_interface) (interface_supported[s_interface].nb_ep)
00453
00462 #define Get_alts_s(s_interface) (interface_supported[s_interface].altset_nb)
00463
00472 #define Get_interface_number(s_interface) (interface_supported[s_interface].interface_nb)
00473
00481 #define Get_nb_supported_interface() (nb_interface_supported)
00482
00490 #define Is_device_self_powered() ((bmattributes & (1<<BIT_SELF_POWERED)) ? TRUE : FALSE)
00491
00499 #define Is_device_supports_remote_wakeup() ((bmattributes & (1<<BIT_REMOTE_WAKEUP)) ? TRUE : FALSE)
00500
00508 #define Is_device_supports_srp() ((otg_features_supported & (1<<BIT_SRP_SUPPORT)) ? TRUE : FALSE)
00509
00517 #define Is_device_supports_hnp() ((otg_features_supported & (1<<BIT_HNP_SUPPORT)) ? TRUE : FALSE)
00518
00519
00520 extern U8 nb_interface_supported;
00521 extern S_interface interface_supported[MAX_INTERFACE_SUPPORTED];
00522 extern U16 device_PID;
00523 extern U16 device_VID;
00524 extern U8 bmattributes;
00525 extern U8 maxpower;
00526
00527 U8 host_check_VID_PID(void);
00528 #if (USB_OTG_FEATURE == ENABLED)
00529 U8 host_check_OTG_features(void);
00530 #endif
00531 U8 host_check_class (void);
00532 U8 host_auto_configure_endpoint();
00533 T_DESC_OFFSET get_interface_descriptor_offset(U8 interface, U8 alt);
00534 U8 host_get_hwd_pipe_nb(U8 ep_addr);
00535
00537
00538 #endif // _USB_HOST_ENUM_H_
00539