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
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
38 #include "drv_analog_in.h"
39 #include "math.h"
40 
61 #define AMRANGLE_ARM_TOOLCHAIN 0x00
62 
67 #define AMRANGLE_PIC_TOOLCHAIN 0x01
68  // sel_toolchain
70 
85 #define AMRANGLE_GAIN_CONTROL_EN 0x01
86 
91 #define AMRANGLE_GAIN_CONTROL_DIS 0x00
92  // gain_control
94 
109 #define AMRANGLE_POWER_DOWN_EN 0x01
110 
115 #define AMRANGLE_POWER_DOWN_DIS 0x00
116  // pd_state
118 
133 #define AMRANGLE_MAP_MIKROBUS( cfg, mikrobus ) \
134  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
135  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
136  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
137  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
138  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
139  cfg.gc = MIKROBUS( mikrobus, MIKROBUS_RST ); \
140  cfg.pd = MIKROBUS( mikrobus, MIKROBUS_PWM )
141  // amrangle_map // amrangle
144 
149 typedef struct
150 {
151  // Output pins
152 
153  digital_out_t gc;
154  digital_out_t pd;
156  // Modules
157 
158  analog_in_t adc;
160  spi_master_t spi;
162  pin_name_t chip_select;
164 } amrangle_t;
165 
170 typedef struct
171 {
172  // Communication gpio pins
173 
174  pin_name_t miso;
175  pin_name_t mosi;
176  pin_name_t sck;
177  pin_name_t cs;
179  // Additional gpio pins
180 
181  pin_name_t an;
182  pin_name_t gc;
183  pin_name_t pd;
185  // static variable
186 
187  uint32_t spi_speed;
188  spi_master_mode_t spi_mode;
189  spi_master_chip_select_polarity_t cs_polarity;
191  analog_in_resolution_t resolution;
192  float vref;
195 
200 typedef enum
201 {
203  AMRANGLE_ERROR = -1
204 
206 
225 void amrangle_cfg_setup ( amrangle_cfg_t *cfg, uint8_t sel_toolchain );
226 
241 err_t amrangle_init ( amrangle_t *ctx, amrangle_cfg_t *cfg );
242 
253 void amrangle_default_cfg ( amrangle_t *ctx );
254 
264 float amrangle_angle_read ( amrangle_t *ctx );
265 
278 err_t amrangle_read_vtp_voltage ( amrangle_t *ctx, float *vtp_volts );
279 
293 float amrangle_read_vtp_temp ( amrangle_t *ctx );
294 
307 void amrangle_gain_control_mode ( amrangle_t *ctx, uint8_t gain_control );
308 
320 void amrangle_power_down_pin ( amrangle_t *ctx, uint8_t pd_state );
321 
322 #ifdef __cplusplus
323 }
324 #endif
325 #endif // AMRANGLE_H
326  // amrangle
328 
329 // ------------------------------------------------------------------------ END
amrangle_read_vtp_temp
float amrangle_read_vtp_temp(amrangle_t *ctx)
AMR Angle read temperature function.
amrangle_t
AMR Angle Click context object.
Definition: amrangle.h:148
AMRANGLE_ERROR
Definition: amrangle.h:202
AMRANGLE_OK
Definition: amrangle.h:201
amrangle_return_value_t
amrangle_return_value_t
AMR Angle Click return value data.
Definition: amrangle.h:199
amrangle_angle_read
float amrangle_angle_read(amrangle_t *ctx)
AMR Angle read angle function.
amrangle_read_vtp_voltage
err_t amrangle_read_vtp_voltage(amrangle_t *ctx, float *vtp_volts)
AMR Angle read vtp voltage function.
amrangle_power_down_pin
void amrangle_power_down_pin(amrangle_t *ctx, uint8_t pd_state)
AMR Angle power down function.
amrangle_cfg_t
AMR Angle Click configuration object.
Definition: amrangle.h:169
amrangle_gain_control_mode
void amrangle_gain_control_mode(amrangle_t *ctx, uint8_t gain_control)
AMR Angle gain control mode function.
amrangle_init
err_t amrangle_init(amrangle_t *ctx, amrangle_cfg_t *cfg)
AMR Angle initialization function.
amrangle_cfg_setup
void amrangle_cfg_setup(amrangle_cfg_t *cfg, uint8_t sel_toolchain)
AMR Angle configuration object setup function.
amrangle_default_cfg
void amrangle_default_cfg(amrangle_t *ctx)
AMR Angle default configuration function.