Index: output/eeprom.dat
===================================================================
--- /YC1308AC/branch/usb/output/eeprom.dat	(revision 827)
+++ /YC1308AC/branch/usb/output/eeprom.dat	(working copy)
@@ -2,28 +2,36 @@
 02
 aa
 55
-46
-01
+1a
+02
 c2
 84
 00
-06
+08
+c0
+41
+80
+1c
 c0
 45
 80
-09
+12
+c0
+46
+00
+71
 c0
 57
 00
-11
+23
 c0
 5d
 80
-17
+33
 c0
 5e
 00
-19
+35
 20
 20
 13
@@ -31,17 +39,45 @@
 c0
 48
 00
-3a
+56
 c0
 4a
 80
-4b
+66
+c0
+54
+80
+0c
 20
 20
 13
 7c
 20
 40
+16
+a6
+70
+8a
+6d
+89
+6f
+f0
+8a
+43
+1f
+e1
+fe
+0f
+67
+f0
+8a
+43
+20
+60
+00
+00
+20
+40
 12
 d1
 20
@@ -61,6 +97,14 @@
 83
 90
 70
+8a
+85
+00
+70
+89
+21
+40
+70
 89
 68
 76
@@ -72,6 +116,34 @@
 20
 12
 56
+70
+89
+00
+05
+20
+00
+00
+02
+70
+89
+00
+00
+6f
+e0
+c0
+c5
+c0
+84
+11
+68
+70
+8a
+87
+29
+20
+20
+11
+7d
 d8
 40
 69
@@ -80,10 +152,50 @@
 40
 23
 20
-20
-40
+58
+00
+36
+4e
+67
+e1
+48
+89
+58
+00
+37
+01
+67
+e1
+48
+8d
+58
+00
+37
+12
+67
+e1
+48
+8f
+58
+00
+36
+f5
+67
+e1
+48
+8b
+58
+00
 36
+5b
+67
+e1
+0b
+45
 20
+40
+79
+9d
 20
 40
 62
@@ -99,7 +211,7 @@
 20
 40
 00
-15
+31
 20
 20
 36
@@ -119,7 +231,7 @@
 20
 40
 00
-1e
+3a
 20
 20
 36
@@ -131,11 +243,11 @@
 20
 40
 00
-21
+3d
 20
 20
 00
-2d
+49
 6f
 e0
 c9
@@ -251,7 +363,7 @@
 c0
 00
 00
-3f
+5b
 20
 20
 7a
@@ -274,12 +386,8 @@
 03
 c0
 00
-7a
-53
-c0
-00
 80
-46
+61
 20
 20
 7a
@@ -291,7 +399,7 @@
 c0
 04
 80
-49
+64
 20
 20
 7a
@@ -328,8 +436,112 @@
 20
 7c
 59
-50
+2f
+ef
+fe
+07
+24
+60
+80
+00
+d8
+40
+ff
+00
+98
+41
+fe
+00
+20
+60
+00
+00
+6f
+f0
+89
+a2
+2f
+ef
+fe
+06
+79
+20
+fe
+07
+67
+e0
+c1
+e9
+6f
+f0
+89
+a3
+1f
+e1
+04
 0f
+18
+43
+84
+00
+1f
+f1
+fe
+00
+98
+40
+84
+00
+18
+4f
+a2
+03
+6f
+e0
+c1
+e9
+20
+40
+00
+6c
+1f
+e6
+7e
+00
+9a
+20
+fe
+00
+1f
+e0
+ff
+f7
+1f
+e1
+7f
+ff
+2f
+ef
+fe
+08
+24
+20
+80
+84
+58
+00
+00
+00
+67
+e0
+80
+19
+20
+20
+12
+91
+01
+02
 aa
 55
 40
@@ -352,8 +564,8 @@
 00
 00
 00
-00
 08
+18
 00
 00
 00
@@ -389,7 +601,7 @@
 21
 00
 00
-00
+02
 00
 00
 00
@@ -422,8 +634,8 @@
 00
 a8
 40
-38
-26
+37
+28
 10
 30
 11
