magneto7  2.0.0.0
magneto7.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 MAGNETO7_H
36 #define MAGNETO7_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_in.h"
53 #include "drv_i2c_master.h"
54 
55 // -------------------------------------------------------------- PUBLIC MACROS
65 #define MAGNETO7_MAP_MIKROBUS( cfg, mikrobus ) \
66  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
67  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
68  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
69 
75 #define MAGNETO7_RETVAL uint8_t
76 
77 #define MAGNETO7_OK 0x00
78 #define MAGNETO7_INIT_ERROR 0xFF
79 
85 #define MAGNETO7_DEV_ADDR_L 0x0E
86 #define MAGNETO7_DEV_ADDR_H 0x0F
87 
93 #define MAGNETO7_INFO_L 0x0D
94 #define MAGNETO7_INFO_H 0x0E
95 #define MAGNETO7_WIA 0x0F
96 #define MAGNETO7_DATA_X_L 0x10
97 #define MAGNETO7_DATA_X_H 0x11
98 #define MAGNETO7_DATA_Y_L 0x12
99 #define MAGNETO7_DATA_Y_H 0x13
100 #define MAGNETO7_DATA_Z_L 0x14
101 #define MAGNETO7_DATA_Z_H 0x15
102 #define MAGNETO7_STA1 0x18
103 #define MAGNETO7_CNTL_1 0x1B
104 #define MAGNETO7_CNTL_2 0x1C
105 #define MAGNETO7_CNTL_3 0x1D
106 #define MAGNETO7_AVE_A 0x40
107 #define MAGNETO7_CNTL_4_L 0x5C
108 #define MAGNETO7_CNTL_4_H 0x5D
109 #define MAGNETO7_TEMP_L 0x60
110 #define MAGNETO7_TEMP_H 0x61
111 #define MAGNETO7_OFF_X_L 0x6C
112 #define MAGNETO7_OFF_X_H 0x6D
113 #define MAGNETO7_OFF_Y_L 0x72
114 #define MAGNETO7_OFF_Y_H 0x73
115 #define MAGNETO7_OFF_Z_L 0x78
116 #define MAGNETO7_OFF_Z_H 0x79
117 #define MAGNETO7_FINEOUTPUTX_L 0x90
118 #define MAGNETO7_FINEOUTPUTX_H 0x91
119 #define MAGNETO7_FINEOUTPUTY_L 0x92
120 #define MAGNETO7_FINEOUTPUTY_H 0x93
121 #define MAGNETO7_FINEOUTPUTZ_L 0x94
122 #define MAGNETO7_FINEOUTPUTZ_H 0x95
123 #define MAGNETO7_GAIN_PARA_X_L 0x9C
124 #define MAGNETO7_GAIN_PARA_X_H 0x9D
125 #define MAGNETO7_GAIN_PARA_Y_L 0x9E
126 #define MAGNETO7_GAIN_PARA_Y_H 0x9F
127 #define MAGNETO7_GAIN_PARA_Z_L 0xA0
128 #define MAGNETO7_GAIN_PARA_Z_H 0xA1
129 
135 #define MAGNETO7_X_AXIS 0x00
136 #define MAGNETO7_Y_AXIS 0x01
137 #define MAGNETO7_Z_AXIS 0x02
138 
144 #define MAGNETO7_SENSOR_RES_12_BIT 0x00
145 #define MAGNETO7_SENSOR_RES_14_BIT 0x01
146  // End group macro
149 // --------------------------------------------------------------- PUBLIC TYPES
158 typedef struct
159 {
160  // Input pins
161 
162  digital_in_t int_pin;
163 
164  // Modules
165 
166  i2c_master_t i2c;
167 
168  // ctx variable
169 
170  uint8_t slave_address;
171 
172  float sensor_res;
173 
174 } magneto7_t;
175 
179 typedef struct
180 {
181  // Communication gpio pins
182 
183  pin_name_t scl;
184  pin_name_t sda;
185 
186  // Additional gpio pins
187 
188  pin_name_t int_pin;
189 
190  // static variable
191 
192  uint32_t i2c_speed;
193  uint8_t i2c_address;
194 
196  // End types group
198 
199 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
200 
206 #ifdef __cplusplus
207 extern "C"{
208 #endif
209 
219 
228 
237 
248 void magneto7_generic_write ( magneto7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
249 
260 void magneto7_generic_read ( magneto7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
261 
269 uint8_t magneto7_int_get ( magneto7_t *ctx );
270 
281 uint8_t magneto7_get_register ( magneto7_t *ctx, uint8_t register_address, uint8_t * data_buffer, uint8_t n_data );
282 
293 uint8_t magneto7_set_register ( magneto7_t *ctx, uint8_t register_address, uint8_t *data_buffer, uint8_t n_data );
294 
304 uint8_t magneto7_set_offset ( magneto7_t *ctx, uint8_t offset_axis, uint8_t offset_value );
305 
314 void magneto7_get_temperature ( magneto7_t *ctx, uint16_t *device_temperature );
315 
326 void magneto7_get_data ( magneto7_t *ctx, int16_t *x_axis, int16_t *y_axis, int16_t *z_axis );
327 
338 void magneto7_get_fine_data ( magneto7_t *ctx, uint16_t *x_axis, uint16_t *y_axis, uint16_t *z_axis );
339 
349 float magneto7_convert_to_ut ( magneto7_t *ctx, int16_t raw_data, uint8_t sensor_resolution );
350 
361 void magneto7_get_gain_para ( magneto7_t *ctx, uint16_t *x_axis, uint16_t *y_axis, uint16_t *z_axis );
362 
363 #ifdef __cplusplus
364 }
365 #endif
366 #endif // _MAGNETO7_H_
367  // End public_function group
370 
371 // ------------------------------------------------------------------------- END
magneto7_get_fine_data
void magneto7_get_fine_data(magneto7_t *ctx, uint16_t *x_axis, uint16_t *y_axis, uint16_t *z_axis)
Getting fine data function.
magneto7_convert_to_ut
float magneto7_convert_to_ut(magneto7_t *ctx, int16_t raw_data, uint8_t sensor_resolution)
Getting fine data function.
magneto7_set_register
uint8_t magneto7_set_register(magneto7_t *ctx, uint8_t register_address, uint8_t *data_buffer, uint8_t n_data)
Setting register value(s) function.
magneto7_t::slave_address
uint8_t slave_address
Definition: magneto7.h:170
magneto7_init
MAGNETO7_RETVAL magneto7_init(magneto7_t *ctx, magneto7_cfg_t *cfg)
Initialization function.
magneto7_get_register
uint8_t magneto7_get_register(magneto7_t *ctx, uint8_t register_address, uint8_t *data_buffer, uint8_t n_data)
Getting register value(s) function.
magneto7_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: magneto7.h:192
magneto7_get_gain_para
void magneto7_get_gain_para(magneto7_t *ctx, uint16_t *x_axis, uint16_t *y_axis, uint16_t *z_axis)
Getting gain data function.
magneto7_t::i2c
i2c_master_t i2c
Definition: magneto7.h:166
magneto7_cfg_t::int_pin
pin_name_t int_pin
Definition: magneto7.h:188
magneto7_cfg_t::scl
pin_name_t scl
Definition: magneto7.h:183
MAGNETO7_RETVAL
#define MAGNETO7_RETVAL
Definition: magneto7.h:75
magneto7_t::sensor_res
float sensor_res
Definition: magneto7.h:172
magneto7_default_cfg
uint8_t magneto7_default_cfg(magneto7_t *ctx)
Click Default Configuration function.
magneto7_generic_write
void magneto7_generic_write(magneto7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
magneto7_cfg_setup
void magneto7_cfg_setup(magneto7_cfg_t *cfg)
Config Object Initialization function.
magneto7_get_temperature
void magneto7_get_temperature(magneto7_t *ctx, uint16_t *device_temperature)
Getting raw device temperature value function.
magneto7_t::int_pin
digital_in_t int_pin
Definition: magneto7.h:162
magneto7_cfg_t
Click configuration structure definition.
Definition: magneto7.h:180
magneto7_set_offset
uint8_t magneto7_set_offset(magneto7_t *ctx, uint8_t offset_axis, uint8_t offset_value)
Setting offset values function.
magneto7_generic_read
void magneto7_generic_read(magneto7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
magneto7_get_data
void magneto7_get_data(magneto7_t *ctx, int16_t *x_axis, int16_t *y_axis, int16_t *z_axis)
Getting data function.
magneto7_int_get
uint8_t magneto7_int_get(magneto7_t *ctx)
Getting INT pin state function.
magneto7_cfg_t::i2c_address
uint8_t i2c_address
Definition: magneto7.h:193
magneto7_t
Click ctx object definition.
Definition: magneto7.h:159
magneto7_cfg_t::sda
pin_name_t sda
Definition: magneto7.h:184