00001
00015 #include "pic_usb.h"
00016 #include "pic_serial.h"
00017 #include "memory.h"
00018 #include "config.h"
00019 #include "pic_usb_buffer_mgt.h"
00020
00021
00022
00023
00024 usb_state_type usb_state = st_POWERED;
00025
00026 setup_data_packet usb_sdp;
00027
00028 uns8 usb_address;
00029 control_mode_type control_mode;
00030 uns16 delivery_bytes_to_send,
00031 delivery_bytes_max_send,
00032 delivery_bytes_sent;
00033 uns8 *delivery_ptr;
00034 uns8 delivery_buffer_size;
00035 uns8 *delivery_buffer;
00036 buffer_descriptor *delivery_bd;
00037
00038 usb_status_type usb_status;
00039
00040 void usb_configure_endpoints() {
00041
00042 #ifdef USB_DEBUG
00043 serial_print_str("Config eps ");
00044 #endif
00045 #ifdef USB_EP1
00046 set_bit (uep1, EPHSHK);
00047 #ifdef USB_EP1_OUT_SIZE
00048 set_bit(uep1, EPOUTEN);
00049 #else
00050 clear_bit(uep1, EPOUTEN);
00051 #endif
00052 #ifdef USB_EP1_IN_SIZE
00053 set_bit(uep1, EPINEN);
00054 #else
00055 clear_bit(uep1, EPINEN);
00056 #endif
00057 set_bit (uep1, EPCONDIS);
00058
00059
00060 #ifdef USB_EP1_IN_SIZE
00061 set_bit(bd1in.stat, DTS);
00062 clear_bit(bd1in.stat, KEN);
00063 clear_bit(bd1in.stat, INCDIS);
00064 clear_bit(bd1in.stat, DTSEN);
00065 clear_bit(bd1in.stat, BSTALL);
00066 clear_bit(bd1in.stat, BC9);
00067 clear_bit(bd1in.stat, BC8);
00068
00069 clear_bit(bd1in.stat, UOWN);
00070 #endif
00071
00072 #ifdef USB_EP1_OUT_SIZE
00073 bd1out.count = USB_EP1_OUT_SIZE;
00074 bd1out.addr = USB_EP1_OUT_ADDR;
00075
00076 clear_bit(bd1out.stat, DTS);
00077 clear_bit(bd1out.stat, KEN);
00078 clear_bit(bd1out.stat, INCDIS);
00079 clear_bit(bd1out.stat, DTSEN);
00080 clear_bit(bd1out.stat, BSTALL);
00081 clear_bit(bd1out.stat, BC9);
00082 clear_bit(bd1out.stat, BC8);
00083 set_bit (bd1out.stat, UOWN);
00084
00085 #endif
00086
00087
00088 #endif
00089
00090 #ifdef USB_EP2
00091 set_bit (uep2, EPHSHK);
00092 #ifdef USB_EP2_OUT_SIZE
00093 set_bit(uep2, EPOUTEN);
00094 #else
00095 clear_bit(uep2, EPOUTEN);
00096 #endif
00097 #ifdef USB_EP2_IN_SIZE
00098 set_bit(uep2, EPINEN);
00099 #else
00100 clear_bit(uep2, EPINEN);
00101 #endif
00102 set_bit (uep2, EPCONDIS);
00103
00104
00105 #ifdef USB_EP2_IN_SIZE
00106
00107 set_bit(bd2in.stat, DTS);
00108 clear_bit(bd2in.stat, KEN);
00109 clear_bit(bd2in.stat, INCDIS);
00110 clear_bit(bd2in.stat, DTSEN);
00111 clear_bit(bd2in.stat, BSTALL);
00112 clear_bit(bd2in.stat, BC9);
00113 clear_bit(bd2in.stat, BC8);
00114
00115 clear_bit(bd2in.stat, UOWN);
00116 #endif
00117
00118 #ifdef USB_EP2_OUT_SIZE
00119 bd2out.count = USB_EP2_OUT_SIZE;
00120 bd2out.addr = USB_EP2_OUT_ADDR;
00121
00122 clear_bit(bd2out.stat, DTS);
00123 clear_bit(bd2out.stat, KEN);
00124 clear_bit(bd2out.stat, INCDIS);
00125 clear_bit(bd2out.stat, DTSEN);
00126 clear_bit(bd2out.stat, BSTALL);
00127 clear_bit(bd2out.stat, BC9);
00128 clear_bit(bd2out.stat, BC8);
00129 set_bit (bd2out.stat, UOWN);
00130 #endif
00131 #endif
00132
00133 #ifdef USB_EP3
00134 set_bit (uep3, EPHSHK);
00135 #ifdef USB_EP3_OUT_SIZE
00136 set_bit(uep3, EPOUTEN);
00137 #else
00138 clear_bit(uep3, EPOUTEN);
00139 #endif
00140 #ifdef USB_EP3_IN_SIZE
00141 set_bit(uep3, EPINEN);
00142 #else
00143 clear_bit(uep3, EPINEN);
00144 #endif
00145 set_bit (uep3, EPCONDIS);
00146
00147 #ifdef USB_EP3_IN_SIZE
00148 set_bit(bd3in.stat, DTS);
00149 clear_bit(bd3in.stat, KEN);
00150 clear_bit(bd3in.stat, INCDIS);
00151 clear_bit(bd3in.stat, DTSEN);
00152 clear_bit(bd3in.stat, BSTALL);
00153 clear_bit(bd3in.stat, BC9);
00154 clear_bit(bd3in.stat, BC8);
00155
00156 clear_bit(bd3in.stat, UOWN);
00157 #endif
00158
00159 #ifdef USB_EP3_OUT_SIZE
00160 bd3out.count = USB_EP3_OUT_SIZE;
00161 bd3out.addr = USB_EP3_OUT_ADDR;
00162
00163 clear_bit(bd3out.stat, DTS);
00164 clear_bit(bd3out.stat, KEN);
00165 clear_bit(bd3out.stat, INCDIS);
00166 clear_bit(bd3out.stat, DTSEN);
00167 clear_bit(bd3out.stat, BSTALL);
00168 clear_bit(bd3out.stat, BC9);
00169 clear_bit(bd3out.stat, BC8);
00170 set_bit (bd3out.stat, UOWN);
00171 #endif
00172
00173 #endif
00174
00175 }
00176
00177 void usb_stall_ep0() {
00178 set_bit(bd0in.stat, BSTALL);
00179 set_bit(bd0in.stat, UOWN);
00180 set_bit(bd0out.stat, BSTALL);
00181 set_bit(bd0out.stat, UOWN);
00182
00183 }
00184
00185 void usb_send_data(uns8 ep, uns8 *data, uns8 send_count, bit first) {
00186 uns8 count;
00187 buffer_descriptor *bd;
00188 uns8 *buffer;
00189
00190
00191
00192
00193 buffer = ep_in_buffer_location[ep];
00194
00195 bd = ep_in_bd_location[ep];
00196
00197 if (test_bit(bd->stat, UOWN)) {
00198 #ifdef USB_DEBUG
00199 serial_print_str(" don't own it! ");
00200 #endif
00201 return;
00202 }
00203
00204 count = 0;
00205 while ((count < send_count)) {
00206 buffer[count] = data[count];
00207 count++;
00208 }
00209
00210
00211 bd->count = count;
00212 bd->addr = (uns16)buffer;
00213 if (first) {
00214 clear_bit(bd->stat, DTS);
00215 }
00216
00217 toggle_bit(bd->stat, DTS);
00218 clear_bit(bd->stat, KEN);
00219 clear_bit(bd->stat, INCDIS);
00220 set_bit (bd->stat, DTSEN);
00221 clear_bit(bd->stat, BSTALL);
00222 clear_bit(bd->stat, BC9);
00223 clear_bit(bd->stat, BC8);
00224
00225 set_bit (bd->stat, UOWN);
00226 }
00227
00228
00229
00230 void usb_send_data_chunk() {
00231
00232 uns8 count;
00233
00234 count = 0;
00235 while ((count < delivery_buffer_size) &&
00236 (delivery_bytes_sent < delivery_bytes_to_send) &&
00237 (delivery_bytes_sent < delivery_bytes_max_send)) {
00238 delivery_buffer[count] = *delivery_ptr;
00239 delivery_ptr++;
00240 delivery_bytes_sent++;
00241 count++;
00242 }
00243
00244 if ((count < delivery_buffer_size) &&
00245 ((delivery_bytes_sent == delivery_bytes_max_send) ||
00246 (delivery_bytes_sent == delivery_bytes_to_send))) {
00247 control_mode = cm_CTRL_READ_AWAITING_STATUS;
00248 }
00249
00250
00251 bd0in.count = count;
00252 bd0in.addr = (uns16)&buffer_0_in;
00253 toggle_bit(bd0in.stat, DTS);
00254 clear_bit(bd0in.stat, KEN);
00255 clear_bit(bd0in.stat, INCDIS);
00256 set_bit (bd0in.stat, DTSEN);
00257 clear_bit(bd0in.stat, BSTALL);
00258 clear_bit(bd0in.stat, BC9);
00259 clear_bit(bd0in.stat, BC8);
00260
00261 set_bit (bd0in.stat, UOWN);
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275 }
00276
00277
00278 void usb_send_empty_data_pkt() {
00279 delivery_buffer_size = USB_EP0_IN_SIZE;
00280 delivery_bd = &bd0in;
00281 delivery_buffer = &buffer_0_in;
00282 delivery_bytes_sent = 0;
00283 delivery_bytes_to_send = 0;
00284 delivery_bytes_max_send = 0;
00285 delivery_ptr = (uns8 *) 0;
00286 clear_bit(bd0in.stat, DTS);
00287 usb_send_data_chunk();
00288 }
00289
00290 uns8 buffer_byte;
00291
00292 void usb_send_one_byte(uns8 data) {
00293 delivery_buffer_size = USB_EP0_IN_SIZE;
00294 delivery_bytes_sent = 0;
00295 delivery_bytes_to_send = 1;
00296 delivery_bytes_max_send = 0;
00297 buffer_byte = data;
00298 delivery_ptr = (uns8 *) &buffer_byte;
00299 delivery_bd = &bd0in;
00300 delivery_buffer = &buffer_0_in;
00301
00302 clear_bit(bd0in.stat, DTS);
00303 usb_send_data_chunk();
00304 }
00305
00306 void usb_prime_ep0_out() {
00307 #ifdef USB_DEBUG
00308 serial_putc('P');
00309 #endif
00310 bd0out.count = USB_EP0_OUT_SIZE;
00311 bd0out.addr = USB_EP0_OUT_ADDR;
00312
00313 set_bit(bd0out.stat, DTS);
00314 clear_bit(bd0out.stat, KEN);
00315 clear_bit(bd0out.stat, INCDIS);
00316
00317 set_bit (bd0out.stat, DTSEN);
00318 clear_bit(bd0out.stat, BSTALL);
00319 clear_bit(bd0out.stat, BC9);
00320 clear_bit(bd0out.stat, BC8);
00321
00322 set_bit (bd0out.stat, UOWN);
00323 }
00324
00325 void usb_handle_standard_request(setup_data_packet sdp) {
00326
00327 switch (sdp.bRequest) {
00328 case req_Get_Descriptor:
00329 #ifdef USB_DEBUG
00330 serial_print_str(" GD: ");
00331 #endif
00332 uns8 descriptor_type = sdp.wValue >> 8;
00333 uns8 descriptor_num = sdp.wValue & 0xff;
00334 #ifdef USB_DEBUG
00335 serial_print_int(descriptor_type);
00336 #endif
00337 usb_get_descriptor_callback(descriptor_type, descriptor_num, &delivery_ptr, &delivery_bytes_to_send);
00338 if (delivery_ptr != 0) {
00339 control_mode = cm_CTRL_READ_DATA_STAGE;
00340 delivery_bytes_max_send = sdp.wLength;
00341 delivery_bytes_sent = 0;
00342 delivery_buffer_size = USB_EP0_IN_SIZE;
00343 delivery_bd = &bd0in;
00344 delivery_buffer = (uns8 *)USB_EP0_IN_ADDR;
00345 clear_bit(bd0in.stat, DTS);
00346 usb_send_data_chunk();
00347 } else {
00348 #ifdef USB_DEBUG
00349 serial_print_str(" <stall> ");
00350 #endif
00351 usb_stall_ep0();
00352 }
00353
00354 break;
00355 case req_Set_Address:
00356 usb_address = sdp.wValue & 0xff;
00357 #ifdef USB_DEBUG
00358 serial_print_str(" SA:");
00359 serial_print_int_hex(usb_address);
00360 #endif
00361 usb_status = us_SET_ADDRESS;
00362
00363
00364 usb_send_status_ack();
00365 control_mode = cm_CTRL_WRITE_SENDING_STATUS;
00366 break;
00367 case req_Set_Configuration:
00368 #ifdef USB_DEBUG
00369 serial_print_str(" SC: ");
00370 #endif
00371
00372
00373 control_mode = cm_CTRL_WRITE_SENDING_STATUS;
00374 usb_send_status_ack();
00375
00376 usb_state = st_CONFIGURED;
00377
00378
00379 usb_configure_endpoints();
00380
00381 #ifdef USB_CALLBACK_ON_DEVICE_CONFIGURED
00382 usb_device_configured_callback();
00383 #endif
00384 break;
00385 case req_Get_Interface:
00386 #ifdef USB_DEBUG
00387 serial_print_str(" GI ");
00388 #endif
00389 control_mode = cm_CTRL_READ_DATA_STAGE;
00390 usb_send_one_byte(1);
00391 case req_Get_Status:
00392
00393 #ifdef USB_DEBUG
00394 serial_print_str(" GS ");
00395 #endif
00396
00397 #ifdef USB_SELF_POWERED
00398 usb_send_one_byte(1);
00399 #else
00400 usb_send_one_byte(0);
00401 #endif
00402 break;
00403 default:
00404 #ifdef USB_DEBUG
00405 serial_print_str(" ??SR ");
00406 serial_print_int(sdp.bRequest);
00407 #endif
00408 break;
00409
00410 }
00411 }
00412
00413
00414 void usb_handle_transaction() {
00415
00416 uns8 end_point, pid;
00417
00418 end_point = ustat >> 3;
00419
00420 if (test_bit(ustat, DIR)) {
00421 #ifdef USB_DEBUG
00422 serial_print_str("\nDI ");
00423 #endif
00424 pid = (bd0in.stat >> 2) & 0x0f;
00425
00426 } else {
00427 pid = (bd0out.stat >> 2) & 0x0f;
00428 #ifdef USB_DEBUG
00429 serial_print_str("\nDO ");
00430 #endif
00431 #ifdef USB_DEBUG_HIGH
00432 serial_print_int(bd0out.count);
00433 serial_print_spc();
00434 #endif
00435
00436 }
00437 #ifdef USB_DEBUG
00438 if (end_point != 0) {
00439 serial_putc('E');
00440 serial_print_int_hex(end_point);
00441 serial_print_spc();
00442 }
00443 #endif
00444
00445 if (end_point == 0) {
00446 #ifdef USB_DEBUG_HIGH
00447 serial_print_str(" bytes: ");
00448 serial_print_int(bd0out.count);
00449 #endif
00450 if (pid == pid_SETUP) {
00451 memcpy( (void*)&usb_sdp, (void *)&buffer_0_out, 8);
00452 usb_prime_ep0_out();
00453 #ifdef USB_DEBUG
00454 serial_print_int_hex(usb_sdp.bmRequestType);
00455 serial_putc('S');
00456 #endif
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467 if (!test_bit(usb_sdp.bmRequestType, REQUEST_TYPE1) &&
00468 !test_bit(usb_sdp.bmRequestType, REQUEST_TYPE0)) {
00469
00470 if ((usb_sdp.bmRequestType & 0b00011111) == 0) {
00471
00472 } else if ((usb_sdp.bmRequestType & 0b00011111) == 1) {
00473
00474 } else if ((usb_sdp.bmRequestType & 0b00011111) == 0b00011) {
00475
00476 }
00477
00478 usb_handle_standard_request(usb_sdp);
00479 } else if (!test_bit(usb_sdp.bmRequestType, REQUEST_TYPE1) &&
00480 test_bit(usb_sdp.bmRequestType, REQUEST_TYPE0)) {
00481
00482 #ifdef USB_CALLBACK_ON_CLASS_CTRL
00483 usb_handle_class_request_callback(usb_sdp);
00484 #endif
00485 } else {
00486
00487
00488
00489 serial_print_str(" ??req t ");
00490 serial_print_int(usb_sdp.bmRequestType);
00491 }
00492 clear_bit(ucon, PKTDIS);
00493
00494 } else if (pid == pid_IN) {
00495
00496 if (control_mode == cm_CTRL_READ_DATA_STAGE) {
00497
00498 usb_send_data_chunk();
00499 } else if (control_mode == cm_CTRL_WRITE_SENDING_STATUS) {
00500
00501 control_mode = cm_IDLE;
00502 if (usb_status == us_SET_ADDRESS) {
00503
00504 usb_state = st_ADDRESS;
00505 uaddr = usb_address;
00506
00507
00508 usb_status = us_IDLE;
00509 }
00510 } else if (control_mode == cm_CTRL_READ_AWAITING_STATUS) {
00511
00512 nop();
00513 } else if (control_mode == cm_CTRL_READ_DATA_STAGE_CLASS) {
00514
00515 #ifdef USB_CALLBACK_ON_CTRL_CLASS
00516 usb_handle_class_ctrl_read_callback();
00517 #else
00518 nop();
00519 #endif
00520 } else {
00521 serial_print_str(" ?? cm=");
00522 serial_print_int((uns8)control_mode);
00523 serial_print_spc();
00524 }
00525 } else if (pid == pid_ACK) {
00526 serial_print_str("A\n");
00527 if (control_mode == cm_CTRL_READ_DATA_STAGE) {
00528 serial_print_str(" &2 ");
00529 usb_send_data_chunk();
00530 } else if (control_mode == cm_CTRL_READ_DATA_STAGE_CLASS) {
00531 #ifdef USB_CALLBACK_ON_CTRL_CLASS
00532 usb_handle_class_ctrl_read_callback();
00533 #else
00534 nop();
00535 #endif
00536 } else if (control_mode == cm_CTRL_WRITE_SENDING_STATUS) {
00537 serial_print_str(" st sent ");
00538 control_mode = cm_IDLE;
00539 }
00540
00541 } else if (pid == pid_OUT) {
00542
00543
00544 if (control_mode == cm_CTRL_READ_AWAITING_STATUS) {
00545
00546 control_mode = cm_IDLE;
00547 } else if (control_mode == cm_CTRL_WRITE_DATA_STAGE_CLASS) {
00548 #ifdef USB_CALLBACK_ON_CTRL_CLASS
00549 usb_handle_class_ctrl_write_callback((uns8 *)&buffer_0_out, bd0out.count);
00550
00551
00552 #else
00553 nop();
00554 #endif
00555 } else if (control_mode == cm_CTRL_READ_DATA_STAGE) {
00556
00557 control_mode = cm_IDLE;
00558 } else {
00559
00560 serial_print_str("unk pid_OUT ");
00561 serial_print_int((uns8)control_mode);
00562 }
00563 usb_prime_ep0_out();
00564
00565 } else {
00566 serial_print_str(" UKPID = ");
00567 serial_print_int(pid);
00568 }
00569
00570 } else {
00571 buffer_descriptor *bd;
00572 if (test_bit(ustat, DIR)) {
00573
00574 #ifdef USB_EP_DATA_CALLBACK
00575 bd = ep_in_bd_location[end_point];
00576 usb_ep_data_in_callback(end_point, bd->count);
00577 #else
00578 nop();
00579 #endif
00580 } else {
00581
00582 bd = ep_out_bd_location[end_point];
00583
00584 #ifdef USB_EP_DATA_CALLBACK
00585 usb_ep_data_out_callback(end_point, ep_out_buffer_location[end_point],
00586 bd->count);
00587 #endif
00588
00589 bd->count = ep_out_buffer_size[end_point];
00590
00591
00592
00593 clear_bit(bd->stat, DTS);
00594 clear_bit(bd->stat, KEN);
00595 clear_bit(bd->stat, INCDIS);
00596 clear_bit(bd->stat, DTSEN);
00597 clear_bit(bd->stat, BSTALL);
00598 clear_bit(bd->stat, BC9);
00599 clear_bit(bd->stat, BC8);
00600 set_bit (bd->stat, UOWN);
00601
00602
00603 }
00604 }
00605 }
00606
00607 void usb_handle_reset() {
00608 usb_address = 0;
00609
00610
00611 control_mode = cm_IDLE;
00612 usb_status = us_IDLE;
00613
00614
00615 clear_bit(uir, TRNIF);
00616 clear_bit(uir, TRNIF);
00617 clear_bit(uir, TRNIF);
00618 clear_bit(uir, TRNIF);
00619
00620
00621
00622
00623
00624 bd0out.count = 8;
00625 bd0out.addr = 0x0500;
00626
00627 clear_bit(bd0out.stat, DTS);
00628 clear_bit(bd0out.stat, KEN);
00629 clear_bit(bd0out.stat, INCDIS);
00630 clear_bit (bd0out.stat, DTSEN);
00631 clear_bit(bd0out.stat, BSTALL);
00632 clear_bit(bd0out.stat, BC9);
00633 clear_bit(bd0out.stat, BC8);
00634
00635 set_bit (bd0out.stat, UOWN);
00636
00637
00638
00639 bd0in.count = 8;
00640 bd0in.addr = 0x0508;
00641 clear_bit(bd0in.stat, DTS);
00642 clear_bit(bd0in.stat, KEN);
00643 clear_bit(bd0in.stat, INCDIS);
00644 clear_bit(bd0in.stat, BSTALL);
00645 clear_bit(bd0in.stat, BC9);
00646 clear_bit(bd0in.stat, BC8);
00647
00648 clear_bit(bd0in.stat, UOWN);
00649
00650 serial_print_str("\nR ");
00651 serial_print_int_hex(uir);
00652
00653 }
00654
00655 void usb_handle_stall() {
00656 serial_print_str(" U:Stall ");
00657 }
00658
00659
00660
00661 void usb_handle_isr() {
00662
00663 if (test_bit(pir2, USBIF)) {
00664 clear_bit(pir2, USBIF);
00665
00666 if (test_bit(uir, TRNIF)) {
00667 usb_handle_transaction();
00668 clear_bit(uir, TRNIF);
00669 }
00670
00671 if (test_bit(uir, URSTIF)) {
00672 usb_handle_reset();
00673 clear_bit(uir, URSTIF);
00674 }
00675
00676 if (test_bit(uir, STALLIF)) {
00677 usb_handle_stall();
00678 clear_bit(uir, STALLIF);
00679 }
00680 #ifdef USB_CALLBACK_ON_SOF
00681 if (test_bit(uir, SOFIF)) {
00682 usb_SOF_callback(ufrm);
00683 clear_bit(uir, SOFIF);
00684 }
00685 #endif
00686 }
00687 }
00688
00689 void turn_usb_ints_on() {
00690
00691 set_bit(uie, STALLIE);
00692 set_bit(uie, TRNIE);
00693 set_bit(uie, URSTIE);
00694 set_bit(pie2, USBIE);
00695 #ifdef USB_CALLBACK_ON_SOF
00696 set_bit(uie, SOFIE);
00697 #endif
00698 }
00699
00700 void usb_setup() {
00701
00702 usb_state = st_POWERED;
00703
00704
00705 clear_bit(ucfg, UTRDIS);
00706 set_bit (ucfg, FSEN);
00707 set_bit (ucfg, UPUEN);
00708
00709 clear_bit(ucfg, PPB1);
00710 clear_bit(ucfg, PPB0);
00711
00712
00713
00714
00715
00716
00717
00718 set_bit(uep0, EPHSHK);
00719 set_bit(uep0, EPOUTEN);
00720 set_bit(uep0, EPINEN);
00721 clear_bit(uep0, EPCONDIS);
00722
00723
00724
00725
00726 ep_out_bd_location[0] = &bd0out;
00727 #if USB_HIGHEST_EP >= 1
00728 ep_out_bd_location[1] = &bd1out;
00729 #endif
00730 #if USB_HIGHEST_EP >= 2
00731 ep_out_bd_location[2] = &bd2out;
00732 #endif
00733 #if USB_HIGHEST_EP >= 3
00734 ep_out_bd_location[3] = &bd3out;
00735 #endif
00736 #if USB_HIGHEST_EP >= 4
00737 ep_out_bd_location[4] = &bd4out;
00738 #endif
00739
00740 ep_in_bd_location[0] = &bd0in;
00741 #if USB_HIGHEST_EP >= 1
00742 ep_in_bd_location[1] = &bd1in;
00743 #endif
00744 #if USB_HIGHEST_EP >= 2
00745 ep_in_bd_location[2] = &bd2in;
00746 #endif
00747 #if USB_HIGHEST_EP >= 3
00748 ep_in_bd_location[3] = &bd3in;
00749 #endif
00750 #if USB_HIGHEST_EP >= 4
00751 ep_in_bd_location[4] = &bd4in;
00752 #endif
00753
00754
00755 }
00756
00757
00758 void usb_enable_module() {
00759 uir = 0;
00760 set_bit(ucon, USBEN);
00761 usb_state = st_DEFAULT;
00762 }
00763
00764 usb_state_type usb_get_state() {
00765 return usb_state;
00766 }