@@ -495,11 +707,5 @@
 ee
 41
 00
-55
-aa
-aa
-55
-44
-1b
-7c
-cd
+e4
+1d
Index: output/program.lis
===================================================================
--- /YC1308AC/branch/usb/output/program.lis	(revision 827)
+++ /YC1308AC/branch/usb/output/program.lis	(working copy)
@@ -1,114 +1,179 @@
               include "bt_format "
               org 0x0000
-0000 c2840006 bbit1 8 ,pf_patch_ext 
-0001 c0458009 beq patch11_3 ,p_initialize_radio_cont 
-0002 c0570011 beq patch15_6 ,p_app_init 
-0003 c05d8017 beq patch17_3 ,p_dongle_usb_dispatch 
-0004 c05e0019 beq patch17_4 ,p_dongle_work_mode_auto 
-0005 2020137c branch loop 
+0000 c2840008 bbit1 8 ,pf_patch_ext 
+0001 c041801c beq patch10_3 ,p_set_sync_on 
+0002 c0458012 beq patch11_3 ,p_initialize_radio_cont 
+0003 c0460071 beq patch11_4 ,p_save_rssi 
+0004 c0570023 beq patch15_6 ,p_app_init 
+0005 c05d8033 beq patch17_3 ,p_dongle_usb_dispatch 
+0006 c05e0035 beq patch17_4 ,p_dongle_work_mode_auto 
+0007 2020137c branch loop 
 
 pf_patch_ext:
-0006 c048003a beq patch32_0 ,p_usb_class_type 
-0007 c04a804b beq patch32_5 ,p_usb_tx 
-0008 2020137c branch loop 
+0008 c0480056 beq patch32_0 ,p_usb_class_type 
+0009 c04a8066 beq patch32_5 ,p_usb_tx 
+000a c054800c beq patch35_1 ,p_le_enable 
+000b 2020137c branch loop 
+
+p_le_enable:
+000c 204016a6 call le_enable + 1 
+000d 708a6d89 jam 0x89 ,core_rx_bq_cfg0 
+000e 6ff08a43 fetch 1 ,core_syn_cal_ctrl 
+000f 1fe1fe0f or pdata ,0x0f ,pdata 
+0010 67f08a43 store 1 ,core_syn_cal_ctrl 
+0011 20600000 rtn 
 
 p_initialize_radio_cont:
-0009 204012d1 call init_lpm_ctrl 
-000a 20000064 nop 100 
-000b 708a0e0b jam 0x0b ,core_rf_ldo_cfg2 
-000c 708a0f05 jam 0x05 ,core_rf_ldo_cfg3 
-000d 708a8390 jam 0x90 ,core_syn_pfd_lkd_cfg 
-000e 70896876 jam 0x76 ,core_agc_wb_sat_th 
-000f 70896976 jam 0x76 ,core_agc_nb_sat_th 
-0010 20201256 branch initialize_radio_cont + 1 
+0012 204012d1 call init_lpm_ctrl 
+0013 20000064 nop 100 
+0014 708a0e0b jam 0x0b ,core_rf_ldo_cfg2 
+0015 708a0f05 jam 0x05 ,core_rf_ldo_cfg3 
+0016 708a8390 jam 0x90 ,core_syn_pfd_lkd_cfg 
+0017 708a8500 jam 0x00 ,core_syn_loopdiv_dsm_cfg 
+0018 70892140 jam 0x40 ,0x8921 
+0019 70896876 jam 0x76 ,core_agc_wb_sat_th 
+001a 70896976 jam 0x76 ,core_agc_nb_sat_th 
+001b 20201256 branch initialize_radio_cont + 1 
+
+p_set_sync_on:
+001c 70890005 jam 0x5 ,modem_en 
+001d 20000002 nop 2 
+001e 70890000 jam 0x0 ,modem_en 
+001f 6fe0c0c5 fetch 1 ,mem_fcomp_div 
+0020 c0841168 bne xtal_16m ,set_sync_on_24m 
+
+p_set_sync_on_16m:
+0021 708a8729 jam 0x29 ,core_syn_afc_cfg1 
+0022 2020117d branch set_sync_on_16m 
 
 p_app_init:
-0011 d8406978 arg 0x6978 ,temp 
-0012 20402320 call g24_rx_window_store 
-0013 20403620 call dongle_init 
-0014 2040623c call wdt_set_enable 
+0023 d8406978 arg 0x6978 ,temp 
+0024 20402320 call g24_rx_window_store 
+0025 5800364e setarg dongle_dispatch 
+0026 67e14889 store 2 ,mem_cb_24g_receive_process 
+0027 58003701 setarg dongle_g24_mouse 
+0028 67e1488d store 2 ,mem_cb_24g_data_device1 
+0029 58003712 setarg dongle_g24_kb 
+002a 67e1488f store 2 ,mem_cb_24g_data_device2 
+002b 580036f5 setarg dongle_ackpayload_prep 
+002c 67e1488b store 2 ,mem_cb_24g_ackpayload 
+002d 5800365b setarg dongle_usb_config 
+002e 67e10b45 store 2 ,mem_cb_usb_config 
+002f 2040799d call usb_init 
+0030 2040623c call wdt_set_enable 
 
 p_wdt_kick:
-0015 5800007d setarg 125 
-0016 2020622d branch wdt_init_config 
+0031 5800007d setarg 125 
+0032 2020622d branch wdt_init_config 
 
 p_dongle_usb_dispatch:
-0017 20400015 call p_wdt_kick 
-0018 202036b5 branch dongle_usb_dispatch + 1 
+0033 20400031 call p_wdt_kick 
+0034 202036b5 branch dongle_usb_dispatch + 1 
 
 p_dongle_work_mode_auto:
-0019 6fe0c8bf fetch 1 ,mem_24g_work_mode 
-001a c1800000 rtnne dongle_work 
-001b 20402491 call g24_work_mode_start 
-001c 2040001e call p_dongle_g24_blank_data_process 
-001d 202036f2 branch dongle_work_mode_auto + 5 
+0035 6fe0c8bf fetch 1 ,mem_24g_work_mode 
+0036 c1800000 rtnne dongle_work 
+0037 20402491 call g24_work_mode_start 
+0038 2040003a call p_dongle_g24_blank_data_process 
+0039 202036f2 branch dongle_work_mode_auto + 5 
 
 p_dongle_g24_blank_data_process:
-001e 2040368a call dongle_g24_ms_blank_data 
-001f 20400021 call p_dongle_g24_kb_blank_data 
-0020 2020002d branch p_dongle_g24_kb_mul_blank_data 
+003a 2040368a call dongle_g24_ms_blank_data 
+003b 2040003d call p_dongle_g24_kb_blank_data 
+003c 20200049 branch p_dongle_g24_kb_mul_blank_data 
 
 p_dongle_g24_kb_blank_data:
-0021 6fe0c906 fetch 1 ,mem_dg_kb_blank_data_enable 
-0022 207a0000 rtn blank 
-0023 d8e0000e arg timer_kb_blank ,queue 
-0024 20407d74 call timer_check 
-0025 247a0000 nrtn blank 
-0026 70490600 jam 0 ,mem_dg_kb_blank_data_enable 
-0027 d8a00c0f arg mem_usb_kb_data ,contw 
-0028 df200002 arg 2 ,loopcnt 
-0029 20407d17 call memset0 
-002a 6fe40c0f fetch 8 ,mem_usb_kb_data 
-002b 67e448f2 store 8 ,mem_dg_kb_data_last_data 
-002c 202036a2 branch dongle_usb_tx_kb_data 
+003d 6fe0c906 fetch 1 ,mem_dg_kb_blank_data_enable 
+003e 207a0000 rtn blank 
+003f d8e0000e arg timer_kb_blank ,queue 
+0040 20407d74 call timer_check 
+0041 247a0000 nrtn blank 
+0042 70490600 jam 0 ,mem_dg_kb_blank_data_enable 
+0043 d8a00c0f arg mem_usb_kb_data ,contw 
+0044 df200002 arg 2 ,loopcnt 
+0045 20407d17 call memset0 
+0046 6fe40c0f fetch 8 ,mem_usb_kb_data 
+0047 67e448f2 store 8 ,mem_dg_kb_data_last_data 
+0048 202036a2 branch dongle_usb_tx_kb_data 
 
 p_dongle_g24_kb_mul_blank_data:
-002d 6fe0c907 fetch 1 ,mem_dg_kb_mul_blank_data_enable 
-002e 207a0000 rtn blank 
-002f d8e0000c arg timer_kb_mul_blank ,queue 
-0030 20407d74 call timer_check 
-0031 247a0000 nrtn blank 
-0032 70490700 jam 0 ,mem_dg_kb_mul_blank_data_enable 
-0033 d8a00c1f arg mem_usb_kb_multikey ,contw 
-0034 df200002 arg 2 ,loopcnt 
-0035 20407d17 call memset0 
-0036 700c1f03 jam kb_multikey_report_id ,mem_usb_kb_multikey 
-0037 6fe18c1f fetch 3 ,mem_usb_kb_multikey 
-0038 67e1c8fd store 3 ,mem_dg_kb_multikey_last_data 
-0039 202036b2 branch dongle_usb_tx_multikey_data 
+0049 6fe0c907 fetch 1 ,mem_dg_kb_mul_blank_data_enable 
+004a 207a0000 rtn blank 
+004b d8e0000c arg timer_kb_mul_blank ,queue 
+004c 20407d74 call timer_check 
+004d 247a0000 nrtn blank 
+004e 70490700 jam 0 ,mem_dg_kb_mul_blank_data_enable 
+004f d8a00c1f arg mem_usb_kb_multikey ,contw 
+0050 df200002 arg 2 ,loopcnt 
+0051 20407d17 call memset0 
+0052 700c1f03 jam kb_multikey_report_id ,mem_usb_kb_multikey 
+0053 6fe18c1f fetch 3 ,mem_usb_kb_multikey 
+0054 67e1c8fd store 3 ,mem_dg_kb_multikey_last_data 
+0055 202036b2 branch dongle_usb_tx_multikey_data 
 
 p_usb_class_type:
-003a 793f8023 set0 mark_isstr ,mark 
-003b 6fe08b59 fetch 1 ,mem_usb_setup_bmrequesttype 
-003c 1fe17e80 and_into 0x80 ,pdata 
-003d c000003f beq out_device ,p_usb_out_device 
-003e 20207a34 branch usb_class_type + 4 
+0056 793f8023 set0 mark_isstr ,mark 
+0057 6fe08b59 fetch 1 ,mem_usb_setup_bmrequesttype 
+0058 1fe17e80 and_into 0x80 ,pdata 
+0059 c000005b beq out_device ,p_usb_out_device 
+005a 20207a34 branch usb_class_type + 4 
 
 p_usb_out_device:
-003f 6fe08b59 fetch 1 ,mem_usb_setup_bmrequesttype 
-0040 1ff1fe00 rshift4 pdata ,pdata 
-0041 1fe37e00 rshift pdata ,pdata 
-0042 1fe17e03 and_into 0x03 ,pdata 
-0043 c0007a53 beq standard_req ,usb_out_standard_req 
-0044 c0008046 beq class_req ,p_usb_out_class_req 
-0045 20207a43 branch usb_out_device + 4 
+005b 6fe08b59 fetch 1 ,mem_usb_setup_bmrequesttype 
+005c 1ff1fe00 rshift4 pdata ,pdata 
+005d 1fe37e00 rshift pdata ,pdata 
+005e 1fe17e03 and_into 0x03 ,pdata 
+005f c0008061 beq class_req ,p_usb_out_class_req 
+0060 20207a43 branch usb_out_device + 4 
 
 p_usb_out_class_req:
-0046 6fe08b5a fetch 1 ,mem_usb_setup_brequest 
-0047 c0048049 beq set_report ,p_usb_set_report 
-0048 20207a5c branch usb_out_class_req + 1 
+0061 6fe08b5a fetch 1 ,mem_usb_setup_brequest 
+0062 c0048064 beq set_report ,p_usb_set_report 
+0063 20207a5c branch usb_out_class_req + 1 
 
 p_usb_set_report:
-0049 20003a98 nop 15000 
-004a 20207bd8 branch usb_set_report 
+0064 20003a98 nop 15000 
+0065 20207bd8 branch usb_set_report 
 
 p_usb_tx:
-004b 6fe08bf9 fetch 1 ,mem_usb_tx_enable 
-004c 207a0000 rtn blank 
-004d 6ff08c24 fetch 1 ,core_usb_txbusy 
-004e 1fe17e0f and_into 0x0f ,pdata 
-004f 243a7ca4 nbranch usb_inwake_state_tx_dispose ,blank 
-0050 20207c59 branch usb_tx + 3 
+0066 6fe08bf9 fetch 1 ,mem_usb_tx_enable 
+0067 207a0000 rtn blank 
+0068 6ff08c24 fetch 1 ,core_usb_txbusy 
+0069 1fe17e0f and_into 0x0f ,pdata 
+006a 243a7ca4 nbranch usb_inwake_state_tx_dispose ,blank 
+006b 20207c59 branch usb_tx + 3 
+
+p_byte_sign_extern:
+006c 2feffe07 isolate1 7 ,pdata 
+006d 24608000 nrtn true 
+006e d840ff00 arg 0xff00 ,temp 
+006f 9841fe00 ior temp ,pdata 
+0070 20600000 rtn 
+
+p_save_rssi:
+0071 6ff089a2 fetch 1 ,modem_nb_pow 
+0072 2feffe06 isolate1 6 ,pdata 
+0073 7920fe07 setflag true ,7 ,pdata 
+0074 67e0c1e9 store 1 ,mem_modem_rssi 
+0075 6ff089a3 fetch 1 ,modem_gain 
+0076 1fe1040f and pdata ,0x0f ,temp 
+0077 18438400 lshift temp ,temp 
+0078 1ff1fe00 rshift4 pdata ,pdata 
+0079 98408400 iadd temp ,temp 
+007a 184fa203 mul32 temp ,3 ,rega 
+007b 6fe0c1e9 fetch 1 ,mem_modem_rssi 
+007c 2040006c call p_byte_sign_extern 
+007d 1fe67e00 sub pdata ,0 ,pdata 
+007e 9a20fe00 iadd rega ,pdata 
+007f 1fe0fff7 increase -9 ,pdata 
+0080 1fe17fff and pdata ,0x1ff ,pdata 
+0081 2feffe08 isolate1 8 ,pdata 
+0082 24208084 nbranch p_save_rssi_store ,true 
+0083 58000000 setarg 0 
+
+p_save_rssi_store:
+0084 67e08019 store 1 ,mem_rssi_hex 
+0085 20201291 branch rssi_hex2dec 
               org 0x800
 
 start:
Index: program/patch.prog
===================================================================
--- /YC1308AC/branch/usb/program/patch.prog	(revision 827)
+++ /YC1308AC/branch/usb/program/patch.prog	(working copy)
@@ -1,6 +1,9 @@
+//define KEYBOARD
 
 	bbit1 8,pf_patch_ext
+	beq patch10_3,p_set_sync_on
 	beq patch11_3,p_initialize_radio_cont
+	beq patch11_4,p_save_rssi
 	beq patch15_6,p_app_init
 	beq patch17_3,p_dongle_usb_dispatch
 	beq patch17_4,p_dongle_work_mode_auto
@@ -9,7 +12,16 @@
 pf_patch_ext:
 	beq patch32_0,p_usb_class_type
 	beq patch32_5,p_usb_tx
+	beq patch35_1,p_le_enable
 	branch loop
+
+p_le_enable:
+	call le_enable+1
+	jam 0x89,core_rx_bq_cfg0
+	fetch 1,core_syn_cal_ctrl
+	or pdata,0x0f,pdata
+	store 1,core_syn_cal_ctrl
+	rtn
 	
 
 /********************rx fail patch************************/
