magneticrotary4  2.0.0.0
magneticrotary4.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 MAGNETICROTARY4_H
29 #define MAGNETICROTARY4_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 MAGNETICROTARY4_REG_NOP 0x0000
71 #define MAGNETICROTARY4_REG_ERRFL 0x0001
72 #define MAGNETICROTARY4_REG_PROG 0x0003
73 #define MAGNETICROTARY4_REG_DIAAGC 0x3FFC
74 #define MAGNETICROTARY4_REG_MAG 0x3FFD
75 #define MAGNETICROTARY4_REG_ANGLEUNC 0x3FFE
76 #define MAGNETICROTARY4_REG_ANGLECOM 0x3FFF
77 
82 #define MAGNETICROTARY4_REG_ZPOSM 0x0016
83 #define MAGNETICROTARY4_REG_ZPOSL 0x0017
84 #define MAGNETICROTARY4_REG_SETTINGS1 0x0018
85 #define MAGNETICROTARY4_REG_SETTINGS2 0x0019
86  // magneticrotary4_reg
88 
103 #define MAGNETICROTARY4_DATA_RESOLUTION 0x3FFF
104 #define MAGNETICROTARY4_FULL_CIRCLE 360
105 
110 #define MAGNETICROTARY4_ODD_PARITY 0x01
111 
116 #define MAGNETICROTARY4_DIRECTION_CW 0
117 #define MAGNETICROTARY4_DIRECTION_CCW 1
118 
127 #define MAGNETICROTARY4_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
128 #define MAGNETICROTARY4_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
129  // magneticrotary4_set
131 
146 #define MAGNETICROTARY4_MAP_MIKROBUS( cfg, mikrobus ) \
147  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
148  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
149  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
150  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
151  // magneticrotary4_map // magneticrotary4
154 
159 typedef struct
160 {
161  // Modules
162  spi_master_t spi;
164  pin_name_t chip_select;
167 
172 typedef struct
173 {
174  // Communication gpio pins
175  pin_name_t miso;
176  pin_name_t mosi;
177  pin_name_t sck;
178  pin_name_t cs;
180  // static variable
181  uint32_t spi_speed;
182  spi_master_mode_t spi_mode;
183  spi_master_chip_select_polarity_t cs_polarity;
186 
191 typedef enum
192 {
195 
197 
214 
229 
242 err_t magneticrotary4_write_register ( magneticrotary4_t *ctx, uint16_t reg, uint16_t data_in );
243 
256 err_t magneticrotary4_read_register ( magneticrotary4_t *ctx, uint16_t reg, uint16_t *data_out );
257 
269 err_t magneticrotary4_get_angle ( magneticrotary4_t *ctx, float *angle );
270 
282 
296 
297 #ifdef __cplusplus
298 }
299 #endif
300 #endif // MAGNETICROTARY4_H
301  // magneticrotary4
303 
304 // ------------------------------------------------------------------------ END
magneticrotary4_t::chip_select
pin_name_t chip_select
Definition: magneticrotary4.h:164
magneticrotary4_cfg_t::miso
pin_name_t miso
Definition: magneticrotary4.h:175
magneticrotary4_read_register
err_t magneticrotary4_read_register(magneticrotary4_t *ctx, uint16_t reg, uint16_t *data_out)
Magnetic Rotary 4 read register function.
spi_specifics.h
This file contains SPI specific macros, functions, etc.
magneticrotary4_cfg_setup
void magneticrotary4_cfg_setup(magneticrotary4_cfg_t *cfg)
Magnetic Rotary 4 configuration object setup function.
MAGNETICROTARY4_OK
@ MAGNETICROTARY4_OK
Definition: magneticrotary4.h:193
magneticrotary4_cfg_t::sck
pin_name_t sck
Definition: magneticrotary4.h:177
magneticrotary4_return_value_t
magneticrotary4_return_value_t
Magnetic Rotary 4 Click return value data.
Definition: magneticrotary4.h:192
magneticrotary4_cfg_t::cs
pin_name_t cs
Definition: magneticrotary4.h:178
magneticrotary4_t
Magnetic Rotary 4 Click context object.
Definition: magneticrotary4.h:160
magneticrotary4_cfg_t
Magnetic Rotary 4 Click configuration object.
Definition: magneticrotary4.h:173
magneticrotary4_set_rotation_direction
err_t magneticrotary4_set_rotation_direction(magneticrotary4_t *ctx, uint8_t direction)
Magnetic Rotary 4 set rotation direction function.
magneticrotary4_write_register
err_t magneticrotary4_write_register(magneticrotary4_t *ctx, uint16_t reg, uint16_t data_in)
Magnetic Rotary 4 write register function.
magneticrotary4_cfg_t::spi_speed
uint32_t spi_speed
Definition: magneticrotary4.h:181
magneticrotary4_init
err_t magneticrotary4_init(magneticrotary4_t *ctx, magneticrotary4_cfg_t *cfg)
Magnetic Rotary 4 initialization function.
magneticrotary4_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: magneticrotary4.h:182
magneticrotary4_get_angle
err_t magneticrotary4_get_angle(magneticrotary4_t *ctx, float *angle)
Magnetic Rotary 4 get angle function.
magneticrotary4_t::spi
spi_master_t spi
Definition: magneticrotary4.h:162
magneticrotary4_calibrate_zero_position
err_t magneticrotary4_calibrate_zero_position(magneticrotary4_t *ctx)
Magnetic Rotary 4 calibrate zero position function.
magneticrotary4_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: magneticrotary4.h:183
magneticrotary4_cfg_t::mosi
pin_name_t mosi
Definition: magneticrotary4.h:176
MAGNETICROTARY4_ERROR
@ MAGNETICROTARY4_ERROR
Definition: magneticrotary4.h:194