magneticrotary2  2.0.0.0
magneticrotary2.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 MAGNETICROTARY2_H
29 #define MAGNETICROTARY2_H
30 
31 #ifdef __cplusplus
32 extern "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_spi_master.h"
52 #include "spi_specifics.h"
53 
74 #define MAGNETICROTARY2_REG_CUST_RES_0 0x00
75 #define MAGNETICROTARY2_REG_CUST_RES_1 0x01
76 #define MAGNETICROTARY2_REG_CUST_RES_2 0x02
77 #define MAGNETICROTARY2_REG_CUST_RES_3 0x03
78 #define MAGNETICROTARY2_REG_CUST_RES_4 0x04
79 #define MAGNETICROTARY2_REG_CUST_RES_5 0x05
80 #define MAGNETICROTARY2_REG_CUST_RES_6 0x06
81 #define MAGNETICROTARY2_REG_CUST_CONFIG_0_MSB 0x07
82 #define MAGNETICROTARY2_REG_CUST_CONFIG_0_LSB 0x08
83 #define MAGNETICROTARY2_REG_CUST_CONFIG_1_MSB 0x09
84 #define MAGNETICROTARY2_REG_CUST_CONFIG_1_LSB 0x0A
85 #define MAGNETICROTARY2_REG_CUST_CONFIG_2 0x0B
86 #define MAGNETICROTARY2_REG_ZERO_RESET_2 0x0C
87 #define MAGNETICROTARY2_REG_ZERO_RESET_1 0x0D
88 #define MAGNETICROTARY2_REG_ZERO_RESET_0 0x0E
89 #define MAGNETICROTARY2_REG_UNLOCK 0x10
90 #define MAGNETICROTARY2_REG_PROGRAM 0x11
91 #define MAGNETICROTARY2_REG_CALIBRATION 0x12
92 #define MAGNETICROTARY2_REG_ERROR_BITS 0x21
93 #define MAGNETICROTARY2_REG_CALIBRATION_STAT 0x22
94 #define MAGNETICROTARY2_REG_POSITION 0x3F
95  // magneticrotary2_reg
97 
112 #define MAGNETICROTARY2_UNLOCK_VALUE 0xAB
113 #define MAGNETICROTARY2_LOCK_VALUE 0xFF
114 #define MAGNETICROTARY2_PROGRAM_VALUE 0xA1
115 
120 #define MAGNETICROTARY2_ODD_PARITY 0x01
121 
126 #define MAGNETICROTARY2_MSEL1_READ_BIT 0x40
127 #define MAGNETICROTARY2_MSEL0_WRITE_BIT 0x80
128 
133 #define MAGNETICROTARY2_CC0_MSB_HW_ST_ZERO_EN 0x80
134 #define MAGNETICROTARY2_CC0_MSB_HW_ACC_CALIB_EN 0x40
135 #define MAGNETICROTARY2_CC0_MSB_AXIS_MODE_OFF 0x20
136 #define MAGNETICROTARY2_CC0_MSB_IWIDTH_90 0x00
137 #define MAGNETICROTARY2_CC0_MSB_IWIDTH_180 0x04
138 #define MAGNETICROTARY2_CC0_MSB_IWIDTH_270 0x08
139 #define MAGNETICROTARY2_CC0_MSB_IWIDTH_360 0x0C
140 #define MAGNETICROTARY2_CC0_MSB_IPHASE_90 0x00
141 #define MAGNETICROTARY2_CC0_MSB_IPHASE_180 0x01
142 #define MAGNETICROTARY2_CC0_MSB_IPHASE_270 0x02
143 #define MAGNETICROTARY2_CC0_MSB_IPHASE_360 0x03
144 #define MAGNETICROTARY2_CC0_LSB_HYST_0_00 0x00
145 #define MAGNETICROTARY2_CC0_LSB_HYST_0_01 0x20
146 #define MAGNETICROTARY2_CC0_LSB_HYST_0_02 0x40
147 #define MAGNETICROTARY2_CC0_LSB_HYST_0_04 0x60
148 #define MAGNETICROTARY2_CC0_LSB_HYST_0_08 0x80
149 #define MAGNETICROTARY2_CC0_LSB_HYST_0_17 0xA0
150 #define MAGNETICROTARY2_CC0_LSB_HYST_0_35 0xC0
151 #define MAGNETICROTARY2_CC0_LSB_HYST_0_70 0xE0
152 #define MAGNETICROTARY2_CC0_LSB_DIR_CCW 0x10
153 #define MAGNETICROTARY2_CC0_LSB_ABS_RES_18BIT 0x00
154 #define MAGNETICROTARY2_CC0_LSB_ABS_RES_17BIT 0x01
155 #define MAGNETICROTARY2_CC0_LSB_ABS_RES_16BIT 0x02
156 #define MAGNETICROTARY2_CC0_LSB_ABS_RES_15BIT 0x03
157 #define MAGNETICROTARY2_CC0_LSB_ABS_RES_14BIT 0x04
158 #define MAGNETICROTARY2_CC0_LSB_ABS_RES_13BIT 0x05
159 #define MAGNETICROTARY2_CC0_LSB_ABS_RES_12BIT 0x06
160 #define MAGNETICROTARY2_CC0_LSB_ABS_RES_11BIT 0x07
161 #define MAGNETICROTARY2_CC0_LSB_ABS_RES_10BIT 0x08
162 #define MAGNETICROTARY2_CC0_LSB_ABS_RES_MASK 0x0F
163 
172 #define MAGNETICROTARY2_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
173 #define MAGNETICROTARY2_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
174  // magneticrotary2_set
176 
191 typedef enum
192 {
197 
202 #define MAGNETICROTARY2_MAP_MIKROBUS( cfg, mikrobus ) \
203  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
204  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
205  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
206  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
207  // magneticrotary2_map // magneticrotary2
210 
215 typedef struct
216 {
217  // Output pins
218  digital_out_t ssi_sel;
219  // Modules
220  spi_master_t spi;
222  pin_name_t chip_select;
224  uint8_t abs_res;
227 
232 typedef struct
233 {
234  // Communication gpio pins
235  pin_name_t miso;
236  pin_name_t mosi;
237  pin_name_t sck;
238  pin_name_t cs;
240  // static variable
241  uint32_t spi_speed;
242  spi_master_mode_t spi_mode;
243  spi_master_chip_select_polarity_t cs_polarity;
247 
252 typedef enum
253 {
256 
258 
275 
291 
306 
320 
334 err_t magneticrotary2_write_register ( magneticrotary2_t *ctx, uint8_t reg, uint8_t data_in );
335 
349 err_t magneticrotary2_read_register ( magneticrotary2_t *ctx, uint8_t reg, uint8_t *data_out );
350 
362 
374 
386 
398 err_t magneticrotary2_get_raw_data ( magneticrotary2_t *ctx, uint32_t *data_out );
399 
411 err_t magneticrotary2_get_angle ( magneticrotary2_t *ctx, float *angle );
412 
413 #ifdef __cplusplus
414 }
415 #endif
416 #endif // MAGNETICROTARY2_H
417  // magneticrotary2
419 
420 // ------------------------------------------------------------------------ END
magneticrotary2_msel_pin_selection
void magneticrotary2_msel_pin_selection(magneticrotary2_cfg_t *cfg, magneticrotary2_msel_t msel)
Magnetic Rotary 2 MSEL pin selection function.
magneticrotary2_msel_t
magneticrotary2_msel_t
Magnetic Rotary 2 Click driver selector.
Definition: magneticrotary2.h:192
magneticrotary2_unlock_eeprom
err_t magneticrotary2_unlock_eeprom(magneticrotary2_t *ctx)
Magnetic Rotary 2 unlock eeprom function.
magneticrotary2_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: magneticrotary2.h:242
magneticrotary2_get_raw_data
err_t magneticrotary2_get_raw_data(magneticrotary2_t *ctx, uint32_t *data_out)
Magnetic Rotary 2 get raw data function.
magneticrotary2_write_register
err_t magneticrotary2_write_register(magneticrotary2_t *ctx, uint8_t reg, uint8_t data_in)
Magnetic Rotary 2 write register function.
magneticrotary2_t::abs_res
uint8_t abs_res
Definition: magneticrotary2.h:224
magneticrotary2_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: magneticrotary2.h:243
magneticrotary2_cfg_t::mosi
pin_name_t mosi
Definition: magneticrotary2.h:236
magneticrotary2_cfg_t::spi_speed
uint32_t spi_speed
Definition: magneticrotary2.h:241
spi_specifics.h
This file contains SPI specific macros, functions, etc.
magneticrotary2_t::chip_select
pin_name_t chip_select
Definition: magneticrotary2.h:222
magneticrotary2_t
Magnetic Rotary 2 Click context object.
Definition: magneticrotary2.h:216
magneticrotary2_cfg_t
Magnetic Rotary 2 Click configuration object.
Definition: magneticrotary2.h:233
magneticrotary2_t::msel
magneticrotary2_msel_t msel
Definition: magneticrotary2.h:223
magneticrotary2_t::ssi_sel
digital_out_t ssi_sel
Definition: magneticrotary2.h:218
magneticrotary2_read_register
err_t magneticrotary2_read_register(magneticrotary2_t *ctx, uint8_t reg, uint8_t *data_out)
Magnetic Rotary 2 read register function.
MAGNETICROTARY2_ERROR
@ MAGNETICROTARY2_ERROR
Definition: magneticrotary2.h:255
magneticrotary2_cfg_t::msel
magneticrotary2_msel_t msel
Definition: magneticrotary2.h:244
MAGNETICROTARY2_MSEL_1
@ MAGNETICROTARY2_MSEL_1
Definition: magneticrotary2.h:194
magneticrotary2_lock_eeprom
err_t magneticrotary2_lock_eeprom(magneticrotary2_t *ctx)
Magnetic Rotary 2 lock eeprom function.
magneticrotary2_t::spi
spi_master_t spi
Definition: magneticrotary2.h:220
MAGNETICROTARY2_OK
@ MAGNETICROTARY2_OK
Definition: magneticrotary2.h:254
magneticrotary2_cfg_t::miso
pin_name_t miso
Definition: magneticrotary2.h:235
MAGNETICROTARY2_MSEL_0
@ MAGNETICROTARY2_MSEL_0
Definition: magneticrotary2.h:193
magneticrotary2_cfg_setup
void magneticrotary2_cfg_setup(magneticrotary2_cfg_t *cfg)
Magnetic Rotary 2 configuration object setup function.
magneticrotary2_return_value_t
magneticrotary2_return_value_t
Magnetic Rotary 2 Click return value data.
Definition: magneticrotary2.h:253
magneticrotary2_get_angle
err_t magneticrotary2_get_angle(magneticrotary2_t *ctx, float *angle)
Magnetic Rotary 2 get angle function.
magneticrotary2_cfg_t::sck
pin_name_t sck
Definition: magneticrotary2.h:237
magneticrotary2_cfg_t::cs
pin_name_t cs
Definition: magneticrotary2.h:238
magneticrotary2_init
err_t magneticrotary2_init(magneticrotary2_t *ctx, magneticrotary2_cfg_t *cfg)
Magnetic Rotary 2 initialization function.
magneticrotary2_program_eeprom
err_t magneticrotary2_program_eeprom(magneticrotary2_t *ctx)
Magnetic Rotary 2 program eeprom function.
magneticrotary2_default_cfg
err_t magneticrotary2_default_cfg(magneticrotary2_t *ctx)
Magnetic Rotary 2 default configuration function.