00001
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
00048
00049
00050 #include "conf_usb.h"
00051
00052
00053 #if USB_DEVICE_FEATURE == ENABLED
00054
00055 #include "usb_drv.h"
00056 #include "usb_descriptors.h"
00057 #include "usb_standard_request.h"
00058 #include "usb_specific_request.h"
00059 #include "cdc.h"
00060 #include "usart.h"
00061 #include "power_clocks_lib.h"
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 S_line_coding line_coding;
00073
00074 extern pcl_freq_param_t pcl_freq_param;
00075
00076
00077
00081 void usb_user_endpoint_init(U8 conf_nb)
00082 {
00083 #if (USB_HIGH_SPEED_SUPPORT==ENABLED)
00084 if( !Is_usb_full_speed_mode() )
00085 {
00086 (void)Usb_configure_endpoint(INT_EP,
00087 EP_ATTRIBUTES_3,
00088 DIRECTION_IN,
00089 EP_SIZE_3,
00090 SINGLE_BANK);
00091
00092 (void)Usb_configure_endpoint(TX_EP,
00093 EP_ATTRIBUTES_1,
00094 DIRECTION_IN,
00095 EP_SIZE_1_HS,
00096 DOUBLE_BANK);
00097
00098 (void)Usb_configure_endpoint(RX_EP,
00099 EP_ATTRIBUTES_2,
00100 DIRECTION_OUT,
00101 EP_SIZE_2_HS,
00102 DOUBLE_BANK);
00103 return;
00104 }
00105 #endif
00106 (void)Usb_configure_endpoint(INT_EP,
00107 EP_ATTRIBUTES_3,
00108 DIRECTION_IN,
00109 EP_SIZE_3,
00110 SINGLE_BANK);
00111
00112 (void)Usb_configure_endpoint(TX_EP,
00113 EP_ATTRIBUTES_1,
00114 DIRECTION_IN,
00115 EP_SIZE_1_FS,
00116 DOUBLE_BANK);
00117
00118 (void)Usb_configure_endpoint(RX_EP,
00119 EP_ATTRIBUTES_2,
00120 DIRECTION_OUT,
00121 EP_SIZE_2_FS,
00122 DOUBLE_BANK);
00123 }
00124
00125
00132 Bool usb_user_read_request(U8 type, U8 request)
00133 {
00134 switch (request)
00135 {
00136 case GET_LINE_CODING:
00137 cdc_get_line_coding();
00138 return TRUE;
00139
00140
00141 case SET_LINE_CODING:
00142 cdc_set_line_coding();
00143 return TRUE;
00144
00145
00146 case SET_CONTROL_LINE_STATE:
00147 cdc_set_control_line_state();
00148 return TRUE;
00149
00150
00151 default:
00152 return FALSE;
00153
00154 }
00155 }
00156
00157
00161 Bool usb_user_get_descriptor(U8 type, U8 string)
00162 {
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202 return FALSE;
00203 }
00204
00205 void cdc_get_line_coding(void)
00206 {
00207 Usb_ack_setup_received_free();
00208
00209 Usb_reset_endpoint_fifo_access(EP_CONTROL);
00210 Usb_write_endpoint_data(EP_CONTROL, 8, LSB0(line_coding.dwDTERate));
00211 Usb_write_endpoint_data(EP_CONTROL, 8, LSB1(line_coding.dwDTERate));
00212 Usb_write_endpoint_data(EP_CONTROL, 8, LSB2(line_coding.dwDTERate));
00213 Usb_write_endpoint_data(EP_CONTROL, 8, LSB3(line_coding.dwDTERate));
00214 Usb_write_endpoint_data(EP_CONTROL, 8, line_coding.bCharFormat);
00215 Usb_write_endpoint_data(EP_CONTROL, 8, line_coding.bParityType);
00216 Usb_write_endpoint_data(EP_CONTROL, 8, line_coding.bDataBits );
00217
00218 Usb_ack_control_in_ready_send();
00219 while (!Is_usb_control_in_ready());
00220
00221 while(!Is_usb_control_out_received());
00222 Usb_ack_control_out_received_free();
00223 }
00224
00225 void cdc_set_line_coding (void)
00226 {
00227 Usb_ack_setup_received_free();
00228
00229 while(!Is_usb_control_out_received());
00230 Usb_reset_endpoint_fifo_access(EP_CONTROL);
00231
00232 LSB0(line_coding.dwDTERate) = Usb_read_endpoint_data(EP_CONTROL, 8);
00233 LSB1(line_coding.dwDTERate) = Usb_read_endpoint_data(EP_CONTROL, 8);
00234 LSB2(line_coding.dwDTERate) = Usb_read_endpoint_data(EP_CONTROL, 8);
00235 LSB3(line_coding.dwDTERate) = Usb_read_endpoint_data(EP_CONTROL, 8);
00236 line_coding.bCharFormat = Usb_read_endpoint_data(EP_CONTROL, 8);
00237 line_coding.bParityType = Usb_read_endpoint_data(EP_CONTROL, 8);
00238 line_coding.bDataBits = Usb_read_endpoint_data(EP_CONTROL, 8);
00239 Usb_ack_control_out_received_free();
00240
00241 Usb_ack_control_in_ready_send();
00242 while (!Is_usb_control_in_ready());
00243
00244
00245 {
00246 static usart_options_t dbg_usart_options;
00247 U32 stopbits, parity;
00248
00249 if ( line_coding.bCharFormat==0 ) stopbits = USART_1_STOPBIT;
00250 else if( line_coding.bCharFormat==1 ) stopbits = USART_1_5_STOPBITS;
00251 else stopbits = USART_2_STOPBITS;
00252
00253 if ( line_coding.bParityType==0 ) parity = USART_NO_PARITY;
00254 else if( line_coding.bParityType==1 ) parity = USART_ODD_PARITY;
00255 else if( line_coding.bParityType==2 ) parity = USART_EVEN_PARITY;
00256 else if( line_coding.bParityType==3 ) parity = USART_MARK_PARITY;
00257 else parity = USART_SPACE_PARITY;
00258
00259
00260 dbg_usart_options.baudrate = line_coding.dwDTERate;
00261 dbg_usart_options.charlength = line_coding.bDataBits;
00262 dbg_usart_options.paritytype = parity;
00263 dbg_usart_options.stopbits = stopbits;
00264 dbg_usart_options.channelmode = USART_NORMAL_CHMODE;
00265
00266
00267 usart_init_rs232(DBG_USART, &dbg_usart_options, pcl_freq_param.pba_f);
00268 }
00269 }
00270
00271 void cdc_set_control_line_state (void)
00272 {
00273 Usb_ack_setup_received_free();
00274 Usb_ack_control_in_ready_send();
00275 while (!Is_usb_control_in_ready());
00276 }
00277
00278
00279 #endif // USB_DEVICE_FEATURE == ENABLED