Lines Matching +full:interrupt +full:- +full:direction
5 * SPDX-License-Identifier: Apache-2.0
21 #include "i2c-priv.h"
24 ((I2C_Type *)((const struct i2c_imx_config * const)(dev)->config)->base)
54 struct i2c_imx_data *data = dev->data; in i2c_imx_write()
55 struct i2c_master_transfer *transfer = &data->transfer; in i2c_imx_write()
57 transfer->isBusy = true; in i2c_imx_write()
59 /* Clear I2C interrupt flag to avoid spurious interrupt */ in i2c_imx_write()
64 transfer->currentDir = i2cDirectionTransmit; in i2c_imx_write()
66 transfer->txBuff = txBuffer; in i2c_imx_write()
67 transfer->txSize = txSize; in i2c_imx_write()
69 I2C_WriteByte(base, *transfer->txBuff); in i2c_imx_write()
70 transfer->txBuff++; in i2c_imx_write()
71 transfer->txSize--; in i2c_imx_write()
73 /* Enable I2C interrupt, subsequent data transfer will be handled in i2c_imx_write()
79 k_sem_take(&data->device_sync_sem, K_FOREVER); in i2c_imx_write()
81 return transfer->ack; in i2c_imx_write()
88 struct i2c_imx_data *data = dev->data; in i2c_imx_read()
89 struct i2c_master_transfer *transfer = &data->transfer; in i2c_imx_read()
91 transfer->isBusy = true; in i2c_imx_read()
93 /* Clear I2C interrupt flag to avoid spurious interrupt */ in i2c_imx_read()
98 transfer->currentDir = i2cDirectionReceive; in i2c_imx_read()
100 transfer->rxBuff = rxBuffer; in i2c_imx_read()
101 transfer->rxSize = rxSize; in i2c_imx_read()
103 if (transfer->rxSize == 1U) { in i2c_imx_read()
114 /* Enable I2C interrupt, subsequent data transfer will be handled in i2c_imx_read()
120 k_sem_take(&data->device_sync_sem, K_FOREVER); in i2c_imx_read()
128 struct i2c_imx_data *data = dev->data; in i2c_imx_configure()
129 struct i2c_master_transfer *transfer = &data->transfer; in i2c_imx_configure()
133 return -EINVAL; in i2c_imx_configure()
137 return -EINVAL; in i2c_imx_configure()
141 transfer->txBuff = 0; in i2c_imx_configure()
142 transfer->rxBuff = 0; in i2c_imx_configure()
143 transfer->cmdSize = 0U; in i2c_imx_configure()
144 transfer->txSize = 0U; in i2c_imx_configure()
145 transfer->rxSize = 0U; in i2c_imx_configure()
146 transfer->isBusy = false; in i2c_imx_configure()
147 transfer->currentDir = i2cDirectionReceive; in i2c_imx_configure()
148 transfer->currentMode = i2cModeSlave; in i2c_imx_configure()
161 return -EINVAL; in i2c_imx_configure()
192 struct i2c_imx_data *data = dev->data; in i2c_imx_transfer()
193 struct i2c_master_transfer *transfer = &data->transfer; in i2c_imx_transfer()
195 int result = -EIO; in i2c_imx_transfer()
202 while ((I2C_I2SR_REG(base) & i2cStatusBusBusy) && (--timeout)) { in i2c_imx_transfer()
211 transfer->currentMode = i2cModeSlave; in i2c_imx_transfer()
212 /* Switch back to Rx direction. */ in i2c_imx_transfer()
214 transfer->currentDir = i2cDirectionReceive; in i2c_imx_transfer()
217 transfer->currentDir = i2cDirectionTransmit; in i2c_imx_transfer()
219 transfer->currentMode = i2cModeMaster; in i2c_imx_transfer()
222 if (!i2c_imx_send_addr(dev, addr, msgs->flags)) { in i2c_imx_transfer()
227 if (msgs->flags & I2C_MSG_RESTART) { in i2c_imx_transfer()
229 if (!i2c_imx_send_addr(dev, addr, msgs->flags)) { in i2c_imx_transfer()
235 if (msgs->len) { in i2c_imx_transfer()
236 if ((msgs->flags & I2C_MSG_RW_MASK) == I2C_MSG_READ) { in i2c_imx_transfer()
237 i2c_imx_read(dev, msgs->buf, msgs->len); in i2c_imx_transfer()
239 if (!i2c_imx_write(dev, msgs->buf, msgs->len)) { in i2c_imx_transfer()
245 if (msgs->flags & I2C_MSG_STOP) { in i2c_imx_transfer()
247 transfer->currentMode = i2cModeSlave; in i2c_imx_transfer()
249 transfer->currentDir = i2cDirectionReceive; in i2c_imx_transfer()
254 num_msgs--; in i2c_imx_transfer()
263 transfer->currentMode = i2cModeSlave; in i2c_imx_transfer()
265 transfer->currentDir = i2cDirectionReceive; in i2c_imx_transfer()
274 struct i2c_imx_data *data = dev->data; in i2c_imx_isr()
275 struct i2c_master_transfer *transfer = &data->transfer; in i2c_imx_isr()
277 /* Clear interrupt flag. */ in i2c_imx_isr()
282 if (!transfer->isBusy) { in i2c_imx_isr()
286 if (i2cModeMaster == transfer->currentMode) { in i2c_imx_isr()
287 if (i2cDirectionTransmit == transfer->currentDir) { in i2c_imx_isr()
289 transfer->ack = in i2c_imx_isr()
292 if (transfer->txSize == 0U) { in i2c_imx_isr()
293 /* Close I2C interrupt. */ in i2c_imx_isr()
296 transfer->isBusy = false; in i2c_imx_isr()
297 k_sem_give(&data->device_sync_sem); in i2c_imx_isr()
299 I2C_WriteByte(base, *transfer->txBuff); in i2c_imx_isr()
300 transfer->txBuff++; in i2c_imx_isr()
301 transfer->txSize--; in i2c_imx_isr()
305 if (transfer->rxSize == 2U) { in i2c_imx_isr()
313 if (transfer->rxSize == 1U) { in i2c_imx_isr()
314 /* Switch back to Tx direction to avoid in i2c_imx_isr()
318 transfer->currentDir = i2cDirectionTransmit; in i2c_imx_isr()
321 *transfer->rxBuff = I2C_ReadByte(base); in i2c_imx_isr()
322 transfer->rxBuff++; in i2c_imx_isr()
323 transfer->rxSize--; in i2c_imx_isr()
326 if (transfer->rxSize == 0U) { in i2c_imx_isr()
327 /* Close I2C interrupt. */ in i2c_imx_isr()
330 transfer->isBusy = false; in i2c_imx_isr()
331 k_sem_give(&data->device_sync_sem); in i2c_imx_isr()
339 const struct i2c_imx_config *config = dev->config; in i2c_imx_init()
340 struct i2c_imx_data *data = dev->data; in i2c_imx_init()
344 k_sem_init(&data->device_sync_sem, 0, K_SEM_MAX_LIMIT); in i2c_imx_init()
346 error = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT); in i2c_imx_init()
351 bitrate_cfg = i2c_map_dt_bitrate(config->bitrate); in i2c_imx_init()
358 config->irq_config_func(dev); in i2c_imx_init()