* if i2c is locked, this function will unlock it * * @param i2c config class. * * @return RT_EOK indicates successful unlock. */
| 205 | * @return RT_EOK indicates successful unlock. |
| 206 | */ |
| 207 | static 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 */ |
| 230 | int rt_soft_i2c_init(void) |
no test coverage detected