Index: format/app_dongle.format
===================================================================
--- /branch/usb/usb_public_base/format/app_dongle.format	(revision 204)
+++ /branch/usb/usb_public_base/format/app_dongle.format	(working copy)
@@ -33,6 +33,18 @@
 
 1 mem_24g_device1_bind_disable
 1 mem_24g_device2_bind_disable
+
+
+//uart start 
+1 mem_device_uart_tx_gpio
+1 mem_device_uart_rx_gpio
+2 mem_device_uart_rx_buffer
+2 mem_device_uart_rx_buffer_end
+2 mem_device_uart_tx_buffer
+2 mem_device_uart_tx_buffer_end
+2 mem_device_uart_baud_rate
+//uart end
+
 )
 
 
Index: output/eeprom.dat
===================================================================
--- /branch/usb/usb_public_base/output/eeprom.dat	(revision 204)
+++ /branch/usb/usb_public_base/output/eeprom.dat	(working copy)
@@ -2,8 +2,8 @@
 02
 aa
 55
-ae
-02
+1a
+03
 c2
 84
 00
@@ -15,7 +15,7 @@
 c0
 01
 80
-80
+9b
 c0
 0b
 b9
@@ -27,27 +27,27 @@
 c0
 4a
 80
-9d
+b8
 c0
 5c
 80
-1b
+22
 c0
 6a
 80
-63
+7e
 c0
 6f
 00
-68
+83
 c0
 71
 00
-83
+9e
 c0
 74
 00
-8d
+a8
 20
 20
 3a
@@ -59,7 +59,7 @@
 c0
 1d
 80
-2c
+33
 20
 20
 3a
@@ -104,14 +104,42 @@
 40
 3c
 41
-70
+58
+00
+52
+7c
+67
+e1
 45
-6d
-01
+23
+58
+00
+53
+5a
+67
+e1
+45
+27
+58
+00
+53
+6b
+67
+e1
+45
+29
+58
+00
+00
+6a
+67
+e1
+45
+25
 20
 20
 52
-49
+51
 20
 40
 6f
@@ -187,15 +215,15 @@
 c0
 55
 00
-31
+38
 c0
 2a
 80
-3b
+42
 c0
 11
 00
-4b
+52
 20
 20
 49
@@ -207,11 +235,11 @@
 c0
 00
 80
-35
+3c
 c0
 01
 00
-38
+3f
 20
 60
 00
@@ -247,7 +275,7 @@
 20
 3a
 00
-41
+48
 6f
 e2
 45
@@ -271,11 +299,11 @@
 c0
 00
 80
-45
+4c
 c0
 01
 00
-48
+4f
 20
 60
 00
@@ -311,7 +339,7 @@
 20
 3a
 00
-51
+58
 6f
 e2
 45
@@ -335,11 +363,11 @@
 c0
 00
 80
-55
+5c
 c0
 01
 00
-5c
+63
 20
 60
 00
@@ -359,7 +387,7 @@
 c0
 01
 00
-5a
+61
 20
 60
 00
@@ -387,7 +415,7 @@
 c0
 80
 00
-61
+68
 20
 60
 00
@@ -400,6 +428,86 @@
 20
 4a
 0c
+6f
+e0
+c4
+cf
+c0
+00
+80
+6d
+c0
+01
+00
+73
+6f
+e0
+c5
+d5
+c2
+80
+53
+43
+6f
+e0
+c5
+54
+c0
+00
+80
+76
+c0
+01
+80
+7a
+20
+60
+00
+00
+6f
+e0
+c5
+d5
+c2
+80
+d3
+47
+20
+20
+00
+6f
+70
+45
+54
+01
+20
+40
+4a
+15
+24
+77
+80
+00
+20
+20
+49
+ab
+6f
+e0
+c4
+3f
+c0
+00
+80
+76
+c0
+7f
+80
+76
+20
+20
+53
+55
 18
 42
 7e
@@ -407,7 +515,7 @@
 c2
 80
 80
-66
+81
 20
 20
 3d
@@ -427,7 +535,7 @@
 c5
 97
 80
-6e
+89
 78
 3c
 fc
@@ -471,7 +579,7 @@
 20
 37
 00
-77
+92
 1b
 42
 04
@@ -523,7 +631,7 @@
 24
 22
 80
-7e
+99
 20
 20
 38
@@ -611,7 +719,7 @@
 c5
 16
 80
-99
+b4
 20
 20
 3e
@@ -627,7 +735,7 @@
 c2
 00
 00
-9a
+b5
 20
 20
 3f
@@ -688,8 +796,8 @@
 20
 6c
 a7
-64
-00
+e1
+10
 aa
 55
 40
@@ -802,7 +910,7 @@
 37
 44
 39
-28
+29
 13
 30
 06
@@ -972,7 +1080,7 @@
 aa
 aa
 55
-50
+51
 3a
