+ if (i2c->flags & I2C_START_R)
+ slave_addr |= I2C_READBIT;
+ else
+ slave_addr &= ~I2C_READBIT;
+
+ /*
+ * Loop on the select write sequence: when the device is busy
+ * writing previously sent data it will reply to the SLA_W
+ * control byte with a NACK. In this case, we must
+ * keep trying until the deveice responds with an ACK.
+ */
+ ticks_t start = timer_clock();
+ while (i2c_bitbang_start())
+ {
+ if (i2c_bitbang_put(slave_addr))
+ return;
+ else if (timer_clock() - start > ms_to_ticks(CONFIG_I2C_START_TIMEOUT))
+ {
+ LOG_ERR("Timeout on I2C start\n");
+ i2c->errors |= I2C_START_TIMEOUT;
+ i2c_bitbang_stop(i2c);
+ return;
+ }
+ }