amrangle 2.0.0.0
amrangle.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 AMRANGLE_H
29#define AMRANGLE_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_digital_in.h"
51#include "drv_spi_master.h"
52#include "drv_analog_in.h"
53#include "math.h"
54
75#define AMRANGLE_ARM_TOOLCHAIN 0x00
76
81#define AMRANGLE_PIC_TOOLCHAIN 0x01
82
83 // sel_toolchain
84
99#define AMRANGLE_GAIN_CONTROL_EN 0x01
100
105#define AMRANGLE_GAIN_CONTROL_DIS 0x00
106
107 // gain_control
108
123#define AMRANGLE_POWER_DOWN_EN 0x01
124
129#define AMRANGLE_POWER_DOWN_DIS 0x00
130
131 // pd_state
132
147#define AMRANGLE_MAP_MIKROBUS( cfg, mikrobus ) \
148 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
149 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
150 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
151 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
152 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
153 cfg.gc = MIKROBUS( mikrobus, MIKROBUS_RST ); \
154 cfg.pd = MIKROBUS( mikrobus, MIKROBUS_PWM )
155
156 // amrangle_map
157 // amrangle
158
163typedef struct
164{
165 // Output pins
166
167 digital_out_t gc;
168 digital_out_t pd;
170 // Modules
171
172 analog_in_t adc;
174 spi_master_t spi;
176 pin_name_t chip_select;
178} amrangle_t;
179
184typedef struct
185{
186 // Communication gpio pins
187
188 pin_name_t miso;
189 pin_name_t mosi;
190 pin_name_t sck;
191 pin_name_t cs;
193 // Additional gpio pins
194
195 pin_name_t an;
196 pin_name_t gc;
197 pin_name_t pd;
199 // static variable
200
201 uint32_t spi_speed;
202 spi_master_mode_t spi_mode;
203 spi_master_chip_select_polarity_t cs_polarity;
205 analog_in_resolution_t resolution;
206 float vref;
209
214typedef enum
215{
217 AMRANGLE_ERROR = -1
218
220
239void amrangle_cfg_setup ( amrangle_cfg_t *cfg, uint8_t sel_toolchain );
240
256
268
279
292err_t amrangle_read_vtp_voltage ( amrangle_t *ctx, float *vtp_volts );
293
308
321void amrangle_gain_control_mode ( amrangle_t *ctx, uint8_t gain_control );
322
334void amrangle_power_down_pin ( amrangle_t *ctx, uint8_t pd_state );
335
336#ifdef __cplusplus
337}
338#endif
339#endif // AMRANGLE_H
340
341 // amrangle
342
343// ------------------------------------------------------------------------ END
amrangle_return_value_t
AMR Angle Click return value data.
Definition amrangle.h:215
@ AMRANGLE_OK
Definition amrangle.h:216
@ AMRANGLE_ERROR
Definition amrangle.h:217
float amrangle_angle_read(amrangle_t *ctx)
AMR Angle read angle function.
void amrangle_gain_control_mode(amrangle_t *ctx, uint8_t gain_control)
AMR Angle gain control mode function.
err_t amrangle_read_vtp_voltage(amrangle_t *ctx, float *vtp_volts)
AMR Angle read vtp voltage function.
err_t amrangle_init(amrangle_t *ctx, amrangle_cfg_t *cfg)
AMR Angle initialization function.
void amrangle_default_cfg(amrangle_t *ctx)
AMR Angle default configuration function.
float amrangle_read_vtp_temp(amrangle_t *ctx)
AMR Angle read temperature function.
void amrangle_power_down_pin(amrangle_t *ctx, uint8_t pd_state)
AMR Angle power down function.
void amrangle_cfg_setup(amrangle_cfg_t *cfg, uint8_t sel_toolchain)
AMR Angle configuration object setup function.
AMR Angle Click configuration object.
Definition amrangle.h:185
analog_in_resolution_t resolution
Definition amrangle.h:205
float vref
Definition amrangle.h:206
spi_master_chip_select_polarity_t cs_polarity
Definition amrangle.h:203
pin_name_t sck
Definition amrangle.h:190
spi_master_mode_t spi_mode
Definition amrangle.h:202
pin_name_t mosi
Definition amrangle.h:189
uint32_t spi_speed
Definition amrangle.h:201
pin_name_t miso
Definition amrangle.h:188
pin_name_t pd
Definition amrangle.h:197
pin_name_t gc
Definition amrangle.h:196
pin_name_t an
Definition amrangle.h:195
pin_name_t cs
Definition amrangle.h:191
AMR Angle Click context object.
Definition amrangle.h:164
digital_out_t gc
Definition amrangle.h:167
spi_master_t spi
Definition amrangle.h:174
digital_out_t pd
Definition amrangle.h:168
pin_name_t chip_select
Definition amrangle.h:176
analog_in_t adc
Definition amrangle.h:172