Commit 6376da04214316c1462c9c2d9499118b9ac3a6b8

Authored by LuoZheSi
1 parent 8e886ba1

Update(usb lib of msc and device):Closes #I3Y7KC

@@ -13,6 +13,7 @@ @@ -13,6 +13,7 @@
13 13
14 #include "hw_uart.h" 14 #include "hw_uart.h"
15 #include "hw_misc.h" 15 #include "hw_misc.h"
  16 +#include "hw_da_pp.h"
16 17
17 #include "fifo.h" 18 #include "fifo.h"
18 #include "app_nav.h" 19 #include "app_nav.h"
@@ -42,9 +43,9 @@ @@ -42,9 +43,9 @@
42 43
43 #include "usbdev.h" 44 #include "usbdev.h"
44 #include "daudio.h" 45 #include "daudio.h"
45 -#include "hw_pll.h"  
46 #include "optek_link.h" 46 #include "optek_link.h"
47 47
  48 +
48 #ifdef USB_SPEAKER_AUTO_DETECT 49 #ifdef USB_SPEAKER_AUTO_DETECT
49 //U8 pre_usb_host_state, 50 //U8 pre_usb_host_state,
50 U8 usb_host_state; 51 U8 usb_host_state;
@@ -56,19 +57,68 @@ U8 usb_host_state; @@ -56,19 +57,68 @@ U8 usb_host_state;
56 FIFO HIDOutFifo; 57 FIFO HIDOutFifo;
57 U8 HIDOutFifoBuf[HIDOutFifoBufSize]; 58 U8 HIDOutFifoBuf[HIDOutFifoBufSize];
58 59
  60 +#if 0//for new usb device lib
  61 +USB_DEV_FEATURE_CONF usbdev_featureconf;
  62 +#endif
  63 +
  64 +#ifdef USB_SPEAKER_VOL_ENABLE
  65 +int usb_speaker_vol_gain = -1;
  66 +#endif
  67 +
  68 +#if 1//def HIDFUNC
  69 +//static U8 hidBuffer[3] ={0x01,0x00,0x00}; //3bytes for consumer usage: Report ID/keycode/00
  70 +U8 hidBuffer[64]; //64bytes for FS HID, 1024 for HS. consumer usage: Report ID/keycode/00
  71 +//static U16 keyi=0, HIDKeycodes[] ={0x0001,0x0002,0x0400}; //Vol+, Vol-. Mute
  72 +#endif
  73 +
59 74
60 void app_nav_usbSpeaker_pocess (UI_MSG *process_msg); 75 void app_nav_usbSpeaker_pocess (UI_MSG *process_msg);
61 76
62 void app_cmd_usbSpeaker_volChange( void ) 77 void app_cmd_usbSpeaker_volChange( void )
63 { 78 {
64 - //AUDIOdevice.Set_Volume(app_main_data.volume); 79 + //DBG_Printf("usbSpeaker_volChange:%d\n\r", vol);
65 80
  81 + //AUDIOdevice.Set_Volume(app_main_data.volume);
66 //AUDIOdevice.Set_Bass_Treble(app_main_data.bass, app_main_data.treble); 82 //AUDIOdevice.Set_Bass_Treble(app_main_data.bass, app_main_data.treble);
67 } 83 }
68 84
69 -void app_cmd_usbSpeaker_volSet( U8 vol ) 85 +void app_cmd_usbSpeaker_volSet( U16 vol )
70 { 86 {
71 //app_main_data.volume = vol; 87 //app_main_data.volume = vol;
  88 + DBG_Printf("usbSpeaker_volSet:%d\n\r", vol);
  89 +
  90 +#ifdef USB_SPEAKER_VOL_ENABLE
  91 +
  92 +#if 0
  93 + U32 switch_vol, value;
  94 +
  95 + switch_vol = (vol*VOLUME_MAX) / PC_SPEAKER_VOL_MAX;
  96 + if (switch_vol)
  97 + {
  98 + #if 0
  99 + if (app_main_data.media == MEDIA_AUX)
  100 + {
  101 + value = (240+650-60) - (switch_vol*650)/VOLUME_MAX;
  102 + }
  103 + else
  104 + #endif
  105 + {
  106 + //240:0db position
  107 + value = (240+650) - (switch_vol*650)/VOLUME_MAX;
  108 + }
  109 + }
  110 + else
  111 + {
  112 + value = 240+990;
  113 + }
  114 + usb_speaker_vol_gain = optek_vol_table_usb_speaker[temp];
  115 +
  116 + //DBG_Printf("speaker_vol_gain:0x%x, switch_vol:%d\n\r", usb_speaker_vol_gain, switch_vol);
  117 +#else
  118 + usb_speaker_vol_gain = (0x8000000/10240)*vol;
  119 +#endif
  120 +
  121 +#endif //USB_SPEAKER_VOL_ENABLE
72 } 122 }
73 123
74 int daudio_isMute( void ); 124 int daudio_isMute( void );
@@ -137,7 +187,11 @@ static void usbSpeakerStreamConfig( void ) @@ -137,7 +187,11 @@ static void usbSpeakerStreamConfig( void )
137 fifo_init(&HIDOutFifo, HIDOutFifoBuf, HIDOutFifoBufSize, TRUE); 187 fifo_init(&HIDOutFifo, HIDOutFifoBuf, HIDOutFifoBufSize, TRUE);
138 188
139 usbdev_featureconf.HIDFuncEnable = TRUE; 189 usbdev_featureconf.HIDFuncEnable = TRUE;
  190 + #ifdef HIDKEY
  191 + usbdev_featureconf.HIDKEYEnable = TRUE;
  192 + #else
140 usbdev_featureconf.HIDKEYEnable = FALSE; 193 usbdev_featureconf.HIDKEYEnable = FALSE;
  194 + #endif
141 #else 195 #else
142 usbdev_featureconf.HIDFuncEnable = FALSE; 196 usbdev_featureconf.HIDFuncEnable = FALSE;
143 usbdev_featureconf.HIDKEYEnable = FALSE; 197 usbdev_featureconf.HIDKEYEnable = FALSE;
@@ -516,8 +570,9 @@ void app_nav_rmt_convert_pc_speaker(void) @@ -516,8 +570,9 @@ void app_nav_rmt_convert_pc_speaker(void)
516 570
517 //app_nav_spk_level_init (); 571 //app_nav_spk_level_init ();
518 572
519 - //app_pre_state_saving(); 573 + #ifdef EEPROM
520 app_save_system_data(); 574 app_save_system_data();
  575 + #endif
521 576
522 p = (U8 *) STRING_USB_SPEAKER_APP; 577 p = (U8 *) STRING_USB_SPEAKER_APP;
523 CPU_SoftReset_Flag_Setting((U8 *) p, FALSE); 578 CPU_SoftReset_Flag_Setting((U8 *) p, FALSE);
@@ -542,7 +597,7 @@ void app_nav_rmt_convert_pc_speaker(void) @@ -542,7 +597,7 @@ void app_nav_rmt_convert_pc_speaker(void)
542 #endif 597 #endif
543 598
544 599
545 - #if 0//def USB_SPEAKER_AUTO_DETECT 600 + #ifdef USB_SPEAKER_AUTO_DETECT
546 if (!PC_USB_DETECT == USB_DEVICE_CONNECT) 601 if (!PC_USB_DETECT == USB_DEVICE_CONNECT)
547 #endif 602 #endif
548 { 603 {
@@ -678,8 +733,8 @@ U32 app_cmd_usbIsoOut_PUT_DATA(U8 *buffer, U32 translen) @@ -678,8 +733,8 @@ U32 app_cmd_usbIsoOut_PUT_DATA(U8 *buffer, U32 translen)
678 //if (dlen >= EX_AUDIO_STREAM_THRESHOLD_FOR_USB_DEV) 733 //if (dlen >= EX_AUDIO_STREAM_THRESHOLD_FOR_USB_DEV)
679 { 734 {
680 //daudio_SetFBSamplerateCorrection(0); 735 //daudio_SetFBSamplerateCorrection(0);
681 - DBG_Printf("start usb dev dec\n\r");  
682 - uDecSend(DECODE_FRAME,TRUE); 736 + DBG_iPrintf("usbDev dec start\n\r");
  737 + uDecSend(DECODE_FRAME, TRUE);
683 app_main_data.playing_stream_status = STREAM_MEDIA; 738 app_main_data.playing_stream_status = STREAM_MEDIA;
684 } 739 }
685 } 740 }
@@ -763,5 +818,129 @@ U32 app_cmd_usbHidOut_PUT_DATA(U8 *buffer, U32 translen) @@ -763,5 +818,129 @@ U32 app_cmd_usbHidOut_PUT_DATA(U8 *buffer, U32 translen)
763 return (size == translen ); 818 return (size == translen );
764 } 819 }
765 820
  821 +
  822 +#ifdef HIDFUNC
  823 +
  824 +extern const APP_NAV_KEY APP_NAV_PC_SPEAKER_KEY [];
  825 +
  826 +int g_submitIntInKup( void ) //HID Input, called by UI
  827 +{
  828 + DBG_Printf("%s\n\r", __func__);
  829 + int ret = 0, len = 3;//pipe->maxpkt; //3 bytes for consumer INPUT
  830 +
  831 + if (usbdev_featureconf.HIDKEYEnable)
  832 + {
  833 + hidBuffer[0] = 0x01; ////Report ID
  834 + hidBuffer[1] = 0; //consumer key up
  835 + hidBuffer[2] = 0; //consumer key up
  836 +
  837 + ret = HIDkeyIN_Buf(hidBuffer, len);
  838 + DBG_USBDev_Printf("dstk_transfer ret:0x%x\n\r", ret);
  839 + }
  840 +
  841 + return ret;
  842 +}
  843 +
  844 +void _dhid_submitIntIn_finished_callback(void);
  845 +
  846 +int g_submitIntInKdown( void ) //HID Input, called by UI
  847 +{
  848 + U16 keyval = key_process_envs.processing_key_id;
  849 + int ret, len;
  850 +
  851 + DBG_Printf("%s: 0x%x\n\r", __func__, keyval);
  852 +
  853 + if (usbdev_featureconf.HIDKEYEnable)
  854 + {
  855 + len = 3;//pipe->maxpkt; //8 bytes for keyboard INPUT
  856 + hidBuffer[0] = 0x01; ////Report ID? bSize=1 byte
  857 +
  858 + if (keyval== APP_KEY_PLUS)
  859 + {
  860 + hidBuffer[1] = enHUTCONSUMER_VOLUP;//(U8)HIDKeycodes[0]; //key down, Vol+
  861 + }
  862 + else if (keyval== APP_KEY_MINUS)
  863 + {
  864 + hidBuffer[1] = enHUTCONSUMER_VOLDOWN;//(U8)HIDKeycodes[1]; //key down, Vol-
  865 + }
  866 +
  867 + else if (keyval == APP_KEY_PLAY)
  868 + {
  869 + #if 1
  870 + hidBuffer[1] = enHUTCONSUMER_PLAY;//(U8)HIDKeycodes[1]; //key down, PLAY
  871 + #else
  872 + hidBuffer[1] = enHUTTELEPHONY_HOOK;//(U8)HIDKeycodes[1]; //key down, Hook
  873 + #endif
  874 + }
  875 + else if (keyval == APP_KEY_STOP)
  876 + {
  877 + #if 1
  878 + hidBuffer[1] = enHUTCONSUMER_STOP;//(U8)HIDKeycodes[1]; //key down, STOP
  879 + #else
  880 + hidBuffer[1] = enHUTTELEPHONY_DROP;//(U8)HIDKeycodes[1]; //key down, Drop
  881 + #endif
  882 + }
  883 +
  884 + else if (keyval == APP_KEY_SKIPF)
  885 + {
  886 + #if 1
  887 + hidBuffer[1] = enHUTCONSUMER_NEXT;//(U8)HIDKeycodes[1]; //key down, Next
  888 + #else
  889 + hidBuffer[1] = enHUTCONSUMER_FF;//(U8)HIDKeycodes[1]; //key down, FF
  890 + #endif
  891 + }
  892 + else if (keyval == APP_KEY_SKIPB)
  893 + {
  894 + #if 1
  895 + hidBuffer[1] = enHUTCONSUMER_NEXT;//(U8)HIDKeycodes[1]; //key down, Prev
  896 + #else
  897 + hidBuffer[1] = enHUTCONSUMER_RW;//(U8)HIDKeycodes[1]; //key down, RW
  898 + #endif
  899 + }
  900 +
  901 + else if (keyval == APP_KEY_EQ)
  902 + {
  903 + hidBuffer[1] = 0x04;//(U8)HIDKeycodes[1]; //key down, Mute
  904 + }
  905 +
  906 + hidBuffer[2] = 0x00;
  907 + ret = HIDkeyIN_Buf(hidBuffer, len);
  908 + }
  909 + else
  910 + {
  911 + memset(hidBuffer, 0, sizeof(hidBuffer));
  912 + hidBuffer[1] = (keyval & 0xff00)>>8;
  913 + hidBuffer[2] = (keyval & 0x00ff);
  914 +
  915 + ret = HIDdataIN_Buf(hidBuffer, 4);
  916 + }
  917 +
  918 + DBG_USBDev_Printf("dstk_transfer ret:%x\n\r", ret);
  919 +
  920 + return ret;
  921 +}
  922 +#endif
  923 +
  924 +
  925 +int isrc_audioZeroCheck( U32 *data, int size ) __INTERNAL_RAM_TEXT;
  926 +int isrc_audioZeroCheck( U32 *data, int size )
  927 +{
  928 + U32 tmp;
  929 + U32 i;
  930 +
  931 + tmp = 1;
  932 +
  933 + for( i=0; i<size; i++ )
  934 + {
  935 + if( data[i] != 0 )
  936 + {
  937 + tmp = 0;
  938 + break;
  939 + }
  940 + }
  941 +
  942 + return tmp;
  943 +}
  944 +
766 #endif //(defined USB_SPEAKER && defined USB_DEV_ENABLE) 945 #endif //(defined USB_SPEAKER && defined USB_DEV_ENABLE)
767 946
@@ -13,6 +13,8 @@ @@ -13,6 +13,8 @@
13 13
14 #include "mem_reloc.h" 14 #include "mem_reloc.h"
15 15
  16 +#include "hw_pll.h"
  17 +
16 #include "fifo.h" 18 #include "fifo.h"
17 19
18 #include "otg.h" 20 #include "otg.h"
@@ -25,7 +27,7 @@ @@ -25,7 +27,7 @@
25 #include "dcd.h" 27 #include "dcd.h"
26 #include "daudio.h" 28 #include "daudio.h"
27 #include "denumAudio.h" 29 #include "denumAudio.h"
28 -#include "optek_link.h" 30 +
29 31
30 //#define DISABLE_VOLUME_CTL 32 //#define DISABLE_VOLUME_CTL
31 33
@@ -38,6 +40,7 @@ typedef struct { @@ -38,6 +40,7 @@ typedef struct {
38 40
39 DENUM_DATA denumData __USB_DEV_BSS; 41 DENUM_DATA denumData __USB_DEV_BSS;
40 42
  43 +
41 #ifdef ADC20 44 #ifdef ADC20
42 //JJ+ for CXD disbale 45 //JJ+ for CXD disbale
43 #define CXDDISABLE 46 #define CXDDISABLE
@@ -100,7 +103,7 @@ DENUM_DATA denumData __USB_DEV_BSS; @@ -100,7 +103,7 @@ DENUM_DATA denumData __USB_DEV_BSS;
100 0x02, 103 0x02,
101 0x00 104 0x00
102 }; 105 };
103 -#endif 106 +#endif
104 107
105 #if 0 108 #if 0
106 // Test for multi list of sample freqs 109 // Test for multi list of sample freqs
@@ -219,85 +222,175 @@ U8 HID_Ready=0; @@ -219,85 +222,175 @@ U8 HID_Ready=0;
219 #ifdef HIDFUNC 222 #ifdef HIDFUNC
220 //USB报告描述符的定义 223 //USB报告描述符的定义
221 static const U8 HIDReportDescriptor[]= 224 static const U8 HIDReportDescriptor[]=
  225 +
222 #ifndef HIDKEY 226 #ifndef HIDKEY
223 { 227 {
  228 + //USAGE_PAGE(Generic Desktop Controls)
224 //Specific protocol for Youchang HID data In/Out! 229 //Specific protocol for Youchang HID data In/Out!
225 -0x05,0x01, //HUT 3, 0x01, USAGE_PAGE (Generic Desktop) 230 +0x05,0x01, //HUT3, 0x01, USAGE_PAGE (Generic Desktop)
226 0x09,0x00, //HUT4, Usage Undefined 231 0x09,0x00, //HUT4, Usage Undefined
227 232
228 -0xA1,0x01, 233 +0xA1,0x01, //COLLECTION(Application)
  234 +
  235 + //USAGE(ID):USAGE(Rerserved)
229 0x09,0x03, //HUT4 Usage reserved 236 0x09,0x03, //HUT4 Usage reserved
230 0x15,0x00, //L Min 1 byte 237 0x15,0x00, //L Min 1 byte
231 0x26,0x00,0xFF, //L Max 2 bytes 238 0x26,0x00,0xFF, //L Max 2 bytes
232 239
233 - 0x75,0x08, //Report size 1 byte :8bits  
234 - 0x95,0x40, //Report Count 1 byte: 1. trans max len, 64x8bits  
235 - 0x81,0x02, //Input-Constant 1 byte : Variable 240 + //REPORT_SIZE(0x08): 8 bits
  241 + 0x75,0x08, //Report size : 8bits
  242 + //REPORT_COUNT(0x04):0x04 times
  243 +// 0x95,0x04, //Report Count 4 times: trans max len, 4xREPORT_SIZE(8) bits
  244 + //REPORT_COUNT(0x40):0x040 times
  245 + 0x95,0x40, //Report Count 64 times: trans max len, 64xREPORT_SIZE(8) bits
  246 + //INPUT(Data, Var, Abs)
  247 + 0x81,0x02, //Input Data 1 byte : Variable
236 248
237 - 249 + //USAGE(ID):USAGE(Joystick)
238 0x09,0x04, //HUT4 Usage Joystick 250 0x09,0x04, //HUT4 Usage Joystick
239 0x15,0x00, //L Min 1 byte 251 0x15,0x00, //L Min 1 byte
240 0x26,0x00,0xFF, //L Max 2 bytes 252 0x26,0x00,0xFF, //L Max 2 bytes
241 253
  254 + //REPORT_SIZE(0x08):8 bits
242 0x75,0x08, //Report size :8bits 255 0x75,0x08, //Report size :8bits
243 - 0x95,0x40, //Report Count: 1 byte, 64x8bits 256 + //REPORT_COUNT(0x04):0x04 times
  257 +// 0x95,0x04, //Report Count: 4 times, 4xREPORT_SIZE(8) bits
  258 + //REPORT_COUNT(0x40):0x040 times
  259 + 0x95,0x40, //Report Count: 64 times, 64xREPORT_SIZE(8) bits
  260 + //OUTPUT(Data, Var, Abs)
244 0x91,0x02, //Output Data 1 byte : Variable 261 0x91,0x02, //Output Data 1 byte : Variable
  262 +
  263 + //END COLLECTION
245 0xC0 264 0xC0
246 }; 265 };
  266 +
