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

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


#include "drv_master_iic.h"

static cola_device_t g_master_iic;

static int bsp_iic_open(cola_device_t *dev, int oflag){
	(void)dev;
	(void)oflag;
	bsp_drv_master_iic_init();
    return 0;
}

static int bsp_iic_close(cola_device_t *dev){
	(void)dev;
	bsp_drv_master_iic_deinit();
    return 0;
}

static int bsp_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_iic_read(cola_device_t *dev, int pos, void *buffer, int size){
	(void)dev;
	(void)pos;
	return bsp_drv_master_iic_read((uint8_t *)buffer,size,true)?size:0;
}

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

static struct cola_device_ops master_iic_Ops ={
    .open   = bsp_iic_open,
    .close  = bsp_iic_close,
    .read   = bsp_iic_read,
    .write  = bsp_iic_write,
    .control= bsp_iic_set_slave_address
};

static void bsp_iic_configuration(void){
	g_master_iic.name = "MASTER_IIC";
    g_master_iic.dops = &master_iic_Ops;
    cola_device_register(&g_master_iic);
}
register_initcall(bsp_iic_configuration);