-d7
-c1
+6e
+d6
Index: output/memmap.format
===================================================================
--- /branch/usb/usb_public_base/output/memmap.format	(revision 204)
+++ /branch/usb/usb_public_base/output/memmap.format	(working copy)
@@ -1323,6 +1323,13 @@
 0x45d6 mem_dg_24g_tx_power_default
 0x45d7 mem_24g_device1_bind_disable
 0x45d8 mem_24g_device2_bind_disable
+0x45d9 mem_device_uart_tx_gpio
+0x45da mem_device_uart_rx_gpio
+0x45db mem_device_uart_rx_buffer
+0x45dd mem_device_uart_rx_buffer_end
+0x45df mem_device_uart_tx_buffer
+0x45e1 mem_device_uart_tx_buffer_end
+0x45e3 mem_device_uart_baud_rate
 0x4518 mem_rssi_hex_received
 0x4519 mem_24g_pair_sm
 0x451a mem_24g_pair_no_ack
Index: output/program.lis
===================================================================
--- /branch/usb/usb_public_base/output/program.lis	(revision 204)
+++ /branch/usb/usb_public_base/output/program.lis	(working copy)
@@ -2,20 +2,20 @@
               org 0x0000
 0000 c284000c bbit1 8 ,pf_patch_ext 
 0001 c000000f beq patch00_0 ,p_soft_reset 
-0002 c0018080 beq patch00_3 ,p_connection_incontext 
+0002 c001809b beq patch00_3 ,p_connection_incontext 
 0003 c00bb9ff beq patch02_7 ,set_tx_power_10db 
 0004 c0310014 beq patch0c_2 ,p_app_init 
-0005 c04a809d beq patch12_5 ,p_enable_adc 
-0006 c05c801b beq patch17_1 ,p_usb_init 
-0007 c06a8063 beq patch1a_5 ,p_le_enable_phy_by_pdata 
-0008 c06f0068 beq patch1b_6 ,p_le_receive_rxon 
-0009 c0710083 beq patch1c_2 ,p_le_crc_fail_tx 
-000a c074008d beq patch1d_0 ,p_le_transmit 
+0005 c04a80b8 beq patch12_5 ,p_enable_adc 
+0006 c05c8022 beq patch17_1 ,p_usb_init 
+0007 c06a807e beq patch1a_5 ,p_le_enable_phy_by_pdata 
+0008 c06f0083 beq patch1b_6 ,p_le_receive_rxon 
+0009 c071009e beq patch1c_2 ,p_le_crc_fail_tx 
+000a c07400a8 beq patch1d_0 ,p_le_transmit 
 000b 20203aba branch assert 
 
 pf_patch_ext:
 000c c17f8000 rtneq patch3f_7 
-000d c01d802c beq patch27_3 ,p_g24_bind_data_parse_next 
+000d c01d8033 beq patch27_3 ,p_g24_bind_data_parse_next 
 000e 20203aba branch assert 
 
 p_soft_reset:
@@ -33,206 +33,245 @@
 0016 20758000 rtn wake 
 0017 7040cc3a jam hvin_vin_greater_than_4v2 ,mem_lpm_ctrl3 
 0018 20403c41 call lpm_write_sel_vdd 
-0019 70456d01 jam 1 ,mem_24g_b_s_mode_switch_disable 
-001a 20205249 branch dongle_init 
+0019 5800527c setarg dongle_dispatch 
+001a 67e14523 store 2 ,mem_cb_24g_receive_process 
+001b 5800535a setarg dongle_g24_mouse 
+001c 67e14527 store 2 ,mem_cb_24g_data_device1 
+001d 5800536b setarg dongle_g24_kb 
+001e 67e14529 store 2 ,mem_cb_24g_data_device2 
+001f 5800006a setarg p_dongle_ackpayload_prep 
+0020 67e14525 store 2 ,mem_cb_24g_ackpayload 
+0021 20205251 branch dongle_init + 8 
 
 p_usb_init:
