mikroSDK Reference Manual
drv_i2c_master.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2023 MikroElektronika d.o.o.
4 ** Contact: https://www.mikroe.com/contact
5 **
6 ** This file is part of the mikroSDK package
7 **
8 ** Commercial License Usage
9 **
10 ** Licensees holding valid commercial NECTO compilers AI licenses may use this
11 ** file in accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The MikroElektronika Company.
14 ** For licensing terms and conditions see
15 ** https://www.mikroe.com/legal/software-license-agreement.
16 ** For further information use the contact form at
17 ** https://www.mikroe.com/contact.
18 **
19 **
20 ** GNU Lesser General Public License Usage
21 **
22 ** Alternatively, this file may be used for
23 ** non-commercial projects under the terms of the GNU Lesser
24 ** General Public License version 3 as published by the Free Software
25 ** Foundation: https://www.gnu.org/licenses/lgpl-3.0.html.
26 **
27 ** The above copyright notice and this permission notice shall be
28 ** included in all copies or substantial portions of the Software.
29 **
30 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31 ** OF MERCHANTABILITY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
32 ** TO THE WARRANTIES FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
33 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
34 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
35 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
36 ** OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 **
38 ****************************************************************************/
44 #ifndef _DRV_I2C_MASTER_H_
45 #define _DRV_I2C_MASTER_H_
46 
47 #ifdef __cplusplus
48 extern "C"{
49 #endif
50 
51 #include "drv_name.h"
52 #include "hal_i2c_master.h"
53 
57 typedef enum
58 {
60  I2C_MASTER_ERROR = (-1)
62 
66 typedef enum
67 {
72 
96 typedef struct
97 {
98  uint8_t addr;
101  pin_name_t scl;
103  uint32_t speed;
104  uint16_t timeout_pass_count;
106 
120 typedef struct
121 {
122  handle_t handle;
123  i2c_master_config_t config;
124 } i2c_master_t;
125 
172 
207 
232 err_t i2c_master_set_speed( i2c_master_t *obj, uint32_t speed );
233 
260 err_t i2c_master_set_timeout( i2c_master_t *obj, uint16_t timeout_pass_count );
261 
287 err_t i2c_master_set_slave_address( i2c_master_t *obj, uint8_t address );
288 
321 err_t i2c_master_write( i2c_master_t *obj, uint8_t *write_data_buf, size_t len_write_data );
322 
355 err_t i2c_master_read( i2c_master_t *obj, uint8_t *read_data_buf, size_t len_read_data );
356 
394 err_t i2c_master_write_then_read( i2c_master_t *obj, uint8_t *write_data_buf, size_t len_write_data, uint8_t *read_data_buf, size_t len_read_data );
395 
421  // drvi2cgroup // drvgroup // pergroup
425 
426 #ifdef __cplusplus
427 }
428 #endif
429 
430 #endif // _DRV_I2C_MASTER_H_
431 // ------------------------------------------------------------------------- END
drv_name.h
Pin and port name type definitions.
i2c_master_err_t
i2c_master_err_t
Definition: drv_i2c_master.h:56
i2c_master_speed_t
i2c_master_speed_t
Definition: drv_i2c_master.h:65
i2c_master_t
I2C Master driver context structure, consisted of the following fields :
Definition: drv_i2c_master.h:119
I2C_MASTER_SPEED_FAST
Definition: drv_i2c_master.h:69
i2c_master_write_then_read
err_t i2c_master_write_then_read(i2c_master_t *obj, uint8_t *write_data_buf, size_t len_write_data, uint8_t *read_data_buf, size_t len_read_data)
Write data to I2C bus followed by read.
i2c_master_set_slave_address
err_t i2c_master_set_slave_address(i2c_master_t *obj, uint8_t address)
Set I2C Slave address.
i2c_master_write
err_t i2c_master_write(i2c_master_t *obj, uint8_t *write_data_buf, size_t len_write_data)
Write data to the I2C bus.
i2c_master_read
err_t i2c_master_read(i2c_master_t *obj, uint8_t *read_data_buf, size_t len_read_data)
Read data from the I2C bus.
I2C_MASTER_ERROR
Definition: drv_i2c_master.h:59
i2c_master_open
err_t i2c_master_open(i2c_master_t *obj, i2c_master_config_t *config)
Open the I2C Master driver object.
i2c_master_set_speed
err_t i2c_master_set_speed(i2c_master_t *obj, uint32_t speed)
Set I2C Master module speed.
hal_i2c_master.h
API for I2C master HAL layer.
i2c_master_configure_default
void i2c_master_configure_default(i2c_master_config_t *config)
Configure I2C Master configuration structure.
i2c_master_set_timeout
err_t i2c_master_set_timeout(i2c_master_t *obj, uint16_t timeout_pass_count)
Set I2C Master timeout value.
I2C_MASTER_SPEED_STANDARD
Definition: drv_i2c_master.h:67
I2C_MASTER_SPEED_FULL
Definition: drv_i2c_master.h:68
I2C_MASTER_SUCCESS
Definition: drv_i2c_master.h:58
pin_name_t
hal_pin_name_t pin_name_t
Definition: drv_name.h:73
err_t
int32_t err_t
Definition: hal_target.h:63
i2c_master_close
err_t i2c_master_close(i2c_master_t *obj)
Close I2C Master driver object.
i2c_master_config_t
I2C Master initialization configuration structure, consisted of the following fields :
Definition: drv_i2c_master.h:95