magneto5  2.0.0.0
magneto5.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 MAGNETO5_H
36 #define MAGNETO5_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_i2c_master.h"
50 
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define MAGNETO5_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65 
71 #define MAGNETO5_RETVAL uint8_t
72 
73 #define MAGNETO5_OK 0x00
74 #define MAGNETO5_INIT_ERROR 0xFF
75 
81 #define MAGNETO5_REG_X_OUT_LOW 0x00
82 #define MAGNETO5_REG_X_OUT_HIGH 0x01
83 #define MAGNETO5_REG_Y_OUT_LOW 0x02
84 #define MAGNETO5_REG_Y_OUT_HIGH 0x03
85 #define MAGNETO5_REG_Z_OUT_LOW 0x04
86 #define MAGNETO5_REG_Z_OUT_HIGH 0x05
87 #define MAGNETO5_REG_STATUS 0x06
88 #define MAGNETO5_REG_INTERNAL_CONTROL_0 0x07
89 #define MAGNETO5_REG_INTERNAL_CONTROL_1 0x08
90 #define MAGNETO5_REG_PRODUCT_ID 0x20
91 
97 #define MAGNETO_STATUS_MEASUREMENT_DONE 0x01
98 #define MAGNETO_STATUS_PUMP_ON 0x02
99 #define MAGNETO_STATUS_READ_DONE 0x04
100 #define MAGNETO_STATUS_SELFTEST_OK 0x08
101 #define MAGNETO5_ERROR 0x00
102 #define MAGNETO5_PRODUCT_ID 0x06
103 
109 #define MAGNETO5_AXIS_X 0x00
110 #define MAGNETO5_AXIS_Y 0x02
111 #define MAGNETO5_AXIS_Z 0x04
112 
118 #define MAGNETO5_CR0_RESET 0x40
119 #define MAGNETO5_CR0_SET 0x20
120 #define MAGNETO5_CR0_REFILL_CAP 0x80
121 #define MAGNETO5_CR0_NO_BOOST 0x10
122 #define MAGNETO5_CR0_MEASUREMENT_MODE_0 0x00
123 #define MAGNETO5_CR0_MEASUREMENT_MODE_1 0x04
124 #define MAGNETO5_CR0_MEASUREMENT_MODE_2 0x08
125 #define MAGNETO5_CR0_MEASUREMENT_MODE_3 0x0C
126 #define MAGNETO5_CR0_CONTINUOUS_MODE 0x02
127 #define MAGNETO5_CR0_TAKE_MEASUREMENT 0x01
128 
134 #define MAGNETO5_CR1_SOFT_RESET 0x80
135 #define MAGNETO5_CR1_TEMP_TEST 0x40
136 #define MAGNETO5_CR1_SELFTEST_XYZ 0x20
137 #define MAGNETO5_CR1_FACTORY_USE_X 0x10
138 #define MAGNETO5_CR1_FACTORY_USE_Y 0x08
139 #define MAGNETO5_CR1_FACTORY_USE_Z 0x04
140 #define MAGNETO5_CH0_16bits_8ms 0x00
141 #define MAGNETO5_CH1_16bits_4ms 0x01
142 #define MAGNETO5_CH2_14bits_2ms 0x02
143 #define MAGNETO5_CH3_12bits_1ms 0x03
144  // End group macro
147 // --------------------------------------------------------------- PUBLIC TYPES
156 typedef struct
157 {
158 
159  // Modules
160 
161  i2c_master_t i2c;
162 
163  // ctx variable
164 
165  uint8_t slave_address;
166 
168  uint8_t data_flag;
169 
170 } magneto5_t;
171 
175 typedef struct
176 {
177  // Communication gpio pins
178 
179  pin_name_t scl;
180  pin_name_t sda;
181 
182  // static variable
183 
184  uint32_t i2c_speed;
185  uint8_t i2c_address;
186 
188  // End types group
190 
191 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
192 
198 #ifdef __cplusplus
199 extern "C"{
200 #endif
201 
211 
220 
229 
240 void magneto5_generic_write ( magneto5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
241 
253 void magneto5_generic_read ( magneto5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
254 
264 
274 
285 void magneto5_get_axis_data ( magneto5_t *ctx, int16_t *axis_buffer, uint8_t max_resolution );
286 
297 float magneto5_get_axis_value ( magneto5_t *ctx, uint8_t axis, uint8_t max_resolution );
298 
314 void magneto5_config_register_0 ( magneto5_t *ctx, uint8_t config_data );
315 
329 void magneto5_config_register_1 ( magneto5_t *ctx, uint8_t config_data );
330 
340 
341 #ifdef __cplusplus
342 }
343 #endif
344 #endif // _MAGNETO5_H_
345  // End public_function group
348 
349 // ------------------------------------------------------------------------- END
magneto5_t::slave_address
uint8_t slave_address
Definition: magneto5.h:165
magneto5_t
Click ctx object definition.
Definition: magneto5.h:157
magneto5_get_product_id
uint8_t magneto5_get_product_id(magneto5_t *ctx)
Functions reads product ID from register.
magneto5_config_register_1
void magneto5_config_register_1(magneto5_t *ctx, uint8_t config_data)
Functions sets configuration register 1.
magneto5_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: magneto5.h:184
magneto5_cfg_t::sda
pin_name_t sda
Definition: magneto5.h:180
magneto5_t::i2c
i2c_master_t i2c
Definition: magneto5.h:161
magneto5_get_axis_data
void magneto5_get_axis_data(magneto5_t *ctx, int16_t *axis_buffer, uint8_t max_resolution)
Functions reads axis data.
magneto5_set_status_reg
uint8_t magneto5_set_status_reg(magneto5_t *ctx)
Functions reads status register.
magneto5_reset
void magneto5_reset(magneto5_t *ctx)
Functions for reset data.
magneto5_generic_read
void magneto5_generic_read(magneto5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
magneto5_cfg_t::scl
pin_name_t scl
Definition: magneto5.h:179
magneto5_default_cfg
void magneto5_default_cfg(magneto5_t *ctx)
Click Default Configuration function.
magneto5_cfg_t::i2c_address
uint8_t i2c_address
Definition: magneto5.h:185
magneto5_cfg_t
Click configuration structure definition.
Definition: magneto5.h:176
magneto5_t::max_resolution
float max_resolution
Definition: magneto5.h:167
magneto5_generic_write
void magneto5_generic_write(magneto5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
magneto5_cfg_setup
void magneto5_cfg_setup(magneto5_cfg_t *cfg)
Config Object Initialization function.
MAGNETO5_RETVAL
#define MAGNETO5_RETVAL
Definition: magneto5.h:71
magneto5_t::data_flag
uint8_t data_flag
Definition: magneto5.h:168
magneto5_init
MAGNETO5_RETVAL magneto5_init(magneto5_t *ctx, magneto5_cfg_t *cfg)
Initialization function.
magneto5_config_register_0
void magneto5_config_register_0(magneto5_t *ctx, uint8_t config_data)
Functions sets configuration register 0.
magneto5_get_axis_value
float magneto5_get_axis_value(magneto5_t *ctx, uint8_t axis, uint8_t max_resolution)
Functions reads axis data value.