-001b 20406fd3 call enable_authrom 
-001c 204071a1 call usb_init_param 
-001d 70061003 jam 0x03 ,mem_devicedesc + 17 
-001e 708c0000 jam 0x00 ,core_usb_config 
-001f 20002710 nop 10000 
-0020 708c1800 jam 0x00 ,core_usb_trig 
-0021 6ff10050 fetch 2 ,core_clkoff 
-0022 793ffe0a set0 clock_off_usb ,pdata 
-0023 67f10050 store 2 ,core_clkoff 
-0024 708c1100 jam 0x0 ,core_usb_hmode 
-0025 708c003c jam 0x3c ,core_usb_config 
-0026 58000bb3 setarg mem_usb_rxbuf_new 
-0027 67f10c03 store 2 ,core_usb_rx_saddr 
-0028 67f10c07 store 2 ,core_usb_rxptr 
-0029 58000bf7 setarg mem_usb_rxbuf_new_end 
-002a 67f10c05 store 2 ,core_usb_rx_eaddr 
-002b 20207192 branch usb_init + 16 
+0022 20406fd3 call enable_authrom 
+0023 204071a1 call usb_init_param 
+0024 70061003 jam 0x03 ,mem_devicedesc + 17 
+0025 708c0000 jam 0x00 ,core_usb_config 
+0026 20002710 nop 10000 
+0027 708c1800 jam 0x00 ,core_usb_trig 
+0028 6ff10050 fetch 2 ,core_clkoff 
+0029 793ffe0a set0 clock_off_usb ,pdata 
+002a 67f10050 store 2 ,core_clkoff 
+002b 708c1100 jam 0x0 ,core_usb_hmode 
+002c 708c003c jam 0x3c ,core_usb_config 
+002d 58000bb3 setarg mem_usb_rxbuf_new 
+002e 67f10c03 store 2 ,core_usb_rx_saddr 
+002f 67f10c07 store 2 ,core_usb_rxptr 
+0030 58000bf7 setarg mem_usb_rxbuf_new_end 
+0031 67f10c05 store 2 ,core_usb_rx_eaddr 
+0032 20207192 branch usb_init + 16 
 
 p_g24_bind_data_parse_next:
-002c 6fe0c52d fetch 1 ,mem_24g_rxdata_temp + 2 
-002d c0550031 beq datatype_bind ,p_g24_bind_first_step 
-002e c02a803b beq datatype_config ,p_g24_bind_second_step 
-002f c011004b beq datatype_ok ,p_g24_bind_third_step 
-0030 202049c8 branch g24_bind_data_parse_next + 4 
+0033 6fe0c52d fetch 1 ,mem_24g_rxdata_temp + 2 
+0034 c0550038 beq datatype_bind ,p_g24_bind_first_step 
+0035 c02a8042 beq datatype_config ,p_g24_bind_second_step 
+0036 c0110052 beq datatype_ok ,p_g24_bind_third_step 
+0037 202049c8 branch g24_bind_data_parse_next + 4 
 
 p_g24_bind_first_step:
-0031 6fe0c52e fetch 1 ,mem_24g_rxdata_temp + 3 
-0032 c0008035 beq datatype_device1 ,p_g24_bind_first_step_device1 
-0033 c0010038 beq datatype_device2 ,p_g24_bind_first_step_device2 
-0034 20600000 rtn 
+0038 6fe0c52e fetch 1 ,mem_24g_rxdata_temp + 3 
+0039 c000803c beq datatype_device1 ,p_g24_bind_first_step_device1 
+003a c001003f beq datatype_device2 ,p_g24_bind_first_step_device2 
+003b 20600000 rtn 
 
 p_g24_bind_first_step_device1:
-0035 6fe0c5d7 fetch 1 ,mem_24g_device1_bind_disable 
-0036 247a0000 nrtn blank 
-0037 202049ce branch g24_bind_first_step_device1 
+003c 6fe0c5d7 fetch 1 ,mem_24g_device1_bind_disable 
+003d 247a0000 nrtn blank 
+003e 202049ce branch g24_bind_first_step_device1 
 
 p_g24_bind_first_step_device2:
-0038 6fe0c5d8 fetch 1 ,mem_24g_device2_bind_disable 
-0039 247a0000 nrtn blank 
-003a 202049d4 branch g24_bind_first_step_device2 
+003f 6fe0c5d8 fetch 1 ,mem_24g_device2_bind_disable 
+0040 247a0000 nrtn blank 
+0041 202049d4 branch g24_bind_first_step_device2 
 
 p_g24_bind_second_step:
-003b 6fe0c4f4 fetch 1 ,mem_24g_pair_switch 
-003c 203a0041 branch p_g24_bind_second_step_skip ,blank 
-003d 6fe2452f fetch 4 ,mem_24g_rxdata_temp + 4 
-003e 684a4437 fetcht 4 ,mem_24g_lap 
-003f 98467c00 isub temp ,null 
-0040 24628000 nrtn zero 
+0042 6fe0c4f4 fetch 1 ,mem_24g_pair_switch 
+0043 203a0048 branch p_g24_bind_second_step_skip ,blank 
+0044 6fe2452f fetch 4 ,mem_24g_rxdata_temp + 4 
+0045 684a4437 fetcht 4 ,mem_24g_lap 
+0046 98467c00 isub temp ,null 
+0047 24628000 nrtn zero 
 
 p_g24_bind_second_step_skip:
-0041 6fe0c52e fetch 1 ,mem_24g_rxdata_temp + 3 
-0042 c0008045 beq datatype_device1 ,p_g24_bind_second_step_device1 
-0043 c0010048 beq datatype_device2 ,p_g24_bind_second_step_device2 
-0044 20600000 rtn 
+0048 6fe0c52e fetch 1 ,mem_24g_rxdata_temp + 3 
+0049 c000804c beq datatype_device1 ,p_g24_bind_second_step_device1 
+004a c001004f beq datatype_device2 ,p_g24_bind_second_step_device2 
+004b 20600000 rtn 
 
 p_g24_bind_second_step_device1:
