Index: program/app_mouse.prog
===================================================================
--- /YC1308AC/branch/mouse_project/YJX_Project/1011-T_Project/SDK/Standard-129_24G_First_Led_Connect_Gnd_SDK/program/app_mouse.prog	(nonexistent)
+++ /YC1308AC/branch/mouse_project/YJX_Project/1011-T_Project/SDK/Standard-129_24G_First_Led_Connect_Gnd_SDK/program/app_mouse.prog	(working copy)
@@ -0,0 +1,4947 @@
+
+ifdef COMPILE_MOUSE
+mouse_init:
+	call mouse_setting_config
+	call mouse_init_sunt
+	call mouse_dpi_config
+	rtn wake
+	call mouse_usb_check_enable
+	call mouse_drawing_optima_init
+	call mouse_cb_fuction
+	call mouse_sensor_powerdown
+	fetch 1,mem_usb_addr
+	rtnbit1 7
+mouse_init_wireless:	
+	fetch 2,mem_ui_state_map
+	bbit1 UI_STATE_BTN_DOWN,mouse_start_discovery
+	call mouse_check_select_device_by_switch
+	branch mouse_start_work
+
+
+mouse_cb_fuction:
+	setarg mouse_24g_package_data
+	store 2,mem_cb_24g_transmit_data
+	setarg mouse_24g_search_dongle
+	store 2,mem_cb_24g_search_receiver
+	setarg mouse_lpm_before_common
+	store 2,mem_cb_24g_lpm_before
+	setarg mouse_le
+	store 2,mem_cb_le_process
+	setarg mouse_bt
+	store 2,mem_cb_bt_process
+	setarg mouse_process_lpm_before
+	store 2,mem_cb_before_lpm
+	setarg mouse_priority_bb_event
+	store 2,mem_cb_bb_event_process
+	setarg mouse_idle
+	store 2,mem_cb_idle_process
+	setarg mouse_before_hibernate
+	store 2,mem_cb_before_hibernate
+	setarg mouse_le_bb_event_connect_complete
+	store 2,mem_cb_att_write	
+	setarg mouse_bb_event_timer
+	store 2,mem_cb_event_timer
+	setarg mouse_spi_write_flash_cb
+	store 2,mem_cb_spi_flash_write_complate
+	setarg mouse_lpm_check_wake_lock
+	store 2,mem_cb_check_wakelock
+	setarg mouse_le_transmit
+	store 2,mem_cb_ble_transmit
+	setarg mouse_bt_slave_match
+	store 2,mem_cb_bt_slave_match
+	setarg mouse_set_lpm_mult
+	store 2,mem_cb_bt_set_mult
+	rtn
+
+
+mouse_setting_config:
+	rtn wake
+	call g24_transmit_init
+	call g24_chmap_param_init
+	call mouse_gpio_init
+	call mouse_param_init
+mouse_setting_config_next:	
+	call le_set_config_fixed_ltk
+	call le_set_justwork
+	call le_set_fixed_ltk
+	call le_set_config_read_authentication
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit1 MOUSE_ENABLE_EEPROM,mouse_load_eeprom_info_check
+	bbit1 MOUSE_ENABLE_FLASH,mouse_load_flash_info_check
+	rtn
+	
+mouse_xtal_init:
+	jam 0x08,mem_fcomp_div		// 0x08--16M 
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	rtnbit1 MOUSE_ENABLE_16M
+	jam 0x18,mem_fcomp_div		// 0x18--24M
+	rtn
+
+mouse_default_init:
+	jam 0xff,mem_usb_offline_check_gpio
+	jam 0xff,mem_ui_button_gpio
+	jam 0x1e,mem_ui_button_timeout
+
+	setarg mem_mouse_led_type
+	store 2,mem_ui_led_struct_ptr
+	jam 1,mem_ui_led_struct_num
+
+	setarg mem_mouse_rssi_signal_buf
+	store 2,mem_rssi_signal_buf_ptr
+
+	jam 1,mem_24g_data_type
+	
+	fetch 2,mem_mouse_discovery_timeout
+	store 2,mem_discovery_timeout
+
+	fetch 2,mem_mouse_24g_pair_timeout_init
+	store 2,mem_24g_pair_timeout_init
+
+	fetch 1,mem_mouse_24g_reconn_timeout_init
+	store 2,mem_24g_reconn_timeout_init
+
+	fetch 5,mem_rssi_dis_min_24g_init
+	store 5,mem_rssi_dis_min_24g
+
+	fetch 1,mem_mouse_24g_pair_tx_power
+	store 1,mem_24g_pair_tx_power
+
+
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	nrtn blank
+
+	
+// mouse.dat no configuration parameters
+	setarg 0x020800					//enable poweron direct  & 24g
+	store 3,mem_mouse_flag			
+	setarg 0x800700					// adc led use mode led
+	istore 3,contw
+	setarg 0x0300
+	istore 2,contw
+
+	jam 1,mem_lpm_mode
+	fetch 1,mem_mouse_enable_flag
+	isolate1 MOUSE_ADC_ENABLE,pdata
+	call mouse_adc_read_enable,true
+
+	fetch 1,mem_mouse_enable_flag
+	isolate1 MOUSE_24G_250HZ_ENABLE,pdata
+	call mouse_24g_set_250Hz,true
+	fetch 1,mem_mouse_enable_flag
+	isolate1 MOUSE_SEARCH_DONGLE_ENABLE,pdata
+	call mouse_24g_search_dongle_enable,true
+	fetch 1,mem_mouse_enable_flag
+	isolate1 MOUSE_CLK_16M_ENABLE,pdata
+	call mouse_16M_enable,true
+	fetch 1,mem_mouse_enable_flag
+	isolate1 MOUSE_DPI_4_LEVEL_ENABLE,pdata
+	call mouse_dpi_4level_enable,true
+	fetch 1,mem_mouse_enable_flag
+	isolate1 MOUSE_KEYBOARD_ENABLE,pdata
+	call mouse_customer_key_enable,true
+	
+	fetch 1,mem_24g_ch_map_update
+	ncall g24_chamap_param_update,blank
+
+	call mouse_xtal_init
+
+	fetch 1,mem_mouse_global_setup
+	and pdata,0x07,temp
+	storet 1,mem_adc_channel
+	rshift3 pdata,pdata
+	and pdata,0x01,temp
+	storet 1,mem_24g_ch_map_update
+	rshift pdata,pdata
+	and pdata,0x03,temp
+	storet 1,mem_adc_config_flag_init
+	rshift2 pdata,pdata
+	and pdata,0x03,pdata
+	call mouse_24g_long_sleep_set
+
+	fetch 1,mem_mouse_global_setup1
+	and pdata,0x03,temp
+	storet 1,mem_sensor_angle_default
+	rshift2 pdata,pdata
+	and pdata,0x03,temp
+	storet 1,mem_sensor_angle_switch
+	rshift2 pdata,pdata
+	and pdata,0x03,pdata
+	store 1,mem_config_sensor_dpi
+	store 1,mem_mouse_dpi
+	rshift2 pdata,pdata
+	and pdata,0x03,pdata
+	store 1,mem_device_number
+
+
+	setarg 0x0b0c0a
+	store 3,mem_lbutton_gpio
+	setarg 0xffffff
+	istore 3,contw
+	setarg 0x0607ff			// clk-07  sdio--06
+	istore 3,contw
+	setarg 0xffffff
+	istore 3,contw
+
+/* adc*/
+	jam 0x0a,mem_adc_read_time_init
+	setarg 0x0064
+	store 2,mem_adc_low_volatage_led_blink_timer
+	call mouse_adc_vol_init	
+/****/
+	setarg 0x1770
+	store 2,mem_mouse_no_data_timeout				// 10min
+	jam 0x14,mem_mouse_device_poweron_timer_count_init	// 2s
+	setarg 0x0190
+	store 2,mem_mouse_low_v_led_blink_time			// 200ms on,200ms off
+	store 2,mem_mouse_dpi_led_blink_time
+	setarg 0x03e8
+	store 2,mem_mouse_disconvey_led_blink_time
+	jam 0x07,mem_rssi_buff_index
+	jam 125,mem_power_ctrl_pac_succ_cnt_init
+	jam TX_POWER_0DB,mem_tx_power
+
+	jam 0x01,mem_24g_fast_conn_enable
+	setarg 0x0f0f
+	store 2,mem_24g_fast_conn_addr
+	store 2,mem_24g_fast_conn_addr+2
+	
+//ble
+	fetch 2,mem_lap
+	store 2,mem_lap+4
+	arg mem_le_lap,contw
+	arg mem_lap,contr
+	arg 0x06,loopcnt
+	call reverse_byte
+	
+	jam 0x20,mem_lpm_mult_init
+	jam 0x34,mem_device1_type
+	fetch 6,mem_le_lap
+	store 6,mem_device1_locall_addr
+	jam 0x02,mem_mouse_bluetooth_type
+
+	jam 0x1f,mem_le_adv_data_len
+	
+	setarg 0x050102
+	store 3,mem_le_adv_data
+	setarg 0x120303
+	istore 3,contw
+	setarg 0x190318
+	istore 3,contw
+	setarg 0x03c2
+	istore 2,contw
+
+	setarg 0x06ff06
+	store 3,mem_le_adv_swift_pair
+	setarg 0x000300
+	istore 3,contw
+	setarg 0x090c80
+	istore 3,contw
+
+	setarg 0x355442		// BT5.2 Mouse
+	istore 3,contw
+	setarg 0x20322e
+	istore 3,contw
+	setarg 0x756f4d
+	istore 3,contw
+	setarg 0x6573
+	istore 2,contw
+
+	jam 0x1f,mem_le_scan_data_len
+	arg mem_le_adv_swift_pair+7,contr
+	arg mem_le_scan_data,contw
+	arg 13,loopcnt
+	call memcpy
+
+	fetch 1,mem_le_scan_data
+	increase -1,pdata
+	store 1,mem_le_name_len
+
+	arg mem_le_scan_data+2,contr
+	arg mem_le_name_len+1,contw
+	arg 11,loopcnt
+	call memcpy
+
+	setarg 0x070007
+	store 3,mem_le_interval_min
+	setarg 0x002000
+	istore 3,contw
+	setarg 0x012c
+	istore 2,contw
+
+	setarg 0x181203
+	store 3,mem_le_adv_ind
+
+	setarg 0x0000ff
+	store 3,mem_le_adv_direct_ind
+
+	setsect 0,0xfb
+	setsect 1,0x2c212
+	setsect 2,0x800f
+	setsect 3,0x21
+	store 8,mem_local_rx_max_octets
+
+	jam 0x07,mem_le_adv_channel_map
+
+	setarg 0x0015
+	store 2,mem_le_keyboard_handle
+	setarg 0x0019
+	store 2,mem_le_notify_handle
+	setarg 0x001d
+	store 2,mem_le_multimedia_handle
+	setarg 0x0021
+	store 2,mem_le_systemctrl_handle
+	setarg 0x0030
+	store 2,mem_le_battery_level_handle
+	setarg 0x0022
+	store 2,mem_le_pairing_handle
+
+	jam 0x96,mem_le_battery_level_updata_timer_init
+
+// 24g
+	jam MODE_24G_DEVICE,mem_device_flag
+	call g24_enable_1M
+	call g24_pair_param_init
+	
+	setarg 0x604800
+	store 3,mem_24g_enter_hibernate
+	setarg 0x012c
+	store 2,mem_24g_long_sleep_param_update_timer_init
+	setarg 0x0050
+	store 2,mem_24g_transmit_by_interrupt_exit_count_init
+	setarg 0x05
+	store 2,mem_mouse_24g_power_on_fast_conn_timer	// 200ms
+	setarg 0x0708									//search dongle 3min
+	store 2,mem_mouse_24g_search_dongle_time_init
+
+	
+// sensor
+	setarg 0x010403
+	store 3,mem_mouse_dpi_seting
+	setarg 0x2a2002
+	istore 3,contw
+	setarg 0x22153f
+	istore 3,contw
+	setarg 0x114433
+	istore 3,contw
+
+	setarg 0x265a09
+	store 3,mem_sensor_3212_init
+	setarg 0x041934
+	istore 3,contw
+	setarg 0x0009
+	istore 2,contw
+	setarg 0xffff
+	istore 2,contw
+
+	setarg 0x0d5a09
+	store 3,mem_sensor_3205_init
+	setarg 0xed1d10
+	istore 3,contw
+	setarg 0x807d
+	istore 2,contw
+	setarg 0xffff
+	istore 2,contw
+
+	setarg 0xff5a09
+	store 3,mem_sensor_8650_init
+	setarg 0x40ab27
+	istore 3,contw
+	setarg 0xa0d1be
+	istore 3,contw
+	setarg 0x12a141
+	istore 3,contw
+	setarg 0xa784a5
+	istore 3,contw
+	setarg 0xd0b5ff
+	istore 3,contw
+	setarg 0xff00b6
+	istore 3,contw
+	setarg 0x000900
+	istore 3,contw
+	setarg 0xffff
+	istore 2,contw
+
+	setarg 0x0d5a09
+	store 3,mem_sensor_ka8ul_init
+	setarg 0xc50e10
+	istore 3,contw
+	setarg 0x109a5b
+	istore 3,contw
+	setarg 0x421138
+	istore 3,contw
+	setarg 0x412828
+	istore 3,contw
+	setarg 0x394923
+	istore 3,contw
+	setarg 0x4bb04a
+	istore 3,contw
+	setarg 0x904ca0
+	istore 3,contw
+	setarg 0x09704d
+	istore 3,contw
+	setarg 0xffff00
+	istore 3,contw
+
+	setarg 0x46a509
+	store 3,mem_sensor_ka8g2_init
+	setarg 0x101934
+	istore 3,contw
+	setarg 0x690760
+	istore 3,contw
+	setarg 0x207d04
+	istore 3,contw
+	setarg 0x09007e
+	istore 3,contw
+	setarg 0x220d00
+	istore 3,contw
+	setarg 0xff220e
+	istore 3,contw
+	jam 0xff,mem_sensor_ka8g2_init+21
+		
+	setarg 0x0b5a09
+	store 3,mem_sensor_poweron_init
+	setarg 0x0009f3
+	istore 3,contw
+	setarg 0xffff
+	istore 2,contw
+
+	//sys init
+	branch app_sys_param_init
+	
+
+mouse_param_init:
+	setarg MOUSE_BT_SDP_ADDR				//bt sdp start address
+	store 2,mem_ui_uuid_table
+	setarg MOUSE_BLE_ATT_LIST_ADDR				//ble attlist start address
+	store 2,mem_ui_le_uuid_table
+	setarg 0x2580
+	store 3,mem_class
+	jam 3,mem_lpm_mult_timeout
+	jam 8,mem_lpm_overhead
+	jam DPI_BUTTON_STATE_UP,mem_select_device_button_statue
+	jam PB_BUTTON_STATE_UP,mem_select_device_button_statue
+	jam COMMBINATION_KEY_STATE_UP,mem_commbination_key_statue	
+	setarg 0x0200
+	store 2,mem_lpm_interval
+	jam 0x17,mem_le_local_mtu
+	jam 0x17,mem_le_remote_mtu
+//===========init spi param==============================
+	setarg 0x0a77
+	store 2,mem_spi_init_clk
+//===========all 16bit uuid==================================
+	setsect 0,0x306
+	setsect 1,0x4440
+	setsect 2,0x10000
+	setsect 3,0x4408
+	store 9,mem_all_uuid_16bits
+	setsect 0,0x1224
+	setsect 1,0x4000
+	setsect 2,0x0
+	istore 5,contw
+//===========features=====================================
+	setsect 0,0x3ffff
+	setsect 1,0x2fe23
+	setsect 2,0x199d9
+	setsect 3,0x20d
+	store 8,mem_features
+//======================================================	
+	setarg mem_le_tx_buffer0_omemalloc
+	store 2,mem_ble_l2cap_tx_buff0_ptr
+	setarg MOUSE_BLE_L2CAP_TXBUFF_SIZE
+	store 2,mem_ble_l2cap_tx_buff_size_ptr
+	
+	call mouse_device_led_all_off
+	call mouse_device_poweron_timer_init
+	call mouse_adc_gpio_mux_init
+
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit0 MOUSE_ENABLE_BT_125Hz,mouse_param_init_intervl_end
+	jam CLASSIC_INTERVAL_7_5MS,mem_sniff_param_interval
+	setarg LE_INTERVAL_7_5MS
+	store 2,mem_le_interval_min
+	store 2,mem_le_interval_min+2
+mouse_param_init_intervl_end:
+	call g24_interval_param_8ms
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit0 MOUSE_ENABLE_24G_250Hz,mouse_24g_short_sleep_set_end
+	call g24_interval_param_4ms
+mouse_24g_short_sleep_set_end:
+	fetch 1,mem_device_flag
+	store 1,mem_device_flag_temp
+	fetch 3,mem_le_lap+3
+	store 3,mem_mouse_le_lap_temp
+	fetch 1,mem_adc_config_flag_init
+	and pdata,0xfe,pdata		// hvin = vinlpm
+	store 1,mem_adc_config_flag_init
+	store 1,mem_adc_config_flag
+	setarg 0
+	store 7,mem_mouse_key
+	fetch 1,mem_ui_button_timeout
+	store 1,mem_bt_discovery_count
+	store 1,mem_select_device_count
+	call le_modified_name
+	branch mouse_sensor_set_angle
+
+
+mouse_start_work:
+	bpatch patch18_3,mem_patch18
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit1 MOUSE_ENABLE_24G_FIRST_AUTO_PAIRING, mouse_24g_first_start_auto_pair_mode
+	fetch 1,mem_device_flag
+	beq MODE_24G_DEVICE,mouse_24g_start_mode
+	call mouse_wakeup_from_power_check	// wake from hibernate :enble user
+	nbranch mouse_buletooth_fast_conn_init,user
+mouse_start_reconnect_device:
+	bpatch patch18_4,mem_patch18
+	arg mem_device1_type,rega
+	fetch 1,mem_device_flag
+	increase -1,pdata
+	mul32 pdata,29,pdata
+	iadd rega,rega
+	ifetch 1,rega
+	store 1,mem_xrecord_mode
+mouse_start_reconnect:	
+	fetch 1,mem_xrecord_mode
+	beq REC_3_MODE,mouse3_0_check_reconn_target
+	beq REC_4_MODE,mouse4_0_check_reconn_target
+	branch mouse_start_discovery
+
+
+mouse_wakeup_from_power_check:
+	bpatch patch18_5,mem_patch18
+	disable user
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit0 MOUSE_ENABLE_WAKEUP_FROM_POWER,mouse_wakeup_from_power
+	fetch 1,mem_wakup_from_power_flag
+	bbit0 BIT_POWER_ON,mouse_wakeup_from_power
+	enable user		// mouse power on
+mouse_wakeup_from_power:
+	fetch 1,mem_reconn_times_init
+	store 1,mem_reconn_times
+	rtn
+
+
+mouse3_0_check_reconn_target:
+	fetcht 2,mem_mouse_fast_page_to
+	fetch 1,mem_mouse_bluetooth_fast_conn_flag
+	beq 0xff,mouse3_0_check_reconn_target_next
+	fetcht 2,mem_mouse_page_to
+mouse3_0_check_reconn_target_next:	
+	storet 2,mem_page_to
+	fetch 6,mem_hci_plap
+	branch app_bt_start_discovery_short,blank
+	jam 0x17,mem_app_connection_options  //ssp
+	fetch 1,mem_ssp_enable
+	nbranch app_bt_start_reconnect,blank
+	jam 0x04,mem_app_connection_options  //no ssp
+	branch app_bt_start_reconnect
+	
+mouse4_0_check_reconn_target:
+	jam 1,mem_mouse_le_reconnect_flag
+	fetcht 1,mem_mouse_fast_direct_timeout
+	fetch 1,mem_mouse_bluetooth_fast_conn_flag
+	beq 0xff,mouse4_0_check_reconn_target_next
+	fetcht 1,mem_mouse_direct_timeout
+mouse4_0_check_reconn_target_next:	
+	storet 1,mem_mouse_direct_timer
+	call app_lpm_mult_disable
+	fetch 3,mem_le_adv_direct_ind
+	store 3,mem_le_adv_data+4
+	call mouse_le_check_adv_flag
+	setarg ADV_FLAG_BREDR_NOT_SUPPORTED
+	istore 1,contr
+	arg mem_le_scan_data,contr
+	call mouse_le_adv_data_update
+	branch check_51cmd_adv
+
+
+/*************************usb**********************************/
+mouse_usb_check_enable:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	rtnbit0 MOUSE_ENABLE_USB
+	setarg mouse_usb_config_param
+	store 2,mem_cb_usb_config
+	jam MOUSE_USB_INTERFACE_REMOVE,mem_mouse_usb_vdd_status
+	branch mouse_usb_interface_check
+
+mouse_usb_config_param:
+	call mouse_usb_config_kb_check
+	call mouse_usb_config_param_init
+	branch mouse_usb_config_param_setup
+
+mouse_usb_config_kb_check:
+	jam DONGLE_KB_BIND_EEPROM_OFFECT,mem_mouse_usb_keyboard_flag
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	rtnbit0 MOUSE_ENABLE_KEYBOARD
+	jam DONGLE_KB_BIND_SUCCESS,mem_mouse_usb_keyboard_flag
+	rtn
+
+mouse_usb_config_param_init:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit1 MOUSE_ENABLE_USB_250,mouse_usb_report_rate_set_250hz
+	bbit1 MOUSE_ENABLE_USB_500,mouse_usb_report_rate_set_500hz
+	bbit1 MOUSE_ENABLE_USB_1000,mouse_usb_report_rate_set_1000hz
+	jam 0x19,mem_wire_usb_interval
+	jam 0x08,mem_usb_tx_interval
+	rtn
+mouse_usb_report_rate_set_250hz:
+	jam 0x0c,mem_wire_usb_interval
+	jam 0x04,mem_usb_tx_interval
+	rtn
+mouse_usb_report_rate_set_500hz:
+	jam 0x06,mem_wire_usb_interval
+	jam 0x02,mem_usb_tx_interval
+	rtn
+mouse_usb_report_rate_set_1000hz:
+	jam 0x03,mem_wire_usb_interval
+	jam 0x01,mem_usb_tx_interval
+	rtn
+
+mouse_usb_config_param_setup:
+	call usb_tx_interval_config
+	call mouse_usb_vid_pid_config
+	branch mouse_usb_hid_icon_config
+
+mouse_usb_vid_pid_config:
+	fetch 1,mem_usb_vid_pid
+	rtn blank
+	fetch 1,mem_mouse_usb_keyboard_flag
+	beq DONGLE_KB_BIND_SUCCESS,dongle_usb_vid_pid_for_suit
+	branch dongle_usb_vid_pid_for_mouse_only_auto_pair
+
+mouse_usb_hid_icon_config:
+	fetch 1,mem_mouse_usb_keyboard_flag
+	branch dongle_usb_hid_icon_config+1
+
+
+mouse_usb_check:
+	fetch 1,core_usb_addr
+	bbit0 7,mouse_usb_no_exsit
+	bbit1 7,mouse_usb_exsit
+	rtn
+mouse_usb_no_exsit:
+	fetch 1,mem_usb_addr
+	rtnbit0 7
+	branch soft_reset_chip
+mouse_usb_exsit:
+	fetch 1,mem_usb_addr
+	rtnbit1 7
+	call mouse_24g_stop
+	branch mouse_stop_bluetooth_mode
+
+mouse_usb_isr:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	rtnbit0 MOUSE_ENABLE_USB
+	call usb_isr
+	branch mouse_usb_interface_check
+//	branch usb_offline_state
+
+
+mouse_usb_interface_check:
+	bpatch patch18_6,mem_patch18
+	fetcht 1,mem_usb_offline_check_gpio
+	call gpio_get_bit
+	branch mouse_usb_gpio_low,true
+	branch mouse_usb_gpio_high
+
+
+mouse_usb_gpio_low:
+	fetch 1,mem_mouse_usb_vdd_status
+	rtneq MOUSE_USB_INTERFACE_REMOVE
+	jam MOUSE_USB_INTERFACE_REMOVE,mem_mouse_usb_vdd_status
+	jam 0,mem_usb_device_enumeration_endflag
+	jam 0,mem_usb_status
+	jam 0,mem_usb_state
+	branch mouse_init_wireless
+	
+	
+mouse_usb_gpio_high:
+	fetch 1,mem_mouse_usb_vdd_status
+	rtneq MOUSE_USB_INTERFACE_INSERT
+	jam MOUSE_USB_INTERFACE_INSERT,mem_mouse_usb_vdd_status
+	call mouse_24g_stop
+	call mouse_stop_bluetooth_mode
+	call mouse_device_led_all_off
+	branch usb_init
+	
+	
+mouse_usb_mode:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	rtnbit0 MOUSE_ENABLE_USB
+	call mouse_usb_check
+	fetch 1,core_usb_addr
+	store 1,mem_usb_addr
+	rtnbit0 7
+	call mouse_clkn_check 
+	fetch 4,mem_btclk_sensor
+	fetcht 1,mem_wire_usb_interval
+	iadd temp,temp
+	copy clkn_bt,pdata
+	isub temp,null
+	nrtn positive
+	store 4,mem_btclk_sensor
+	call mouse_motion
+	nrtn user
+mouse_push_data_to_usb:
+	fetch 1,core_usb_addr
+	rtnbit0 7
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit0 MOUSE_ENABLE_KEYBOARD,mouse_push_mouse_data_to_usb
+	fetch 1,mem_customer_key
+	beq 1,mouse_push_keyboard_data_to_usb
+mouse_push_mouse_data_to_usb:
+	call dongle_usb_tx_ms_data
+	setarg MS_REPORT_ID
+	store 1,mem_usb_mouse_data
+	fetch 7,mem_mouse_key
+	istore 7,contw
+	rtn
+
+mouse_push_keyboard_data_to_usb:
+	fetch 1,mem_customer_data_trigger
+	branch mouse_push_release_keyboard_data_to_usb,blank
+	fetch 8,mem_customer_key_press+1
+mouse_push_keyboard_package_data_to_usb:
+	store 8,mem_pdatatemp
+	fetch 1,mem_customer_key_press
+	beq KB_MULTIKEY_REPORT_ID,mouse_push_multimedia_key_data_to_usb
+	beq KB_SYSTEM_CONCTRL_REPORT_ID,mouse_push_systemctrl_key_data_to_usb
+	call dongle_usb_tx_kb_data
+	fetch 8,mem_pdatatemp
+	store 8,mem_usb_kb_data
+	rtn
+	
+mouse_push_release_keyboard_data_to_usb:
+	fetch 8,mem_customer_key_release+1
+	branch mouse_push_keyboard_package_data_to_usb
+
+mouse_push_multimedia_key_data_to_usb:
+	call dongle_usb_tx_enable_ep2
+	jam USB_EP2_MULTIKEY,mem_usb_ep2_data
+	setarg KB_MULTIKEY_REPORT_ID
+	store 1,mem_usb_kb_multikey
+	fetch 2,mem_pdatatemp
+	istore 2,contw
+	rtn
+
+mouse_push_systemctrl_key_data_to_usb:
+	call dongle_usb_tx_enable_ep2
+	jam USB_EP2_SYSTEMKEY,mem_usb_ep2_data
+	setarg KB_SYSTEM_CONCTRL_REPORT_ID
+	store 1,mem_usb_kb_system
+	fetch 1,mem_pdatatemp
+	istore 1,contw
+	rtn
+
+	
+/*************************usb**********************************/
+
+
+/*****************system clk***********************************/
+
+mouse_clkn_check:
+	fetcht 4,mem_btclk_sensor
+	copy clkn_bt,pdata
+	isub temp,null
+	ncall mouse_clkn_timeout,positive
+	rtn
+mouse_clkn_timeout:
+	setarg 0
+	store 4,mem_btclk_sensor
+	rtn
+
+
+/*
+mouse_enable_clock_qdecoder:
+	fetch 2,core_clkoff
+	set0 CLOCK_OFF_QDECODER,pdata
+	store 2,core_clkoff
+	rtn
+*/
+
+mouse_lpm_check_wake_lock:
+	bmark1 mark_24g,app_get_lpm_wake_lock
+	fetch 1,mem_mouse_clear_sensor_data_flag
+	branch app_get_lpm_wake_lock,blank
+	fetch 1,mem_mouse_le_conn_param_reject
+	beq LE_LPM_DISABLE,app_get_lpm_wake_lock
+	fetch 2,mem_sdp_remote_cid
+	nbranch app_get_lpm_wake_lock,blank
+	fetch 1,mem_mouse_wheel_trigger
+	nbranch app_get_lpm_wake_lock,blank
+	branch app_put_lpm_wake_lock
+
+mouse_delay_enter_hibernata:
+	fetch 1,mem_mouse_direct_timeout
+	store 1,mem_mouse_bluetooth_reconnect_timeout
+	rtn
+
+
+mouse_app_enter_hibernate:
+	bpatch patch18_7,mem_patch18
+	call mouse_sensor_reset
+	call mouse_sensor_powerdown
+	call mouse_setgpio_hibernate
+	branch app_enter_hibernate
+
+	
+mouse_before_hibernate:
+	bpatch patch19_0,mem_patch19
+	enable user
+	fetch 4,0x8138
+	setflag user,26,pdata
+	store 4,core_lpm_reg
+	call lpm_write_ctrl
+	call disable_authrom
+	call mouse_device_led_all_off
+	call mouse_before_hibernate_wheel_gpio_set
+	call mouse_setgpio_hibernate
+	call mouse_flash_power_down
+	call gpio_set_before_lpm_common
+	fetcht 1,mem_sensor_motion_gpio
+	branch gpio_clr_wake
+
+
+mouse_setgpio_hibernate:
+	bpatch patch19_1,mem_patch19
+	call mouse_set_sdio_high
+	call clear_wake
+	call mouse_lpm_before_common
+	call gpio_pd_idle
+	arg 19,temp
+	call mouse_gpio_config_input_pu
+	branch mouse_gpio_set_high_impedance
+	
+
+	
+mouse_process_lpm_before:
+	rtnmark1 mark_24g
+	call mouse_lpm_before_common
+	fetch 1,mem_lpm_current_mult
+	nrtn blank					// 7.5ms, no gpio wakeup
+	branch gpio_clr_wake
+
+mouse_lpm_before_common:
+	bpatch patch19_2,mem_patch19
+	
+	call mouse_wheel_check
+	fetcht 1,mem_mouse_sensor_sclk_gpio					// set sclk high
+	call gpio_config_output
+mouse_lpm_before_common_next:
+	call twspi_disable
+	
+	fetcht 1,mem_lbutton_gpio
+	call gpio_set_wake
+	fetcht 1,mem_rbutton_gpio
+	call gpio_set_wake
+	fetcht 1,mem_mbutton_gpio
+	call gpio_set_wake
+
+	fetcht 1,mem_bk_button_gpio
+	call gpio_set_wake
+	fetcht 1,mem_fw_button_gpio
+	call gpio_set_wake
+	fetcht 1,mem_dpi_button_gpio
+	call gpio_set_wake
+	fetcht 1,mem_config_select_device_button_gpio
+	call gpio_set_wake
+
+	fetcht 1,mem_customer_key_gpio
+	call gpio_set_wake
+	
+	fetcht 1,mem_whee_a_data_gpio
+	call gpio_set_wake_by_current_state
+	fetcht 1,mem_whee_b_data_gpio
+	call gpio_set_wake_by_current_state
+	fetcht 1,mem_whee_ta_data_gpio
+	call gpio_set_wake_by_current_state
+	fetcht 1,mem_whee_tb_data_gpio
+	call gpio_set_wake_by_current_state
+	fetcht 1,mem_sensor_motion_gpio
+	branch gpio_set_wake
+
+
+//short mult: no key 
+mouse_set_mult:
+	fetch 2,mem_ui_state_map
+	bbit1 UI_STATE_BLE_CONNECTED,mouse_set_ble_mult
+	fetch 2,mem_ui_state_map
+	bbit1 UI_STATE_BT_CONNECTED,mouse_set_bt_mult
+	rtn
+mouse_set_ble_mult:
+	copy rega,pdata
+	nbranch le_set_config_short_mult,blank
+	branch le_clr_config_short_mult
+mouse_set_bt_mult:
+	copy rega,pdata
+	nbranch classic_bt_set_mult_short_flag,blank
+	branch classic_bt_clr_mult_short_flag
+
+/*****************system clk***********************************/
+	
+	
+/****************************adc**************************************/	
+mouse_adc_gpio_set:
+	fetch 1,mem_adc_config_flag
+	rtnne ADC_CONFIG_GPIO
+mouse_adc_gpio_check_output:
+	bpatch patch19_3,mem_patch19
+	fetcht 1,mem_adc_channel
+	sub temp,3,null
+	branch mouse_adc_gpio_4_7_set,positive
+	increase 5,temp
+	storet 1,mem_adc_channel_gpio
+mouse_adc_gpio_set_next:
+	copy temp,rega
+	call gpio_get_config
+	beq gpcfg_output_high,mouse_set_24g_led_statue
+	call mouse_clear_24g_led_statue
+	copy rega,temp
+	branch gpio_set_high_impedance
+
+mouse_adc_gpio_4_7_set:
+	increase 4,temp
+	storet 1,mem_adc_channel_gpio
+	branch mouse_adc_gpio_set_next
+
+mouse_adc_vol_init:
+	fetch 1,mem_adc_config_flag_init
+	beq ADC_CONFIG_GPIO,mouse_adc_gpio_vol_init
+	beq ADC_CONFIG_VINLPM,mouse_adc_gpio_vinlpm_init
+	jam ADC_CONFIG_VINLPM,mem_adc_config_flag_init
+	setarg 0x2c0172		// 0x0172--3.7V  0x012c--3.0V  0x0140--3.2V  0x014a--3.3V
+	store 3,mem_mouse_vdd_full_vol
+	setarg 0x014001
+	istore 3,contw
+	rtn
+mouse_adc_gpio_vol_init:	
+	setarg 0x5d0099		// 0x0099--1.5V   0x005d--0.9V  0x0068--1.0V  0x0071--1.1V
+	store 3,mem_mouse_vdd_full_vol
+	setarg 0x007100
+	istore 3,contw
+	rtn
+mouse_adc_gpio_vinlpm_init:
+	setarg 0xc8012c		// 0x012c--3.0V  0x00c8--2.0V  0x00dc--2.2V
+	store 3,mem_mouse_vdd_full_vol
+	setarg 0x00dc00
+	istore 3,contw
+	rtn
+	
+
+
+mouse_adc_gpio_mux_init:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	rtnbit0 MOUSE_ENABLE_ADC
+	jam MOUSE_ADC_CHECK_MULTIPLE,mem_adc_mux_status
+	rtnbit1 MOUSE_ENABLE_DPI_KEY_CONNECT_ADC
+	rtnbit1 MOUSE_ENABLE_SELECT_DEVICE_BY_SWITCH_ADC
+	jam MOUSE_ADC_CHECK_BATTERY_ONLY,mem_adc_mux_status
+	rtn
+
+mouse_adc_read_interval:	
+	fetch 1,mem_adc_read_timer
+	increase 1,pdata
+	store 1,mem_adc_read_timer
+	fetcht 1,mem_adc_read_time_init	//1s read adc
+	isub temp,null
+	rtn
+
+
+mouse_adc_read:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	rtnbit0 MOUSE_ENABLE_ADC
+	call mouse_adc_gpio_set
+	fetch 1,mem_adc_mux_status
+	branch mouse_adc_read_battery,blank
+	fetch 1,mem_adc_config_flag
+	beq ADC_CONFIG_GPIO,mouse_adc_read_gpio_mux_start	// gpio + dpi/switch
+	jam MOUSE_ADC_CHECK_VINLPM_MULTIPLE,mem_adc_mux_status
+	call mouse_adc_read_interval					// vinlpm + dpi/switch
+	branch  mouse_adc_read_gpio, positive
+	call mouse_adc_read_vinlpm
+	branch mouse_adc_read_start
+
+mouse_adc_read_gpio_mux_start:
+	jam MOUSE_ADC_CHECK_GPIO_MULTIPLE,mem_adc_mux_status
+	branch mouse_adc_read_start
+
+mouse_adc_read_gpio:
+	call mouse_adc_gpio_check_output
+	jam ADC_CONFIG_GPIO,mem_adc_config_flag
+	fetch 1,mem_24g_device_led_status
+	ncall mouse_adc_read_vinlpm,blank
+	branch mouse_adc_read_start
+	
+mouse_adc_read_vinlpm:
+	jam 0,mem_adc_read_timer
+	fetch 1,mem_adc_config_flag_init
+	store 1,mem_adc_config_flag
+	rtn	
+	
+mouse_adc_read_battery:		// only get battery
+	fetch 1,mem_adc_config_flag
+	bne ADC_CONFIG_GPIO,mouse_adc_read_battery_start
+	fetch 1,mem_24g_device_led_status
+	nrtn blank
+mouse_adc_read_battery_start:
+	call mouse_adc_read_interval
+	nrtn positive
+mouse_adc_read_start:
+	bpatch patch19_4,mem_patch19
+	fetch 1,mem_24g_device_led_status
+	nrtn blank
+	jam 0,mem_adc_read_timer
+	call vdd_calculate_by_mode
+	store 2,mem_mouse_vdd_now_vol
+	fetch 1,mem_adc_config_flag
+	bne ADC_CONFIG_GPIO, mouse_adc_data_process
+	fetcht 2,mem_mouse_vdd_now_vol	// BAT= 1.5V, R = 200k, a = a*1.8
+	mul32 temp,8,pdata
+	div pdata,10
+	call get_div_result
+	iadd temp,pdata
+	store 2,mem_mouse_vdd_now_vol
+mouse_adc_data_process:	
+	arg mem_mouse_vdd_calculate_set,rega
+	call mouse_adc_bat_percent_lowpower_out
+	fetch 1,mem_adc_power_flag
+	bbit1 2,mouse_adc_button_press
+	bbit1 1,mouse_power_down
+	bbit0 0,mouse_adc_no_low_voltage
+mouse_adc_data_process_next:
+	jam 1,mem_mouse_adc_last_low_voltage_flag
+	branch mouse_adc_low_voltage
+	
+mouse_adc_low_voltage:
+	arg MOUSE_LOW_VOLTAGE_FLAG,queue
+	branch mouse_enable_function_flag
+mouse_adc_no_low_voltage:
+	arg MOUSE_LOW_VOLTAGE_FLAG,queue
+	call mouse_disable_function_flag
+	jam 12,mem_adc_low_volatage_led_timer_count
+	fetch 1,mem_mouse_adc_last_low_voltage_flag
+	rtn blank
+	jam 0,mem_mouse_adc_last_low_voltage_flag
+	fetcht 1,mem_config_low_voltage_alarm_gpio
+	branch mouse_led_off
+
+
+
+mouse_adc_bat_percent_lowpower_out:
+	bpatch patch19_5,mem_patch19
+	ifetch 8,rega
+	store 8,mem_pdatatemp
+	fetch 1,mem_adc_mux_status
+	beq MOUSE_ADC_CHECK_BATTERY_ONLY,mouse_adc_bat_percent_lowpower_out_battery
+	beq MOUSE_ADC_CHECK_GPIO_MULTIPLE,mouse_adc_bat_percent_lowpower_out_gpio_multiple
+	beq MOUSE_ADC_CHECK_VINLPM_MULTIPLE,mouse_adc_bat_percent_lowpower_out_vinlpm_multiple
+mouse_adc_bat_percent_lowpower_out_gpio_multiple:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit0 MOUSE_ENABLE_DPI_KEY_CONNECT_ADC,mouse_adc_bat_percent_lowpower_out_gpio_switch
+	fetch 2,mem_pdatatemp+6		               	//now voltage
+	fetcht 2,mem_mouse_vdd_button_press_vol	// button press check
+	isub temp,null
+	nbranch mouse_adc_set_button_press_flag,positive
+	
+mouse_adc_bat_percent_lowpower_out_gpio_switch:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit0 MOUSE_ENABLE_SELECT_DEVICE_BY_SWITCH_ADC,mouse_adc_bat_percent_lowpower_out_battery
+	jam 0,mem_mouse_adc_button_press_flag
+	fetch 2,mem_pdatatemp+6				    	        //now voltage	
+	fetcht 2,mem_mouse_vdd_switch_gnd_24g_vol	// switch mode check
+	isub temp,null
+	nbranch mouse_select_24gdevice,positive
+	call mouse_select_btdevice
+	branch mouse_adc_bat_percent_lowpower_out_battery
+
+mouse_select_24gdevice:
+	call mouse_check_select_24gdevice
+	branch mouse_adc_bat_percent_lowpower_out_battery
+
+
+mouse_adc_bat_percent_lowpower_out_battery:	
+	call mouse_adc_clear_button_press_flag
+	call adc_clear_no_power_flag
+	call adc_clear_low_power_flag
+	fetch 2,mem_pdatatemp+6
+	fetcht 2,mem_pdatatemp+2	        //shutdown voltage
+	isub temp,null
+	ncall adc_set_no_power_flag,positive
+
+	fetcht 2,mem_pdatatemp+4		//low voltage
+	isub temp,null
+	ncall adc_set_low_power_flag,positive
+
+mouse_adc_bat_level_set:
+	fetch 2,mem_pdatatemp+6		//now voltage	
+	fetcht 2,mem_pdatatemp		//full voltage
+	isub temp,null
+	branch mouse_adc_bat_level_100_percent,positive		// now >= full
+	fetcht 2,mem_pdatatemp+2	        //shutdown voltage
+	isub temp,pdata
+	nbranch mouse_adc_bat_level_0_percent,positive		// now < shutdown
+	branch mouse_adc_bat_level_0_percent,blank			// now = shutdown
+	mul32 pdata,100,rega								// (now - shutdown)*100 /(full - shutdown)
+	fetch 2,mem_pdatatemp
+	fetcht 2,mem_pdatatemp+2
+	isub temp,temp
+	copy rega,pdata
+	idiv temp
+	call get_div_result
+	store 1,mem_le_battery_level_percentage
+	rtn
+
+mouse_adc_bat_level_100_percent:
+	jam 100,mem_le_battery_level_percentage
+	rtn
+mouse_adc_bat_level_0_percent:	
+	jam 0,mem_le_battery_level_percentage
+	rtn
+
+	
+mouse_adc_bat_percent_lowpower_out_vinlpm_multiple:
+	fetch 1,mem_adc_config_flag
+	beq ADC_CONFIG_GPIO,mouse_adc_bat_percent_lowpower_out_gpio_multiple
+	branch mouse_adc_bat_percent_lowpower_out_battery
+	
+
+mouse_adc_set_button_press_flag:
+	fetcht 1,mem_adc_power_flag
+	set1 2,temp
+	storet 1,mem_adc_power_flag
+	rtn	
+
+mouse_adc_clear_button_press_flag:
+	fetcht 1,mem_adc_power_flag
+	set0 2,temp
+	storet 1,mem_adc_power_flag
+	rtn		
+
+mouse_adc_button_press:
+	jam 1,mem_mouse_adc_button_press_flag
+	rtn
+
+mouse_power_down:
+	call mouse_device_led_all_off
+	branch mouse_app_enter_hibernate
+	
+/****************************adc**************************************/	
+
+/****************************gpio******************************************/
+mouse_gpio_init:
+	fetcht 1,mem_eeprom_wp_gpio
+	call gpio_config_output
+	call usb_offline_check_init
+	fetcht 1,mem_lbutton_gpio
+	call mouse_gpio_config_input_pu
+	fetcht 1,mem_rbutton_gpio
+	call mouse_gpio_config_input_pu
+	fetcht 1,mem_mbutton_gpio
+	call mouse_gpio_config_input_pu
+	fetcht 1,mem_bk_button_gpio
+	call mouse_gpio_config_input_pu
+	fetcht 1,mem_fw_button_gpio
+	call mouse_gpio_config_input_pu
+	fetcht 1,mem_dpi_button_gpio
+	call mouse_gpio_config_input_pu
+
+	fetcht 1,mem_matrix_public_gpio
+	call mouse_gpio_config_input_pu
+
+	fetcht 1,mem_config_select_device_button_gpio
+	call mouse_gpio_config_input_pu
+
+	fetcht 1,mem_customer_key_gpio
+	call mouse_gpio_config_input_pu
+
+	fetcht 1,mem_whee_a_data_gpio
+	call mouse_gpio_config_input_pu
+
+	fetcht 1,mem_whee_b_data_gpio
+	call mouse_gpio_config_input_pu
+
+	fetcht 1,mem_whee_ta_data_gpio
+	call mouse_gpio_config_input_pu
+	fetcht 1,mem_whee_tb_data_gpio
+	call mouse_gpio_config_input_pu
+
+	fetcht 1,mem_sensor_motion_gpio
+	call mouse_gpio_config_input_pu
+
+	fetcht 1,mem_device_switch_gpio
+	call mouse_gpio_config_input_pu
+	
+
+	fetcht 1,mem_sensor_reset_gpio
+	call gpio_config_output
+
+	fetcht 1,mem_config_low_voltage_alarm_gpio
+	call gpio_config_output
+
+	fetcht 1,mem_config_device_24g_led_gpio
+	call gpio_config_output
+
+	fetcht 1,mem_config_device_bt1_led_gpio
+	call gpio_config_output
+	
+	fetcht 1,mem_config_device_bt2_led_gpio
+	call gpio_config_output
+
+	fetcht 1,mem_dpi_led_gpio
+	call gpio_config_output
+
+	fetcht 1,mem_select_sensor_angle_gpio
+	branch mouse_gpio_config_input_pu
+
+
+mouse_gpio_set_pupd_by_input:
+	sub temp,UI_BUTTON_GPIO_DISABLE,null
+	rtn zero
+	and temp,0x7f,queue
+	fetch 4,core_gpio_in
+	qisolate1 pdata
+	branch mouse_gpio_config_input_pu,true
+	branch mouse_gpio_config_input_pd
+
+	
+mouse_gpio_config_input_pd:
+	set1 gpio_active_bit,temp
+	branch gpio_config_input
+
+mouse_gpio_config_input_pu:
+	set0 gpio_active_bit,temp
+	branch gpio_config_input
+
+mouse_gpio_set_high_impedance:
+	fetch 3,mem_mouse_set_high_impedance_bit_set
+	store 3,mem_pdatatemp
+	arg 20,loopcnt
+	arg 0,temp
+mouse_gpio_set_high_impedance_bit_loop:	
+	fetch 3,mem_pdatatemp
+	isolate1 0,pdata
+	call gpio_set_high_impedance,true
+	fetch 3,mem_pdatatemp
+	lshift pdata,pdata
+	store 3,mem_pdatatemp
+	increase 1,temp
+	loop mouse_gpio_set_high_impedance_bit_loop
+	rtn
+
+
+
+/****************************gpio******************************************/
+
+/*******************spi*****************************/
+mouse_sensor_spi_init:
+	call mouse_spid_init_pin
+	jam 0x73,mem_spi_init_clk
+//	jam 0x1e,mem_spi_init_delay_time
+	call mouse_spi_init
+	branch twspi_enable
+	
+mouse_spi_write_flash_cb:
+mouse_spi_init:
+	branch spid_init
+	
+mouse_spid_init_pin:
+	fetch 1,mem_mouse_sensor_sclk_gpio
+ 	arg gpcfg_spid_sck,temp
+ 	call gpio_config_function_int
+ 	fetch 1,mem_mouse_sensor_sdio_gpio
+ 	arg gpcfg_spid_sdio,temp
+ 	branch gpio_config_function_int
+
+
+/*******************spi*****************************/
+
+
+
+
+mouse_motion:
+	bpatch patch19_6,mem_patch19
+	disable user
+	setarg 0
+	store 6,mem_mouse_x
+	call mouse_check_sensor_data
+	call mouse_zwheel
+	call mouse_t_zwheel
+	call mouse_key
+	fetch 1,mem_mouse_key
+	and_into 0x1f,pdata
+	store 1,mem_mouse_key
+	nbranch mouse_drawing_optima_init,user
+	call mouse_drawing_optima
+	branch mouse_no_data_timer_init
+
+	
+
+/*******************wheel*************************/
+mouse_zwheel:
+	fetch 1,mem_mouse_z_data
+	rtn blank	
+	store 1,mem_mouse_z
+	jam 0,mem_mouse_z_data
+	branch enable_user
+	
+mouse_t_zwheel:
+	fetch 1,mem_mouse_tz_data
+	rtn blank	
+	store 1,mem_mouse_tz
+	jam 0,mem_mouse_tz_data
+	branch enable_user
+
+mouse_wheel_check:
+	call mouse_t_wheel_scan
+	call mouse_wheel_scan
+	fetch 1,mem_wheel_tb_new_pinlevel
+	fetcht 1,mem_wheel_tb_old_pinlevel
+	store 1,mem_wheel_tb_old_pinlevel
+	isub temp,null
+	nbranch app_lpm_wake_auto_lock,zero
+	fetch 1,mem_mwheel_b_new_pinlevel
+	fetcht 1,mem_mwheel_b_old_pinlevel
+	store 1,mem_mwheel_b_old_pinlevel
+	isub temp,null
+	nbranch app_lpm_wake_auto_lock,zero
+	rtn
+mouse_t_wheel_scan:
+	fetch 1,mem_whee_ta_data_gpio
+	rtneq GPIO_DISABLE
+	arg 0,rega
+	fetcht 1,mem_whee_ta_data_gpio
+	call gpio_get_bit
+	setflag true,0,rega
+	fetcht 1,mem_whee_tb_data_gpio
+	call gpio_get_bit
+	setflag true,1,rega
+	copy rega,pdata
+	store 1,mem_wheel_tb_new_pinlevel
+	beq 0x01,mouse_t_wheel_scan_judge1
+	beq 0x02,mouse_t_wheel_scan_judge2
+	fetch 1,mem_wheel_tog
+	bbit1 7,mouse_t_wheel_scan_judge3
+	rtn
+
+mouse_t_wheel_scan_judge1:
+	fetch 1,mem_wheel_tb_old_pinlevel
+	beq 0,mouse_t_wheel_scan_judge11
+	beq 3,mouse_t_wheel_scan_judge12
+	rtn
+mouse_t_wheel_scan_judge2:
+	fetch 1,mem_wheel_tb_old_pinlevel
+	beq 0,mouse_t_wheel_scan_judge21
+	beq 3,mouse_t_wheel_scan_judge22
+	rtn
+mouse_t_wheel_scan_judge11:
+	jam 0x82,mem_wheel_tog
+	rtn
+mouse_t_wheel_scan_judge12:
+	jam 0x81,mem_wheel_tog
+	rtn
+mouse_t_wheel_scan_judge21:
+	jam 0x80,mem_wheel_tog
+	rtn
+mouse_t_wheel_scan_judge22:
+	jam 0x83,mem_wheel_tog
+	rtn
+mouse_t_wheel_scan_judge3:
+	fetch 1,mem_wheel_tog
+	set0 7,pdata
+	store 1,mem_wheel_tog
+	beq 0,mouse_t_wheel_scan_judge30
+	beq 1,mouse_t_wheel_scan_judge31
+	beq 2,mouse_t_wheel_scan_judge32
+	beq 3,mouse_t_wheel_scan_judge33
+	rtn
+mouse_t_wheel_scan_judge30:
+	fetch 1,mem_wheel_tb_new_pinlevel
+	beq 3,mouse_wheel_t_forward
+	rtn
+mouse_t_wheel_scan_judge31:
+	fetch 1,mem_wheel_tb_new_pinlevel
+	beq 0,mouse_wheel_t_forward
+	rtn
+mouse_t_wheel_scan_judge32:
+	fetch 1,mem_wheel_tb_new_pinlevel
+	beq 3,mouse_wheel_t_back
+	rtn
+mouse_t_wheel_scan_judge33:
+	fetch 1,mem_wheel_tb_new_pinlevel
+	beq 0,mouse_wheel_t_back
+	rtn
+mouse_wheel_t_forward:
+	fetch 1,mem_mouse_tz_data
+	increase 1,pdata
+	store 1,mem_mouse_tz_data
+	rtn
+mouse_wheel_t_back:
+	fetch 1,mem_mouse_tz_data
+	increase -1,pdata
+	store 1,mem_mouse_tz_data
+	rtn
+
+
+mouse_wheel_scan:
+	fetch 1,mem_whee_a_data_gpio
+	rtneq GPIO_DISABLE
+	arg 0,rega
+	fetcht 1,mem_whee_a_data_gpio
+	call gpio_get_bit
+	setflag true,0,rega
+	fetcht 1,mem_whee_b_data_gpio
+	call gpio_get_bit
+	setflag true,1,rega
+	copy rega,pdata
+	store 1,mem_mwheel_b_new_pinlevel
+	beq 0x01,mouse_wheel_scan_judge1
+	beq 0x02,mouse_wheel_scan_judge2
+	fetch 1,mem_mwheel_tog
+	bbit1 7,mouse_wheel_scan_judge3
+	rtn
+
+mouse_wheel_scan_judge1:
+	fetch 1,mem_mwheel_b_old_pinlevel
+	beq 0,mouse_wheel_scan_judge11
+	beq 3,mouse_wheel_scan_judge12
+	rtn
+mouse_wheel_scan_judge2:
+	fetch 1,mem_mwheel_b_old_pinlevel
+	beq 0,mouse_wheel_scan_judge21
+	beq 3,mouse_wheel_scan_judge22
+	rtn
+mouse_wheel_scan_judge11:
+	jam 0x82,mem_mwheel_tog
+	rtn
+mouse_wheel_scan_judge12:
+	jam 0x81,mem_mwheel_tog
+	rtn
+mouse_wheel_scan_judge21:
+	jam 0x80,mem_mwheel_tog
+	rtn
+mouse_wheel_scan_judge22:
+	jam 0x83,mem_mwheel_tog
+	rtn
+mouse_wheel_scan_judge3:
+	fetch 1,mem_mwheel_tog
+	set0 7,pdata
+	store 1,mem_mwheel_tog
+	beq 0,mouse_wheel_scan_judge30
+	beq 1,mouse_wheel_scan_judge31
+	beq 2,mouse_wheel_scan_judge32
+	beq 3,mouse_wheel_scan_judge33
+	rtn
+mouse_wheel_scan_judge30:
+	fetch 1,mem_mwheel_b_new_pinlevel
+	beq 3,mouse_wheel_forward
+	rtn
+mouse_wheel_scan_judge31:
+	fetch 1,mem_mwheel_b_new_pinlevel
+	beq 0,mouse_wheel_forward
+	rtn
+mouse_wheel_scan_judge32:
+	fetch 1,mem_mwheel_b_new_pinlevel
+	beq 3,mouse_wheel_back
+	rtn
+mouse_wheel_scan_judge33:
+	fetch 1,mem_mwheel_b_new_pinlevel
+	beq 0,mouse_wheel_back
+	rtn
+mouse_wheel_forward:
+	fetch 1,mem_mouse_z_data
+	increase 1,pdata
+	store 1,mem_mouse_z_data
+	rtn
+mouse_wheel_back:
+	fetch 1,mem_mouse_z_data
+	increase -1,pdata
+	store 1,mem_mouse_z_data
+	rtn
+
+
+mouse_wheel_gpio_set_wake:
+	fetcht 1,mem_whee_a_data_gpio
+	call gpio_set_wake_by_current_state
+	fetcht 1,mem_whee_b_data_gpio
+	call gpio_set_wake_by_current_state
+	fetcht 1,mem_whee_ta_data_gpio
+	call gpio_set_wake_by_current_state
+	fetcht 1,mem_whee_tb_data_gpio
+	branch gpio_set_wake_by_current_state
+	
+mouse_before_hibernate_wheel_gpio_set:
+	fetcht 1,mem_whee_a_data_gpio
+	call mouse_gpio_set_pupd_by_input
+	fetcht 1,mem_whee_b_data_gpio
+	call mouse_gpio_set_pupd_by_input
+	fetcht 1,mem_whee_ta_data_gpio
+	call mouse_gpio_set_pupd_by_input
+	fetcht 1,mem_whee_tb_data_gpio
+	branch mouse_gpio_set_pupd_by_input
+
+mouse_wheel_trigger:
+	fetch 2,mem_mouse_z
+	rtn blank
+	jam 1,mem_mouse_wheel_trigger
+	jam 10,mem_mouse_wheel_trigger_timer
+	rtn
+
+mouse_wheel_trigger_timer:
+	arg mem_mouse_wheel_trigger_timer,regc
+	arg mouse_wheel_trigger_disable,regb
+	branch timer_single_step
+mouse_wheel_trigger_disable:
+	jam 0,mem_mouse_wheel_trigger
+	rtn
+
+
+/*
+mouse_set_qdecoder_x:
+	arg MOUSE_DEFAULT_XA_GPIO,temp
+	call mouse_gpio_config_input_pu
+	arg MOUSE_DEFAULT_XA_GPIO,temp
+	call gpio_get_bit
+	rtn true
+	fetch 1,core_qdec_cntx
+	set1 4,pdata
+	store 1,core_qdec_cntx
+	rtn
+*/	
+	
+/*******************wheel*************************/
+
+
+
+/********************dpi******************************/
+mouse_dpi_check:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit1 MOUSE_ENABLE_DPI_KEY_CONNECT_ADC,mouse_dpi_check_connect_adc
+	fetch 1,mem_dpi_button_gpio
+	rtneq GPIO_DISABLE
+	arg 0,rega
+	jam MOUSE_DPI_KEY,mem_mouse_key_temp
+	fetcht 1,mem_dpi_button_gpio
+	call mouse_dpi_key_check
+mouse_dpi_check_next:
+	store 1,mem_mouse_dpikey_press_status
+	fetch 1,mem_matrix_public_gpio
+	beq GPIO_DISABLE,mouse_3io6key_dpi_check_end
+	call mouse_matrix_public_gpio_reset
+mouse_dpi_check_exit:	
+	copy rega,pdata
+	bbit1 MOUSE_DPI_KEY,mouse_dpi_down
+	branch mouse_dpi_up
+
+mouse_dpi_check_connect_adc:
+	fetch 1,mem_mouse_adc_button_press_flag
+	branch mouse_dpi_up,blank
+	branch mouse_dpi_down
+	
+mouse_dpi_key_check:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit1 MOUSE_ENABLE_DPI_KEY_CONNECT_GND,mouse_dpi_key_connect_gnd
+	fetch 1,mem_mouse_dpikey_press_status
+	copy pdata,regc
+	fetch 1,mem_matrix_public_gpio
+	beq GPIO_DISABLE,mouse_3io6key_check
+mouse_dpi_key_check_next:
+	fetch 1,mem_mouse_ghost_flag
+	nbranch mouse_dpi_check_end,blank
+	branch mouse_dpi_key_connect_matrix	
+
+mouse_3io6key_dpi_check_end:
+	fetcht 1,mem_dpi_button_gpio
+	call mouse_gpio_config_input_pu
+	branch mouse_dpi_check_exit
+
+mouse_dpi_check_end:
+	jam DPI_BUTTON_STATE_UP,mem_mouse_dpi_button_state
+	jam 0,mem_mouse_dpikey_press_status
+	rtn
+
+mouse_dpi_key_connect_gnd:
+	fetch 1,mem_mouse_dpikey_press_status
+	branch mouse_check_key_connect_gnd
+
+mouse_dpi_key_connect_matrix:
+	call gpio_get_bit
+	fetcht 1,mem_matrix_public_gpio
+	branch mouse_dpi_key_connect_gnd,true
+	fetcht 1,mem_matrix_public_gpio
+	call gpio_out_active
+	fetcht 1,mem_dpi_button_gpio
+	fetch 1,mem_mouse_dpikey_press_status
+	branch mouse_check_key_connect_gnd
+
+
+mouse_dpi_down:
+	fetch 1,mem_mouse_dpi_button_state
+	rtneq DPI_BUTTON_STATE_DOWN
+	jam DPI_BUTTON_STATE_DOWN,mem_mouse_dpi_button_state
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	rtnbit1 MOUSE_ENABLE_SELECT_DEVICE_BY_DPI_BUTTON
+	rtnbit1 MOUSE_ENABLE_DPI_KEY_LONG_PRESS_DISCONVERY
+	branch mouse_dpi_process
+
+mouse_dpi_up:
+	fetch 1,mem_mouse_dpi_button_state
+	rtneq DPI_BUTTON_STATE_UP
+	jam DPI_BUTTON_STATE_UP,mem_mouse_dpi_button_state
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit1 MOUSE_ENABLE_SELECT_DEVICE_BY_DPI_BUTTON,mouse_dpi_up_next
+	bbit1 MOUSE_ENABLE_DPI_KEY_LONG_PRESS_DISCONVERY,mouse_dpi_up_next
+	rtn
+mouse_dpi_up_next:	
+	fetch 1,mem_mouse_dpi_long_press_flag
+	nbranch mouse_dpi_up_after_long_press,blank
+	fetch 1,mem_select_device_count
+	ncall mouse_dpi_process,blank
+mouse_dpi_up_after_long_press:	
+	jam 0,mem_mouse_dpi_long_press_flag
+	fetch 1,mem_ui_button_timeout
+	store 1,mem_select_device_count	
+	store 1,mem_bt_discovery_count	
+	rtn
+	
+mouse_dpi_process:	
+	bpatch patch19_7,mem_patch19
+	call mouse_dpi_ghost_check
+	rtn user
+	fetch 1,mem_mouse_dpi
+	increase 1,pdata
+	and pdata,0x03,pdata
+	store 1,mem_mouse_dpi
+	call mouse_seting_dpi
+	branch mouse_store_device_info_delay
+
+mouse_dpi_ghost_check:
+	disable user
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	rtnbit1 MOUSE_ENABLE_DPI_KEY_CONNECT_GND
+	rtnbit1 MOUSE_ENABLE_DPI_KEY_CONNECT_ADC
+	fetch 1,mem_mouse_lkey_press_status
+	rtn blank
+	fetch 1,mem_mouse_rkey_press_status
+	rtn blank
+	enable user
+	rtn
+	
+
+mouse_dpi_key_check_long_press:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit1 MOUSE_ENABLE_SELECT_DEVICE_BY_DPI_BUTTON,mouse_select_device_by_dpi_button
+	bbit1 MOUSE_ENABLE_DPI_KEY_LONG_PRESS_DISCONVERY,mouse_discovery_by_dpi_button
+	rtn
+
+
+mouse_select_device_by_dpi_button:
+	fetch 1,mem_mouse_dpi_button_state
+	rtnne DPI_BUTTON_STATE_DOWN	
+	arg mem_select_device_count,regc
+	arg mouse_ready_reconnection_by_dpi_button,regb
+	branch timer_single_step
+
+mouse_ready_reconnection_by_dpi_button:
+	jam 1,mem_mouse_dpi_long_press_flag
+	branch mouse_ready_reconnection_by_button
+
+mouse_discovery_by_dpi_button:
+	fetch 1,mem_mouse_dpi_button_state
+	rtnne DPI_BUTTON_STATE_DOWN	
+	arg mem_bt_discovery_count,regc
+	arg mouse_long_dpi_button_bt_discovery,regb
+	branch timer_single_step
+
+mouse_long_dpi_button_bt_discovery:
+	jam 1,mem_mouse_dpi_long_press_flag
+	branch mouse_long_button_bt_discovery
+
+
+
+mouse_dpi_config:
+	branch mouse_seting_sensor_type
+
+
+mouse_setting_dpi_4_level:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	rtnbit1 MOUSE_ENABLE_DPI_LEVEL_4
+	fetch 1,mem_mouse_dpi
+	rtnne MOUSE_DPI_LEVEL4
+	jam MOUSE_DPI_LEVEL1,mem_mouse_dpi
+	rtn
+	
+
+mouse_seting_dpi:
+	bpatch patch1a_0,mem_patch1a
+	call mouse_setting_dpi_4_level
+	call mouse_dpi_led_blink_delay
+mouse_seting_sensor_type:
+	fetch 1,mem_config_sensor_type
+	beq P3212,mouse_seting_3212_dpi
+	beq KA8G2,mouse_seting_ka8g2_dpi
+	fetch 1,mem_mouse_dpi
+	beq MOUSE_DPI_LEVEL1,mouse_set_cpi0		//1200
+	beq MOUSE_DPI_LEVEL2,mouse_set_cpi1		//1600
+	beq MOUSE_DPI_LEVEL3,mouse_set_cpi2		//800
+	beq MOUSE_DPI_LEVEL4,mouse_set_cpi3		//1000
+mouse_set_cpi1:	//320x+8009
+	fetcht 1,mem_320x_dpi_1
+	branch mouse_dpi_store
+mouse_set_cpi0:
+	fetcht 1,mem_320x_dpi_0
+	branch mouse_dpi_store
+mouse_set_cpi2:
+	fetcht 1,mem_320x_dpi_2
+	branch mouse_dpi_store
+mouse_set_cpi3:
+	fetcht 1,mem_320x_dpi_3
+	branch mouse_dpi_store
+
+mouse_dpi_store:
+	fetch 1,mem_config_sensor_type
+	beq P3065_XY,mouse_3065xy_set_dpi
+	beq MX8650,mouse_3065xy_set_dpi
+	beq KA8,mouse_ka8_set_dpi
+	beq P6520,mouse_ka8_set_dpi
+	beq P8009,mouse_3065xy_set_dpi
+mouse_dpi_write:		// 3205  1  2  3  4
+	storet 1,mem_mouse_cpi_count
+	setarg MOUSE_DPI_ADDRESS
+	call twspi_read
+	and pdata,0xf8,temp
+	fetch 1,mem_mouse_cpi_count
+	iadd temp,pdata
+	lshift8 pdata,pdata
+	add pdata,MOUSE_DPI_ADDRESS,pdata
+	branch twspi_write
+
+mouse_3065xy_set_dpi:	// 0 1 2 3
+	increase -1,temp
+	branch mouse_dpi_write
+
+mouse_ka8_set_dpi:	// 3 4 5 6
+	increase 2,temp
+	branch mouse_dpi_write
+
+mouse_seting_3212_dpi:
+	fetch 1,mem_mouse_dpi
+	beq MOUSE_DPI_LEVEL1,mouse_set_p3212_cpi0	//1200
+	beq MOUSE_DPI_LEVEL2,mouse_set_p3212_cpi1	//1600
+	beq MOUSE_DPI_LEVEL3,mouse_set_p3212_cpi2	//2400
+	beq MOUSE_DPI_LEVEL4,mouse_set_p3212_cpi3	//800
+mouse_set_p3212_cpi1:
+	fetch 1,mem_3212_dpi_1
+	branch mouse_p3212_dpi
+mouse_set_p3212_cpi0:
+	fetch 1,mem_3212_dpi_0
+	branch mouse_p3212_dpi
+mouse_set_p3212_cpi2:
+	fetch 1,mem_3212_dpi_2
+	branch mouse_p3212_dpi
+mouse_set_p3212_cpi3:
+	fetch 1,mem_3212_dpi_3
+mouse_p3212_dpi:
+	store 1,mem_mouse_cpi_count
+	lshift8 pdata,pdata
+	copy pdata,rega
+	add pdata,MOUSE_P3212_DPI_XADDRESS,pdata
+  	call twspi_write
+ 	copy rega,pdata
+  	add pdata,MOUSE_P3212_DPI_YADDRESS,pdata
+	branch twspi_write
+
+mouse_seting_ka8g2_dpi:
+	fetch 1,mem_mouse_dpi
+	beq MOUSE_DPI_LEVEL1,mouse_set_pka8g2_cpi0		//1600
+	beq MOUSE_DPI_LEVEL2,mouse_set_pka8g2_cpi1		//2400
+	beq MOUSE_DPI_LEVEL3,mouse_set_pka8g2_cpi2		//3200
+	beq MOUSE_DPI_LEVEL4,mouse_set_pka8g2_cpi3		//800
+mouse_set_pka8g2_cpi1:
+	fetch 1,mem_ka8g2_dpi_1
+	branch mouse_p3212_dpi
+
+mouse_set_pka8g2_cpi0:
+	fetch 1,mem_ka8g2_dpi_0
+	branch mouse_p3212_dpi
+	
+mouse_set_pka8g2_cpi2:
+	fetch 1,mem_ka8g2_dpi_2
+	branch mouse_p3212_dpi
+
+mouse_set_pka8g2_cpi3:
+	fetch 1,mem_ka8g2_dpi_3
+	branch mouse_p3212_dpi
+
+		
+/********************dpi******************************/		
+
+
+/***********************key******************************/
+
+mouse_key:
+	call mouse_check_key_gpio
+	call mouse_ghost_key_check
+	call mouse_set_mult
+	call mouse_24g_key
+	copy rega,pdata
+	fetcht 1,mem_mouse_key_last
+	store 1,mem_mouse_key_last
+	store 1,mem_mouse_key
+	ixor temp,pdata
+	sub pdata,0,null
+	rtn zero
+	branch enable_user
+
+mouse_24g_key:
+	rtnmark0 mark_24g
+	copy rega,pdata
+	rtn blank
+	store 1,mem_mouse_key
+	branch enable_user
+
+mouse_ghost_key_check:
+	jam 0,mem_mouse_matrix_key_cow_count
+	jam 0,mem_mouse_matrix_key_row_count
+	jam 0,mem_mouse_ghost_flag
+	copy pdata,temp
+	call mouse_ghost_key_check_L_BK
+	call mouse_ghost_key_check_M_FW
+	call mouse_ghost_key_check_BK_FW
+	call mouse_ghost_key_check_LMR
+	fetch 1,mem_mouse_matrix_key_row_count
+	rtn blank
+	fetch 1,mem_mouse_matrix_key_cow_count
+	rtn blank
+	jam 1,mem_mouse_ghost_flag
+	fetch 1,mem_mouse_key_last		// matrix have ghost key
+	copy pdata,rega
+	rtn
+
+mouse_ghost_key_check_L_BK:
+	and temp,MOUSE_L_BK_BUTTON,pdata
+	beq MOUSE_L_BK_BUTTON,mouse_matrix_cow_more_than_one_key
+	rtn
+mouse_ghost_key_check_M_FW:
+	and temp,MOUSE_M_FW_BUTTON,pdata
+	beq MOUSE_M_FW_BUTTON,mouse_matrix_cow_more_than_one_key
+	rtn
+mouse_ghost_key_check_BK_FW:
+	and temp,MOUSE_BK_FW_BUTTON,pdata
+	beq MOUSE_BK_FW_BUTTON,mouse_matrix_row_more_than_one_key
+	rtn	
+
+mouse_ghost_key_check_LMR:
+	and temp,MOUSE_LMR_BUTTON,pdata	// key LMR press
+	beq MOUSE_LR_BUTTON,mouse_matrix_row_more_than_one_key
+	beq MOUSE_LM_BUTTON,mouse_matrix_row_more_than_one_key
+	beq MOUSE_RM_BUTTON,mouse_matrix_row_more_than_one_key
+	beq MOUSE_LMR_BUTTON,mouse_matrix_row_more_than_one_key
+	rtn
+
+
+mouse_matrix_row_more_than_one_key:
+	jam 1,mem_mouse_matrix_key_row_count
+	rtn
+
+mouse_matrix_cow_more_than_one_key:
+	jam 1,mem_mouse_matrix_key_cow_count
+	rtn
+
+mouse_key_check_once:
+	call mouse_check_key_gpio_once
+	call mouse_check_key_gpio
+	setarg 0x00
+	store 3,mem_mouse_lkey_press_status
+	rtn
+	
+mouse_check_key_gpio:
+	bpatch patch1a_1,mem_patch1a
+	fetch 1,mem_sensor_shutdown_flag
+	ncall mouse_check_key_gpio_once,blank
+	arg 0,rega
+	call mouse_check_lkey_gpio
+	call mouse_check_rkey_gpio
+	call mouse_check_mkey_gpio
+	call mouse_check_bkkey_gpio
+	call mouse_check_fwkey_gpio
+mouse_check_key_gpio_next:
+	call mouse_check_customerkey_gpio
+	copy rega,pdata
+	rtn
+
+mouse_check_key_gpio_once:
+	setarg 0x030303
+	store 3,mem_mouse_lkey_press_status
+	rtn
+
+mouse_check_lkey_gpio:
+	jam MOUSE_L_KEY,mem_mouse_key_temp
+	fetcht 1,mem_lbutton_gpio
+	fetch 1,mem_mouse_lkey_press_status
+	call mouse_check_key_connect_gnd
+	store 1,mem_mouse_lkey_press_status
+	rtn
+
+mouse_check_rkey_gpio:
+	jam MOUSE_R_KEY,mem_mouse_key_temp
+	fetcht 1,mem_rbutton_gpio
+	fetch 1,mem_mouse_rkey_press_status
+	call mouse_check_key_connect_gnd
+	store 1,mem_mouse_rkey_press_status
+	rtn
+	
+mouse_check_mkey_gpio:
+	jam MOUSE_M_KEY,mem_mouse_key_temp
+	fetcht 1,mem_mbutton_gpio
+	fetch 1,mem_mouse_mkey_press_status
+	call mouse_check_key_connect_gnd
+	store 1,mem_mouse_mkey_press_status
+	rtn
+
+mouse_check_bkkey_gpio:
+	fetch 1,mem_bk_button_gpio
+	rtneq GPIO_DISABLE
+	jam MOUSE_BK_KEY,mem_mouse_key_temp
+	fetch 1,mem_mouse_bkkey_press_status
+	copy pdata,regc
+	fetcht 1,mem_bk_button_gpio
+	fetch 1,mem_matrix_public_gpio
+	beq GPIO_DISABLE,mouse_3io6key_bk_check
+mouse_check_bkkey_gpio_next:
+	call gpio_get_bit
+	branch mouse_check_bk_button_connect_gnd,true
+	fetcht 1,mem_matrix_public_gpio
+	call gpio_out_active
+	fetcht 1,mem_bk_button_gpio
+	fetch 1,mem_mouse_bkkey_press_status
+	call mouse_check_key_connect_gnd
+mouse_check_bkkey_gpio_end:	
+	store 1,mem_mouse_bkkey_press_status
+	branch mouse_matrix_public_gpio_reset
+
+mouse_check_bk_button_connect_gnd:
+	fetcht 1,mem_matrix_public_gpio
+	fetch 1,mem_mouse_bkkey_press_status
+	call mouse_check_key_connect_gnd
+	branch mouse_check_bkkey_gpio_end
+
+mouse_3io6key_bk_check:
+	call mouse_3io6key_check
+	store 1,mem_mouse_bkkey_press_status
+	fetcht 1,mem_bk_button_gpio
+	branch mouse_gpio_config_input_pu
+
+
+mouse_check_fwkey_gpio:
+	fetch 1,mem_fw_button_gpio
+	rtneq GPIO_DISABLE
+	jam MOUSE_FW_KEY,mem_mouse_key_temp
+	fetch 1,mem_mouse_fwkey_press_status
+	copy pdata,regc
+	fetcht 1,mem_fw_button_gpio
+	fetch 1,mem_matrix_public_gpio
+	beq GPIO_DISABLE,mouse_3io6key_fw_check
+mouse_check_fwkey_gpio_next:
+	call gpio_get_bit
+	branch mouse_check_fw_button_connect_gnd,true
+	fetcht 1,mem_matrix_public_gpio
+	call gpio_out_active
+	fetcht 1,mem_fw_button_gpio
+	fetch 1,mem_mouse_fwkey_press_status
+	call mouse_check_key_connect_gnd
+mouse_check_fwkey_gpio_end:	
+	store 1,mem_mouse_fwkey_press_status
+	branch mouse_matrix_public_gpio_reset
+
+mouse_check_fw_button_connect_gnd:
+	fetcht 1,mem_matrix_public_gpio
+	fetch 1,mem_mouse_fwkey_press_status
+	call mouse_check_key_connect_gnd
+	branch mouse_check_fwkey_gpio_end	
+
+mouse_3io6key_fw_check:
+	call mouse_3io6key_check
+	store 1,mem_mouse_fwkey_press_status
+	fetcht 1,mem_fw_button_gpio
+	branch mouse_gpio_config_input_pu
+
+
+mouse_matrix_public_gpio_reset:	
+	fetcht 1,mem_matrix_public_gpio
+	branch mouse_gpio_config_input_pu
+
+mouse_check_customerkey_gpio:
+	jam 0,mem_customer_key
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	rtnbit0 MOUSE_ENABLE_KEYBOARD
+	fetch 1,mem_customer_key_gpio
+	rtneq GPIO_DISABLE
+	jam MOUSE_CUSTOMER_KEY,mem_mouse_key_temp
+	fetcht 1,mem_customer_key_gpio
+	fetch 1,mem_mouse_customerkey_press_status
+	call mouse_check_key_connect_gnd
+	store 1,mem_mouse_customerkey_press_status
+mouse_check_customerkey_state:
+	copy rega,pdata
+	bbit1 MOUSE_CUSTOMER_KEY,mouse_customerkey_press
+	call mouse_customerkey_release
+mouse_check_customerkey_gpio_exit:
+	fetch 1,mem_customer_data_trigger
+	store 1,mem_customer_data_trigger_last
+	rtn
+
+
+mouse_customerkey_press:
+	jam 1,mem_customer_data_trigger
+	call mouse_customer_key_need_send
+	branch mouse_check_customerkey_gpio_exit
+
+mouse_customerkey_release:
+	jam 0,mem_customer_data_trigger
+	fetch 1,mem_customer_data_trigger_last
+	rtn blank
+mouse_customer_key_need_send:	
+	jam 1,mem_customer_key
+	rtn	
+
+
+mouse_check_matrix_button_connect_gnd:	
+	call gpio_get_bit
+	fetcht 1,mem_mouse_key_temp
+	copy temp,queue	
+	branch  mouse_key_press,true
+	branch mouse_key_release
+
+mouse_check_key_connect_gnd:	
+	lshift pdata,pdata
+	copy pdata,regb
+	call gpio_get_bit
+	setflag true,0,regb
+	and regb,0x07,pdata
+	fetcht 1,mem_mouse_key_temp
+	copy temp,queue
+	beq 0x07,mouse_key_press		//  about 17~22ms three times
+	beq 0x00,mouse_key_release
+	rtn
+
+mouse_key_release:
+	qset0 rega
+	rtn		
+
+mouse_key_press:
+	qset1 rega
+	rtn
+
+mouse_3io6key_check:
+	bpatch patch1a_2,mem_patch1a
+	copy regc,pdata
+	store 1,mem_mouse_key_status
+	lshift pdata,pdata
+	copy pdata,regb
+	copy temp,regc
+	call mouse_gpio_config_input_pd
+	copy regc,temp
+	call gpio_get_bit
+	nsetflag true,0,regb
+	call mouse_check_press
+	branch mouse_check_key_connect_gnd+4
+
+mouse_check_press:
+	fetcht 1,mem_mouse_key_status
+	and_into 0x01,temp
+	and regb,0x01,pdata
+	isub temp,null
+	nbranch mouse_current_mult_update,zero
+	rtn
+	
+/*************************key***************************************/
+
+/**********************sensor******************************/	
+mouse_init_sunt:
+	bpatch patch1a_3,mem_patch1a
+	call mouse_sensor_spi_init
+	rtn wake
+mouse_init_sensor_wakeup:	
+	call mouse_sensor_poweron
+mouse_init_sensor:
+	call mouse_read_sensor_id
+	beq P32XX_ID1,mouse_init_p32xx_id2_judge
+	beq P3065_ID1,mouse_init_p3065
+	beq PKA8G2_ID1,mouse_ka8g2_id2_judge
+	call mouse_twspi_reset
+	nop 6900
+	branch mouse_init_sensor
+mouse_twspi_reset:
+	fetch 1,mem_mouse_sensor_sclk_gpio
+	call twspi_reset 
+	branch mouse_spid_init_pin
+
+mouse_read_sensor_id:
+	setarg PAN_REG_PID_H
+	call twspi_read
+	store 1,mem_sensor_id2
+	setarg PAN_REG_PID_L
+	call twspi_read
+	store 1,mem_sensor_id1
+	rtn
+
+	
+
+mouse_init_p32xx_id2_judge:
+	fetch 1,mem_sensor_id2
+	beq P_MX8650,mouse_mx8650_init_param
+	beq P8009_ID2,mouse_8009_init_param
+	beq P3205_TJ3T_ID2,mouse_3205_3t_init_param
+	beq P3204_TJ3L_ID2,mouse_3204_3l_init_param
+	beq P3212_ID2,mouse_3212_init_param
+	beq PKA8_ID2,mouse_ka8_init_param_check
+	beq P6520A_ID2,mouse_p6520_init_param
+	branch mouse_init_sensor
+	
+mouse_mx8650_init_param:
+	jam MX8650,mem_config_sensor_type
+	call mouse_sensor_reset
+	call delay_10ms
+	arg mem_sensor_8650_init,regc
+	call mouse_sensor_wr_seq
+	branch mouse_dpi_config
+
+mouse_8009_init_param:
+	setarg 0x16
+	call twspi_read
+	sub pdata,0xbd,null 
+	nbranch mouse_init_sunt,zero
+	setarg 0x19
+	call twspi_read
+	sub pdata,0x55,null 
+	nbranch mouse_init_sunt,zero
+	setarg 0x1b
+	call twspi_read
+	sub pdata,0x1d,null 
+	nbranch mouse_init_sunt,zero
+	jam P8009,mem_config_sensor_type
+	arg mem_sensor_8009_init,regc
+	branch mouse_sensor_wr_seq
+
+mouse_3205_3t_init_param:
+	jam P3205,mem_config_sensor_type
+	arg mem_sensor_3205_init,regc
+	call mouse_sensor_wr_seq
+	arg mem_sensor_32xx_init,regc
+	call mouse_sensor_wr_seq
+	setarg 0x0943
+	call twspi_write
+	arg mem_sensor_32xx_init_1,regc
+	branch mouse_sensor_wr_seq	
+
+mouse_3204_3l_init_param:
+	jam P3204,mem_config_sensor_type
+	arg mem_sensor_3204_init,regc
+	call mouse_sensor_wr_seq
+	arg mem_sensor_32xx_init,regc
+	call mouse_sensor_wr_seq
+	arg mem_sensor_32xx_init_1,regc
+	branch mouse_sensor_wr_seq	
+
+mouse_3212_init_param:
+	jam P3212,mem_config_sensor_type
+	arg mem_sensor_3212_init,regc
+	branch mouse_sensor_wr_seq
+
+mouse_ka8_init_param_check:	
+	call mouse_sensor_disable_wp
+	setarg 0x9a5b
+	call twspi_write
+	setarg 0x0d
+	call twspi_read
+	sub pdata,0x12,null
+	branch mouse_ka8ul_init_param,zero
+	sub pdata,0x0a,null
+	nbranch mouse_ka8hd_sensor_judge,zero
+	setarg 0x0e
+	call twspi_read
+	sub pdata,0xe5,null
+	nbranch mouse_init_sensor,zero
+	setarg 0x10
+	call twspi_read
+	sub pdata,0xa5,null
+	branch mouse_ka8ul_init_param,zero
+	call mouse_enable_ka8_sensor_wp
+mouse_ka8_init_param:
+	jam KA8,mem_config_sensor_type	
+	rtn
+mouse_ka8ul_init_param:
+	jam KA8_UL,mem_config_sensor_type	
+	arg mem_sensor_ka8ul_init,regc
+	branch mouse_sensor_wr_seq
+mouse_ka8hd_sensor_judge:
+	sub pdata,0x10,null
+	nbranch mouse_init_sensor,zero
+	setarg 0x0e
+	call twspi_read
+	sub pdata,0xc5,null
+	nbranch mouse_init_sensor,zero
+	setarg 0x10
+	call twspi_read
+	sub pdata,0x38,null
+	nbranch mouse_init_sensor,zero
+mouse_ka8hd_init_param:
+	call mouse_enable_ka8_sensor_wp
+	jam KA8_HD,mem_config_sensor_type
+	rtn
+mouse_enable_ka8_sensor_wp:
+	setarg 0x005b
+	call twspi_write
+	branch mouse_sensor_enable_wp
+	
+mouse_p6520_init_param:
+	jam P6520,mem_config_sensor_type
+	arg mem_sensor_p6520_init,regc
+	branch mouse_sensor_wr_seq
+	
+mouse_init_p3065:
+	call mouse_sensor_poweron
+	fetch 1,mem_sensor_id2
+	beq P3065_XY_ID2,mouse_p3065xy_init_param
+	beq P3065_ID2,mouse_p3065_init_param
+	branch mouse_init_sensor
+	
+mouse_p3065_init_param:	
+	jam P3065,mem_config_sensor_type
+	rtn
+
+mouse_p3065xy_init_param:
+	jam P3065_XY,mem_config_sensor_type
+	rtn
+	
+mouse_ka8g2_id2_judge:
+	call mouse_sensor_poweron
+	fetch 1,mem_sensor_id2
+	beq PKA8G2_ID2,mouse_ka8g2_init_param
+	branch mouse_init_p32xx_id2_judge
+mouse_ka8g2_init_param:
+	jam KA8G2,mem_config_sensor_type
+	arg mem_sensor_ka8g2_init,regc
+	branch mouse_sensor_wr_seq
+	
+mouse_sensor_enable_wp:
+	setarg 0x0009
+	branch twspi_write
+mouse_sensor_disable_wp:
+	setarg 0x5a09
+	branch twspi_write
+
+mouse_sensor_wr_seq:
+	ifetch 2,regc
+	arg 0xffff,temp
+	isub temp,null
+	rtn zero
+	call twspi_write
+	increase 2,regc
+	branch mouse_sensor_wr_seq
+
+mouse_sensor_reset:
+	setarg 0x8006		// reset to factory settings
+mouse_sensor_reset_end:
+	call twspi_write
+	nop 12000
+	rtn
+	
+mouse_sensor_poweron:
+	bpatch patch1a_4,mem_patch1a
+	call mouse_sensor_spi_init
+mouse_sensor_poweron_next:
+	call mouse_sensor_reset
+	arg mem_sensor_poweron_init,regc
+mouse_sensor_poweron_end:
+	call mouse_sensor_wr_seq
+	branch mouse_dpi_config
+
+mouse_sensor_powerdown:
+	call mouse_init_sunt
+	call mouse_sensor_spi_init
+mouse_sensor_powerdown_end:
+	setarg 0x0806
+	branch twspi_write
+/*********sensor init*************/	
+
+
+
+/*********sensor motion*************/
+mouse_check_sensor_data:
+	fetch 1,mem_spi_write_flash_sm
+	rtnne FLASH_SM_NO_BUYS
+	fetch 1,mem_config_sensor_type
+	beq P3205,mouse_p32xx_sensor_motion
+	beq P3065,mouse_p32xx_sensor_motion
+	beq KA8,mouse_p32xx_sensor_motion
+	beq P3204,mouse_p32xx_sensor_motion
+	beq P3212,mouse_p3212_sensor_motion
+	beq P3065_xy,mouse_p32xx_sensor_motion
+	beq P8009,mouse_p8009_sensor_motion	
+	beq KA8G2,mouse_pka8g2_sensor_motion
+	branch mouse_p32xx_sensor_motion
+
+
+mouse_p32xx_sensor_motion:
+	call mouse_clear_sensor_data
+	disable user
+	fetch 1,mem_sensor_motion_gpio
+	beq GPIO_DISABLE,mouse_p32xx_sensor_motion_2
+	fetcht 1,mem_sensor_motion_gpio
+	call gpio_get_bit
+	nrtn true
+mouse_p32xx_sensor_motion_2:
+	setarg PAN_REG_PID_L
+	call twspi_read
+	bne P32XX_ID1,mouse_p3065_judge   
+mouse_p32xx_sensor_motion_1:
+	setarg PAN_REG_MOTION_STAUS
+	call twspi_read
+	rtnbit0 7
+	call mouse_read_sensor_common
+	fetch 1,mem_mouse_x
+	call mouse_data_extsign
+	store 2,mem_mouse_x
+	fetch 1,mem_mouse_y
+	call mouse_data_extsign
+	store 2,mem_mouse_y
+	fetch 1,mem_config_sensor_angle
+	beq MOUSE_6CLK_ANGLE,mouse_motion32xx_6clk_direction_selection
+	beq MOUSE_9CLK_ANGLE,mouse_motion32xx_9clk_direction_selection
+	beq MOUSE_12CLK_ANGLE,mouse_motion32xx_12clk_direction_selection
+	beq MOUSE_3CLK_ANGLE,mouse_motion32xx_3clk_direction_selection
+	rtn
+
+mouse_p3065_judge:
+	beq P3065_ID1,mouse_p32xx_sensor_motion_1
+	branch mouse_twspi_reset
+	
+mouse_motion32xx_6clk_direction_selection:
+	call mouse_motion_6clk_direction_dispose
+	branch mouse_sensor_sdio_low
+mouse_motion32xx_9clk_direction_selection:
+	call mouse_motion_9clk_direction_dispose
+	branch mouse_sensor_sdio_low
+mouse_motion32xx_12clk_direction_selection:
+	call mouse_motion_12clk_direction_dispose
+	branch mouse_sensor_sdio_low
+mouse_motion32xx_3clk_direction_selection:
+	call mouse_motion_3clk_direction_dispose
+	branch mouse_sensor_sdio_low
+
+
+	
+mouse_p3212_sensor_motion:
+	call mouse_clear_sensor_data
+	fetch 1,mem_sensor_motion_gpio
+	beq GPIO_DISABLE,mouse_p3212_sensor_motion_1
+	fetcht 1,mem_sensor_motion_gpio
+	call gpio_get_bit
+	nrtn true
+mouse_p3212_sensor_motion_1:	
+	setarg PAN_REG_PID_L
+	call twspi_read
+	bne P32XX_ID1,mouse_twspi_reset
+mouse_p3212_sensor_motion_2:
+	setarg PAN_REG_MOTION_STAUS
+	call twspi_read
+	rtnbit0 7
+	call mouse_read_sensor_common
+	call mouse_read_3212sensor_xy_high
+	store 1,mem_mouse_xy_h
+	rshift4 pdata,pdata
+	call mouse_data_extsign_bit3
+	store 1,mem_mouse_x+1
+	fetch 1,mem_mouse_xy_h
+	and pdata,0x0f,pdata
+	call mouse_data_extsign_bit3
+	store 1,mem_mouse_y+1
+	fetch 1,mem_config_sensor_angle
+	beq MOUSE_6CLK_ANGLE,mouse_motion_6clk_direction_dispose
+	beq MOUSE_9CLK_ANGLE,mouse_motion_9clk_direction_dispose
+	beq MOUSE_12CLK_ANGLE,mouse_motion_12clk_direction_dispose
+	beq MOUSE_3CLK_ANGLE,mouse_motion_3clk_direction_dispose
+	rtn
+
+mouse_read_3212sensor_xy_high:
+	setarg 0x12
+	branch twspi_read
+
+mouse_pka8g2_sensor_motion:
+	call mouse_clear_sensor_data
+	fetch 1,mem_sensor_motion_gpio
+	beq GPIO_DISABLE,mouse_pka8g2_sensor_motion_1
+	fetcht 1,mem_sensor_motion_gpio
+	call gpio_get_bit
+	nrtn true
+mouse_pka8g2_sensor_motion_1:
+	branch mouse_p3212_sensor_motion_2
+
+
+mouse_p8009_sensor_motion:
+	call mouse_clear_sensor_data
+	disable user
+	setarg PAN_REG_MOTION_STAUS
+	call twspi_read
+	rtnbit0 7
+	setarg PAN_REG_OPRATION_STATE
+	call twspi_read
+	branch mouse_p32xx_sensor_motion_1+3,blank
+	setarg 0
+	store 6,mem_mouse_x
+	rtn
+
+
+
+mouse_sensor_set_angle:
+	fetch 1,mem_sensor_angle_default
+	store 1,mem_config_sensor_angle
+	fetch 1,mem_select_sensor_angle_gpio
+	rtneq GPIO_DISABLE
+	fetcht 1,mem_select_sensor_angle_gpio
+	call mouse_gpio_config_input_pu
+	fetcht 1,mem_select_sensor_angle_gpio
+	call gpio_get_bit
+	call mouse_sensor_switch_angle,true
+	branch mouse_gpio_config_input_pd
+mouse_sensor_switch_angle:
+	fetch 1,mem_sensor_angle_switch
+	store 1,mem_config_sensor_angle
+	rtn
+	
+mouse_motion_6clk_direction_dispose:
+	fetch 2,mem_mouse_x
+	sub pdata,0,pdata
+	store 2,mem_mouse_x
+	branch enable_user
+mouse_motion_12clk_direction_dispose:
+	fetch 2,mem_mouse_y
+	sub pdata,0,pdata
+	store 2,mem_mouse_y
+	branch enable_user
+mouse_motion_9clk_direction_dispose:
+	fetch 2,mem_mouse_y
+	sub pdata,0,pdata
+	store 2,mem_mouse_y
+	fetch 2,mem_mouse_x
+	sub pdata,0,pdata
+	store 2,mem_mouse_x
+	call mouse_sensor_data_swap_places
+	branch enable_user
+mouse_motion_3clk_direction_dispose:
+	call mouse_sensor_data_swap_places
+	branch enable_user
+
+mouse_sensor_data_swap_places:
+	fetch 2, mem_mouse_y
+	fetcht 2,mem_mouse_x
+	store 2,mem_mouse_x
+	storet 2,mem_mouse_y
+	rtn
+
+	
+mouse_clear_sensor_data:
+	fetch 1,mem_mouse_move_flag
+	call mouse_read_sensor_common,blank
+	jam 1,mem_mouse_move_flag
+	rtn
+
+mouse_clear_sensor_data_by_reset:
+	jam 1,mem_mouse_clear_sensor_data_flag
+	call le_set_config_more_data
+mouse_init_sensor_reset:
+	branch mouse_init_sunt
+
+mouse_data_xy_release:
+	fetch 1,mem_sensor_motion_gpio
+	rtnne GPIO_DISABLE
+	fetch 1,mem_mouse_long_mult_flag
+	rtnne 1
+	setarg 0
+	store 1,mem_mouse_long_mult_flag
+	store 4,mem_mouse_x
+	branch mouse_init_sensor_reset
+
+mouse_data_extsign:
+	rtnbit0 7
+mouse_data_overflow:
+	arg 0xff00,temp
+	ior temp,pdata
+	rtn
+
+mouse_data_extsign_bit3:
+	rtnbit0 3
+	arg 0xf0,temp
+	ior temp,pdata
+	rtn
+
+mouse_read_sensor_common:
+	arg PAN_REG_DELTA_X,pdata
+	call twspi_read
+	store 2,mem_mouse_x
+	arg PAN_REG_DELTA_Y,pdata
+	call twspi_read
+	store 2,mem_mouse_y
+	rtn
+
+	/* sdio high will cost extra 9mA */
+mouse_sensor_sdio_low:
+	fetcht 1,mem_mouse_sensor_sdio_gpio
+	call gpio_get_bit
+	rtn true
+	setarg 0x0a
+	call twspi_read
+	nop 1000
+	branch mouse_sensor_sdio_low
+
+mouse_set_sdio_high:		// make sdio high to make 100uA less
+	setarg 0x8100
+	branch twspi_write
+	
+/****************************sensor*************************/
+
+/*******************mouse fast connect******************/
+mouse_buletooth_fast_conn_init:
+	jam 0xff,mem_mouse_bluetooth_fast_conn_flag
+	fetch 1,mem_mouse_bluetooth_type
+	bbit1 MODE_4_MOUSE,mouse_ble_fast_conn_init
+	bbit1 MODE_3_MOUSE,mouse_bt_fast_conn_init
+mouse_ble_fast_conn_init:	
+	jam 0x34,mem_xrecord_mode
+	setarg 0x0f0f0f
+	store 3,mem_le_lap
+	store 3,mem_le_lap+3
+	branch mouse_start_reconnect
+
+mouse_bt_fast_conn_init:
+	jam 0x33,mem_xrecord_mode
+	arg mem_mouse_compare_addr_ff,contr
+	call mouse_load_bt_device
+	branch mouse_start_reconnect
+
+mouse_buletooth_fast_conn_end:
+	bpatch patch1a_5,mem_patch1a
+	call mouse_select_reconn_device
+	call mouse_bluetooth_fast_conn_disable
+	fetch 1,mem_device_flag
+	beq MODE_BT_DEVICE1,mouse_device1_check_auto_discover
+	beq MODE_BT_DEVICE2,mouse_device2_check_auto_discover
+	rtn
+mouse_device1_check_auto_discover:
+	fetch 6,mem_device1_addr
+	branch mouse_device_check_auto_discover
+mouse_device2_check_auto_discover:
+	fetch 6,mem_device2_addr
+mouse_device_check_auto_discover:	
+	fetcht 6,mem_mouse_compare_addr_ff
+	isub temp,null
+	branch mouse_start_discovery ,zero
+	branch mouse_start_reconnect_device
+
+mouse_bt_fast_conn_send_device_name:
+	call mouse_bluetooth_fast_conn_disable
+	fetch 1,mem_local_name_length
+	increase 3,pdata
+	copy pdata,rega
+	call hid_malloc_tx_buff
+	fetch 2,mem_hid_int_remote_cid
+	istore 2,contw
+	setarg 0x04a1		// report id = 4
+	istore 2,contw
+	fetch 1,mem_local_name_length
+	increase 1,pdata
+	copy pdata,loopcnt
+	arg mem_local_name_length,contr
+	branch memcpy
+
+mouse_bluetooth_fast_conn_disable:
+	jam 0x5a,mem_mouse_bluetooth_fast_conn_flag
+	rtn	
+/*******************mouse fast connect******************/
+
+mouse_stop_bluetooth_mode:
+	fetch 2,mem_ui_state_map
+	bbit1 UI_STATE_BT_RECONNECT,mouse_cancel_reconnect
+	bbit1 UI_STATE_BLE_CONNECTED,app_ble_disconnect
+	bbit1 UI_STATE_BT_CONNECTED,app_bt_disconnect
+	branch mouse_stop_discovery
+
+mouse_disconnect:
+	setarg 0
+	store 2,mem_mouse_no_data_timer
+	fetch 2,mem_ui_state_map
+	bbit1 UI_STATE_BLE_CONNECTED,app_ble_disconnect
+	fetch 2,mem_ui_state_map
+	bbit1 UI_STATE_BT_CONNECTED,app_bt_disconnect
+	rtn
+	
+mouse_cancel_reconnect:
+	call mouse_bt_cannel_reconn_enable
+	branch check_51cmd_bb_reconn_cancel
+
+mouse_check_125Hz:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	rtnbit0 MOUSE_ENABLE_BT_125Hz
+mouse_bluetooth_125Hz:
+	nbranch mouse_bluetooth_125hz_clear,user
+	fetch 1,mem_bluetooth_125hz_cnt
+	increase 1,pdata
+	and_into 0x0f,pdata
+	store 1,mem_bluetooth_125hz_cnt
+	nrtn blank
+mouse_bluetooth_125hz_clear:
+	jam 0,mem_bluetooth_125hz_cnt
+	disable user
+	rtn
+
+
+mouse_current_mult_update:
+	fetch 1,mem_sensor_motion_gpio
+	rtnne GPIO_DISABLE
+	jam 0,mem_lpm_mult
+	jam 30,mem_mouse_current_mult_timer
+	rtn
+
+
+mouse_priority_bb_event:	
+	bpatch patch1a_6,mem_patch1a
+	copy regc,pdata
+	beq BT_EVT_LE_CONNECTED,mouse_le_bb_event_connected
+	beq BT_EVT_BB_CONNECTED,mouse_bb_event_connected
+	beq BT_EVT_LE_DISCONNECTED,mouse_le_bb_disconnected
+	beq BT_EVT_BB_DISCONNECTED,mouse_bb_disconnected
+	beq BT_EVT_SETUP_COMPLETE,mouse_bt_event_setup_complete
+	beq BT_EVT_BUTTON_LONG_PRESSED,mouse_bb_event_discovery_btn
+	beq BT_EVT_HID_HANDSHAKE,mouse_bt_hid_handshake
+	beq BT_EVT_HID_CONNECTED,app_hid_connected
+	beq BT_EVT_RECONN_FAILED,mouse_bb_event_reconn_failed
+	beq BT_EVT_RECONN_PAGE_TIMEOUT,mouse_bb_event_reconn_timeout
+	beq BT_EVT_SWITCH_NOT_ACCEPT,app_bt_role_switch	
+	beq BT_EVT_SWITCH_SUCCESS_MASTER,mouse_enter_sniff_check
+	beq BT_EVT_SNIFF_NOT_ACCEPT,mouse_sniff_not_accept
+	beq BT_EVT_PINCODE_REQ,mouse_bb_event_pincode
+	beq BT_EVT_REMOTE_UNSNIFF,app_start_auto_sniff
+	beq BT_EVT_LE_PAIRING_SUCCESS,mouse_le_pairing_success
+	beq BT_EVT_LE_ENC_INFO,mouse_le_enc_info
+	beq BT_EVT_LE_START_ENC,mouse_le_ll_start_encryt
+	beq BT_EVT_LE_PAIRING_COMPLETE,mouse_le_pairing_complete
+	beq BT_EVT_LE_PARSE_CONN_PAPA_UPDATE_RSP,mouse_le_conn_param_update_rsp_recieved
+	beq BT_EVT_VIRTUAL_CABLE_UNPLUG,mouse_irtual_cable_unplug
+	beq BT_EVT_24G_PAIRING_COMPLETE,mouse_24g_pairing_complete
+	beq BT_EVT_24G_ATTEMPT_FAIL,mouse_24g_attempt_fail
+	beq BT_EVT_24G_ATTEMPT_SUCCESS,mouse_24g_attempt_success
+	beq BT_EVT_LE_PARSE_CONN_PARAM_ACCEPTED,mouse_le_parse_conn_param_accepted
+	rtn
+
+/***************************le*************************/
+mouse_le_bb_event_connected:
+	jam 0,mem_mouse_long_mult_flag
+	call mouse_init_sensor_reset
+	jam 1,mem_mouse_le_bb_connected_flag
+	call mouse_24g_first_store_reconn_info
+	fetch 1,mem_mouse_le_reconnect_flag
+	nbranch mouse_le_bb_event_connected_next,blank
+	jam 0x14,mem_mouse_send_secutiry_request_timer
+mouse_le_bb_event_connected_next:
+	fetch APP_DISC_RSN_SIZE,mem_app_disconn_reason_flag
+	set0 APP_DISC_BY_BUTTON ,pdata
+	store APP_DISC_RSN_SIZE,mem_app_disconn_reason_flag
+	jam 0,mem_mouse_direct_timer
+	fetch 2,mem_le_battery_level_updata_timer_init
+	store 2,mem_le_battery_level_updata_timer
+	call mouse_no_data_timer_init
+	branch mouse_stop_discovery
+
+mouse_le_bb_disconnected:
+	jam 0,mem_mouse_le_bb_connected_flag
+	setarg LE_INTERVAL_7_5MS
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit1 MOUSE_ENABLE_BT_125Hz,mouse_le_bb_disconnected_next
+	setarg LE_INTERVAL_8_75MS
+mouse_le_bb_disconnected_next:
+	store 2,mem_le_interval_min
+	store 2,mem_le_interval_min+2
+	jam LE_LPM_ENABLE,mem_mouse_le_conn_param_reject
+	jam 0,mem_mouse_clear_sensor_data_flag
+	call le_clr_config_more_data
+	branch mouse_bb_disconnected
+
+mouse_le_pairing_success:
+	arg LL_PAIRING_SUCCESS_FLAG,queue
+	branch mouse_le_enable_connect_flag
+
+mouse_le_enc_info:
+mouse_updata_le_param:
+	jam BT_CMD_LE_UPDATE_CONN,mem_fifo_temp
+	branch ui_ipc_send_cmd
+	
+mouse_le_ll_start_encryt:
+	fetch 1,mem_mouse_le_reconnect_flag
+	beq 1,mouse_le_ll_reconn_start_encryt
+	branch mouse_le_ll_enable_start_enc_flag
+mouse_le_ll_reconn_start_encryt:
+	call mouse_updata_le_param
+	jam 20,mem_le_start_encrypt_timer
+mouse_le_ll_enable_start_enc_flag:
+	arg LL_START_ENC_FLAG,queue
+	branch mouse_le_enable_connect_flag
+
+mouse_le_enable_connect_flag:
+	fetch 1,mem_le_connect_status_flag
+	qset1 pdata
+	store 1,mem_le_connect_status_flag
+	rtn
+
+mouse_le_pairing_complete:
+	branch app_ble_store_reconn_info
+
+mouse_le_conn_param_update_rsp_recieved:
+	fetch 2,mem_le_l2cap_signaling_conn_param_update_rsp_result
+	rtneq BLE_SIGNALING_CONNECT_PARAMETER_UPDATE_ACCEPTED
+	fetch 1,mem_le_tsniff
+	rshift2 pdata,pdata
+	sub pdata,LE_INTERVAL_15MS,null
+	rtn positive
+	setarg LE_INTERVAL_11_25MS
+	store 2,mem_le_interval_min
+	store 2,mem_le_interval_min+2
+	call mouse_updata_le_param
+mouse_le_conn_param_lpm_disable:
+	jam LE_LPM_DISABLE,mem_mouse_le_conn_param_reject
+	rtn
+
+mouse_le_conn_param_lpm_enable:
+	jam LE_LPM_ENABLE,mem_mouse_le_conn_param_reject
+	rtn
+
+mouse_le_bb_event_connect_complete:
+	fetch 1,mem_mouse_le_reconnect_flag
+	nrtn blank
+	fetch 1,mem_le_att_handle
+	sub pdata,34,pdata
+	nrtn zero
+	jam 0,mem_le_start_encrypt_timer
+mouse_le_write_enable:	
+	arg WRITE_REQ_ENABLE_FLAG,queue
+	branch mouse_le_enable_connect_flag
+
+mouse_le_parse_conn_param_accepted:
+	fetch 1,mem_le_new_conninterval
+	sub pdata,LE_INTERVAL_15MS,null
+	nbranch mouse_le_conn_param_lpm_disable,positive
+	fetch 1,mem_le_new_connslavelatency
+	fetcht 1,mem_lpm_mult_init
+	isub temp,null
+	branch mouse_le_lpm_mult_reinit,positive
+	fetch 1,mem_le_new_connslavelatency
+	store 1,mem_lpm_mult
+	branch mouse_le_conn_param_lpm_enable
+mouse_le_lpm_mult_reinit:
+	fetch 1,mem_lpm_mult_init
+	store 1,mem_lpm_mult
+	branch mouse_le_conn_param_lpm_enable
+	
+/*
+mouse_le_disable_connect_flag:
+	fetch 1,mem_le_connect_status_flag
+	qset0 pdata
+	store 1,mem_le_connect_status_flag
+	rtn
+*/
+mouse_le_clean_connect_flag:
+	jam 0,mem_le_connect_status_flag
+	rtn
+
+/*
+mouse_le_reconn_write_enable_timer_reinit:
+	fetch 1,mem_mouse_le_reconnect_flag
+	rtn blank
+	fetch 1,mem_le_connect_status_flag
+	and pdata,0x03,pdata
+	rtneq 0x03
+	jam 2,mem_le_start_encrypt_timer
+	rtn
+*/
+mouse_le:
+	bpatch patch1a_7,mem_patch1a
+	call le_fifo_check_nearly_full
+	nrtn blank
+	fetch 1,mem_mouse_bluetooth_fast_conn_flag
+	beq 0xff,mouse_le_next
+	fetch 1,mem_le_connect_status_flag
+	and pdata,0x03,pdata
+	rtnne 0x03
+mouse_le_next:	
+	fetch 1,mem_mouse_clear_sensor_data_flag
+	call mouse_clear_sensor_data_by_reset,blank
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit1 MOUSE_24G_PAIRING_FLAG,mouse_le_send_empty_packet
+	bbit1 MOUSE_SELECT_DEVICE_FLAG,mouse_le_send_empty_packet
+	bbit1 MOUSE_BT_DISCOVERY_BUTTON_DOWN_FLAG,mouse_le_send_empty_packet
+	bbit1 MOUSE_BT_DISCOVERY_BUTTON_LONG_DOWN_FLAG,mouse_le_send_empty_packet
+	call mouse_motion
+	call mouse_check_125Hz
+	nrtn user
+	call mouse_current_mult_update
+	call mouse_data_xy_release
+	call mouse_wheel_trigger
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit0 MOUSE_ENABLE_KEYBOARD,mouse_le_send_mouse_data
+	fetch 1,mem_customer_key
+	beq 1,mouse_le_send_keyboard_package_data		
+mouse_le_send_mouse_data:
+	branch mouse_fill_mouse_data_le
+
+
+mouse_le_send_keyboard_package_data:
+	fetch 1,mem_customer_data_trigger
+	branch mouse_le_release_keyboard_data,blank
+	fetch 8,mem_customer_key_press+1
+mouse_fill_keyboard_package_data_le:
+	store 8,mem_pdatatemp
+	fetch 1,mem_customer_key_press
+	beq KB_MULTIKEY_REPORT_ID,mouse_fill_multimedia_key_data_le
+	beq KB_SYSTEM_CONCTRL_REPORT_ID,mouse_fill_systemctrl_key_data_le
+	jam 8,mem_le_data_len
+	fetcht 2,mem_le_keyboard_handle
+	branch mouse_fill_data_le
+	
+
+mouse_le_release_keyboard_data:
+	fetch 8,mem_customer_key_release+1
+	branch mouse_fill_keyboard_package_data_le
+
+mouse_fill_multimedia_key_data_le:
+	jam 3,mem_le_data_len
+	fetcht 2,mem_le_multimedia_handle
+	branch mouse_fill_data_le
+
+mouse_fill_systemctrl_key_data_le:
+	jam 2,mem_le_data_len
+	fetcht 2,mem_le_systemctrl_handle
+	branch mouse_fill_data_le
+
+mouse_fill_battery_level_le:
+	arg 1,rega
+	fetcht 2,mem_le_battery_level_handle
+	call le_att_malloc_tx_notify
+	fetch 1,mem_le_battery_level_percentage
+	istore 1,contw
+	rtn
+
+
+mouse_le_send_empty_packet:
+	setarg 0
+	store 7,mem_mouse_key
+mouse_fill_mouse_data_le:
+	jam 7,mem_le_data_len
+	fetch 7,mem_mouse_key
+	store 7,mem_pdatatemp
+	fetcht 2,mem_le_notify_handle
+	branch mouse_fill_data_le
+
+mouse_fill_data_le:
+	fetch 1,mem_le_data_len
+	copy pdata,rega
+	call le_att_malloc_tx_notify
+	fetcht 1,mem_le_data_len
+	copy temp,loopcnt
+	arg mem_pdatatemp,contr
+	branch memcpy	
+
+mouse_check_51cmd_adv:
+	jam 0,mem_mouse_le_reconnect_flag
+	fetch 3,mem_le_adv_ind
+	store 3,mem_le_adv_data+4
+	call mouse_le_check_adv_flag
+	setarg ADV_FLAG_BREDR_NOT_SUPPORTED |ADV_FLAG_LIMITED_DISCOVERABLE
+	istore 1,contr
+	arg mem_le_adv_swift_pair,contr
+	call mouse_le_adv_data_update
+	branch check_51cmd_adv
+
+mouse_le_check_adv_flag:
+	arg mem_le_adv_data,rega
+mouse_le_check_adv_flag_loop:
+	ifetch 1,rega	//length
+	rtn blank
+	iadd contr,rega
+	ifetch 1,contr	//type
+	rtneq 0x01
+	branch mouse_le_check_adv_flag_loop
+	
+mouse_le_adv_data_update:
+	arg mem_le_adv_data+11,contw
+	arg 19,loopcnt
+	call memcpy
+	branch le_modified_name_adv
+	
+/***************************le*************************/
+
+
+/***********************bt****************************/	
+mouse_bt_sniff_param_interval_setup:
+	setarg CLASSIC_INTERVAL_7_5MS
+	store 2,mem_sniff_param_interval
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	rtnbit1 MOUSE_ENABLE_BT_125Hz
+	setarg CLASSIC_INTERVAL_8_75MS
+	store 2,mem_sniff_param_interval
+	rtn
+
+mouse_bb_event_connected:
+	jam 0,mem_mouse_long_mult_flag
+	call mouse_init_sensor_reset
+	call mouse_24g_first_store_reconn_info
+	branch mouse_stop_discovery
+
+mouse_bb_disconnected:
+	jam 0,mem_mouse_enter_sniff_count
+	jam 0,mem_mouse_bt_send_first_package_flag
+	call mouse_bt_sniff_param_interval_setup
+	call mouse_bb_discon_clear_stack
+	fetch APP_DISC_RSN_SIZE,mem_app_disconn_reason
+	bbit1 APP_DISC_BLE,mouse4_0_event_bb_disconn
+	bbit1 APP_DISC_BY_BUTTON,app_disconn_reason_clear
+	bbit1 APP_DISC_AFTER_PAIRING,mouse_event_light_state_pairing
+	bbit1 APP_DISC_AFTER_RECONN,mouse_event_light_state_hibernate
+	bbit1 APP_DISC_AFTER_SNIFF,mouse_event_light_state_hibernate
+	branch mouse_start_discovery
+mouse_bb_discon_clear_stack:
+	setarg 0
+	store 8,mem_wheel_tb_old_pinlevel
+	istore 4,contw             //clean wheel statue
+	jam 0,mem_mouse_move_flag
+	jam APP_HANDSHAKE_NULL,mem_app_handshake_flag
+	jam 0,mem_ltk_exists
+	rtn
+
+mouse4_0_event_bb_disconn:
+	call mouse_le_clean_connect_flag
+	fetch APP_DISC_RSN_SIZE,mem_app_disconn_reason
+	bbit1 APP_DISC_BY_BUTTON,app_disconn_reason_clear
+	branch mouse_app_enter_hibernate
+
+
+mouse_event_light_state_pairing:
+	bbit1 APP_DISC_AFTER_HANDSHAKE,mouse_event_light_state_hibernate
+	bbit1 APP_DISC_AFTER_SNIFF,mouse_event_light_state_hibernate
+	branch mouse_start_discovery
+mouse_event_light_state_hibernate:
+	fetch 2,mem_ui_state_map
+	bbit1 UI_STATE_BTN_DOWN,mouse_start_discovery
+	call app_disconn_reason_clear
+
+	call mouse_key_check_once	//mult_key pair
+	call mouse_commbination_key_process
+	fetch 1,mem_commbination_key_statue
+	beq COMMBINATION_KEY_STATE_DOWN,mouse_delay_enter_hibernata
+	
+	fetch 1,mem_mouse_bluetooth_reconnect_timeout
+	nrtn blank
+	branch mouse_app_enter_hibernate
+
+
+mouse_bt_event_setup_complete:
+	rtn
+
+mouse_bt_send_first_package_timer_init:
+	jam 4,mem_mouse_bt_send_first_package_timer
+	rtn
+
+mouse_bt_hid_handshake:
+	jam APP_HANDSHAKE_DONE,mem_app_handshake_flag
+	call app_lpm_mult_enable
+	call app_bt_store_reconn_info
+	setarg 0
+	store 2,mem_discovery_timeout_timer_count
+	store 1,mem_hid_handshake_timer_count
+	call mouse_bt_send_first_package_timer_init
+	branch app_bt_enter_sniff
+
+mouse_bt_hid_handshake_boot_check:	
+	jam 0,mem_mouse_bt_boot_mode
+	fetch 1,mem_l2cap_rcv_hidtype
+	isolate1 0,pdata
+	rtn true
+	jam 1,mem_mouse_bt_boot_mode	//boot mode
+	rtn
+
+	
+mouse_bb_event_reconn_timeout:
+mouse_bb_event_reconn_failed:
+	fetch 1,mem_mouse_bluetooth_fast_conn_flag
+	beq 0xff,mouse_buletooth_fast_conn_end
+	fetch 2,mem_ui_state_map
+	rtnbit1 UI_STATE_BTN_DOWN
+	rtnbit1 UI_STATE_BT_DISCOVERY
+	rtnbit1 UI_STATE_BLE_ADV
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	rtnbit1 MOUSE_BT_DISCOVERY_BUTTON_DOWN_FLAG
+	bbit1 MOUSE_ENABLE_BT_RECONNECT_TIMEOUT_ENTER_DISCOVERY,mouse_start_discovery
+	bbit1 MOUSE_ENABLE_24G_FIRST_AUTO_PAIRING,mouse_24g_first_bb_event_reconn_timeout
+	branch mouse_app_enter_hibernate
+
+mouse_enter_sniff_check:
+	fetch 1,mem_mouse_enter_sniff_count
+	rtnne 2
+	jam 0,mem_mouse_enter_sniff_count
+	call mouse_bt_sniff_param_interval_setup
+	call mouse_bt_send_first_package_timer_init
+	branch app_bt_enter_sniff
+
+mouse_sniff_not_accept:
+	fetch 1,mem_mouse_enter_sniff_count
+	rtneq 2
+	increase 1,pdata
+	store 1,mem_mouse_enter_sniff_count
+	jam 0x12,mem_sniff_param_interval	//89Hz
+	call mouse_bt_send_first_package_timer_init
+	branch app_bt_enter_sniff
+
+mouse_bb_event_pincode:
+	call pincode_reinit
+	branch app_bt_set_pincode
+
+mouse_irtual_cable_unplug:
+	setarg 0x01
+	store 6,mem_plap
+	jam REC_3_MODE,mem_record_bt_mode
+	branch mouse_unplug_clean_bdaddr
+
+mouse_irtual_cable_unplug1:
+	setarg -1
+	store 6,mem_plap
+	jam REC_3_MODE,mem_record_bt_mode
+	jam 0xff,mem_mouse_bluetooth_fast_conn_flag
+	call mouse_before_store_reconn_info
+	jam 0xff,mem_device1_type
+	branch mouse_store_device_info_delay
+
+mouse_bt:
+	bpatch patch1b_0,mem_patch1b
+	rtn attempt
+	fetch 1,mem_app_handshake_flag
+	rtn blank
+	call l2cap_malloc_is_fifo_nearly_full
+	nrtn blank
+	fetch 1,mem_mouse_bluetooth_fast_conn_flag
+	beq 0xff,mouse_bt_fast_conn_send_device_name	
+	fetch 1,mem_mouse_clear_sensor_data_flag
+	call mouse_clear_sensor_data_by_reset,blank
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit1 MOUSE_24G_PAIRING_FLAG,mouse_send_empty_data
+	bbit1 MOUSE_SELECT_DEVICE_FLAG,mouse_send_empty_data
+	bbit1 MOUSE_BT_DISCOVERY_BUTTON_DOWN_FLAG,mouse_send_empty_data
+	bbit1 MOUSE_BT_DISCOVERY_BUTTON_LONG_DOWN_FLAG,mouse_send_empty_data
+	call mouse_motion
+	call mouse_check_125Hz
+	nrtn user
+	call mouse_current_mult_update
+	call mouse_data_xy_release
+	call mouse_wheel_trigger
+	fetch 1,mem_mouse_bt_boot_mode
+	beq 1,mouse_send_data_boot_mode	//boot
+	fetch 1,mem_mouse_bt_send_first_package_flag
+	rtn blank
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit0 MOUSE_ENABLE_KEYBOARD,mouse_send_data
+	fetch 1,mem_customer_key
+	beq 1,mouse_bt_send_keyboard_packet
+mouse_send_data:
+	arg 9,rega
+	call hid_malloc_tx_buff
+	fetch 2,mem_hid_int_remote_cid
+	istore 2,contw
+	setarg 0x02a1
+	istore 2,contw
+	fetch 7,mem_mouse_key
+	istore 7,contw
+	rtn
+
+mouse_send_data_boot_mode:
+	fetch 1,mem_mouse_key
+	store 1,mem_mouse_bt_boot_data
+	fetch 1,mem_mouse_x
+	istore 1,contw
+	fetch 1,mem_mouse_y
+	istore 1,contw
+	fetch 2,mem_mouse_z
+	istore 2,contw
+	arg 7,rega
+	call hid_malloc_tx_buff
+	fetch 2,mem_hid_int_remote_cid
+	istore 2,contw
+	setarg 0x02a1		// pid:02  mouse
+	istore 2,contw
+	fetch 5,mem_mouse_bt_boot_data
+	istore 5,contw
+	rtn
+
+mouse_send_empty_data:
+	setarg 0
+	store 7,mem_mouse_key
+	branch mouse_send_data
+
+
+mouse_bt_send_keyboard_packet:
+	fetch 1,mem_customer_data_trigger
+	branch mouse_bt_release_keyboard_data,blank
+	fetch 8,mem_customer_key_press+1
+mouse_bt_send_keyboard_data:
+	store 8,mem_pdatatemp
+	fetch 1,mem_customer_key_press
+	beq KB_MULTIKEY_REPORT_ID,mouse_bt_send_multimedia_key_data
+	beq KB_SYSTEM_CONCTRL_REPORT_ID,mouse_bt_send_systemctrl_key_data
+	arg 10,rega
+	call hid_malloc_tx_buff
+	fetch 2,mem_hid_int_remote_cid
+	istore 2,contw
+	setarg 0x01a1		// pid:01  standard key
+	istore 2,contw
+	fetch 8,mem_pdatatemp
+	istore 8,contw
+	rtn
+
+mouse_bt_send_multimedia_key_data:
+	arg 4,rega
+	call hid_malloc_tx_buff
+	fetch 2,mem_hid_int_remote_cid
+	istore 2,contw
+	setarg 0x03a1		// pid:03  multimedia key
+	istore 2,contw
+	fetch 2,mem_pdatatemp
+	istore 2,contw
+	rtn	
+
+mouse_bt_send_systemctrl_key_data:
+	arg 3,rega
+	call hid_malloc_tx_buff
+	fetch 2,mem_hid_int_remote_cid
+	istore 2,contw
+	setarg 0x04a1		// pid:04  systemctrl key	
+	istore 2,contw
+	fetch 1,mem_pdatatemp
+	istore 1,contw
+	rtn		
+
+mouse_bt_release_keyboard_data:
+	fetch 8,mem_customer_key_release+1
+	branch mouse_bt_send_keyboard_data	
+/*******************bt****************************/
+
+
+
+/********************mouse 100ms timer*****************/
+mouse_bb_event_timer:
+	bpatch patch1b_1,mem_patch1b
+	call mouse_adc_read
+	call mouse_low_voltage_led_timer
+	//24g
+	call g24_pair_timeout_timer
+	call g24_reconn_timeout_timer
+	call mouse_24g_long_sleep_param_update_timer
+	//led
+	call mouse_device_poweron_timer
+	call mouse_dpi_led_blink_delay_timer
+	//poll
+	call mouse_dpi_key_check_long_press
+	call mouse_bt_discovery_check
+	call mouse_commbination_key_process
+	call mouse_check_discovery_timeout_timer
+	//ble
+	call mouse_check_direct_timeout_timer
+	call mouse_le_enable_att_list_timer
+	call mouse_le_battery_updata_timer
+	call mouse_le_send_smp_security_request_timer
+	//bt
+	call mouse_check_hid_handshake_timer
+	call mouse_bt_check_sniff_req_timeout_timer
+	call mouse_check_reconnect_delay_long_sleep		//delete 3.0,reconnect fail
+	call mouse_current_mult_update_timer
+	call mouse_wheel_trigger_timer
+	call mouse_store_information_delay_timer
+	branch mouse_check_no_data_timeout_timer
+
+
+
+
+mouse_bt_discovery_check:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit1 MOUSE_ENABLE_PB_BUTTON_LONG_PRESS_DISCONVERY,mouse_bt_discovery_by_pb_button
+	rtn
+
+mouse_bt_discovery_by_pb_button:
+	fetch 1,mem_select_device_button_statue
+	rtnne PB_BUTTON_STATE_DOWN
+	arg mem_bt_discovery_count,regc
+	arg mouse_long_button_bt_discovery,regb
+	branch timer_single_step
+		
+mouse_long_button_bt_discovery:
+	fetch 1,mem_device_flag
+	rtneq MODE_24G_DEVICE
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	rtnbit1 MOUSE_BT_DISCOVERY_BUTTON_LONG_DOWN_FLAG
+	arg MOUSE_BT_DISCOVERY_BUTTON_LONG_DOWN_FLAG,queue
+	call mouse_enable_function_flag
+	call app_evt_button_long_pressed
+	branch mouse_bb_event_discovery_btn
+
+		
+mouse_commbination_key_process:
+	fetch 1,mem_device_flag
+	beq MODE_24G_DEVICE,mouse_24g_commbination_key_process
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	rtnbit0 MOUSE_ENABLE_COMMBINATION_KEY_BY_BT_DISCOVERY
+	fetcht 1,mem_mouse_commbination_key_bt
+	branch mouse_commbination_key_start
+
+mouse_24g_commbination_key_process:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	rtnbit0 MOUSE_ENABLE_COMMBINATION_KEY_BY_24G_PAIRING
+	fetcht 1,mem_mouse_commbination_key_24g
+mouse_commbination_key_start:
+	storet 1,mem_mouse_commbination_key
+	call mouse_check_key_gpio
+	and pdata,0x07,pdata
+	fetcht 1,mem_mouse_commbination_key
+	isub temp,null
+	branch mouse_commbination_key_down,zero
+mouse_commbination_key_up:
+	fetch 1,mem_ui_button_timeout
+	store 1,mem_combination_ui_button_count	//combination key timer init 
+	fetch 1,mem_commbination_key_statue
+	rtneq COMMBINATION_KEY_STATE_UP
+	jam COMMBINATION_KEY_STATE_UP,mem_commbination_key_statue	
+	rtn
+		
+mouse_commbination_key_down:
+	call mouse_combination_ui_timer
+	fetch 1,mem_commbination_key_statue
+	rtneq COMMBINATION_KEY_STATE_DOWN
+	jam COMMBINATION_KEY_STATE_DOWN,mem_commbination_key_statue
+	branch check_51cmd_bb_reconn_cancel
+
+
+mouse_combination_ui_timer:
+	arg mouse_24g_start_pair_mode,regb
+	arg mem_combination_ui_button_count,regc
+	fetch 1,mem_device_flag
+	beq MODE_24G_DEVICE,timer_single_step
+	arg mouse_long_button_bt_discovery,regb
+	call timer_single_step
+	fetch 1,mem_combination_ui_button_count
+	beq 1,mouse_bt_discovery_button_down_enable	// ble release key press
+	rtn
+
+
+
+mouse_check_discovery_timeout_timer:	
+	arg mem_mouse_discovery_timer,regc
+	arg mouse_check_discovery_timeout,regb
+	branch timer_single_step_2B
+
+mouse_check_discovery_timeout:
+	call mouse_stop_discovery
+	branch mouse_app_enter_hibernate
+
+
+mouse_check_direct_timeout_timer:	
+	arg mem_mouse_direct_timer,regc
+	arg mouse_check_direct_timeout,regb
+	call timer_single_step_2B
+	fetch 1,mem_mouse_direct_timer
+	beq 1,app_ble_stop_direct_adv
+	rtn
+
+mouse_check_direct_timeout:
+	fetch 1,mem_mouse_bluetooth_fast_conn_flag
+	beq 0xff,mouse_buletooth_fast_conn_end
+	fetch 1,mem_reconn_times
+	nbranch mouse_polling_device,blank
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit1 MOUSE_ENABLE_BT_RECONNECT_TIMEOUT_ENTER_DISCOVERY,mouse_start_discovery
+	bbit1 MOUSE_ENABLE_24G_FIRST_AUTO_PAIRING,mouse_24g_first_bb_event_reconn_timeout
+	branch mouse_app_enter_hibernate
+	
+mouse_le_enable_att_list_timer:
+	arg mem_le_start_encrypt_timer,regc
+	arg mouse_le_write_enable,regb
+	branch timer_single_step
+
+mouse_le_send_smp_security_request_timer:
+	fetch 1,mem_mouse_le_bb_connected_flag
+	rtn blank
+	arg mem_mouse_send_secutiry_request_timer,regc
+	arg mouse_le_pairing_sm_start_check,regb
+	branch timer_single_step
+mouse_le_pairing_sm_start_check:
+	fetch 1,mem_mouse_le_reconnect_flag
+	nrtn blank
+	fetch 1,mem_le_pairing_state
+	rtnne FLAG_LE_PAIRING_NULL
+	branch le_pairing_sm_start
+
+mouse_le_battery_updata_timer:
+	arg mem_le_battery_level_updata_timer,regc
+	arg mouse_le_battery_level_updata,regb
+	branch timer_single_step
+
+mouse_le_battery_level_updata:
+	fetch 2,mem_le_battery_level_updata_timer_init
+	store 2,mem_le_battery_level_updata_timer
+	branch mouse_fill_battery_level_le
+	
+mouse_le_enable_att_list:	
+	fetch 1,mem_le_connect_status_flag
+	rtnbit1 LL_PAIRING_SUCCESS_FLAG
+	call mouse_updata_le_param
+	arg WRITE_REQ_ENABLE_FLAG,queue
+	branch mouse_le_enable_connect_flag
+
+mouse_check_hid_handshake_timer:
+	arg mem_hid_handshake_timer_count,regc
+	arg mouse_bt_hid_handshake,regb
+	branch timer_single_step
+	
+mouse_bt_check_sniff_req_timeout_timer:
+	arg mem_mouse_bt_send_first_package_timer,regc
+	arg mouse_bt_send_first_package,regb
+	branch timer_single_step
+mouse_bt_send_first_package:
+	jam 1,mem_mouse_bt_send_first_package_flag
+	rtn
+
+mouse_check_reconnect_delay_long_sleep:
+	arg mem_mouse_bluetooth_reconnect_timeout,regc
+	arg mouse_app_enter_hibernate,regb
+	branch timer_single_step
+
+
+mouse_current_mult_update_timer:
+	arg mem_mouse_current_mult_timer,regc
+	arg mouse_current_mult_reinit,regb
+	branch timer_single_step
+mouse_current_mult_reinit:
+	fetch 1,mem_lpm_mult_init
+	store 1,mem_lpm_mult
+	jam 1,mem_mouse_long_mult_flag
+	rtn
+
+
+mouse_check_no_data_timeout_timer:	
+	fetch 1,mem_usb_addr
+	rtnbit1 7
+	arg mem_mouse_no_data_timer,regc
+	arg mouse_check_no_data_timeout,regb
+	branch timer_single_step_2B
+
+mouse_check_no_data_timeout:
+	fetch 1,mem_device_flag
+	beq MODE_24G_DEVICE,mouse_24g_hibernate_set
+	branch mouse_disconnect
+	
+mouse_no_data_timer_init:
+	fetch 2,mem_mouse_no_data_timeout
+	store 2,mem_mouse_no_data_timer
+	rtn
+
+mouse_store_information_delay_timer:
+	arg mem_store_information_delay_timer,regc
+	arg mouse_store_device_info_check,regb
+	branch timer_single_step
+
+mouse_store_device_info_check:
+	call mouse_store_device_info
+	fetch 1,mem_mouse_need_soft_reset
+	nbranch mouse_soft_reset,blank
+	rtn
+
+mouse_bb_event_discovery_btn:
+	isolate1 mark_24g,mark
+	call mouse_24g_stop,true
+	call mouse_disconnect
+	call mouse_le_clean_connect_flag
+	branch mouse_start_discovery
+	
+mouse_start_discovery:
+	bpatch patch1b_2,mem_patch1b
+	call mouse_bluetooth_fast_conn_disable
+	fetch 2,mem_ui_state_map
+	bbit1 UI_STATE_BLE_ADV,mouse_start_discovery_norandom
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit0 MOUSE_ENABLE_BLE_RANDOM_ADDRE,mouse_start_discovery_norandom
+	fetcht 2,mem_random_addr_increase_count
+	increase 1,temp
+	storet 2,mem_random_addr_increase_count
+	storet 2,mem_le_lap+1
+	random pdata					//random ble addr
+	store 1,mem_le_lap
+mouse_start_discovery_norandom:
+	fetch 3,mem_mouse_le_lap_temp
+	store 3,mem_le_lap+3
+	call app_lpm_mult_disable
+	fetch 2,mem_discovery_timeout
+	store 2,mem_mouse_discovery_timer
+	jam 6,mem_connection_options
+	setarg 0
+	store 2,mem_mouse_no_data_timer
+	store 1,mem_mouse_direct_timer
+	store 1,mem_mouse_bluetooth_reconnect_timeout
+	store 1,mem_mouse_device_poweron_timer_count
+	store 1,mem_mouse_clear_sensor_data_flag
+	arg MOUSE_STORE_EEPROM_FLAG,queue
+	call mouse_enable_function_flag
+	call mouse_bt_discovery_button_down_disable
+	fetch 1,mem_mouse_bluetooth_type
+	isolate1 MODE_4_MOUSE,pdata
+	call mouse_check_51cmd_adv,true
+	fetch 1,mem_mouse_bluetooth_type
+	isolate1 MODE_3_MOUSE,pdata
+	call check_51cmd_start_discovery,true
+	call mouse_low_voltage_led_blink_disable
+	branch mouse_discover_setting_led_gpio
+
+
+mouse_stop_discovery:
+	bpatch patch1b_3,mem_patch1b
+	arg MOUSE_BT_DISCOVERY_BUTTON_LONG_DOWN_FLAG,queue
+	call mouse_disable_function_flag
+	jam 0,mem_mouse_bluetooth_reconnect_timeout
+	fetch 1,mem_mouse_bluetooth_type
+	isolate1 MODE_4_MOUSE,pdata
+	call mouse_stop_le_adv,true
+	fetch 1,mem_mouse_bluetooth_type
+	isolate1 MODE_3_MOUSE,pdata
+	call mouse_stop_bt3_discovery,true
+	branch mouse_device_led_off
+mouse_stop_le_adv:
+	jam 0,mem_mouse_direct_timer
+	branch check_51cmd_stop_adv
+mouse_stop_bt3_discovery:
+	setarg 0
+	store 2,mem_mouse_discovery_timer
+	branch check_51cmd_stop_discovery
+
+mouse_store_remote_bdaddr:
+	bpatch patch1b_4,mem_patch1b
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	rtnbit0 MOUSE_STORE_EEPROM_FLAG
+	call mouse_device_poweron_timer_init
+	arg MOUSE_STORE_EEPROM_FLAG,queue
+	call mouse_disable_function_flag
+	call mouse_check_device_addr
+mouse_unplug_clean_bdaddr:
+	call mouse_before_store_reconn_info
+	branch mouse_store_device_info_delay
+
+	
+mouse_check_device_addr:
+	fetch 1,mem_record_bt_mode
+	beq REC_4_MODE,mouse_check_le_device_addr
+	beq REC_3_MODE,mouse_check_bt_device_addr
+	rtn
+mouse_check_le_device_addr:
+	store 1,mem_device_addr_temp
+	fetch 6,mem_le_plap
+	branch mouse_check_bt_device_addr_common
+mouse_check_bt_device_addr:
+	store 1,mem_device_addr_temp
+	fetch 6,mem_plap
+mouse_check_bt_device_addr_common:
+	store 6,mem_device_addr_temp+1
+	fetch 7,mem_device_addr_temp
+	arg mem_device1_type,contr
+	arg 3,loopcnt
+mouse_check_device_addr_end:
+	ifetcht 7,contr
+	isub temp,null
+	branch mouse_clean_addr,zero
+	increase 22,contr
+	loop mouse_check_device_addr_end
+	rtn
+mouse_before_store_reconn_info:
+	arg mem_device1_type,rega
+	fetch 1,mem_device_flag
+	increase -1,pdata
+	mul32 pdata,29,pdata
+	iadd rega,rega
+	fetch 1,mem_record_bt_mode
+	istore 1,rega
+	beq REC_4_MODE,mouse_store_le_device
+	beq REC_3_MODE,mouse_store_bt_device
+	rtn
+	
+mouse_store_le_device:
+	fetch 6,mem_le_plap
+	istore 6,contw
+	arg mem_le_ltk,contr
+	call memcpy16
+	fetch 6,mem_le_lap
+	istore 6,contw
+	rtn
+mouse_store_bt_device:
+	fetch 6,mem_plap
+	istore 6,contw
+	arg mem_link_key,contr
+	branch memcpy16
+
+mouse_clean_addr:
+	increase -6,contr
+	copy contr,contw
+	fetcht 6,mem_device_addr_temp+1
+	increase 3,temp
+	istoret 6,contw
+	rtn
+	
+mouse_select_reconn_device:
+	arg mem_device1_type,rega
+	fetch 1,mem_device_flag
+	rtneq MODE_24G_DEVICE
+	increase -1,pdata
+	mul32 pdata,29,pdata
+	iadd rega,rega
+	ifetch 1,rega
+	store 1,mem_xrecord_mode
+	beq REC_3_MODE,mouse_load_bt_device
+	beq REC_4_MODE,mouse_load_le_device
+	rtn
+
+mouse_load_bt_device:
+	ifetch 6,contr
+mouse_load_bt_device_end:
+	store 6,mem_hci_plap
+	arg mem_link_key,contw
+	call memcpy16
+	branch check_link_key_load
+
+mouse_load_le_device:
+	ifetch 6,contr
+mouse_load_le_device_end:
+	store 6,mem_hci_plap
+	arg mem_le_ltk,contw
+	call memcpy16
+	ifetch 6,contr
+	store 6,mem_le_lap
+	rtn
+
+
+
+mouse_app_initflag_check:
+	fetch 2,mem_store_flag
+	arg EEPROM_INIT_FLAG,temp
+	isub temp,null
+	branch mouse_load_device_info,zero
+	storet 2,mem_store_flag
+	call mouse_ble_init_address
+	fetch 1,mem_device_flag_temp
+	store 1,mem_device_flag
+	fetch 1,mem_config_sensor_dpi
+	store 1,mem_mouse_dpi
+	fetch 4,mem_24g_fast_conn_addr
+	store 4,mem_24g_receiver_addr
+	store 4,mem_24g_addr	
+	rtn
+
+mouse_load_device_info:
+	call mouse_select_reconn_device
+	fetch 4,mem_mouse_24g_addr
+	store 4,mem_24g_receiver_addr
+	store 4,mem_24g_addr
+	rtn
+	
+mouse_ble_init_address:
+	fetch 6,mem_le_lap
+	store 6,mem_device1_locall_addr
+	add pdata,0x0100,pdata
+	store 6,mem_device2_locall_addr
+	add pdata,0x0100,pdata
+	store 6,mem_device3_locall_addr
+	rtn
+	
+
+mouse_store_device_info_delay:	
+	fetch 1,mem_store_information_delay_timer_init
+	store 1,mem_store_information_delay_timer
+	rtn
+
+mouse_store_device_info:
+	bpatch patch1b_5,mem_patch1b
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit1 MOUSE_ENABLE_EEPROM,mouse_store_eeprom_device_info
+	bbit1 MOUSE_ENABLE_FLASH,mouse_store_flash_device_info
+	rtn
+
+mouse_load_flash_info_check:
+	call spid_init_flash
+	call mouse_spid_flash_release_form_powerdown
+	call mouse_information_flash_parameters
+	call spid_read_flash
+	call mouse_spid_flash_powerdown
+	call mouse_app_initflag_check
+	branch mouse_sensor_spi_init
+
+
+mouse_information_flash_parameters:
+	setarg mem_mouse_information_end
+	arg mem_mouse_information_start,temp
+	isub temp,temp
+	fetch 3,mem_flash_base
+	arg mem_mouse_information_start,rega
+	rtn
+	
+mouse_store_flash_device_info:
+	call spid_init_flash
+	call mouse_spid_flash_release_form_powerdown
+	call mouse_flash_erase_sector
+
+	call mouse_information_flash_parameters
+	call mouse_spid_write_flash
+	call mouse_spid_flash_powerdown
+	branch mouse_sensor_spi_init
+
+mouse_spid_flash_release_form_powerdown:
+	jam FLASH_COMMAND_RELEASE_FROM_POWERDOWN,mem_temp
+mouse_spid_write_flash_cmd:
+	call delay_nop100
+	call spid_unlock_flash
+	arg mem_write_flash_head_temp,rega
+	fetcht 1,mem_temp
+	call mouse_spid_write_flash_cmd_common
+	branch delay_nop100
+
+mouse_spid_flash_powerdown:
+	jam FLASH_COMMAND_POWERDOWN,mem_temp
+	branch mouse_spid_write_flash_cmd
+
+mouse_spid_write_flash_cmd_common:
+	istoret 1,rega
+	rshift16 pdata,temp
+	istoret 1,contw
+	rshift8 pdata,temp
+	istoret 1,contw
+	istore 1,contw
+	deposit rega
+	store 2,core_spid_txaddr
+	setarg 0
+	store 2,core_spid_rxlen
+	jam spid_start,core_misc_ctrl
+	branch wait_spid_done
+		
+mouse_flash_erase_sector:
+	fetch 3,mem_flash_base
+	store 3,mem_spi_write_addr
+	branch spid_flash_erase_sector+2
+
+mouse_spid_write_flash:
+	copy pdata,regc
+	copy rega,pdata
+	increase -4,pdata
+	copy pdata,regb
+	ifetch 4,regb
+	store 4,mem_write_flash_head_temp
+	copy regc,pdata
+	call spid_write_flash
+	fetch 4,mem_write_flash_head_temp
+	istore 4,regb
+	rtn
+
+mouse_flash_power_down:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	rtnbit0 MOUSE_ENABLE_FLASH
+	call mouse_spid_flash_powerdown
+	call twspi_enable	// 2 wire mode
+	fetcht 1,mem_spi_cs_gpio		//disable flash
+	call gpio_out_inactive
+	fetcht 1,mem_spi_hold_gpio
+	branch mouse_gpio_config_input_pd
+
+mouse_load_eeprom_info_check:
+	call iicd_read_init_pin
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	isolate1 MOUSE_ENABLE_2K_EEPROM,pdata
+	ncall clear_eeprom_size_2k,true
+	call mouse_eeprom_load_recon_info
+	branch mouse_app_initflag_check
+
+mouse_eeprom_load_recon_info:
+	arg 128,temp
+	arg mem_device_flag,rega
+	arg MOUSE_INFO_EEPROM_OFFECT,regb
+	branch iicd_read_eep_data
+
+mouse_store_eeprom_device_info:
+	arg 128,temp
+	arg mem_device_flag,rega
+	arg MOUSE_INFO_EEPROM_OFFECT,regb
+	branch iicd_write_protect_eep_data
+
+
+mouse_store_eerpom_dpi:
+	arg 1,temp
+	arg mem_mouse_dpi,rega
+	arg MOUSE_DPI_EEPROM_OFFECT,regb
+	branch iicd_write_protect_eep_data
+
+mouse_load_eeprom_dpi:
+	arg 1,temp
+	arg mem_mouse_dpi,rega
+	arg MOUSE_DPI_EEPROM_OFFECT,regb
+	branch iicd_read_eep_data
+
+
+
+mouse_idle:
+	bpatch patch1b_6,mem_patch1b
+	call mouse_low_voltage_led_no_enter_lpm
+	call ui_check_paring_button
+	call mouse_dpi_check
+	call mouse_select_device_check
+	call mouse_check_select_device_by_switch
+	call mouse_bt_button_check
+	call mouse_usb_isr
+	call mouse_wheel_check
+	branch mouse_usb_mode
+
+mouse_select_device_check:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit1 MOUSE_ENABLE_SELECT_DEVICE_BY_PB_BUTTON,mouse_select_device_by_pb_button
+	bbit1 MOUSE_ENABLE_PB_BUTTON_LONG_PRESS_DISCONVERY,mouse_select_device_by_pb_button
+	rtn
+
+mouse_select_device_by_pb_button_check_once:
+	jam 0x03,mem_mouse_pbkey_press_status
+mouse_select_device_by_pb_button:	
+	fetch 1,mem_config_select_device_button_gpio
+	rtneq GPIO_DISABLE
+	arg 0,rega
+	jam MOUSE_PB_KEY,mem_mouse_key_temp
+	fetcht 1,mem_config_select_device_button_gpio
+	call mouse_pb_button_check
+	store 1,mem_mouse_pbkey_press_status
+	fetch 1,mem_matrix_public_gpio
+	beq GPIO_DISABLE,mouse_3io6key_pb_button_check_end	
+	call mouse_matrix_public_gpio_reset
+mouse_select_device_by_pb_button_exit:	
+	copy rega,pdata
+	bbit1 MOUSE_PB_KEY,mouse_select_device_button_down
+	branch mouse_select_device_button_up
+
+mouse_3io6key_pb_button_check_end:
+	fetcht 1,mem_config_select_device_button_gpio
+	call mouse_gpio_config_input_pu
+	branch mouse_select_device_by_pb_button_exit
+
+
+mouse_pb_button_check:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit1 MOUSE_ENABLE_PB_BUTTON_CONNECT_GND,mouse_pb_button_connect_gnd
+	fetch 1,mem_mouse_pbkey_press_status
+	copy pdata,regc
+	fetch 1,mem_matrix_public_gpio
+	beq GPIO_DISABLE,mouse_3io6key_check
+	fetch 1,mem_mouse_ghost_flag
+	nbranch mouse_select_device_by_pb_button_end,blank
+	branch mouse_pb_button_connect_matrix
+
+mouse_select_device_by_pb_button_end:
+	jam PB_BUTTON_STATE_UP,mem_select_device_button_statue
+	jam 0,mem_mouse_pbkey_press_status
+	rtn
+
+mouse_pb_button_connect_gnd:
+	fetch 1,mem_mouse_pbkey_press_status
+	branch mouse_check_key_connect_gnd
+
+mouse_pb_button_connect_matrix:
+	call gpio_get_bit
+	fetcht 1,mem_matrix_public_gpio
+	branch mouse_pb_button_connect_gnd,true
+	fetcht 1,mem_matrix_public_gpio
+	call gpio_out_active
+	fetcht 1,mem_config_select_device_button_gpio
+	fetch 1,mem_mouse_pbkey_press_status
+	branch mouse_check_key_connect_gnd
+	
+mouse_select_device_button_up:
+	fetch 1,mem_select_device_button_statue
+	rtneq PB_BUTTON_STATE_UP
+	jam PB_BUTTON_STATE_UP,mem_select_device_button_statue	
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	rtnbit1 MOUSE_ENABLE_PB_BUTTON_SHORT_PRESS_ENTER_DISCOVERY
+	fetch 1,mem_bt_discovery_count
+	sub pdata,20,null
+	ncall mouse_ready_reconnection_by_button,positive		// press button less than 30-20=1000ms
+	fetch 1,mem_ui_button_timeout
+	store 1,mem_bt_discovery_count
+	rtn
+
+mouse_select_device_button_down:
+	call mouse_select_device_ghost_check
+	rtn user
+	fetch 1,mem_select_device_button_statue
+	rtneq PB_BUTTON_STATE_DOWN
+	jam PB_BUTTON_STATE_DOWN,mem_select_device_button_statue
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit1 MOUSE_ENABLE_PB_BUTTON_SHORT_PRESS_ENTER_DISCOVERY,mouse_long_button_bt_discovery
+	fetch 1,mem_mouse_direct_timer
+	rtn blank
+	fetch 1,mem_mouse_direct_timeout
+	store 1,mem_mouse_direct_timer
+	rtn
+
+mouse_select_device_ghost_check:
+	disable user
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	rtnbit1 MOUSE_ENABLE_PB_BUTTON_CONNECT_GND
+	fetch 1,mem_mouse_lkey_press_status
+	rtn blank
+	fetch 1,mem_mouse_rkey_press_status
+	rtn blank
+	enable user
+	rtn
+	
+
+
+mouse_check_select_device_by_switch:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit1 MOUSE_ENABLE_SELECT_DEVICE_BY_SWITCH_GPIO,mouse_check_select_device_by_switch_gpio
+	bbit1 MOUSE_ENABLE_SELECT_DEVICE_BY_SWITCH_ADC,mouse_adc_read
+	rtn
+mouse_check_select_device_by_switch_gpio:	
+	fetcht 1,mem_device_switch_gpio
+	call mouse_gpio_config_input_pu
+	fetcht 1,mem_device_switch_gpio
+	call gpio_get_bit
+	branch mouse_check_select_24gdevice,true
+mouse_select_btdevice:
+	fetch 1,mem_device_flag
+	rtneq MODE_BT_DEVICE1
+	jam MODE_BT_DEVICE1,mem_device_flag
+	branch mouse_stop_bluetooth_mode
+	
+	
+mouse_check_select_24gdevice:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit0 MOUSE_ENABLE_SELECT_DEVICE_BY_SWITCH_ADC,mouse_check_select_24g_device
+	fetch 6,mem_mouse_vdd_switch_gnd_full_vol
+	store 6,mem_mouse_vdd_calculate_set
+mouse_check_select_24g_device:	
+	fetch 1,mem_device_flag
+	rtneq MODE_24G_DEVICE
+	jam MODE_24G_DEVICE,mem_device_flag
+	branch mouse_24g_stop
+
+	
+
+mouse_ready_reconnection_by_button:
+	bpatch patch1b_7,mem_patch1b
+	fetch 1,mem_device_number
+	rtneq 1		// 1channel
+	call mouse_select_device_number
+	storet 1,mem_device_flag
+mouse_store_device_number_before_reset:	
+	jam 0,mem_link_key_exists
+	call mouse_select_device_enable
+	call mouse_stop_bluetooth_mode
+	call mouse_select_device_disable
+	jam 1,mem_mouse_need_soft_reset
+	branch mouse_store_device_info_delay
+
+
+mouse_soft_reset:
+	call mouse_select_device_enable
+	branch soft_reset_chip
+
+mouse_select_device_number:
+	fetcht 1,mem_device_flag
+	increase 1,temp
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit1 MOUSE_ENABLE_24G,mouse_select_device_number_24g
+	sub temp,2,null
+	ncall mouse_select_device_count_clean_bt,positive
+	rtn
+	
+mouse_select_device_number_24g:	
+	fetch 1,mem_device_number
+	increase -1,pdata
+	isub temp,null
+	ncall mouse_select_device_count_clean_24g,positive
+	rtn
+
+mouse_select_device_count_clean_24g:
+	arg 0,temp
+	rtn
+mouse_select_device_count_clean_bt:
+	arg 1,temp
+	rtn
+
+
+mouse_store_device_number2eeprom:
+	arg 1,temp
+	arg mem_device_flag,rega
+	arg 0,regb
+	branch iicd_write_protect_eep_data
+		
+
+mouse_bt_button_check:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	rtnbit0 MOUSE_ENABLE_PB_BUTTON_SHORT_PRESS_ENTER_DISCOVERY
+	call mouse_select_device_by_pb_button
+	rtn
+
+
+
+
+mouse_select_device_enable:
+	arg MOUSE_SELECT_DEVICE_FLAG,queue
+	branch mouse_enable_function_flag
+mouse_select_device_disable:
+	arg MOUSE_SELECT_DEVICE_FLAG,queue
+	branch mouse_disable_function_flag
+mouse_bt_cannel_reconn_enable:
+	arg MOUSE_BT_CANNEL_RECONN_FLAG,queue
+	branch mouse_enable_function_flag
+mouse_bt_cannel_reconn_disable:
+	arg MOUSE_BT_CANNEL_RECONN_FLAG,queue
+	branch mouse_disable_function_flag
+mouse_bt_discovery_button_down_enable:
+	arg MOUSE_BT_DISCOVERY_BUTTON_DOWN_FLAG,queue
+	branch mouse_enable_function_flag
+mouse_bt_discovery_button_down_disable:
+	arg MOUSE_BT_DISCOVERY_BUTTON_DOWN_FLAG,queue
+	branch mouse_disable_function_flag
+
+mouse_adc_read_enable:
+	arg MOUSE_ENABLE_ADC,queue
+	branch mouse_enable_function_flag
+
+mouse_24g_set_250Hz:
+	arg MOUSE_ENABLE_24G_250Hz,queue
+	branch mouse_enable_function_flag
+
+mouse_24g_search_dongle_enable:
+	arg MOUSE_ENABLE_24G_SEARCH_DONGLE,queue
+	branch mouse_enable_function_flag
+	
+mouse_16M_enable:
+	arg MOUSE_ENABLE_16M,queue
+	branch mouse_enable_function_flag
+	
+mouse_dpi_4level_enable:
+	arg MOUSE_ENABLE_DPI_LEVEL_4,queue
+	branch mouse_enable_function_flag
+
+
+mouse_enable_function_flag:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	qset1 pdata
+	store MOUSE_FLAG_LEN,mem_mouse_flag
+	rtn
+
+mouse_disable_function_flag:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	qset0 pdata
+	store MOUSE_FLAG_LEN,mem_mouse_flag
+	rtn
+
+mouse_customer_key_enable:
+	arg MOUSE_ENABLE_KEYBOARD,queue
+	call mouse_enable_function_flag
+	setarg 0
+	store 8,mem_customer_key_press
+	store 8,mem_customer_key_release
+	fetch 1,mem_mouse_enable_flag	// 00--win+d     01--ctrl+alt+a    02--AC home    03--play
+	and pdata,0xc0,pdata
+	beq 0x40,mouse_customer_key_ctrl_alt_a
+	beq 0x80,mouse_customer_AC_home
+	beq 0xc0,mouse_customer_key_play
+	setarg 0x070008
+mouse_customer_standrad_key_set:	
+	store 8,mem_customer_key_press+1		// win + d
+	rtn
+
+mouse_customer_key_ctrl_alt_a:
+	setarg 0x040005
+	branch mouse_customer_standrad_key_set
+
+	
+mouse_customer_AC_home:
+	setarg 0x022303
+mouse_customer_media_key_set:	
+	store 8,mem_customer_key_press
+	setarg 0x03
+	store 8,mem_customer_key_release
+	rtn
+	
+mouse_customer_key_play:
+	setarg 0x00cd03
+	branch mouse_customer_media_key_set
+
+	
+
+
+
+	
+mouse_polling_device:
+	bpatch patch1c_0,mem_patch1c
+	fetch 1,mem_reconn_times
+	increase -1,pdata
+	store 1,mem_reconn_times
+	fetcht 1,mem_device_flag
+	sub temp,1,null
+	ncall mouse_select_device_number,zero
+	storet 1,mem_device_flag
+	jam 0,mem_link_key_exists
+	call mouse_store_device_number2eeprom
+	call mouse_before_store_reconn_info
+	branch mouse_start_reconnect_device
+	
+
+
+//notice: need to call p_mouse_drawing_optima_init when waked from mult
+mouse_drawing_optima:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	rtnbit0 MOUSE_ENABLE_SMOOTHER
+	fetch 4,mem_mouse_x
+	rtn blank
+	call mouse_data_abs_check
+	setarg 0x03	//asm_flag enable condition
+	call mouse_pdata_greater_than_check
+	call mouse_disable_asm,blank
+	ncall mouse_enable_asm,blank
+	setarg 0x02	//asm_flag disable condition
+	call mouse_data_less_than_check
+	call mouse_disable_asm,blank
+	fetch 1,mem_mouse_asm_flag
+	beq 1,mouse_drawing_optima_modify
+mouse_drawing_optima_init:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	rtnbit0 MOUSE_ENABLE_SMOOTHER
+	arg 5,loopcnt
+	arg mem_mouse_asm_flag,contw
+	branch clear_mem
+
+mouse_drawing_optima_modify:
+	call mouse_drawing_optima_xy_offset_modify
+	fetch 2,mem_mouse_x_pre
+	store 2,mem_data_pre
+	fetch 2,mem_mouse_x
+	store 2,mem_data_current
+	call mouse_drawing_optima_data_x
+	fetch 2,mem_data_pre
+	store 2,mem_mouse_x_pre
+	fetch 2,mem_data_current
+	store 2,mem_mouse_x
+
+	fetch 2,mem_mouse_y_pre
+	store 2,mem_data_pre
+	fetch 2,mem_mouse_y
+	store 2,mem_data_current
+	call mouse_drawing_optima_data_y
+	fetch 2,mem_data_pre
+	store 2,mem_mouse_y_pre
+	fetch 2,mem_data_current
+	store 2,mem_mouse_y
+	rtn
+
+mouse_drawing_optima_xy_offset_modify:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	rtnbit0 MOUSE_ENABLE_XY_OFFSET
+	fetch 2,mem_mouse_x_pre
+	store 2,mem_data_value
+	call mouse_pre_xy_data_judge
+	store 2,mem_mouse_x_pre
+	fetch 2,mem_mouse_x
+	store 2,mem_data_value
+	call mouse_current_xy_data_judge
+	store 2,mem_mouse_x
+	fetch 2,mem_mouse_y_pre
+	store 2,mem_data_value
+	call mouse_pre_xy_data_judge
+	store 2,mem_mouse_y_pre
+	fetch 2,mem_mouse_y
+	store 2,mem_data_value
+	call mouse_current_xy_data_judge
+	store 2,mem_mouse_y
+	rtn
+
+mouse_pre_xy_data_judge:	
+	fetch 1,mem_data_value+1
+	branch mouse_pre_xy_pdata_offset,blank
+	branch mouse_pre_xy_ndata_offset
+
+mouse_pre_xy_pdata_offset:
+	fetch 1,mem_data_value
+	call mouse_pre_xy_get_0_4_times
+	store 1,mem_data_value
+mouse_xy_data_offset_new:
+	fetch 2,mem_data_value
+	rtn
+mouse_pre_xy_ndata_offset:
+	fetch 1,mem_data_value
+	call mouse_pdata_invert
+	call mouse_pre_xy_get_0_4_times
+	call disable_blank,blank
+	call mouse_pdata_get_new_value
+	branch mouse_xy_data_offset_new
+	
+mouse_current_xy_data_judge:
+	fetch 1,mem_data_value+1
+	branch mouse_current_xy_pdata_offset,blank
+	branch mouse_current_xy_ndata_offset
+mouse_current_xy_pdata_offset:
+	fetch 1,mem_data_value
+	call mouse_current_xy_get_0_6_times
+	store 1,mem_data_value
+	branch mouse_xy_data_offset_new
+mouse_current_xy_ndata_offset:	
+	fetch 1,mem_data_value
+	call mouse_pdata_invert
+	call mouse_current_xy_get_0_6_times
+	call disable_blank,blank
+	call mouse_pdata_get_new_value
+	branch mouse_xy_data_offset_new
+	
+mouse_pre_xy_get_0_4_times:
+	mul32 pdata,4,pdata
+	div pdata,5
+	call wait_div_end
+	quotient pdata
+	rtn
+mouse_current_xy_get_0_6_times:	//0.6 times
+	mul32 pdata,12,pdata
+	div pdata,10
+	call wait_div_end
+	quotient pdata
+	rtn	
+	
+mouse_drawing_optima_data_x:
+	fetch 2,mem_data_pre
+	fetcht 2,mem_data_current
+	iadd temp,pdata
+	fetcht 1,mem_mouse_data_xtemp
+	iadd temp,pdata
+	and pdata,0x01,temp
+	storet 1,mem_mouse_data_xtemp
+	branch mouse_drawing_optima_data
+
+mouse_drawing_optima_data_y:
+	fetch 2,mem_data_pre
+	fetcht 2,mem_data_current
+	iadd temp,pdata
+	fetcht 1,mem_mouse_data_ytemp
+	iadd temp,pdata
+	and pdata,0x01,temp
+	storet 1,mem_mouse_data_ytemp
+	branch mouse_drawing_optima_data
+
+/**********
+input:data_pre,data_current
+output:data_pre,data_current after optima
+***********/
+mouse_drawing_optima_data:
+	store 3,mem_data_sum
+	isolate1 16,pdata
+	branch mouse_data_sum_overflow,true
+	fetch 1,mem_data_sum+1
+	beq 0xff,mouse_data_sum_n
+	fetch 1,mem_data_sum
+mouse_data_store_pre:
+	rshift pdata,pdata
+	store 2,mem_data_pre
+	store 2,mem_data_current
+	rtn
+mouse_data_sum_overflow:
+	fetch 1,mem_data_sum+1	//sum positive
+	beq 0,mouse_data_sum_overflow_p
+	fetch 3,mem_data_sum	
+	branch mouse_data_store_pre
+mouse_data_sum_overflow_p:
+	jam 0,mem_data_sum+2
+	fetch 1,mem_data_sum
+	branch mouse_data_store_pre
+
+mouse_data_sum_n:
+	fetch 1,mem_data_sum	//sum negetive
+	call mouse_pdata_get_half
+	store 1,mem_data_pre
+	store 1,mem_data_current
+	branch mouse_data_zero,blank
+	setarg 0xff
+mouse_data_set_direction:	
+	store 1,mem_data_pre+1
+	store 1,mem_data_current+1
+	rtn
+mouse_data_zero:
+	setarg 0
+	branch mouse_data_set_direction
+
+mouse_pdata_get_half:
+	call mouse_pdata_invert
+	rshift pdata,pdata
+mouse_pdata_get_new_value:	
+	call mouse_rega_in_out
+	sub pdata,0,pdata
+	store 1,mem_data_value	
+	rtn
+
+mouse_pdata_invert:
+	sub pdata,0,pdata
+mouse_rega_in_out:	
+	store 1,mem_rega
+	fetch 1,mem_rega
+	rtn
+
+mouse_disable_asm:
+	jam 0,mem_mouse_asm_flag
+	rtn
+mouse_enable_asm:
+	jam 1,mem_mouse_asm_flag
+	rtn
+
+//rega mouse_x, regb mouse_y, pdata refer
+mouse_pdata_greater_than_check:
+	isub rega,null
+	nbranch disable_blank,positive
+	isub regb,null
+	nbranch disable_blank,positive
+	branch enable_blank
+mouse_data_less_than_check:
+	isub rega,null
+	nrtn positive
+	isub regb,null
+	nrtn positive
+	branch enable_blank
+
+mouse_data_abs_check:
+	fetch 2,mem_mouse_x
+	call mouse_data_abs
+	copy pdata,rega
+	fetch 2,mem_mouse_y
+	call mouse_data_abs
+	copy pdata,regb
+	rtn
+
+/***********
+input: data_current
+output:pdata,abs
+************/
+mouse_data_abs:
+	store 2,mem_data_current
+	fetch 1,mem_data_current+1
+	beq 0xff,mouse_data_reversal
+	fetch 1,mem_data_current
+mouse_data_abs_store:
+	and_into 0xff,pdata
+	//output:pdata
+	rtn
+mouse_data_reversal:
+	fetch 2,mem_data_current
+	sub pdata,0,pdata
+	branch mouse_data_abs_store
+
+mouse_24g_long_sleep_param_update_timer:
+	arg mem_24g_long_sleep_param_update_timer,regc
+	arg mouse_24g_long_sleep_normal_param,regb
+	branch timer_single_step
+mouse_24g_long_sleep_normal_param:
+	fetch 4,mem_24g_long_sleep_set1
+	store 4,mem_24g_enter_hibernate
+	jam 1,mem_mouse_long_mult_flag
+	rtn
+
+
+mouse_24g_long_sleep_set:
+	beq 0x00,mouse_24g_long_sleep_set_30ms
+	beq 0x01,mouse_24g_long_sleep_set_50ms
+	beq 0x02,mouse_24g_long_sleep_set_80ms
+	beq 0x03,mouse_24g_long_sleep_set_100ms
+mouse_24g_long_sleep_set_80ms:
+	setarg 0x0ea600
+mouse_24g_long_sleep_set_end:	
+	store 4,mem_24g_long_sleep_set1
+	rtn
+mouse_24g_long_sleep_set_30ms:
+	setarg 0x05e740
+	branch mouse_24g_long_sleep_set_end
+mouse_24g_long_sleep_set_50ms:
+	setarg 0x0927c0
+	branch mouse_24g_long_sleep_set_end
+mouse_24g_long_sleep_set_100ms:
+	setarg 0x124f80
+	branch mouse_24g_long_sleep_set_end
+
+	
+
+mouse_24g_hibernate_set:
+	jam 0,mem_24g_attempt_fail_flag
+	call g24_transmit_next_packet
+	setarg -1
+	store 4,mem_24g_enter_hibernate
+	setarg 0
+	store 7,mem_mouse_key
+	jam 1,mem_sensor_shutdown_flag
+	call mouse_sensor_powerdown
+	call mouse_setgpio_hibernate
+	branch g24_long_sleep
+
+mouse_wakeup_24g:
+	fetch 1,mem_sensor_shutdown_flag
+	ncall mouse_init_sensor_wakeup,blank
+	jam 0,mem_sensor_shutdown_flag
+	branch g24_transmit_no_ack
+
+mouse_24g_transmit_start:
+	fetch 1,mem_sensor_shutdown_flag
+	nbranch g24_short_sleep,blank
+	branch g24_transmit_start_next
+
+
+mouse_24g_stop:
+	set0 mark_24g,mark
+	jam STATE_24G_STOP,mem_24g_conn_sm
+	arg MOUSE_24G_PAIRING_FLAG,queue
+	branch mouse_disable_function_flag
+
+
+mouse_24g_start_mode:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit0 MOUSE_ENABLE_24G,mouse_24g_mode_setup_error
+	call mouse_wakeup_from_power_check	// wake from hibernate :enble user
+	branch mouse_24g_reconn_dongle_start,user
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit1 MOUSE_ENABLE_AUTO_24G_PARING,mouse_24g_reconn_general_dongle
+	bbit0 MOUSE_ENABLE_24G_POWER_ON_PAIRING,mouse_24g_reconn_general_dongle
+	call mouse_key_check_once
+	and pdata,0x07,pdata
+	fetcht 1,mem_mouse_commbination_key_24g
+	isub temp,null
+	branch mouse_24g_start_pair_mode,zero
+	branch mouse_24g_reconn_general_dongle
+
+mouse_24g_mode_setup_error:
+	fetch 1,mem_reconn_times
+	nbranch mouse_polling_device,blank
+	rtn
+
+mouse_24g_reconn_dongle_start:
+	fetch 2,mem_24g_reconn_timeout_init
+	store 2,mem_24g_reconn_timeout
+	jam RECEIVER_AND_3_0_ADDR,mem_24g_reconn_type
+	branch g24_reconn_start
+
+
+mouse_24g_first_start_auto_pair_mode:
+	call mouse_wakeup_from_power_check
+	branch mouse_24g_first_start_reconn,user  	// wake from hibernate :enble user
+mouse_24g_reconn_general_dongle:	
+	jam MODE_24G_DEVICE,mem_device_flag
+	fetch 2,mem_mouse_24g_power_on_fast_conn_timer
+	store 2,mem_24g_reconn_timeout
+	jam FAST_CONN_AND_3_0_ADDR,mem_24g_reconn_type
+	branch g24_reconn_start
+
+mouse_24g_start_auto_pair:
+	call mouse_discover_setting_led_gpio
+	fetch 2,mem_24g_pair_timeout_init
+	store 2,mem_24g_reconn_timeout
+	jam PAIR_AND_3_0_ADDR,mem_24g_reconn_type
+	branch g24_reconn_start
+
+
+mouse_24g_first_start_reconn:
+	fetch 1,mem_device_flag
+	beq MODE_24G_DEVICE,mouse_24g_reconn_dongle_start
+	call mouse_bluetooth_fast_conn_disable
+	branch mouse_24g_first_bluetooth_reconnect
+	
+mouse_24g_first_bluetooth_reconnect:
+	call mouse_24g_stop
+	call mouse_device_led_all_off
+mouse_check_bt_reconn_target:
+	jam MODE_BT_DEVICE1,mem_device_flag
+	call mouse_select_reconn_device
+	branch mouse_start_reconnect_device
+
+mouse_24g_first_bb_event_reconn_timeout:
+	call mouse_wakeup_from_power_check
+	branch mouse_app_enter_hibernate,user
+	branch mouse_start_discovery
+
+
+mouse_24g_first_store_reconn_info:
+	call mouse_wakeup_from_power_check
+	rtn user
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit1 MOUSE_ENABLE_24G_FIRST_AUTO_PAIRING,mouse_store_device_info_delay
+	rtn
+
+mouse_24g_start_pair_mode:
+	arg MOUSE_24G_PAIRING_FLAG,queue
+	call mouse_enable_function_flag
+	setarg 0
+	store 2,mem_24g_reconn_timeout	
+	call mouse_stop_discovery
+	call mouse_low_voltage_led_blink_disable
+	call mouse_discover_setting_led_gpio
+	jam TYPE_MS,mem_24g_data_type
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit0 MOUSE_ENABLE_KEYBOARD,g24_pair_start
+	jam TYPE_KB,mem_24g_data_type
+	branch g24_pair_start
+
+	
+mouse_24g_attempt_fail:
+	fetch 1,mem_24g_attempt_fail_flag
+	nbranch mouse_24g_hibernate_set,blank
+	fetch 1,mem_24g_reconn_type
+	beq FAST_CONN_AND_3_0_ADDR,mouse_24g_fast_conn_attempt_fail
+	beq PAIR_AND_3_0_ADDR,mouse_24g_auto_pair_attempt_fail
+	beq RECEIVER_AND_3_0_ADDR,mouse_reconn_dongle_attempt_fail
+mouse_24g_attempt_fail_enter_hibernate:
+	call mouse_device_led_off
+	call mouse_24g_stop
+	fetch 1,mem_reconn_times
+	nbranch mouse_polling_device,blank
+	fetch 1,mem_device_flag
+	beq MODE_24G_DEVICE,mouse_app_enter_hibernate
+	rtn
+
+mouse_24g_fast_conn_attempt_fail:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag 
+	bbit1 MOUSE_ENABLE_24G_FIRST_AUTO_PAIRING,mouse_24g_start_auto_pair
+	bbit1 MOUSE_ENABLE_AUTO_24G_PARING,mouse_24g_start_auto_pair
+	branch mouse_24g_reconn_dongle_start
+
+
+mouse_24g_auto_pair_attempt_fail:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag 
+	bbit0 MOUSE_ENABLE_24G_FIRST_AUTO_PAIRING,mouse_24g_attempt_fail_enter_hibernate
+	fetch 1,mem_device_number
+	beq 1,mouse_24g_attempt_fail_enter_hibernate		//24g first mode and only 2.4g device
+	branch mouse_24g_first_bluetooth_reconnect
+
+mouse_reconn_dongle_attempt_fail:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit0 MOUSE_ENABLE_24G_FIRST_AUTO_PAIRING,mouse_24g_attempt_fail_enter_hibernate
+	bbit1 MOUSE_ENABLE_EEPROM,mouse_24g_attempt_fail_enter_hibernate
+	bbit1 MOUSE_ENABLE_FLASH,mouse_24g_attempt_fail_enter_hibernate
+	branch mouse_24g_start_auto_pair+1
+
+		
+mouse_24g_attempt_success:
+	call mouse_init_sensor_reset
+	jam 0,mem_mouse_long_mult_flag
+	jam 0,mem_24g_conn_sm
+	jam 0,mem_24g_reconn_type
+	fetch 4,mem_24g_receiver_addr
+	fetch 4,mem_24g_fast_conn_addr
+	isub temp,null
+	rtn zero
+	branch mouse_24g_first_store_reconn_info
+	
+mouse_24g_pairing_complete:
+	arg MOUSE_24G_PAIRING_FLAG,queue
+	call mouse_disable_function_flag
+	call mouse_device_poweron_timer_init
+	setarg 0
+	store 2,mem_24g_pair_timeout
+	store 2,mem_24g_reconn_timeout
+	store 1,mem_24g_conn_sm
+	store 1,mem_mouse_move_flag
+	store 1,mem_24g_reconn_type
+
+	call mouse_init_sensor_reset
+	call mouse_read_sensor_common
+	fetch 4,mem_24g_addr
+	store 4,mem_24g_receiver_addr
+	store 4,mem_mouse_24g_addr
+	branch mouse_store_device_info_delay
+
+mouse_24g_package_data:
+	rtnmark0 mark_24g
+	call mouse_motion
+	nrtn user
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit0 MOUSE_ENABLE_KEYBOARD,mouse_24g_mouse_package_data
+	fetch 1,mem_customer_key
+	nbranch mouse_24g_keyboard_package_data,blank
+mouse_24g_mouse_package_data:
+	call mouse_data_xy_release
+	fetch 1,mem_24g_data_type
+	bbit1 1,mouse_24g_mouse_package_data_now	// last package is keyboard data
+	fetcht 1,mem_24g_txbuf+1
+	fetch 1,mem_mouse_key
+	ior temp,pdata
+	store 1,mem_mouse_key
+	fetcht 1,mem_24g_txbuf+6
+	fetch 1,mem_mouse_z
+	iadd temp,pdata
+	store 1,mem_mouse_z
+	fetcht 1,mem_24g_txbuf+7
+	fetch 1,mem_mouse_tz
+	iadd temp,pdata
+	store 1,mem_mouse_tz	
+mouse_24g_mouse_package_data_now:	
+	jam TYPE_MS,mem_24g_data_type
+	arg 7,rega	//length
+	arg mem_mouse_key,regb //tx buff
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit1 MOUSE_ENABLE_24G_250Hz,g24_transmit_by_interrupt_enable
+	fetch 2,mem_mouse_z
+	rtn blank
+	branch g24_transmit_by_interrupt_enable
+
+mouse_24g_keyboard_package_data:
+	jam TYPE_KB,mem_24g_data_type
+	arg 9,rega	//length
+	fetch 1,mem_customer_data_trigger
+	nbranch mouse_customer_key_press,blank
+	arg mem_customer_key_release,regb	//tx buff
+	rtn
+mouse_customer_key_press:
+	arg mem_customer_key_press,regb
+	rtn
+
+
+
+/**************************************g24 search receiver*****************************************/
+
+mouse_24g_search_dongle_init:
+	setarg 0
+	store 3,mem_mouse_search_dongle_action
+	rtn
+
+mouse_24g_search_dongle:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	rtnbit0 MOUSE_ENABLE_24G_SEARCH_DONGLE
+	fetch 1,mem_mouse_long_mult_flag
+	rtn blank
+	fetch 1,mem_24g_abort_pac
+	rtn blank
+	fetch 1,mem_mouse_search_dongle_interval
+	increase 1,pdata
+	and_into 3,pdata
+	store 1,mem_mouse_search_dongle_interval
+	nrtn blank	//400ms
+	jam 0,mem_mouse_search_dongle_ch
+mouse_24g_search_dongle_loop:
+	fetch 1,mem_mouse_search_dongle_ch
+	increase 1,pdata
+	store 1,mem_mouse_search_dongle_ch
+	sub pdata,G24_CH_NUMBER,null
+	nbranch mouse_24g_search_dongle_loop_end,positive
+	call g24_reconn_data_prep
+	call g24_transmit_receive_ack
+	nbranch mouse_24g_search_dongle_loop_retry,sync
+	nbranch mouse_24g_search_dongle_loop_retry,user3
+	call mouse_24g_search_dongle_success
+mouse_24g_search_dongle_loop_end:
+	call g24_txbuf_clear
+	fetch 1,mem_mouse_search_dongle_count
+	increase 1,pdata
+	store 1,mem_mouse_search_dongle_count
+	beq G24_CH_POLL_COUNT,mouse_24g_search_dongle_check
+	rtn
+
+mouse_24g_search_dongle_loop_retry:
+	call g24_ch
+	branch mouse_24g_search_dongle_loop
+
+mouse_24g_search_dongle_check:
+	jam 0,mem_mouse_search_dongle_count
+	fetch 1,mem_mouse_search_dongle_action
+	rtnbit1 G24_DISCONN_STATE
+	set1 G24_DISCONN_STATE,pdata
+	store 1,mem_mouse_search_dongle_action
+	fetch 2,mem_mouse_24g_search_dongle_time_init		//3min
+	store 2,mem_mouse_no_data_timer
+	branch mouse_sensor_powerdown
+
+mouse_24g_search_dongle_success:
+	fetch 1,mem_24g_abort_pac
+	branch mouse_24g_search_dongle_init,blank
+	jam 0,mem_mouse_search_dongle_count
+	fetch 1,mem_mouse_search_dongle_action
+	rtnbit0 G24_DISCONN_STATE
+	set0 G24_DISCONN_STATE,pdata
+	store 1,mem_mouse_search_dongle_action
+	call mouse_no_data_timer_init
+	branch mouse_init_sensor_wakeup
+
+/**************************************g24 search receiver*****************************************/
+
+
+
+/*******************led*************************/
+mouse_device_poweron_timer:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	rtnbit0 MOUSE_ENABLE_POWER_ON_LED
+	fetch 1,mem_mouse_device_poweron_timer_count
+	rtn blank
+	increase -1,pdata
+	store 1,mem_mouse_device_poweron_timer_count
+	branch mouse_device_led_off,blank
+	branch mouse_device_led_on
+	
+mouse_device_poweron_timer_init:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	rtnbit0 MOUSE_ENABLE_POWER_ON_LED
+	call mouse_low_voltage_led_blink_disable
+	fetch 1,mem_mouse_device_poweron_timer_count_init
+	store 1,mem_mouse_device_poweron_timer_count
+	rtn	
+
+	
+mouse_discover_setting_led_gpio:
+	jam 0,mem_mouse_device_poweron_timer_count
+	fetch 2,mem_mouse_disconvey_led_blink_time
+	store 2,mem_mouse_on_time
+	store 2,mem_mouse_off_time	
+mouse_setting_led_gpio_comman:
+	fetch 1,mem_device_flag
+	beq MODE_24G_DEVICE,mouse_device_led_24g
+	beq MODE_BT_DEVICE1,mouse_device_led_bt1
+	beq MODE_BT_DEVICE2,mouse_device_led_bt2
+	rtn
+mouse_device_led_24g:
+	fetch 1,mem_config_device_24g_led_gpio
+	branch mouse_led_blink
+mouse_device_led_bt1:
+	fetch 1,mem_config_device_bt1_led_gpio
+	branch mouse_led_blink
+mouse_device_led_bt2:
+	fetch 1,mem_config_device_bt2_led_gpio
+mouse_led_blink:
+	store 1,mem_temp
+	call mouse_device_led_off
+	fetch 1,mem_temp
+	store 1,mem_mouse_struct_led_gpio
+	arg 0,rega
+	jam UI_LED_STATE_BLINK_START,mem_mouse_led_type
+	branch ui_led_blink_start_global
+
+
+mouse_dpi_led_blink_delay:
+	fetch 1,mem_dpi_led_gpio
+	rtneq GPIO_DISABLE
+	fetch 2,mem_mouse_discovery_timer
+	nrtn blank
+	fetch 2,mem_24g_pair_timeout
+	nrtn blank
+	fetch 2,mem_24g_reconn_timeout
+	nrtn blank
+	fetch 1,mem_mouse_device_poweron_timer_count
+	nrtn blank
+	fetch 1,mem_mouse_dpi_led_delay_count_init
+	branch mouse_dpi_led_blink_init,blank
+	store 1,mem_mouse_dpi_led_delay_count  //delay 1s led blink
+	rtn
+
+
+mouse_dpi_led_blink_delay_timer:
+	arg mem_mouse_dpi_led_delay_count,regc
+	arg mouse_dpi_led_blink_init,regb
+	branch timer_single_step	
+	
+mouse_dpi_led_blink_init:
+	fetch 1,mem_dpi_led_gpio
+	store 1,mem_mouse_struct_led_gpio
+	fetch 2,mem_mouse_dpi_led_blink_time
+	store 2,mem_mouse_on_time
+	store 2,mem_mouse_off_time
+	arg 0,rega
+	fetcht 1,mem_mouse_dpi
+	increase 1,temp
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit0 MOUSE_ENABLE_DPI_LEVEL_4,mouse_dpi_led_blink_init_end
+	increase 1,temp
+	sub temp,4,null
+	ncall mouse_dpi_led_blink_count_clean,positive		// blink count:2 3 4 1
+mouse_dpi_led_blink_init_end:	
+	storet 1,mem_mouse_blink_count
+	jam UI_LED_STATE_BLINK_START,mem_mouse_led_type
+	rtn
+
+mouse_dpi_led_blink_count_clean:
+	arg 1,temp
+	rtn
+
+mouse_check_dpi_blink:
+	disable user
+	fetch 1,mem_dpi_led_gpio
+	fetcht 1,mem_mouse_struct_led_gpio
+	isub temp,null
+	nrtn zero
+	fetch 1,mem_mouse_blink_count
+	rtn blank
+	jam 0,mem_adc_low_volatage_led_blink_enable
+	enable user
+	rtn
+
+mouse_device_led_all_off:
+	call mouse_dpi_led_off
+	call mouse_device_24g_led_off
+	call mouse_device_bt1_led_off
+	branch mouse_device_bt2_led_off
+
+mouse_device_led_off:
+	fetch 1,mem_device_flag
+	beq MODE_24G_DEVICE,mouse_device_24g_led_off
+	beq MODE_BT_DEVICE1,mouse_device_bt1_led_off
+	beq MODE_BT_DEVICE2,mouse_device_bt2_led_off
+	rtn
+
+mouse_device_24g_led_off:
+	jam 0,mem_24g_device_led_status
+	fetcht 1,mem_config_device_24g_led_gpio
+	branch mouse_led_off
+
+mouse_device_bt1_led_off:
+	fetcht 1,mem_config_device_bt1_led_gpio
+	branch mouse_led_off
+	
+mouse_device_bt2_led_off:
+	fetcht 1,mem_config_device_bt2_led_gpio
+	branch mouse_led_off
+
+mouse_dpi_led_off:
+	fetcht 1,mem_dpi_led_gpio
+	branch mouse_led_off
+
+mouse_device_led_on:
+	fetch 1,mem_device_flag
+	beq MODE_24G_DEVICE,mouse_device_24g_led_on
+	beq MODE_BT_DEVICE1,mouse_device_bt1_led_on
+	beq MODE_BT_DEVICE2,mouse_device_bt2_led_on
+	rtn
+
+mouse_device_24g_led_on:
+	fetcht 1,mem_config_device_24g_led_gpio
+	branch mouse_led_on
+mouse_device_bt1_led_on:
+	fetcht 1,mem_config_device_bt1_led_gpio
+	branch mouse_led_on
+mouse_device_bt2_led_on:
+	fetcht 1,mem_config_device_bt2_led_gpio
+	branch mouse_led_on
+
+mouse_led_off:
+	bpatch patch1c_1,mem_patch1c
+	storet 1,mem_mouse_struct_led_gpio
+	arg 0,rega
+	branch ui_led_off_global
+mouse_led_on:
+	bpatch patch1c_2,mem_patch1c
+	storet 1,mem_mouse_struct_led_gpio
+	arg 0,rega
+	branch ui_led_on_global
+
+mouse_ui_led_off_static:
+	fetch 1,mem_config_device_24g_led_gpio
+	isub temp,null
+	call mouse_clear_24g_led_statue,zero
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit0 MOUSE_ENABLE_4_LED,gpio_out_inactive
+	call mouse_check_bt2_led_off
+	call mouse_check_dpi_led_off
+	call mouse_check_low_v_led_off
+	fetch 1,mem_mouse_led_off_4_led
+	branch gpio_out_inactive,blank
+	jam 0,mem_mouse_led_off_4_led
+	branch gpio_set_high_impedance
+
+mouse_ui_led_on_static:
+	fetch 1,mem_config_device_24g_led_gpio
+	isub temp,null
+	call mouse_set_24g_led_statue,zero
+	branch gpio_out_active 
+
+
+mouse_check_bt2_led_off:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	rtnbit0 MOUSE_ENABLE_BT2_FOR_4_LED
+	fetch 1,mem_config_device_bt2_led_gpio
+	branch mouse_check_1gpio_2led_off
+mouse_check_dpi_led_off:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	rtnbit0 MOUSE_ENABLE_DPI_FOR_4_LED
+	fetch 1,mem_dpi_led_gpio
+	branch mouse_check_1gpio_2led_off
+mouse_check_low_v_led_off:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	rtnbit0 MOUSE_ENABLE_LOW_V_FOR_4_LED
+	fetch 1,mem_config_low_voltage_alarm_gpio
+mouse_check_1gpio_2led_off:
+	isub temp,null
+	nrtn zero
+	jam 1,mem_mouse_led_off_4_led
+	rtn
+
+mouse_clear_24g_led_statue:
+	jam 0,mem_24g_device_led_status
+	rtn
+
+mouse_set_24g_led_statue:
+	jam 1,mem_24g_device_led_status
+	rtn
+
+mouse_low_voltage_led_timer:
+	fetch 2,mem_mouse_discovery_timer
+	nrtn blank
+	fetch 2,mem_24g_pair_timeout
+	nrtn blank
+	fetch 2,mem_24g_reconn_timeout
+	nrtn blank
+	fetch 1,mem_mouse_device_poweron_timer_count
+	nrtn blank
+	call mouse_check_dpi_blink
+	rtn user
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	rtnbit0 MOUSE_ENABLE_LOW_VOLTAGE_LED
+	rtnbit0 MOUSE_LOW_VOLTAGE_FLAG
+	bbit1 MOUSE_ENABLE_LOW_VOLTAGE_LED_BLINK_N_SECOND,mouse_low_voltage_led_blink_new_data
+	fetch 1,mem_adc_low_volatage_led_timer_count
+	increase 1,pdata
+	store 1,mem_adc_low_volatage_led_timer_count
+	sub pdata,20,null
+	ncall mouse_adc_low_volatage_led_timer_count_clean,positive
+	beq 2,mouse_low_voltage_led_on
+	beq 4,mouse_low_voltage_led_off
+	beq 6,mouse_low_voltage_led_on
+	beq 8,mouse_low_voltage_led_off
+	rtn
+mouse_adc_low_volatage_led_timer_count_clean:
+	jam 1,mem_adc_low_volatage_led_timer_count
+	branch mouse_low_voltage_led_off
+mouse_low_voltage_led_on:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit1 MOUSE_ENABLE_LOW_VOLTAGE_USE_MODE_LED,mouse_device_led_on
+	fetch 1,mem_config_low_voltage_alarm_gpio
+	rtneq GPIO_DISABLE
+	fetcht 1,mem_config_low_voltage_alarm_gpio
+	branch mouse_led_on
+mouse_low_voltage_led_off:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit1 MOUSE_ENABLE_LOW_VOLTAGE_USE_MODE_LED,mouse_device_led_off
+	fetch 1,mem_config_low_voltage_alarm_gpio
+	rtneq GPIO_DISABLE
+	fetcht 1,mem_config_low_voltage_alarm_gpio
+	branch mouse_led_off
+
+mouse_low_voltage_led_blink_new_data:
+	fetch 2,mem_mouse_no_data_timeout
+	fetcht 2,mem_mouse_no_data_timer
+	isub temp,temp
+	fetch 2,mem_adc_low_volatage_led_blink_timer
+	isub temp,null
+	nbranch mouse_low_voltage_led_blink_disable,positive
+	fetch 1,mem_adc_low_volatage_led_blink_enable
+	nrtn blank
+	jam 1,mem_adc_low_volatage_led_blink_enable
+	branch mouse_low_voltage_led_blink_init
+	
+mouse_low_voltage_led_blink_init:
+	fetch 2,mem_mouse_low_v_led_blink_time
+	store 2,mem_mouse_on_time
+	store 2,mem_mouse_off_time
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	bbit1 MOUSE_ENABLE_LOW_VOLTAGE_USE_MODE_LED,mouse_setting_led_gpio_comman
+	fetch 1,mem_config_low_voltage_alarm_gpio
+	rtneq GPIO_DISABLE
+	branch mouse_led_blink
+
+mouse_low_voltage_led_blink_disable:
+	jam 0,mem_adc_low_volatage_led_blink_enable
+	branch mouse_low_voltage_led_off
+
+
+mouse_low_voltage_led_no_enter_lpm:	
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag
+	rtnbit0 MOUSE_ENABLE_LOW_VOLTAGE_LED
+	rtnbit0 MOUSE_LOW_VOLTAGE_FLAG
+	bbit1 MOUSE_ENABLE_LOW_VOLTAGE_LED_BLINK_N_SECOND,mouse_low_voltage_led_no_enter_lpm_blink
+	fetch 1,mem_adc_low_volatage_led_timer_count
+	sub pdata,10,null
+	branch mouse_lpm_mode_clear,positive
+mouse_low_voltage_led_no_enter_lpm_next:	
+	fetch 1,mem_device_flag
+	beq MODE_24G_DEVICE,g24_transmit_by_interrupt_exit_check
+	jam 1,mem_lpm_mode
+	rtn
+
+g24_transmit_by_interrupt_exit_check:
+	fetch MOUSE_FLAG_LEN,mem_mouse_flag	
+	rtnbit1 MOUSE_ENABLE_24G_250Hz	
+	branch g24_transmit_by_interrupt_exit
+
+mouse_lpm_mode_clear:
+	fetch 1,mem_device_flag
+	beq MODE_24G_DEVICE,g24_transmit_by_interrupt_enable
+	jam 0,mem_lpm_mode
+	rtn
+
+mouse_low_voltage_led_no_enter_lpm_blink:
+	fetch 1,mem_adc_low_volatage_led_blink_enable
+	nbranch mouse_lpm_mode_clear,blank
+	branch mouse_low_voltage_led_no_enter_lpm_next
+	
+	
+/*******************led*************************/	
+mouse_store_signal_rssi:
+	call rssi_hex2dec
+	fetch 1,mem_rssi
+	branch rssi_signal
+
+mouse_le_transmit:
+	call mouse_store_signal_rssi
+	branch power_ctrl_start
+
+mouse_bt_slave_match:
+	call mouse_store_signal_rssi
+	fetch 1,mem_state
+	isolate1 state_inconn,pdata
+	nrtn true
+	fetch 1,mem_arq
+	isolate1 wack,pdata
+	call power_ctrl_pac_succ_decrs,true
+	ncall power_ctrl_pac_succ_incrs,true
+	branch power_ctrl_start
+
+mouse_le_set_lpm_mult:
+	fetch 1,mem_le_connect_status_flag
+	compare 3,pdata,3
+	nbranch disable_blank,true
+	call app_lpm_mult_enable
+	branch enable_blank
+
+mouse_bt_set_lpm_mult:
+	call l2cap_malloc_is_fifo_empty
+	nrtn blank
+	jam 1,mem_current_sniff_attempt
+	jam 0,mem_current_sniff_timeout
+	branch enable_blank
+
+mouse_set_lpm_mult:
+	fetch 2,mem_ui_state_map
+	bbit1 UI_STATE_BLE_CONNECTED,mouse_le_set_lpm_mult
+	branch mouse_bt_set_lpm_mult
+
+/*****************close define  COMPILE_MOUSE**********/
+else
+mouse_init:
+mouse_irtual_cable_unplug:
+mouse_store_remote_bdaddr:
+mouse_ui_led_off_static:
+mouse_ui_led_on_static:
+mouse_bt_hid_handshake_boot_check:
+mouse_delay_enter_hibernata:
+mouse_low_voltage_led_no_enter_lpm_blink:
+	rtn
+endif
+
+
+
