1 /*! 2 * \file i2c.h 3 * 4 * \brief I2C driver implementation 5 * 6 * \copyright Revised BSD License, see section \ref LICENSE. 7 * 8 * \code 9 * ______ _ 10 * / _____) _ | | 11 * ( (____ _____ ____ _| |_ _____ ____| |__ 12 * \____ \| ___ | (_ _) ___ |/ ___) _ \ 13 * _____) ) ____| | | || |_| ____( (___| | | | 14 * (______/|_____)_|_|_| \__)_____)\____)_| |_| 15 * (C)2013-2017 Semtech 16 * 17 * \endcode 18 * 19 * \author Miguel Luis ( Semtech ) 20 * 21 * \author Gregory Cristian ( Semtech ) 22 */ 23 #ifndef __I2C_H__ 24 #define __I2C_H__ 25 26 #ifdef __cplusplus 27 extern "C" 28 { 29 #endif 30 31 #include "utilities.h" 32 #include "gpio.h" 33 34 /*! 35 * I2C peripheral ID 36 */ 37 typedef enum 38 { 39 I2C_1, 40 I2C_2, 41 }I2cId_t; 42 43 /*! 44 * I2C object type definition 45 */ 46 typedef struct 47 { 48 I2cId_t I2cId; 49 Gpio_t Scl; 50 Gpio_t Sda; 51 }I2c_t; 52 53 /*! 54 * \brief Initializes the I2C object and MCU peripheral 55 * 56 * \param [IN] obj I2C object 57 * \param [IN] scl I2C Scl pin name to be used 58 * \param [IN] sda I2C Sda pin name to be used 59 */ 60 void I2cInit( I2c_t *obj, I2cId_t i2cId, PinNames scl, PinNames sda ); 61 62 /*! 63 * \brief DeInitializes the I2C object and MCU peripheral 64 * 65 * \param [IN] obj I2C object 66 */ 67 void I2cDeInit( I2c_t *obj ); 68 69 /*! 70 * \brief Reset the I2C object and MCU peripheral 71 * 72 * \param [IN] obj I2C object 73 */ 74 void I2cResetBus( I2c_t *obj ); 75 76 /*! 77 * \brief Write data to the I2C device 78 * 79 * \param [IN] obj I2C object 80 * \param [IN] deviceAddr device address 81 * \param [IN] data data to write 82 */ 83 LmnStatus_t I2cWrite( I2c_t *obj, uint8_t deviceAddr, uint8_t data ); 84 85 /*! 86 * \brief Write data buffer to the I2C device 87 * 88 * \param [IN] obj I2C object 89 * \param [IN] deviceAddr device address 90 * \param [IN] buffer data buffer to write 91 * \param [IN] size number of bytes to write 92 */ 93 LmnStatus_t I2cWriteBuffer( I2c_t *obj, uint8_t deviceAddr, uint8_t *buffer, uint16_t size ); 94 95 /*! 96 * \brief Write data at addr to the I2C device 97 * 98 * \param [IN] obj I2C object 99 * \param [IN] deviceAddr device address 100 * \param [IN] addr data address 101 * \param [IN] data data to write 102 */ 103 LmnStatus_t I2cWriteMem( I2c_t *obj, uint8_t deviceAddr, uint16_t addr, uint8_t data ); 104 105 /*! 106 * \brief Write data buffer starting at addr to the I2C device 107 * 108 * \param [IN] obj I2C object 109 * \param [IN] deviceAddr device address 110 * \param [IN] addr data address 111 * \param [IN] buffer data buffer to write 112 * \param [IN] size number of bytes to write 113 */ 114 LmnStatus_t I2cWriteMemBuffer( I2c_t *obj, uint8_t deviceAddr, uint16_t addr, uint8_t *buffer, uint16_t size ); 115 116 /*! 117 * \brief Read data from the I2C device 118 * 119 * \param [IN] obj I2C object 120 * \param [IN] deviceAddr device address 121 * \param [OUT] data data to read 122 */ 123 LmnStatus_t I2cRead( I2c_t *obj, uint8_t deviceAddr, uint8_t *data ); 124 125 /*! 126 * \brief Read data buffer from the I2C device 127 * 128 * \param [IN] obj I2C object 129 * \param [IN] deviceAddr device address 130 * \param [OUT] buffer data buffer to read 131 * \param [IN] size number of data bytes to read 132 */ 133 LmnStatus_t I2cReadBuffer( I2c_t *obj, uint8_t deviceAddr, uint8_t *buffer, uint16_t size ); 134 135 /*! 136 * \brief Read data at addr from the I2C device 137 * 138 * \param [IN] obj I2C object 139 * \param [IN] deviceAddr device address 140 * \param [IN] addr data address 141 * \param [OUT] data data to read 142 */ 143 LmnStatus_t I2cReadMem( I2c_t *obj, uint8_t deviceAddr, uint16_t addr, uint8_t *data ); 144 145 /*! 146 * \brief Read data buffer starting at addr from the I2C device 147 * 148 * \param [IN] obj I2C object 149 * \param [IN] deviceAddr device address 150 * \param [IN] addr data address 151 * \param [OUT] buffer data buffer to read 152 * \param [IN] size number of data bytes to read 153 */ 154 LmnStatus_t I2cReadMemBuffer( I2c_t *obj, uint8_t deviceAddr, uint16_t addr, uint8_t *buffer, uint16_t size ); 155 156 #ifdef __cplusplus 157 } 158 #endif 159 160 #endif // __I2C_H__ 161