//########################################################################### // // FILE: i2c.h // // TITLE: CM I2C driver. // //########################################################################### // $Copyright: // Copyright (C) 2022 Texas Instruments Incorporated - http://www.ti.com // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // // Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the // distribution. // // Neither the name of Texas Instruments Incorporated nor the names of // its contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // $ //########################################################################### #ifndef I2C_H #define I2C_H //***************************************************************************** // // If building with a C++ compiler, make all of the definitions in this header // have a C binding. // //***************************************************************************** #ifdef __cplusplus extern "C" { #endif //***************************************************************************** // //! \addtogroup i2c_api I2C //! @{ // //***************************************************************************** #include "inc/hw_i2c.h" #include "inc/hw_memmap.h" #include "inc/hw_types.h" #include "interrupt.h" #include "debug.h" //***************************************************************************** // // Defines for the API. // //***************************************************************************** //***************************************************************************** // //Values that can be returned from I2C_getMasterErr() as I2C Master error //status // //***************************************************************************** #define I2C_MASTER_ERR_NONE 0X00000000U //!< No error #define I2C_MASTER_ERR_ADDR_ACK 0x00000004U //!< Acknowledge Address error #define I2C_MASTER_ERR_DATA_ACK 0x00000008U //!< Acknowledge Data error #define I2C_MASTER_ERR_ARB_LOST 0x00000010U //!< Arbitration Lost error #define I2C_MASTER_ERR_CLK_TOUT 0x00000080U //!< Clock Timeout error //***************************************************************************** // // Values that can be passed to I2C_enableMasterIntSource() as I2C Master // interrupts // //***************************************************************************** #define I2C_MASTER_INT_RX_FIFO_FULL 0x00000800U //!< RX FIFO Full Interrupt #define I2C_MASTER_INT_TX_FIFO_EMPTY 0x00000400U //!< TX FIFO Empty Intrpt #define I2C_MASTER_INT_RX_FIFO_REQ 0x00000200U //!< RX FIFO Request Intrpt #define I2C_MASTER_INT_TX_FIFO_REQ 0x00000100U //!< TX FIFO Request Intrpt #define I2C_MASTER_INT_ARB_LOST 0x00000080U //!< Arb Lost Interrupt #define I2C_MASTER_INT_STOP 0x00000040U //!< Stop Condition Intrpt #define I2C_MASTER_INT_START 0x00000020U //!< Start Condition Intrpt #define I2C_MASTER_INT_NACK 0x00000010U //!< Addr/Data NACK Intrpt #define I2C_MASTER_INT_TX_DMA_DONE 0x00000008U //!< TX DMA Complete Intrpt #define I2C_MASTER_INT_RX_DMA_DONE 0x00000004U //!< RX DMA Complete Intrpt #define I2C_MASTER_INT_TIMEOUT 0x00000002U //!< Clock Timeout Intrpt #define I2C_MASTER_INT_DATA 0x00000001U //!< Data Interrupt //***************************************************************************** // // Values that are returned from I2C_getSlaveStatus() as I2C Slave // action requests // //***************************************************************************** #define I2C_SLAVE_ACT_NONE 0x00000000U //!< Master has sent no command #define I2C_SLAVE_ACT_RREQ 0x00000001U //!< Master has sent data #define I2C_SLAVE_ACT_TREQ 0x00000002U //!< Master has requested data #define I2C_SLAVE_ACT_RREQ_FBR 0x00000005U //!< Master has sent first byte #define I2C_SLAVE_ACT_OWN2SEL 0x00000008U //!< Master requested secondary //!< slave #define I2C_SLAVE_ACT_QCMD 0x00000010U //!< Master has sent Quick Command #define I2C_SLAVE_ACT_QCMD_DATA 0x00000020U //!< Master Quick Command value //***************************************************************************** // // Values that are returned from I2C_getSlaveStatus() as I2C DMA status // //***************************************************************************** #define I2C_SLAVE_DMA_TX 0x00000040U //!< DMA TX active #define I2C_SLAVE_DMA_RX 0x00000080U //!< DMA RX active //***************************************************************************** // // Miscellaneous I2C driver definitions. // //***************************************************************************** #define I2C_MASTER_MAX_RETRIES 1000U //!< Number of retries #define I2C_SA_A6_0_MASK 0x80U //!< Mask for Slave Address A6-0 #define I2C_TXFIFO_MASK 0xffff0000U //!< TX FIFO Mask #define I2C_RXFIFO_MASK 0x0000ffffU //!< RX FIFO Mask #define I2C_SCL_FREQ_FAST_MODE 400000U //!< SCL freq Fast mode #define I2C_SCL_FREQ_STD_MODE 100000U //!< SCL freq Std mode #define I2C_SCL_FREQ_HS_MODE 3400000U //!< SCL freq High speed mode //***************************************************************************** // // Values that can be passed to I2C_enableSlaveIntSource() as I2C Slave // interrupts // //***************************************************************************** #define I2C_SLAVE_INT_RX_FIFO_FULL 0x00000100U //!< RX FIFO Full Intrpt #define I2C_SLAVE_INT_TX_FIFO_EMPTY 0x00000080U //!< TX FIFO Empty Intrpt #define I2C_SLAVE_INT_RX_FIFO_REQ 0x00000040U //!< RX FIFO Req Intrpt #define I2C_SLAVE_INT_TX_FIFO_REQ 0x00000020U //!< TX FIFO Req Intrpt #define I2C_SLAVE_INT_TX_DMA_DONE 0x00000010U //!< TX DMA Complete Intrpt #define I2C_SLAVE_INT_RX_DMA_DONE 0x00000008U //!< RX DMA Complete Intrpt #define I2C_SLAVE_INT_STOP 0x00000004U //!< Stop Condition Intrpt #define I2C_SLAVE_INT_START 0x00000002U //!< Start Condition Intrpt #define I2C_SLAVE_INT_DATA 0x00000001U //!< Data Interrupt //***************************************************************************** // // Values that can be passed to I2C_enableFIFO() for I2C FIFO configuration // //***************************************************************************** #define I2C_SLAVE_TX_FIFO_ENABLE 0x00000002U //!< TX FIFO enable #define I2C_SLAVE_RX_FIFO_ENABLE 0x00000004U //!< RX FIFO enable //***************************************************************************** // // Values that can be passed to I2C_configureSlaveAckOverride() as I2C Slave // Ack override enable/Disable configuration // //***************************************************************************** #define I2C_SLAVE_ACK_OVERRIDE_ENABLE true //!