MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / i2c_bus_unlock

Function i2c_bus_unlock

components/drivers/i2c/dev_soft_i2c.c:207–227  ·  view source on GitHub ↗

* if i2c is locked, this function will unlock it * * @param i2c config class. * * @return RT_EOK indicates successful unlock. */

Source from the content-addressed store, hash-verified

205* @return RT_EOK indicates successful unlock.
206*/
207static rt_err_t i2c_bus_unlock(const struct soft_i2c_config *cfg)
208{
209 rt_ubase_t i = 0;
210
211 if(PIN_LOW == rt_pin_read(cfg->sda_pin))
212 {
213 while(i++ < 9)
214 {
215 rt_pin_write(cfg->scl_pin, PIN_HIGH);
216 rt_hw_us_delay(cfg->timing_delay);
217 rt_pin_write(cfg->scl_pin, PIN_LOW);
218 rt_hw_us_delay(cfg->timing_delay);
219 }
220 }
221 if(PIN_LOW == rt_pin_read(cfg->sda_pin))
222 {
223 return -RT_ERROR;
224 }
225
226 return RT_EOK;
227}
228
229/* I2C initialization function */
230int rt_soft_i2c_init(void)

Callers 1

rt_soft_i2c_initFunction · 0.85

Calls 3

rt_pin_readFunction · 0.50
rt_pin_writeFunction · 0.50
rt_hw_us_delayFunction · 0.50

Tested by

no test coverage detected