mikroSDK Reference Manual
hal_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 _HAL_I2C_MASTER_H_
45 #define _HAL_I2C_MASTER_H_
46 
47 #ifdef __cplusplus
48 extern "C"{
49 #endif
50 
51 #include "hal_target.h"
52 
60 typedef struct
61 {
62  handle_t *hal_i2c_master_handle;
63  handle_t *drv_i2c_master_handle;
64  bool init_state;
66 
70 typedef enum
71 {
76  HAL_I2C_MASTER_ERROR = (-1)
78 
82 typedef enum
83 {
91 
95 typedef enum
96 {
101 
125 typedef struct
126 {
127  uint8_t addr;
130  hal_pin_name_t scl;
132  uint32_t speed;
133  uint16_t timeout_pass_count;
135 
148 typedef struct
149 {
150  handle_t handle;
151  hal_i2c_master_config_t config;
153 
200 
230 err_t hal_i2c_master_open( handle_t *handle, bool hal_obj_open_state );
231 
254 err_t hal_i2c_master_set_speed( handle_t *handle, hal_i2c_master_config_t *config );
255 
280 void hal_i2c_master_set_timeout( handle_t *handle, hal_i2c_master_config_t *config );
281 
305 void hal_i2c_master_set_slave_address( handle_t *handle, hal_i2c_master_config_t *config );
306 
334 err_t hal_i2c_master_write( handle_t handle, uint8_t *write_data_buf, size_t len_write_data );
335 
363 err_t hal_i2c_master_read( handle_t handle, uint8_t *read_data_buf, size_t len_read_data );
364 
396 err_t hal_i2c_master_write_then_read( handle_t handle, uint8_t *write_data_buf, size_t len_write_data, uint8_t *read_data_buf, size_t len_read_data );
397 
414 err_t hal_i2c_master_close( handle_t *handle );
415  // hali2cgroup // halgroup // pergroup
419 
420 #ifdef __cplusplus
421 }
422 #endif
423 
424 #endif // _HAL_I2C_MASTER_H_
425 // ------------------------------------------------------------------------- END
HAL_I2C_MASTER_TIMEOUT_STOP
Definition: hal_i2c_master.h:84
hal_i2c_master_set_speed
err_t hal_i2c_master_set_speed(handle_t *handle, hal_i2c_master_config_t *config)
Set I2C master module speed.
HAL_I2C_MASTER_SPEED_FULL
Definition: hal_i2c_master.h:97
hal_i2c_master_timeout_t
hal_i2c_master_timeout_t
Definition: hal_i2c_master.h:81
HAL_I2C_MASTER_WRONG_PINS
Definition: hal_i2c_master.h:72
hal_i2c_master_close
err_t hal_i2c_master_close(handle_t *handle)
Closes I2C Master HAL object.
hal_i2c_master_handle_register_t
Definition: hal_i2c_master.h:59
hal_target.h
HAL target macros and typedefs.
HAL_I2C_MASTER_TIMEOUT_READ
Definition: hal_i2c_master.h:86
HAL_I2C_MASTER_MODULE_ERROR
Definition: hal_i2c_master.h:73
hal_pin_name_t
hal_ll_pin_name_t hal_pin_name_t
Definition: hal_target.h:59
HAL_I2C_MASTER_ARBITRATION_LOST
Definition: hal_i2c_master.h:87
HAL_I2C_MASTER_SPEED_FAST
Definition: hal_i2c_master.h:98
HAL_I2C_MASTER_SUCCESS
Definition: hal_i2c_master.h:71
hal_i2c_master_write_then_read
err_t hal_i2c_master_write_then_read(handle_t handle, uint8_t *write_data_buf, size_t len_write_data, uint8_t *read_data_buf, size_t len_read_data)
Write data followed by read.
hal_i2c_master_config_t
I2C Master HAL init configuration structure, consisted of the following fields :
Definition: hal_i2c_master.h:124
hal_i2c_master_write
err_t hal_i2c_master_write(handle_t handle, uint8_t *write_data_buf, size_t len_write_data)
Write data to the I2C bus.
hal_i2c_master_t
I2C Master HAL context structure, consisted of the following fields :
Definition: hal_i2c_master.h:147
hal_i2c_master_speed_t
hal_i2c_master_speed_t
Definition: hal_i2c_master.h:94
hal_i2c_master_set_slave_address
void hal_i2c_master_set_slave_address(handle_t *handle, hal_i2c_master_config_t *config)
Set I2C slave address.
hal_i2c_master_open
err_t hal_i2c_master_open(handle_t *handle, bool hal_obj_open_state)
Open the I2C Master HAL object.
HAL_I2C_MASTER_SPEED_STANDARD
Definition: hal_i2c_master.h:96
HAL_I2C_MASTER_TIMEOUT_INIT
Definition: hal_i2c_master.h:88
HAL_I2C_MASTER_TIMEOUT_WRITE
Definition: hal_i2c_master.h:85
HAL_I2C_MASTER_TIMEOUT_START
Definition: hal_i2c_master.h:83
hal_i2c_master_err_t
hal_i2c_master_err_t
Definition: hal_i2c_master.h:69
hal_i2c_master_set_timeout
void hal_i2c_master_set_timeout(handle_t *handle, hal_i2c_master_config_t *config)
Set I2C master timeout value.
err_t
int32_t err_t
Definition: hal_target.h:63
hal_i2c_master_read
err_t hal_i2c_master_read(handle_t handle, uint8_t *read_data_buf, size_t len_read_data)
Read data from the I2C bus.
hal_i2c_master_configure_default
void hal_i2c_master_configure_default(hal_i2c_master_config_t *config)
Configure I2C Master HAL configuration structure.
HAL_I2C_MASTER_ERROR
Definition: hal_i2c_master.h:75