Lines Matching full:i2c
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 */
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()
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()
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()
154 LL_I2C_Enable(i2c); in msg_init()
156 LL_I2C_GenerateStartCondition(i2c); in msg_init()
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()
175 LL_I2C_DisableIT_ERR(i2c); in stm32_i2c_disable_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()
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()
205 LL_I2C_Disable(i2c); in stm32_i2c_master_mode_end()
209 LL_I2C_Disable(i2c); in stm32_i2c_master_mode_end()
220 I2C_TypeDef *i2c = cfg->i2c; in stm32_i2c_slave_event() local
228 slave_address = LL_I2C_GetAddressMatchCode(i2c) >> 1; in stm32_i2c_slave_event()
254 if (LL_I2C_IsActiveFlag_TXIS(i2c)) { 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()
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()
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()
302 LL_I2C_EnableIT_RX(i2c); 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 */
325 I2C_TypeDef *i2c = cfg->i2c; in i2c_stm32_target_register() local
345 LOG_ERR("i2c: failure initializing"); 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()
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()
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()
388 LL_I2C_EnableIT_ADDR(i2c); in i2c_stm32_target_register()
398 I2C_TypeDef *i2c = cfg->i2c; in i2c_stm32_target_unregister() local
409 LL_I2C_DisableOwnAddress1(i2c); in i2c_stm32_target_unregister()
412 LOG_DBG("i2c: slave #1 unregistered"); in i2c_stm32_target_unregister()
414 LL_I2C_DisableOwnAddress2(i2c); in i2c_stm32_target_unregister()
417 LOG_DBG("i2c: slave #2 unregistered"); 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()
437 LL_I2C_Disable(i2c); 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()
461 I2C_TypeDef *i2c = cfg->i2c; in stm32_i2c_event() local
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()
485 if (LL_I2C_IsActiveFlag_NACK(i2c)) { in stm32_i2c_event()
486 LL_I2C_ClearFlag_NACK(i2c); 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()
508 LL_I2C_GenerateStopCondition(i2c); in stm32_i2c_event()
524 I2C_TypeDef *i2c = cfg->i2c; in stm32_i2c_error() local
533 if (LL_I2C_IsActiveFlag_ARLO(i2c)) { in stm32_i2c_error()
534 LL_I2C_ClearFlag_ARLO(i2c); 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()
546 if (LL_I2C_IsActiveSMBusFlag_ALERT(i2c)) { in stm32_i2c_error()
547 LL_I2C_ClearSMBusFlag_ALERT(i2c); in stm32_i2c_error()
593 I2C_TypeDef *i2c = cfg->i2c; in stm32_i2c_msg_write() local
606 LL_I2C_EnableIT_TX(i2c); in stm32_i2c_msg_write()
651 I2C_TypeDef *i2c = cfg->i2c; in stm32_i2c_msg_read() local
665 LL_I2C_EnableIT_RX(i2c); in stm32_i2c_msg_read()
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()
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()
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()
772 I2C_TypeDef *i2c = cfg->i2c; in stm32_i2c_msg_write() local
781 if (LL_I2C_IsActiveFlag_TXIS(i2c)) { in stm32_i2c_msg_write()
790 LL_I2C_TransmitData8(i2c, *buf); in stm32_i2c_msg_write()
802 I2C_TypeDef *i2c = cfg->i2c; in stm32_i2c_msg_read() local
810 while (!LL_I2C_IsActiveFlag_RXNE(i2c)) { in stm32_i2c_msg_read()
816 *buf = LL_I2C_ReceiveData8(i2c); in stm32_i2c_msg_read()
853 * @param clock_src_freq I2C source clock in Hz.
854 * @param i2c_speed I2C frequency (index).
946 * @param clock_src_freq I2C source clock in Hz.
947 * @param i2c_speed I2C frequency (index).
1020 I2C_TypeDef *i2c = cfg->i2c; in stm32_i2c_configure_timing() local
1053 LL_I2C_SetTiming(i2c, timing); in stm32_i2c_configure_timing()
1063 I2C_TypeDef *i2c = cfg->i2c; in stm32_i2c_configure_timing() local
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()
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()
1127 LOG_ERR("I2C:failed to find prescaler value"); 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()