/***********************************************************************
 * Copyright (c)  2017 - 2023, Unicmicro Co.,Ltd .
 * All rights reserved.
 * Filename    : um_i2c.h
 * Description : um i2c header file
 * Author(s)   : MCU Team
 * version     : V1.0
 * Modify date : 2023-06-13
 ***********************************************************************/
#ifndef __UM_I2C_H__
#define __UM_I2C_H__

#include "um321xA.h"
#include "gpio.h"

#define I2C_SDA_0		((*(volatile uint32_t *)(0x40004C0C)) |= (1U << PIN3))
#define I2C_SDA_1		((*(volatile uint32_t *)(0x40004C08)) |= (1U << PIN3))
#define I2C_SDA_IN		((*(volatile uint32_t *)(0x40004C00)) &= ~(1U << PIN3))
#define I2C_SDA_OUT		((*(volatile uint32_t *)(0x40004C00)) |= (1U << PIN3))
#define I2C_SDA_READ	(((*(volatile uint32_t *)(0x40004C14)) >> PIN3) & 0x01)
	
#define I2C_SCL_0		((*(volatile uint32_t *)(0x4000440C)) |= (1U << PIN7))
#define I2C_SCL_1		((*(volatile uint32_t *)(0x40004408)) |= (1U << PIN7))


void i2c_init(void);

void i2c_delay(void);

void i2c_start(void);

void i2c_stop(void);

void i2c_ack(void);

void i2c_noack(void);

uint8_t i2c_wait_ack(void);

void i2c_write_byte(uint8_t data);

uint8_t i2c_read_byte(void);

uint16_t i2c_write_buff(uint8_t dev_addr,uint8_t rom_addr,uint8_t *buff,uint16_t len);

uint16_t i2c_read_buff(uint8_t dev_addr,uint8_t rom_addr,uint8_t *buff,uint16_t len);

uint8_t i2c_master_send_command(uint8_t slave_addr, uint8_t memory_addr, uint8_t data);

uint8_t i2c_master_recv_command(uint8_t slave_addr, uint8_t memory_addr, uint8_t *data);

#endif
