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_RETVAL uint8_t
65 
66 #define MAGNETO8_OK 0x00
67 #define MAGNETO8_INIT_ERROR 0xFF
68 
74 #define MAGNETO8_REG_ZMCO 0x00
75 #define MAGNETO8_REG_ZPOS_MSB 0x01
76 #define MAGNETO8_REG_ZPOS_LSB 0x02
77 #define MAGNETO8_REG_CONF_C1 0x07
78 #define MAGNETO8_REG_CONF_C2 0x08
79 #define MAGNETO8_REG_ABN 0x09
80 #define MAGNETO8_REG_PUSHTHR 0x0A
81 
87 #define MAGNETO8_REG_RAW_ANGLE_MSB 0x0C
88 #define MAGNETO8_REG_RAW_ANGLE_LSB 0x0D
89 #define MAGNETO8_REG_ANGLE_MSB 0x0E
90 #define MAGNETO8_REG_ANGLE_LSB 0x0F
91 
97 #define MAGNETO8_REG_STATUS 0x0B
98 #define MAGNETO8_REG_AGC 0x1A
99 #define MAGNETO8_REG_MAGNITUDE_MSB 0x1B
100 #define MAGNETO8_REG_MAGNITUDE_LSB 0x1C
101 
107 #define MAGNETO8_REG_BURN 0xFF
108 #define MAGNETO8_BURN_ANGLE 0x80
109 #define MAGNETO8_BURN_SETTING 0x40
110 
116 #define MAGNETO8_CFG_MODE_NOM 0x0000
117 #define MAGNETO8_CFG_MODE_LPM1 0x0001
118 #define MAGNETO8_CFG_MODE_LPM2 0x0002
119 #define MAGNETO8_CFG_MODE_LPM3 0x0003
120 
121 #define MAGNETO8_CFG_HYST_OFF 0x0000
122 #define MAGNETO8_CFG_HYST_1_LSB 0x0004
123 #define MAGNETO8_CFG_HYST_2_LSB 0x0008
124 #define MAGNETO8_CFG_HYST_3_LSB 0x000C
125 
126 #define MAGNETO8_CFG_SF_16x 0x0000
127 #define MAGNETO8_CFG_SF_8x 0x0100
128 #define MAGNETO8_CFG_SF_4x 0x0200
129 #define MAGNETO8_CFG_SF_2x 0x0300
130 
131 #define MAGNETO8_CFG_FTH_SLOW 0x0000
132 #define MAGNETO8_CFG_FTH_6_LSB 0x0400
133 #define MAGNETO8_CFG_FTH_7_LSB 0x0800
134 #define MAGNETO8_CFG_FTH_9_LSB 0x0C00
135 #define MAGNETO8_CFG_FTH_18_LSB 0x1000
136 #define MAGNETO8_CFG_FTH_21_LSB 0x1400
137 #define MAGNETO8_CFG_FTH_24_LSB 0x1800
138 #define MAGNETO8_CFG_FTH_10_LSB 0x1C00
139 
140 #define MAGNETO8_CFG_WD_OFF 0x2000
141 #define MAGNETO8_CFG_WD_ON 0x2000
142 
148 #define MAGNETO8_ABN_8 0x00
149 #define MAGNETO8_ABN_16 0x01
150 #define MAGNETO8_ABN_32 0x02
151 #define MAGNETO8_ABN_64 0x03
152 #define MAGNETO8_ABN_128 0x04
153 #define MAGNETO8_ABN_256 0x05
154 #define MAGNETO8_ABN_512 0x06
155 #define MAGNETO8_ABN_1024 0x07
156 #define MAGNETO8_ABN_2048 0x08
157 
163 #define MAGNETO8_STATUS_MD 0x20
164 #define MAGNETO8_STATUS_ML 0x10
165 #define MAGNETO8_STATUS_MH 0x08
166 
167 #define MAGNETO8_SLAVE_ADDR 0x36
168  // End group macro
171 // --------------------------------------------------------------- PUBLIC TYPES
180 typedef struct
181 {
182  // Input pins
183 
184  digital_in_t rst;
185  digital_in_t cs;
186  digital_in_t int_pin;
187 
188  // Modules
189 
190  i2c_master_t i2c;
191 
192  // ctx variable
193 
194  uint8_t slave_address;
195 
196 } magneto8_t;
197 
201 typedef struct
202 {
203  // Communication gpio pins
204 
205  pin_name_t scl;
206  pin_name_t sda;
207 
208  // Additional gpio pins
209 
210  pin_name_t rst;
211  pin_name_t cs;
212  pin_name_t int_pin;
213 
214  // static variable
215 
216  uint32_t i2c_speed;
217  uint8_t i2c_address;
218 
220  // End types group
222 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
223 
229 #ifdef __cplusplus
230 extern "C"{
231 #endif
232 
241 void magneto8_cfg_setup ( magneto8_cfg_t *cfg );
242 
252 
272 void magneto8_default_cfg ( magneto8_t *ctx );
273 
283 void magneto8_generic_write ( magneto8_t *ctx, uint8_t reg, uint8_t tx_data );
284 
293 uint8_t magneto8_generic_read ( magneto8_t *ctx, uint8_t reg );
294 
302 uint16_t magneto8_get_raw_angle ( magneto8_t *ctx );
303 
311 uint16_t magneto8_get_angle_data ( magneto8_t *ctx );
312 
320 uint8_t magneto8_get_status ( magneto8_t *ctx );
321 
329 uint16_t magneto8_get_magnitude ( magneto8_t *ctx );
330 
338 uint8_t magneto8_get_agc ( magneto8_t *ctx );
339 
347 uint8_t magneto8_get_zmco ( magneto8_t *ctx );
348 
356 uint8_t magneto8_a_pin_state ( magneto8_t *ctx );
357 
365 uint8_t magneto8_b_pin_state ( magneto8_t *ctx );
366 
374 uint8_t magneto8_psh_pin_state ( magneto8_t *ctx );
375 
376 #ifdef __cplusplus
377 }
378 #endif
379 #endif // _MAGNETO8_H_
380  // End public_function group
383 
384 // ------------------------------------------------------------------------- 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:185
magneto8_cfg_t::scl
pin_name_t scl
Definition: magneto8.h:205
magneto8_get_agc
uint8_t magneto8_get_agc(magneto8_t *ctx)
Gets AGC data.
MAGNETO8_RETVAL
#define MAGNETO8_RETVAL
Definition: magneto8.h:64
magneto8_t::rst
digital_in_t rst
Definition: magneto8.h:184
magneto8_cfg_t::cs
pin_name_t cs
Definition: magneto8.h:211
magneto8_cfg_t::sda
pin_name_t sda
Definition: magneto8.h:206
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:216
magneto8_t::i2c
i2c_master_t i2c
Definition: magneto8.h:190
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:210
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_cfg_t::i2c_address
uint8_t i2c_address
Definition: magneto8.h:217
magneto8_cfg_t
Click configuration structure definition.
Definition: magneto8.h:201
magneto8_cfg_t::int_pin
pin_name_t int_pin
Definition: magneto8.h:212
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:194
magneto8_init
MAGNETO8_RETVAL magneto8_init(magneto8_t *ctx, magneto8_cfg_t *cfg)
Initialization function.
magneto8_get_angle_data
uint16_t magneto8_get_angle_data(magneto8_t *ctx)
Gets Angle data.
magneto8_a_pin_state
uint8_t magneto8_a_pin_state(magneto8_t *ctx)
Gets A pin state.
magneto8_t
Click ctx object definition.
Definition: magneto8.h:180
magneto8_t::int_pin
digital_in_t int_pin
Definition: magneto8.h:186
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.