-0045 6fe0c5d7 fetch 1 ,mem_24g_device1_bind_disable 
-0046 247a0000 nrtn blank 
-0047 202049e1 branch g24_bind_second_step_device1 
+004c 6fe0c5d7 fetch 1 ,mem_24g_device1_bind_disable 
+004d 247a0000 nrtn blank 
+004e 202049e1 branch g24_bind_second_step_device1 
 
 p_g24_bind_second_step_device2:
-0048 6fe0c5d8 fetch 1 ,mem_24g_device2_bind_disable 
-0049 247a0000 nrtn blank 
-004a 202049ec branch g24_bind_second_step_device2 
+004f 6fe0c5d8 fetch 1 ,mem_24g_device2_bind_disable 
+0050 247a0000 nrtn blank 
+0051 202049ec branch g24_bind_second_step_device2 
 
 p_g24_bind_third_step:
-004b 6fe0c4f4 fetch 1 ,mem_24g_pair_switch 
-004c 203a0051 branch p_g24_bind_third_step_skip ,blank 
-004d 6fe2452f fetch 4 ,mem_24g_rxdata_temp + 4 
-004e 684a456f fetcht 4 ,mem_24g_transmitter_addr 
-004f 98467c00 isub temp ,null 
-0050 24628000 nrtn zero 
+0052 6fe0c4f4 fetch 1 ,mem_24g_pair_switch 
+0053 203a0058 branch p_g24_bind_third_step_skip ,blank 
+0054 6fe2452f fetch 4 ,mem_24g_rxdata_temp + 4 
+0055 684a456f fetcht 4 ,mem_24g_transmitter_addr 
+0056 98467c00 isub temp ,null 
+0057 24628000 nrtn zero 
 
 p_g24_bind_third_step_skip:
-0051 6fe0c52e fetch 1 ,mem_24g_rxdata_temp + 3 
-0052 c0008055 beq datatype_device1 ,p_g24_bind_third_step_device1 
-0053 c001005c beq datatype_device2 ,p_g24_bind_third_step_device2 
-0054 20600000 rtn 
+0058 6fe0c52e fetch 1 ,mem_24g_rxdata_temp + 3 
+0059 c000805c beq datatype_device1 ,p_g24_bind_third_step_device1 
+005a c0010063 beq datatype_device2 ,p_g24_bind_third_step_device2 
+005b 20600000 rtn 
 
 p_g24_bind_third_step_device1:
-0055 6fe0c5d7 fetch 1 ,mem_24g_device1_bind_disable 
-0056 247a0000 nrtn blank 
-0057 6fe0c518 fetch 1 ,mem_24g_device1_bind_step 
-0058 c001005a beq 2 ,p_g24_bind_dvc1_step_success 
-0059 20600000 rtn 
+005c 6fe0c5d7 fetch 1 ,mem_24g_device1_bind_disable 
+005d 247a0000 nrtn blank 
+005e 6fe0c518 fetch 1 ,mem_24g_device1_bind_step 
+005f c0010061 beq 2 ,p_g24_bind_dvc1_step_success 
+0060 20600000 rtn 
 
 p_g24_bind_dvc1_step_success:
-005a 7045d701 jam 1 ,mem_24g_device1_bind_disable 
-005b 20204a01 branch g24_bind_dvc1_step_success 
+0061 7045d701 jam 1 ,mem_24g_device1_bind_disable 
+0062 20204a01 branch g24_bind_dvc1_step_success 
 
 p_g24_bind_third_step_device2:
-005c 6fe0c5d8 fetch 1 ,mem_24g_device2_bind_disable 
-005d 247a0000 nrtn blank 
-005e 6fe0c519 fetch 1 ,mem_24g_device2_bind_step 
-005f c0800061 bne 0 ,p_g24_bind_dvc2_step_success 
-0060 20600000 rtn 
+0063 6fe0c5d8 fetch 1 ,mem_24g_device2_bind_disable 
+0064 247a0000 nrtn blank 
+0065 6fe0c519 fetch 1 ,mem_24g_device2_bind_step 
+0066 c0800068 bne 0 ,p_g24_bind_dvc2_step_success 
+0067 20600000 rtn 
 
 p_g24_bind_dvc2_step_success:
