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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
49 #define T_MAGNROTARY_P const uint8_t*
50 
56 #define MAGNETICROTARY_MAP_MIKROBUS( cfg, mikrobus ) \
57  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
58  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
59  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
60  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
61 
67 #define MAGNETICROTARY_RETVAL uint8_t
68 
69 #define MAGNETICROTARY_OK 0x00
70 #define MAGNETICROTARY_INIT_ERROR 0xFF
71 
77 #define MAGNROTARY_CHA_POS_GND_NEG 0x80
78 #define MAGNROTARY_CHB_POS_GND_NEG 0xC0
79 #define MAGNROTARY_CHA_POS_CHB_NEG 0x00
80 #define MAGNROTARY_CHB_POS_CHA_NEG 0x40
81 
87 #define MAGNROTARY_MSB_LSB_ORDER 0x00
88 #define MAGNROTARY_MSB_ZEROS_ORDER 0x20
89 
95 #define MAGNROTARY_VDD_3V3 3298
96 #define MAGNROTARY_VDD_5V 4960
97 
103 #define MAGNROTARY_START_BYTE 0x01
104 #define MAGNROTARY_DUMMY_BYTE 0x00
105 #define MAGNROTARY_CMD_MASK 0xE0
106 #define MAGNROTARY_ADC_RESOLUTION 4096
107 #define MAGNROTARY_SIGN_BIT 0x0800
108  // End group macro
110 // --------------------------------------------------------------- PUBLIC TYPES
119 typedef struct
120 {
121  digital_out_t cs;
122 
123  // Modules
124  spi_master_t spi;
125  pin_name_t chip_select;
126 
128 
132 typedef struct
133 {
134  // Communication gpio pins
135 
136  pin_name_t miso;
137  pin_name_t mosi;
138  pin_name_t sck;
139  pin_name_t cs;
140 
141  // static variable
142 
143  uint32_t spi_speed;
144  spi_master_mode_t spi_mode;
145  spi_master_chip_select_polarity_t cs_polarity;
146 
148  // End types group
150 
151 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
152 
157 #ifdef __cplusplus
158 extern "C"{
159 #endif
160 
170 
179 
192 (
193  magneticrotary_t *ctx,
194  uint8_t *wr_buf,
195  uint16_t wr_len,
196  uint8_t *rd_buf,
197  uint16_t rd_len
198 );
199 
212 uint16_t magnrotary_out_volt_adc ( magneticrotary_t *ctx, uint8_t cmd_byte, uint16_t pwr_volt );
213 
224 uint16_t magnrotary_read_adc ( magneticrotary_t *ctx, uint8_t cmnd_byte );
225 
237 double magnrotary_get_field_angle ( magneticrotary_t *ctx, uint8_t cmd_byte );
238 
239 
240 #ifdef __cplusplus
241 }
242 #endif
243 #endif // _MAGNETICROTARY_H_
244  // End public_function group
247 
248 // ------------------------------------------------------------------------- END
magneticrotary_t::cs
digital_out_t cs
Definition: magneticrotary.h:121
magneticrotary_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: magneticrotary.h:145
magneticrotary_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: magneticrotary.h:144
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:67
magneticrotary_cfg_t
Click configuration structure definition.
Definition: magneticrotary.h:133
magneticrotary_cfg_t::mosi
pin_name_t mosi
Definition: magneticrotary.h:137
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:125
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:139
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:143
magneticrotary_t::spi
spi_master_t spi
Definition: magneticrotary.h:124
magneticrotary_t
Click ctx object definition.
Definition: magneticrotary.h:120
magneticrotary_cfg_t::miso
pin_name_t miso
Definition: magneticrotary.h:136
magneticrotary_cfg_t::sck
pin_name_t sck
Definition: magneticrotary.h:138