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_audio_mixer.h"
00051 #include "conf_audio_player.h"
00052 #include "conf_usb.h"
00053
00054
00055 #if USB_DEVICE_FEATURE == ENABLED
00056
00057 #include "usb_drv.h"
00058 #include "usb_descriptors.h"
00059 #include "usb_standard_request.h"
00060 #include "usb_specific_request.h"
00061 #include "usart.h"
00062 #include "audio_example.h"
00063 #include "usb_stream_player.h"
00064 #include "device_audio_task.h"
00065 #include "hid.h"
00066
00067 #define TASKS_SCHEDULE() device_audio_task()
00068
00069
00070
00071 #define TARGET_UNDEFINED 0
00072 #define TARGET_SPEAKER 1
00073 #define TARGET_MICRO 2
00074
00075 typedef struct {
00076 U8 target;
00077 U8 cs;
00078 } st_audio_cmd;
00079
00083 Bool b_speaker_mute;
00084
00086 S16 s16_speaker_volume = (SPEAKER_VOL_MIN + SPEAKER_VOL_MAX)/2;
00087
00092 S16 s16_usb_speaker_volume = (USB_SPEAKER_VOL_MIN + USB_SPEAKER_VOL_MAX)/2;
00093
00097 Bool b_micro_mute;
00098
00102 S16 s16_micro_volume;
00103
00104
00105
00106
00107 st_audio_cmd check_audio_control_request(U16 wValue);
00108
00109
00110
00111
00112 extern const void *pbuffer;
00113 extern U16 data_to_transfer;
00114
00115
00116
00117 static void hid_get_descriptor(U8 size_of_report, const U8* p_usb_hid_report);
00118 static void usb_hid_set_report_ouput(void);
00119 static void usb_hid_set_idle (U8 u8_report_id, U8 u8_duration );
00120 static void usb_hid_get_idle (U8 u8_report_id);
00121 static S16 volume_usb_to_appli(S16 usb_volume);
00122
00123
00124
00128 void usb_user_endpoint_init(U8 conf_nb)
00129 {
00130
00131 (void)Usb_configure_endpoint( EP_KBD_IN,
00132 TYPE_INTERRUPT,
00133 DIRECTION_IN,
00134 EP_SIZE_KBD,
00135 SINGLE_BANK);
00136
00137 (void)Usb_configure_endpoint( EP_AUDIO_OUT,
00138 EP_ATTRIBUTES_OUT,
00139 DIRECTION_OUT,
00140 EP_SIZE_OUT,
00141 DOUBLE_BANK);
00142
00143 (void)Usb_configure_endpoint( EP_AUDIO_IN,
00144 EP_ATTRIBUTES_IN,
00145 DIRECTION_IN,
00146 EP_SIZE_IN,
00147 DOUBLE_BANK);
00148 }
00149
00150
00157 Bool usb_user_read_request(U8 bmRequestType, U8 bmRequest)
00158 {
00159 st_audio_cmd cmd;
00160
00161 U16 wValue;
00162 LSB(wValue)=Usb_read_endpoint_data(EP_CONTROL, 8);
00163 MSB(wValue)=Usb_read_endpoint_data(EP_CONTROL, 8);
00164
00165
00166 if( USB_SETUP_GET_STAND_INTERFACE == bmRequestType )
00167 {
00168 switch( bmRequest )
00169 {
00170 case SETUP_GET_DESCRIPTOR:
00171 switch( MSB(wValue) )
00172 {
00173 case HID_DESCRIPTOR:
00174 hid_get_descriptor(
00175 sizeof(usb_conf_desc.hid_kbd)
00176 , (const U8*)&usb_conf_desc.hid_kbd);
00177 return TRUE;
00178
00179
00180 case HID_REPORT_DESCRIPTOR:
00181 hid_get_descriptor(
00182 sizeof(usb_hid_report_descriptor_kbd)
00183 , usb_hid_report_descriptor_kbd);
00184 return TRUE;
00185
00186 case HID_PHYSICAL_DESCRIPTOR:
00187
00188 break;
00189 }
00190 break;
00191 }
00192 }
00193
00194
00195
00196 if( USB_SETUP_SET_CLASS_INTER == bmRequestType )
00197 {
00198 switch( bmRequest )
00199 {
00200
00201
00202 case HID_SET_REPORT:
00203
00204
00205 switch (MSB(wValue))
00206 {
00207 case HID_REPORT_INPUT:
00208
00209 break;
00210
00211 case HID_REPORT_OUTPUT:
00212 usb_hid_set_report_ouput();
00213 return TRUE;
00214
00215
00216 case HID_REPORT_FEATURE:
00217 break;
00218 }
00219 break;
00220
00221 case HID_SET_IDLE:
00222 usb_hid_set_idle(LSB(wValue), MSB(wValue));
00223 return TRUE;
00224
00225 case HID_SET_PROTOCOL:
00226
00227 break;
00228
00229
00230
00231
00232
00233 case SETUP_AUDIO_SET_CUR:
00234 cmd = check_audio_control_request(wValue);
00235 switch( cmd.target )
00236 {
00237 case TARGET_SPEAKER:
00238 switch( cmd.cs )
00239 {
00240 case AUDIO_FU_CONTROL_CS_MUTE:
00241 audio_speaker_set_mute();
00242 return TRUE;
00243
00244 case AUDIO_FU_CONTROL_CS_VOLUME:
00245 audio_speaker_set_volume();
00246 return TRUE;
00247
00248 }
00249 break;
00250 case TARGET_MICRO:
00251 switch( cmd.cs )
00252 {
00253 case AUDIO_FU_CONTROL_CS_MUTE:
00254 audio_micro_set_mute();
00255 return TRUE;
00256
00257 case AUDIO_FU_CONTROL_CS_VOLUME:
00258 audio_micro_set_volume();
00259 return TRUE;
00260
00261 }
00262 break;
00263 }
00264 break;
00265
00266 case SETUP_AUDIO_SET_MIN:
00267 case SETUP_AUDIO_SET_MAX:
00268 case SETUP_AUDIO_SET_RES:
00269 case SETUP_AUDIO_SET_MEM:
00270
00271 break;
00272 }
00273 }
00274
00275 if( USB_SETUP_GET_CLASS_INTER == bmRequestType )
00276 {
00277
00278 switch( bmRequest )
00279 {
00280 case HID_GET_REPORT:
00281
00282 break;
00283 case HID_GET_IDLE:
00284 usb_hid_get_idle(LSB(wValue));
00285 return TRUE;
00286 case HID_GET_PROTOCOL:
00287
00288 break;
00289 }
00290
00291
00292
00293
00294
00295 switch( bmRequest )
00296 {
00297 case SETUP_AUDIO_GET_CUR:
00298 cmd = check_audio_control_request(wValue);
00299 switch( cmd.target )
00300 {
00301 case TARGET_SPEAKER:
00302 switch( cmd.cs )
00303 {
00304 case AUDIO_FU_CONTROL_CS_MUTE:
00305 audio_speaker_get_mute();
00306 return TRUE;
00307
00308 case AUDIO_FU_CONTROL_CS_VOLUME:
00309 audio_speaker_get_vol_cur();
00310 return TRUE;
00311
00312 }
00313 break;
00314 case TARGET_MICRO:
00315 switch( cmd.cs )
00316 {
00317 case AUDIO_FU_CONTROL_CS_MUTE:
00318 audio_micro_get_mute();
00319 return TRUE;
00320
00321 case AUDIO_FU_CONTROL_CS_VOLUME:
00322 audio_micro_get_vol_cur();
00323 return TRUE;
00324
00325 }
00326 break;
00327 }
00328 break;
00329
00330 case SETUP_AUDIO_GET_MIN:
00331 cmd = check_audio_control_request(wValue);
00332 switch( cmd.target )
00333 {
00334 case TARGET_SPEAKER:
00335 switch( cmd.cs )
00336 {
00337 case AUDIO_FU_CONTROL_CS_MUTE:
00338 audio_speaker_get_mute();
00339 return TRUE;
00340
00341 case AUDIO_FU_CONTROL_CS_VOLUME:
00342 audio_speaker_get_vol_min();
00343 return TRUE;
00344
00345 }
00346 break;
00347 case TARGET_MICRO:
00348 switch( cmd.cs )
00349 {
00350 case AUDIO_FU_CONTROL_CS_MUTE:
00351 audio_micro_get_mute();
00352 return TRUE;
00353
00354 case AUDIO_FU_CONTROL_CS_VOLUME:
00355 audio_micro_get_vol_min();
00356 return TRUE;
00357
00358 }
00359 break;
00360 }
00361 break;
00362
00363 case SETUP_AUDIO_GET_MAX:
00364 cmd = check_audio_control_request(wValue);
00365 switch( cmd.target )
00366 {
00367 case TARGET_SPEAKER:
00368 switch( cmd.cs )
00369 {
00370 case AUDIO_FU_CONTROL_CS_MUTE:
00371 audio_speaker_get_mute();
00372 return TRUE;
00373
00374 case AUDIO_FU_CONTROL_CS_VOLUME:
00375 audio_speaker_get_vol_max();
00376 return TRUE;
00377
00378 }
00379 break;
00380 case TARGET_MICRO:
00381 switch( cmd.cs )
00382 {
00383 case AUDIO_FU_CONTROL_CS_MUTE:
00384 audio_micro_get_mute();
00385 return TRUE;
00386
00387 case AUDIO_FU_CONTROL_CS_VOLUME:
00388 audio_micro_get_vol_max();
00389 return TRUE;
00390
00391 }
00392 break;
00393 }
00394 break;
00395
00396 case SETUP_AUDIO_GET_RES:
00397 cmd = check_audio_control_request(wValue);
00398 switch( cmd.target )
00399 {
00400 case TARGET_SPEAKER:
00401 switch( cmd.cs )
00402 {
00403 case AUDIO_FU_CONTROL_CS_MUTE:
00404 audio_speaker_get_mute();
00405 return TRUE;
00406
00407 case AUDIO_FU_CONTROL_CS_VOLUME:
00408 audio_speaker_get_vol_res();
00409 return TRUE;
00410
00411 }
00412 break;
00413 case TARGET_MICRO:
00414 switch( cmd.cs )
00415 {
00416 case AUDIO_FU_CONTROL_CS_MUTE:
00417 audio_micro_get_mute();
00418 return TRUE;
00419
00420 case AUDIO_FU_CONTROL_CS_VOLUME:
00421 audio_micro_get_vol_res();
00422 return TRUE;
00423
00424 }
00425 break;
00426 }
00427 break;
00428
00429 case SETUP_AUDIO_GET_MEM:
00430 case SETUP_AUDIO_GET_STAT:
00431
00432 break;
00433 }
00434 }
00435
00436
00437 if( USB_SETUP_SET_CLASS_ENDPOINT == bmRequestType )
00438 {
00439 switch( bmRequest )
00440 {
00441 case SETUP_AUDIO_SAMPLING_FREQ_CONTROL:
00442 audio_speaker_set_sample_freq();
00443 return TRUE;
00444
00445 case SETUP_AUDIO_SET_MEM:
00446 case SETUP_AUDIO_SET_MIN:
00447 case SETUP_AUDIO_SET_MAX:
00448 case SETUP_AUDIO_SET_RES:
00449
00450 break;
00451 }
00452 }
00453 if( USB_SETUP_GET_CLASS_ENDPOINT == bmRequestType )
00454 {
00455 switch( bmRequest )
00456 {
00457 case SETUP_AUDIO_GET_CUR:
00458 case SETUP_AUDIO_GET_MIN:
00459 case SETUP_AUDIO_GET_MAX:
00460 case SETUP_AUDIO_GET_RES:
00461 case SETUP_AUDIO_GET_MEM:
00462 case SETUP_AUDIO_GET_STAT:
00463
00464 break;
00465 }
00466 }
00467 return FALSE;
00468 }
00469
00473 Bool usb_user_get_descriptor(U8 type, U8 string)
00474 {
00475 pbuffer = NULL;
00476
00477 switch(type)
00478 {
00479 case STRING_DESCRIPTOR:
00480 switch (string)
00481 {
00482 case LANG_ID:
00483 data_to_transfer = sizeof (usb_user_language_id);
00484 pbuffer = &usb_user_language_id;
00485 break;
00486
00487 case MAN_INDEX:
00488 data_to_transfer = sizeof (usb_user_manufacturer_string_descriptor);
00489 pbuffer = &usb_user_manufacturer_string_descriptor;
00490 break;
00491
00492 case PROD_INDEX:
00493 data_to_transfer = sizeof (usb_user_product_string_descriptor);
00494 pbuffer = &usb_user_product_string_descriptor;
00495 break;
00496
00497 case SN_INDEX:
00498 data_to_transfer = sizeof (usb_user_serial_number);
00499 pbuffer = &usb_user_serial_number;
00500 break;
00501
00502 default:
00503 break;
00504 }
00505 break;
00506
00507 default:
00508 break;
00509 }
00510
00511 return pbuffer != NULL;
00512 }
00513
00514
00515
00520 st_audio_cmd check_audio_control_request(U16 wValue)
00521 {
00522 st_audio_cmd cmd;
00523 U16 wIndex;
00524 U16 length;
00525
00526 LSB(wIndex)=Usb_read_endpoint_data(EP_CONTROL, 8);
00527 MSB(wIndex)=Usb_read_endpoint_data(EP_CONTROL, 8);
00528 LSB(length)=Usb_read_endpoint_data(EP_CONTROL, 8);
00529 MSB(length)=Usb_read_endpoint_data(EP_CONTROL, 8);
00530 Usb_ack_setup_received_free();
00531
00532 cmd.target = TARGET_UNDEFINED;
00533 cmd.cs = AUDIO_FU_CONTROL_CS_UNDEFINED;
00534
00535
00536
00537 if( LSB(wIndex) == AC_INTERFACE_NB)
00538 {
00539
00540
00541 cmd.cs = MSB(wValue);
00542
00543 if( (MSB(wIndex) == SPEAKER_FEATURE_UNIT_ID)
00544 && (LSB(wValue) == 0) )
00545 {
00546
00547 cmd.target = TARGET_SPEAKER;
00548
00549 }
00550 if( (MSB(wIndex) == MICRO_FEATURE_UNIT_ID)
00551 && (LSB(wValue) == 0) )
00552 {
00553
00554 cmd.target = TARGET_MICRO;
00555 }
00556 }
00557 return cmd;
00558 }
00559
00560
00561 void audio_speaker_set_mute(void)
00562 {
00563 while(!Is_usb_control_out_received())
00564 {
00565 TASKS_SCHEDULE();
00566 }
00567 Usb_reset_endpoint_fifo_access(EP_CONTROL);
00568 b_speaker_mute=Usb_read_endpoint_data(EP_CONTROL, 8);
00569 audio_mixer_mute_audio(b_speaker_mute);
00570
00571 if( b_speaker_mute )
00572 {
00573 audio_mixer_dacs_set_volume_direct((U8)SPEAKER_VOL_MIN);
00574 }
00575 else
00576 {
00577 audio_mixer_dacs_set_volume_direct(s16_speaker_volume);
00578 }
00579
00580 Usb_ack_control_out_received_free();
00581 Usb_ack_control_in_ready_send();
00582 while (!Is_usb_control_in_ready())
00583 {
00584 TASKS_SCHEDULE();
00585 }
00586 }
00587 void audio_speaker_get_mute(void)
00588 {
00589 Usb_reset_endpoint_fifo_access(EP_CONTROL);
00590 Usb_write_endpoint_data(EP_CONTROL, 8, b_speaker_mute);
00591 Usb_ack_control_in_ready_send();
00592 while(!Is_usb_control_out_received())
00593 {
00594 TASKS_SCHEDULE();
00595 }
00596 Usb_ack_control_out_received_free();
00597 }
00598 void audio_speaker_set_sample_freq(void)
00599 {
00600 U32 sample_freq=0;
00601 Usb_ack_setup_received_free();
00602 while(!Is_usb_control_out_received())
00603 {
00604 TASKS_SCHEDULE();
00605 }
00606 Usb_reset_endpoint_fifo_access(EP_CONTROL);
00607 LSB0(sample_freq)=Usb_read_endpoint_data(EP_CONTROL, 8);
00608 LSB1(sample_freq)=Usb_read_endpoint_data(EP_CONTROL, 8);
00609 LSB2(sample_freq)=Usb_read_endpoint_data(EP_CONTROL, 8);
00610 Usb_ack_control_out_received_free();
00611 Usb_ack_control_in_ready_send();
00612 while (!Is_usb_control_in_ready())
00613 {
00614 TASKS_SCHEDULE();
00615 }
00616
00617 #if (defined BOARD) && (BOARD==EVK1105) && (defined DEFAULT_DACS) && (DEFAULT_DACS==AUDIO_MIXER_DAC_AIC23B)
00618
00619
00620
00621 device_audio_disable_microphone();
00622 #endif
00623 audio_mixer_dacs_flush_direct(FALSE);
00624 usb_stream_init(
00625 sample_freq
00626 , 2
00627 , 16
00628 , FALSE
00629 );
00630 #if (defined BOARD) && (BOARD==EVK1105) && (defined DEFAULT_DACS) && (DEFAULT_DACS==AUDIO_MIXER_DAC_AIC23B)
00631
00632 device_audio_enable_microphone();
00633 #endif
00634 }
00635 void audio_speaker_set_volume(void)
00636 {
00637 while(!Is_usb_control_out_received())
00638 {
00639 TASKS_SCHEDULE();
00640 }
00641 Usb_reset_endpoint_fifo_access(EP_CONTROL);
00642 LSB(s16_usb_speaker_volume)=Usb_read_endpoint_data(EP_CONTROL, 8);
00643 MSB(s16_usb_speaker_volume)=Usb_read_endpoint_data(EP_CONTROL, 8);
00644
00645
00646 s16_speaker_volume = volume_usb_to_appli(s16_usb_speaker_volume) ;
00647
00648 Usb_ack_control_out_received_free();
00649 Usb_ack_control_in_ready_send();
00650
00651
00652 s16_speaker_volume = min( s16_speaker_volume, SPEAKER_VOL_MAX);
00653 s16_speaker_volume = max( s16_speaker_volume, SPEAKER_VOL_MIN);
00654 audio_mixer_dacs_set_volume_direct(s16_speaker_volume);
00655 while (!Is_usb_control_in_ready())
00656 {
00657 TASKS_SCHEDULE();
00658 }
00659 }
00660 void audio_speaker_get_vol_cur(void)
00661 {
00662 Usb_reset_endpoint_fifo_access(EP_CONTROL);
00663 Usb_write_endpoint_data(EP_CONTROL, 16, Usb_format_mcu_to_usb_data(16, s16_usb_speaker_volume));
00664 Usb_ack_control_in_ready_send();
00665 while(!Is_usb_control_out_received())
00666 {
00667 TASKS_SCHEDULE();
00668 }
00669 Usb_ack_control_out_received_free();
00670 }
00671 void audio_speaker_get_vol_min(void)
00672 {
00673 Usb_reset_endpoint_fifo_access(EP_CONTROL);
00674 Usb_write_endpoint_data(EP_CONTROL, 16, Usb_format_mcu_to_usb_data(16, USB_SPEAKER_VOL_MIN));
00675 Usb_ack_control_in_ready_send();
00676 while(!Is_usb_control_out_received())
00677 {
00678 TASKS_SCHEDULE();
00679 }
00680 Usb_ack_control_out_received_free();
00681 }
00682 void audio_speaker_get_vol_max(void)
00683 {
00684 Usb_reset_endpoint_fifo_access(EP_CONTROL);
00685 Usb_write_endpoint_data(EP_CONTROL, 16, Usb_format_mcu_to_usb_data(16, USB_SPEAKER_VOL_MAX));
00686 Usb_ack_control_in_ready_send();
00687 while(!Is_usb_control_out_received())
00688 {
00689 TASKS_SCHEDULE();
00690 }
00691 Usb_ack_control_out_received_free();
00692 }
00693 void audio_speaker_get_vol_res(void)
00694 {
00695 Usb_reset_endpoint_fifo_access(EP_CONTROL);
00696 Usb_write_endpoint_data(EP_CONTROL, 16, Usb_format_mcu_to_usb_data(16, USB_SPEAKER_VOL_RES));
00697 Usb_ack_control_in_ready_send();
00698 while(!Is_usb_control_out_received())
00699 {
00700 TASKS_SCHEDULE();
00701 }
00702 Usb_ack_control_out_received_free();
00703 }
00704
00705
00706
00707 void audio_micro_set_mute(void)
00708 {
00709 while(!Is_usb_control_out_received())
00710 {
00711 TASKS_SCHEDULE();
00712 }
00713 Usb_reset_endpoint_fifo_access(EP_CONTROL);
00714 b_micro_mute=Usb_read_endpoint_data(EP_CONTROL, 8);
00715 Usb_ack_control_out_received_free();
00716 Usb_ack_control_in_ready_send();
00717 while (!Is_usb_control_in_ready())
00718 {
00719 TASKS_SCHEDULE();
00720 }
00721 }
00722 void audio_micro_get_mute(void)
00723 {
00724 Usb_reset_endpoint_fifo_access(EP_CONTROL);
00725 Usb_write_endpoint_data(EP_CONTROL, 8, b_micro_mute);
00726 Usb_ack_control_in_ready_send();
00727 while(!Is_usb_control_out_received())
00728 {
00729 TASKS_SCHEDULE();
00730 }
00731 Usb_ack_control_out_received_free();
00732 }
00733 void audio_micro_set_volume(void)
00734 {
00735 while(!Is_usb_control_out_received())
00736 {
00737 TASKS_SCHEDULE();
00738 }
00739 Usb_reset_endpoint_fifo_access(EP_CONTROL);
00740 LSB(s16_micro_volume)=Usb_read_endpoint_data(EP_CONTROL, 8);
00741 MSB(s16_micro_volume)=Usb_read_endpoint_data(EP_CONTROL, 8);
00742 Usb_ack_control_out_received_free();
00743 Usb_ack_control_in_ready_send();
00744 while (!Is_usb_control_in_ready())
00745 {
00746 TASKS_SCHEDULE();
00747 }
00748 }
00749 void audio_micro_get_vol_cur(void)
00750 {
00751 Usb_reset_endpoint_fifo_access(EP_CONTROL);
00752 Usb_write_endpoint_data(EP_CONTROL, 8, LSB(s16_micro_volume));
00753 Usb_write_endpoint_data(EP_CONTROL, 8, MSB(s16_micro_volume));
00754 Usb_ack_control_in_ready_send();
00755 while(!Is_usb_control_out_received())
00756 {
00757 TASKS_SCHEDULE();
00758 }
00759 Usb_ack_control_out_received_free();
00760 }
00761 void audio_micro_get_vol_min(void)
00762 {
00763 Usb_reset_endpoint_fifo_access(EP_CONTROL);
00764 Usb_write_endpoint_data(EP_CONTROL, 16, Usb_format_mcu_to_usb_data(16, MICRO_VOL_MIN));
00765 Usb_ack_control_in_ready_send();
00766 while(!Is_usb_control_out_received())
00767 {
00768 TASKS_SCHEDULE();
00769 }
00770 Usb_ack_control_out_received_free();
00771 }
00772 void audio_micro_get_vol_max(void)
00773 {
00774 Usb_reset_endpoint_fifo_access(EP_CONTROL);
00775 Usb_write_endpoint_data(EP_CONTROL, 16, Usb_format_mcu_to_usb_data(16, MICRO_VOL_MAX));
00776 Usb_ack_control_in_ready_send();
00777 while(!Is_usb_control_out_received())
00778 {
00779 TASKS_SCHEDULE();
00780 }
00781 Usb_ack_control_out_received_free();
00782 }
00783 void audio_micro_get_vol_res(void)
00784 {
00785 Usb_reset_endpoint_fifo_access(EP_CONTROL);
00786 Usb_write_endpoint_data(EP_CONTROL, 16, Usb_format_mcu_to_usb_data(16, MICRO_VOL_RES));
00787 Usb_ack_control_in_ready_send();
00788 while(!Is_usb_control_out_received())
00789 {
00790 TASKS_SCHEDULE();
00791 }
00792 Usb_ack_control_out_received_free();
00793 }
00794
00795
00798 static void usb_hid_set_report_ouput (void)
00799 {
00800
00801 Usb_ack_setup_received_free();
00802
00803 Usb_ack_control_in_ready_send();
00804
00805
00806 while (!Is_usb_control_out_received());
00807
00808 Usb_ack_control_out_received_free();
00809
00810 Usb_ack_control_in_ready_send();
00811 }
00812
00813
00819 U8 g_u8_report_rate=0;
00820 static void usb_hid_set_idle (U8 u8_report_id, U8 u8_duration )
00821 {
00822 U16 wInterface;
00823
00824
00825 wInterface=usb_format_usb_to_mcu_data(16, Usb_read_endpoint_data(EP_CONTROL, 16));
00826 Usb_ack_setup_received_free();
00827
00828 if( wInterface == INTERFACE_NB_KBD )
00829 g_u8_report_rate = u8_duration;
00830
00831 Usb_ack_control_in_ready_send();
00832 while (!Is_usb_control_in_ready());
00833 }
00834
00835
00840 static void usb_hid_get_idle (U8 u8_report_id)
00841 {
00842 U16 wLength;
00843 U16 wInterface;
00844
00845
00846 wInterface=usb_format_usb_to_mcu_data(16, Usb_read_endpoint_data(EP_CONTROL, 16));
00847 wLength =usb_format_usb_to_mcu_data(16, Usb_read_endpoint_data(EP_CONTROL, 16));
00848 Usb_ack_setup_received_free();
00849
00850 if( (wLength != 0) && (wInterface == INTERFACE_NB_KBD) )
00851 {
00852 Usb_reset_endpoint_fifo_access(EP_CONTROL);
00853 Usb_write_endpoint_data(EP_CONTROL, 8, g_u8_report_rate);
00854 Usb_ack_control_in_ready_send();
00855 }
00856
00857 while (!Is_usb_control_out_received());
00858 Usb_ack_control_out_received_free();
00859 }
00860
00861
00864 static void hid_get_descriptor(U8 size_of_report, const U8* p_usb_hid_report)
00865 {
00866 Bool zlp;
00867 U16 wIndex;
00868 U16 wLength;
00869
00870 zlp = FALSE;
00871
00872 data_to_transfer = size_of_report;
00873 pbuffer = p_usb_hid_report;
00874
00875 wIndex = Usb_read_endpoint_data(EP_CONTROL, 16);
00876 wIndex = usb_format_usb_to_mcu_data(16, wIndex);
00877 wLength = Usb_read_endpoint_data(EP_CONTROL, 16);
00878 wLength = usb_format_usb_to_mcu_data(16, wLength);
00879 Usb_ack_setup_received_free();
00880
00881 if (wLength > data_to_transfer)
00882 {
00883 zlp = !(data_to_transfer % EP_CONTROL_LENGTH);
00884 }
00885 else
00886 {
00887 data_to_transfer = wLength;
00888 }
00889
00890 Usb_ack_nak_out(EP_CONTROL);
00891
00892 while (data_to_transfer && (!Is_usb_nak_out(EP_CONTROL)))
00893 {
00894 while( !Is_usb_control_in_ready() && !Is_usb_nak_out(EP_CONTROL) );
00895
00896 if( Is_usb_nak_out(EP_CONTROL) )
00897 break;
00898
00899 Usb_reset_endpoint_fifo_access(EP_CONTROL);
00900 data_to_transfer = usb_write_ep_txpacket(EP_CONTROL, pbuffer,
00901 data_to_transfer, &pbuffer);
00902 if( Is_usb_nak_out(EP_CONTROL) )
00903 break;
00904 else
00905 Usb_ack_control_in_ready_send();
00906 }
00907
00908 if ( zlp && (!Is_usb_nak_out(EP_CONTROL)) )
00909 {
00910 while (!Is_usb_control_in_ready());
00911 Usb_ack_control_in_ready_send();
00912 }
00913
00914 while (!(Is_usb_nak_out(EP_CONTROL)));
00915 Usb_ack_nak_out(EP_CONTROL);
00916 while (!Is_usb_control_out_received());
00917 Usb_ack_control_out_received_free();
00918 }
00919
00923 static S16 volume_usb_to_appli(S16 usb_volume)
00924 {
00925 S16 volume;
00926 if( usb_volume==-32768 )
00927 {
00928 volume=SPEAKER_VOL_MIN;
00929 }
00930 else
00931 {
00932 volume= (((S32)usb_volume-USB_SPEAKER_VOL_MIN)*(SPEAKER_VOL_MAX-SPEAKER_VOL_MIN)/(USB_SPEAKER_VOL_MAX-USB_SPEAKER_VOL_MIN))+SPEAKER_VOL_MIN;
00933 }
00934
00935 return volume;
00936 }
00937
00938 #endif // USB_DEVICE_FEATURE == ENABLED