magneto8  2.0.0.0
magneto8.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 MAGNETO8_H
36 #define MAGNETO8_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define MAGNETO8_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
56  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
57  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
58 
64 #define MAGNETO8_OK 0
65 #define MAGNETO8_ERROR -1
66 
72 #define MAGNETO8_REG_ZMCO 0x00
73 #define MAGNETO8_REG_ZPOS_MSB 0x01
74 #define MAGNETO8_REG_ZPOS_LSB 0x02
75 #define MAGNETO8_REG_CONF_C1 0x07
76 #define MAGNETO8_REG_CONF_C2 0x08
77 #define MAGNETO8_REG_ABN 0x09
78 #define MAGNETO8_REG_PUSHTHR 0x0A
79 
85 #define MAGNETO8_REG_RAW_ANGLE_MSB 0x0C
86 #define MAGNETO8_REG_RAW_ANGLE_LSB 0x0D
87 #define MAGNETO8_REG_ANGLE_MSB 0x0E
88 #define MAGNETO8_REG_ANGLE_LSB 0x0F
89 
95 #define MAGNETO8_REG_STATUS 0x0B
96 #define MAGNETO8_REG_AGC 0x1A
97 #define MAGNETO8_REG_MAGNITUDE_MSB 0x1B
98 #define MAGNETO8_REG_MAGNITUDE_LSB 0x1C
99 
105 #define MAGNETO8_REG_BURN 0xFF
106 #define MAGNETO8_BURN_ANGLE 0x80
107 #define MAGNETO8_BURN_SETTING 0x40
108 
114 #define MAGNETO8_CFG_MODE_NOM 0x0000
115 #define MAGNETO8_CFG_MODE_LPM1 0x0001
116 #define MAGNETO8_CFG_MODE_LPM2 0x0002
117 #define MAGNETO8_CFG_MODE_LPM3 0x0003
118 
119 #define MAGNETO8_CFG_HYST_OFF 0x0000
120 #define MAGNETO8_CFG_HYST_1_LSB 0x0004
121 #define MAGNETO8_CFG_HYST_2_LSB 0x0008
122 #define MAGNETO8_CFG_HYST_3_LSB 0x000C
123 
124 #define MAGNETO8_CFG_SF_16x 0x0000
125 #define MAGNETO8_CFG_SF_8x 0x0100
126 #define MAGNETO8_CFG_SF_4x 0x0200
127 #define MAGNETO8_CFG_SF_2x 0x0300
128 
129 #define MAGNETO8_CFG_FTH_SLOW 0x0000
130 #define MAGNETO8_CFG_FTH_6_LSB 0x0400
131 #define MAGNETO8_CFG_FTH_7_LSB 0x0800
132 #define MAGNETO8_CFG_FTH_9_LSB 0x0C00
133 #define MAGNETO8_CFG_FTH_18_LSB 0x1000
134 #define MAGNETO8_CFG_FTH_21_LSB 0x1400
135 #define MAGNETO8_CFG_FTH_24_LSB 0x1800
136 #define MAGNETO8_CFG_FTH_10_LSB 0x1C00
137 
138 #define MAGNETO8_CFG_WD_OFF 0x2000
139 #define MAGNETO8_CFG_WD_ON 0x2000
140 
146 #define MAGNETO8_ABN_8 0x00
147 #define MAGNETO8_ABN_16 0x01
148 #define MAGNETO8_ABN_32 0x02
149 #define MAGNETO8_ABN_64 0x03
150 #define MAGNETO8_ABN_128 0x04
151 #define MAGNETO8_ABN_256 0x05
152 #define MAGNETO8_ABN_512 0x06
153 #define MAGNETO8_ABN_1024 0x07
154 #define MAGNETO8_ABN_2048 0x08
155 
161 #define MAGNETO8_STATUS_MD 0x20
162 #define MAGNETO8_STATUS_ML 0x10
163 #define MAGNETO8_STATUS_MH 0x08
164 
165 #define MAGNETO8_SLAVE_ADDR 0x36
166  // End group macro
169 // --------------------------------------------------------------- PUBLIC TYPES
178 typedef struct
179 {
180  // Input pins
181 
182  digital_in_t rst;
183  digital_in_t cs;
184  digital_in_t int_pin;
185 
186  // Modules
187 
188  i2c_master_t i2c;
189 
190  // ctx variable
191 
192  uint8_t slave_address;
193 
194 } magneto8_t;
195 
199 typedef struct
200 {
201  // Communication gpio pins
202 
203  pin_name_t scl;
204  pin_name_t sda;
205 
206  // Additional gpio pins
207 
208  pin_name_t rst;
209  pin_name_t cs;
210  pin_name_t int_pin;
211 
212  // static variable
213 
214  uint32_t i2c_speed;
215  uint8_t i2c_address;
216 
218  // End types group
220 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
221 
227 #ifdef __cplusplus
228 extern "C"{
229 #endif
230 
240 
250 
271 
281 void magneto8_generic_write ( magneto8_t *ctx, uint8_t reg, uint8_t tx_data );
282 
291 uint8_t magneto8_generic_read ( magneto8_t *ctx, uint8_t reg );
292 
301 
310 
319 
328 
336 uint8_t magneto8_get_agc ( magneto8_t *ctx );
337 
345 uint8_t magneto8_get_zmco ( magneto8_t *ctx );
346 
355 
364 
373 
374 #ifdef __cplusplus
375 }
376 #endif
377 #endif // _MAGNETO8_H_
378  // End public_function group
381 
382 // ------------------------------------------------------------------------- END
magneto8_psh_pin_state
uint8_t magneto8_psh_pin_state(magneto8_t *ctx)
Gets PSH pin state.
magneto8_generic_write
void magneto8_generic_write(magneto8_t *ctx, uint8_t reg, uint8_t tx_data)
Generic write function.
magneto8_t::cs
digital_in_t cs
Definition: magneto8.h:183
magneto8_cfg_t::scl
pin_name_t scl
Definition: magneto8.h:203
magneto8_get_agc
uint8_t magneto8_get_agc(magneto8_t *ctx)
Gets AGC data.
magneto8_t::rst
digital_in_t rst
Definition: magneto8.h:182
magneto8_cfg_t::cs
pin_name_t cs
Definition: magneto8.h:209
magneto8_cfg_t::sda
pin_name_t sda
Definition: magneto8.h:204
magneto8_default_cfg
void magneto8_default_cfg(magneto8_t *ctx)
Click Default Configuration function.
magneto8_cfg_setup
void magneto8_cfg_setup(magneto8_cfg_t *cfg)
Config Object Initialization function.
magneto8_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: magneto8.h:214
magneto8_t::i2c
i2c_master_t i2c
Definition: magneto8.h:188
magneto8_get_zmco
uint8_t magneto8_get_zmco(magneto8_t *ctx)
Gets ZMCO data.
magneto8_cfg_t::rst
pin_name_t rst
Definition: magneto8.h:208
magneto8_get_status
uint8_t magneto8_get_status(magneto8_t *ctx)
Gets status data.
magneto8_get_magnitude
uint16_t magneto8_get_magnitude(magneto8_t *ctx)
Gets magnitude data.
magneto8_get_angle_data
float magneto8_get_angle_data(magneto8_t *ctx)
Gets Angle data.
magneto8_cfg_t::i2c_address
uint8_t i2c_address
Definition: magneto8.h:215
magneto8_cfg_t
Click configuration structure definition.
Definition: magneto8.h:200
magneto8_cfg_t::int_pin
pin_name_t int_pin
Definition: magneto8.h:210
magneto8_generic_read
uint8_t magneto8_generic_read(magneto8_t *ctx, uint8_t reg)
Generic read function.
magneto8_t::slave_address
uint8_t slave_address
Definition: magneto8.h:192
magneto8_a_pin_state
uint8_t magneto8_a_pin_state(magneto8_t *ctx)
Gets A pin state.
magneto8_init
err_t magneto8_init(magneto8_t *ctx, magneto8_cfg_t *cfg)
Initialization function.
magneto8_t
Click ctx object definition.
Definition: magneto8.h:179
magneto8_t::int_pin
digital_in_t int_pin
Definition: magneto8.h:184
magneto8_b_pin_state
uint8_t magneto8_b_pin_state(magneto8_t *ctx)
Gets B pin state.
magneto8_get_raw_angle
uint16_t magneto8_get_raw_angle(magneto8_t *ctx)
Gets Angle raw data.