/*
 * bsp_PMIC.c
 *
 *  Created on: 2025年4月9日
 *      Author: 22332
 */
#include "../bsp/drv_master_iic.h"
#include "cola_init.h"
#include "cola_device.h"
#include "bsp_register_map.h"

static cola_device_t g_pmic_iic;

static uint16_t slave_address = PMIC_Slave_Address;


static int bsp_iic_pmic_write(cola_device_t *dev, int pos, const void *buffer, int size){
	int bACK = 0;
	uint8_t *data = (uint8_t *)buffer;
	uint8_t buf[8];
	if(size > 7)
		size = 7;
	buf[0] = (uint8_t)pos;
	for(int i=0; i<size; i++)
		buf[1+i] = (uint8_t)data[i];
	bACK = bsp_ctrl_write_register(slave_address,buf,1+size);
	return bACK;
}

static int  bsp_iic_pmic_read(cola_device_t *dev, int pos, void *buffer, int size){
	return bsp_ctrl_read_register(slave_address,pos,buffer,size);
}


static struct cola_device_ops PMIC_iic_Ops ={
    .read   = bsp_iic_pmic_read,
    .write  = bsp_iic_pmic_write,
};

static void bsp_PMIC_iic_configuration(void){
    g_pmic_iic.name = "PMIC_IIC";
    g_pmic_iic.dops = &PMIC_iic_Ops;
    cola_device_register(&g_pmic_iic);
}
register_initcall(bsp_PMIC_iic_configuration);

