magneticrotary3  2.0.0.0
magneticrotary3.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 MAGNETICROTARY3_H
29 #define MAGNETICROTARY3_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 MAGNETICROTARY3_REG_NOP 0x0000
71 #define MAGNETICROTARY3_REG_ERRFL 0x0001
72 #define MAGNETICROTARY3_REG_PROG 0x0003
73 #define MAGNETICROTARY3_REG_DIA 0x3FF5
74 #define MAGNETICROTARY3_REG_AGC 0x3FF9
75 #define MAGNETICROTARY3_REG_SIN_DATA 0x3FFA
76 #define MAGNETICROTARY3_REG_COS_DATA 0x3FFB
77 #define MAGNETICROTARY3_REG_VEL 0x3FFC
78 #define MAGNETICROTARY3_REG_MAG 0x3FFD
79 #define MAGNETICROTARY3_REG_ANGLEUNC 0x3FFE
80 #define MAGNETICROTARY3_REG_ANGLECOM 0x3FFF
81 #define MAGNETICROTARY3_REG_ECC_CHECKSUM 0x00D1
82 
87 #define MAGNETICROTARY3_REG_DISABLE 0x0015
88 #define MAGNETICROTARY3_REG_ZPOSM 0x0016
89 #define MAGNETICROTARY3_REG_ZPOSL 0x0017
90 #define MAGNETICROTARY3_REG_SETTINGS1 0x0018
91 #define MAGNETICROTARY3_REG_SETTINGS2 0x0019
92 #define MAGNETICROTARY3_REG_SETTINGS3 0x001A
93 #define MAGNETICROTARY3_REG_ECC 0x001B
94  // magneticrotary3_reg
96 
111 #define MAGNETICROTARY3_DATA_RESOLUTION 0x3FFF
112 #define MAGNETICROTARY3_FULL_CIRCLE 360
113 
120 #define MAGNETICROTARY3_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
121 #define MAGNETICROTARY3_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
122  // magneticrotary3_set
124 
139 #define MAGNETICROTARY3_MAP_MIKROBUS( cfg, mikrobus ) \
140  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
141  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
142  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
143  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
144  // magneticrotary3_map // magneticrotary3
147 
152 typedef struct
153 {
154  // Modules
155  spi_master_t spi;
157  pin_name_t chip_select;
160 
165 typedef struct
166 {
167  // Communication gpio pins
168  pin_name_t miso;
169  pin_name_t mosi;
170  pin_name_t sck;
171  pin_name_t cs;
173  // static variable
174  uint32_t spi_speed;
175  spi_master_mode_t spi_mode;
176  spi_master_chip_select_polarity_t cs_polarity;
179 
184 typedef enum
185 {
188 
190 
207 
222 
235 err_t magneticrotary3_write_register ( magneticrotary3_t *ctx, uint16_t reg, uint16_t data_in );
236 
249 err_t magneticrotary3_read_register ( magneticrotary3_t *ctx, uint16_t reg, uint16_t *data_out );
250 
262 err_t magneticrotary3_get_angle ( magneticrotary3_t *ctx, float *angle );
263 
264 #ifdef __cplusplus
265 }
266 #endif
267 #endif // MAGNETICROTARY3_H
268  // magneticrotary3
270 
271 // ------------------------------------------------------------------------ END
magneticrotary3_write_register
err_t magneticrotary3_write_register(magneticrotary3_t *ctx, uint16_t reg, uint16_t data_in)
Magnetic Rotary 3 write register function.
spi_specifics.h
This file contains SPI specific macros, functions, etc.
magneticrotary3_t::chip_select
pin_name_t chip_select
Definition: magneticrotary3.h:157
magneticrotary3_cfg_t::mosi
pin_name_t mosi
Definition: magneticrotary3.h:169
magneticrotary3_cfg_t::spi_speed
uint32_t spi_speed
Definition: magneticrotary3.h:174
magneticrotary3_cfg_t
Magnetic Rotary 3 Click configuration object.
Definition: magneticrotary3.h:166
magneticrotary3_read_register
err_t magneticrotary3_read_register(magneticrotary3_t *ctx, uint16_t reg, uint16_t *data_out)
Magnetic Rotary 3 read register function.
magneticrotary3_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: magneticrotary3.h:175
magneticrotary3_cfg_t::sck
pin_name_t sck
Definition: magneticrotary3.h:170
magneticrotary3_cfg_setup
void magneticrotary3_cfg_setup(magneticrotary3_cfg_t *cfg)
Magnetic Rotary 3 configuration object setup function.
magneticrotary3_return_value_t
magneticrotary3_return_value_t
Magnetic Rotary 3 Click return value data.
Definition: magneticrotary3.h:185
magneticrotary3_t
Magnetic Rotary 3 Click context object.
Definition: magneticrotary3.h:153
magneticrotary3_t::spi
spi_master_t spi
Definition: magneticrotary3.h:155
magneticrotary3_cfg_t::miso
pin_name_t miso
Definition: magneticrotary3.h:168
MAGNETICROTARY3_ERROR
@ MAGNETICROTARY3_ERROR
Definition: magneticrotary3.h:187
magneticrotary3_init
err_t magneticrotary3_init(magneticrotary3_t *ctx, magneticrotary3_cfg_t *cfg)
Magnetic Rotary 3 initialization function.
magneticrotary3_get_angle
err_t magneticrotary3_get_angle(magneticrotary3_t *ctx, float *angle)
Magnetic Rotary 3 get angle function.
MAGNETICROTARY3_OK
@ MAGNETICROTARY3_OK
Definition: magneticrotary3.h:186
magneticrotary3_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: magneticrotary3.h:176
magneticrotary3_cfg_t::cs
pin_name_t cs
Definition: magneticrotary3.h:171