Files
kunlun/driver/src/hw3/i2c_slv_hw.c

220 lines
4.8 KiB
C
Raw Normal View History

2024-09-28 14:24:04 +08:00
/****************************************************************************
*
* Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
*
* This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
* be copied by any method or incorporated into another program without
* the express written consent of Aerospace C.Power. This Information or any portion
* thereof remains the property of Aerospace C.Power. The Information contained herein
* is believed to be accurate and Aerospace C.Power assumes no responsibility or
* liability for its use in any way and conveys no license or title under
* any patent or copyright and makes no representation or warranty that this
* Information is free from patent or copyright infringement.
*
* ****************************************************************************/
#include "os_types.h"
#include "i2c_slv_hw.h"
uint32_t i2c_s_get_fifo_st(uint8_t port)
{
return 0;
}
uint8_t i2c_s_rece_1st_byte(uint8_t port)
{
return 0;
}
void i2c_s_clear_st(uint8_t port, uint8_t st)
{
}
uint32_t i2c_s_get_st(uint8_t port)
{
return 0;
}
uint8_t i2c_s_fifo_read_byte(uint8_t port)
{
return 0;
}
void i2c_s_write_byte(uint8_t port, uint8_t value)
{
}
#if 0
#include "iot_errno.h"
#include "apb_glb_reg.h"
#include "hw_reg_api.h"
#include "i2c_slave_reg.h"
#include "iot_io.h"
#include "iot_i2c_api.h"
#include "gpio_mtx.h"
#include "i2c_reg.h"
#include "apb.h"
uint8_t i2c_s_gpio_sel(uint8_t port, uint8_t scl, uint8_t sda)
{
if(I2C_S_INVALID(port))
return ERR_FAIL;
gpio_mtx_enable();
uint8_t scl_func = 0;
uint8_t sda_func = 0;
scl_func = gpio_pin_func_get(scl);
sda_func = gpio_pin_func_get(sda);
gpio_sig_info_t info = {0};
if (port == IOT_I2C_S_PORT_0) {
info.sig_type = 2;
info.CFG[0].type = IO_TYPE_IN;
info.CFG[0].func = scl_func;
info.CFG[0].gpio = scl;
info.CFG[0].inid = 99;
info.CFG[0].outid = 0xff;
info.CFG[1].type = IO_TYPE_IO;
info.CFG[1].func = sda_func;
info.CFG[1].gpio = sda;
info.CFG[1].inid = 100;
info.CFG[1].outid = 151;
}
gpio_module_pin_select(&info);
gpio_module_sig_select(&info, GPIO_MTX_MODE_MATRIX);
return ERR_OK;
}
uint8_t i2c_s_port_enable(uint8_t port)
{
if (port == IOT_I2C_S_PORT_0) {
apb_enable(APB_I2C0_S);
}else {
return ERR_FAIL;
}
return ERR_OK;
}
uint8_t i2c_s_fifo_full(uint8_t port)
{
uint32_t tmp = I2C_S_PORT_READ_REG(port, CFG_I2C_SLAVE_FIFO_STATUS_ADDR);
return REG_FIELD_GET(FIFO_FULL, tmp);
}
uint8_t i2c_s_fifo_empty(uint8_t port)
{
uint32_t tmp = I2C_S_PORT_READ_REG(port, CFG_I2C_SLAVE_FIFO_STATUS_ADDR);
return REG_FIELD_GET(FIFO_EMP, tmp);
}
void i2c_s_set_dev_addr(uint8_t port, uint8_t addr)
{
uint32_t tmp;
tmp = I2C_S_PORT_READ_REG(port, CFG_I2C_SLAVE_CTRL0_ADDR);
REG_FIELD_SET(I2C_DEV_ADDR, tmp, addr);
I2C_S_PORT_WRITE_REG(port, CFG_I2C_SLAVE_CTRL0_ADDR, tmp);
}
void i2c_s_ena(uint8_t port)
{
uint32_t tmp;
tmp = I2C_S_PORT_READ_REG(port, CFG_I2C_SLAVE_CTRL0_ADDR);
REG_FIELD_SET(I2C_FSM_EB, tmp, 1);
I2C_S_PORT_WRITE_REG(port, CFG_I2C_SLAVE_CTRL0_ADDR, tmp);
}
void i2c_s_reset(uint8_t port)
{
uint32_t tmp;
tmp = I2C_S_PORT_READ_REG(port, CFG_I2C_SLAVE_CTRL1_ADDR);
REG_FIELD_SET(I2C_FSM_RST, tmp, 1);
I2C_S_PORT_WRITE_REG(port, CFG_I2C_SLAVE_CTRL1_ADDR, tmp);
tmp = I2C_S_PORT_READ_REG(port, CFG_I2C_SLAVE_CTRL1_ADDR);
REG_FIELD_SET(I2C_FSM_RST, tmp, 0);
I2C_S_PORT_WRITE_REG(port, CFG_I2C_SLAVE_CTRL1_ADDR, tmp);
}
void i2c_s_set_drive(uint8_t port, uint8_t drive)
{
uint32_t tmp;
tmp = I2C_S_PORT_READ_REG(port, CFG_I2C_SLAVE_CTRL1_ADDR);
REG_FIELD_SET(I2C_FORCE_DRIVE_SDA, tmp, drive);
I2C_S_PORT_WRITE_REG(port, CFG_I2C_SLAVE_CTRL1_ADDR, tmp);
}
uint8_t i2c_s_get_data_num(uint8_t port)
{
uint32_t tmp;
tmp = I2C_S_PORT_READ_REG(port, CFG_I2C_SLAVE_FIFO_STATUS_ADDR);
return REG_FIELD_GET(FIFO_DATA_NUM, tmp);
}
void i2c_s_set_write_en(uint8_t port)
{
uint32_t tmp;
tmp = I2C_S_PORT_READ_REG(port, CFG_I2C_S_FIFO_RD_ADDR);
REG_FIELD_SET(FIFO_RD_WE, tmp, 1);
I2C_S_PORT_WRITE_REG(port, CFG_I2C_S_FIFO_RD_ADDR, tmp);
}
#endif
uint8_t i2c_s_gpio_sel(uint8_t port, uint8_t scl, uint8_t sda)
{
return 0;
}
uint8_t i2c_s_port_enable(uint8_t port)
{
return 0;
}
uint8_t i2c_s_fifo_full(uint8_t port)
{
return 0;
}
uint8_t i2c_s_fifo_empty(uint8_t port)
{
return 0;
}
void i2c_s_set_dev_addr(uint8_t port, uint8_t addr)
{
}
void i2c_s_ena(uint8_t port)
{
}
void i2c_s_reset(uint8_t port)
{
}
void i2c_s_set_drive(uint8_t port, uint8_t drive)
{
}
uint8_t i2c_s_get_data_num(uint8_t port)
{
return 0;
}
void i2c_s_set_write_en(uint8_t port)
{
}