hallcurrent2  2.0.0.0
hallcurrent2.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 HALLCURRENT2_H
36 #define HALLCURRENT2_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 HALLCURRENT2_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
66  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
67 
73 #define HALLCURRENT2_RETVAL uint8_t
74 
75 #define HALLCURRENT2_OK 0x00
76 #define HALLCURRENT2_INIT_ERROR 0xFF
77  // End group macro
80 // --------------------------------------------------------------- PUBLIC TYPES
89 typedef struct
90 {
91  // Output pins
92 
93  digital_out_t rst;
94 
95  // Input pins
96 
97  digital_in_t int_pin;
98 
99  // Modules
100 
101  i2c_master_t i2c;
102 
103  // ctx variable
104 
105  uint8_t slave_address;
106 
108 
112 typedef struct
113 {
114  // Communication gpio pins
115 
116  pin_name_t scl;
117  pin_name_t sda;
118 
119  // Additional gpio pins
120 
121  pin_name_t rst;
122  pin_name_t int_pin;
123 
124  // static variable
125 
126  uint32_t i2c_speed;
127  uint8_t i2c_address;
128 
130  // End types group
132 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
133 
139 #ifdef __cplusplus
140 extern "C"{
141 #endif
142 
152 
162 
174 
185 
197 
198 #ifdef __cplusplus
199 }
200 #endif
201 #endif // _HALLCURRENT2_H_
202  // End public_function group
205 
206 // ------------------------------------------------------------------------- END
hallcurrent2_generic_read
uint16_t hallcurrent2_generic_read(hallcurrent2_t *ctx)
Generic read function.
hallcurrent2_cfg_setup
void hallcurrent2_cfg_setup(hallcurrent2_cfg_t *cfg)
Config Object Initialization function.
hallcurrent2_cfg_t::int_pin
pin_name_t int_pin
Definition: hallcurrent2.h:122
hallcurrent2_cfg_t::i2c_address
uint8_t i2c_address
Definition: hallcurrent2.h:127
hallcurrent2_t::slave_address
uint8_t slave_address
Definition: hallcurrent2.h:105
hallcurrent2_cfg_t::sda
pin_name_t sda
Definition: hallcurrent2.h:117
hallcurrent2_t::rst
digital_out_t rst
Definition: hallcurrent2.h:93
HALLCURRENT2_RETVAL
#define HALLCURRENT2_RETVAL
Definition: hallcurrent2.h:73
hallcurrent2_get_current
int16_t hallcurrent2_get_current(hallcurrent2_t *ctx)
Reads current in mV.
hallcurrent2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: hallcurrent2.h:126
hallcurrent2_t::int_pin
digital_in_t int_pin
Definition: hallcurrent2.h:97
hallcurrent2_reset
void hallcurrent2_reset(hallcurrent2_t *ctx)
Functions for reset chip.
hallcurrent2_cfg_t::scl
pin_name_t scl
Definition: hallcurrent2.h:116
hallcurrent2_init
HALLCURRENT2_RETVAL hallcurrent2_init(hallcurrent2_t *ctx, hallcurrent2_cfg_t *cfg)
Initialization function.
hallcurrent2_t::i2c
i2c_master_t i2c
Definition: hallcurrent2.h:101
hallcurrent2_cfg_t
Click configuration structure definition.
Definition: hallcurrent2.h:113
hallcurrent2_t
Click ctx object definition.
Definition: hallcurrent2.h:90
hallcurrent2_cfg_t::rst
pin_name_t rst
Definition: hallcurrent2.h:121