00001
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 #include "config.h"
00048 #include "conf_usb.h"
00049 #include "lib_mcu/usb/usb_drv.h"
00050 #include "usb_descriptors.h"
00051 #include "modules/usb/device_chap9/usb_standard_request.h"
00052 #include "usb_specific_request.h"
00053 #include "modules/control_access/ctrl_access.h"
00054 #if ((USB_DEVICE_SN_USE==ENABLE) && (USE_DEVICE_SN_UNIQUE==ENABLE))
00055 #include "lib_mcu/flash/flash_drv.h"
00056 #endif
00057
00058
00059
00060 bit ms_multiple_drive;
00061
00062 #ifdef __GNUC__
00063 extern PGM_VOID_P pbuffer;
00064 #else
00065 extern U8 code *pbuffer;
00066 #endif
00067 extern U8 data_to_transfer;
00068
00069
00070
00071
00080 Bool usb_user_read_request(U8 type, U8 request)
00081 {
00082 U16 wInterface;
00083 U8 wValue_msb;
00084 U8 wValue_lsb;
00085
00086
00087 wValue_lsb = Usb_read_byte();
00088 wValue_msb = Usb_read_byte();
00089
00090
00091 if( USB_SETUP_SET_CLASS_INTER == type )
00092 {
00093 switch( request )
00094 {
00095 case SETUP_MASS_STORAGE_RESET:
00096
00097
00098 if( (0!=wValue_lsb) || (0!=wValue_msb) )
00099 break;
00100 LSB(wInterface)=Usb_read_byte();
00101 MSB(wInterface)=Usb_read_byte();
00102 if( INTERFACE_NB != wInterface )
00103 break;
00104 Usb_ack_receive_setup();
00105 Usb_send_control_in();
00106 return TRUE;
00107 break;
00108 }
00109 }
00110 if( USB_SETUP_GET_CLASS_INTER == type )
00111 {
00112 switch( request )
00113 {
00114 case SETUP_MASS_STORAGE_GET_MAX_LUN:
00115
00116
00117 if( (0!=wValue_lsb) || (0!=wValue_msb) )
00118 break;
00119 LSB(wInterface)=Usb_read_byte();
00120 MSB(wInterface)=Usb_read_byte();
00121 if( INTERFACE_NB != wInterface )
00122 break;
00123 Usb_ack_receive_setup();
00124 Usb_write_byte( (get_nb_lun()-1) );
00125 Usb_send_control_in();
00126 ms_multiple_drive = 1;
00127 return TRUE;
00128 break;
00129 }
00130 }
00131
00132 return FALSE;
00133 }
00134
00135
00140 void usb_user_endpoint_init(U8 conf_nb)
00141 {
00142 usb_configure_endpoint(EP_MS_IN, \
00143 TYPE_BULK, \
00144 DIRECTION_IN, \
00145 SIZE_64, \
00146 TWO_BANKS, \
00147 NYET_ENABLED);
00148 usb_configure_endpoint(EP_MS_OUT, \
00149 TYPE_BULK, \
00150 DIRECTION_OUT, \
00151 SIZE_64, \
00152 TWO_BANKS, \
00153 NYET_ENABLED);
00154 }
00155
00156
00163 U8 usb_user_interface_get( U16 wInterface )
00164 {
00165 return 0;
00166 }
00167
00168
00174 void usb_user_interface_reset(U16 wInterface, U8 alternate_setting)
00175 {
00176
00177 if( INTERFACE_NB == wInterface )
00178 {
00179
00180 Usb_select_endpoint(EP_MS_IN);
00181 Usb_disable_stall_handshake();
00182 Usb_reset_endpoint(EP_MS_IN);
00183 Usb_reset_data_toggle();
00184 Usb_select_endpoint(EP_MS_OUT);
00185 Usb_disable_stall_handshake();
00186 Usb_reset_endpoint(EP_MS_OUT);
00187 Usb_reset_data_toggle();
00188 }
00189 }
00190
00191
00199 Bool usb_user_get_descriptor(U8 type, U8 string)
00200 {
00201 switch(type)
00202 {
00203 case DESCRIPTOR_STRING:
00204 switch (string)
00205 {
00206 case LANG_ID:
00207 data_to_transfer = sizeof (usb_user_language_id);
00208 pbuffer = &(usb_user_language_id.bLength);
00209 return TRUE;
00210 break;
00211
00212 case MAN_INDEX:
00213 data_to_transfer = sizeof (usb_user_manufacturer_string_descriptor);
00214 pbuffer = &(usb_user_manufacturer_string_descriptor.bLength);
00215 return TRUE;
00216 break;
00217
00218 case PROD_INDEX:
00219 data_to_transfer = sizeof (usb_user_product_string_descriptor);
00220 pbuffer = &(usb_user_product_string_descriptor.bLength);
00221 return TRUE;
00222 break;
00223
00224 #if (USB_DEVICE_SN_USE==ENABLE)
00225 case SN_INDEX:
00226 data_to_transfer = sizeof (usb_user_serial_number);
00227 pbuffer = &(usb_user_serial_number.bLength);
00228 #if (USE_DEVICE_SN_UNIQUE==ENABLE)
00229 f_get_serial_string=TRUE;
00230 data_to_transfer += (SN_LENGTH*4);
00231 #endif
00232 return TRUE;
00233 break;
00234 #endif
00235 }
00236 break;
00237 }
00238 return FALSE;
00239 }
00240