Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
i2c.h
00001 /***************************************************************************//** 00002 * @file i2c.h 00003 * @brief Header file of I2C Interface 00004 * @author DBogdan (dragos.bogdan@analog.com) 00005 ******************************************************************************** 00006 * Copyright 2019(c) Analog Devices, Inc. 00007 * 00008 * All rights reserved. 00009 * 00010 * Redistribution and use in source and binary forms, with or without 00011 * modification, are permitted provided that the following conditions are met: 00012 * - Redistributions of source code must retain the above copyright 00013 * notice, this list of conditions and the following disclaimer. 00014 * - Redistributions in binary form must reproduce the above copyright 00015 * notice, this list of conditions and the following disclaimer in 00016 * the documentation and/or other materials provided with the 00017 * distribution. 00018 * - Neither the name of Analog Devices, Inc. nor the names of its 00019 * contributors may be used to endorse or promote products derived 00020 * from this software without specific prior written permission. 00021 * - The use of this software may or may not infringe the patent rights 00022 * of one or more patent holders. This license does not release you 00023 * from the requirement that you obtain separate licenses from these 00024 * patent holders to use this software. 00025 * - Use of the software either in source or binary form, must be run 00026 * on or directly connected to an Analog Devices Inc. component. 00027 * 00028 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR 00029 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 00030 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00031 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, 00032 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00033 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR 00034 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00035 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00036 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00037 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00038 *******************************************************************************/ 00039 00040 #ifndef I2C_H_ 00041 #define I2C_H_ 00042 00043 /******************************************************************************/ 00044 /***************************** Include Files **********************************/ 00045 /******************************************************************************/ 00046 00047 #include <stdint.h> 00048 00049 /******************************************************************************/ 00050 /*************************** Types Declarations *******************************/ 00051 /******************************************************************************/ 00052 00053 /** 00054 * @struct i2c_platform_ops 00055 * @brief Structure holding I2C function pointers that point to the platform 00056 * specific function 00057 */ 00058 struct i2c_platform_ops ; 00059 00060 /** 00061 * @struct i2c_init_param 00062 * @brief Structure holding the parameters for I2C initialization. 00063 */ 00064 typedef struct i2c_init_param { 00065 /** I2C maximum transfer speed supported */ 00066 uint32_t max_speed_hz; 00067 /** Slave address */ 00068 uint8_t slave_address; 00069 /** I2C platform specific functions */ 00070 const struct i2c_platform_ops *platform_ops; 00071 /** I2C extra parameters (device specific parameters) */ 00072 void *extra; 00073 } i2c_init_param; 00074 00075 /** 00076 * @struct i2c_desc 00077 * @brief Structure holding I2C descriptor 00078 */ 00079 typedef struct i2c_desc { 00080 /** I2C maximum transfer speed supported */ 00081 uint32_t max_speed_hz; 00082 /** Slave address */ 00083 uint8_t slave_address; 00084 /** I2C platform specific functions */ 00085 const struct i2c_platform_ops *platform_ops; 00086 /** I2C extra parameters (device specific parameters) */ 00087 void *extra; 00088 } i2c_desc; 00089 00090 /** 00091 * @struct i2c_platform_ops 00092 * @brief Structure holding i2c function pointers that point to the platform 00093 * specific function 00094 */ 00095 struct i2c_platform_ops { 00096 /** i2c initialization function pointer */ 00097 int32_t (*i2c_ops_init)(struct i2c_desc **, const struct i2c_init_param *); 00098 /** i2c write function pointer */ 00099 int32_t (*i2c_ops_write)(struct i2c_desc *, uint8_t *, uint8_t, uint8_t); 00100 /** i2c write function pointer */ 00101 int32_t (*i2c_ops_read)(struct i2c_desc *, uint8_t *, uint8_t, uint8_t); 00102 /** i2c remove function pointer */ 00103 int32_t (*i2c_ops_remove)(struct i2c_desc *); 00104 }; 00105 00106 /******************************************************************************/ 00107 /************************ Functions Declarations ******************************/ 00108 /******************************************************************************/ 00109 00110 /* Initialize the I2C communication peripheral. */ 00111 int32_t i2c_init(struct i2c_desc **desc, 00112 const struct i2c_init_param *param); 00113 00114 /* Free the resources allocated by i2c_init(). */ 00115 int32_t i2c_remove(struct i2c_desc *desc); 00116 00117 /* Write data to a slave device. */ 00118 int32_t i2c_write(struct i2c_desc *desc, 00119 uint8_t *data, 00120 uint8_t bytes_number, 00121 uint8_t stop_bit); 00122 00123 /* Read data from a slave device. */ 00124 int32_t i2c_read(struct i2c_desc *desc, 00125 uint8_t *data, 00126 uint8_t bytes_number, 00127 uint8_t stop_bit); 00128 00129 #endif // I2C_H_
Generated on Wed Jul 20 2022 16:03:27 by
1.7.2