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
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 MAGNETICROTARY3_REG_NOP 0x0000
75#define MAGNETICROTARY3_REG_ERRFL 0x0001
76#define MAGNETICROTARY3_REG_PROG 0x0003
77#define MAGNETICROTARY3_REG_DIA 0x3FF5
78#define MAGNETICROTARY3_REG_AGC 0x3FF9
79#define MAGNETICROTARY3_REG_SIN_DATA 0x3FFA
80#define MAGNETICROTARY3_REG_COS_DATA 0x3FFB
81#define MAGNETICROTARY3_REG_VEL 0x3FFC
82#define MAGNETICROTARY3_REG_MAG 0x3FFD
83#define MAGNETICROTARY3_REG_ANGLEUNC 0x3FFE
84#define MAGNETICROTARY3_REG_ANGLECOM 0x3FFF
85#define MAGNETICROTARY3_REG_ECC_CHECKSUM 0x00D1
86
91#define MAGNETICROTARY3_REG_DISABLE 0x0015
92#define MAGNETICROTARY3_REG_ZPOSM 0x0016
93#define MAGNETICROTARY3_REG_ZPOSL 0x0017
94#define MAGNETICROTARY3_REG_SETTINGS1 0x0018
95#define MAGNETICROTARY3_REG_SETTINGS2 0x0019
96#define MAGNETICROTARY3_REG_SETTINGS3 0x001A
97#define MAGNETICROTARY3_REG_ECC 0x001B
98
99 // magneticrotary3_reg
100
115#define MAGNETICROTARY3_DATA_RESOLUTION 0x3FFF
116#define MAGNETICROTARY3_FULL_CIRCLE 360
117
124#define MAGNETICROTARY3_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
125#define MAGNETICROTARY3_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
126
127 // magneticrotary3_set
128
143#define MAGNETICROTARY3_MAP_MIKROBUS( cfg, mikrobus ) \
144 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
145 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
146 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
147 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
148
149 // magneticrotary3_map
150 // magneticrotary3
151
156typedef struct
157{
158 // Modules
159 spi_master_t spi;
161 pin_name_t chip_select;
164
169typedef struct
170{
171 // Communication gpio pins
172 pin_name_t miso;
173 pin_name_t mosi;
174 pin_name_t sck;
175 pin_name_t cs;
177 // static variable
178 uint32_t spi_speed;
179 spi_master_mode_t spi_mode;
180 spi_master_chip_select_polarity_t cs_polarity;
183
194
211
226
239err_t magneticrotary3_write_register ( magneticrotary3_t *ctx, uint16_t reg, uint16_t data_in );
240
253err_t magneticrotary3_read_register ( magneticrotary3_t *ctx, uint16_t reg, uint16_t *data_out );
254
266err_t magneticrotary3_get_angle ( magneticrotary3_t *ctx, float *angle );
267
268#ifdef __cplusplus
269}
270#endif
271#endif // MAGNETICROTARY3_H
272
273 // magneticrotary3
274
275// ------------------------------------------------------------------------ END
err_t magneticrotary3_read_register(magneticrotary3_t *ctx, uint16_t reg, uint16_t *data_out)
Magnetic Rotary 3 read register function.
void magneticrotary3_cfg_setup(magneticrotary3_cfg_t *cfg)
Magnetic Rotary 3 configuration object setup function.
err_t magneticrotary3_get_angle(magneticrotary3_t *ctx, float *angle)
Magnetic Rotary 3 get angle function.
err_t magneticrotary3_init(magneticrotary3_t *ctx, magneticrotary3_cfg_t *cfg)
Magnetic Rotary 3 initialization function.
err_t magneticrotary3_write_register(magneticrotary3_t *ctx, uint16_t reg, uint16_t data_in)
Magnetic Rotary 3 write register function.
magneticrotary3_return_value_t
Magnetic Rotary 3 Click return value data.
Definition magneticrotary3.h:189
@ MAGNETICROTARY3_OK
Definition magneticrotary3.h:190
@ MAGNETICROTARY3_ERROR
Definition magneticrotary3.h:191
This file contains SPI specific macros, functions, etc.
Magnetic Rotary 3 Click configuration object.
Definition magneticrotary3.h:170
spi_master_chip_select_polarity_t cs_polarity
Definition magneticrotary3.h:180
pin_name_t sck
Definition magneticrotary3.h:174
spi_master_mode_t spi_mode
Definition magneticrotary3.h:179
pin_name_t mosi
Definition magneticrotary3.h:173
uint32_t spi_speed
Definition magneticrotary3.h:178
pin_name_t miso
Definition magneticrotary3.h:172
pin_name_t cs
Definition magneticrotary3.h:175
Magnetic Rotary 3 Click context object.
Definition magneticrotary3.h:157
spi_master_t spi
Definition magneticrotary3.h:159
pin_name_t chip_select
Definition magneticrotary3.h:161