-0061 7045d801 jam 1 ,mem_24g_device2_bind_disable 
-0062 20204a0c branch g24_bind_dvc2_step_success 
+0068 7045d801 jam 1 ,mem_24g_device2_bind_disable 
+0069 20204a0c branch g24_bind_dvc2_step_success 
+
+p_dongle_ackpayload_prep:
+006a 6fe0c4cf fetch 1 ,mem_24g_data_type 
+006b c000806d beq datatype_device1 ,p_dongle_ackpayload_prep_mouse 
+006c c0010073 beq datatype_device2 ,p_dongle_ackpayload_prep_keyboard 
+
+p_dongle_ackpayload_prep_mouse:
+006d 6fe0c5d5 fetch 1 ,mem_dg_pc_sleep_flag 
+006e c2805343 bbit1 0 ,dongle_pc_sleep_ackpayload_prep_mouse 
+
+p_dongle_ackpayload_prep_end:
+006f 6fe0c554 fetch 1 ,mem_24g_ackpayload_enable 
+0070 c0008076 beq bind_ackpayload ,p_dongle_g24_bind_ackpayload_prep 
+0071 c001807a beq kb_led_ackpayload ,p_dongle_g24_kb_led_ackpayload_prep 
+0072 20600000 rtn 
+
+p_dongle_ackpayload_prep_keyboard:
+0073 6fe0c5d5 fetch 1 ,mem_dg_pc_sleep_flag 
+0074 c280d347 bbit1 1 ,dongle_pc_sleep_ackpayload_prep_keyboard 
+0075 2020006f branch p_dongle_ackpayload_prep_end 
+
+p_dongle_g24_bind_ackpayload_prep:
+0076 70455401 jam 1 ,mem_24g_ackpayload_enable 
+0077 20404a15 call g24_binding_device_check + 2 
+0078 24778000 nrtn user3 
+0079 202049ab branch g24_bind_ackpayload_prep 
+
+p_dongle_g24_kb_led_ackpayload_prep:
+007a 6fe0c43f fetch 1 ,mem_24g_rxbuf + 2 
+007b c0008076 beq datatype_device1 ,p_dongle_g24_bind_ackpayload_prep 
+007c c07f8076 beq datatype_attemp ,p_dongle_g24_bind_ackpayload_prep 
+007d 20205355 branch dongle_g24_kb_led_ackpayload_prep + 3 
 
 p_le_enable_phy_by_pdata:
-0063 18427e00 copy temp ,pdata 
-0064 c2808066 bbit1 bit_le_2m_phy ,p_le_enable_2m 
-0065 20203d19 branch le_enable_phy_by_pdata + 3 
+007e 18427e00 copy temp ,pdata 
+007f c2808081 bbit1 bit_le_2m_phy ,p_le_enable_2m 
+0080 20203d19 branch le_enable_phy_by_pdata + 3 
 
 p_le_enable_2m:
-0066 708a6d89 jam 0x89 ,core_rx_bq_cfg0 
-0067 20203d1f branch le_enable_2m 
+0081 708a6d89 jam 0x89 ,core_rx_bq_cfg0 
+0082 20203d1f branch le_enable_2m 
 
 p_le_receive_rxon:
-0068 20403d3c call le_prep 
-0069 c597806e bmark0 mark_ble_lr ,p_le_receive_nolr 
-006a 783cfc00 pulse dewhiten_code_calc 
-006b 2000001e nop 30 
-006c 20403d3c call le_prep 
-006d 19699600 lshift3 timeup ,timeup 
+0083 20403d3c call le_prep 
+0084 c5978089 bmark0 mark_ble_lr ,p_le_receive_nolr 
+0085 783cfc00 pulse dewhiten_code_calc 
+0086 2000001e nop 30 
+0087 20403d3c call le_prep 
+0088 19699600 lshift3 timeup ,timeup 
 
 p_le_receive_nolr:
-006e 7856fc00 disable match 
-006f 7826fc00 enable decode_fec0 
-0070 7830fc00 enable is_rx 
-0071 78507c00 disable is_tx 
-0072 19623600 copy timeup ,stop_watch 
-0073 37c18400 correlate null ,timeout 
-0074 20370077 branch p_le_receive_on_attempt ,attempt 
-0075 1b420400 copy clke ,temp 
-0076 604b000f storet 6 ,mem_sync_clke 
+0089 7856fc00 disable match 
+008a 7826fc00 enable decode_fec0 
+008b 7830fc00 enable is_rx 
+008c 78507c00 disable is_tx 
+008d 19623600 copy timeup ,stop_watch 
+008e 37c18400 correlate null ,timeout 
+008f 20370092 branch p_le_receive_on_attempt ,attempt 
+0090 1b420400 copy clke ,temp 
+0091 604b000f storet 6 ,mem_sync_clke 
 
 p_le_receive_on_attempt:
-0077 242c3e75 nbranch le_unsync_end ,sync 
-0078 78287c00 enable swfine 
-0079 db604eab arg param_t_ifs_150us + param_20ms_init + param_sync_time_difference ,stop_watch 
-007a 6fe0c11d fetch 1 ,mem_system_clk 
-007b 9b6f8400 imul32 stop_watch ,temp 
-007c 9840b600 iadd temp ,stop_watch 
-007d 20203de9 branch le_receive_on_attempt + 6 
+0092 242c3e75 nbranch le_unsync_end ,sync 
+0093 78287c00 enable swfine 
+0094 db604eab arg param_t_ifs_150us + param_20ms_init + param_sync_time_difference ,stop_watch 
+0095 6fe0c11d fetch 1 ,mem_system_clk 
+0096 9b6f8400 imul32 stop_watch ,temp 
+0097 9840b600 iadd temp ,stop_watch 
+0098 20203de9 branch le_receive_on_attempt + 6 
 
 p_connection_nosniff:
