magneticrotary  2.0.0.0
magneticrotary.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef MAGNETICROTARY_H
36 #define MAGNETICROTARY_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_spi_master.h"
51 
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
59 #define T_MAGNROTARY_P const uint8_t*
60 
66 #define MAGNETICROTARY_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
68  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
69  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
70  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
71 
77 #define MAGNETICROTARY_RETVAL uint8_t
78 
79 #define MAGNETICROTARY_OK 0x00
80 #define MAGNETICROTARY_INIT_ERROR 0xFF
81 
87 #define MAGNROTARY_CHA_POS_GND_NEG 0x80
88 #define MAGNROTARY_CHB_POS_GND_NEG 0xC0
89 #define MAGNROTARY_CHA_POS_CHB_NEG 0x00
90 #define MAGNROTARY_CHB_POS_CHA_NEG 0x40
91 
97 #define MAGNROTARY_MSB_LSB_ORDER 0x00
98 #define MAGNROTARY_MSB_ZEROS_ORDER 0x20
99 
105 #define MAGNROTARY_VDD_3V3 3298
106 #define MAGNROTARY_VDD_5V 4960
107 
113 #define MAGNROTARY_START_BYTE 0x01
114 #define MAGNROTARY_DUMMY_BYTE 0x00
115 #define MAGNROTARY_CMD_MASK 0xE0
116 #define MAGNROTARY_ADC_RESOLUTION 4096
117 #define MAGNROTARY_SIGN_BIT 0x0800
118  // End group macro
120 // --------------------------------------------------------------- PUBLIC TYPES
129 typedef struct
130 {
131  digital_out_t cs;
132 
133  // Modules
134  spi_master_t spi;
135  pin_name_t chip_select;
136 
138 
142 typedef struct
143 {
144  // Communication gpio pins
145 
146  pin_name_t miso;
147  pin_name_t mosi;
148  pin_name_t sck;
149  pin_name_t cs;
150 
151  // static variable
152 
153  uint32_t spi_speed;
154  spi_master_mode_t spi_mode;
155  spi_master_chip_select_polarity_t cs_polarity;
156 
158  // End types group
160 
161 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
162 
167 #ifdef __cplusplus
168 extern "C"{
169 #endif
170 
180 
189 
202 (
203  magneticrotary_t *ctx,
204  uint8_t *wr_buf,
205  uint16_t wr_len,
206  uint8_t *rd_buf,
207  uint16_t rd_len
208 );
209 
222 uint16_t magnrotary_out_volt_adc ( magneticrotary_t *ctx, uint8_t cmd_byte, uint16_t pwr_volt );
223 
234 uint16_t magnrotary_read_adc ( magneticrotary_t *ctx, uint8_t cmnd_byte );
235 
247 double magnrotary_get_field_angle ( magneticrotary_t *ctx, uint8_t cmd_byte );
248 
249 
250 #ifdef __cplusplus
251 }
252 #endif
253 #endif // _MAGNETICROTARY_H_
254  // End public_function group
257 
258 // ------------------------------------------------------------------------- END
magneticrotary_t::cs
digital_out_t cs
Definition: magneticrotary.h:131
magneticrotary_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: magneticrotary.h:155
magneticrotary_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: magneticrotary.h:154
magnrotary_read_adc
uint16_t magnrotary_read_adc(magneticrotary_t *ctx, uint8_t cmnd_byte)
ADC Result Read function.
magnrotary_get_field_angle
double magnrotary_get_field_angle(magneticrotary_t *ctx, uint8_t cmd_byte)
Magnetic Field Angle Get function.
MAGNETICROTARY_RETVAL
#define MAGNETICROTARY_RETVAL
Definition: magneticrotary.h:77
magneticrotary_cfg_t
Click configuration structure definition.
Definition: magneticrotary.h:143
magneticrotary_cfg_t::mosi
pin_name_t mosi
Definition: magneticrotary.h:147
magnrotary_out_volt_adc
uint16_t magnrotary_out_volt_adc(magneticrotary_t *ctx, uint8_t cmd_byte, uint16_t pwr_volt)
ADC Output Voltage Get function.
magneticrotary_t::chip_select
pin_name_t chip_select
Definition: magneticrotary.h:135
magneticrotary_init
MAGNETICROTARY_RETVAL magneticrotary_init(magneticrotary_t *ctx, magneticrotary_cfg_t *cfg)
Initialization function.
magneticrotary_cfg_setup
void magneticrotary_cfg_setup(magneticrotary_cfg_t *cfg)
Config Object Initialization function.
magneticrotary_cfg_t::cs
pin_name_t cs
Definition: magneticrotary.h:149
magneticrotary_generic_transfer
void magneticrotary_generic_transfer(magneticrotary_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
magneticrotary_cfg_t::spi_speed
uint32_t spi_speed
Definition: magneticrotary.h:153
magneticrotary_t::spi
spi_master_t spi
Definition: magneticrotary.h:134
magneticrotary_t
Click ctx object definition.
Definition: magneticrotary.h:130
magneticrotary_cfg_t::miso
pin_name_t miso
Definition: magneticrotary.h:146
magneticrotary_cfg_t::sck
pin_name_t sck
Definition: magneticrotary.h:148