247 #else 267 #else
248 - //for HID Consumer device 268 +
  269 +#if 0
  270 +{
  271 + // Report ID 2: Advanced buttons
  272 + 0x05, 0x0B, // Usage Page (Telephony Devices)
  273 + 0x09, 0x01, // Usage (Phone)
  274 + 0xA1, 0x01, // Collection (Application)
  275 + 0x85, 0x01, // Report Id (1)
  276 + 0x15, 0x00, // Logical minimum (0)
  277 + 0x25, 0x01, // Logical maximum (1)
  278 + 0x75, 0x01, // Report Size (1)
  279 + 0x95, 0x01, // Report Count (1)
  280 +
  281 + 0x09, 0x20, // Usage (HookSwitch)
  282 + 0x81, 0x02, // Input (Data,Value,Relative,Bit Field)
  283 +
  284 +// 0x09, 0x23, // Usage (Hold)
  285 + 0x09, 0x26, // HUT14, USAGE (Drop) bit 9 = 0x02
  286 + 0x81, 0x02, // Input (Data,Value,Relative,Bit Field)
  287 +
  288 + 0x09, 0x2F, // Usage (PhoneMute)
  289 + 0x81, 0x02, // Input (Data,Value,Relative,Bit Field)
  290 +
  291 +
  292 +
  293 + 0x09, 0x06, // Usage (Telephony Key Pad)
  294 + 0x81, 0x02, // Input (Data,Value,Relative,Bit Field)
  295 +
  296 + 0x09, 0x50, // Usage (SpeedDial)
  297 + 0x81, 0x02, // Input (Data,Value,Relative,Bit Field)
  298 +
  299 + 0x09, 0x52, // Usage (RecallNumber)
  300 + 0x81, 0x02, // Input (Data,Value,Relative,Bit Field)
  301 +
  302 + 0x09, 0x51, // Usage (StoreNumber)
  303 + 0x81, 0x02, // Input (Data,Value,Relative,Bit Field)
  304 +
  305 + 0x09, 0x53, // Usage (PhoneDirectory)
  306 + 0x81, 0x02, // Input (Data,Value,Relative,Bit Field)
  307 +
  308 + //END COLLECTION
  309 + 0xC0 // End Collection
  310 +};
  311 +
  312 +#else
  313 +
  314 +//HID Report Descriptor in USB_Audio Device Class for Basic Audio Devices_V1.0.pdf
  315 +//Table 8-4: Recommended Report Descriptor for Report (ID1)
  316 +
  317 +//for HID Telephony Device (0x0B)
249 { 318 {
250 - 0x05, 0x0C, //HUT3, USAGE Pages (Consumer) ++++++++++++++++++++++++++++++++ 319 + //Table 1: Usage Pages Summary in HUT
  320 + //USAGE_PAGE(Consumer Devices)
  321 + 0x05, 0x0C, //HUT3, USAGE Pages (Consumer) ++++++++++++++++++++++++++++++++
  322 + //Table 17: Consumer Usage Page in HUT
  323 + //USAGE(ID): USAGE(0x01): USAGE(Comsumer Control)
251 0x09, 0x01, //USAGE HUT15 (Comsumer Control) 324 0x09, 0x01, //USAGE HUT15 (Comsumer Control)
252 - 0xA1, 0x01, //COLLECTION  
253 - 0x85, 0x01, //Report ID  
254 - 0x15, 0x00, //Logical Minimum, 1 byte  
255 - 0x25, 0x01, //Logical Maximum, 1 byte  
256 -  
257 - 0x75, 0x01, //HID 6.2.2.7 Global Items, Report Size, 1 bit !Global items!  
258 - 0x95, 0x01, //6.2.2.7 Global Items, Report Count, 1x1bit !Global items! 1x1 bit ?????? Not 8+3 = 0x0b ? 325 + 0xA1, 0x01, //COLLECTION(Application)
  326 + 0x85, 0x01, //Report ID(0x01)
  327 + 0x15, 0x00, //Logical Minimum(0), 1 byte
  328 + 0x25, 0x01, //Logical Maximum(1), 1 byte
259 329
260 - 0x09, 0xE9, //HUT15 USAGE (Vol Inc) bit 0 = 0x01 ++++++++++++++++++++++++++++++++Byte 1  
261 - 0x81, 0x02, // Input (Array0 Var1) Variable ...... belows are same, 1x1 bit ! 330 + //REPORT_SIZE(0x01):1 bit
  331 + 0x75, 0x01, //HID 6.2.2.7 Global Items, Report Size, 1 bit !Global items!
  332 + //REPORT_COUNT(0x01):1 times
  333 + 0x95, 0x01, //6.2.2.7 Global Items, Report Count, 1x1bit !Global items! 1x1 bit ?????? Not 8+3 = 0x0b ?
  334 +
  335 + //USAGE(ID): USAGE(0xE9): USAGE(Volume Up)
  336 + 0x09, 0xE9, //HUT15 USAGE (Vol Inc) bit 0 = 0x01 ++++++++++++++++++++++++++++++++Byte 1
  337 + 0x81, 0x02, // Input (Data, Var, Abs) ...... belows are same, 1x1 bit !
  338 +
  339 + //USAGE(ID): USAGE(0xEA): USAGE(Volume Down)
  340 + 0x09, 0xEA, //HUT15 USAGE (Vol Dec) bit 1 = 0x02
  341 + 0x81, 0x02, // Input(Data, Var, Abs), Var:Variable, Abs: Absolute
262 342
263 - 0x09, 0xEA, //HUT15 USAGE (Vol Dec) bit 1 = 0x02  
264 - 0x81, 0x02, // Input 343 + 0x09, 0xCD, //USAGE (Play/Pause)bit 2 = 0x04
  344 + 0x81, 0x02, // Input(Data, Var, Abs)
265 345
266 - 0x09, 0xCD, //USAGE (Play/Pause)bit 2  
267 - 0x81, 0x02, // Input 346 + 0x09, 0xB5, //USAGE (Scan Next) bit 3 = 0x08
  347 + 0x81, 0x02, // Input(Data, Var, Abs)
268 348
269 - 0x09, 0xB5, //USAGE (Scan Next) bit 3  
270 - 0x81, 0x02, // Input 349 + 0x09, 0xB6, //USAGE (Scan Prev) bit 4 = 0x10
  350 + 0x81, 0x02, // Input(Data, Var, Abs)
271 351
272 - 0x09, 0xB6, //USAGE (Scan Prev) bit 4  
273 - 0x81, 0x02, // Input 352 + 0x09, 0xB7, //USAGE (Stop) bit 5 = 0x20
  353 + 0x81, 0x02, // Input(Data, Var, Abs)
274 354
275 - 0x09, 0xB7, //USAGE (Stop) bit 5 = 0x20  
276 - 0x81, 0x02, // Input 355 + 0x09, 0xB5, //USAGE (FF) bit 6 = 0x40
  356 + 0x81, 0x02, // Input(Data, Var, Abs)
277 357
278 - 0x09, 0xB3, //USAGE (FF) bit 6  
279 - 0x81, 0x02, // Input 358 + 0x09, 0xB6, //USAGE (Rewind) bit 7 = 0x80
  359 + 0x81, 0x02, // Input(Data, Var, Abs)
  360 +
  361 + //USAGE_PAGE(Telephony Devices)
  362 + 0x05, 0x0B, //HUT3, Usage Page (Telephony Device) ++++++++++++++++++++++++++++++++Byte 2
  363 + #if 0
  364 + 0x09, 0x24, //HUT14, USAGE (Redial) bit 9
  365 + 0x81, 0x02, // Input
  366 + #endif
  367 +
  368 + //USAGE(ID): USAGE(0x20): USAGE(Hook Switch)
  369 + 0x09, 0x20, //HUT14, USAGE (Hook) bit 8 = 0x01
  370 + 0x81, 0x02, // Input(Data, Var, Abs)
280 371
281 - 0x09, 0xB4, //USAGE (Rewind) bit 7  
282 - 0x81, 0x02, // Input  
283 -  
284 - 0x05, 0x0B, //HUT3, Usage Page (Telephony Device) ++++++++++++++++++++++++++++++++Byte 2  
285 - 0x09, 0x24, //HUT14, USAGE (Redial) bit 8  
286 - 0x81, 0x02, // Input 372 +// 0x09, 0x24, //HUT14, USAGE (Redial) bit 9 = 0x02
  373 + 0x09, 0x26, //HUT14, USAGE (Drop) bit 9 = 0x02
  374 + 0x81, 0x02, // Input(Data, Var, Abs)
287 375
288 - 0x09, 0x20, //HUT14, USAGE (Hook) bit 9  
289 - 0x81, 0x02, // Input 376 + //USAGE(ID): USAGE(0x2F): USAGE(Phone Mute)
  377 + 0x09, 0x2F, //HUT14, USAGE (Phone Mute) bit a = 0x04
290 378
291 - 0x09, 0x2F, //HUT14, USAGE (Phone Mute) bit a = 0x0400  
292 - 0x81, 0x06, // Input (Array0 Var1 Abs0 Rela1)  
293 -  
294 - 0x95, 0x05, //Report Count 5x? //padding 5x1 bit  
295 - 0x81, 0x01, // Input (Array0 Var1) Constant 379 + //Input (Data, Var, Rel): (Bit0 {Data(0)|Constant(1)}; Bit1 {Array(0)|Variable(1)}; Bit2 {Absolute(0)|Relative(1)}
  380 + 0x81, 0x06, //Input (Data, Var, Rel)
  381 +
  382 + //REPORT_COUNT(5)
  383 + 0x95, 0x05, //Report Count 5 times, Pad Report to 5x1 bits
  384 + 0x81, 0x01, // Input(Const, Array, Abs))
296 385
297 - 0xC0 386 + //END COLLECTION
  387 + 0xC0
298 }; 388 };
  389 +#endif
  390 +
299 #endif //HIDKEY 391 #endif //HIDKEY
300 -/* //for HID keyboard 392 +/*
  393 +//for HID keyboard
301 { 394 {
302 //每行开始的第一字节为该条目的前缀,前缀的格式为: 395 //每行开始的第一字节为该条目的前缀,前缀的格式为:
303 //D7~D4:bTag。D3~D2:bType;D1~D0:bSize。以下分别对每个条目注释。 396 //D7~D4:bTag。D3~D2:bType;D1~D0:bSize。以下分别对每个条目注释。
@@ -528,12 +621,13 @@ U8 QdeviceDescriptor[USB_DEVICE_DESCRIPTOR_LENGTH] = { //USB20 9.6.1 @@ -528,12 +621,13 @@ U8 QdeviceDescriptor[USB_DEVICE_DESCRIPTOR_LENGTH] = { //USB20 9.6.1
528 #define AUDIO_FEATURE_UNIT_LEN 0x00 621 #define AUDIO_FEATURE_UNIT_LEN 0x00
529 #else 622 #else
530 623
531 - #ifdef VOLUME_MASTER_CHAN_ONLY 624 + #ifdef VOLUME_MASTER_CHAN_ONLY
532 #ifdef ADC20 625 #ifdef ADC20
533 - #define AUDIO_FEATURE_UNIT_LEN 0x12 626 + #define AUDIO_FEATURE_UNIT_LEN 0x12
534 #else 627 #else
535 - #define AUDIO_FEATURE_UNIT_LEN 0x0A  
536 - //#define AUDIO_FEATURE_UNIT_LEN 0x09 628 + #define AUDIO_FEATURE_UNIT_LEN 0x0A
  629 + //#define AUDIO_FEATURE_UNIT_LEN 0x0D
  630 + //#define AUDIO_FEATURE_UNIT_LEN 0x09
537 #endif 631 #endif
538 #else 632 #else
539 #define AUDIO_FEATURE_UNIT_LEN 0x0d 633 #define AUDIO_FEATURE_UNIT_LEN 0x0d
@@ -597,16 +691,27 @@ U8 QdeviceDescriptor[USB_DEVICE_DESCRIPTOR_LENGTH] = { //USB20 9.6.1 @@ -597,16 +691,27 @@ U8 QdeviceDescriptor[USB_DEVICE_DESCRIPTOR_LENGTH] = { //USB20 9.6.1
597 // AUDIO_CTL_INTF_TOTAL_LEN: 691 // AUDIO_CTL_INTF_TOTAL_LEN:
598 // AUDIO_AC_INT_ENDP_LEN: FB ep for ADC20 692 // AUDIO_AC_INT_ENDP_LEN: FB ep for ADC20
599 693
  694 +#ifdef HIDFUNC
  695 + #ifdef HIDKEY
  696 + #define HID_LEN (0x19)
  697 + #else
  698 + #define HID_LEN (0x19 + 0x7)
  699 + #endif
  700 +#else
  701 + #define HID_LEN (0x00)
  702 +#endif
  703 +
  704 +
600 #ifdef ONLYSpeakerCFG//JJ 0x6D 705 #ifdef ONLYSpeakerCFG//JJ 0x6D
601 706
602 #ifdef HIDFUNC 707 #ifdef HIDFUNC
603 #ifdef USBDEV_ISOIN_ASYNC 708 #ifdef USBDEV_ISOIN_ASYNC
604 //#ifndef HIDKEY 709 //#ifndef HIDKEY
605 #define DEV_CONFIGURATION_TOTAL_LEN (USB_CONFIGURATION_DESCRIPTOR_LENGTH + USB_IAD_LENGTH + \ 710 #define DEV_CONFIGURATION_TOTAL_LEN (USB_CONFIGURATION_DESCRIPTOR_LENGTH + USB_IAD_LENGTH + \
606 - AUDIO_CTL_INTF_TOTAL_LEN + AUDIO_STREAM_INTF_TOTAL_LEN + AUDIO_CLASS_STD_ENDP_LEN + AUDIO_AC_INT_ENDP_LEN + 0x19 + 0x7) 711 + AUDIO_CTL_INTF_TOTAL_LEN + AUDIO_STREAM_INTF_TOTAL_LEN + AUDIO_CLASS_STD_ENDP_LEN + AUDIO_AC_INT_ENDP_LEN + HID_LEN)
607 #else 712 #else
608 #define DEV_CONFIGURATION_TOTAL_LEN (USB_CONFIGURATION_DESCRIPTOR_LENGTH + USB_IAD_LENGTH + \ 713 #define DEV_CONFIGURATION_TOTAL_LEN (USB_CONFIGURATION_DESCRIPTOR_LENGTH + USB_IAD_LENGTH + \
609 - AUDIO_CTL_INTF_TOTAL_LEN + AUDIO_STREAM_INTF_TOTAL_LEN + AUDIO_AC_INT_ENDP_LEN + 0x19 + 0x7) 714 + AUDIO_CTL_INTF_TOTAL_LEN + AUDIO_STREAM_INTF_TOTAL_LEN + AUDIO_AC_INT_ENDP_LEN + HID_LEN)
610 #endif 715 #endif
611 #else 716 #else
612 #ifdef DFUFUNC 717 #ifdef DFUFUNC
@@ -624,10 +729,11 @@ U8 QdeviceDescriptor[USB_DEVICE_DESCRIPTOR_LENGTH] = { //USB20 9.6.1 @@ -624,10 +729,11 @@ U8 QdeviceDescriptor[USB_DEVICE_DESCRIPTOR_LENGTH] = { //USB20 9.6.1
624 #endif //HIDFUNC 729 #endif //HIDFUNC
625 730
626 #else //ONLYSpeakerCFG 731 #else //ONLYSpeakerCFG
  732 +
627 //9+48+52+52 = 109+52 = 161, 162, 9+79+52+52 = 192 (0xc0) for now, 0x19 Desc of HID [Here only ADC20] 733 //9+48+52+52 = 109+52 = 161, 162, 9+79+52+52 = 192 (0xc0) for now, 0x19 Desc of HID [Here only ADC20]
628 #ifdef HIDFUNC 734 #ifdef HIDFUNC
629 735
630 - #ifndef ONLYMicCFG 736 + #ifndef ONLYMicCFG
631 #ifndef SECOND_OUTEP 737 #ifndef SECOND_OUTEP
632 /* #define DEV_CONFIGURATION_TOTAL_LEN (USB_CONFIGURATION_DESCRIPTOR_LENGTH + USB_IAD_LENGTH + \ 738 /* #define DEV_CONFIGURATION_TOTAL_LEN (USB_CONFIGURATION_DESCRIPTOR_LENGTH + USB_IAD_LENGTH + \
633 AUDIO_CTL_INTF_TOTAL_LEN + AUDIO_STREAM_INTF_TOTAL_LEN + AUDIO_STREAM_INTF_TOTAL_LEN + AUDIO_AC_INT_ENDP_LEN + 0x19 + 0x7) 739 AUDIO_CTL_INTF_TOTAL_LEN + AUDIO_STREAM_INTF_TOTAL_LEN + AUDIO_STREAM_INTF_TOTAL_LEN + AUDIO_AC_INT_ENDP_LEN + 0x19 + 0x7)
@@ -636,26 +742,22 @@ U8 QdeviceDescriptor[USB_DEVICE_DESCRIPTOR_LENGTH] = { //USB20 9.6.1 @@ -636,26 +742,22 @@ U8 QdeviceDescriptor[USB_DEVICE_DESCRIPTOR_LENGTH] = { //USB20 9.6.1
636 AUDIO_CTL_INTF_TOTAL_LEN + AUDIO_STREAM_INTF_TOTAL_LEN + AUDIO_CLASS_STD_ENDP_LEN + AUDIO_STREAM_INTF_TOTAL_LEN + AUDIO_AC_INT_ENDP_LEN + 0x19 + 0x19) 742 AUDIO_CTL_INTF_TOTAL_LEN + AUDIO_STREAM_INTF_TOTAL_LEN + AUDIO_CLASS_STD_ENDP_LEN + AUDIO_STREAM_INTF_TOTAL_LEN + AUDIO_AC_INT_ENDP_LEN + 0x19 + 0x19)
637 */ 743 */
638 #ifdef USBDEV_ISOIN_ASYNC 744 #ifdef USBDEV_ISOIN_ASYNC
639 - #ifndef HIDKEY  
640 - #define DEV_CONFIGURATION_TOTAL_LEN (USB_CONFIGURATION_DESCRIPTOR_LENGTH + USB_IAD_LENGTH + \  
641 - AUDIO_CTL_INTF_TOTAL_LEN + AUDIO_STREAM_INTF_TOTAL_LEN + AUDIO_CLASS_STD_ENDP_LEN + AUDIO_STREAM_INTF_TOTAL_LEN + AUDIO_AC_INT_ENDP_LEN + 0x19 + 0x7)  
642 - #else  
643 #define DEV_CONFIGURATION_TOTAL_LEN (USB_CONFIGURATION_DESCRIPTOR_LENGTH + USB_IAD_LENGTH + \ 745 #define DEV_CONFIGURATION_TOTAL_LEN (USB_CONFIGURATION_DESCRIPTOR_LENGTH + USB_IAD_LENGTH + \
644 - AUDIO_CTL_INTF_TOTAL_LEN + AUDIO_STREAM_INTF_TOTAL_LEN + AUDIO_CLASS_STD_ENDP_LEN + AUDIO_STREAM_INTF_TOTAL_LEN + AUDIO_AC_INT_ENDP_LEN + 0x19)  
645 - #endif //HIDKEY 746 + AUDIO_CTL_INTF_TOTAL_LEN + AUDIO_STREAM_INTF_TOTAL_LEN + AUDIO_CLASS_STD_ENDP_LEN + AUDIO_STREAM_INTF_TOTAL_LEN + AUDIO_AC_INT_ENDP_LEN + HID_LEN)
646 #else //USBDEV_ISOIN_ASYNC 747 #else //USBDEV_ISOIN_ASYNC
647 #define DEV_CONFIGURATION_TOTAL_LEN (USB_CONFIGURATION_DESCRIPTOR_LENGTH + USB_IAD_LENGTH + \ 748 #define DEV_CONFIGURATION_TOTAL_LEN (USB_CONFIGURATION_DESCRIPTOR_LENGTH + USB_IAD_LENGTH + \
648 - AUDIO_CTL_INTF_TOTAL_LEN + AUDIO_STREAM_INTF_TOTAL_LEN + AUDIO_STREAM_INTF_TOTAL_LEN + AUDIO_AC_INT_ENDP_LEN + 0x19 + 0x7) 749 + AUDIO_CTL_INTF_TOTAL_LEN + AUDIO_STREAM_INTF_TOTAL_LEN + AUDIO_STREAM_INTF_TOTAL_LEN + AUDIO_AC_INT_ENDP_LEN + HID_LEN)
649 #endif //USBDEV_ISOIN_ASYNC 750 #endif //USBDEV_ISOIN_ASYNC
650 751
651 #endif //SECOND_OUTEP 752 #endif //SECOND_OUTEP
652 - #else 753 + #else
653 //No Asnyc, but with HID ! 754 //No Asnyc, but with HID !
654 #define DEV_CONFIGURATION_TOTAL_LEN (USB_CONFIGURATION_DESCRIPTOR_LENGTH + USB_IAD_LENGTH + \ 755 #define DEV_CONFIGURATION_TOTAL_LEN (USB_CONFIGURATION_DESCRIPTOR_LENGTH + USB_IAD_LENGTH + \
655 - AUDIO_CTL_INTF_TOTAL_LEN + AUDIO_STREAM_INTF_TOTAL_LEN + 0x19 + 0x7)  
656 - #endif //ONLYMicCFG 756 + AUDIO_CTL_INTF_TOTAL_LEN + AUDIO_STREAM_INTF_TOTAL_LEN + HID_LEN)
  757 + #endif //ONLYMicCFG
