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
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_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
66#define MAGNETO8_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
70 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
71 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
78#define MAGNETO8_OK 0
79#define MAGNETO8_ERROR -1
86#define MAGNETO8_REG_ZMCO 0x00
87#define MAGNETO8_REG_ZPOS_MSB 0x01
88#define MAGNETO8_REG_ZPOS_LSB 0x02
89#define MAGNETO8_REG_CONF_C1 0x07
90#define MAGNETO8_REG_CONF_C2 0x08
91#define MAGNETO8_REG_ABN 0x09
92#define MAGNETO8_REG_PUSHTHR 0x0A
99#define MAGNETO8_REG_RAW_ANGLE_MSB 0x0C
100#define MAGNETO8_REG_RAW_ANGLE_LSB 0x0D
101#define MAGNETO8_REG_ANGLE_MSB 0x0E
102#define MAGNETO8_REG_ANGLE_LSB 0x0F
109#define MAGNETO8_REG_STATUS 0x0B
110#define MAGNETO8_REG_AGC 0x1A
111#define MAGNETO8_REG_MAGNITUDE_MSB 0x1B
112#define MAGNETO8_REG_MAGNITUDE_LSB 0x1C
119#define MAGNETO8_REG_BURN 0xFF
120#define MAGNETO8_BURN_ANGLE 0x80
121#define MAGNETO8_BURN_SETTING 0x40
128#define MAGNETO8_CFG_MODE_NOM 0x0000
129#define MAGNETO8_CFG_MODE_LPM1 0x0001
130#define MAGNETO8_CFG_MODE_LPM2 0x0002
131#define MAGNETO8_CFG_MODE_LPM3 0x0003
132
133#define MAGNETO8_CFG_HYST_OFF 0x0000
134#define MAGNETO8_CFG_HYST_1_LSB 0x0004
135#define MAGNETO8_CFG_HYST_2_LSB 0x0008
136#define MAGNETO8_CFG_HYST_3_LSB 0x000C
137
138#define MAGNETO8_CFG_SF_16x 0x0000
139#define MAGNETO8_CFG_SF_8x 0x0100
140#define MAGNETO8_CFG_SF_4x 0x0200
141#define MAGNETO8_CFG_SF_2x 0x0300
142
143#define MAGNETO8_CFG_FTH_SLOW 0x0000
144#define MAGNETO8_CFG_FTH_6_LSB 0x0400
145#define MAGNETO8_CFG_FTH_7_LSB 0x0800
146#define MAGNETO8_CFG_FTH_9_LSB 0x0C00
147#define MAGNETO8_CFG_FTH_18_LSB 0x1000
148#define MAGNETO8_CFG_FTH_21_LSB 0x1400
149#define MAGNETO8_CFG_FTH_24_LSB 0x1800
150#define MAGNETO8_CFG_FTH_10_LSB 0x1C00
151
152#define MAGNETO8_CFG_WD_OFF 0x2000
153#define MAGNETO8_CFG_WD_ON 0x2000
160#define MAGNETO8_ABN_8 0x00
161#define MAGNETO8_ABN_16 0x01
162#define MAGNETO8_ABN_32 0x02
163#define MAGNETO8_ABN_64 0x03
164#define MAGNETO8_ABN_128 0x04
165#define MAGNETO8_ABN_256 0x05
166#define MAGNETO8_ABN_512 0x06
167#define MAGNETO8_ABN_1024 0x07
168#define MAGNETO8_ABN_2048 0x08
175#define MAGNETO8_STATUS_MD 0x20
176#define MAGNETO8_STATUS_ML 0x10
177#define MAGNETO8_STATUS_MH 0x08
178
179#define MAGNETO8_SLAVE_ADDR 0x36
182 // End group macro
183// --------------------------------------------------------------- PUBLIC TYPES
192typedef struct
193{
194 // Input pins
195
196 digital_in_t rst;
197 digital_in_t cs;
198 digital_in_t int_pin;
199
200 // Modules
201
202 i2c_master_t i2c;
203
204 // ctx variable
205
207
208} magneto8_t;
209
213typedef struct
214{
215 // Communication gpio pins
216
217 pin_name_t scl;
218 pin_name_t sda;
219
220 // Additional gpio pins
221
222 pin_name_t rst;
223 pin_name_t cs;
224 pin_name_t int_pin;
225
226 // static variable
227
228 uint32_t i2c_speed;
229 uint8_t i2c_address;
230
232
233 // End types group
234// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
235
241#ifdef __cplusplus
242extern "C"{
243#endif
244
254
264
285
295void magneto8_generic_write ( magneto8_t *ctx, uint8_t reg, uint8_t tx_data );
296
305uint8_t magneto8_generic_read ( magneto8_t *ctx, uint8_t reg );
306
315
324
333
342
351
360
369
378
387
388#ifdef __cplusplus
389}
390#endif
391#endif // _MAGNETO8_H_
392
393 // End public_function group
395
396// ------------------------------------------------------------------------- END
uint8_t magneto8_generic_read(magneto8_t *ctx, uint8_t reg)
Generic read function.
err_t magneto8_init(magneto8_t *ctx, magneto8_cfg_t *cfg)
Initialization function.
uint8_t magneto8_get_status(magneto8_t *ctx)
Gets status data.
uint8_t magneto8_a_pin_state(magneto8_t *ctx)
Gets A pin state.
void magneto8_cfg_setup(magneto8_cfg_t *cfg)
Config Object Initialization function.
float magneto8_get_angle_data(magneto8_t *ctx)
Gets Angle data.
void magneto8_generic_write(magneto8_t *ctx, uint8_t reg, uint8_t tx_data)
Generic write function.
uint16_t magneto8_get_raw_angle(magneto8_t *ctx)
Gets Angle raw data.
uint8_t magneto8_get_zmco(magneto8_t *ctx)
Gets ZMCO data.
uint8_t magneto8_psh_pin_state(magneto8_t *ctx)
Gets PSH pin state.
uint8_t magneto8_b_pin_state(magneto8_t *ctx)
Gets B pin state.
uint8_t magneto8_get_agc(magneto8_t *ctx)
Gets AGC data.
void magneto8_default_cfg(magneto8_t *ctx)
Click Default Configuration function.
uint16_t magneto8_get_magnitude(magneto8_t *ctx)
Gets magnitude data.
Click configuration structure definition.
Definition magneto8.h:214
uint32_t i2c_speed
Definition magneto8.h:228
pin_name_t scl
Definition magneto8.h:217
pin_name_t int_pin
Definition magneto8.h:224
pin_name_t sda
Definition magneto8.h:218
pin_name_t rst
Definition magneto8.h:222
pin_name_t cs
Definition magneto8.h:223
uint8_t i2c_address
Definition magneto8.h:229
Click ctx object definition.
Definition magneto8.h:193
digital_in_t cs
Definition magneto8.h:197
digital_in_t int_pin
Definition magneto8.h:198
i2c_master_t i2c
Definition magneto8.h:202
digital_in_t rst
Definition magneto8.h:196
uint8_t slave_address
Definition magneto8.h:206