/*
 * bsp_tp_iic.c
 *
 *  Created on: 2025年4月7日
 *      Author: 22332
 */

#include "cola_init.h"
#include "cola_device.h"


#include "drv_tp_iic.h"

static cola_device_t g_tp_iic;

static int bsp_tp_iic_open(cola_device_t *dev, int oflag){
	(void)dev;
	(void)oflag;
	bsp_drv_tp_iic_init();
    return 0;
}

static int bsp_tp_iic_close(cola_device_t *dev){
	(void)dev;
	bsp_drv_tp_iic_deinit();
    return 0;
}

static int bsp_tp_iic_set_slave_address(cola_device_t *dev, int cmd, void *args){
	(void)dev;
	(void)args;
    return bsp_drv_maste_iic_set_slave_address((uint16_t)cmd);
}

static int bsp_tp_iic_read(cola_device_t *dev, int pos, void *buffer, int size){
	(void)dev;
	(void)pos;
	return bsp_drv_tp_iic_read((uint8_t *)buffer,size,true)?size:0;
}

static int  bsp_tp_iic_write(cola_device_t *dev, int pos, const void *buffer, int size){
	(void)dev;
	(void)pos;
	return bsp_drv_tp_iic_write((uint8_t *)buffer,size,false)?size:0;
}

static struct cola_device_ops tp_iic_Ops ={
    .open   = bsp_tp_iic_open,
    .close  = bsp_tp_iic_close,
    .read   = bsp_tp_iic_read,
    .write  = bsp_tp_iic_write,
    .control= bsp_tp_iic_set_slave_address
};

static void bsp_tp_iic_configuration(void){
	g_tp_iic.name = "touch";
    g_tp_iic.dops = &tp_iic_Ops;
    cola_device_register(&g_tp_iic);
}
register_initcall(bsp_tp_iic_configuration);
