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 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_spi_master.h"
48 #include "spi_specifics.h"
49 
70 #define MAGNETICROTARY2_REG_CUST_RES_0 0x00
71 #define MAGNETICROTARY2_REG_CUST_RES_1 0x01
72 #define MAGNETICROTARY2_REG_CUST_RES_2 0x02
73 #define MAGNETICROTARY2_REG_CUST_RES_3 0x03
74 #define MAGNETICROTARY2_REG_CUST_RES_4 0x04
75 #define MAGNETICROTARY2_REG_CUST_RES_5 0x05
76 #define MAGNETICROTARY2_REG_CUST_RES_6 0x06
77 #define MAGNETICROTARY2_REG_CUST_CONFIG_0_MSB 0x07
78 #define MAGNETICROTARY2_REG_CUST_CONFIG_0_LSB 0x08
79 #define MAGNETICROTARY2_REG_CUST_CONFIG_1_MSB 0x09
80 #define MAGNETICROTARY2_REG_CUST_CONFIG_1_LSB 0x0A
81 #define MAGNETICROTARY2_REG_CUST_CONFIG_2 0x0B
82 #define MAGNETICROTARY2_REG_ZERO_RESET_2 0x0C
83 #define MAGNETICROTARY2_REG_ZERO_RESET_1 0x0D
84 #define MAGNETICROTARY2_REG_ZERO_RESET_0 0x0E
85 #define MAGNETICROTARY2_REG_UNLOCK 0x10
86 #define MAGNETICROTARY2_REG_PROGRAM 0x11
87 #define MAGNETICROTARY2_REG_CALIBRATION 0x12
88 #define MAGNETICROTARY2_REG_ERROR_BITS 0x21
89 #define MAGNETICROTARY2_REG_CALIBRATION_STAT 0x22
90 #define MAGNETICROTARY2_REG_POSITION 0x3F
91  // magneticrotary2_reg
93 
108 #define MAGNETICROTARY2_UNLOCK_VALUE 0xAB
109 #define MAGNETICROTARY2_LOCK_VALUE 0xFF
110 #define MAGNETICROTARY2_PROGRAM_VALUE 0xA1
111 
116 #define MAGNETICROTARY2_ODD_PARITY 0x01
117 
122 #define MAGNETICROTARY2_MSEL1_READ_BIT 0x40
123 #define MAGNETICROTARY2_MSEL0_WRITE_BIT 0x80
124 
129 #define MAGNETICROTARY2_CC0_MSB_HW_ST_ZERO_EN 0x80
130 #define MAGNETICROTARY2_CC0_MSB_HW_ACC_CALIB_EN 0x40
131 #define MAGNETICROTARY2_CC0_MSB_AXIS_MODE_OFF 0x20
132 #define MAGNETICROTARY2_CC0_MSB_IWIDTH_90 0x00
133 #define MAGNETICROTARY2_CC0_MSB_IWIDTH_180 0x04
134 #define MAGNETICROTARY2_CC0_MSB_IWIDTH_270 0x08
135 #define MAGNETICROTARY2_CC0_MSB_IWIDTH_360 0x0C
136 #define MAGNETICROTARY2_CC0_MSB_IPHASE_90 0x00
137 #define MAGNETICROTARY2_CC0_MSB_IPHASE_180 0x01
138 #define MAGNETICROTARY2_CC0_MSB_IPHASE_270 0x02
139 #define MAGNETICROTARY2_CC0_MSB_IPHASE_360 0x03
140 #define MAGNETICROTARY2_CC0_LSB_HYST_0_00 0x00
141 #define MAGNETICROTARY2_CC0_LSB_HYST_0_01 0x20
142 #define MAGNETICROTARY2_CC0_LSB_HYST_0_02 0x40
143 #define MAGNETICROTARY2_CC0_LSB_HYST_0_04 0x60
144 #define MAGNETICROTARY2_CC0_LSB_HYST_0_08 0x80
145 #define MAGNETICROTARY2_CC0_LSB_HYST_0_17 0xA0
146 #define MAGNETICROTARY2_CC0_LSB_HYST_0_35 0xC0
147 #define MAGNETICROTARY2_CC0_LSB_HYST_0_70 0xE0
148 #define MAGNETICROTARY2_CC0_LSB_DIR_CCW 0x10
149 #define MAGNETICROTARY2_CC0_LSB_ABS_RES_18BIT 0x00
150 #define MAGNETICROTARY2_CC0_LSB_ABS_RES_17BIT 0x01
151 #define MAGNETICROTARY2_CC0_LSB_ABS_RES_16BIT 0x02
152 #define MAGNETICROTARY2_CC0_LSB_ABS_RES_15BIT 0x03
153 #define MAGNETICROTARY2_CC0_LSB_ABS_RES_14BIT 0x04
154 #define MAGNETICROTARY2_CC0_LSB_ABS_RES_13BIT 0x05
155 #define MAGNETICROTARY2_CC0_LSB_ABS_RES_12BIT 0x06
156 #define MAGNETICROTARY2_CC0_LSB_ABS_RES_11BIT 0x07
157 #define MAGNETICROTARY2_CC0_LSB_ABS_RES_10BIT 0x08
158 #define MAGNETICROTARY2_CC0_LSB_ABS_RES_MASK 0x0F
159 
168 #define MAGNETICROTARY2_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
169 #define MAGNETICROTARY2_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
170  // magneticrotary2_set
172 
187 typedef enum
188 {
193 
198 #define MAGNETICROTARY2_MAP_MIKROBUS( cfg, mikrobus ) \
199  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
200  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
201  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
202  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
203  // magneticrotary2_map // magneticrotary2
206 
211 typedef struct
212 {
213  // Output pins
214  digital_out_t ssi_sel;
215  // Modules
216  spi_master_t spi;
218  pin_name_t chip_select;
220  uint8_t abs_res;
223 
228 typedef struct
229 {
230  // Communication gpio pins
231  pin_name_t miso;
232  pin_name_t mosi;
233  pin_name_t sck;
234  pin_name_t cs;
236  // static variable
237  uint32_t spi_speed;
238  spi_master_mode_t spi_mode;
239  spi_master_chip_select_polarity_t cs_polarity;
243 
248 typedef enum
249 {
252 
254 
271 
287 
302 
316 
330 err_t magneticrotary2_write_register ( magneticrotary2_t *ctx, uint8_t reg, uint8_t data_in );
331 
345 err_t magneticrotary2_read_register ( magneticrotary2_t *ctx, uint8_t reg, uint8_t *data_out );
346 
358 
370 
382 
394 err_t magneticrotary2_get_raw_data ( magneticrotary2_t *ctx, uint32_t *data_out );
395 
407 err_t magneticrotary2_get_angle ( magneticrotary2_t *ctx, float *angle );
408 
409 #ifdef __cplusplus
410 }
411 #endif
412 #endif // MAGNETICROTARY2_H
413  // magneticrotary2
415 
416 // ------------------------------------------------------------------------ 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:188
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:238
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:220
magneticrotary2_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: magneticrotary2.h:239
magneticrotary2_cfg_t::mosi
pin_name_t mosi
Definition: magneticrotary2.h:232
magneticrotary2_cfg_t::spi_speed
uint32_t spi_speed
Definition: magneticrotary2.h:237
spi_specifics.h
This file contains SPI specific macros, functions, etc.
magneticrotary2_t::chip_select
pin_name_t chip_select
Definition: magneticrotary2.h:218
magneticrotary2_t
Magnetic Rotary 2 Click context object.
Definition: magneticrotary2.h:212
magneticrotary2_cfg_t
Magnetic Rotary 2 Click configuration object.
Definition: magneticrotary2.h:229
magneticrotary2_t::msel
magneticrotary2_msel_t msel
Definition: magneticrotary2.h:219
magneticrotary2_t::ssi_sel
digital_out_t ssi_sel
Definition: magneticrotary2.h:214
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:251
magneticrotary2_cfg_t::msel
magneticrotary2_msel_t msel
Definition: magneticrotary2.h:240
MAGNETICROTARY2_MSEL_1
@ MAGNETICROTARY2_MSEL_1
Definition: magneticrotary2.h:190
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:216
MAGNETICROTARY2_OK
@ MAGNETICROTARY2_OK
Definition: magneticrotary2.h:250
magneticrotary2_cfg_t::miso
pin_name_t miso
Definition: magneticrotary2.h:231
MAGNETICROTARY2_MSEL_0
@ MAGNETICROTARY2_MSEL_0
Definition: magneticrotary2.h:189
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:249
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:233
magneticrotary2_cfg_t::cs
pin_name_t cs
Definition: magneticrotary2.h:234
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.