Lines Matching +full:i2c +full:- +full:speed

5  * SPDX-License-Identifier: Apache-2.0
7 * I2C Driver for: STM32F0, STM32F3, STM32F7, STM32L0, STM32L4, STM32WB and
19 #include <zephyr/drivers/i2c.h>
28 #include "i2c-priv.h"
33 /* Use the algorithm to calcuate the I2C timing */
124 const struct i2c_stm32_config *cfg = dev->config; in msg_init()
125 struct i2c_stm32_data *data = dev->data; in msg_init()
126 I2C_TypeDef *i2c = cfg->i2c; in msg_init() local
128 if (LL_I2C_IsEnabledReloadMode(i2c)) { in msg_init()
129 LL_I2C_SetTransferSize(i2c, msg->len); in msg_init()
131 if (I2C_ADDR_10_BITS & data->dev_config) { in msg_init()
132 LL_I2C_SetMasterAddressingMode(i2c, in msg_init()
134 LL_I2C_SetSlaveAddr(i2c, (uint32_t) slave); in msg_init()
136 LL_I2C_SetMasterAddressingMode(i2c, in msg_init()
138 LL_I2C_SetSlaveAddr(i2c, (uint32_t) slave << 1); in msg_init()
141 if (!(msg->flags & I2C_MSG_STOP) && next_msg_flags && in msg_init()
143 LL_I2C_EnableReloadMode(i2c); in msg_init()
145 LL_I2C_DisableReloadMode(i2c); in msg_init()
147 LL_I2C_DisableAutoEndMode(i2c); in msg_init()
148 LL_I2C_SetTransferRequest(i2c, transfer); in msg_init()
149 LL_I2C_SetTransferSize(i2c, msg->len); in msg_init()
152 data->master_active = true; in msg_init()
154 LL_I2C_Enable(i2c); in msg_init()
156 LL_I2C_GenerateStartCondition(i2c); in msg_init()
164 const struct i2c_stm32_config *cfg = dev->config; in stm32_i2c_disable_transfer_interrupts()
165 struct i2c_stm32_data *data = dev->data; in stm32_i2c_disable_transfer_interrupts()
166 I2C_TypeDef *i2c = cfg->i2c; in stm32_i2c_disable_transfer_interrupts() local
168 LL_I2C_DisableIT_TX(i2c); in stm32_i2c_disable_transfer_interrupts()
169 LL_I2C_DisableIT_RX(i2c); in stm32_i2c_disable_transfer_interrupts()
170 LL_I2C_DisableIT_STOP(i2c); in stm32_i2c_disable_transfer_interrupts()
171 LL_I2C_DisableIT_NACK(i2c); in stm32_i2c_disable_transfer_interrupts()
172 LL_I2C_DisableIT_TC(i2c); in stm32_i2c_disable_transfer_interrupts()
174 if (!data->smbalert_active) { in stm32_i2c_disable_transfer_interrupts()
175 LL_I2C_DisableIT_ERR(i2c); in stm32_i2c_disable_transfer_interrupts()
181 const struct i2c_stm32_config *cfg = dev->config; in stm32_i2c_enable_transfer_interrupts()
182 I2C_TypeDef *i2c = cfg->i2c; in stm32_i2c_enable_transfer_interrupts() local
184 LL_I2C_EnableIT_STOP(i2c); in stm32_i2c_enable_transfer_interrupts()
185 LL_I2C_EnableIT_NACK(i2c); in stm32_i2c_enable_transfer_interrupts()
186 LL_I2C_EnableIT_TC(i2c); in stm32_i2c_enable_transfer_interrupts()
187 LL_I2C_EnableIT_ERR(i2c); in stm32_i2c_enable_transfer_interrupts()
192 const struct i2c_stm32_config *cfg = dev->config; in stm32_i2c_master_mode_end()
193 struct i2c_stm32_data *data = dev->data; in stm32_i2c_master_mode_end()
194 I2C_TypeDef *i2c = cfg->i2c; in stm32_i2c_master_mode_end() local
198 if (LL_I2C_IsEnabledReloadMode(i2c)) { in stm32_i2c_master_mode_end()
199 LL_I2C_DisableReloadMode(i2c); in stm32_i2c_master_mode_end()
203 data->master_active = false; in stm32_i2c_master_mode_end()
204 if (!data->slave_attached && !data->smbalert_active) { in stm32_i2c_master_mode_end()
205 LL_I2C_Disable(i2c); in stm32_i2c_master_mode_end()
208 if (!data->smbalert_active) { in stm32_i2c_master_mode_end()
209 LL_I2C_Disable(i2c); in stm32_i2c_master_mode_end()
212 k_sem_give(&data->device_sync_sem); in stm32_i2c_master_mode_end()
218 const struct i2c_stm32_config *cfg = dev->config; in stm32_i2c_slave_event()
219 struct i2c_stm32_data *data = dev->data; in stm32_i2c_slave_event()
220 I2C_TypeDef *i2c = cfg->i2c; in stm32_i2c_slave_event() local
224 if (data->slave_cfg->flags != I2C_TARGET_FLAGS_ADDR_10_BITS) { in stm32_i2c_slave_event()
228 slave_address = LL_I2C_GetAddressMatchCode(i2c) >> 1; in stm32_i2c_slave_event()
229 if (data->slave_cfg != NULL && in stm32_i2c_slave_event()
230 slave_address == data->slave_cfg->address) { in stm32_i2c_slave_event()
231 slave_cfg = data->slave_cfg; in stm32_i2c_slave_event()
232 } else if (data->slave2_cfg != NULL && in stm32_i2c_slave_event()
233 slave_address == data->slave2_cfg->address) { in stm32_i2c_slave_event()
234 slave_cfg = data->slave2_cfg; in stm32_i2c_slave_event()
244 if (data->slave_cfg != NULL) { in stm32_i2c_slave_event()
245 slave_cfg = data->slave_cfg; in stm32_i2c_slave_event()
252 slave_cb = slave_cfg->callbacks; in stm32_i2c_slave_event()
254 if (LL_I2C_IsActiveFlag_TXIS(i2c)) { in stm32_i2c_slave_event()
257 if (slave_cb->read_processed(slave_cfg, &val) < 0) { in stm32_i2c_slave_event()
260 LL_I2C_TransmitData8(i2c, val); in stm32_i2c_slave_event()
265 if (LL_I2C_IsActiveFlag_RXNE(i2c)) { in stm32_i2c_slave_event()
266 uint8_t val = LL_I2C_ReceiveData8(i2c); in stm32_i2c_slave_event()
268 if (slave_cb->write_received(slave_cfg, val)) { in stm32_i2c_slave_event()
269 LL_I2C_AcknowledgeNextData(i2c, LL_I2C_NACK); in stm32_i2c_slave_event()
274 if (LL_I2C_IsActiveFlag_NACK(i2c)) { in stm32_i2c_slave_event()
275 LL_I2C_ClearFlag_NACK(i2c); in stm32_i2c_slave_event()
278 if (LL_I2C_IsActiveFlag_STOP(i2c)) { in stm32_i2c_slave_event()
282 LL_I2C_ClearFlag_TXE(i2c); in stm32_i2c_slave_event()
284 LL_I2C_ClearFlag_STOP(i2c); in stm32_i2c_slave_event()
286 slave_cb->stop(slave_cfg); in stm32_i2c_slave_event()
289 LL_I2C_AcknowledgeNextData(i2c, LL_I2C_ACK); in stm32_i2c_slave_event()
292 if (LL_I2C_IsActiveFlag_ADDR(i2c)) { in stm32_i2c_slave_event()
295 LL_I2C_ClearFlag_ADDR(i2c); in stm32_i2c_slave_event()
297 dir = LL_I2C_GetTransferDirection(i2c); in stm32_i2c_slave_event()
299 if (slave_cb->write_requested(slave_cfg) < 0) { in stm32_i2c_slave_event()
302 LL_I2C_EnableIT_RX(i2c); in stm32_i2c_slave_event()
307 if (slave_cb->read_requested(slave_cfg, &val) < 0) { in stm32_i2c_slave_event()
310 LL_I2C_TransmitData8(i2c, val); in stm32_i2c_slave_event()
311 LL_I2C_EnableIT_TX(i2c); in stm32_i2c_slave_event()
319 /* Attach and start I2C as target */
323 const struct i2c_stm32_config *cfg = dev->config; in i2c_stm32_target_register()
324 struct i2c_stm32_data *data = dev->data; in i2c_stm32_target_register()
325 I2C_TypeDef *i2c = cfg->i2c; in i2c_stm32_target_register() local
330 return -EINVAL; in i2c_stm32_target_register()
333 if (data->slave_cfg && data->slave2_cfg) { in i2c_stm32_target_register()
334 return -EBUSY; in i2c_stm32_target_register()
337 if (data->master_active) { in i2c_stm32_target_register()
338 return -EBUSY; in i2c_stm32_target_register()
341 bitrate_cfg = i2c_map_dt_bitrate(cfg->bitrate); in i2c_stm32_target_register()
345 LOG_ERR("i2c: failure initializing"); in i2c_stm32_target_register()
353 /* Enable wake-up from stop */ in i2c_stm32_target_register()
354 LOG_DBG("i2c: enabling wakeup from stop"); in i2c_stm32_target_register()
355 LL_I2C_EnableWakeUpFromStop(cfg->i2c); in i2c_stm32_target_register()
359 LL_I2C_Enable(i2c); in i2c_stm32_target_register()
361 if (!data->slave_cfg) { in i2c_stm32_target_register()
362 data->slave_cfg = config; in i2c_stm32_target_register()
363 if (data->slave_cfg->flags == I2C_TARGET_FLAGS_ADDR_10_BITS) { in i2c_stm32_target_register()
364 LL_I2C_SetOwnAddress1(i2c, config->address, LL_I2C_OWNADDRESS1_10BIT); in i2c_stm32_target_register()
365 LOG_DBG("i2c: target #1 registered with 10-bit address"); in i2c_stm32_target_register()
367 LL_I2C_SetOwnAddress1(i2c, config->address << 1U, LL_I2C_OWNADDRESS1_7BIT); in i2c_stm32_target_register()
368 LOG_DBG("i2c: target #1 registered with 7-bit address"); in i2c_stm32_target_register()
371 LL_I2C_EnableOwnAddress1(i2c); in i2c_stm32_target_register()
373 LOG_DBG("i2c: target #1 registered"); in i2c_stm32_target_register()
375 data->slave2_cfg = config; in i2c_stm32_target_register()
377 if (data->slave2_cfg->flags == I2C_TARGET_FLAGS_ADDR_10_BITS) { in i2c_stm32_target_register()
378 return -EINVAL; in i2c_stm32_target_register()
380 LL_I2C_SetOwnAddress2(i2c, config->address << 1U, in i2c_stm32_target_register()
382 LL_I2C_EnableOwnAddress2(i2c); in i2c_stm32_target_register()
383 LOG_DBG("i2c: target #2 registered"); in i2c_stm32_target_register()
386 data->slave_attached = true; in i2c_stm32_target_register()
388 LL_I2C_EnableIT_ADDR(i2c); in i2c_stm32_target_register()
396 const struct i2c_stm32_config *cfg = dev->config; in i2c_stm32_target_unregister()
397 struct i2c_stm32_data *data = dev->data; in i2c_stm32_target_unregister()
398 I2C_TypeDef *i2c = cfg->i2c; in i2c_stm32_target_unregister() local
400 if (!data->slave_attached) { in i2c_stm32_target_unregister()
401 return -EINVAL; in i2c_stm32_target_unregister()
404 if (data->master_active) { in i2c_stm32_target_unregister()
405 return -EBUSY; in i2c_stm32_target_unregister()
408 if (config == data->slave_cfg) { in i2c_stm32_target_unregister()
409 LL_I2C_DisableOwnAddress1(i2c); in i2c_stm32_target_unregister()
410 data->slave_cfg = NULL; in i2c_stm32_target_unregister()
412 LOG_DBG("i2c: slave #1 unregistered"); in i2c_stm32_target_unregister()
413 } else if (config == data->slave2_cfg) { in i2c_stm32_target_unregister()
414 LL_I2C_DisableOwnAddress2(i2c); in i2c_stm32_target_unregister()
415 data->slave2_cfg = NULL; in i2c_stm32_target_unregister()
417 LOG_DBG("i2c: slave #2 unregistered"); in i2c_stm32_target_unregister()
419 return -EINVAL; in i2c_stm32_target_unregister()
423 if (data->slave_cfg || data->slave2_cfg) { in i2c_stm32_target_unregister()
424 LOG_DBG("i2c: target#%c still registered", data->slave_cfg?'1':'2'); in i2c_stm32_target_unregister()
428 /* Otherwise disable I2C */ in i2c_stm32_target_unregister()
429 LL_I2C_DisableIT_ADDR(i2c); in i2c_stm32_target_unregister()
432 LL_I2C_ClearFlag_NACK(i2c); in i2c_stm32_target_unregister()
433 LL_I2C_ClearFlag_STOP(i2c); in i2c_stm32_target_unregister()
434 LL_I2C_ClearFlag_ADDR(i2c); in i2c_stm32_target_unregister()
436 if (!data->smbalert_active) { in i2c_stm32_target_unregister()
437 LL_I2C_Disable(i2c); in i2c_stm32_target_unregister()
442 /* Disable wake-up from STOP */ in i2c_stm32_target_unregister()
443 LOG_DBG("i2c: disabling wakeup from stop"); in i2c_stm32_target_unregister()
444 LL_I2C_DisableWakeUpFromStop(i2c); in i2c_stm32_target_unregister()
450 data->slave_attached = false; in i2c_stm32_target_unregister()
459 const struct i2c_stm32_config *cfg = dev->config; in stm32_i2c_event()
460 struct i2c_stm32_data *data = dev->data; in stm32_i2c_event()
461 I2C_TypeDef *i2c = cfg->i2c; in stm32_i2c_event() local
464 if (data->slave_attached && !data->master_active) { in stm32_i2c_event()
469 if (data->current.len) { in stm32_i2c_event()
471 if (LL_I2C_IsActiveFlag_TXIS(i2c)) { in stm32_i2c_event()
472 LL_I2C_TransmitData8(i2c, *data->current.buf); in stm32_i2c_event()
476 if (LL_I2C_IsActiveFlag_RXNE(i2c)) { in stm32_i2c_event()
477 *data->current.buf = LL_I2C_ReceiveData8(i2c); in stm32_i2c_event()
480 data->current.buf++; in stm32_i2c_event()
481 data->current.len--; in stm32_i2c_event()
485 if (LL_I2C_IsActiveFlag_NACK(i2c)) { in stm32_i2c_event()
486 LL_I2C_ClearFlag_NACK(i2c); in stm32_i2c_event()
487 data->current.is_nack = 1U; in stm32_i2c_event()
492 LL_I2C_GenerateStopCondition(i2c); in stm32_i2c_event()
497 if (LL_I2C_IsActiveFlag_STOP(i2c)) { in stm32_i2c_event()
498 LL_I2C_ClearFlag_STOP(i2c); in stm32_i2c_event()
499 LL_I2C_DisableReloadMode(i2c); in stm32_i2c_event()
504 if (LL_I2C_IsActiveFlag_TC(i2c) || in stm32_i2c_event()
505 LL_I2C_IsActiveFlag_TCR(i2c)) { in stm32_i2c_event()
507 if (data->current.msg->flags & I2C_MSG_STOP) { in stm32_i2c_event()
508 LL_I2C_GenerateStopCondition(i2c); in stm32_i2c_event()
511 k_sem_give(&data->device_sync_sem); in stm32_i2c_event()
522 const struct i2c_stm32_config *cfg = dev->config; in stm32_i2c_error()
523 struct i2c_stm32_data *data = dev->data; in stm32_i2c_error()
524 I2C_TypeDef *i2c = cfg->i2c; in stm32_i2c_error() local
527 if (data->slave_attached && !data->master_active) { in stm32_i2c_error()
533 if (LL_I2C_IsActiveFlag_ARLO(i2c)) { in stm32_i2c_error()
534 LL_I2C_ClearFlag_ARLO(i2c); in stm32_i2c_error()
535 data->current.is_arlo = 1U; in stm32_i2c_error()
539 if (LL_I2C_IsActiveFlag_BERR(i2c)) { in stm32_i2c_error()
540 LL_I2C_ClearFlag_BERR(i2c); in stm32_i2c_error()
541 data->current.is_err = 1U; in stm32_i2c_error()
546 if (LL_I2C_IsActiveSMBusFlag_ALERT(i2c)) { in stm32_i2c_error()
547 LL_I2C_ClearSMBusFlag_ALERT(i2c); in stm32_i2c_error()
548 if (data->smbalert_cb_func != NULL) { in stm32_i2c_error()
549 data->smbalert_cb_func(data->smbalert_cb_dev); in stm32_i2c_error()
558 return -EIO; in stm32_i2c_error()
591 const struct i2c_stm32_config *cfg = dev->config; in stm32_i2c_msg_write()
592 struct i2c_stm32_data *data = dev->data; in stm32_i2c_msg_write()
593 I2C_TypeDef *i2c = cfg->i2c; in stm32_i2c_msg_write() local
596 data->current.len = msg->len; in stm32_i2c_msg_write()
597 data->current.buf = msg->buf; in stm32_i2c_msg_write()
598 data->current.is_write = 1U; in stm32_i2c_msg_write()
599 data->current.is_nack = 0U; in stm32_i2c_msg_write()
600 data->current.is_err = 0U; in stm32_i2c_msg_write()
601 data->current.msg = msg; in stm32_i2c_msg_write()
606 LL_I2C_EnableIT_TX(i2c); in stm32_i2c_msg_write()
608 if (k_sem_take(&data->device_sync_sem, in stm32_i2c_msg_write()
611 k_sem_take(&data->device_sync_sem, K_FOREVER); in stm32_i2c_msg_write()
615 if (data->current.is_nack || data->current.is_err || in stm32_i2c_msg_write()
616 data->current.is_arlo || is_timeout) { in stm32_i2c_msg_write()
622 if (data->current.is_arlo) { in stm32_i2c_msg_write()
624 data->current.is_arlo); in stm32_i2c_msg_write()
625 data->current.is_arlo = 0U; in stm32_i2c_msg_write()
628 if (data->current.is_nack) { in stm32_i2c_msg_write()
630 data->current.is_nack = 0U; in stm32_i2c_msg_write()
633 if (data->current.is_err) { in stm32_i2c_msg_write()
635 data->current.is_err); in stm32_i2c_msg_write()
636 data->current.is_err = 0U; in stm32_i2c_msg_write()
643 return -EIO; in stm32_i2c_msg_write()
649 const struct i2c_stm32_config *cfg = dev->config; in stm32_i2c_msg_read()
650 struct i2c_stm32_data *data = dev->data; in stm32_i2c_msg_read()
651 I2C_TypeDef *i2c = cfg->i2c; in stm32_i2c_msg_read() local
654 data->current.len = msg->len; in stm32_i2c_msg_read()
655 data->current.buf = msg->buf; in stm32_i2c_msg_read()
656 data->current.is_write = 0U; in stm32_i2c_msg_read()
657 data->current.is_arlo = 0U; in stm32_i2c_msg_read()
658 data->current.is_err = 0U; in stm32_i2c_msg_read()
659 data->current.is_nack = 0U; in stm32_i2c_msg_read()
660 data->current.msg = msg; in stm32_i2c_msg_read()
665 LL_I2C_EnableIT_RX(i2c); in stm32_i2c_msg_read()
667 if (k_sem_take(&data->device_sync_sem, in stm32_i2c_msg_read()
670 k_sem_take(&data->device_sync_sem, K_FOREVER); in stm32_i2c_msg_read()
674 if (data->current.is_nack || data->current.is_err || in stm32_i2c_msg_read()
675 data->current.is_arlo || is_timeout) { in stm32_i2c_msg_read()
681 if (data->current.is_arlo) { in stm32_i2c_msg_read()
683 data->current.is_arlo); in stm32_i2c_msg_read()
684 data->current.is_arlo = 0U; in stm32_i2c_msg_read()
687 if (data->current.is_nack) { in stm32_i2c_msg_read()
689 data->current.is_nack = 0U; in stm32_i2c_msg_read()
692 if (data->current.is_err) { in stm32_i2c_msg_read()
694 data->current.is_err); in stm32_i2c_msg_read()
695 data->current.is_err = 0U; in stm32_i2c_msg_read()
702 return -EIO; in stm32_i2c_msg_read()
708 const struct i2c_stm32_config *cfg = dev->config; in check_errors()
709 I2C_TypeDef *i2c = cfg->i2c; in check_errors() local
711 if (LL_I2C_IsActiveFlag_NACK(i2c)) { in check_errors()
712 LL_I2C_ClearFlag_NACK(i2c); in check_errors()
717 if (LL_I2C_IsActiveFlag_ARLO(i2c)) { in check_errors()
718 LL_I2C_ClearFlag_ARLO(i2c); in check_errors()
723 if (LL_I2C_IsActiveFlag_OVR(i2c)) { in check_errors()
724 LL_I2C_ClearFlag_OVR(i2c); in check_errors()
729 if (LL_I2C_IsActiveFlag_BERR(i2c)) { in check_errors()
730 LL_I2C_ClearFlag_BERR(i2c); in check_errors()
737 if (LL_I2C_IsEnabledReloadMode(i2c)) { in check_errors()
738 LL_I2C_DisableReloadMode(i2c); in check_errors()
740 return -EIO; in check_errors()
746 const struct i2c_stm32_config *cfg = dev->config; in msg_done()
747 I2C_TypeDef *i2c = cfg->i2c; in msg_done() local
750 while (!LL_I2C_IsActiveFlag_TC(i2c) && !LL_I2C_IsActiveFlag_TCR(i2c)) { in msg_done()
752 return -EIO; in msg_done()
757 LL_I2C_GenerateStopCondition(i2c); in msg_done()
758 while (!LL_I2C_IsActiveFlag_STOP(i2c)) { in msg_done()
761 LL_I2C_ClearFlag_STOP(i2c); in msg_done()
762 LL_I2C_DisableReloadMode(i2c); in msg_done()
771 const struct i2c_stm32_config *cfg = dev->config; in stm32_i2c_msg_write()
772 I2C_TypeDef *i2c = cfg->i2c; in stm32_i2c_msg_write() local
774 uint8_t *buf = msg->buf; in stm32_i2c_msg_write()
778 len = msg->len; in stm32_i2c_msg_write()
781 if (LL_I2C_IsActiveFlag_TXIS(i2c)) { in stm32_i2c_msg_write()
786 return -EIO; in stm32_i2c_msg_write()
790 LL_I2C_TransmitData8(i2c, *buf); in stm32_i2c_msg_write()
792 len--; in stm32_i2c_msg_write()
795 return msg_done(dev, msg->flags); in stm32_i2c_msg_write()
801 const struct i2c_stm32_config *cfg = dev->config; in stm32_i2c_msg_read()
802 I2C_TypeDef *i2c = cfg->i2c; in stm32_i2c_msg_read() local
804 uint8_t *buf = msg->buf; in stm32_i2c_msg_read()
808 len = msg->len; in stm32_i2c_msg_read()
810 while (!LL_I2C_IsActiveFlag_RXNE(i2c)) { in stm32_i2c_msg_read()
812 return -EIO; in stm32_i2c_msg_read()
816 *buf = LL_I2C_ReceiveData8(i2c); in stm32_i2c_msg_read()
818 len--; in stm32_i2c_msg_read()
821 return msg_done(dev, msg->flags); in stm32_i2c_msg_read()
828 * "DEEP_INDENTATION: Too many leading tabs - consider code refactoring
837 int32_t error = (int32_t)tscl - (int32_t)ti2cspeed; \
840 error = -error; \
853 * @param clock_src_freq I2C source clock in Hz.
854 * @param i2c_speed I2C frequency (index).
895 * tI2CCLK < (tLOW - tfilters) / 4 and tI2CCLK < tHIGH in i2c_compute_scll_sclh()
898 (ti2cclk < ((tscl_l - tafdel_min - dnf_delay) / 4U))) { in i2c_compute_scll_sclh()
924 * "DEEP_INDENTATION: Too many leading tabs - consider code refactoring
946 * @param clock_src_freq I2C source clock in Hz.
947 * @param i2c_speed I2C frequency (index).
968 * SDADEL >= {tf +tHD;DAT(min) - tAF(min) - tDNF - [3 x tI2CCLK]} / {tPRESC} in i2c_compute_presc_scldel_sdadel()
969 * SDADEL <= {tVD;DAT(max) - tr - tAF(max) - tDNF- [4 x tI2CCLK]} / {tPRESC} in i2c_compute_presc_scldel_sdadel()
972 (int32_t)stm32_i2c_charac[i2c_speed].hddat_min - in i2c_compute_presc_scldel_sdadel()
973 (int32_t)tafdel_min - in i2c_compute_presc_scldel_sdadel()
977 tsdadel_max = (int32_t)stm32_i2c_charac[i2c_speed].vddat_max - in i2c_compute_presc_scldel_sdadel()
978 (int32_t)stm32_i2c_charac[i2c_speed].trise - in i2c_compute_presc_scldel_sdadel()
979 (int32_t)tafdel_max - in i2c_compute_presc_scldel_sdadel()
983 /* {[tr+ tSU;DAT(min)] / [tPRESC]} - 1 <= SCLDEL */ in i2c_compute_presc_scldel_sdadel()
1018 const struct i2c_stm32_config *cfg = dev->config; in stm32_i2c_configure_timing()
1019 struct i2c_stm32_data *data = dev->data; in stm32_i2c_configure_timing()
1020 I2C_TypeDef *i2c = cfg->i2c; in stm32_i2c_configure_timing() local
1023 uint32_t speed = 0U; in stm32_i2c_configure_timing() local
1024 uint32_t i2c_freq = cfg->bitrate; in stm32_i2c_configure_timing()
1030 for (speed = 0 ; speed <= (uint32_t)STM32_I2C_SPEED_FREQ_FAST_PLUS ; speed++) { in stm32_i2c_configure_timing()
1031 if ((i2c_freq >= stm32_i2c_charac[speed].freq_min) && in stm32_i2c_configure_timing()
1032 (i2c_freq <= stm32_i2c_charac[speed].freq_max)) { in stm32_i2c_configure_timing()
1033 i2c_compute_presc_scldel_sdadel(clock, speed); in stm32_i2c_configure_timing()
1034 idx = i2c_compute_scll_sclh(clock, speed); in stm32_i2c_configure_timing()
1049 data->current_timing.periph_clock = clock; in stm32_i2c_configure_timing()
1050 data->current_timing.i2c_speed = i2c_freq; in stm32_i2c_configure_timing()
1051 data->current_timing.timing_setting = timing; in stm32_i2c_configure_timing()
1053 LL_I2C_SetTiming(i2c, timing); in stm32_i2c_configure_timing()
1061 const struct i2c_stm32_config *cfg = dev->config; in stm32_i2c_configure_timing()
1062 struct i2c_stm32_data *data = dev->data; in stm32_i2c_configure_timing()
1063 I2C_TypeDef *i2c = cfg->i2c; in stm32_i2c_configure_timing() local
1070 for (uint32_t i = 0; i < cfg->n_timings; i++) { in stm32_i2c_configure_timing()
1071 const struct i2c_config_timing *preset = &cfg->timings[i]; in stm32_i2c_configure_timing()
1072 uint32_t speed = i2c_map_dt_bitrate(preset->i2c_speed); in stm32_i2c_configure_timing() local
1074 if ((I2C_SPEED_GET(speed) == I2C_SPEED_GET(data->dev_config)) in stm32_i2c_configure_timing()
1075 && (preset->periph_clock == clock)) { in stm32_i2c_configure_timing()
1076 /* Found a matching periph clock and i2c speed */ in stm32_i2c_configure_timing()
1077 LL_I2C_SetTiming(i2c, preset->timing_setting); in stm32_i2c_configure_timing()
1083 switch (I2C_SPEED_GET(data->dev_config)) { in stm32_i2c_configure_timing()
1097 LOG_ERR("i2c: speed above \"fast\" requires manual timing configuration, " in stm32_i2c_configure_timing()
1098 "see \"timings\" property of st,stm32-i2c-v2 devicetree binding"); in stm32_i2c_configure_timing()
1099 return -EINVAL; in stm32_i2c_configure_timing()
1111 if ((sclh - 1) > 255 || (scll - 1) > 255) { in stm32_i2c_configure_timing()
1116 if (sdadel > 15 || (scldel - 1) > 15) { in stm32_i2c_configure_timing()
1121 timing = __LL_I2C_CONVERT_TIMINGS(presc - 1, in stm32_i2c_configure_timing()
1122 scldel - 1, sdadel, sclh - 1, scll - 1); in stm32_i2c_configure_timing()
1127 LOG_ERR("I2C:failed to find prescaler value"); in stm32_i2c_configure_timing()
1128 return -EINVAL; in stm32_i2c_configure_timing()
1131 LOG_DBG("I2C TIMING = 0x%x", timing); in stm32_i2c_configure_timing()
1132 LL_I2C_SetTiming(i2c, timing); in stm32_i2c_configure_timing()
1143 * Perform a I2C transaction, while taking into account the STM32 I2C V2 in stm32_i2c_transaction()
1150 * bits turned off. This will cause the backend to use reload-mode, in stm32_i2c_transaction()
1162 do { /* do ... while to allow zero-length transactions */ in stm32_i2c_transaction()
1179 rest -= msg.len; in stm32_i2c_transaction()