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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
38 #include "spi_specifics.h"
39 
60 #define MAGNETICROTARY2_REG_CUST_RES_0 0x00
61 #define MAGNETICROTARY2_REG_CUST_RES_1 0x01
62 #define MAGNETICROTARY2_REG_CUST_RES_2 0x02
63 #define MAGNETICROTARY2_REG_CUST_RES_3 0x03
64 #define MAGNETICROTARY2_REG_CUST_RES_4 0x04
65 #define MAGNETICROTARY2_REG_CUST_RES_5 0x05
66 #define MAGNETICROTARY2_REG_CUST_RES_6 0x06
67 #define MAGNETICROTARY2_REG_CUST_CONFIG_0_MSB 0x07
68 #define MAGNETICROTARY2_REG_CUST_CONFIG_0_LSB 0x08
69 #define MAGNETICROTARY2_REG_CUST_CONFIG_1_MSB 0x09
70 #define MAGNETICROTARY2_REG_CUST_CONFIG_1_LSB 0x0A
71 #define MAGNETICROTARY2_REG_CUST_CONFIG_2 0x0B
72 #define MAGNETICROTARY2_REG_ZERO_RESET_2 0x0C
73 #define MAGNETICROTARY2_REG_ZERO_RESET_1 0x0D
74 #define MAGNETICROTARY2_REG_ZERO_RESET_0 0x0E
75 #define MAGNETICROTARY2_REG_UNLOCK 0x10
76 #define MAGNETICROTARY2_REG_PROGRAM 0x11
77 #define MAGNETICROTARY2_REG_CALIBRATION 0x12
78 #define MAGNETICROTARY2_REG_ERROR_BITS 0x21
79 #define MAGNETICROTARY2_REG_CALIBRATION_STAT 0x22
80 #define MAGNETICROTARY2_REG_POSITION 0x3F
81  // magneticrotary2_reg
83 
98 #define MAGNETICROTARY2_UNLOCK_VALUE 0xAB
99 #define MAGNETICROTARY2_LOCK_VALUE 0xFF
100 #define MAGNETICROTARY2_PROGRAM_VALUE 0xA1
101 
106 #define MAGNETICROTARY2_ODD_PARITY 0x01
107 
112 #define MAGNETICROTARY2_MSEL1_READ_BIT 0x40
113 #define MAGNETICROTARY2_MSEL0_WRITE_BIT 0x80
114 
119 #define MAGNETICROTARY2_CC0_MSB_HW_ST_ZERO_EN 0x80
120 #define MAGNETICROTARY2_CC0_MSB_HW_ACC_CALIB_EN 0x40
121 #define MAGNETICROTARY2_CC0_MSB_AXIS_MODE_OFF 0x20
122 #define MAGNETICROTARY2_CC0_MSB_IWIDTH_90 0x00
123 #define MAGNETICROTARY2_CC0_MSB_IWIDTH_180 0x04
124 #define MAGNETICROTARY2_CC0_MSB_IWIDTH_270 0x08
125 #define MAGNETICROTARY2_CC0_MSB_IWIDTH_360 0x0C
126 #define MAGNETICROTARY2_CC0_MSB_IPHASE_90 0x00
127 #define MAGNETICROTARY2_CC0_MSB_IPHASE_180 0x01
128 #define MAGNETICROTARY2_CC0_MSB_IPHASE_270 0x02
129 #define MAGNETICROTARY2_CC0_MSB_IPHASE_360 0x03
130 #define MAGNETICROTARY2_CC0_LSB_HYST_0_00 0x00
131 #define MAGNETICROTARY2_CC0_LSB_HYST_0_01 0x20
132 #define MAGNETICROTARY2_CC0_LSB_HYST_0_02 0x40
133 #define MAGNETICROTARY2_CC0_LSB_HYST_0_04 0x60
134 #define MAGNETICROTARY2_CC0_LSB_HYST_0_08 0x80
135 #define MAGNETICROTARY2_CC0_LSB_HYST_0_17 0xA0
136 #define MAGNETICROTARY2_CC0_LSB_HYST_0_35 0xC0
137 #define MAGNETICROTARY2_CC0_LSB_HYST_0_70 0xE0
138 #define MAGNETICROTARY2_CC0_LSB_DIR_CCW 0x10
139 #define MAGNETICROTARY2_CC0_LSB_ABS_RES_18BIT 0x00
140 #define MAGNETICROTARY2_CC0_LSB_ABS_RES_17BIT 0x01
141 #define MAGNETICROTARY2_CC0_LSB_ABS_RES_16BIT 0x02
142 #define MAGNETICROTARY2_CC0_LSB_ABS_RES_15BIT 0x03
143 #define MAGNETICROTARY2_CC0_LSB_ABS_RES_14BIT 0x04
144 #define MAGNETICROTARY2_CC0_LSB_ABS_RES_13BIT 0x05
145 #define MAGNETICROTARY2_CC0_LSB_ABS_RES_12BIT 0x06
146 #define MAGNETICROTARY2_CC0_LSB_ABS_RES_11BIT 0x07
147 #define MAGNETICROTARY2_CC0_LSB_ABS_RES_10BIT 0x08
148 #define MAGNETICROTARY2_CC0_LSB_ABS_RES_MASK 0x0F
149 
158 #define MAGNETICROTARY2_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
159 #define MAGNETICROTARY2_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
160  // magneticrotary2_set
162 
177 typedef enum
178 {
183 
188 #define MAGNETICROTARY2_MAP_MIKROBUS( cfg, mikrobus ) \
189  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
190  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
191  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
192  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
193  // magneticrotary2_map // magneticrotary2
196 
201 typedef struct
202 {
203  // Output pins
204  digital_out_t ssi_sel;
205  // Modules
206  spi_master_t spi;
208  pin_name_t chip_select;
210  uint8_t abs_res;
213 
218 typedef struct
219 {
220  // Communication gpio pins
221  pin_name_t miso;
222  pin_name_t mosi;
223  pin_name_t sck;
224  pin_name_t cs;
226  // static variable
227  uint32_t spi_speed;
228  spi_master_mode_t spi_mode;
229  spi_master_chip_select_polarity_t cs_polarity;
233 
238 typedef enum
239 {
242 
244 
261 
277 
292 
306 
320 err_t magneticrotary2_write_register ( magneticrotary2_t *ctx, uint8_t reg, uint8_t data_in );
321 
335 err_t magneticrotary2_read_register ( magneticrotary2_t *ctx, uint8_t reg, uint8_t *data_out );
336 
348 
360 
372 
384 err_t magneticrotary2_get_raw_data ( magneticrotary2_t *ctx, uint32_t *data_out );
385 
397 err_t magneticrotary2_get_angle ( magneticrotary2_t *ctx, float *angle );
398 
399 #ifdef __cplusplus
400 }
401 #endif
402 #endif // MAGNETICROTARY2_H
403  // magneticrotary2
405 
406 // ------------------------------------------------------------------------ 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:178
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:228
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:210
magneticrotary2_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: magneticrotary2.h:229
magneticrotary2_cfg_t::mosi
pin_name_t mosi
Definition: magneticrotary2.h:222
magneticrotary2_cfg_t::spi_speed
uint32_t spi_speed
Definition: magneticrotary2.h:227
spi_specifics.h
This file contains SPI specific macros, functions, etc.
magneticrotary2_t::chip_select
pin_name_t chip_select
Definition: magneticrotary2.h:208
magneticrotary2_t
Magnetic Rotary 2 Click context object.
Definition: magneticrotary2.h:202
magneticrotary2_cfg_t
Magnetic Rotary 2 Click configuration object.
Definition: magneticrotary2.h:219
magneticrotary2_t::msel
magneticrotary2_msel_t msel
Definition: magneticrotary2.h:209
magneticrotary2_t::ssi_sel
digital_out_t ssi_sel
Definition: magneticrotary2.h:204
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:241
magneticrotary2_cfg_t::msel
magneticrotary2_msel_t msel
Definition: magneticrotary2.h:230
MAGNETICROTARY2_MSEL_1
@ MAGNETICROTARY2_MSEL_1
Definition: magneticrotary2.h:180
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:206
MAGNETICROTARY2_OK
@ MAGNETICROTARY2_OK
Definition: magneticrotary2.h:240
magneticrotary2_cfg_t::miso
pin_name_t miso
Definition: magneticrotary2.h:221
MAGNETICROTARY2_MSEL_0
@ MAGNETICROTARY2_MSEL_0
Definition: magneticrotary2.h:179
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:239
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:223
magneticrotary2_cfg_t::cs
pin_name_t cs
Definition: magneticrotary2.h:224
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.