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
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_spi_master.h"
55
56
57// -------------------------------------------------------------- PUBLIC MACROS
63#define T_MAGNROTARY_P const uint8_t*
64
70#define MAGNETICROTARY_MAP_MIKROBUS( cfg, mikrobus ) \
71 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
72 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
73 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
74 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
81#define MAGNETICROTARY_RETVAL uint8_t
82
83#define MAGNETICROTARY_OK 0x00
84#define MAGNETICROTARY_INIT_ERROR 0xFF
91#define MAGNROTARY_CHA_POS_GND_NEG 0x80
92#define MAGNROTARY_CHB_POS_GND_NEG 0xC0
93#define MAGNROTARY_CHA_POS_CHB_NEG 0x00
94#define MAGNROTARY_CHB_POS_CHA_NEG 0x40
101#define MAGNROTARY_MSB_LSB_ORDER 0x00
102#define MAGNROTARY_MSB_ZEROS_ORDER 0x20
109#define MAGNROTARY_VDD_3V3 3298
110#define MAGNROTARY_VDD_5V 4960
117#define MAGNROTARY_START_BYTE 0x01
118#define MAGNROTARY_DUMMY_BYTE 0x00
119#define MAGNROTARY_CMD_MASK 0xE0
120#define MAGNROTARY_ADC_RESOLUTION 4096
121#define MAGNROTARY_SIGN_BIT 0x0800
123 // End group macro
124// --------------------------------------------------------------- PUBLIC TYPES
133typedef struct
134{
135 digital_out_t cs;
136
137 // Modules
138 spi_master_t spi;
139 pin_name_t chip_select;
140
142
146typedef struct
147{
148 // Communication gpio pins
149
150 pin_name_t miso;
151 pin_name_t mosi;
152 pin_name_t sck;
153 pin_name_t cs;
154
155 // static variable
156
157 uint32_t spi_speed;
158 spi_master_mode_t spi_mode;
159 spi_master_chip_select_polarity_t cs_polarity;
160
162
163 // End types group
164
165// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
166
171#ifdef __cplusplus
172extern "C"{
173#endif
174
184
193
206(
207 magneticrotary_t *ctx,
208 uint8_t *wr_buf,
209 uint16_t wr_len,
210 uint8_t *rd_buf,
211 uint16_t rd_len
212);
213
226uint16_t magnrotary_out_volt_adc ( magneticrotary_t *ctx, uint8_t cmd_byte, uint16_t pwr_volt );
227
238uint16_t magnrotary_read_adc ( magneticrotary_t *ctx, uint8_t cmnd_byte );
239
251double magnrotary_get_field_angle ( magneticrotary_t *ctx, uint8_t cmd_byte );
252
253
254#ifdef __cplusplus
255}
256#endif
257#endif // _MAGNETICROTARY_H_
258
259 // End public_function group
261
262// ------------------------------------------------------------------------- END
#define MAGNETICROTARY_RETVAL
Definition magneticrotary.h:81
uint16_t magnrotary_read_adc(magneticrotary_t *ctx, uint8_t cmnd_byte)
ADC Result Read function.
uint16_t magnrotary_out_volt_adc(magneticrotary_t *ctx, uint8_t cmd_byte, uint16_t pwr_volt)
ADC Output Voltage Get function.
void magneticrotary_cfg_setup(magneticrotary_cfg_t *cfg)
Config Object Initialization function.
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.
double magnrotary_get_field_angle(magneticrotary_t *ctx, uint8_t cmd_byte)
Magnetic Field Angle Get function.
MAGNETICROTARY_RETVAL magneticrotary_init(magneticrotary_t *ctx, magneticrotary_cfg_t *cfg)
Initialization function.
Click configuration structure definition.
Definition magneticrotary.h:147
spi_master_chip_select_polarity_t cs_polarity
Definition magneticrotary.h:159
pin_name_t sck
Definition magneticrotary.h:152
spi_master_mode_t spi_mode
Definition magneticrotary.h:158
pin_name_t mosi
Definition magneticrotary.h:151
uint32_t spi_speed
Definition magneticrotary.h:157
pin_name_t miso
Definition magneticrotary.h:150
pin_name_t cs
Definition magneticrotary.h:153
Click ctx object definition.
Definition magneticrotary.h:134
digital_out_t cs
Definition magneticrotary.h:135
spi_master_t spi
Definition magneticrotary.h:138
pin_name_t chip_select
Definition magneticrotary.h:139