sdk:bsp: add i2c0 slave api

Signed-off-by: liangkangnan <liangkangnan@163.com>
pull/4/head
liangkangnan 2021-08-20 14:17:01 +08:00
parent 08492931fc
commit 9905a7c3a2
2 changed files with 132 additions and 89 deletions

View File

@ -32,6 +32,12 @@ void i2c0_clear_irq_pending();
uint8_t i2c0_get_irq_pending(); uint8_t i2c0_get_irq_pending();
void i2c0_master_set_info(uint8_t addr, uint8_t reg, uint8_t data); void i2c0_master_set_info(uint8_t addr, uint8_t reg, uint8_t data);
uint8_t i2c0_master_get_data(); uint8_t i2c0_master_get_data();
void i2c0_slave_set_address(uint8_t addr);
void i2c0_slave_set_ready(uint8_t yes);
uint8_t i2c0_slave_op_read();
uint32_t i2c0_slave_get_op_address();
uint32_t i2c0_slave_get_op_data();
void i2c0_slave_set_rsp_data(uint32_t data);
void i2c0_start(); void i2c0_start();
void i2c0_stop(); void i2c0_stop();

View File

@ -62,6 +62,43 @@ uint8_t i2c0_master_get_data()
return data; return data;
} }
void i2c0_slave_set_address(uint8_t addr)
{
I2C0_REG(I2C_CTRL_REG_OFFSET) &= ~(I2C_CTRL_SLAVE_ADDR_MASK << I2C_CTRL_SLAVE_ADDR_OFFSET);
I2C0_REG(I2C_CTRL_REG_OFFSET) |= addr << I2C_CTRL_SLAVE_ADDR_OFFSET;
}
void i2c0_slave_set_ready(uint8_t yes)
{
if (yes)
I2C0_REG(I2C_CTRL_REG_OFFSET) |= 1 << I2C_CTRL_SLAVE_RDY_BIT;
else
I2C0_REG(I2C_CTRL_REG_OFFSET) &= ~(1 << I2C_CTRL_SLAVE_RDY_BIT);
}
uint8_t i2c0_slave_op_read()
{
if (I2C0_REG(I2C_CTRL_REG_OFFSET) & (1 << I2C_CTRL_SLAVE_WR_BIT))
return 1;
else
return 0;
}
uint32_t i2c0_slave_get_op_address()
{
return (I2C0_REG(I2C_SLAVE_ADDR_REG_OFFSET));
}
uint32_t i2c0_slave_get_op_data()
{
return (I2C0_REG(I2C_SLAVE_WDATA_REG_OFFSET));
}
void i2c0_slave_set_rsp_data(uint32_t data)
{
I2C0_REG(I2C_SLAVE_RDATA_REG_OFFSET) = data;
}
void i2c0_start() void i2c0_start()
{ {
I2C0_REG(I2C_CTRL_REG_OFFSET) |= 1 << I2C_CTRL_START_BIT; I2C0_REG(I2C_CTRL_REG_OFFSET) |= 1 << I2C_CTRL_START_BIT;