#include <stdint.h>
#include <stdbool.h>
#include "dm_imitate_spi.h"
#include "user_imitate_spi.h"
#include "cpu_qdec.h"
#include "app_trace.h"

/*mouse init*/
void mouse_ic_init(void)
{	
	dm_imitate_spi_gpio_init();
	gpio_set_sclk(1);
}

/*set clk,sda gpio*/
void dm_imitate_spi_gpio_init(void)
{
	imitate_spi_gpio_t gpio_init_param={
		.spi_mosi_pin	= GPIOB_Pin5,
		.spi_scl_pin 	= GPIOB_Pin3
	};
	
    syscfg_deepsleep_set_gpiopin_wakeup_src(GPIO_Int3,WakeUpType_32K_AntiShake,GPIOB_Pin5);
	imitate_spi_gpio_init(gpio_init_param);
}

/*Write value to a register*/
void write_mouse_register(mouse_ic_register_t ic_register, uint8_t data)
{
	ic_register = (mouse_ic_register_t)(ic_register | OPERATION_STATE) ;
	spi_write_byte(ic_register);
	spi_write_byte(data);	
}

/*Read value from a register*/
uint8_t read_mouse_register(uint8_t ic_register)
{
	uint8_t mouse_data = 0;
	spi_write_byte(ic_register);
	mouse_data = spi_read_byte();
	return mouse_data;
}


