00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "config.h"
00022 #include "conf_usb.h"
00023 #include "lib_mcu\usb\usb_drv.h"
00024 #include "usb_descriptors.h"
00025 #include "modules\usb\device_chap9\usb_standard_request.h"
00026 #include "usb_specific_request.h"
00027 #include "lib_mcu\uart\uart_lib.h"
00028
00029
00030
00031
00032
00033
00034
00035 extern U8 code *pbuffer;
00036 extern U8 data_to_transfer;
00037 extern S_line_coding line_coding;
00038
00039
00040
00051 Bool usb_user_read_request(U8 type, U8 request)
00052 {
00053 U8 descriptor_type ;
00054 U8 string_type ;
00055
00056 string_type = Usb_read_byte();
00057 descriptor_type = Usb_read_byte();
00058 switch(request)
00059 {
00060 case GET_LINE_CODING:
00061 cdc_get_line_coding();
00062 return TRUE;
00063 break;
00064
00065 case SET_LINE_CODING:
00066 cdc_set_line_coding();
00067 return TRUE;
00068 break;
00069
00070 case SET_CONTROL_LINE_STATE:
00071 cdc_set_control_line_state();
00072 return TRUE;
00073 break;
00074
00075 default:
00076 return FALSE;
00077 break;
00078
00079 }
00080 return FALSE;
00081 }
00082
00083
00093 Bool usb_user_get_descriptor(U8 type, U8 string)
00094 {
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127 return FALSE;
00128 }
00129
00138 void usb_user_endpoint_init(U8 conf_nb)
00139 {
00140 usb_configure_endpoint(INT_EP, \
00141 TYPE_INTERRUPT, \
00142 DIRECTION_IN, \
00143 SIZE_32, \
00144 ONE_BANK, \
00145 NYET_ENABLED);
00146
00147 usb_configure_endpoint(TX_EP, \
00148 TYPE_BULK, \
00149 DIRECTION_IN, \
00150 SIZE_32, \
00151 ONE_BANK, \
00152 NYET_ENABLED);
00153
00154 usb_configure_endpoint(RX_EP, \
00155 TYPE_BULK, \
00156 DIRECTION_OUT, \
00157 SIZE_32, \
00158 ONE_BANK, \
00159 NYET_ENABLED);
00160
00161 Usb_reset_endpoint(INT_EP);
00162 Usb_reset_endpoint(TX_EP);
00163 Usb_reset_endpoint(RX_EP);
00164
00165
00166 }
00167
00176 void cdc_get_line_coding(void)
00177 {
00178 Usb_ack_receive_setup();
00179 Usb_write_byte(LSB0(line_coding.dwDTERate));
00180 Usb_write_byte(LSB1(line_coding.dwDTERate));
00181 Usb_write_byte(LSB2(line_coding.dwDTERate));
00182 Usb_write_byte(LSB3(line_coding.dwDTERate));
00183 Usb_write_byte(line_coding.bCharFormat);
00184 Usb_write_byte(line_coding.bParityType);
00185 Usb_write_byte(line_coding.bDataBits);
00186
00187 Usb_send_control_in();
00188 while(!(Is_usb_read_control_enabled()));
00189
00190
00191 while(!Is_usb_receive_out());
00192 Usb_ack_receive_out();
00193 }
00194
00195
00204 void cdc_set_line_coding (void)
00205 {
00206 Usb_ack_receive_setup();
00207 while (!(Is_usb_receive_out()));
00208 LSB0(line_coding.dwDTERate) = Usb_read_byte();
00209 LSB1(line_coding.dwDTERate) = Usb_read_byte();
00210 LSB2(line_coding.dwDTERate) = Usb_read_byte();
00211 LSB3(line_coding.dwDTERate) = Usb_read_byte();
00212 line_coding.bCharFormat = Usb_read_byte();
00213 line_coding.bParityType = Usb_read_byte();
00214 line_coding.bDataBits = Usb_read_byte();
00215 Usb_ack_receive_out();
00216
00217 Usb_send_control_in();
00218 while(!(Is_usb_read_control_enabled()));
00219 #ifdef UART_U2
00220 Uart_set_baudrate((line_coding.dwDTERate)/2);
00221 #else
00222 Uart_set_baudrate(line_coding.dwDTERate);
00223 #endif
00224 }
00225
00226
00237 void cdc_set_control_line_state (void)
00238 {
00239 Usb_ack_receive_setup();
00240 Usb_send_control_in();
00241 while(!(Is_usb_read_control_enabled()));
00242
00243 }
00244
00245