@@ -23,19 +35,47 @@
 	jam 0x05,core_rf_ldo_cfg3
 	jam 0x90,core_syn_pfd_lkd_cfg
 
+	jam 0x00,core_syn_loopdiv_dsm_cfg
+	jam 0x40,0x8921
+
 	//Improve auto agc
 	jam 0x76,core_agc_wb_sat_th
 	jam 0x76,core_agc_nb_sat_th
 
 	branch initialize_radio_cont+1
 
+p_set_sync_on:
+	jam 0x5,modem_en
+	nop 2
+	jam 0x0,modem_en					/* if called from tx or rx */
+	fetch 1,mem_fcomp_div
+	bne XTAL_16M,set_sync_on_24m
+p_set_sync_on_16m:
+	jam 0x29,core_syn_afc_cfg1
+	branch set_sync_on_16m
+
 
 p_app_init:
 /********************dongle rx window patch************************/
 	arg 0x6978,temp
 	call g24_rx_window_store
 
-	call dongle_init
+	setarg dongle_dispatch
+	store 2,mem_cb_24g_receive_process
+	setarg dongle_g24_mouse
+	store 2,mem_cb_24g_data_device1
+	setarg dongle_g24_kb
+	store 2,mem_cb_24g_data_device2
+	setarg dongle_ackpayload_prep
+	store 2,mem_cb_24g_ackpayload
+
+	setarg dongle_usb_config
+	store 2,mem_cb_usb_config
+
+ifdef KEYBOARD
+	jam DONGLE_KB_BIND_SUCCESS,mem_dg_kb_bind_flag
+endif
+	call usb_init
 	
 	//watch dog enable
 	call wdt_set_enable
@@ -108,7 +148,6 @@
 	rshift4 pdata,pdata
 	rshift pdata,pdata
 	and_into 0x03,pdata
-	beq STANDARD_REQ,usb_out_standard_req
 	beq CLASS_REQ,p_usb_out_class_req
 	branch usb_out_device+4
 
@@ -132,6 +171,38 @@
 	nbranch usb_inwake_state_tx_dispose,blank
 	branch usb_tx+3
 
-
+p_byte_sign_extern:
+	isolate1 7,pdata
+	nrtn true
+	arg 0xff00,temp
+	ior temp,pdata
+	rtn
+
+p_save_rssi:
+	// bit6 is signed bit. 
+	fetch 1,modem_nb_pow 
+	isolate1 6,pdata 
+	setflag true,7,pdata 
+	store 1,mem_modem_rssi 
+	
+	fetch 1,modem_gain 
+	and pdata,0x0f,temp 
+	lshift temp,temp 
+	rshift4 pdata,pdata 
+	iadd temp,temp 
+	mul32 temp,3,rega // (abb_gain + lna_gain*2)*3 
+
+	fetch 1,mem_modem_rssi 
+	call p_byte_sign_extern 
+	sub pdata,0,pdata //-modem_nb_pow 
+	iadd rega,pdata // (abb_gain + lna_gain*2)*3 + (-modem_nb_pow) 
+	increase -9,pdata // (abb_gain + lna_gain*2)*3 + (-modem_nb_pow) - 9 
+	and pdata,0x1ff,pdata 
+	isolate1 8,pdata 
+	nbranch p_save_rssi_store,true 
+	setarg 0 
+p_save_rssi_store:
+	store 1,mem_rssi_hex
+	branch rssi_hex2dec
 	
 
Index: sched/dongle.dat
===================================================================
--- /YC1308AC/branch/usb/sched/dongle.dat	(revision 827)
+++ /YC1308AC/branch/usb/sched/dongle.dat	(working copy)
@@ -24,7 +24,7 @@
 
 
 #rf config
-mem_lap:37 26 10 30 11 12#low 4B used for 24g rxaddr
+mem_lap:37 28 10 30 11 12#low 4B used for 24g rxaddr
 #mem_24g_tx_phy:01#0x01:1M/0x02:2M/0x04:S2/0x84:S8
 #mem_24g_rx_phy:01#0x01:1M/0x02:2M/0x04:S2/0x84:S8
 #mem_24g_no_ack:00#no ack
