c8pini2c  2.0.0.0
c8pini2c.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef C8PINI2C_H
36 #define C8PINI2C_H
37 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 #include "drv_i2c_master.h"
55 
56 // -------------------------------------------------------------- PUBLIC MACROS
66 #define C8PINI2C_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
69 
75 #define C8PINI2C_RETVAL uint8_t
76 
77 #define C8PINI2C_OK 0x00
78 #define C8PINI2C_INIT_ERROR 0xFF
79  // End group macro
82 // --------------------------------------------------------------- PUBLIC TYPES
91 typedef struct
92 {
93  // Modules
94 
95  i2c_master_t i2c;
96 
97 } c8pini2c_t;
98 
102 typedef struct
103 {
104  // Communication gpio pins
105 
106  pin_name_t scl;
107  pin_name_t sda;
108 
109  // static variable
110 
111  uint32_t i2c_speed;
112 
114  // End types group
116 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
117 
123 #ifdef __cplusplus
124 extern "C"{
125 #endif
126 
136 
145 
157 void c8pini2c_generic_write ( c8pini2c_t *ctx, uint8_t slave_addr, uint8_t reg, uint8_t *data_buf, uint8_t len );
158 
171 void c8pini2c_generic_read ( c8pini2c_t *ctx, uint8_t slave_addr, uint8_t reg, uint8_t *data_buf, uint8_t len );
172 
173 #ifdef __cplusplus
174 }
175 #endif
176 #endif // _C8PINI2C_H_
177  // End public_function group
180 
181 // ------------------------------------------------------------------------- END
c8pini2c_cfg_setup
void c8pini2c_cfg_setup(c8pini2c_cfg_t *cfg)
Config Object Initialization function.
c8pini2c_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: c8pini2c.h:111
c8pini2c_cfg_t::sda
pin_name_t sda
Definition: c8pini2c.h:107
c8pini2c_t::i2c
i2c_master_t i2c
Definition: c8pini2c.h:95
C8PINI2C_RETVAL
#define C8PINI2C_RETVAL
Definition: c8pini2c.h:75
c8pini2c_generic_write
void c8pini2c_generic_write(c8pini2c_t *ctx, uint8_t slave_addr, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
c8pini2c_cfg_t::scl
pin_name_t scl
Definition: c8pini2c.h:106
c8pini2c_generic_read
void c8pini2c_generic_read(c8pini2c_t *ctx, uint8_t slave_addr, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
c8pini2c_cfg_t
Click configuration structure definition.
Definition: c8pini2c.h:103
c8pini2c_t
Click ctx object definition.
Definition: c8pini2c.h:92
c8pini2c_init
C8PINI2C_RETVAL c8pini2c_init(c8pini2c_t *ctx, c8pini2c_cfg_t *cfg)
Initialization function.