-static void i2c_stm32_start(struct I2c *i2c, uint16_t slave_addr)
-{
- i2c->hw->cached = false;
-
- if (I2C_TEST_START(i2c->flags) == I2C_START_W)
- {
- /*
- * Loop on the select write sequence: when the eeprom 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 eeprom responds with an ACK.
- */
- ticks_t start = timer_clock();
- while (true)
- {
- i2c->hw->base->CR1 |= CR1_ACK_SET | CR1_START_SET;
-
- if(!wait_event(i2c, I2C_EVENT_MASTER_MODE_SELECT))
- {
- LOG_ERR("ARBIT lost\n");
- i2c->errors |= I2C_ARB_LOST;
- break;
- }
-
- i2c->hw->base->DR = slave_addr & OAR1_ADD0_RESET;
-
- if(wait_event(i2c, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
- break;
-
- if (timer_clock() - start > ms_to_ticks(CONFIG_I2C_START_TIMEOUT))
- {
- LOG_ERR("Timeout on I2C START\n");
- i2c->errors |= I2C_START_TIMEOUT;
- i2c->hw->base->CR1 |= CR1_STOP_SET;
- break;
- }
- }