优化模拟i2c时序逻辑,使模拟I2C时序更加接近设定的延迟时间 模拟I2C的IO翻转时间单位改为ns,使I2C通讯速率可调节度更准确

This commit is contained in:
2023-08-02 13:00:07 +08:00
parent ba913a7eaf
commit 4ca7e495ab
2 changed files with 12 additions and 9 deletions

View File

@ -25,12 +25,12 @@
rt_inline void i2c_delay(struct rt_i2c_bit_ops *ops)
{
ops->udelay((ops->delay_us + 1) >> 1);
ops->ndelay((ops->delay_ns + 1) >> 1);
}
rt_inline void i2c_delay2(struct rt_i2c_bit_ops *ops)
{
ops->udelay(ops->delay_us);
ops->ndelay(ops->delay_ns);
}
#define SDA_L(ops) SET_SDA(ops, 0)
@ -47,7 +47,10 @@ static rt_err_t SCL_H(struct rt_i2c_bit_ops *ops)
SET_SCL(ops, 1);
if (!ops->get_scl)
goto done;
{
i2c_delay(ops);
return RT_EOK;
}
start = rt_tick_get();
i2c_delay(ops);
@ -65,9 +68,6 @@ static rt_err_t SCL_H(struct rt_i2c_bit_ops *ops)
}
#endif
done:
i2c_delay(ops);
return RT_EOK;
}
@ -181,7 +181,7 @@ static rt_int32_t i2c_readb(struct rt_i2c_bus_device *bus)
if (GET_SDA(ops))
data |= 1;
SCL_L(ops);
i2c_delay2(ops);
i2c_delay(ops);
}
return data;