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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
38 #include "spi_specifics.h"
39 
60 #define MAGNETICROTARY4_REG_NOP 0x0000
61 #define MAGNETICROTARY4_REG_ERRFL 0x0001
62 #define MAGNETICROTARY4_REG_PROG 0x0003
63 #define MAGNETICROTARY4_REG_DIAAGC 0x3FFC
64 #define MAGNETICROTARY4_REG_MAG 0x3FFD
65 #define MAGNETICROTARY4_REG_ANGLEUNC 0x3FFE
66 #define MAGNETICROTARY4_REG_ANGLECOM 0x3FFF
67 
72 #define MAGNETICROTARY4_REG_ZPOSM 0x0016
73 #define MAGNETICROTARY4_REG_ZPOSL 0x0017
74 #define MAGNETICROTARY4_REG_SETTINGS1 0x0018
75 #define MAGNETICROTARY4_REG_SETTINGS2 0x0019
76  // magneticrotary4_reg
78 
93 #define MAGNETICROTARY4_DATA_RESOLUTION 0x3FFF
94 #define MAGNETICROTARY4_FULL_CIRCLE 360
95 
100 #define MAGNETICROTARY4_ODD_PARITY 0x01
101 
106 #define MAGNETICROTARY4_DIRECTION_CW 0
107 #define MAGNETICROTARY4_DIRECTION_CCW 1
108 
117 #define MAGNETICROTARY4_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
118 #define MAGNETICROTARY4_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
119  // magneticrotary4_set
121 
136 #define MAGNETICROTARY4_MAP_MIKROBUS( cfg, mikrobus ) \
137  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
138  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
139  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
140  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
141  // magneticrotary4_map // magneticrotary4
144 
149 typedef struct
150 {
151  // Modules
152  spi_master_t spi;
154  pin_name_t chip_select;
157 
162 typedef struct
163 {
164  // Communication gpio pins
165  pin_name_t miso;
166  pin_name_t mosi;
167  pin_name_t sck;
168  pin_name_t cs;
170  // static variable
171  uint32_t spi_speed;
172  spi_master_mode_t spi_mode;
173  spi_master_chip_select_polarity_t cs_polarity;
176 
181 typedef enum
182 {
185 
187 
204 
219 
232 err_t magneticrotary4_write_register ( magneticrotary4_t *ctx, uint16_t reg, uint16_t data_in );
233 
246 err_t magneticrotary4_read_register ( magneticrotary4_t *ctx, uint16_t reg, uint16_t *data_out );
247 
259 err_t magneticrotary4_get_angle ( magneticrotary4_t *ctx, float *angle );
260 
272 
286 
287 #ifdef __cplusplus
288 }
289 #endif
290 #endif // MAGNETICROTARY4_H
291  // magneticrotary4
293 
294 // ------------------------------------------------------------------------ END
magneticrotary4_t::chip_select
pin_name_t chip_select
Definition: magneticrotary4.h:154
magneticrotary4_cfg_t::miso
pin_name_t miso
Definition: magneticrotary4.h:165
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:183
magneticrotary4_cfg_t::sck
pin_name_t sck
Definition: magneticrotary4.h:167
magneticrotary4_return_value_t
magneticrotary4_return_value_t
Magnetic Rotary 4 Click return value data.
Definition: magneticrotary4.h:182
magneticrotary4_cfg_t::cs
pin_name_t cs
Definition: magneticrotary4.h:168
magneticrotary4_t
Magnetic Rotary 4 Click context object.
Definition: magneticrotary4.h:150
magneticrotary4_cfg_t
Magnetic Rotary 4 Click configuration object.
Definition: magneticrotary4.h:163
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:171
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:172
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:152
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:173
magneticrotary4_cfg_t::mosi
pin_name_t mosi
Definition: magneticrotary4.h:166
MAGNETICROTARY4_ERROR
@ MAGNETICROTARY4_ERROR
Definition: magneticrotary4.h:184