-007e 70000600 jam 0 ,mem_current_context 
-007f 20203822 branch connection_nosniff 
+0099 70000600 jam 0 ,mem_current_context 
+009a 20203822 branch connection_nosniff 
 
 p_connection_incontext:
-0080 20403863 call context_search_insniff 
-0081 2422807e nbranch p_connection_nosniff ,zero 
-0082 2020381d branch connection_incontext + 3 
+009b 20403863 call context_search_insniff 
+009c 24228099 nbranch p_connection_nosniff ,zero 
+009d 2020381d branch connection_incontext + 3 
 
 p_le_crc_fail_tx:
-0083 20406f09 call ccm_ctrl_clr 
-0084 6fe08198 fetch 1 ,mem_le_rx_phy 
-0085 7d3e7e07 nsetflag ble_coded_info ,bit_le_coded_phy_s8 ,pdata 
-0086 67e08198 store 1 ,mem_le_rx_phy 
-0087 7846fc00 disable decode_fec0 
-0088 20403925 call set_sync_on 
-0089 708a3d12 jam 0x12 ,core_syn_top_ctrl 
-008a 68488008 fetcht 1 ,mem_last_freq 
-008b 1840a202 add temp ,2 ,rega 
-008c 2020398e branch rf_tx_write_freq 
+009e 20406f09 call ccm_ctrl_clr 
+009f 6fe08198 fetch 1 ,mem_le_rx_phy 
+00a0 7d3e7e07 nsetflag ble_coded_info ,bit_le_coded_phy_s8 ,pdata 
+00a1 67e08198 store 1 ,mem_le_rx_phy 
+00a2 7846fc00 disable decode_fec0 
+00a3 20403925 call set_sync_on 
+00a4 708a3d12 jam 0x12 ,core_syn_top_ctrl 
+00a5 68488008 fetcht 1 ,mem_last_freq 
+00a6 1840a202 add temp ,2 ,rega 
+00a7 2020398e branch rf_tx_write_freq 
 
 p_le_transmit:
-008d 20403d3c call le_prep 
-008e 20403d4b call le_tx_setfreq 
-008f 20406451 call rf_debug_tx_on_line 
-0090 79202a00 set1 txgfsk ,radio_ctrl 
-0091 782efc00 enable encode_fec0 
-0092 78307c00 enable is_tx 
-0093 7850fc00 disable is_rx 
-0094 20403dc2 call le_wait_tx 
-0095 785d7c00 disable lr_s2en 
-0096 c517beff bmark1 mark_ble_lr ,le_transmit_lr 
-0097 c5168099 bmark1 mark_ble_2m ,p_le_transmit_2m 
-0098 20203ec8 branch le_transmit + 12 
+00a8 20403d3c call le_prep 
+00a9 20403d4b call le_tx_setfreq 
+00aa 20406451 call rf_debug_tx_on_line 
+00ab 79202a00 set1 txgfsk ,radio_ctrl 
+00ac 782efc00 enable encode_fec0 
+00ad 78307c00 enable is_tx 
+00ae 7850fc00 disable is_rx 
+00af 20403dc2 call le_wait_tx 
+00b0 785d7c00 disable lr_s2en 
+00b1 c517beff bmark1 mark_ble_lr ,le_transmit_lr 
+00b2 c51680b4 bmark1 mark_ble_2m ,p_le_transmit_2m 
+00b3 20203ec8 branch le_transmit + 12 
 
 p_le_transmit_2m:
-0099 6f20c11d fetchr loopcnt ,1 ,mem_system_clk 
+00b4 6f20c11d fetchr loopcnt ,1 ,mem_system_clk 
 
 p_le_transmit_2m_dealy:
-009a 20000001 nop 1 
-009b c200009a loop p_le_transmit_2m_dealy 
-009c 20203f15 branch le_transmit_2m_dealy + 2 
+00b5 20000001 nop 1 
+00b6 c20000b5 loop p_le_transmit_2m_dealy 
+00b7 20203f15 branch le_transmit_2m_dealy + 2 
 
 p_enable_adc:
