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
32extern "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 MAGNETICROTARY4_REG_NOP 0x0000
75#define MAGNETICROTARY4_REG_ERRFL 0x0001
76#define MAGNETICROTARY4_REG_PROG 0x0003
77#define MAGNETICROTARY4_REG_DIAAGC 0x3FFC
78#define MAGNETICROTARY4_REG_MAG 0x3FFD
79#define MAGNETICROTARY4_REG_ANGLEUNC 0x3FFE
80#define MAGNETICROTARY4_REG_ANGLECOM 0x3FFF
81
86#define MAGNETICROTARY4_REG_ZPOSM 0x0016
87#define MAGNETICROTARY4_REG_ZPOSL 0x0017
88#define MAGNETICROTARY4_REG_SETTINGS1 0x0018
89#define MAGNETICROTARY4_REG_SETTINGS2 0x0019
90
91 // magneticrotary4_reg
92
107#define MAGNETICROTARY4_DATA_RESOLUTION 0x3FFF
108#define MAGNETICROTARY4_FULL_CIRCLE 360
109
114#define MAGNETICROTARY4_ODD_PARITY 0x01
115
120#define MAGNETICROTARY4_DIRECTION_CW 0
121#define MAGNETICROTARY4_DIRECTION_CCW 1
122
131#define MAGNETICROTARY4_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
132#define MAGNETICROTARY4_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
133
134 // magneticrotary4_set
135
150#define MAGNETICROTARY4_MAP_MIKROBUS( cfg, mikrobus ) \
151 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
152 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
153 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
154 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
155
156 // magneticrotary4_map
157 // magneticrotary4
158
163typedef struct
164{
165 // Modules
166 spi_master_t spi;
168 pin_name_t chip_select;
171
176typedef struct
177{
178 // Communication gpio pins
179 pin_name_t miso;
180 pin_name_t mosi;
181 pin_name_t sck;
182 pin_name_t cs;
184 // static variable
185 uint32_t spi_speed;
186 spi_master_mode_t spi_mode;
187 spi_master_chip_select_polarity_t cs_polarity;
190
201
218
233
246err_t magneticrotary4_write_register ( magneticrotary4_t *ctx, uint16_t reg, uint16_t data_in );
247
260err_t magneticrotary4_read_register ( magneticrotary4_t *ctx, uint16_t reg, uint16_t *data_out );
261
273err_t magneticrotary4_get_angle ( magneticrotary4_t *ctx, float *angle );
274
286
300
301#ifdef __cplusplus
302}
303#endif
304#endif // MAGNETICROTARY4_H
305
306 // magneticrotary4
307
308// ------------------------------------------------------------------------ END
err_t magneticrotary4_read_register(magneticrotary4_t *ctx, uint16_t reg, uint16_t *data_out)
Magnetic Rotary 4 read register function.
err_t magneticrotary4_get_angle(magneticrotary4_t *ctx, float *angle)
Magnetic Rotary 4 get angle function.
void magneticrotary4_cfg_setup(magneticrotary4_cfg_t *cfg)
Magnetic Rotary 4 configuration object setup function.
err_t magneticrotary4_set_rotation_direction(magneticrotary4_t *ctx, uint8_t direction)
Magnetic Rotary 4 set rotation direction function.
err_t magneticrotary4_init(magneticrotary4_t *ctx, magneticrotary4_cfg_t *cfg)
Magnetic Rotary 4 initialization function.
err_t magneticrotary4_write_register(magneticrotary4_t *ctx, uint16_t reg, uint16_t data_in)
Magnetic Rotary 4 write register function.
err_t magneticrotary4_calibrate_zero_position(magneticrotary4_t *ctx)
Magnetic Rotary 4 calibrate zero position function.
magneticrotary4_return_value_t
Magnetic Rotary 4 Click return value data.
Definition magneticrotary4.h:196
@ MAGNETICROTARY4_ERROR
Definition magneticrotary4.h:198
@ MAGNETICROTARY4_OK
Definition magneticrotary4.h:197
This file contains SPI specific macros, functions, etc.
Magnetic Rotary 4 Click configuration object.
Definition magneticrotary4.h:177
spi_master_chip_select_polarity_t cs_polarity
Definition magneticrotary4.h:187
pin_name_t sck
Definition magneticrotary4.h:181
spi_master_mode_t spi_mode
Definition magneticrotary4.h:186
pin_name_t mosi
Definition magneticrotary4.h:180
uint32_t spi_speed
Definition magneticrotary4.h:185
pin_name_t miso
Definition magneticrotary4.h:179
pin_name_t cs
Definition magneticrotary4.h:182
Magnetic Rotary 4 Click context object.
Definition magneticrotary4.h:164
spi_master_t spi
Definition magneticrotary4.h:166
pin_name_t chip_select
Definition magneticrotary4.h:168