657 758
658 #else //no HIDFUNC 759 #else //no HIDFUNC
  760 +
659 #ifdef USBDEV_ISOIN_ASYNC 761 #ifdef USBDEV_ISOIN_ASYNC
660 762
661 #ifndef ONLYMicCFG 763 #ifndef ONLYMicCFG
@@ -690,6 +792,7 @@ U8 QdeviceDescriptor[USB_DEVICE_DESCRIPTOR_LENGTH] = { //USB20 9.6.1 @@ -690,6 +792,7 @@ U8 QdeviceDescriptor[USB_DEVICE_DESCRIPTOR_LENGTH] = { //USB20 9.6.1
690 #endif //USBDEV_ISOIN_ASYNC 792 #endif //USBDEV_ISOIN_ASYNC
691 793
692 #endif //HIDFUNC 794 #endif //HIDFUNC
  795 +
693 #endif //ONLYSpeakerCFG 796 #endif //ONLYSpeakerCFG
694 797
695 798
@@ -720,14 +823,29 @@ U8 QdeviceDescriptor[USB_DEVICE_DESCRIPTOR_LENGTH] = { //USB20 9.6.1 @@ -720,14 +823,29 @@ U8 QdeviceDescriptor[USB_DEVICE_DESCRIPTOR_LENGTH] = { //USB20 9.6.1
720 #define AUDIO_STRAM_NON_ZEROBAND_ALT_SET 1 823 #define AUDIO_STRAM_NON_ZEROBAND_ALT_SET 1
721 #define AUDIO_STRAM_NON_ZEROBAND_ALT_SET2 2 824 #define AUDIO_STRAM_NON_ZEROBAND_ALT_SET2 2
722 825
  826 +
723 //For DNUSB -- FU -- SPK 827 //For DNUSB -- FU -- SPK
724 -#define AUDIO_INPUT_TERM_ID 0x01  
725 -#define AUDIO_FEATURE_UNIT_ID 0x02  
726 -#define AUDIO_OUTPUT_TERM_ID 0x03 828 +//Input Terminal ID1 represents the AudioSreaming Interface
  829 +//that is used to stream the speaker data from the Host to Headset device
  830 +#define AUDIO_INPUT_TERM_ID 0x01
  831 +//The Output Pin of Input Terminal ID1 is connecte to the Input Pin 1 of Mixer Unit ID8
  832 +#define AUDIO_INPUT_MIXER_TERM_ID 0x08
  833 +//The Output Pin of Mixer Unit ID8 is connected to the Input Pin of Feature Unit ID2
  834 +#define AUDIO_FEATURE_UNIT_ID 0x02
  835 +//The Output Pin of Feature Unit ID2 is connected to the Input Pin of the Out Terminal ID3
  836 +//which presents the physical speaker(s)
  837 +#define AUDIO_OUTPUT_TERM_ID 0x03
  838 +
  839 +
727 //For MIC -- FU -- UPUSB 840 //For MIC -- FU -- UPUSB
  841 +//Input Terminal ID4 represents the phsical miccrophone
728 #define AUDIO_INPUTMIC_TERM_ID 0x04 842 #define AUDIO_INPUTMIC_TERM_ID 0x04
729 -//#define AUDIO_FEATUREMIC_UNIT_ID 0x05  
730 -#define AUDIO_OUTPUTMIC_TERM_ID 0x06 843 +//The Output Pin of Input Terminal ID4 is connecte to the Input Pin of Featture ID5
  844 +//#define AUDIO_FEATUREMIC_UNIT_ID 0x05
  845 +//The Output Pin of Feature Unit ID5 is connected to the Input Pin of the Out Terminal ID6,
  846 +//which represents the AudioStreaming Interface that is used to stream the microphone data to the Host
  847 +#define AUDIO_OUTPUTMIC_TERM_ID 0x06 //to host USB in
  848 +
731 849
732 #ifdef ADC20 850 #ifdef ADC20
733 #define AUDIO_CLASS_SPEC_VER 0x0200 851 #define AUDIO_CLASS_SPEC_VER 0x0200
@@ -752,10 +870,39 @@ U8 QdeviceDescriptor[USB_DEVICE_DESCRIPTOR_LENGTH] = { //USB20 9.6.1 @@ -752,10 +870,39 @@ U8 QdeviceDescriptor[USB_DEVICE_DESCRIPTOR_LENGTH] = { //USB20 9.6.1
752 //39, 40 for now 870 //39, 40 for now
753 871
754 872
755 -#define AUDIO_CHANNEL_CONFIG 0x03 //L + R 873 +/*
  874 +//below copied from USB Device Class Definition for Audio Devices 1.0
  875 +D0: Left Front (L)
  876 +D1: Right Front (R)
  877 +D2: Center Front (C)
  878 +D3: Low Frequency Enhancement (LFE)
  879 +D4: Left Surround (LS)
  880 +D5: Right Surround (RS)
  881 +D6: Left of Center (LC)
  882 +D7: Right of Center (RC)
  883 +D8: Surround (S)
  884 +D9: Side Left (SL)
  885 +D10: Side Right (SR)
  886 +D11: Top (T)
  887 +D15..12: Reserved
  888 +*/
  889 +#if (AUDIO_OUT_CHANNELS == 2)
  890 +#define AUDIO_CHANNEL_CONFIG 0x0003 //L + R
  891 +#define AUDIO_OUT_CHANNEL_CONFIG 0x0003 //L + R
  892 +#elif (AUDIO_OUT_CHANNELS == 6)
  893 +#define AUDIO_CHANNEL_CONFIG 0x003F //L R C (LFE) Ls Rs
  894 +#define AUDIO_OUT_CHANNEL_CONFIG 0x003F //L R C (LFE) Ls Rs
  895 +#else
  896 +#define AUDIO_CHANNEL_CONFIG 0x0003 //L + R
  897 +#define AUDIO_OUT_CHANNEL_CONFIG 0x0003 //L + R
  898 +#endif
756 899
757 900
  901 +#if 0
758 #define FEATURE_UNIT_CTL_SIZE 2 902 #define FEATURE_UNIT_CTL_SIZE 2
  903 +#else
  904 +#define FEATURE_UNIT_CTL_SIZE 1
  905 +#endif
759 906
760 #ifdef VOLUME_MASTER_CHAN_ONLY 907 #ifdef VOLUME_MASTER_CHAN_ONLY
761 #define FU_BMA_CTL0 0x03 //mute & vol 908 #define FU_BMA_CTL0 0x03 //mute & vol
@@ -871,28 +1018,36 @@ static const U8 fsUsbSpeaker_configDescriptor[] = { @@ -871,28 +1018,36 @@ static const U8 fsUsbSpeaker_configDescriptor[] = {
871 DESCRIPTOR_TYPE_CONFIGURATION, 1018 DESCRIPTOR_TYPE_CONFIGURATION,
872 BYTE_SPLIT1(DEV_CONFIGURATION_TOTAL_LEN),//0x09 remove FU of Mic, 0x19 Desc of HID 1019 BYTE_SPLIT1(DEV_CONFIGURATION_TOTAL_LEN),//0x09 remove FU of Mic, 0x19 Desc of HID
873 BYTE_SPLIT2(DEV_CONFIGURATION_TOTAL_LEN), 1020 BYTE_SPLIT2(DEV_CONFIGURATION_TOTAL_LEN),
874 -#ifdef HIDFUNC //(? HID ) + (? Speaker ) + (? Mic ) + (? DFU)  
875 - #ifndef ONLYSpeakerCFG//JJ  
876 - #ifndef ONLYMicCFG  
877 - 4,//INTERFACE_NUM, //now have 4 INTFs:INTF0, INTF1 for OUT, INTF2 for IN, INTF3/ITF4 for HID IN/OUT  
878 - #else //ONLYMicCFG  
879 - 3,//INTERFACE_NUM, //now have 3 INTFs:INTF0, INTF2 for IN, INTF3 for HID IN  
880 - #endif  
881 - #else //ONLYSpeakerCFG  
882 - 3,//INTERFACE_NUM, //now have 3 INTFs:INTF0, INTF1 for OUT, INTF3 for HID IN  
883 - #endif  
884 -#else //no HIDFUNC //(? Speaker ) + (? Mic ) + (? DFU)  
885 - #ifndef ONLYSpeakerCFG//JJ  
886 - #ifndef ONLYMicCFG  
887 - 3,//INTERFACE_NUM, //now have 3 INTFs:INTF0, INTF1 for OUT, INTF2 for IN  
888 - #else //ONLYMicCFG  
889 - 2,//INTERFACE_NUM, //now have 2 INTFs:INTF0, INTF2 for IN  
890 - #endif  
891 - #else //ONLYSpeakerCFG  
892 - 2,//INTERFACE_NUM, //now have 2 INTFs:INTF0, INTF1 for OUT  
893 - #endif 1021 +#ifdef HIDFUNC //(? HID ) + (? Speaker ) + (? Mic ) + (? DFU)
  1022 +
  1023 + #ifndef ONLYSpeakerCFG//JJ
  1024 + #ifndef ONLYMicCFG
  1025 + 4, //INTERFACE_NUM, //now have 4 INTFs:INTF0, INTF1 for OUT, INTF2 for IN, INTF3/ITF4 for HID IN/OUT
  1026 + #else
  1027 + 3, //INTERFACE_NUM, //now have 3 INTFs:INTF0, INTF2 for IN, INTF3 for HID IN
  1028 + #endif
  1029 +
  1030 + #else //ONLYSpeakerCFG
  1031 + 3, //INTERFACE_NUM, //now have 3 INTFs:INTF0, INTF1 for OUT, INTF3 for HID IN
  1032 + #endif
  1033 +
  1034 +#else //no HIDFUNC //(? Speaker ) + (? Mic ) + (? DFU)
  1035 +
  1036 + #ifndef ONLYSpeakerCFG//JJ
  1037 + #ifndef ONLYMicCFG
  1038 + 3, //INTERFACE_NUM, //now have 3 INTFs:INTF0, INTF1 for OUT, INTF2 for IN
  1039 + #else
  1040 + 2, //INTERFACE_NUM, //now have 2 INTFs:INTF0, INTF2 for IN
  1041 + #endif
  1042 +
  1043 + #else //ONLYSpeakerCFG
  1044 + 2, //INTERFACE_NUM, //now have 2 INTFs:INTF0, INTF1 for OUT
  1045 + #endif
  1046 +
894 #endif //HIDFUNC 1047 #endif //HIDFUNC
  1048 +
895 //3,//INTERFACE_NUM, //now have 2 INTFs:INTF0, INTF1 for OUT, DFU 1049 //3,//INTERFACE_NUM, //now have 2 INTFs:INTF0, INTF1 for OUT, DFU
  1050 +
896 CONFIG_VALUE, //argument to the SetConfiguration() request to select this configuration 1051 CONFIG_VALUE, //argument to the SetConfiguration() request to select this configuration
897 0x00, //Index of string descriptor describing this configuration 1052 0x00, //Index of string descriptor describing this configuration
898 CONFIGURATION_ATTRIBUTE, 1053 CONFIGURATION_ATTRIBUTE,
@@ -999,11 +1154,12 @@ CONFIGURATION_MAXPOWER, @@ -999,11 +1154,12 @@ CONFIGURATION_MAXPOWER,
999 1154
1000 #ifndef ONLYMicCFG 1155 #ifndef ONLYMicCFG
1001 //----- for down pipe Terms (PC -- SPEAKER) IT1 -- FU2 -- OT3 1156 //----- for down pipe Terms (PC -- SPEAKER) IT1 -- FU2 -- OT3
1002 - //input terminal audio10 Table 4-3: Input Terminal Descriptor 1157 + //Refer to USB Device Class Definition for Audio Devices 1.0.pdf
  1158 + //input terminal: audio 1.0: Table 4-3: Input Terminal Descriptor
1003 AUDIO_INPUT_TERMINAL_LEN, //l=0x0c, 0x11 for ADC20 1159 AUDIO_INPUT_TERMINAL_LEN, //l=0x0c, 0x11 for ADC20
1004 AUDIO_DESCRIPTOR_CS_INTERFACE, 1160 AUDIO_DESCRIPTOR_CS_INTERFACE,
1005 AUDIO_DESCRIPTOR_CS_SUB_AC_INPUT_TERMINAL, //30 1161 AUDIO_DESCRIPTOR_CS_SUB_AC_INPUT_TERMINAL, //30
1006 - AUDIO_INPUT_TERM_ID, //ID = 0x01 1162 + AUDIO_INPUT_TERM_ID, //ID = 0x01, 0x01 represents from Feature Unit ID1
1007 BYTE_SPLIT1(AUDIO_USB_TERM_USB_STREAM), 1163 BYTE_SPLIT1(AUDIO_USB_TERM_USB_STREAM),
1008 BYTE_SPLIT2(AUDIO_USB_TERM_USB_STREAM), 1164 BYTE_SPLIT2(AUDIO_USB_TERM_USB_STREAM),
1009 0x00, //jj- AUDIO_OUTPUT_TERM_ID, //output terminal ID = 0x03 assoc 1165 0x00, //jj- AUDIO_OUTPUT_TERM_ID, //output terminal ID = 0x03 assoc
@@ -1022,9 +1178,9 @@ CONFIGURATION_MAXPOWER, @@ -1022,9 +1178,9 @@ CONFIGURATION_MAXPOWER,
1022 BYTE_SPLIT1(0x0000), //bmControls 1178 BYTE_SPLIT1(0x0000), //bmControls
1023 BYTE_SPLIT2(0x0000), //bmControls 1179 BYTE_SPLIT2(0x0000), //bmControls
1024 #else 1180 #else
1025 - AUDIO_CHANNELS,  
1026 - BYTE_SPLIT1(AUDIO_CHANNEL_CONFIG),  
1027 - BYTE_SPLIT2(AUDIO_CHANNEL_CONFIG), 1181 + AUDIO_OUT_CHANNELS, //bNrChannels
  1182 + BYTE_SPLIT1(AUDIO_OUT_CHANNEL_CONFIG),
  1183 + BYTE_SPLIT2(AUDIO_OUT_CHANNEL_CONFIG),
1028 0x00, //Index of a string descriptor, first logic channel 1184 0x00, //Index of a string descriptor, first logic channel
1029 #endif 1185 #endif
1030 0x00, //Index of a string descriptor, IT 1186 0x00, //Index of a string descriptor, IT
@@ -1049,10 +1205,20 @@ CONFIGURATION_MAXPOWER, @@ -1049,10 +1205,20 @@ CONFIGURATION_MAXPOWER,
1049 BYTE_SPLIT3(0x00000000), 1205 BYTE_SPLIT3(0x00000000),
1050 BYTE_SPLIT4(0x00000000), 1206 BYTE_SPLIT4(0x00000000),
1051 #else 1207 #else
1052 - 1,/*FEATURE_UNIT_CTL_SIZE,*/  
1053 - 3,//bmaControls[0] 1208 + #if 1
  1209 + 1,//FEATURE_UNIT_CTL_SIZE, Size in bytes of an element of the bmaControls() array: n
  1210 + 0x03,//0x02,//bmaControls[0]
1054 0,//bmaControls[1] 1211 0,//bmaControls[1]
1055 0,//bmaControls[2] 1212 0,//bmaControls[2]
  1213 + #else
  1214 + 2,/*FEATURE_UNIT_CTL_SIZE,*/
  1215 + 0x03,//3,//bmaControls[0]
  1216 + 0x00,
  1217 + 0x00,//0,//bmaControls[1]
  1218 + 0x00,
  1219 + 0x00,//0,//bmaControls[2]
  1220 + 0x00,
  1221 + #endif
1056 /* BYTE_SPLIT1(FU_BMA_CTL0), 1222 /* BYTE_SPLIT1(FU_BMA_CTL0),
1057 BYTE_SPLIT2(FU_BMA_CTL0),*/ 1223 BYTE_SPLIT2(FU_BMA_CTL0),*/
1058 #ifndef VOLUME_MASTER_CHAN_ONLY 1224 #ifndef VOLUME_MASTER_CHAN_ONLY
@@ -1064,15 +1230,24 @@ CONFIGURATION_MAXPOWER, @@ -1064,15 +1230,24 @@ CONFIGURATION_MAXPOWER,
1064 #endif //ADC20 1230 #endif //ADC20
1065 0x00, //Index of a string descriptor, describing this Feature Unit 1231 0x00, //Index of a string descriptor, describing this Feature Unit
1066 1232
1067 - //output terminal audio10 Table 4-4: Output Terminal Descriptor 1233 +
  1234 + //Host USB Output Terminal Descriptor
  1235 + //output terminal audio10 Table 4-4: Output Terminal Descriptor
1068 AUDIO_OUTPUT_TERMINAL_LEN, //l=9, 0x0c for ADC20 1236 AUDIO_OUTPUT_TERMINAL_LEN, //l=9, 0x0c for ADC20
1069 AUDIO_DESCRIPTOR_CS_INTERFACE, 1237 AUDIO_DESCRIPTOR_CS_INTERFACE,
1070 AUDIO_DESCRIPTOR_CS_SUB_AC_OUTPUT_TERMINAL, 1238 AUDIO_DESCRIPTOR_CS_SUB_AC_OUTPUT_TERMINAL,
1071 AUDIO_OUTPUT_TERM_ID, //ID = 0x03 1239 AUDIO_OUTPUT_TERM_ID, //ID = 0x03
  1240 +#if 0
1072 BYTE_SPLIT1(AUDIO_OUTPUT_TERM_SPEAKER),//BYTE_SPLIT1(AUDIO_OUTPUT_TERM_DESKTOP_SPEAKER), 1241 BYTE_SPLIT1(AUDIO_OUTPUT_TERM_SPEAKER),//BYTE_SPLIT1(AUDIO_OUTPUT_TERM_DESKTOP_SPEAKER),
1073 BYTE_SPLIT2(AUDIO_OUTPUT_TERM_SPEAKER),//BYTE_SPLIT2(AUDIO_OUTPUT_TERM_DESKTOP_SPEAKER), 1242 BYTE_SPLIT2(AUDIO_OUTPUT_TERM_SPEAKER),//BYTE_SPLIT2(AUDIO_OUTPUT_TERM_DESKTOP_SPEAKER),
1074 - 0x00, //jj- AUDIO_INPUT_TERM_ID, //input terminal ID = 0x01 assoc  
1075 - AUDIO_FEATURE_UNIT_ID, //60 bSourceID this Term is connected 1243 +#else
  1244 + /*BYTE_SPLIT1(AUDIO_OUTPUT_TERM_SPEAKER),*/
  1245 + BYTE_SPLIT1(AUDIO_OUTPUT_TERM_DESKTOP_SPEAKER),
  1246 + /*BYTE_SPLIT2(AUDIO_OUTPUT_TERM_SPEAKER),*/
  1247 + BYTE_SPLIT2(AUDIO_OUTPUT_TERM_DESKTOP_SPEAKER),
  1248 +#endif
  1249 + 0x00, //bAssocTermal, no association
  1250 + AUDIO_FEATURE_UNIT_ID, //bSourceID, 0x02 represents from Feature Unit ID2
1076 #ifdef ADC20 1251 #ifdef ADC20
1077 #ifdef CXDDISABLE 1252 #ifdef CXDDISABLE
1078 AUDIO_CLKS_ID, //bCSourceID, ID of the Clock Entity to which this Output Terminal is connected. 1253 AUDIO_CLKS_ID, //bCSourceID, ID of the Clock Entity to which this Output Terminal is connected.
@@ -1085,13 +1260,15 @@ CONFIGURATION_MAXPOWER, @@ -1085,13 +1260,15 @@ CONFIGURATION_MAXPOWER,
1085 0x00, //Index of a string descriptor 1260 0x00, //Index of a string descriptor
1086 #endif //ONLYMicCFG 1261 #endif //ONLYMicCFG
1087 1262
  1263 +
1088 #ifndef ONLYSpeakerCFG//JJ 1264 #ifndef ONLYSpeakerCFG//JJ
1089 //----- for up pipe Terms (MIC -- HOST) IT4 -- -- OT6 1265 //----- for up pipe Terms (MIC -- HOST) IT4 -- -- OT6
  1266 + //Host USB Microphone Input Terminal Descriptor
1090 //input terminal --> MIC audio10 Table 4-3: Input Terminal Descriptor 1267 //input terminal --> MIC audio10 Table 4-3: Input Terminal Descriptor
1091 AUDIO_INPUT_TERMINAL_LEN, //l=0x0c, 0x11 for ADC20 1268 AUDIO_INPUT_TERMINAL_LEN, //l=0x0c, 0x11 for ADC20
1092 AUDIO_DESCRIPTOR_CS_INTERFACE, 1269 AUDIO_DESCRIPTOR_CS_INTERFACE,
1093 AUDIO_DESCRIPTOR_CS_SUB_AC_INPUT_TERMINAL, //30 1270 AUDIO_DESCRIPTOR_CS_SUB_AC_INPUT_TERMINAL, //30
1094 - AUDIO_INPUTMIC_TERM_ID, //ID = 4 1271 + AUDIO_INPUTMIC_TERM_ID, //ID = 4
1095 BYTE_SPLIT1(AUDIO_INPUT_TERM_MICROPHONE), //Terminal is Microphone. //JJ for mic 1272 BYTE_SPLIT1(AUDIO_INPUT_TERM_MICROPHONE), //Terminal is Microphone. //JJ for mic
1096 BYTE_SPLIT2(AUDIO_INPUT_TERM_MICROPHONE), 1273 BYTE_SPLIT2(AUDIO_INPUT_TERM_MICROPHONE),
1097 0x00, //jj- AUDIO_OUTPUTMIC_TERM_ID, //output terminal ID = 6 assoc 1274 0x00, //jj- AUDIO_OUTPUTMIC_TERM_ID, //output terminal ID = 6 assoc
@@ -1113,7 +1290,7 @@ CONFIGURATION_MAXPOWER, @@ -1113,7 +1290,7 @@ CONFIGURATION_MAXPOWER,
1113 AUDIO_CHANNELS, 1290 AUDIO_CHANNELS,
1114 BYTE_SPLIT1(AUDIO_CHANNEL_CONFIG), 1291 BYTE_SPLIT1(AUDIO_CHANNEL_CONFIG),
1115 BYTE_SPLIT2(AUDIO_CHANNEL_CONFIG), 1292 BYTE_SPLIT2(AUDIO_CHANNEL_CONFIG),
1116 - 0x00, //Index of a string descriptor, first logic channel 1293 + 0x00, //biChannelName, Unused. Shall be set to 0.
1117 #endif //ADC20 1294 #endif //ADC20
1118 0x00, //Index of a string descriptor, IT 1295 0x00, //Index of a string descriptor, IT
1119 1296
@@ -1220,7 +1397,7 @@ CONFIGURATION_MAXPOWER, @@ -1220,7 +1397,7 @@ CONFIGURATION_MAXPOWER,
1220 AUDIO_AS_GENERAL_INTF_LEN, //80, l=7 1397 AUDIO_AS_GENERAL_INTF_LEN, //80, l=7
1221 AUDIO_DESCRIPTOR_CS_INTERFACE, 1398 AUDIO_DESCRIPTOR_CS_INTERFACE,
1222 AUDIO_DESCRIPTOR_CS_SUB_AS_GENERAL, 1399 AUDIO_DESCRIPTOR_CS_SUB_AS_GENERAL,
1223 - AUDIO_INPUT_TERM_ID,//AUDIO_OUTPUT_TERM_ID, // Spk -- TERM ID=0x01!!! 1400 + AUDIO_INPUT_TERM_ID,//AUDIO_OUTPUT_TERM_ID, // Spk -- TERM ID=0x01!!! Terminal the endpoint connected.
1224 0x01, //? frame delay 1401 0x01, //? frame delay
1225 BYTE_SPLIT1(AUDIO_FORMAT_TYPE_I_PCM), 1402 BYTE_SPLIT1(AUDIO_FORMAT_TYPE_I_PCM),
1226 BYTE_SPLIT2(AUDIO_FORMAT_TYPE_I_PCM), 1403 BYTE_SPLIT2(AUDIO_FORMAT_TYPE_I_PCM),
@@ -1458,12 +1635,14 @@ CONFIGURATION_MAXPOWER, @@ -1458,12 +1635,14 @@ CONFIGURATION_MAXPOWER,
1458 AUDIO_DESCRIPTOR_CS_INTERFACE, 1635 AUDIO_DESCRIPTOR_CS_INTERFACE,
1459 AUDIO_DESCRIPTOR_CS_SUB_AS_GENERAL, 1636 AUDIO_DESCRIPTOR_CS_SUB_AS_GENERAL,
1460 AUDIO_OUTPUTMIC_TERM_ID, // mic -- TERM ID=0x06!!! Linked to USB Stream 1637 AUDIO_OUTPUTMIC_TERM_ID, // mic -- TERM ID=0x06!!! Linked to USB Stream
  1638 +//??? AUDIO_INPUTMIC_TERM_ID, //AUDIO_OUTPUTMIC_TERM_ID, // mic -- TERM ID=0x06!!! Linked to USB Stream
1461 0x01, //? frame delay 1639 0x01, //? frame delay
1462 BYTE_SPLIT1(AUDIO_FORMAT_TYPE_I_PCM), 1640 BYTE_SPLIT1(AUDIO_FORMAT_TYPE_I_PCM),
1463 BYTE_SPLIT2(AUDIO_FORMAT_TYPE_I_PCM), 1641 BYTE_SPLIT2(AUDIO_FORMAT_TYPE_I_PCM),
1464 #endif 1642 #endif
1465 1643
1466 - //type I format C.3.4.2.1.3 Type I Format Type Descriptor 1644 +
  1645 + //type I format C.3.4.2.1.3 Type I Format Type Descriptor
1467 #ifdef ADC20 1646 #ifdef ADC20
1468 AUDIO_TYPE_I_FORMAT_LEN, //l=11 = 8+(ns*3), 6 for ADC20 1647 AUDIO_TYPE_I_FORMAT_LEN, //l=11 = 8+(ns*3), 6 for ADC20
1469 AUDIO_DESCRIPTOR_CS_INTERFACE, //140 1648 AUDIO_DESCRIPTOR_CS_INTERFACE, //140
@@ -1533,6 +1712,7 @@ CONFIGURATION_MAXPOWER, @@ -1533,6 +1712,7 @@ CONFIGURATION_MAXPOWER,
1533 //? OUT or Set_Report() with Control Ep ? 1712 //? OUT or Set_Report() with Control Ep ?
1534 //IF 03 HID Intf Descriptor, Alt 0, 1 Ep <0x83>, 3 HID Class code, 0 No subclass Alt0 ------ 1713 //IF 03 HID Intf Descriptor, Alt 0, 1 Ep <0x83>, 3 HID Class code, 0 No subclass Alt0 ------
1535 //0x01 Boot Intf subc, 0x01 Keyboard protocol*/ 1714 //0x01 Boot Intf subc, 0x01 Keyboard protocol*/
  1715 + //HID Standard Interfance Descriptor
1536 #ifndef HIDKEY 1716 #ifndef HIDKEY
1537 //Keyboard { 0x09 0x04 0x03 0x00 0x02 0x03 0x01 0x01 0x00 } 2 Eps! Class code (HID code=3)! bInterfaceSubClass=1 Boot Interface subclass, bInterfaceProtocol=1 Keyboard 1717 //Keyboard { 0x09 0x04 0x03 0x00 0x02 0x03 0x01 0x01 0x00 } 2 Eps! Class code (HID code=3)! bInterfaceSubClass=1 Boot Interface subclass, bInterfaceProtocol=1 Keyboard
1538 USB_INTERFACE_DESCRIPTOR_LENGTH, //l=9 1718 USB_INTERFACE_DESCRIPTOR_LENGTH, //l=9
@@ -1543,16 +1723,19 @@ CONFIGURATION_MAXPOWER, @@ -1543,16 +1723,19 @@ CONFIGURATION_MAXPOWER,
1543 DESCRIPTOR_TYPE_INTERFACE, 0x03,0x00,0x01,0x03,0x00,0x00,0x00, //HID headset 1723 DESCRIPTOR_TYPE_INTERFACE, 0x03,0x00,0x01,0x03,0x00,0x00,0x00, //HID headset
1544 #endif 1724 #endif
1545 1725
  1726 + //HID Descriptor
1546 //DESCRIPTOR_TYPE_HID 0x21, HID Descriptor 1.11, 00 country, 01 Number of HID class descriptors, 1727 //DESCRIPTOR_TYPE_HID 0x21, HID Descriptor 1.11, 00 country, 01 Number of HID class descriptors,
1547 1728
1548 //HID Desc, 0111 Specification release number, 0x00country,01#of HID class descriptors, 22 Report descriptor type, 0017/45 Total length of Report descriptor 1729 //HID Desc, 0111 Specification release number, 0x00country,01#of HID class descriptors, 22 Report descriptor type, 0017/45 Total length of Report descriptor
1549 - 0x09,0x21,0x11,0x01,0x00,0x01,0x22,sizeof(HIDReportDescriptor),0x00,//0x0045, len of report desc  
1550 -  
1551 - //Ep Descriptor IN Ep <0x82> <0x81> addr, 03 Interrupt 0010 Maximum packet size 01/0A Interval  
1552 - 0x07,0x05,0x82,0x03,0x40,0x00,0x0A, 1730 + 0x09,AUDIO_DESCRIPTOR_CS_DEVICE,0x11,0x01,0x00,0x01,0x22,sizeof(HIDReportDescriptor),0x00,//0x0043, len of report desc
  1731 +
  1732 + //HID interrupt Endpoint Descriptor
  1733 + //Ep Descriptor IN Ep <0x82> addr, 0x03 Interrupt, Maximum packet size 0x0003/0A Interval
  1734 +// 0x07,0x05,0x82,0x03,0x40,0x00,0x0A,
  1735 + 0x07,0x05,0x82,0x03,0x03,0x00,0x0A,
1553 1736
1554 #ifndef HIDKEY 1737 #ifndef HIDKEY
1555 - //EP <0x85> addr, 02 Interrupt 0010 Maximum packet size 01 Interval 1738 + //Ep Descriptor Out Ep <0x02> addr, 0x03 Interrupt, Maximum packet size 0x0040/01 Interval
1556 0x07,0x05,0x02,0x03,0x40,0x00,0x01, 1739 0x07,0x05,0x02,0x03,0x40,0x00,0x01,
1557 #endif 1740 #endif
1558 1741
@@ -1782,7 +1965,7 @@ static int reqGetDescriptor(void) @@ -1782,7 +1965,7 @@ static int reqGetDescriptor(void)
1782 1965
1783 int ret; 1966 int ret;
1784 1967
1785 - //DBG_USBDev_Printf(" reqGetD %x,%x,%x", dtype, idx, len); 1968 + DBG_USBDev_Printf(" reqGetD %x,%x,%x", dtype, idx, len);
1786 1969
1787 switch( dtype ) 1970 switch( dtype )
1788 { 1971 {
@@ -1832,7 +2015,7 @@ static int reqGetDescriptor(void) @@ -1832,7 +2015,7 @@ static int reqGetDescriptor(void)
1832 len = StringDescriptor[idx][0]; 2015 len = StringDescriptor[idx][0];
1833 } 2016 }
1834 ret = dstk_transfer( pipe, TRUE, (U8*)StringDescriptor[idx], &len, NULL, TRUE ); 2017 ret = dstk_transfer( pipe, TRUE, (U8*)StringDescriptor[idx], &len, NULL, TRUE );
1835 - //DBG_USBDev_Printf("dstk_tr %d %x %x\n", idx, len, ret); 2018 + DBG_USBDev_Printf("dstk_tr %d %x %x\n", idx, len, ret);
1836 } 2019 }
1837 break; 2020 break;
1838 2021
@@ -1840,7 +2023,7 @@ static int reqGetDescriptor(void) @@ -1840,7 +2023,7 @@ static int reqGetDescriptor(void)
1840 #ifdef OTG_FORCE_FULL_SPEED 2023 #ifdef OTG_FORCE_FULL_SPEED
1841 ret = reqUnknown(); 2024 ret = reqUnknown();
1842 #else 2025 #else
1843 - //DBG_USBDev_Printf(" _DEVICE_QUALIFIER\n\r"); 2026 + DBG_USBDev_Printf(" _DEVICE_QUALIFIER\n\r");
1844 if( len > sizeof(QdeviceDescriptor) ) 2027 if( len > sizeof(QdeviceDescriptor) )
1845 { 2028 {
1846 len = sizeof(QdeviceDescriptor); 2029 len = sizeof(QdeviceDescriptor);
@@ -1853,13 +2036,13 @@ static int reqGetDescriptor(void) @@ -1853,13 +2036,13 @@ static int reqGetDescriptor(void)
1853 #ifdef OTG_FORCE_FULL_SPEED 2036 #ifdef OTG_FORCE_FULL_SPEED
1854 ret = reqUnknown(); 2037 ret = reqUnknown();
1855 #else 2038 #else
1856 - //DBG_USBDev_Printf(" _OTHER_SPEED_CONFIG\n\r"); 2039 + DBG_USBDev_Printf(" _OTHER_SPEED_CONFIG\n\r");
1857 #endif 2040 #endif
1858 break; 2041 break;
1859 2042
1860 #ifdef HIDFUNC 2043 #ifdef HIDFUNC
1861 case DESCRIPTOR_TYPE_REPORT://JJ+ HID Report Desc 2044 case DESCRIPTOR_TYPE_REPORT://JJ+ HID Report Desc
1862 - //DBG_USBDev_Printf(" _REPORT %x\n\r", len); 2045 + DBG_USBDev_Printf(" _REPORT %x\n\r", len);
1863 if( len > sizeof(HIDReportDescriptor) ) 2046 if( len > sizeof(HIDReportDescriptor) )
1864 { 2047 {
1865 len = sizeof(HIDReportDescriptor); 2048 len = sizeof(HIDReportDescriptor);
@@ -1948,8 +2131,17 @@ static int reqSetConfiguration(void) @@ -1948,8 +2131,17 @@ static int reqSetConfiguration(void)
1948 { 2131 {
1949 ret = reqUnknown(); 2132 ret = reqUnknown();
1950 } 2133 }
1951 -void clock_sync_init(void); 2134 +
  2135 + #ifdef CLOCK_SYNC_WITH_MASTER_ENABLE
1952 clock_sync_init(); 2136 clock_sync_init();
  2137 + #if 1
  2138 + //clock_sync_cnt = 10000/DMA_TX_INT_INTERVAL_MS_TIME; //zjl
  2139 + //clock_sync_cnt = (10000*1000)/DMA_TX_INT_INTERVAL_MS_TIME; //zjl
  2140 + #else
  2141 + //clock_sync_cnt = 25000/DMA_TX_INT_INTERVAL_MS_TIME;
  2142 + //clock_sync_cnt = (25000*1000)/DMA_TX_INT_INTERVAL_MS_TIME;
  2143 + #endif
  2144 + #endif
1953 2145
1954 return ret; 2146 return ret;
1955 } 2147 }
@@ -2246,7 +2438,7 @@ static int audioReq_getFUvol(void) @@ -2246,7 +2438,7 @@ static int audioReq_getFUvol(void)
2246 VOLUME_SETTING *pvol; 2438 VOLUME_SETTING *pvol;
2247 2439
2248 daudio_getVol( &pvol ); 2440 daudio_getVol( &pvol );
2249 - //DBG_USBDev_Printf(" %s:%x %x %x\n", __func__, req->bRequest, pvol->cur, pvol->res); 2441 + DBG_Printf(" %s:%x %x %x\n", __func__, req->bRequest, pvol->cur, pvol->res);
2250 2442
2251 switch(req->bRequest ) 2443 switch(req->bRequest )
2252 { 2444 {
@@ -2458,7 +2650,7 @@ static int HIDreq_GetReport(void) //send a HID report (length of packet) on EPx @@ -2458,7 +2650,7 @@ static int HIDreq_GetReport(void) //send a HID report (length of packet) on EPx
2458 DPIPE *pipe = dstk_getCtlPipe(); 2650 DPIPE *pipe = dstk_getCtlPipe();
2459 //dcd_ctlStatusStageAck(); 2651 //dcd_ctlStatusStageAck();
2460 2652
2461 - DBG_USBDev_Printf("%s:0x%x\n\r", __func__, len); 2653 + DBG_Printf("%s:0x%x\n\r", __func__, len);
2462 getReport_test[0] = (U8)req->wValue; 2654 getReport_test[0] = (U8)req->wValue;
2463 len = req->wLength; 2655 len = req->wLength;
2464 ret = dstk_transfer( pipe, TRUE, (U8*)getReport_test, &len, NULL, TRUE );//Input 2656 ret = dstk_transfer( pipe, TRUE, (U8*)getReport_test, &len, NULL, TRUE );//Input
@@ -2476,7 +2668,7 @@ static int HIDreq_SetReport(void) //send a HID report (length of packet) on EPx @@ -2476,7 +2668,7 @@ static int HIDreq_SetReport(void) //send a HID report (length of packet) on EPx
2476 DPIPE *pipe = dstk_getCtlPipe(); 2668 DPIPE *pipe = dstk_getCtlPipe();
2477 dcd_ctlStatusStageAck(); 2669 dcd_ctlStatusStageAck();
2478 2670
2479 - DBG_USBDev_Printf("%s:0x%x\n\r", __func__, len); 2671 + DBG_Printf("%s:0x%x\n\r", __func__, len);
2480 2672
2481 //len = req->wLength; 2673 //len = req->wLength;
2482 //ret = dstk_transfer( pipe, TRUE, (U8*)HIDReportDescriptor, &len, NULL, TRUE );//Input 2674 //ret = dstk_transfer( pipe, TRUE, (U8*)HIDReportDescriptor, &len, NULL, TRUE );//Input
@@ -2952,10 +3144,10 @@ int denum_process( IRP *irp) @@ -2952,10 +3144,10 @@ int denum_process( IRP *irp)
2952 3144
2953 void _dhid_submitIntIn_finished_callback(void) 3145 void _dhid_submitIntIn_finished_callback(void)
2954 { 3146 {
2955 -// DBG_Printf(" %s called!\n\r", __func__); 3147 + DBG_Printf("%s\n\r", __func__);
2956 } 3148 }
2957 3149
2958 - 3150 +#if 0
2959 int _dhid_submitIntIn(U8* pU8data) 3151 int _dhid_submitIntIn(U8* pU8data)
2960 { 3152 {
2961 DPIPE *pipe = dstk_getIntInPipe(); //or Control pipe ? 3153 DPIPE *pipe = dstk_getIntInPipe(); //or Control pipe ?
@@ -2967,5 +3159,6 @@ int _dhid_submitIntIn(U8* pU8data) @@ -2967,5 +3159,6 @@ int _dhid_submitIntIn(U8* pU8data)
2967 DBG_USBDev_Printf("%s ret:%x\n\r", __func__, ret); 3159 DBG_USBDev_Printf("%s ret:%x\n\r", __func__, ret);
2968 return ret; 3160 return ret;
2969 } 3161 }
  3162 +#endif
2970 3163
2971 #endif //#ifdef USB_DEV_ENABLE 3164 #endif //#ifdef USB_DEV_ENABLE
@@ -46,6 +46,7 @@ typedef enum { @@ -46,6 +46,7 @@ typedef enum {
46 //#define MAX_DEV_PIPES 3 46 //#define MAX_DEV_PIPES 3
47 //for HID 47 //for HID
48 #define MAX_DEV_PIPES 4 48 #define MAX_DEV_PIPES 4
  49 +
49 //0 is dummy, ep1 Host OUT (in INTERFACE 01) 50 //0 is dummy, ep1 Host OUT (in INTERFACE 01)
50 #define ENDP_NUM_ISO_OUT 1 51 #define ENDP_NUM_ISO_OUT 1
51 //JJ+, ep2 Host IN (in INTERFACE 02) 52 //JJ+, ep2 Host IN (in INTERFACE 02)
@@ -67,12 +68,15 @@ typedef enum { @@ -67,12 +68,15 @@ typedef enum {
67 #define DISO_MAX_PKT_SIZE 256 68 #define DISO_MAX_PKT_SIZE 256
68 #endif 69 #endif
69 */ 70 */
70 -#if 0 //for low BW cfg: such as Windows7 ...  
71 -#define DISO_MAX_PKT_SIZE 576 71 +#if 0 //for low BW cfg: such as Windows7 ...
  72 +#define DISO_MAX_PKT_SIZE 576
72 #else 73 #else
73 -//jj #define DISO_MAX_PKT_SIZE (96000*2*3/1000)  
74 -//#define DISO_MAX_PKT_SIZE (48000*2*3/1000)  
75 -#define DISO_MAX_PKT_SIZE (48000*2*2/1000) 74 +//96kHz, 24-bit
  75 +//#define DISO_MAX_PKT_SIZE (96000*2*3/1000)
  76 +//48kHz, 24-bit
  77 +#define DISO_MAX_PKT_SIZE (48000*2*3/1000)
  78 +//48kHz, 16-bit
  79 +//#define DISO_MAX_PKT_SIZE (48000*2*2/1000)
76 #endif 80 #endif
77 81
78 typedef struct _DUSB_DEVICE { 82 typedef struct _DUSB_DEVICE {
@@ -29,6 +29,7 @@ @@ -29,6 +29,7 @@
29 #include "Audio_dec.h" 29 #include "Audio_dec.h"
30 #include "optek_link.h" 30 #include "optek_link.h"
31 31
  32 +
32 U32 usbTransLen = 0; 33 U32 usbTransLen = 0;
33 U8 usbErr = 0; 34 U8 usbErr = 0;
34 35
@@ -54,10 +55,12 @@ int usb_devStart(enum_USB_DEVICE_STACK_ATTR attr) @@ -54,10 +55,12 @@ int usb_devStart(enum_USB_DEVICE_STACK_ATTR attr)
54 55
55 if (usbdev_start_flag == FALSE) 56 if (usbdev_start_flag == FALSE)
56 { 57 {
57 - DBG_USBDev_Printf ("usbSlave open\n\r"); 58 + DBG_Printf ("usbSlave open\n\r");
  59 + delayms(5);
58 60
59 - //tx_mutex_get( &mutex_usb, TX_WAIT_FOREVER );  
60 USB_MUTEX_LOCK; 61 USB_MUTEX_LOCK;
  62 + DBG_Printf ("usbSlave open 1\n\r");
  63 + delayms(5);
61 FILL_NORMAL_IRP( &irp, enIRPT_DEV_STACK, enIRP_TYPE_DEV_START, 0, 64 FILL_NORMAL_IRP( &irp, enIRPT_DEV_STACK, enIRP_TYPE_DEV_START, 0,
62 attr, 0, 0, enIRPR_SUBMIT, usbirpCompleteCallback ); //(PIRP)->param = attr !!! 65 attr, 0, 0, enIRPR_SUBMIT, usbirpCompleteCallback ); //(PIRP)->param = attr !!!
63 66
@@ -66,14 +69,13 @@ int usb_devStart(enum_USB_DEVICE_STACK_ATTR attr) @@ -66,14 +69,13 @@ int usb_devStart(enum_USB_DEVICE_STACK_ATTR attr)
66 DBG_assert( usbErr == enIRPR_SUCCESS ); 69 DBG_assert( usbErr == enIRPR_SUCCESS );
67 usbdev_start_flag = TRUE; 70 usbdev_start_flag = TRUE;
68 71
69 - //tx_mutex_put( &mutex_usb );  
70 USB_MUTEX_UNLOCK; 72 USB_MUTEX_UNLOCK;
71 - //DBG_USBDev_Printf ("usb_devStart::enIRP_TYPE_DEV_START is sent!\n\r"); 73 + DBG_Printf ("usbSlave open exit\n\r");
72 return ( usbErr == enIRPR_SUCCESS ); 74 return ( usbErr == enIRPR_SUCCESS );
73 } 75 }
74 else 76 else
75 { 77 {
76 - DBG_USBDev_Printf ("usbSlave is open\n\r"); 78 + DBG_Printf ("usbSlave opened\n\r");
77 } 79 }
78 } 80 }
79 81
@@ -83,25 +85,29 @@ int usb_devStop(void) @@ -83,25 +85,29 @@ int usb_devStop(void)
83 85
84 if (usbdev_start_flag == TRUE) 86 if (usbdev_start_flag == TRUE)
85 { 87 {
86 - DBG_USBDev_Printf ("usbSlave close\n\r"); 88 + DBG_Printf ("usbSlave close\n\r");
  89 + delayms(5);
87 90
88 - //tx_mutex_get( &mutex_usb, TX_WAIT_FOREVER );  
89 USB_MUTEX_LOCK; 91 USB_MUTEX_LOCK;
  92 + DBG_Printf ("usbSlave close 1\n\r");
  93 + delayms(5);
90 FILL_NORMAL_IRP( &irp, enIRPT_DEV_STACK, enIRP_TYPE_DEV_STOP, 0, 94 FILL_NORMAL_IRP( &irp, enIRPT_DEV_STACK, enIRP_TYPE_DEV_STOP, 0,
91 0, 0, 0, enIRPR_SUBMIT, usbirpCompleteCallback ); 95 0, 0, 0, enIRPR_SUBMIT, usbirpCompleteCallback );
92 96
  97 + DBG_Printf ("usbSlave close 2\n\r");
  98 + delayms(5);
93 usbmsg_sendIRP( &irp ); 99 usbmsg_sendIRP( &irp );
94 usbmsg_waitIRPcomplete(); 100 usbmsg_waitIRPcomplete();
95 DBG_assert( usbErr == enIRPR_SUCCESS ); 101 DBG_assert( usbErr == enIRPR_SUCCESS );
96 usbdev_start_flag = FALSE; 102 usbdev_start_flag = FALSE;
97 103
98 - //tx_mutex_put( &mutex_usb );  
99 USB_MUTEX_UNLOCK; 104 USB_MUTEX_UNLOCK;
  105 + DBG_Printf ("usbSlave close exit\n\r");
100 return ( usbErr == enIRPR_SUCCESS ); 106 return ( usbErr == enIRPR_SUCCESS );
101 } 107 }
102 else 108 else
103 { 109 {
104 - DBG_USBDev_Printf ("usbSlave is close\n\r"); 110 + DBG_USBDev_Printf ("usbSlave closed\n\r");
105 } 111 }
106 } 112 }
107 113
@@ -156,6 +162,7 @@ const U8 usbAudioStringProductDescriptor[STR_PRODUCT_LENGTH] = { @@ -156,6 +162,7 @@ const U8 usbAudioStringProductDescriptor[STR_PRODUCT_LENGTH] = {
156 'r',0 162 'r',0
157 }; 163 };
158 #endif 164 #endif
  165 +
159 const U8 usbAudioStringProductDescriptor[STR_PRODUCT_LENGTH] = { 166 const U8 usbAudioStringProductDescriptor[STR_PRODUCT_LENGTH] = {
160 STR_PRODUCT_LENGTH-8, 167 STR_PRODUCT_LENGTH-8,
161 DESCRIPTOR_TYPE_STRING, 168 DESCRIPTOR_TYPE_STRING,
@@ -343,7 +350,13 @@ For 48000 Sample Frequency: @@ -343,7 +350,13 @@ For 48000 Sample Frequency:
343 app_timer_usbdev_upstream_timeout_time_set(1000); 350 app_timer_usbdev_upstream_timeout_time_set(1000);
344 change_to_game_mode_cnt = 0; 351 change_to_game_mode_cnt = 0;
345 if (optek_link_mode == BC_SF48K_PT5MS) 352 if (optek_link_mode == BC_SF48K_PT5MS)
346 - app_change_mode_req(GAME_HEADPHONE_PT_5MS_LP,100,51); 353 + {
  354 + #ifdef UPSTREAM_SAMPLERATE_48k
  355 + app_change_mode_req(GAME_HEADPHONE_PT_5MS_LP,100,60);
  356 + #else
  357 + app_change_mode_req(GAME_HEADPHONE_PT_5MS_LP,100,50);
  358 + #endif
  359 + }
347 else// if (optek_link_mode == BC_SF48K_PT7P5MS) 360 else// if (optek_link_mode == BC_SF48K_PT7P5MS)
348 app_change_mode_req(GAME_HEADPHONE_PT7P5MS_T7R3E,150,75); 361 app_change_mode_req(GAME_HEADPHONE_PT7P5MS_T7R3E,150,75);
349 } 362 }
@@ -3,14 +3,16 @@ @@ -3,14 +3,16 @@
3 3
4 4
5 //#define USB_SPEAKER_DONGLE 5 //#define USB_SPEAKER_DONGLE
6 -#ifndef USB_SPEAKER_DONGLE  
7 -//#define USB_SPEAKER_AUTO_DETECT 6 +#if 0//ndef USB_SPEAKER_DONGLE
  7 +#define USB_SPEAKER_AUTO_DETECT
  8 +#else
  9 +#undef USB_SPEAKER_AUTO_DETECT
8 #endif 10 #endif
9 11
10 12
11 #if 1 13 #if 1
12 #define VENDOR_ID 0x0475 14 #define VENDOR_ID 0x0475
13 -#define PRODUCT_ID 0x1630 15 +#define PRODUCT_ID 0x1503
14 #else 16 #else
15 #define VENDOR_ID 0x0000 17 #define VENDOR_ID 0x0000
16 #define PRODUCT_ID 0x0005 18 #define PRODUCT_ID 0x0005
@@ -24,34 +26,40 @@ @@ -24,34 +26,40 @@
24 //JJ+ for USB audio class 2.0 26 //JJ+ for USB audio class 2.0
25 //#define ADC20 27 //#define ADC20
26 28
  29 +//JJ!!!+ for USB duplex both downwards and upwards pipe
  30 +//Normal undef below macros, i.e. both Speaker and Mic exist!
  31 +//#undef ONLYSpeakerCFG
  32 +//#undef ONLYMicCFG
  33 +
  34 +
27 35
28 -#define HIDFUNC 36 +//#define HIDFUNC
29 37
30 #ifdef HIDFUNC 38 #ifdef HIDFUNC
31 //for HID Consumer device! 39 //for HID Consumer device!
32 - //#define HIDKEY 40 + #define HIDKEY
33 #endif 41 #endif
34 42
35 -//2nd ISO In endp3In (#define ENDP_NUM_ISO_INFB 3) for USB Audio Device Async ! 43 +//2nd ISO IN Intf1/endp3In (#define ENDP_NUM_ISO_INFB 3) for USB Audio Device Async !
36 //#define USBDEV_ISOIN_ASYNC 44 //#define USBDEV_ISOIN_ASYNC
37 45
38 -//JJ!!!+ for USB duplex both downwards and upwards pipe  
39 -//only for intf, ep config  
40 -//obsolete #define USB_DEVICE_IN_OUT_CFG  
41 -  
42 -  
43 -//Test only function of USB Speaker  
44 -//#undef ONLYSpeakerCFG 46 +//Only function of USB Speaker
45 //#define ONLYSpeakerCFG 47 //#define ONLYSpeakerCFG
46 48
47 -//Test only function of USB Microphone 49 +//Only function of USB Microphone
48 //#define ONLYMicCFG 50 //#define ONLYMicCFG
49 51
50 //JJ+ for DFU 52 //JJ+ for DFU
51 //#define DFUFUNC 53 //#define DFUFUNC
52 54
  55 +
53 //Enable USB SOF Interrupt 56 //Enable USB SOF Interrupt
  57 +#define USB_DEV_LIB_V1P0P10
  58 +#ifdef USB_DEV_LIB_V1P0P10
  59 +//V1.0.10
54 #define SOFINTEN 60 #define SOFINTEN
  61 +#endif
  62 +
55 63
56 //Window XP/7 can support only up to 44.1, 48Khz and 16bits !!! 64 //Window XP/7 can support only up to 44.1, 48Khz and 16bits !!!
57 //#define USB_AUDIO_SRC_44100 65 //#define USB_AUDIO_SRC_44100
@@ -66,12 +74,13 @@ @@ -66,12 +74,13 @@
66 /* second USB Audio Out should be mandatory ! */ 74 /* second USB Audio Out should be mandatory ! */
67 #if 1//ndef ADC20 75 #if 1//ndef ADC20
68 76
69 -#define AUDIO_CHANNELS 2 77 +#define AUDIO_CHANNELS 2 /*for Audio Out*/
  78 +#define AUDIO_OUT_CHANNELS AUDIO_CHANNELS
70 #define AUDIO_SUB_FRAME_SIZE 2 //pcm16 79 #define AUDIO_SUB_FRAME_SIZE 2 //pcm16
71 #define AUDIO_BIT_RESOLUTION 16 80 #define AUDIO_BIT_RESOLUTION 16
72 81
73 -#if 1  
74 -#define AUDIOIN_CHANNELS 1 /*for Audio In*/ 82 +#if 0
  83 +#define AUDIOIN_CHANNELS 2 /*for Audio In*/
75 #else 84 #else
76 #define AUDIOIN_CHANNELS 1 /*for Audio In*/ 85 #define AUDIOIN_CHANNELS 1 /*for Audio In*/
77 #endif 86 #endif
@@ -155,13 +164,15 @@ @@ -155,13 +164,15 @@
155 #endif 164 #endif
156 165
157 166
158 -#if 1//for new usb device lib 167 +
159 typedef struct { 168 typedef struct {
160 BOOL USBOutEnable; //USB Speaker 169 BOOL USBOutEnable; //USB Speaker
161 BOOL USBInEnable; //USB Mic, ONLYMicCFG, USB_DEVICE_IN_OUT_CFG 170 BOOL USBInEnable; //USB Mic, ONLYMicCFG, USB_DEVICE_IN_OUT_CFG
162 BOOL USBOutMixInEnable; //Mix USB Out with other data then USB In. 171 BOOL USBOutMixInEnable; //Mix USB Out with other data then USB In.
163 172
  173 +#if 1//def USB_DEV_LIB_V1P0P10
164 BOOL SOFINTEnable; //Enable SOF Interrupt 174 BOOL SOFINTEnable; //Enable SOF Interrupt
  175 +#endif
165 176
166 BOOL ADC20Enable; //ADC20 177 BOOL ADC20Enable; //ADC20
167 178
@@ -191,7 +202,6 @@ typedef struct { @@ -191,7 +202,6 @@ typedef struct {
191 } USB_DEV_FEATURE_CONF; 202 } USB_DEV_FEATURE_CONF;
192 203
193 extern USB_DEV_FEATURE_CONF usbdev_featureconf; 204 extern USB_DEV_FEATURE_CONF usbdev_featureconf;
194 -#endif  
195 205
196 /* 206 /*
197 device 207 device
@@ -204,8 +214,29 @@ typedef enum { @@ -204,8 +214,29 @@ typedef enum {
204 enUSB_DEV_STACK_ATTR_NULL = 0, 214 enUSB_DEV_STACK_ATTR_NULL = 0,
205 enUSB_DEV_STACK_ATTR_PC_SPEAKER, 215 enUSB_DEV_STACK_ATTR_PC_SPEAKER,
206 enUSB_DEV_STACK_ATTR_APPLE_LIGHTNING, 216 enUSB_DEV_STACK_ATTR_APPLE_LIGHTNING,
207 - enUSB_DEV_STACK_ATTR_USB_MICROPHONE  
208 -} enum_USB_DEVICE_STACK_ATTR; 217 + enUSB_DEV_STACK_ATTR_USB_MICROPHONE,
  218 + enUSB_DEV_STACK_ATTR_USB_MSC
  219 +} enum_USB_DEVICE_STACK_ATTR;
  220 +
  221 +typedef enum {
  222 + //Telephony Page
  223 + enHUTTELEPHONY_HOOK = 0x01,
  224 + enHUTTELEPHONY_DROP = 0x04,
  225 + enHUTTELEPHONY_MUTE = 0x04
  226 +} enum_USB_HUTTELEPHONY_KEYCODE;
  227 +
  228 +typedef enum {
  229 + //Consumer Page
  230 + enHUTCONSUMER_VOLUP = 0x01,
  231 + enHUTCONSUMER_VOLDOWN = 0x02,
  232 + enHUTCONSUMER_PLAY = 0x04,
  233 + enHUTCONSUMER_NEXT = 0x08,
  234 + enHUTCONSUMER_PREV = 0x10,
  235 + enHUTCONSUMER_STOP = 0x20,
  236 + enHUTCONSUMER_FF = 0x40,
  237 + enHUTCONSUMER_RW = 0x80
  238 +} enum_USB_HUTCONSUMER_KEYCODE;
  239 +
209 240
210 int usb_devStart(enum_USB_DEVICE_STACK_ATTR attr); 241 int usb_devStart(enum_USB_DEVICE_STACK_ATTR attr);
211 int usb_devStop(void); 242 int usb_devStop(void);
@@ -215,5 +246,6 @@ int usb_devAudioSampleRate_get(U32 *pSampleRate); @@ -215,5 +246,6 @@ int usb_devAudioSampleRate_get(U32 *pSampleRate);
215 246
216 void daudio_SetFBSamplerateCorrection(int value); 247 void daudio_SetFBSamplerateCorrection(int value);
217 248
  249 +
218 #endif 250 #endif
219 251
@@ -39,13 +39,15 @@ @@ -39,13 +39,15 @@
39 39
40 #define EX_AUDIO_STREAM_THRESHOLD_FOR_USB_DEV (EX_AUDIO_DEC_SAMPLES+192*2) 40 #define EX_AUDIO_STREAM_THRESHOLD_FOR_USB_DEV (EX_AUDIO_DEC_SAMPLES+192*2)
41 41
  42 +
  43 +
42 void audiodata_down_sample_24bit_by_2(U8 *pBuf, U16 len) 44 void audiodata_down_sample_24bit_by_2(U8 *pBuf, U16 len)
43 { 45 {
44 U8 *pBufD; 46 U8 *pBufD;
45 U16 i; 47 U16 i;
46 pBufD = pBuf; 48 pBufD = pBuf;
47 49
48 - for (i=0; i<(len); i++) 50 + for (i=0; i<(len); )
49 { 51 {
50 *pBufD++ = *pBuf++; 52 *pBufD++ = *pBuf++;
51 *pBufD++ = *pBuf++; 53 *pBufD++ = *pBuf++;
@@ -43,11 +43,11 @@ typedef enum { @@ -43,11 +43,11 @@ typedef enum {
43 enIRP_HUB_POLL, 43 enIRP_HUB_POLL,
44 enIRP_HUB_NOTIFY, 44 enIRP_HUB_NOTIFY,
45 45
46 - enIRP_OTG_NOTIFY, //0d 46 + enIRP_OTG_NOTIFY, //0d
47 47
48 enIRP_TYPE_MTP_INT_POLL, 48 enIRP_TYPE_MTP_INT_POLL,
49 enIRP_TYPE_MTP_IF, 49 enIRP_TYPE_MTP_IF,
50 - enIRP_TYPE_MTP_SPECIFIC, //10 50 + enIRP_TYPE_MTP_SPECIFIC, //10
51 51
52 enIRP_TYPE_IPOD_NOTIFY, 52 enIRP_TYPE_IPOD_NOTIFY,
53 enIRP_TYPE_IPOD_PKT_TX, 53 enIRP_TYPE_IPOD_PKT_TX,
@@ -59,9 +59,9 @@ typedef enum { @@ -59,9 +59,9 @@ typedef enum {
59 enIRP_TYPE_IPOD_BACK2MSC, 59 enIRP_TYPE_IPOD_BACK2MSC,
60 enIRP_TYPE_IPOD_TIMEOUT, 60 enIRP_TYPE_IPOD_TIMEOUT,
61 61
62 - enIRP_TYPE_DEV_START, //1A  
63 - enIRP_TYPE_DEV_STOP, //1B  
64 - enIRP_TYPE_DEV_SETUP_PKT, //1C 62 + enIRP_TYPE_DEV_START, //1A
  63 + enIRP_TYPE_DEV_STOP, //1B
  64 + enIRP_TYPE_DEV_SETUP_PKT, //1C
65 65
66 enIRP_TYPE_AOA_SET_ZERO_BANDWIDTH, 66 enIRP_TYPE_AOA_SET_ZERO_BANDWIDTH,
67 enIRP_TYPE_AOA_START_RX, 67 enIRP_TYPE_AOA_START_RX,
@@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
5 #include "oem.h" 5 #include "oem.h"
6 6
7 #include "hw_timer.h" 7 #include "hw_timer.h"
  8 +#include "hw_da_pp.h"
8 9
9 #include "mem_reloc.h" 10 #include "mem_reloc.h"
10 #include "fifo.h" 11 #include "fifo.h"
@@ -18,9 +19,9 @@ @@ -18,9 +19,9 @@
18 #include "app_cmd.h" 19 #include "app_cmd.h"
19 #include "oem_string.h" 20 #include "oem_string.h"
20 #include <string.h> 21 #include <string.h>
21 -//#include "app_wave.h" 22 +#include "app_flash_program.h"
22 23
23 -#ifdef MP3_ENCODE_ENABLE 24 +#if 1//def MP3_ENCODE_ENABLE
24 #include "app_mp3_encode.h" 25 #include "app_mp3_encode.h"
25 #endif 26 #endif
26 27
@@ -45,14 +46,16 @@ @@ -45,14 +46,16 @@
45 #ifdef BT_HCI_ENABLE 46 #ifdef BT_HCI_ENABLE
46 #include "ht_hci_main.h" 47 #include "ht_hci_main.h"
47 #endif 48 #endif
  49 +
48 #include "app_media.h" 50 #include "app_media.h"
  51 +#include "app_string_oem.h"
49 52
50 #ifdef WAV_DEC 53 #ifdef WAV_DEC
51 #include "wave_decode.h" 54 #include "wave_decode.h"
52 #endif 55 #endif
53 56
54 57
55 -#define TASK_HDD_PRIORITY_CHANGE 58 +//#define TASK_HDD_PRIORITY_CHANGE
56 59
57 60
58 //#define IDE_BLOCK_SIZE 1024 61 //#define IDE_BLOCK_SIZE 1024
@@ -65,8 +68,8 @@ volatile U8 task_hdd_check_cnt; @@ -65,8 +68,8 @@ volatile U8 task_hdd_check_cnt;
65 #endif 68 #endif
66 69
67 70
68 -extern int osentry_HddTaskPriority( void );  
69 -extern int osentry_restoreHdd_TaskPriority( void ); 71 +int osentry_HddTaskPriority( void );
  72 +int osentry_restoreHdd_TaskPriority( void );
70 //#pragma section ide_data " " ".fat_file_data1" 73 //#pragma section ide_data " " ".fat_file_data1"
71 //#pragma use_section ide_data ide_buf 74 //#pragma use_section ide_data ide_buf
72 75
@@ -120,6 +123,7 @@ volatile U8 sd1_FileSysPresent; @@ -120,6 +123,7 @@ volatile U8 sd1_FileSysPresent;
120 123
121 extern U16 gwEntryNum; 124 extern U16 gwEntryNum;
122 extern U16 gwFolderNum; 125 extern U16 gwFolderNum;
  126 +extern U32 rec_files_num;
123 127
124 128
125 U8 media_write_err_cnt; 129 U8 media_write_err_cnt;
@@ -21,9 +21,10 @@ @@ -21,9 +21,10 @@
21 21
22 #include "usbdev.h" 22 #include "usbdev.h"
23 23
24 -//#ifndef OTG_FORCE_FULL_SPEED 24 +
  25 +#ifndef OTG_FORCE_FULL_SPEED
25 U8 usb_highspeed_flag; 26 U8 usb_highspeed_flag;
26 -//#endif 27 +#endif
27 28
28 29
29 volatile USB_OTG_REGISTERS * otgRegister; 30 volatile USB_OTG_REGISTERS * otgRegister;
@@ -52,9 +53,11 @@ void usbotg_isr( void ) __USBHOST_TEXT; @@ -52,9 +53,11 @@ void usbotg_isr( void ) __USBHOST_TEXT;
52 //int8, dma is int9 53 //int8, dma is int9
53 void usbotg_isr( void ) 54 void usbotg_isr( void )
54 { 55 {
  56 + //volatile U32 reg32;
  57 +
55 //do 58 //do
56 { 59 {
57 -/* volatile U32 reg32; 60 + #if 0//it is moved to the file of interrupt.c
58 reg32 = *otgEnhCtrl->ctrl; 61 reg32 = *otgEnhCtrl->ctrl;
59 *otgEnhCtrl->ctrl &= ~ENH_CTRL_INT_STAT_MASK; 62 *otgEnhCtrl->ctrl &= ~ENH_CTRL_INT_STAT_MASK;
60 reg32 &= ENH_CTRL_INT_STAT_MASK; 63 reg32 &= ENH_CTRL_INT_STAT_MASK;
@@ -70,7 +73,7 @@ void usbotg_isr( void ) @@ -70,7 +73,7 @@ void usbotg_isr( void )
70 } 73 }
71 74
72 if( reg32 & ENH_CTRL_INT_USB ) 75 if( reg32 & ENH_CTRL_INT_USB )
73 -*/ 76 + #endif
74 { 77 {
75 otg.curstate = otgRegister->state; 78 otg.curstate = otgRegister->state;
76 79
@@ -82,15 +85,15 @@ void usbotg_isr( void ) @@ -82,15 +85,15 @@ void usbotg_isr( void )
82 hcd_intProcess(); 85 hcd_intProcess();
83 } 86 }
84 87
85 -#ifdef USB_DEV_ENABLE 88 + #ifdef USB_DEV_ENABLE
86 if( otg.curstate == 0x09 ) //dev 89 if( otg.curstate == 0x09 ) //dev
87 { 90 {
88 dcd_intProcess(); 91 dcd_intProcess();
89 } 92 }
90 -#else 93 + #else
91 DBG_assert( otg.curstate != 0x09 ); //dev 94 DBG_assert( otg.curstate != 0x09 ); //dev
92 //dcd_int_process(); 95 //dcd_int_process();
93 -#endif 96 + #endif
94 97
95 if( otg.curstate != otg.oldstate ) 98 if( otg.curstate != otg.oldstate )
96 { 99 {
@@ -112,37 +115,41 @@ void otg_intProcess(void) @@ -112,37 +115,41 @@ void otg_intProcess(void)
112 { 115 {
113 IRP *irp = &otg.irp; 116 IRP *irp = &otg.irp;
114 volatile U8 reg8; 117 volatile U8 reg8;
  118 +
  119 + //DBG_iPrintf("*\n\r");
115 120
116 reg8 = (otgRegister->irq & otgRegister->ien); 121 reg8 = (otgRegister->irq & otgRegister->ien);
117 if( reg8 ) 122 if( reg8 )
118 { 123 {
119 otgRegister->irq = reg8; 124 otgRegister->irq = reg8;
120 125
121 - //DBG_iPrintf("\n---%x\n", reg8);  
122 - if( reg8 & 0x01 ) //2.16.1: a_idle or b_idle state. 126 + //DBG_iPrintf("\n\r%x\n\r", reg8);
  127 + if( reg8 & 0x01 ) //2.16.1: a_idle or b_idle state.
123 { 128 {
124 //DBG_iPrintf("\n---reg8 & 0x01\n"); 129 //DBG_iPrintf("\n---reg8 & 0x01\n");
125 - if( otgRegister->state == 0x08 ) //2.16.2: otgstate 0x08 b_idle. 130 + if( otgRegister->state == 0x08 ) //2.16.2: b_idle.
126 { 131 {
127 //dev 132 //dev
128 - /*  
129 otgRegister->ctrl &= ~0x01; 133 otgRegister->ctrl &= ~0x01;
130 - *usbdevReg->ctrl->usbcs &= ~0x40; //disconnect bit, 1 is discon  
131 - */  
132 - otgRegister->ctrl &= ~0x01; //2.16.3 set otgctrl bit0 to 0, end the session.  
133 - otgRegister->ctrl |= 0x02; //JJ+ set bit1 to forces the bus power-down.  
134 - *usbdevReg->ctrl->usbcs |= 0x40; //2.18.41 usbcs: discon bit, 1 is discon. JJ+ 134 +
  135 + #if 0
  136 + *usbdevReg->ctrl->usbcs &= ~0x40; //2.18.41: disconnect bit, 1 is discon
  137 + #else
  138 + otgRegister->ctrl |= 0x02; //JJ+
  139 + *usbdevReg->ctrl->usbcs |= 0x40; //2.18.41: disconnect bit, 1 is discon. JJ+
  140 + #endif
  141 +
  142 + DBG_iPrintf("\n\rPC_discon\n\r");
135 143
136 if( (otg.curstate == 0x08) && (otg.oldstate == 0x09 ) && dcd_isOpen() ) 144 if( (otg.curstate == 0x08) && (otg.oldstate == 0x09 ) && dcd_isOpen() )
137 { 145 {
138 dcd_hostUnplug(); 146 dcd_hostUnplug();
139 147
140 - //DBG_iPrintf("\n_HOST_DISCON\n");  
141 FILL_OTG_IRP( irp, enIRPT_DEV_STACK, IRP_PARAM_HOST_DISCONNECT ); 148 FILL_OTG_IRP( irp, enIRPT_DEV_STACK, IRP_PARAM_HOST_DISCONNECT );
142 usbmsg_isendIRP( irp ); 149 usbmsg_isendIRP( irp );
143 } 150 }
144 } 151 }
145 - else //2.16.1: a_idle. 152 + else //2.16.1: a_idle.
146 { 153 {
147 //host 154 //host
148 otgRegister->ctrl &= ~0x02; 155 otgRegister->ctrl &= ~0x02;
@@ -150,17 +157,18 @@ void otg_intProcess(void) @@ -150,17 +157,18 @@ void otg_intProcess(void)
150 } 157 }
151 } 158 }
152 159
153 - if( reg8 & 0x08 ) //2.16.1: vbuserrirq, free the bus, then power-down bus. 160 + if( reg8 & 0x08 ) //2.16.1: vbuserrirq, free the bus, then power-down bus.
154 { 161 {
155 otgRegister->ctrl &= ~0x01; 162 otgRegister->ctrl &= ~0x01;
156 otgRegister->ctrl |= 0x02; 163 otgRegister->ctrl |= 0x02;
157 //send error msg out ? 164 //send error msg out ?
158 } 165 }
159 166
160 - if( reg8 & 0x04 ) //2.16.1: a_host or b_host state entering. 167 + if( reg8 & 0x04 ) //2.16.1: a_host or b_host state entering.
161 { 168 {
162 //DBG_iPrintf("\n---reg8 & 0x04\n"); 169 //DBG_iPrintf("\n---reg8 & 0x04\n");
163 //host --> take this as dev connect 170 //host --> take this as dev connect
  171 + DBG_iPrintf("\n\rPC conn1\n\r");
164 if( otg.curstate == 0x03 ) 172 if( otg.curstate == 0x03 )
165 { 173 {
166 FILL_OTG_IRP( irp, enIRPT_USBD, IRP_PARAM_DEV_CONNECT ); 174 FILL_OTG_IRP( irp, enIRPT_USBD, IRP_PARAM_DEV_CONNECT );
@@ -174,13 +182,15 @@ void otg_intProcess(void) @@ -174,13 +182,15 @@ void otg_intProcess(void)
174 usbmsg_isendIRP( irp ); 182 usbmsg_isendIRP( irp );
175 } 183 }
176 184
177 - if( reg8 & 0x10 ) //2.16.1: a_peri or b_peri state entering. 185 + if( reg8 & 0x10 ) //2.16.1: a_peri or b_peri state entering.
178 { 186 {
179 - //DBG_iPrintf("\n---reg8 & 0x10\n"); 187 + //DBG_iPrintf("\n\r reg8 & 0x10\n\r");
180 //dev --> take this as host connnect 188 //dev --> take this as host connnect
  189 + //DBG_iPrintf("\n\r usbDev connected2\n\r");
  190 + DBG_Printf("\n\rPC conn2\n\r");
181 if( dcd_isOpen() ) 191 if( dcd_isOpen() )
182 { 192 {
183 - //DBG_iPrintf("\n_HOST_CON\n"); 193 + //DBG_iPrintf("\n\rHOST_CON\n\r");
184 FILL_OTG_IRP( irp, enIRPT_DEV_STACK, IRP_PARAM_HOST_CONNECT ); 194 FILL_OTG_IRP( irp, enIRPT_DEV_STACK, IRP_PARAM_HOST_CONNECT );
185 usbmsg_isendIRP( irp ); 195 usbmsg_isendIRP( irp );
186 } 196 }
@@ -267,60 +277,65 @@ int otg_isHostPlugin( void ) @@ -267,60 +277,65 @@ int otg_isHostPlugin( void )
267 #endif 277 #endif
268 278
269 279
270 -#define REG_ADDR(x) (void*)(USB_DEVICE_BASE_ADDR + x)  
271 -//#define REG_ADDR(x) (USB_DEVICE_BASE_ADDR + x) 280 +#define REG_ADDR(x) (void*)(USB_DEVICE_BASE_ADDR + x)
  281 +//#define REG_ADDR(x) (USB_DEVICE_BASE_ADDR + x)
272 282
273 283
274 const ENDPOINT0_REGS endp0Addr = { 284 const ENDPOINT0_REGS endp0Addr = {
275 REG_ADDR(0x00), REG_ADDR(0x01), REG_ADDR(0x02), 285 REG_ADDR(0x00), REG_ADDR(0x01), REG_ADDR(0x02),
276 REG_ADDR(0xc0), REG_ADDR(0xc1), REG_ADDR(0xc3), REG_ADDR(0x1e0), 286 REG_ADDR(0xc0), REG_ADDR(0xc1), REG_ADDR(0xc3), REG_ADDR(0x1e0),
277 - REG_ADDR(0x180), REG_ADDR(0x140), REG_ADDR(0x100) 287 + REG_ADDR(0x180),REG_ADDR(0x140), REG_ADDR(0x100)
278 }; 288 };
279 289
280 -  
281 - 290 +//in the host mode: rx, in the device mode: tx
282 const ENDPOINT_REGS endp1RxAddr = { 291 const ENDPOINT_REGS endp1RxAddr = {
283 REG_ADDR(0x08), REG_ADDR(0x0b), REG_ADDR(0x0a), 292 REG_ADDR(0x08), REG_ADDR(0x0b), REG_ADDR(0x0a),
284 REG_ADDR(0xc6), REG_ADDR(0xc7), 293 REG_ADDR(0xc6), REG_ADDR(0xc7),
285 - REG_ADDR(0x1e2), REG_ADDR(0x304), 294 + REG_ADDR(0x1e2),REG_ADDR(0x304),
286 REG_ADDR(0x84), REG_ADDR(0x84), REG_ADDR(0x84) 295 REG_ADDR(0x84), REG_ADDR(0x84), REG_ADDR(0x84)
287 }; 296 };
288 297
  298 +//in the host mode: tx, in the device mode: rx
  299 +const ENDPOINT_REGS endp1TxAddr = {
  300 + REG_ADDR(0x0c), REG_ADDR(0x0f), REG_ADDR(0x0e),
  301 + REG_ADDR(0xc4), REG_ADDR(0xc5),
  302 + REG_ADDR(0x3e2),REG_ADDR(0x344),
  303 + REG_ADDR(0x84), REG_ADDR(0x84), REG_ADDR(0x84)
  304 +};
  305 +
  306 +//in the host mode: rx, in the device mode: tx
289 const ENDPOINT_REGS endp2RxAddr = { 307 const ENDPOINT_REGS endp2RxAddr = {
290 REG_ADDR(0x10), REG_ADDR(0x13), REG_ADDR(0x12), 308 REG_ADDR(0x10), REG_ADDR(0x13), REG_ADDR(0x12),
291 REG_ADDR(0xca), REG_ADDR(0xcb), 309 REG_ADDR(0xca), REG_ADDR(0xcb),
292 - REG_ADDR(0x1e4), REG_ADDR(0x308), 310 + REG_ADDR(0x1e4),REG_ADDR(0x308),
293 REG_ADDR(0x88), REG_ADDR(0x88), REG_ADDR(0x88) 311 REG_ADDR(0x88), REG_ADDR(0x88), REG_ADDR(0x88)
294 }; 312 };
295 313
  314 +//in the host mode: tx, in the device mode: rx
  315 +const ENDPOINT_REGS endp2TxAddr = {
  316 + REG_ADDR(0x14), REG_ADDR(0x17), REG_ADDR(0x16),
  317 + REG_ADDR(0xc8), REG_ADDR(0xc9),
  318 + REG_ADDR(0x3e4),REG_ADDR(0x348),
  319 + REG_ADDR(0x88), REG_ADDR(0x88), REG_ADDR(0x88)
  320 +};
  321 +
  322 +#if 1//( (defined USB_HOST_ENABLE || defined USB_DEV_ENABLE) && (defined HID_FUNC_ENABLE) )
  323 +//in the host mode: rx, in the device mode: tx
296 const ENDPOINT_REGS endp3RxAddr = { //ep3 Rx=Host OUT byte counter, cs, con,... 324 const ENDPOINT_REGS endp3RxAddr = { //ep3 Rx=Host OUT byte counter, cs, con,...
297 - //REG_ADDR(0x18), REG_ADDR(0x13), REG_ADDR(0x1b), //JJ  
298 REG_ADDR(0x18), REG_ADDR(0x1b), REG_ADDR(0x1a), 325 REG_ADDR(0x18), REG_ADDR(0x1b), REG_ADDR(0x1a),
299 REG_ADDR(0xce), REG_ADDR(0xcf), 326 REG_ADDR(0xce), REG_ADDR(0xcf),
300 REG_ADDR(0x1e6), REG_ADDR(0x30c),//2.17.20 HC INx Max, 2.18.47 outxstaddr 327 REG_ADDR(0x1e6), REG_ADDR(0x30c),//2.17.20 HC INx Max, 2.18.47 outxstaddr
301 REG_ADDR(0x8c), REG_ADDR(0x8c), REG_ADDR(0x8c) 328 REG_ADDR(0x8c), REG_ADDR(0x8c), REG_ADDR(0x8c)
302 }; 329 };
303 330
304 -const ENDPOINT_REGS endp1TxAddr = {  
305 - REG_ADDR(0x0c), REG_ADDR(0x0f), REG_ADDR(0x0e),  
306 - REG_ADDR(0xc4), REG_ADDR(0xc5),  
307 - REG_ADDR(0x3e2), REG_ADDR(0x344),  
308 - REG_ADDR(0x84), REG_ADDR(0x84), REG_ADDR(0x84)  
309 -};  
310 -  
311 -const ENDPOINT_REGS endp2TxAddr = {  
312 - REG_ADDR(0x14), REG_ADDR(0x17), REG_ADDR(0x16),  
313 - REG_ADDR(0xc8), REG_ADDR(0xc9),  
314 - REG_ADDR(0x3e4), REG_ADDR(0x348),  
315 - REG_ADDR(0x88), REG_ADDR(0x88), REG_ADDR(0x88)  
316 -};  
317 - 331 +//in the host mode: tx, in the device mode: rx
318 const ENDPOINT_REGS endp3TxAddr = { //ep3 Tx=Host IN byte counter, cs, con,... !!! 332 const ENDPOINT_REGS endp3TxAddr = { //ep3 Tx=Host IN byte counter, cs, con,... !!!
319 REG_ADDR(0x1c), REG_ADDR(0x1f), REG_ADDR(0x1e), 333 REG_ADDR(0x1c), REG_ADDR(0x1f), REG_ADDR(0x1e),
320 REG_ADDR(0xcc), REG_ADDR(0xcd), 334 REG_ADDR(0xcc), REG_ADDR(0xcd),
321 REG_ADDR(0x3e6), REG_ADDR(0x34c),//2.17.22 HC OUTx Max, 2.18.48 inxstaddr 335 REG_ADDR(0x3e6), REG_ADDR(0x34c),//2.17.22 HC OUTx Max, 2.18.48 inxstaddr
322 REG_ADDR(0x8c), REG_ADDR(0x8c), REG_ADDR(0x8c) 336 REG_ADDR(0x8c), REG_ADDR(0x8c), REG_ADDR(0x8c)
323 }; 337 };
  338 +#endif
324 339
325 340
326 341
@@ -348,6 +363,7 @@ void loopdelay( U32 t ) @@ -348,6 +363,7 @@ void loopdelay( U32 t )
348 363
349 void otg_phy_set(BOOL bHost_Dev) 364 void otg_phy_set(BOOL bHost_Dev)
350 { 365 {
  366 +#if 1//def USB_CONFIG
351 //for the 3rd Generation Chip 367 //for the 3rd Generation Chip
352 volatile U32 tmp,val; 368 volatile U32 tmp,val;
353 369
@@ -414,6 +430,7 @@ void otg_phy_set(BOOL bHost_Dev) @@ -414,6 +430,7 @@ void otg_phy_set(BOOL bHost_Dev)
414 //usbphy_config->utmi_vbus_src = 0; 430 //usbphy_config->utmi_vbus_src = 0;
415 usbphy_config->utmi_vbus_src = 1; 431 usbphy_config->utmi_vbus_src = 1;
416 REG_MISC_USBPHY = tmp; 432 REG_MISC_USBPHY = tmp;
  433 +#endif
417 434
418 } 435 }
419 436
@@ -444,8 +461,10 @@ int otg_init( void ) @@ -444,8 +461,10 @@ int otg_init( void )
444 usbhostReg->endp2In = (ENDPOINT_REGS*)&endp2RxAddr; 461 usbhostReg->endp2In = (ENDPOINT_REGS*)&endp2RxAddr;
445 usbhostReg->endp2Out = (ENDPOINT_REGS*)&endp2TxAddr; 462 usbhostReg->endp2Out = (ENDPOINT_REGS*)&endp2TxAddr;
446 463
  464 +#if 1//( (defined USB_HOST_ENABLE) && (defined HID_FUNC_ENABLE) )
447 usbhostReg->endp3In = (ENDPOINT_REGS*)&endp3RxAddr; //HID 465 usbhostReg->endp3In = (ENDPOINT_REGS*)&endp3RxAddr; //HID
448 usbhostReg->endp3Out = (ENDPOINT_REGS*)&endp3TxAddr; 466 usbhostReg->endp3Out = (ENDPOINT_REGS*)&endp3TxAddr;
  467 +#endif
449 468
450 usbhostReg->ctrl = (COMMON_CTRL_REG*)&commCtlAddr; 469 usbhostReg->ctrl = (COMMON_CTRL_REG*)&commCtlAddr;
451 usbhostReg->irq = (USB_IRQ_REGS*)&irqAddr; 470 usbhostReg->irq = (USB_IRQ_REGS*)&irqAddr;
@@ -460,8 +479,11 @@ int otg_init( void ) @@ -460,8 +479,11 @@ int otg_init( void )
460 usbdevReg->endp2In = (ENDPOINT_REGS*)&endp2TxAddr; //ep2 0x82, Mic,*endp2In, IN in dcd_open() 479 usbdevReg->endp2In = (ENDPOINT_REGS*)&endp2TxAddr; //ep2 0x82, Mic,*endp2In, IN in dcd_open()
461 usbdevReg->endp2Out = (ENDPOINT_REGS*)&endp2RxAddr; //useless ! 480 usbdevReg->endp2Out = (ENDPOINT_REGS*)&endp2RxAddr; //useless !
462 481
  482 +#if 1//( (defined USB_DEV_ENABLE) && (defined HID_FUNC_ENABLE) )
  483 + //HID Int Input
463 usbdevReg->endp3In = (ENDPOINT_REGS*)&endp3TxAddr; //ep3 0x83, HID,*endp3In, IN in dcd_open() 484 usbdevReg->endp3In = (ENDPOINT_REGS*)&endp3TxAddr; //ep3 0x83, HID,*endp3In, IN in dcd_open()
464 usbdevReg->endp3Out = (ENDPOINT_REGS*)&endp3RxAddr; //useless ! 485 usbdevReg->endp3Out = (ENDPOINT_REGS*)&endp3RxAddr; //useless !
  486 +#endif
465 487
466 usbdevReg->ctrl = (COMMON_CTRL_REG*)&commCtlAddr; 488 usbdevReg->ctrl = (COMMON_CTRL_REG*)&commCtlAddr;
467 usbdevReg->irq = (USB_IRQ_REGS*)&irqAddr; 489 usbdevReg->irq = (USB_IRQ_REGS*)&irqAddr;
@@ -479,8 +501,15 @@ int otg_init( void ) @@ -479,8 +501,15 @@ int otg_init( void )
479 int otg_init_for_dev( void ) 501 int otg_init_for_dev( void )
480 { 502 {
481 int ret; 503 int ret;
482 - DBG_Printf("+++++++++++++++ %s\n\r", __func__); 504 + DBG_Printf("%s\n\r", __func__);
483 505
  506 + #if 1
  507 + DBG_Printf("%s\n\r", optek_lib_usb_device_version_get());
  508 + delayms(2);
  509 + //DBG_Printf("%s\n\r", optek_lib_usb_device_date_get());
  510 + //DBG_Printf("%s\n\r", optek_lib_usb_device_time_get());
  511 + #endif
  512 +
484 otg_phy_set(FALSE); //Dev 513 otg_phy_set(FALSE); //Dev
485 514
486 otgRegister = (USB_OTG_REGISTERS *)USB_OTG_BASE_ADDR; 515 otgRegister = (USB_OTG_REGISTERS *)USB_OTG_BASE_ADDR;
@@ -497,17 +526,41 @@ int otg_init_for_dev( void ) @@ -497,17 +526,41 @@ int otg_init_for_dev( void )
497 usbdevReg = &usbDevRegs; 526 usbdevReg = &usbDevRegs;
498 527
499 528
  529 +#if 0 //By JJ
  530 + usbhostReg->endp0 = (ENDPOINT0_REGS*)&endp0Addr;
  531 + usbhostReg->endp1In = (ENDPOINT_REGS*)&endp1RxAddr;
  532 + usbhostReg->endp1Out = (ENDPOINT_REGS*)&endp1TxAddr;
  533 + usbhostReg->endp2In = (ENDPOINT_REGS*)&endp2RxAddr;
  534 + usbhostReg->endp2Out = (ENDPOINT_REGS*)&endp2TxAddr;
  535 +
  536 +#if ( (defined USB_DEV_ENABLE) && (defined HID_FUNC_ENABLE) )
  537 + usbhostReg->endp3In = (ENDPOINT_REGS*)&endp3RxAddr; //HID
  538 + usbhostReg->endp3Out = (ENDPOINT_REGS*)&endp3TxAddr;
  539 +#endif
  540 +
  541 + usbhostReg->ctrl = (COMMON_CTRL_REG*)&commCtlAddr;
  542 + usbhostReg->irq = (USB_IRQ_REGS*)&irqAddr;
  543 +
  544 + usbhostReg->portctrl = (U8*)REG_ADDR(0x1ab); //0x1ab [des] 2.17.6 hcportctrl
  545 + usbhostReg->framenum = (U16*)REG_ADDR(0x1ac); //0x1ac [des] 2.17.7 hcfrmnrl
  546 + usbhostReg->frameRemain = (U16*)REG_ADDR(0x1ae); //0x1ae [des] 2.17.8 hcfrmnrh
  547 +#endif
  548 +
  549 +
500 usbdevReg->endp0 = (ENDPOINT0_REGS*)&endp0Addr; //rxbc, txbc, cs, ... setupdat, rxdata, txdata 550 usbdevReg->endp0 = (ENDPOINT0_REGS*)&endp0Addr; //rxbc, txbc, cs, ... setupdat, rxdata, txdata
501 551
502 usbdevReg->endp1In = (ENDPOINT_REGS*)&endp1TxAddr; //useless ! 552 usbdevReg->endp1In = (ENDPOINT_REGS*)&endp1TxAddr; //useless !
503 553
504 - usbdevReg->endp1Out = (ENDPOINT_REGS*)&endp1RxAddr; //ep1 0x01, Spk,*endp1Out,Out for Device in dcd_open()  
505 - usbdevReg->endp2In = (ENDPOINT_REGS*)&endp2TxAddr; //ep2 0x82, Mic,*endp2In, IN in dcd_open() 554 + usbdevReg->endp1Out = (ENDPOINT_REGS*)&endp1RxAddr; //ep1 0x01, Spk Out from host,*endp1Out,Out for Device in dcd_open()
  555 + usbdevReg->endp2In = (ENDPOINT_REGS*)&endp2TxAddr; //ep2 0x82, Mic In to host,*endp2In, IN in dcd_open()
506 556
507 usbdevReg->endp2Out = (ENDPOINT_REGS*)&endp2RxAddr; //useless ! 557 usbdevReg->endp2Out = (ENDPOINT_REGS*)&endp2RxAddr; //useless !
508 558
  559 +#if 1//( (defined USB_DEV_ENABLE) && (defined HID_FUNC_ENABLE) )
  560 + //HID Int Input
509 usbdevReg->endp3In = (ENDPOINT_REGS*)&endp3TxAddr; //ep3 0x83, HID,*endp3In, IN in dcd_open() 561 usbdevReg->endp3In = (ENDPOINT_REGS*)&endp3TxAddr; //ep3 0x83, HID,*endp3In, IN in dcd_open()
510 usbdevReg->endp3Out = (ENDPOINT_REGS*)&endp3RxAddr; //useless ! 562 usbdevReg->endp3Out = (ENDPOINT_REGS*)&endp3RxAddr; //useless !
  563 +#endif
511 564
512 usbdevReg->ctrl = (COMMON_CTRL_REG*)&commCtlAddr; 565 usbdevReg->ctrl = (COMMON_CTRL_REG*)&commCtlAddr;
513 usbdevReg->irq = (USB_IRQ_REGS*)&irqAddr; 566 usbdevReg->irq = (USB_IRQ_REGS*)&irqAddr;
@@ -547,7 +600,7 @@ int otg_open( void ) @@ -547,7 +600,7 @@ int otg_open( void )
547 #if 1//def OPTEK_SOC2_VERSION 600 #if 1//def OPTEK_SOC2_VERSION
548 for( i = 0; i < 1; i ++ ) 601 for( i = 0; i < 1; i ++ )
549 { 602 {
550 -#ifdef OTG_FORCE_FULL_SPEED 603 + #ifdef OTG_FORCE_FULL_SPEED
551 reg32 = ENH_CTRL_PHY_CLK_ENA|ENH_CTRL_PHY_REG_ENA|ENH_CTRL_PHY_PLL_ENA|ENH_CTRL_DIS_HSPEED | ENH_CTRL_PHY_NO_SUSPEND; 604 reg32 = ENH_CTRL_PHY_CLK_ENA|ENH_CTRL_PHY_REG_ENA|ENH_CTRL_PHY_PLL_ENA|ENH_CTRL_DIS_HSPEED | ENH_CTRL_PHY_NO_SUSPEND;
552 *otgEnhCtrl->ctrl = reg32; 605 *otgEnhCtrl->ctrl = reg32;
553 timer_delayms(10); 606 timer_delayms(10);
@@ -556,11 +609,11 @@ int otg_open( void ) @@ -556,11 +609,11 @@ int otg_open( void )
556 609
557 timer_delayms(10); 610 timer_delayms(10);
558 reg32 = ENH_CTRL_PHY_CLK_ENA|ENH_CTRL_PHY_REG_ENA|ENH_CTRL_PHY_PLL_ENA|ENH_CTRL_DIS_HSPEED | ENH_CTRL_PHY_NO_SUSPEND; 611 reg32 = ENH_CTRL_PHY_CLK_ENA|ENH_CTRL_PHY_REG_ENA|ENH_CTRL_PHY_PLL_ENA|ENH_CTRL_DIS_HSPEED | ENH_CTRL_PHY_NO_SUSPEND;
559 -#else 612 + #else
560 613
561 -#ifndef OTG_FORCE_FULL_SPEED 614 + #ifndef OTG_FORCE_FULL_SPEED
562 if (usb_highspeed_flag) 615 if (usb_highspeed_flag)
563 -#endif 616 + #endif
564 { 617 {
565 DBG_Puts("USB high speed\n\n\r"); 618 DBG_Puts("USB high speed\n\n\r");
566 619
@@ -574,7 +627,7 @@ int otg_open( void ) @@ -574,7 +627,7 @@ int otg_open( void )
574 timer_delayms(10); 627 timer_delayms(10);
575 reg32 = ENH_CTRL_PHY_CLK_ENA|ENH_CTRL_PHY_REG_ENA|ENH_CTRL_PHY_PLL_ENA| ENH_CTRL_PHY_NO_SUSPEND; 628 reg32 = ENH_CTRL_PHY_CLK_ENA|ENH_CTRL_PHY_REG_ENA|ENH_CTRL_PHY_PLL_ENA| ENH_CTRL_PHY_NO_SUSPEND;
576 } 629 }
577 -#ifndef OTG_FORCE_FULL_SPEED 630 + #ifndef OTG_FORCE_FULL_SPEED
578 else 631 else
579 { 632 {
580 DBG_Puts("USB full speed\n\r"); 633 DBG_Puts("USB full speed\n\r");
@@ -588,9 +641,9 @@ int otg_open( void ) @@ -588,9 +641,9 @@ int otg_open( void )
588 timer_delayms(10); 641 timer_delayms(10);
589 reg32 = ENH_CTRL_PHY_CLK_ENA|ENH_CTRL_PHY_REG_ENA|ENH_CTRL_PHY_PLL_ENA|ENH_CTRL_DIS_HSPEED | ENH_CTRL_PHY_NO_SUSPEND; 642 reg32 = ENH_CTRL_PHY_CLK_ENA|ENH_CTRL_PHY_REG_ENA|ENH_CTRL_PHY_PLL_ENA|ENH_CTRL_DIS_HSPEED | ENH_CTRL_PHY_NO_SUSPEND;
590 } 643 }
591 -#endif 644 + #endif
592 645
593 -#endif 646 + #endif
594 647
595 reg32 |= (ENH_CTRL_INT_USB<<ENH_CTRL_INT_ENA_SHIFT) ; 648 reg32 |= (ENH_CTRL_INT_USB<<ENH_CTRL_INT_ENA_SHIFT) ;
596 *otgEnhCtrl->ctrl = reg32; 649 *otgEnhCtrl->ctrl = reg32;
@@ -629,10 +682,10 @@ int otg_open( void ) @@ -629,10 +682,10 @@ int otg_open( void )
629 682
630 #ifdef USB_DEV_ENABLE 683 #ifdef USB_DEV_ENABLE
631 //patch for device mode 684 //patch for device mode
632 - otgRegister->ctrl = 0x00; 685 + //otgRegister->ctrl = 0x00;
633 #endif 686 #endif
634 687
635 - #if 0//it is moved to the dstack.c of library of optek_lib_usb_device.a 688 + #if 1//it is moved to the library
636 USB_INT_ENABLE; 689 USB_INT_ENABLE;
637 #endif 690 #endif
638 691
@@ -647,7 +700,7 @@ int otg_open( void ) @@ -647,7 +700,7 @@ int otg_open( void )
647 700
648 int otg_close( void ) 701 int otg_close( void )
649 { 702 {
650 - DBG_Printf("----------------- %s\n\r", __func__); 703 + DBG_Printf("%s\n\r", __func__);
651 704
652 USB_INT_DISABLE; 705 USB_INT_DISABLE;
653 otgRegister->ien = 0x00; 706 otgRegister->ien = 0x00;
@@ -2,12 +2,13 @@ @@ -2,12 +2,13 @@
2 #define __OTG_H__ 2 #define __OTG_H__
3 3
4 4
  5 +#include "interrupt.h"
5 #include "wave_decode.h" 6 #include "wave_decode.h"
6 7
7 8
8 -#if 0// HS ( (defined WAV_DEC) && (defined WAV_192K_SUPPORT) ) 9 +#if 0//( (defined WAV_DEC) && (defined WAV_192K_SUPPORT) )
9 #undef OTG_FORCE_FULL_SPEED 10 #undef OTG_FORCE_FULL_SPEED
10 -#else// FS 11 +#else
11 #define OTG_FORCE_FULL_SPEED 12 #define OTG_FORCE_FULL_SPEED
12 #endif 13 #endif
13 14
@@ -75,6 +76,7 @@ typedef struct { @@ -75,6 +76,7 @@ typedef struct {
75 #define USB_ORG_REGFILE_SIZE (12) 76 #define USB_ORG_REGFILE_SIZE (12)
76 77
77 78
  79 +//usbhs_otg_sd_des.pdf
78 80
79 typedef struct { 81 typedef struct {
80 volatile U8 * rxbc; //dev out, host in //0x00 [des] 2.18.1 out0bc/hcin0bc 82 volatile U8 * rxbc; //dev out, host in //0x00 [des] 2.18.1 out0bc/hcin0bc
@@ -155,8 +157,10 @@ typedef struct { @@ -155,8 +157,10 @@ typedef struct {
155 ENDPOINT_REGS *endp2In; //data IN 157 ENDPOINT_REGS *endp2In; //data IN
156 ENDPOINT_REGS *endp2Out; 158 ENDPOINT_REGS *endp2Out;
157 159
  160 +#if 1//( (defined USB_DEV_ENABLE) && (defined HID_FUNC_ENABLE) )
158 ENDPOINT_REGS *endp3In; //data IN for HID 161 ENDPOINT_REGS *endp3In; //data IN for HID
159 ENDPOINT_REGS *endp3Out; 162 ENDPOINT_REGS *endp3Out;
  163 +#endif
160 164
161 USB_IRQ_REGS *irq; 165 USB_IRQ_REGS *irq;
162 166
@@ -176,8 +180,10 @@ typedef struct { @@ -176,8 +180,10 @@ typedef struct {
176 ENDPOINT_REGS *endp2In; 180 ENDPOINT_REGS *endp2In;
177 ENDPOINT_REGS *endp2Out; 181 ENDPOINT_REGS *endp2Out;
178 182
  183 +#if 1//( (defined USB_HOST_ENABLE) || (defined HID_FUNC_ENABLE) )
179 ENDPOINT_REGS *endp3In; //HID 184 ENDPOINT_REGS *endp3In; //HID
180 ENDPOINT_REGS *endp3Out; 185 ENDPOINT_REGS *endp3Out;
  186 +#endif
181 187
182 USB_IRQ_REGS *irq; //see const USB_IRQ_REGS irqAddr in otg.c 188 USB_IRQ_REGS *irq; //see const USB_IRQ_REGS irqAddr in otg.c
183 189
@@ -44,6 +44,7 @@ void task_usbotg(void *pvParameters) @@ -44,6 +44,7 @@ void task_usbotg(void *pvParameters)
44 #ifdef USB_INT_CHANGEs_TO_LEVEL1 44 #ifdef USB_INT_CHANGEs_TO_LEVEL1
45 SOFT5_INT_ENABLE; 45 SOFT5_INT_ENABLE;
46 #endif 46 #endif
  47 +
47 /* 48 /*
48 #ifdef USB_DEV_ENABLE 49 #ifdef USB_DEV_ENABLE
49 usbd_init(); 50 usbd_init();
@@ -89,7 +90,7 @@ void task_usbotg(void *pvParameters) @@ -89,7 +90,7 @@ void task_usbotg(void *pvParameters)
89 { 90 {
90 case enIRP_USB_OPEN: 91 case enIRP_USB_OPEN:
91 92
92 -#if 0 93 + #if 0
93 usbd_init(); 94 usbd_init();
94 usbd_open(); 95 usbd_open();
95 96
@@ -98,11 +99,11 @@ void task_usbotg(void *pvParameters) @@ -98,11 +99,11 @@ void task_usbotg(void *pvParameters)
98 99
99 otg_init(); 100 otg_init();
100 otg_open(); 101 otg_open();
101 -#endif 102 + #endif
102 103
103 -#ifndef OTG_FORCE_FULL_SPEED 104 + #ifndef OTG_FORCE_FULL_SPEED
104 usb_highspeed_flag = TRUE; 105 usb_highspeed_flag = TRUE;
105 -#endif 106 + #endif
106 107
107 irp->target = enIRPT_USBD; 108 irp->target = enIRPT_USBD;
108 irp->type = enIRP_USBHOST_START; 109 irp->type = enIRP_USBHOST_START;
@@ -122,7 +123,7 @@ void task_usbotg(void *pvParameters) @@ -122,7 +123,7 @@ void task_usbotg(void *pvParameters)
122 (*irp->complete) ( irp->result, irp->actualLen ); 123 (*irp->complete) ( irp->result, irp->actualLen );
123 } 124 }
124 125
125 -#if 0 126 + #if 0
126 //usbd_fini(); 127 //usbd_fini();
127 //usbd_clsoe(); 128 //usbd_clsoe();
128 129
@@ -131,16 +132,16 @@ void task_usbotg(void *pvParameters) @@ -131,16 +132,16 @@ void task_usbotg(void *pvParameters)
131 132
132 //otg_fini(); 133 //otg_fini();
133 otg_close(); 134 otg_close();
134 -#endif 135 + #endif
135 136
136 break; 137 break;
137 138
138 case enIRPT_USBD: 139 case enIRPT_USBD:
139 //DBG_Printf("enIRPT_USBD\n"); 140 //DBG_Printf("enIRPT_USBD\n");
140 141
141 -#ifndef OTG_FORCE_FULL_SPEED 142 + #ifndef OTG_FORCE_FULL_SPEED
142 usb_highspeed_flag = TRUE; 143 usb_highspeed_flag = TRUE;
143 -#endif 144 + #endif
144 145
145 usbd_IRPprocess( irp ); 146 usbd_IRPprocess( irp );
146 if( irp->complete != NULL ) 147 if( irp->complete != NULL )
@@ -157,13 +158,13 @@ void task_usbotg(void *pvParameters) @@ -157,13 +158,13 @@ void task_usbotg(void *pvParameters)
157 break; 158 break;
158 159
159 160
160 -#if 0 161 + #if 0
161 case enIRPT_HUB: 162 case enIRPT_HUB:
162 hub_IRPprocess( irp ); 163 hub_IRPprocess( irp );
163 break; 164 break;
164 -#endif 165 + #endif
165 166
166 -#ifdef PTP_MTP_CLASS 167 + #ifdef PTP_MTP_CLASS
167 case enIRPT_MTP: 168 case enIRPT_MTP:
168 mtpClass_IRPprocess( irp ); 169 mtpClass_IRPprocess( irp );
169 if( irp->complete != NULL ) 170 if( irp->complete != NULL )
@@ -171,13 +172,13 @@ void task_usbotg(void *pvParameters) @@ -171,13 +172,13 @@ void task_usbotg(void *pvParameters)
171 (*irp->complete) ( irp->result, irp->actualLen ); 172 (*irp->complete) ( irp->result, irp->actualLen );
172 } 173 }
173 break; 174 break;
174 -#endif 175 + #endif
175 176
176 -#ifdef USB_DEV_ENABLE 177 + #ifdef USB_DEV_ENABLE
177 case enIRPT_DEV_STACK: 178 case enIRPT_DEV_STACK:
178 -#ifndef OTG_FORCE_FULL_SPEED 179 + #ifndef OTG_FORCE_FULL_SPEED
179 usb_highspeed_flag = TRUE; 180 usb_highspeed_flag = TRUE;
180 -#endif 181 + #endif
181 182
182 dstk_IRPprocess( irp ); 183 dstk_IRPprocess( irp );
183 if( irp->complete != NULL ) 184 if( irp->complete != NULL )
@@ -185,9 +186,9 @@ void task_usbotg(void *pvParameters) @@ -185,9 +186,9 @@ void task_usbotg(void *pvParameters)
185 (*irp->complete) ( irp->result, irp->actualLen ); 186 (*irp->complete) ( irp->result, irp->actualLen );
186 } 187 }
187 break; 188 break;
188 -#endif 189 + #endif
189 190
190 -#ifdef APPLE_IAP2_STACK 191 + #ifdef APPLE_IAP2_STACK
191 case enIRPT_IAP2: 192 case enIRPT_IAP2:
192 iap2stk_IRPprocess( irp ); 193 iap2stk_IRPprocess( irp );
193 if( irp->complete != NULL ) 194 if( irp->complete != NULL )
@@ -195,7 +196,7 @@ void task_usbotg(void *pvParameters) @@ -195,7 +196,7 @@ void task_usbotg(void *pvParameters)
195 (*irp->complete) ( irp->result, irp->actualLen ); 196 (*irp->complete) ( irp->result, irp->actualLen );
196 } 197 }
197 break; 198 break;
198 -#endif 199 + #endif
199 200
200 default: 201 default:
201 HALT; 202 HALT;
@@ -345,7 +345,7 @@ typedef struct _AUDIO_STREAM_INTF { @@ -345,7 +345,7 @@ typedef struct _AUDIO_STREAM_INTF {
345 345
346 //The "IPOD_USB_AUDIO" macro is defined in the file of "oem_drogon.h" 346 //The "IPOD_USB_AUDIO" macro is defined in the file of "oem_drogon.h"
347 //the head file must use the macro below. 347 //the head file must use the macro below.
348 -#if 1//def IPOD_USB_AUDIO 348 +#if (defined AOA_USB_AUDIO || defined USB_HOST_AUDIO_ENABLE)
349 349
350 struct _IPOD_DEVICE; 350 struct _IPOD_DEVICE;
351 351
@@ -386,11 +386,23 @@ typedef struct _USB_DEVICE { @@ -386,11 +386,23 @@ typedef struct _USB_DEVICE {
386 // U32 tmpConfigBufTotalLen; 386 // U32 tmpConfigBufTotalLen;
387 // U32 tmpConfigTotalLen; 387 // U32 tmpConfigTotalLen;
388 388
389 -#if 1//(defined AOA_USB_AUDIO || defined USB_HOST_AUDIO_ENABLE)  
390 -#define CONFIG_BUF_SIZE 256 /*changed for AOA & USB Host Audio*/  
391 -#else  
392 -#define CONFIG_BUF_SIZE 64  
393 -#endif 389 + #if 1
  390 + #if 1//(defined AOA_USB_AUDIO || defined USB_HOST_AUDIO_ENABLE)
  391 + #define CONFIG_BUF_SIZE 256 /*changed for AOA & USB Host Audio*/
  392 + #else
  393 + #define CONFIG_BUF_SIZE 64
  394 + #endif
  395 + #endif
  396 +
  397 + #if 0
  398 + #if 1//(defined AOA_USB_AUDIO || defined USB_HOST_AUDIO_ENABLE)
  399 + #define CONFIG_BUF_SIZE 512 /*changed for AOA & USB Host Audio*/
  400 + //#define CONFIG_BUF_SIZE 384 /*changed for AOA & USB Host Audio*/
  401 + #else
  402 + #define CONFIG_BUF_SIZE 64
  403 + #endif
  404 + #endif
  405 +
394 //CONFIG despt + audioCtl i/f despt + 2x audioStream i/f despt + hid i/f 406 //CONFIG despt + audioCtl i/f despt + 2x audioStream i/f despt + hid i/f
395 407
396 U8 activeConfigVal; 408 U8 activeConfigVal;
@@ -134,6 +134,7 @@ U8 usbmsc_stopUSBhost( void ) @@ -134,6 +134,7 @@ U8 usbmsc_stopUSBhost( void )
134 134
135 if (!usbmsc_USBhostOpened) 135 if (!usbmsc_USBhostOpened)
136 { 136 {
  137 + DBG_TPrintf ("usbHost wasn't opened\n\r");
137 return TRUE; 138 return TRUE;
138 } 139 }
139 140
@@ -236,7 +237,7 @@ U8 usbmsc_USBhostOpenEx( enum_USB_HOST_STACK_ATTR attr ) @@ -236,7 +237,7 @@ U8 usbmsc_USBhostOpenEx( enum_USB_HOST_STACK_ATTR attr )
236 } 237 }
237 else 238 else
238 { 239 {
239 - DBG_Printf ("USB is open\n\r"); 240 + DBG_Printf ("usbHost opened\n\r");
240 } 241 }
241 242
242 return TRUE; 243 return TRUE;
  1 +#include "c_def.h"
  2 +#include "oem.h"
  3 +#include "debug.h"
  4 +
  5 +
  6 +#if 1//def IPOD_USB_AUDIO
  7 +
  8 +#define MAX_RANGES 6
  9 +U8 utf8Byte0Range[MAX_RANGES] = {
  10 + 0x7F, //1 byte
  11 + 0xc0, //2 byte -
  12 + 0xe0, //3 byte -
  13 + 0xf0, //4 byte
  14 + 0xf8, //5
  15 + 0xfc //6
  16 +};
  17 +
  18 +
  19 +//don't do much check
  20 +static int getSize( U8 *utf8 )
  21 +{
  22 + int i;
  23 +
  24 + for( i = 1; i < MAX_RANGES; i ++ ) {
  25 + if( utf8[0] < utf8Byte0Range[i] ) break;
  26 + }
  27 +
  28 + if( (i == 1 ) && (utf8[0] > utf8Byte0Range[0]) ) i = 100; //make it err
  29 +
  30 + return i;
  31 +}
  32 +
  33 +//bigEndian
  34 +static U16 decodeWord( U8 **utf8 )
  35 +{
  36 + U8 *ptr = *utf8;
  37 + int size;
  38 + U16 tmp;
  39 +
  40 + size = getSize( ptr );
  41 + switch( size ) {
  42 + case 1:
  43 + tmp = ptr[0];
  44 + *utf8 += 1;
  45 + break;
  46 +
  47 + case 2:
  48 + tmp = ptr[0] & 0x1f;
  49 + tmp <<= 6;
  50 + tmp |= ptr[1] & 0x3f;
  51 +
  52 + *utf8 += 2;
  53 + break;
  54 +
  55 + case 3:
  56 + tmp = ptr[0] & 0x0f;
  57 + tmp <<= 6;
  58 + tmp |= ptr[1] & 0x3f;
  59 + tmp <<= 6;
  60 + tmp |= ptr[2] & 0x3f;
  61 +
  62 + *utf8 += 3;
  63 + break;
  64 +
  65 + default:
  66 + //err
  67 + tmp = 0;
  68 + }
  69 +
  70 + return tmp;
  71 +}
  72 +
  73 +//len is size in bytes
  74 +//maxlen/len16 is size in U16
  75 +//len16 include terminal null \0\0
  76 +int utf8_toUcs16( U8 *utf8, int len, U16 *ucs16, int maxlen )
  77 +{
  78 + int len16 = 0;
  79 + U16 t16;
  80 + U8 *ptr = utf8;
  81 +
  82 + do {
  83 + t16 = decodeWord( &ptr );
  84 + if (t16 == 0)
  85 + {
  86 + break;
  87 + }
  88 +
  89 + *ucs16 ++ = t16;
  90 +
  91 +#if 0
  92 + if( ++len16 >= maxlen ) {
  93 + --ucs16;
  94 + *ucs16 = 0;
  95 + break;
  96 + }
  97 +#else
  98 + if( len16 > maxlen ) {
  99 + *ucs16 = 0;
  100 + break;
  101 + }
  102 +
  103 + len16++;
  104 +#endif
  105 + } while( t16 != 0 );
  106 +
  107 +
  108 +#if 1
  109 + return len16;
  110 +#else
  111 + if (len16 > 0)
  112 + {
  113 + len16 -= 1;
  114 + }
  115 +
  116 + return len16;
  117 +#endif
  118 +}
  119 +
  120 +
  121 +#endif //IPOD_USB_AUDIO
  1 +#ifndef __UTF8_H__
  2 +#define __UTF8_H__
  3 +
  4 +
  5 +//len is size in bytes
  6 +//maxlen/len16 is size in U16
  7 +//len16 include terminal null \0\0
  8 +int utf8_toUcs16( U8 *utf8, int len, U16 *ucs16, int maxlen );
  9 +
  10 +
  11 +#endif //__UTF8_H__
Please register or login to post a comment