magneticrotary6  2.0.0.0
magneticrotary6.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 MAGNETICROTARY6_H
29 #define MAGNETICROTARY6_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
38 #include "spi_specifics.h"
39 
60 #define MAGNETICROTARY6_REG_NOP 0x0000u
61 #define MAGNETICROTARY6_REG_ERRFL 0x0001u
62 #define MAGNETICROTARY6_REG_PROG 0x0003u
63 #define MAGNETICROTARY6_REG_DIA 0x3FF5u
64 #define MAGNETICROTARY6_REG_AGC 0x3FF9u
65 #define MAGNETICROTARY6_REG_SIN_DATA 0x3FFAu
66 #define MAGNETICROTARY6_REG_COS_DATA 0x3FFBu
67 #define MAGNETICROTARY6_REG_VEL 0x3FFCu
68 #define MAGNETICROTARY6_REG_MAG 0x3FFDu
69 #define MAGNETICROTARY6_REG_ANGLEUNC 0x3FFEu
70 #define MAGNETICROTARY6_REG_ANGLECOM 0x3FFFu
71 #define MAGNETICROTARY6_REG_ECC_CHECKSUM 0x00D1u
72 
77 #define MAGNETICROTARY6_REG_DISABLE 0x0015u
78 #define MAGNETICROTARY6_REG_ZPOSM 0x0016u
79 #define MAGNETICROTARY6_REG_ZPOSL 0x0017u
80 #define MAGNETICROTARY6_REG_SETTINGS1 0x0018u
81 #define MAGNETICROTARY6_REG_SETTINGS2 0x0019u
82 #define MAGNETICROTARY6_REG_SETTINGS3 0x001Au
83 #define MAGNETICROTARY6_REG_ECC 0x001Bu
84  // magneticrotary6_reg
86 
101 #define MAGNETICROTARY6_ERRFL_CORDIC_OF 0x0400u
102 #define MAGNETICROTARY6_ERRFL_OFF_COMP_NOT_FIN 0x0200u
103 #define MAGNETICROTARY6_ERRFL_BRKHALL 0x0100u
104 #define MAGNETICROTARY6_ERRFL_WDTST 0x0080u
105 #define MAGNETICROTARY6_ERRFL_CRC_ERROR 0x0040u
106 #define MAGNETICROTARY6_ERRFL_CMD_ERROR 0x0020u
107 #define MAGNETICROTARY6_ERRFL_FRAMING_ERROR 0x0010u
108 #define MAGNETICROTARY6_ERRFL_P2RAM_ERROR 0x0008u
109 #define MAGNETICROTARY6_ERRFL_P2RAM_WARNING 0x0004u
110 #define MAGNETICROTARY6_ERRFL_MAGHALF 0x0002u
111 #define MAGNETICROTARY6_ERRFL_AGC_WARNING 0x0001u
112 
117 #define MAGNETICROTARY6_PROG_PROGVER 0x0040u
118 #define MAGNETICROTARY6_PROG_PROGOTP 0x0008u
119 #define MAGNETICROTARY6_PROG_OTPREF 0x0004u
120 #define MAGNETICROTARY6_PROG_PROGEN 0x0001u
121 
126 #define MAGNETICROTARY6_DIA_SPI_CNT 0x1800u
127 #define MAGNETICROTARY6_DIA_FUSA_ERROR 0x0400u
128 #define MAGNETICROTARY6_DIA_AGC_FIN 0x0200u
129 #define MAGNETICROTARY6_DIA_OFF_COMP_FIN 0x0100u
130 #define MAGNETICROTARY6_DIA_SINOFF_FIN 0x0080u
131 #define MAGNETICROTARY6_DIA_COSOFF_FIN 0x0040u
132 #define MAGNETICROTARY6_DIA_MAGHALF_FLAG 0x0020u
133 #define MAGNETICROTARY6_DIA_COMP_H 0x0010u
134 #define MAGNETICROTARY6_DIA_COMP_L 0x0008u
135 #define MAGNETICROTARY6_DIA_CORDIC_OF 0x0004u
136 #define MAGNETICROTARY6_DIA_LOOPSFIN 0x0002u
137 #define MAGNETICROTARY6_DIA_VDD_MODE_5V 0x0001u
138 #define MAGNETICROTARY6_DIA_VDD_MODE_3V 0x0000u
139 
144 #define MAGNETICROTARY6_DISABLE_FILTER_DISABLE 0x0040u
145 #define MAGNETICROTARY6_DISABLE_BRKHALL_SET 0x003Cu
146 #define MAGNETICROTARY6_DISABLE_ABI_OFF 0x0002u
147 #define MAGNETICROTARY6_DISABLE_UVW_OFF 0x0001u
148 
153 #define MAGNETICROTARY6_ZPOSL_DIA2_EN 0x0080u
154 #define MAGNETICROTARY6_ZPOSL_DIA1_EN 0x0040u
155 #define MAGNETICROTARY6_ZPOSL_LSB 0x003Fu
156 
161 #define MAGNETICROTARY6_SETTINGS1_DIA3_EN 0x0040u
162 #define MAGNETICROTARY6_SETTINGS1_K_MIN 0x0038u
163 #define MAGNETICROTARY6_SETTINGS1_K_MAX 0x0007u
164 
169 #define MAGNETICROTARY6_SETTINGS2_PWMON 0x0080u
170 #define MAGNETICROTARY6_SETTINGS2_DATA_SELECT 0x0040u
171 #define MAGNETICROTARY6_SETTINGS2_ABI_DEC 0x0020u
172 #define MAGNETICROTARY6_SETTINGS2_DAECDIS 0x0010u
173 #define MAGNETICROTARY6_SETTINGS2_UVW_ABI 0x0008u
174 #define MAGNETICROTARY6_SETTINGS2_DIR_CW 0x0000u
175 #define MAGNETICROTARY6_SETTINGS2_DIR_CCW 0x0004u
176 #define MAGNETICROTARY6_SETTINGS2_DIR_MASK 0x0004u
177 #define MAGNETICROTARY6_SETTINGS2_NOISESET 0x0002u
178 #define MAGNETICROTARY6_SETTINGS2_IWIDTH 0x0001u
179 
184 #define MAGNETICROTARY6_SETTINGS3_ABIRES_MASK 0x00E0u
185 #define MAGNETICROTARY6_SETTINGS3_HYS_MASK 0x0018u
186 #define MAGNETICROTARY6_SETTINGS3_UVWPP_1PP 0x0000u
187 #define MAGNETICROTARY6_SETTINGS3_UVWPP_2PP 0x0001u
188 #define MAGNETICROTARY6_SETTINGS3_UVWPP_3PP 0x0002u
189 #define MAGNETICROTARY6_SETTINGS3_UVWPP_4PP 0x0003u
190 #define MAGNETICROTARY6_SETTINGS3_UVWPP_5PP 0x0004u
191 #define MAGNETICROTARY6_SETTINGS3_UVWPP_6PP 0x0005u
192 #define MAGNETICROTARY6_SETTINGS3_UVWPP_7PP 0x0006u
193 #define MAGNETICROTARY6_SETTINGS3_UVWPP_MASK 0x0007u
194 
199 #define MAGNETICROTARY6_ECC_EN 0x0080u
200 #define MAGNETICROTARY6_ECC_CHSUM_MASK 0x007Fu
201 
206 #define MAGNETICROTARY6_DIE_BOTTOM 0
207 #define MAGNETICROTARY6_DIE_TOP 1
208 
213 #define MAGNETICROTARY6_DATA_RESOLUTION 0x3FFFu
214 #define MAGNETICROTARY6_FULL_CIRCLE 360u
215 
220 #define MAGNETICROTARY6_DIR_CW 0
221 #define MAGNETICROTARY6_DIR_CCW 1
222 
229 #define MAGNETICROTARY6_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
230 #define MAGNETICROTARY6_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
231  // magneticrotary6_set
233 
248 #define MAGNETICROTARY6_MAP_MIKROBUS( cfg, mikrobus ) \
249  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
250  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
251  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
252  cfg.cs_t = MIKROBUS( mikrobus, MIKROBUS_CS ); \
253  cfg.cs_b = MIKROBUS( mikrobus, MIKROBUS_PWM );
254  // magneticrotary6_map // magneticrotary6
257 
262 typedef struct
263 {
264  // Modules
265  spi_master_t spi;
267  pin_name_t cs_t;
268  pin_name_t cs_b;
271 
276 typedef struct
277 {
278  // Communication gpio pins
279  pin_name_t miso;
280  pin_name_t mosi;
281  pin_name_t sck;
282  pin_name_t cs_t;
283  pin_name_t cs_b;
285  // static variable
286  uint32_t spi_speed;
287  spi_master_mode_t spi_mode;
288  spi_master_chip_select_polarity_t cs_polarity;
291 
296 typedef enum
297 {
300 
302 
319 
334 
348 
363 err_t magneticrotary6_write_register ( magneticrotary6_t *ctx, uint8_t die_sel, uint16_t reg, uint16_t data_in );
364 
379 err_t magneticrotary6_read_register ( magneticrotary6_t *ctx, uint8_t die_sel, uint16_t reg, uint16_t *data_out );
380 
394 err_t magneticrotary6_get_angle ( magneticrotary6_t *ctx, uint8_t die_sel, float *angle );
395 
408 err_t magneticrotary6_set_direction ( magneticrotary6_t *ctx, uint8_t die_sel, uint8_t dir );
409 
410 #ifdef __cplusplus
411 }
412 #endif
413 #endif // MAGNETICROTARY6_H
414  // magneticrotary6
416 
417 // ------------------------------------------------------------------------ END
magneticrotary6_t::spi
spi_master_t spi
Definition: magneticrotary6.h:265
magneticrotary6_cfg_t::cs_b
pin_name_t cs_b
Definition: magneticrotary6.h:283
magneticrotary6_read_register
err_t magneticrotary6_read_register(magneticrotary6_t *ctx, uint8_t die_sel, uint16_t reg, uint16_t *data_out)
Magnetic Rotary 6 read register b function.
magneticrotary6_get_angle
err_t magneticrotary6_get_angle(magneticrotary6_t *ctx, uint8_t die_sel, float *angle)
Magnetic Rotary 6 get angle function.
magneticrotary6_t::cs_t
pin_name_t cs_t
Definition: magneticrotary6.h:267
magneticrotary6_cfg_setup
void magneticrotary6_cfg_setup(magneticrotary6_cfg_t *cfg)
Magnetic Rotary 6 configuration object setup function.
spi_specifics.h
This file contains SPI specific macros, functions, etc.
magneticrotary6_default_cfg
err_t magneticrotary6_default_cfg(magneticrotary6_t *ctx)
Magnetic Rotary 6 default configuration function.
magneticrotary6_cfg_t
Magnetic Rotary 6 Click configuration object.
Definition: magneticrotary6.h:277
magneticrotary6_init
err_t magneticrotary6_init(magneticrotary6_t *ctx, magneticrotary6_cfg_t *cfg)
Magnetic Rotary 6 initialization function.
magneticrotary6_t::cs_b
pin_name_t cs_b
Definition: magneticrotary6.h:268
magneticrotary6_cfg_t::cs_t
pin_name_t cs_t
Definition: magneticrotary6.h:282
magneticrotary6_return_value_t
magneticrotary6_return_value_t
Magnetic Rotary 6 Click return value data.
Definition: magneticrotary6.h:297
magneticrotary6_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: magneticrotary6.h:287
magneticrotary6_t
Magnetic Rotary 6 Click context object.
Definition: magneticrotary6.h:263
magneticrotary6_cfg_t::miso
pin_name_t miso
Definition: magneticrotary6.h:279
magneticrotary6_write_register
err_t magneticrotary6_write_register(magneticrotary6_t *ctx, uint8_t die_sel, uint16_t reg, uint16_t data_in)
Magnetic Rotary 6 write register function.
MAGNETICROTARY6_OK
@ MAGNETICROTARY6_OK
Definition: magneticrotary6.h:298
magneticrotary6_set_direction
err_t magneticrotary6_set_direction(magneticrotary6_t *ctx, uint8_t die_sel, uint8_t dir)
Magnetic Rotary 6 set direction function.
magneticrotary6_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: magneticrotary6.h:288
magneticrotary6_cfg_t::mosi
pin_name_t mosi
Definition: magneticrotary6.h:280
magneticrotary6_cfg_t::spi_speed
uint32_t spi_speed
Definition: magneticrotary6.h:286
magneticrotary6_cfg_t::sck
pin_name_t sck
Definition: magneticrotary6.h:281
MAGNETICROTARY6_ERROR
@ MAGNETICROTARY6_ERROR
Definition: magneticrotary6.h:299