mrangle 2.0.0.0
mrangle.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 MRANGLE_H
29#define MRANGLE_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_spi_master.h"
51#include "math.h"
52
53
74#define MRANGLE_MAP_MIKROBUS( cfg, mikrobus ) \
75 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
76 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
77 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
78 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
79 cfg.tce = MIKROBUS( mikrobus, MIKROBUS_RST ); \
80 cfg.pdn = MIKROBUS( mikrobus, MIKROBUS_PWM )
81
82 // mrangle_map
83 // mrangle
84
89typedef struct
90{
91 // Output pins
92 digital_out_t tce;
93 digital_out_t pdn;
95 // Modules
96 spi_master_t spi;
98 pin_name_t chip_select;
100 float vref;
102} mrangle_t;
103
108typedef struct
109{
110 // Communication gpio pins
111 pin_name_t miso;
112 pin_name_t mosi;
113 pin_name_t sck;
114 pin_name_t cs;
116 // Additional gpio pins
117 pin_name_t tce;
118 pin_name_t pdn;
120 // static variable
121 uint32_t spi_speed;
122 spi_master_mode_t spi_mode;
123 spi_master_chip_select_polarity_t cs_polarity;
125 float vref;
128
133typedef enum
134{
136 MRANGLE_ERROR = -1
137
139
150
161
178
193
205
218
232
247err_t mrangle_generic_write ( mrangle_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
248
263err_t mrangle_generic_read ( mrangle_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
264
278err_t mrangle_get_adc_sin ( mrangle_t *ctx, uint16_t *sin_adc );
279
294err_t mrangle_get_sin ( mrangle_t *ctx, float *sin );
295
309err_t mrangle_get_adc_cos ( mrangle_t *ctx, uint16_t *cos_adc );
310
325err_t mrangle_get_cos ( mrangle_t *ctx, float *cos );
326
340err_t mrangle_get_adc_temp ( mrangle_t *ctx, uint16_t *temp_adc );
341
355err_t mrangle_get_temperature ( mrangle_t *ctx, float *temperature );
356
370err_t mrangle_get_angle ( mrangle_t *ctx, float *angle );
371
372#ifdef __cplusplus
373}
374#endif
375#endif // MRANGLE_H
376
377 // mrangle
378
379// ------------------------------------------------------------------------ END
err_t mrangle_get_adc_sin(mrangle_t *ctx, uint16_t *sin_adc)
MR Angle get ADC sine function.
err_t mrangle_get_adc_cos(mrangle_t *ctx, uint16_t *cos_adc)
MR Angle get ADC cosine function.
err_t mrangle_generic_read(mrangle_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
MR Angle data reading function.
void mrangle_output_mode(mrangle_t *ctx, mrangle_output_mode_value_t output_mode)
MR Angle output mode function.
err_t mrangle_get_sin(mrangle_t *ctx, float *sin)
MR Angle get sine function.
err_t mrangle_generic_write(mrangle_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
MR Angle data writing function.
err_t mrangle_get_adc_temp(mrangle_t *ctx, uint16_t *temp_adc)
MR Angle get ADC temperature function.
void mrangle_default_cfg(mrangle_t *ctx)
MR Angle default configuration function.
void mrangle_cfg_setup(mrangle_cfg_t *cfg)
MR Angle configuration object setup function.
void mrangle_powerdown_mode(mrangle_t *ctx, mrangle_powerdown_mode_value_t pd_mode)
MR Angle powerdown mode function.
err_t mrangle_get_temperature(mrangle_t *ctx, float *temperature)
MR Angle get temperature function.
err_t mrangle_get_angle(mrangle_t *ctx, float *angle)
MR Angle get angle function.
err_t mrangle_init(mrangle_t *ctx, mrangle_cfg_t *cfg)
MR Angle initialization function.
err_t mrangle_get_cos(mrangle_t *ctx, float *cos)
MR Angle get cosine function.
mrangle_output_mode_value_t
MR Angle Click output mode value data.
Definition mrangle.h:156
@ OUTPUT_MODE_VOUT_TEMP
Definition mrangle.h:158
@ OUTPUT_MODE_VOUT_SIN_COS
Definition mrangle.h:157
mrangle_powerdown_mode_value_t
MR Angle Click powerdown mode value data.
Definition mrangle.h:145
@ POWERDOWN_MODE_DISABLE
Definition mrangle.h:146
@ POWERDOWN_MODE_ENABLE
Definition mrangle.h:147
mrangle_return_value_t
MR Angle Click return value data.
Definition mrangle.h:134
@ MRANGLE_ERROR
Definition mrangle.h:136
@ MRANGLE_OK
Definition mrangle.h:135
MR Angle Click configuration object.
Definition mrangle.h:109
float vref
Definition mrangle.h:125
spi_master_chip_select_polarity_t cs_polarity
Definition mrangle.h:123
pin_name_t sck
Definition mrangle.h:113
spi_master_mode_t spi_mode
Definition mrangle.h:122
pin_name_t pdn
Definition mrangle.h:118
pin_name_t mosi
Definition mrangle.h:112
uint32_t spi_speed
Definition mrangle.h:121
pin_name_t tce
Definition mrangle.h:117
pin_name_t miso
Definition mrangle.h:111
pin_name_t cs
Definition mrangle.h:114
MR Angle Click context object.
Definition mrangle.h:90
spi_master_t spi
Definition mrangle.h:96
float vref
Definition mrangle.h:100
digital_out_t pdn
Definition mrangle.h:93
digital_out_t tce
Definition mrangle.h:92
pin_name_t chip_select
Definition mrangle.h:98