-009d 6a508a12 fetchr regb ,1 ,core_rf_ldo_cfg6 
-009e 708a123d jam 0x3d ,core_rf_ldo_cfg6 
-009f 708a11aa jam 0xaa ,core_rf_ldo_cfg5 
-00a0 708a0a0c jam 0x0c ,core_rf_ldo_en0 
-00a1 6ff08a09 fetch 1 ,core_clkpll_cfg6 
-00a2 79207e07 set1 7 ,pdata 
-00a3 67f08a09 store 1 ,core_clkpll_cfg6 
-00a4 708a0b04 jam 0x04 ,core_rf_ldo_en1 
-00a5 2000003c nop 60 
-00a6 708a1600 jam 0 ,core_syn_en 
-00a7 708a1706 jam 6 ,core_rx_en0 
-00a8 20406cb4 call read_adc_mode 
-00a9 67f08a97 store 1 ,core_gpadc_ctrl 
-00aa 20206ca7 branch enable_adc + 15 
+00b8 6a508a12 fetchr regb ,1 ,core_rf_ldo_cfg6 
+00b9 708a123d jam 0x3d ,core_rf_ldo_cfg6 
+00ba 708a11aa jam 0xaa ,core_rf_ldo_cfg5 
+00bb 708a0a0c jam 0x0c ,core_rf_ldo_en0 
+00bc 6ff08a09 fetch 1 ,core_clkpll_cfg6 
+00bd 79207e07 set1 7 ,pdata 
+00be 67f08a09 store 1 ,core_clkpll_cfg6 
+00bf 708a0b04 jam 0x04 ,core_rf_ldo_en1 
+00c0 2000003c nop 60 
+00c1 708a1600 jam 0 ,core_syn_en 
+00c2 708a1706 jam 6 ,core_rx_en0 
+00c3 20406cb4 call read_adc_mode 
+00c4 67f08a97 store 1 ,core_gpadc_ctrl 
+00c5 20206ca7 branch enable_adc + 15 
               org 0x3800
 
 start:
Index: program/patch.prog
===================================================================
--- /branch/usb/usb_public_base/program/patch.prog	(revision 204)
+++ /branch/usb/usb_public_base/program/patch.prog	(working copy)
@@ -1,4 +1,6 @@
 
+//define UART_LOG
+
 	bbit1 8,pf_patch_ext
 	beq patch00_0,p_soft_reset
 	beq patch00_3,p_connection_incontext
@@ -31,14 +33,22 @@
 	fetch 1,mem_device_option
 	branch app_init,blank
 p_dongle_init:
+ifdef UART_LOG
+	call p_device_hardware_init
+endif
 	rtn wake
 	jam HVIN_VIN_GREATER_THAN_4V2,mem_lpm_ctrl3
 	call lpm_write_sel_vdd
-
-	//disable mode switch
-	jam 1,mem_24g_B_S_mode_switch_disable
 	
-	branch 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 p_dongle_ackpayload_prep
+	store 2,mem_cb_24g_ackpayload
+	branch dongle_init+8
 
 	//watch dog enable
 //p_wdt_kick:
@@ -156,7 +166,41 @@
 	jam 1,mem_24g_device2_bind_disable
 	branch g24_bind_dvc2_step_success
 
-	
+
+p_dongle_ackpayload_prep:
+	fetch 1,mem_24g_data_type
+	beq DATATYPE_DEVICE1,p_dongle_ackpayload_prep_mouse
+	beq DATATYPE_DEVICE2,p_dongle_ackpayload_prep_keyboard
+p_dongle_ackpayload_prep_mouse:
+	fetch 1,mem_dg_pc_sleep_flag
+	bbit1 0,dongle_pc_sleep_ackpayload_prep_mouse
+p_dongle_ackpayload_prep_end:
+	fetch 1,mem_24g_ackpayload_enable
+	beq BIND_ACKPAYLOAD,p_dongle_g24_bind_ackpayload_prep
+	beq KB_LED_ACKPAYLOAD,p_dongle_g24_kb_led_ackpayload_prep
+	rtn
+
+p_dongle_ackpayload_prep_keyboard:
+	fetch 1,mem_dg_pc_sleep_flag
+	bbit1 1,dongle_pc_sleep_ackpayload_prep_keyboard
+	branch p_dongle_ackpayload_prep_end
+
+p_dongle_g24_bind_ackpayload_prep:
+	jam 1,mem_24g_ackpayload_enable
+	call g24_binding_device_check+2	//works on auto pair only
+	nrtn user3
+ifdef UART_LOG
+	call p_24g_binding_device_print
+endif
+	branch g24_bind_ackpayload_prep
+
+p_dongle_g24_kb_led_ackpayload_prep:
+	fetch 1,mem_24g_rxbuf+2
+	beq DATATYPE_DEVICE1,p_dongle_g24_bind_ackpayload_prep
+	beq DATATYPE_ATTEMP,p_dongle_g24_bind_ackpayload_prep
+	branch dongle_g24_kb_led_ackpayload_prep+3
+
+
 
 p_le_enable_phy_by_pdata:
 	copy temp,pdata
@@ -253,5 +297,134 @@
 	call read_adc_mode
 	store 1,core_gpadc_ctrl
 	branch enable_adc+15
