优化模拟i2c时序逻辑,使模拟I2C时序更加接近设定的延迟时间 模拟I2C的IO翻转时间单位改为ns,使I2C通讯速率可调节度更准确
This commit is contained in:
@ -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;
|
||||
|
@ -11,6 +11,9 @@
|
||||
#ifndef __I2C_BIT_OPS_H__
|
||||
#define __I2C_BIT_OPS_H__
|
||||
|
||||
#include <rtdef.h>
|
||||
#include <rtdevice.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@ -23,9 +26,9 @@ struct rt_i2c_bit_ops
|
||||
rt_int32_t (*get_sda)(void *data);
|
||||
rt_int32_t (*get_scl)(void *data);
|
||||
|
||||
void (*udelay)(rt_uint32_t us);
|
||||
void (*ndelay)(rt_uint32_t us);
|
||||
|
||||
rt_uint32_t delay_us; /* scl and sda line delay */
|
||||
rt_uint32_t delay_ns; /* scl and sda line delay */
|
||||
rt_uint32_t timeout; /* in tick */
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user