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
00054
00055
00056
00057
00058
00059
00060 extern U8 code *pbuffer;
00061 extern U8 data_to_transfer;
00062 extern S_line_coding line_coding;
00063
00064
00065
00076 Bool usb_user_read_request(U8 type, U8 request)
00077 {
00078 U8 descriptor_type ;
00079 U8 string_type ;
00080
00081 string_type = Usb_read_byte();
00082 descriptor_type = Usb_read_byte();
00083 switch(request)
00084 {
00085 case GET_LINE_CODING:
00086 cdc_get_line_coding();
00087 return TRUE;
00088 break;
00089
00090 case SET_LINE_CODING:
00091 cdc_set_line_coding();
00092 return TRUE;
00093 break;
00094
00095 case SET_CONTROL_LINE_STATE:
00096 cdc_set_control_line_state();
00097 return TRUE;
00098 break;
00099
00100 default:
00101 return FALSE;
00102 break;
00103
00104 }
00105 return FALSE;
00106 }
00107
00108
00118 Bool usb_user_get_descriptor(U8 type, U8 string)
00119 {
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 return FALSE;
00153 }
00154
00163 void usb_user_endpoint_init(U8 conf_nb)
00164 {
00165 usb_configure_endpoint(INT_EP, \
00166 TYPE_INTERRUPT, \
00167 DIRECTION_IN, \
00168 SIZE_32, \
00169 ONE_BANK, \
00170 NYET_ENABLED);
00171
00172 usb_configure_endpoint(TX_EP, \
00173 TYPE_BULK, \
00174 DIRECTION_OUT, \
00175 SIZE_32, \
00176 ONE_BANK, \
00177 NYET_ENABLED);
00178
00179 usb_configure_endpoint(RX_EP, \
00180 TYPE_BULK, \
00181 DIRECTION_IN, \
00182 SIZE_32, \
00183 ONE_BANK, \
00184 NYET_ENABLED);
00185
00186 Usb_reset_endpoint(INT_EP);
00187 Usb_reset_endpoint(TX_EP);
00188 Usb_reset_endpoint(RX_EP);
00189
00190
00191 }
00192
00201 void cdc_get_line_coding(void)
00202 {
00203 Usb_ack_receive_setup();
00204 Usb_write_byte(LSB0(line_coding.dwDTERate));
00205 Usb_write_byte(LSB1(line_coding.dwDTERate));
00206 Usb_write_byte(LSB2(line_coding.dwDTERate));
00207 Usb_write_byte(LSB3(line_coding.dwDTERate));
00208 Usb_write_byte(line_coding.bCharFormat);
00209 Usb_write_byte(line_coding.bParityType);
00210 Usb_write_byte(line_coding.bDataBits);
00211
00212 Usb_send_control_in();
00213 while(!(Is_usb_read_control_enabled()));
00214
00215
00216 while(!Is_usb_receive_out());
00217 Usb_ack_receive_out();
00218 }
00219
00220
00229 void cdc_set_line_coding (void)
00230 {
00231 Usb_ack_receive_setup();
00232 while (!(Is_usb_receive_out()));
00233 LSB0(line_coding.dwDTERate) = Usb_read_byte();
00234 LSB1(line_coding.dwDTERate) = Usb_read_byte();
00235 LSB2(line_coding.dwDTERate) = Usb_read_byte();
00236 LSB3(line_coding.dwDTERate) = Usb_read_byte();
00237 line_coding.bCharFormat = Usb_read_byte();
00238 line_coding.bParityType = Usb_read_byte();
00239 line_coding.bDataBits = Usb_read_byte();
00240 Usb_ack_receive_out();
00241
00242 Usb_send_control_in();
00243 while(!(Is_usb_read_control_enabled()));
00244 }
00245
00246
00257 void cdc_set_control_line_state (void)
00258 {
00259 Usb_ack_receive_setup();
00260 Usb_send_control_in();
00261 while(!(Is_usb_read_control_enabled()));
00262
00263 }
00264
00265