+
+
+
+ifdef UART_LOG
+p_device_hardware_init:
+	fetch 1,core_uart_ctrl
+	set0 BIT_UART_CONTROL_ENABLE,pdata
+	store 1,core_uart_ctrl
+	fetch 8,mem_device_uart_rx_buffer
+	call uarta_init_dma_mem
+	fetch uart_baud_len,mem_device_uart_baud_rate
+	call uarta_init_baud_rate
+	call uart_clock_select_main_freq_crystal
+	fetch 1,mem_device_uart_tx_gpio
+	arg gpcfg_uart_txd,temp
+	call p_gpio_config_function_int
+	fetch 1,mem_device_uart_rx_gpio
+	arg gpcfg_uart_rxd|gpcfg_pullup,temp
+	call p_gpio_config_function_int
+	arg FUN_UART_CONTROL_ENABLE|FUN_UART_CONTROL_SETTING_RATE_BAUD,temp
+	storet 1,core_uart_ctrl
+	rtn
+
+p_gpio_config_function_int:
+	rtneq GPIO_DISABLE
+	branch gpio_config_function_int
+
+p_24g_binding_device_print:
+	arg 1,loopcnt
+	arg mem_24g_work_mode,regc
+	call log_bytes
+	branch log_end
+	
+
+p_24g_rxpayload_print:
+	fetch 8,mem_24g_rxdata_temp+3
+	rtn blank
+	
+	arg 8,loopcnt
+	arg mem_24g_rxdata_temp+3,regc
+	call log_bytes
+	branch log_end
+
+	
+
+//input: 1 byte hex @pdata  
+//output: 4 byte  '0','x', ASCII,ASCII, @pdata
+hex2ascii:
+	rshift4 pdata,rega  //high 4bit in rega
+	and_into 0x0f,pdata
+	call hex2ascii_half_byte
+	copy pdata,regb
+	copy rega,pdata
+	call hex2ascii_half_byte
+	lshift8 regb,regb
+	iadd regb,pdata
+//	lshift16 pdata,pdata
+//	arg 0x7830,regb   //0x
+//	iadd regb,pdata
+	rtn
+
+//input: 1 byte hex @pdata  
+//output: 4 byte  '0','x', ASCII,ASCII, @pdata
+hex2ascii_half_byte:
+	arg 0xa,temp
+	isub temp,temp
+	nbranch hex2ascii_half_byte_numberic,positive
+	setarg 0x41  // A
+	iadd temp,pdata
+	rtn
+hex2ascii_half_byte_numberic:
+	arg 0x30,temp
+	iadd temp,pdata
+	rtn
+
+//input: loopcnt--length,regc--data ptr	
+log_bytes:
+	copy loopcnt,pdata
+	branch log_len0,blank
+log_bytes_loop:
+	ifetch 1,regc
+	increase 1,regc
+	call log_byte
+	call log_space
+	loop log_bytes_loop
+uart_wait:
+	fetch 1,core_uart_status
+	bbit1 uart_status_tx_busy,uart_wait
+//	nop 12000
+	rtn	
+
+log_len0:
+	call uarta_prepare_tx
+	setarg 0x656c
+	istore 2,contwu
+	setarg 0x306e
+	istore 2,contwu
+	call uarta_send
+	branch log_end
+
+//input 1byte @pdata
+log_byte:
+	call uarta_prepare_tx
+	call hex2ascii
+//	istore 4,contu	//0x
+	istore 2,contwu
+	branch uarta_send
+
+log_space:
+	call uarta_prepare_tx
+	setarg 0x20
+	istore 1,contwu
+	branch uarta_send
+
+log_end:
+	call uarta_prepare_tx
+	setarg 0x0a0d
+	istore 2,contwu
+	branch uarta_send
+
+log_colon:
+	call uarta_prepare_tx
+	setarg 0x3a
+	istore 1,contwu
+	branch uarta_send
+
+endif
+
+	
 	
 
Index: sched/dongle.dat
===================================================================
--- /branch/usb/usb_public_base/sched/dongle.dat	(revision 204)
+++ /branch/usb/usb_public_base/sched/dongle.dat	(working copy)
@@ -33,7 +33,7 @@
 
 
 #rf config
-mem_24g_lap:39 28 13 30 06 13#low 4B used for 24g rxaddr
+mem_24g_lap:39 29 13 30 06 13#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
@@ -64,4 +64,16 @@
 mem_load_check_sum:5a
 
 
+#log log log log log log log log log log log
+
+#uart config
+#mem_device_uart_tx_gpio:06	#08
+#mem_device_uart_rx_gpio:ff
+#mem_device_uart_baud_rate:d0 00	#115200	
+#mem_device_uart_rx_buffer:00 1c
+#mem_device_uart_rx_buffer_end:ff 1f
+#mem_device_uart_tx_buffer:00 4f
+#mem_device_uart_tx_buffer_end:ff 4f
+
+
 
