c3dhall6  2.0.0.0
c3dhall6.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 C3DHALL6_H
36 #define C3DHALL6_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 // -------------------------------------------------------------- PUBLIC MACROS
67 #define C3DHALL6_MAP_MIKROBUS( cfg, mikrobus ) \
68  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
69  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
70  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
71  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
72 
78 #define C3DHALL6_OK 0
79 #define C3DHALL6_ERROR -1
80 
86 #define C3DHALL6_CHANNEL_0 0x00
87 #define C3DHALL6_CHANNEL_1 0x40
88 #define C3DHALL6_CHANNEL_2 0x80
89 #define C3DHALL6_CHANNEL_3 0xC0
90 
96 #define C3DHALL6_DIE_A 0x01
97 #define C3DHALL6_DIE_B 0x02
98 
104 #define SINGLE_PI_CONST 3.14
105 #define HALF_PI_CONST 1.57
106  // End group macro
109 // --------------------------------------------------------------- PUBLIC TYPES
115 typedef struct
116 {
117  uint16_t aux_ch0;
118  uint16_t aux_ch1;
119  uint16_t aux_ch2;
120  uint16_t aux_ch3;
121 
123 
124 typedef struct
125 {
130 
132 
133 typedef struct
134 {
140 
142 
146 typedef struct
147 {
148  // Modules
149  spi_master_t spi;
150  pin_name_t chip_select;
151 
155 
156 } c3dhall6_t;
157 
161 typedef struct
162 {
163  // Communication gpio pins
164  pin_name_t miso;
165  pin_name_t mosi;
166  pin_name_t sck;
167  pin_name_t cs;
168 
169  // static variable
170  uint32_t spi_speed;
171  spi_master_mode_t spi_mode;
172  spi_master_chip_select_polarity_t cs_polarity;
173 
175 
177  // End types group
179 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
180 
185 #ifdef __cplusplus
186 extern "C"{
187 #endif
188 
198 
208 
217 
231 
241 void c3dhall6_get_adc_value ( c3dhall6_t *ctx, uint8_t channel_no, uint16_t *adc_value );
242 
252 void c3dhall6_get_volt( c3dhall6_t *ctx, uint8_t channel_no, float *channel_voltage );
253 
263 void c3dhall6_get_angle_deg ( c3dhall6_t *ctx, uint8_t die, float *angle_value );
264 
274 void c3dhall6_get_angle_rad ( c3dhall6_t *ctx, uint8_t die, float *angle_value );
275 
276 #ifdef __cplusplus
277 }
278 #endif
279 #endif // _C3DHALL6_H_
280  // End public_function group
283 
284 // ------------------------------------------------------------------------- END
c3dhall6_aux_ch_t::aux_ch1
uint16_t aux_ch1
Definition: c3dhall6.h:118
c3dhall6_t
Click ctx object definition.
Definition: c3dhall6.h:147
c3dhall6_t::chip_select
pin_name_t chip_select
Definition: c3dhall6.h:150
c3dhall6_aux_ch_t::aux_ch0
uint16_t aux_ch0
Definition: c3dhall6.h:117
c3dhall6_cfg_setup
void c3dhall6_cfg_setup(c3dhall6_cfg_t *cfg)
Config Object Initialization function.
c3dhall6_t::device_aux_ref
c3dhall6_aux_ref_t device_aux_ref
Definition: c3dhall6.h:152
c3dhall6_set_reference_values
void c3dhall6_set_reference_values(c3dhall6_t *ctx, c3dhall6_aux_ref_t ref_val)
Setting reference values function.
c3dhall6_aux_float_ch_t::aux_float_ch0
float aux_float_ch0
Definition: c3dhall6.h:126
c3dhall6_t::spi
spi_master_t spi
Definition: c3dhall6.h:149
c3dhall6_aux_ref_t::aux_ref_adc_ch0
float aux_ref_adc_ch0
Definition: c3dhall6.h:135
c3dhall6_aux_ch_t
Definition: c3dhall6.h:116
c3dhall6_get_angle_deg
void c3dhall6_get_angle_deg(c3dhall6_t *ctx, uint8_t die, float *angle_value)
GGetting angle value function.
c3dhall6_aux_ref_t::aux_ref_adc_ch1
float aux_ref_adc_ch1
Definition: c3dhall6.h:136
c3dhall6_aux_ch_t::aux_ch3
uint16_t aux_ch3
Definition: c3dhall6.h:120
c3dhall6_get_volt
void c3dhall6_get_volt(c3dhall6_t *ctx, uint8_t channel_no, float *channel_voltage)
Getting voltage on each channel function.
c3dhall6_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: c3dhall6.h:171
c3dhall6_aux_float_ch_t::aux_float_ch1
float aux_float_ch1
Definition: c3dhall6.h:127
c3dhall6_aux_ref_t
Definition: c3dhall6.h:134
c3dhall6_cfg_t::sck
pin_name_t sck
Definition: c3dhall6.h:166
c3dhall6_default_cfg
void c3dhall6_default_cfg(c3dhall6_t *ctx)
Click Default Configuration function.
c3dhall6_cfg_t::mosi
pin_name_t mosi
Definition: c3dhall6.h:165
c3dhall6_aux_ref_t::aux_ref_adc_ch2
float aux_ref_adc_ch2
Definition: c3dhall6.h:137
c3dhall6_aux_float_ch_t::aux_float_ch2
float aux_float_ch2
Definition: c3dhall6.h:128
c3dhall6_t::device_float_ch
c3dhall6_aux_float_ch_t device_float_ch
Definition: c3dhall6.h:154
c3dhall6_cfg_t
Click configuration structure definition.
Definition: c3dhall6.h:162
c3dhall6_cfg_t::spi_speed
uint32_t spi_speed
Definition: c3dhall6.h:170
c3dhall6_aux_float_ch_t
Definition: c3dhall6.h:125
c3dhall6_cfg_t::cs
pin_name_t cs
Definition: c3dhall6.h:167
c3dhall6_aux_float_ch_t::aux_float_ch3
float aux_float_ch3
Definition: c3dhall6.h:129
c3dhall6_cfg_t::dev_aux_ref
c3dhall6_aux_ref_t dev_aux_ref
Definition: c3dhall6.h:174
c3dhall6_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: c3dhall6.h:172
c3dhall6_init
err_t c3dhall6_init(c3dhall6_t *ctx, c3dhall6_cfg_t *cfg)
Initialization function.
c3dhall6_t::device_aux_ch
c3dhall6_aux_ch_t device_aux_ch
Definition: c3dhall6.h:153
c3dhall6_aux_ch_t::aux_ch2
uint16_t aux_ch2
Definition: c3dhall6.h:119
c3dhall6_aux_ref_t::aux_ref_volt
float aux_ref_volt
Definition: c3dhall6.h:139
c3dhall6_aux_ref_t::aux_ref_adc_ch3
float aux_ref_adc_ch3
Definition: c3dhall6.h:138
c3dhall6_get_angle_rad
void c3dhall6_get_angle_rad(c3dhall6_t *ctx, uint8_t die, float *angle_value)
GGetting angle value function.
c3dhall6_get_adc_value
void c3dhall6_get_adc_value(c3dhall6_t *ctx, uint8_t channel_no, uint16_t *adc_value)
Getting ADC value on each channel function.
c3dhall6_cfg_t::miso
pin_name_t miso
Definition: c3dhall6.h:164