|
| int | MXC_I2C_Init (mxc_i2c_regs_t *i2c, int masterMode, unsigned int slaveAddr) |
| |
| int | MXC_I2C_SetSlaveAddr (mxc_i2c_regs_t *i2c, unsigned int slaveAddr, int idx) |
| |
| int | MXC_I2C_Shutdown (mxc_i2c_regs_t *i2c) |
| |
| int | MXC_I2C_Reset (mxc_i2c_regs_t *i2c) |
| |
| int | MXC_I2C_SetFrequency (mxc_i2c_regs_t *i2c, unsigned int hz) |
| |
| int | MXC_I2C_GetFrequency (mxc_i2c_regs_t *i2c) |
| |
| int | MXC_I2C_ReadyForSleep (mxc_i2c_regs_t *i2c) |
| |
| int | MXC_I2C_SetClockStretching (mxc_i2c_regs_t *i2c, int enable) |
| |
| int | MXC_I2C_GetClockStretching (mxc_i2c_regs_t *i2c) |
| |
| int | MXC_I2C_DMA_Init (mxc_i2c_regs_t *i2c, mxc_dma_regs_t *dma, bool use_dma_tx, bool use_dma_rx) |
| |
| int | MXC_I2C_DMA_GetTXChannel (mxc_i2c_regs_t *i2c) |
| |
| int | MXC_I2C_DMA_GetRXChannel (mxc_i2c_regs_t *i2c) |
| |
| int | MXC_I2C_DMA_SetRequestSelect (mxc_i2c_regs_t *i2c, uint8_t *txData, uint8_t *rxData) |
| |
| int | MXC_I2C_Start (mxc_i2c_regs_t *i2c) |
| |
| int | MXC_I2C_Stop (mxc_i2c_regs_t *i2c) |
| |
| int | MXC_I2C_WriteByte (mxc_i2c_regs_t *i2c, unsigned char byte) |
| |
| int | MXC_I2C_ReadByte (mxc_i2c_regs_t *i2c, unsigned char *byte, int ack) |
| |
| int | MXC_I2C_ReadByteInteractive (mxc_i2c_regs_t *i2c, unsigned char *byte, mxc_i2c_getAck_t getAck) |
| |
| int | MXC_I2C_Write (mxc_i2c_regs_t *i2c, unsigned char *bytes, unsigned int *len) |
| |
| int | MXC_I2C_Read (mxc_i2c_regs_t *i2c, unsigned char *bytes, unsigned int *len, int ack) |
| |
| int | MXC_I2C_ReadRXFIFO (mxc_i2c_regs_t *i2c, volatile unsigned char *bytes, unsigned int len) |
| |
| int | MXC_I2C_ReadRXFIFODMA (mxc_i2c_regs_t *i2c, unsigned char *bytes, unsigned int len, mxc_i2c_dma_complete_cb_t callback) |
| |
| int | MXC_I2C_GetRXFIFOAvailable (mxc_i2c_regs_t *i2c) |
| |
| int | MXC_I2C_WriteTXFIFO (mxc_i2c_regs_t *i2c, volatile unsigned char *bytes, unsigned int len) |
| |
| int | MXC_I2C_WriteTXFIFODMA (mxc_i2c_regs_t *i2c, unsigned char *bytes, unsigned int len, mxc_i2c_dma_complete_cb_t callback) |
| |
| int | MXC_I2C_GetTXFIFOAvailable (mxc_i2c_regs_t *i2c) |
| |
| void | MXC_I2C_ClearRXFIFO (mxc_i2c_regs_t *i2c) |
| |
| void | MXC_I2C_ClearTXFIFO (mxc_i2c_regs_t *i2c) |
| |
| int | MXC_I2C_GetFlags (mxc_i2c_regs_t *i2c, unsigned int *flags0, unsigned int *flags1) |
| |
| void | MXC_I2C_ClearFlags (mxc_i2c_regs_t *i2c, unsigned int flags0, unsigned int flags1) |
| |
| void | MXC_I2C_EnableInt (mxc_i2c_regs_t *i2c, unsigned int flags0, unsigned int flags1) |
| |
| void | MXC_I2C_DisableInt (mxc_i2c_regs_t *i2c, unsigned int flags0, unsigned int flags1) |
| |
| void | MXC_I2C_EnablePreload (mxc_i2c_regs_t *i2c) |
| |
| void | MXC_I2C_DisablePreload (mxc_i2c_regs_t *i2c) |
| |
| void | MXC_I2C_EnableGeneralCall (mxc_i2c_regs_t *i2c) |
| |
| void | MXC_I2C_DisableGeneralCall (mxc_i2c_regs_t *i2c) |
| |
| void | MXC_I2C_SetTimeout (mxc_i2c_regs_t *i2c, unsigned int timeout) |
| |
| unsigned int | MXC_I2C_GetTimeout (mxc_i2c_regs_t *i2c) |
| |
| int | MXC_I2C_Recover (mxc_i2c_regs_t *i2c, unsigned int retries) |
| |
| int | MXC_I2C_MasterTransaction (mxc_i2c_req_t *req) |
| |
| int | MXC_I2C_MasterTransactionAsync (mxc_i2c_req_t *req) |
| |
| int | MXC_I2C_MasterTransactionDMA (mxc_i2c_req_t *req) |
| |
| int | MXC_I2C_SlaveTransaction (mxc_i2c_regs_t *i2c, mxc_i2c_slave_handler_t callback) |
| |
| int | MXC_I2C_SlaveTransactionAsync (mxc_i2c_regs_t *i2c, mxc_i2c_slave_handler_t callback) |
| |
| int | MXC_I2C_SetRXThreshold (mxc_i2c_regs_t *i2c, unsigned int numBytes) |
| |
| int | MXC_I2C_GetRXThreshold (mxc_i2c_regs_t *i2c) |
| |
| int | MXC_I2C_SetTXThreshold (mxc_i2c_regs_t *i2c, unsigned int numBytes) |
| |
| int | MXC_I2C_GetTXThreshold (mxc_i2c_regs_t *i2c) |
| |
| void | MXC_I2C_AsyncStop (mxc_i2c_regs_t *i2c) |
| |
| void | MXC_I2C_AbortAsync (mxc_i2c_regs_t *i2c) |
| |
| void | MXC_I2C_AsyncHandler (mxc_i2c_regs_t *i2c) |
| |
| void | MXC_I2C_DMACallback (int ch, int error) |
| |
| int MXC_I2C_MasterTransactionDMA |
( |
mxc_i2c_req_t * |
req | ) |
|
Performs a non-blocking I2C Master transaction using DMA for reduced time in the ISR. This function initializes the DMA and acquires DMA channels if MXC_I2C_DMA_Init(...) was not called earlier.
It is recommended to initialize the DMA by calling MXC_I2C_DMA_Init(...) function before calling MXC_I2C_MasterTransactionDMA(...). This provides flexibility in setting up generic DMA channel vectors during run-time without knowing what DMA channels will be acquired beforehand.
Performs a non-blocking I2C transaction. These actions will be performed:
- If necessary, generate a start condition on the bus.
- Send the slave address with the low bit set to 0 (indicating a write).
- Transmit req->tx_len bytes of req->tx_buff.
- Generate a repeated start condition on the bus.
- Send the slave address with the low bit set to 1 (indicating a read).
- Receive req->rx_len bytes into req->rx_buf, acknowledging each byte.
- Generate a stop (or repeated start) condition on the bus.
- Execute req->callback to indicate the transaction is complete. Steps 3-6 will be skipped if tx_len and rx_len are both 0. Steps 2-4 will be skipped if tx_len equals 0. Steps 4-6 will be skipped if rx_len equals 0.
- Note
- MXC_I2C_AsyncHandler() must be called periodically for this function to operate properly. Ideally from the I2C ISR.
- Parameters
-
| req | Pointer to details of the transaction. The memory used by this parameter must remain available until the callback is executed. |
- Returns
- Success/Fail, see Error Codes for a list of return codes.
| int MXC_I2C_SetRXThreshold |
( |
mxc_i2c_regs_t * |
i2c, |
|
|
unsigned int |
numBytes |
|
) |
| |
Set the receive threshold level.
When operating as a master, the function sets the receive threshold level for when the master should unload the receive FIFO. Smaller values may consume more CPU cycles, but decrease the chances of the master delaying the generation of I2C bus clocks because it has no room in the FIFO to receive data. Larger values may consume fewer CPU cycles, but risk delays of the I2C clock. When operating as a slave, this function sets the number of bytes the slave transaction functions should receive before issuing a call to their callback function. Smaller values may consume more CPU cycles, but reduce the risk of missing data from the master due to the recieve FIFO being full. Larger values may reduce the number of CPU cycles, but may cause bytes sent from the master to be missed.
- Parameters
-
| i2c | Pointer to I2C registers (selects the I2C block used.) |
| numBytes | The threshold level to set. This value must be between 0 and 8 inclusive. |
- Returns
- Success/Fail, see Error Codes for a list of return codes.
| int MXC_I2C_SetTXThreshold |
( |
mxc_i2c_regs_t * |
i2c, |
|
|
unsigned int |
numBytes |
|
) |
| |
Set the transmit threshold level.
When operating as a master, the function sets the transmit threshold level for when the master should add additional bytes to the transmit FIFO. Larger values may consume more CPU cycles, but decrease the chances of the master delaying the generation of I2C bus clocks because it has no data in the FIFO to transmit. Smaller values may consume fewer CPU cycles, but risk delays of the I2C clock. When operating as a slave, this function sets the number of bytes the slave transaction functions should transmit before issuing a call to their callback function. Larger values may consume more CPU cycles, but reduce the risk of not having data ready when the master requests it. Smaller values may reduce the number of CPU cycles, but may cause the master to read from an empty FIFO. (The master will read 0xFF in this case.)
- Parameters
-
| i2c | Pointer to I2C registers (selects the I2C block used.) |
| numBytes | The threshold level to set. This value must be between 0 and 8 inclusive. |
- Returns
- Success/Fail, see Error Codes for a list of return codes.
Performs a blocking I2C slave transaction.
Performs a blocking I2C slave transaction. This function will block until a complete transaction with this slave has been performed. A transaction begins with the master addressing the slave and ends with a repeated start condition, a stop condition, or a bus error. The provided callback function will be called for these events:
- A slave address match occurs with the master requesting a write to the slave.
- A slave address match occurs with the master requesting a read from the slave.
- The receive FIFO crosses the set threshold (see MXC_I2C_SetRXThreshold()). The callback code should unload the receive FIFO (see MXC_I2C_ReadFIFO()) to allow the master to send more data. The return value of the callback function will determine if the last byte received should be acknowledged or not. Return 0 to acknowledge, non-zero to not acknowledge.
- The transmit FIFO crosses the set threshold (see MXC_I2C_SetTXThreshold()). If the master is expected to read more data from this slave, the callback code should add data to the transmit FIFO (see MXC_I2C_WriteFIFO()).
- The transaction ends. If the master was writing to the slave, the receive FIFO may still contain valid data that needs to be retreived (see MXC_I2C_ReadFIFO()).
- The transmit FIFO underflows because the master requests data when the transmit FIFO is empty.
- The receive FIFO overflows because the master writes data while the receive FIFO was full.
If clock stretching is disabled, careful attention must be paid to the timing of the callback to avoid losing data on write or unintentionally nacking a read.
- Parameters
-
| i2c | Pointer to I2C registers (selects the I2C block used.) |
| callback | The function to be called when an I2C event occurs. |
- Returns
- Success/Fail, see Error Codes for a list of return codes.
Performs a non-blocking I2C slave transaction.
Performs a non-blocking I2C slave transaction. This request will remain active until a complete transaction with this slave has been performed. A transaction begins with the master begins with the master addressing the slave and ends with a repeated start condition, a stop condition, or a bus error. The provided callback function will be called for these events:
- A slave address match occurs with the master requesting a write to the slave.
- A slave address match occurs with the master requesting a read from the slave.
- The receive FIFO crosses the set threshold (see MXC_I2C_SetRXThreshold()). The callback code should unload the receive FIFO (see MXC_I2C_ReadFIFO()) to allow the master to send more data. The return value of the callback function will determine if the last byte received should be acknowledged or not. Return 0 to acknowledge, non-zero to not acknowledge.
- The transmit FIFO crosses the set threshold (see MXC_I2C_SetTXThreshold()). If the master is expected to read more data from this slave, the callback code should add data to the transmit FIFO (see MXC_I2C_WriteFIFO()).
- The transaction ends. If the master was writing to the slave, the receive FIFO may still contain valid data that needs to be retreived (see MXC_I2C_ReadFIFO()).
- The transmit FIFO underflows because the master requests data when the transmit FIFO is empty.
- The receive FIFO overflows because the master writes data while the receive FIFO was full.
If clock stretching is disabled, careful attention must be paid to the timing of the callback to avoid losing data on write or unintentionally nacking a read.
- Note
- MXC_I2C_AsyncHandler() must be called peridocally for this function to operate properly.
- Parameters
-
| i2c | Pointer to I2C registers (selects the I2C block used.) |
| callback | The function to be called when an I2C event occurs. |
- Returns
- Success/Fail, see Error Codes for a list of return codes.