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 "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 MAGNETO8_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.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
67  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
68 
74 #define MAGNETO8_OK 0
75 #define MAGNETO8_ERROR -1
76 
82 #define MAGNETO8_REG_ZMCO 0x00
83 #define MAGNETO8_REG_ZPOS_MSB 0x01
84 #define MAGNETO8_REG_ZPOS_LSB 0x02
85 #define MAGNETO8_REG_CONF_C1 0x07
86 #define MAGNETO8_REG_CONF_C2 0x08
87 #define MAGNETO8_REG_ABN 0x09
88 #define MAGNETO8_REG_PUSHTHR 0x0A
89 
95 #define MAGNETO8_REG_RAW_ANGLE_MSB 0x0C
96 #define MAGNETO8_REG_RAW_ANGLE_LSB 0x0D
97 #define MAGNETO8_REG_ANGLE_MSB 0x0E
98 #define MAGNETO8_REG_ANGLE_LSB 0x0F
99 
105 #define MAGNETO8_REG_STATUS 0x0B
106 #define MAGNETO8_REG_AGC 0x1A
107 #define MAGNETO8_REG_MAGNITUDE_MSB 0x1B
108 #define MAGNETO8_REG_MAGNITUDE_LSB 0x1C
109 
115 #define MAGNETO8_REG_BURN 0xFF
116 #define MAGNETO8_BURN_ANGLE 0x80
117 #define MAGNETO8_BURN_SETTING 0x40
118 
124 #define MAGNETO8_CFG_MODE_NOM 0x0000
125 #define MAGNETO8_CFG_MODE_LPM1 0x0001
126 #define MAGNETO8_CFG_MODE_LPM2 0x0002
127 #define MAGNETO8_CFG_MODE_LPM3 0x0003
128 
129 #define MAGNETO8_CFG_HYST_OFF 0x0000
130 #define MAGNETO8_CFG_HYST_1_LSB 0x0004
131 #define MAGNETO8_CFG_HYST_2_LSB 0x0008
132 #define MAGNETO8_CFG_HYST_3_LSB 0x000C
133 
134 #define MAGNETO8_CFG_SF_16x 0x0000
135 #define MAGNETO8_CFG_SF_8x 0x0100
136 #define MAGNETO8_CFG_SF_4x 0x0200
137 #define MAGNETO8_CFG_SF_2x 0x0300
138 
139 #define MAGNETO8_CFG_FTH_SLOW 0x0000
140 #define MAGNETO8_CFG_FTH_6_LSB 0x0400
141 #define MAGNETO8_CFG_FTH_7_LSB 0x0800
142 #define MAGNETO8_CFG_FTH_9_LSB 0x0C00
143 #define MAGNETO8_CFG_FTH_18_LSB 0x1000
144 #define MAGNETO8_CFG_FTH_21_LSB 0x1400
145 #define MAGNETO8_CFG_FTH_24_LSB 0x1800
146 #define MAGNETO8_CFG_FTH_10_LSB 0x1C00
147 
148 #define MAGNETO8_CFG_WD_OFF 0x2000
149 #define MAGNETO8_CFG_WD_ON 0x2000
150 
156 #define MAGNETO8_ABN_8 0x00
157 #define MAGNETO8_ABN_16 0x01
158 #define MAGNETO8_ABN_32 0x02
159 #define MAGNETO8_ABN_64 0x03
160 #define MAGNETO8_ABN_128 0x04
161 #define MAGNETO8_ABN_256 0x05
162 #define MAGNETO8_ABN_512 0x06
163 #define MAGNETO8_ABN_1024 0x07
164 #define MAGNETO8_ABN_2048 0x08
165 
171 #define MAGNETO8_STATUS_MD 0x20
172 #define MAGNETO8_STATUS_ML 0x10
173 #define MAGNETO8_STATUS_MH 0x08
174 
175 #define MAGNETO8_SLAVE_ADDR 0x36
176  // End group macro
179 // --------------------------------------------------------------- PUBLIC TYPES
188 typedef struct
189 {
190  // Input pins
191 
192  digital_in_t rst;
193  digital_in_t cs;
194  digital_in_t int_pin;
195 
196  // Modules
197 
198  i2c_master_t i2c;
199 
200  // ctx variable
201 
202  uint8_t slave_address;
203 
204 } magneto8_t;
205 
209 typedef struct
210 {
211  // Communication gpio pins
212 
213  pin_name_t scl;
214  pin_name_t sda;
215 
216  // Additional gpio pins
217 
218  pin_name_t rst;
219  pin_name_t cs;
220  pin_name_t int_pin;
221 
222  // static variable
223 
224  uint32_t i2c_speed;
225  uint8_t i2c_address;
226 
228  // End types group
230 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
231 
237 #ifdef __cplusplus
238 extern "C"{
239 #endif
240 
250 
260 
281 
291 void magneto8_generic_write ( magneto8_t *ctx, uint8_t reg, uint8_t tx_data );
292 
301 uint8_t magneto8_generic_read ( magneto8_t *ctx, uint8_t reg );
302 
311 
320 
329 
338 
346 uint8_t magneto8_get_agc ( magneto8_t *ctx );
347 
355 uint8_t magneto8_get_zmco ( magneto8_t *ctx );
356 
365 
374 
383 
384 #ifdef __cplusplus
385 }
386 #endif
387 #endif // _MAGNETO8_H_
388  // End public_function group
391 
392 // ------------------------------------------------------------------------- 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:193
magneto8_cfg_t::scl
pin_name_t scl
Definition: magneto8.h:213
magneto8_get_agc
uint8_t magneto8_get_agc(magneto8_t *ctx)
Gets AGC data.
magneto8_t::rst
digital_in_t rst
Definition: magneto8.h:192
magneto8_cfg_t::cs
pin_name_t cs
Definition: magneto8.h:219
magneto8_cfg_t::sda
pin_name_t sda
Definition: magneto8.h:214
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:224
magneto8_t::i2c
i2c_master_t i2c
Definition: magneto8.h:198
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:218
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:225
magneto8_cfg_t
Click configuration structure definition.
Definition: magneto8.h:210
magneto8_cfg_t::int_pin
pin_name_t int_pin
Definition: magneto8.h:220
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:202
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:189
magneto8_t::int_pin
digital_in_t int_pin
Definition: magneto8.h:194
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.