magneticrotary5 2.1.0.0
magneticrotary5.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef MAGNETICROTARY5_H
29#define MAGNETICROTARY5_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_analog_in.h"
52
73#define MAGNETICROTARY5_CMD_WRITE_CONFIG 0x17
74#define MAGNETICROTARY5_CMD_SET_MT_COUNTER 0x14
75#define MAGNETICROTARY5_CMD_EN_PROG 0x10
76#define MAGNETICROTARY5_CMD_RD_MT_COUNTER 0x04
77#define MAGNETICROTARY5_CMD_RD_ANGLE 0x00
78#define MAGNETICROTARY5_CMD_WRITE_OTP 0x1F
79#define MAGNETICROTARY5_CMD_PROG_OTP 0x19
80#define MAGNETICROTARY5_CMD_READ_OTP 0x0F
81#define MAGNETICROTARY5_CMD_READ_ANA 0x09
82
83 // magneticrotary5_reg
84
99#define MAGNETICROTARY5_MASK_AGC_BITS 0x3F
100#define MAGNETICROTARY5_MASK_ANGLE_MSB 0x01
101#define MAGNETICROTARY5_MASK_MT_CNT_MSB 0x01FE
102#define MAGNETICROTARY5_MASK_MT_CNT_LSB 0x01
103#define MAGNETICROTARY5_MASK_5_LSB 0x1F
104#define MAGNETICROTARY5_MASK_3_LSB 0x07
105#define MAGNETICROTARY5_MAX_DATA_LEN 8
106#define MAGNETICROTARY5_MIN_DATA_LEN 1
107#define MAGNETICROTARY5_MAX_MT_CNT 255
108#define MAGNETICROTARY5_MIN_MT_CNT (-256)
109#define MAGNETICROTARY5_DEFAULT_MT_CNT 0
110
115#define MAGNETICROTARY5_VREF_3V3 3.3
116#define MAGNETICROTARY5_VREF_5V 5.0
117
118 // magneticrotary5_set
119
134#define MAGNETICROTARY5_MAP_MIKROBUS( cfg, mikrobus ) \
135 cfg.dio = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
136 cfg.ddclk = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
137 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
138 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN );
139
140 // magneticrotary5_map
141 // magneticrotary5
142
147typedef struct
148{
149 digital_out_t ddclk;
150 digital_out_t cs;
151 pin_name_t dio;
153 analog_in_t adc;
156
161typedef struct
162{
163 pin_name_t ddclk;
164 pin_name_t cs;
165 pin_name_t dio;
166 pin_name_t an;
168 analog_in_resolution_t resolution;
169 float vref;
172
183
200
215
229
244err_t magneticrotary5_write_cmd ( magneticrotary5_t *ctx, uint8_t cmd, uint8_t *data_in, uint8_t len );
245
260err_t magneticrotary5_read_cmd ( magneticrotary5_t *ctx, uint8_t cmd, uint8_t *data_out, uint8_t len );
261
275err_t magneticrotary5_read_angle ( magneticrotary5_t *ctx, uint8_t *agc, uint16_t *angle );
276
289err_t magneticrotary5_read_mt_cnt ( magneticrotary5_t *ctx, int16_t *mt_cnt );
290
302err_t magneticrotary5_set_mt_cnt ( magneticrotary5_t *ctx, int16_t mt_cnt );
303
315err_t magneticrotary5_read_raw_adc ( magneticrotary5_t *ctx, uint16_t *raw_adc );
316
328err_t magneticrotary5_read_voltage ( magneticrotary5_t *ctx, float *voltage );
329
342
343#ifdef __cplusplus
344}
345#endif
346#endif // MAGNETICROTARY5_H
347
348 // magneticrotary5
349
350// ------------------------------------------------------------------------ END
err_t magneticrotary5_set_mt_cnt(magneticrotary5_t *ctx, int16_t mt_cnt)
Magnetic Rotary 5 set multi turn counter function.
err_t magneticrotary5_read_raw_adc(magneticrotary5_t *ctx, uint16_t *raw_adc)
Magnetic Rotary 5 read raw ADC value function.
err_t magneticrotary5_read_angle(magneticrotary5_t *ctx, uint8_t *agc, uint16_t *angle)
Magnetic Rotary 5 read angle function.
err_t magneticrotary5_init(magneticrotary5_t *ctx, magneticrotary5_cfg_t *cfg)
Magnetic Rotary 5 initialization function.
err_t magneticrotary5_read_cmd(magneticrotary5_t *ctx, uint8_t cmd, uint8_t *data_out, uint8_t len)
Magnetic Rotary 5 read cmd function.
err_t magneticrotary5_read_mt_cnt(magneticrotary5_t *ctx, int16_t *mt_cnt)
Magnetic Rotary 5 read multi turn counter function.
err_t magneticrotary5_default_cfg(magneticrotary5_t *ctx)
Magnetic Rotary 5 default configuration function.
err_t magneticrotary5_set_vref(magneticrotary5_t *ctx, float vref)
Magnetic Rotary 5 set vref function.
void magneticrotary5_cfg_setup(magneticrotary5_cfg_t *cfg)
Magnetic Rotary 5 configuration object setup function.
err_t magneticrotary5_read_voltage(magneticrotary5_t *ctx, float *voltage)
Magnetic Rotary 5 read voltage level function.
err_t magneticrotary5_write_cmd(magneticrotary5_t *ctx, uint8_t cmd, uint8_t *data_in, uint8_t len)
Magnetic Rotary 5 write cmd function.
magneticrotary5_return_value_t
Magnetic Rotary 5 Click return value data.
Definition magneticrotary5.h:178
@ MAGNETICROTARY5_OK
Definition magneticrotary5.h:179
@ MAGNETICROTARY5_ERROR
Definition magneticrotary5.h:180
Magnetic Rotary 5 Click configuration object.
Definition magneticrotary5.h:162
analog_in_resolution_t resolution
Definition magneticrotary5.h:168
float vref
Definition magneticrotary5.h:169
pin_name_t dio
Definition magneticrotary5.h:165
pin_name_t an
Definition magneticrotary5.h:166
pin_name_t cs
Definition magneticrotary5.h:164
pin_name_t ddclk
Definition magneticrotary5.h:163
Magnetic Rotary 5 Click context object.
Definition magneticrotary5.h:148
digital_out_t cs
Definition magneticrotary5.h:150
digital_out_t ddclk
Definition magneticrotary5.h:149
pin_name_t dio
Definition magneticrotary5.h:151
analog_in_t adc
Definition magneticrotary5.h:153