dualee  2.0.0.0
dualee.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 DUALEE_H
36 #define DUALEE_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define DUALEE_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
65 
71 #define DUALEE_RETVAL uint8_t
72 
73 #define DUALEE_OK 0x00
74 #define DUALEE_INIT_ERROR 0xFF
75 
81 #define DUALEE_SLAVEADDRESS_1 0x50
82 #define DUALEE_SLAVEADDRESS_2 0x54
83 
89 #define DUALEE_ADDRESS_START 0x00000000
90 #define DUALEE_ADDRESS_END 0x0007FFFE
91 
97 #define DUALEE_PAGE_START_OF_FIRST 0x00000000
98 #define DUALEE_PAGE_END_OF_FIRST 0x0003FFFF
99 #define DUALEE_PAGE_START_OF_SECOND 0x00040000
100 #define DUALEE_PAGE_END_OF_SECOND 0x0007FFFE
101 
107 #define DUALEE_MAXIMUM_DATA 251
108 
114 #define DUALEE_ERROR_RW 0
115 #define DUALEE_SUCCESSFUL_RW 1
116  // End group macro
119 // --------------------------------------------------------------- PUBLIC TYPES
128 typedef struct
129 {
130  // Modules
131 
132  i2c_master_t i2c;
133 
134  // ctx variable
135 
136  uint8_t slave_address;
139 
140 } dualee_t;
141 
145 typedef struct
146 {
147  // Communication gpio pins
148 
149  pin_name_t scl;
150  pin_name_t sda;
151 
152  // static variable
153 
154  uint32_t i2c_speed;
155  uint8_t i2c_address;
156  uint8_t i2c_address_1;
157  uint8_t i2c_address_2;
158 
159 } dualee_cfg_t;
160  // End types group
162 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
163 
169 #ifdef __cplusplus
170 extern "C"{
171 #endif
172 
182 
192 
203 void dualee_generic_write ( dualee_t *ctx, uint8_t *reg, uint8_t *data_buf, uint8_t len );
204 
215 void dualee_generic_read ( dualee_t *ctx, uint8_t *reg, uint8_t *data_buf, uint8_t len );
216 
227 uint8_t dualee_write ( dualee_t *ctx, uint32_t reg_address, uint8_t *data_buff, uint8_t n_bytes);
228 
239 uint8_t dualee_read ( dualee_t *ctx, uint32_t reg_address, uint8_t *data_buff, uint8_t n_bytes );
240 
241 
242 #ifdef __cplusplus
243 }
244 #endif
245 #endif // _DUALEE_H_
246  // End public_function group
249 
250 // ------------------------------------------------------------------------- END
dualee_write
uint8_t dualee_write(dualee_t *ctx, uint32_t reg_address, uint8_t *data_buff, uint8_t n_bytes)
Generic write data function.
dualee_cfg_t
Click configuration structure definition.
Definition: dualee.h:146
dualee_cfg_t::i2c_address_2
uint8_t i2c_address_2
Definition: dualee.h:157
dualee_read
uint8_t dualee_read(dualee_t *ctx, uint32_t reg_address, uint8_t *data_buff, uint8_t n_bytes)
Generic write data function.
dualee_t::slave_address_2
uint8_t slave_address_2
Definition: dualee.h:138
dualee_t::slave_address_1
uint8_t slave_address_1
Definition: dualee.h:137
DUALEE_RETVAL
#define DUALEE_RETVAL
Definition: dualee.h:71
dualee_generic_write
void dualee_generic_write(dualee_t *ctx, uint8_t *reg, uint8_t *data_buf, uint8_t len)
Generic write function.
dualee_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: dualee.h:154
dualee_t::slave_address
uint8_t slave_address
Definition: dualee.h:136
dualee_cfg_t::scl
pin_name_t scl
Definition: dualee.h:149
dualee_cfg_setup
void dualee_cfg_setup(dualee_cfg_t *cfg)
Config Object Initialization function.
dualee_init
DUALEE_RETVAL dualee_init(dualee_t *ctx, dualee_cfg_t *cfg)
Initialization function.
dualee_t::i2c
i2c_master_t i2c
Definition: dualee.h:132
dualee_t
Click ctx object definition.
Definition: dualee.h:129
dualee_cfg_t::i2c_address
uint8_t i2c_address
Definition: dualee.h:155
dualee_generic_read
void dualee_generic_read(dualee_t *ctx, uint8_t *reg, uint8_t *data_buf, uint8_t len)
Generic read function.
dualee_cfg_t::i2c_address_1
uint8_t i2c_address_1
Definition: dualee.h:156
dualee_cfg_t::sda
pin_name_t sda
Definition: dualee.h:150