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 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
53 #define C3DHALL6_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
55  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
56  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
57  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
58 
64 #define C3DHALL6_OK 0
65 #define C3DHALL6_ERROR -1
66 
72 #define C3DHALL6_CHANNEL_0 0x00
73 #define C3DHALL6_CHANNEL_1 0x40
74 #define C3DHALL6_CHANNEL_2 0x80
75 #define C3DHALL6_CHANNEL_3 0xC0
76 
82 #define C3DHALL6_DIE_A 0x01
83 #define C3DHALL6_DIE_B 0x02
84 
90 #define SINGLE_PI_CONST 3.14
91 #define HALF_PI_CONST 1.57
92  // End group macro
95 // --------------------------------------------------------------- PUBLIC TYPES
101 typedef struct
102 {
103  uint16_t aux_ch0;
104  uint16_t aux_ch1;
105  uint16_t aux_ch2;
106  uint16_t aux_ch3;
107 
109 
110 typedef struct
111 {
116 
118 
119 typedef struct
120 {
126 
128 
132 typedef struct
133 {
134  // Modules
135  spi_master_t spi;
136  pin_name_t chip_select;
137 
141 
142 } c3dhall6_t;
143 
147 typedef struct
148 {
149  // Communication gpio pins
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  uint32_t spi_speed;
157  spi_master_mode_t spi_mode;
158  spi_master_chip_select_polarity_t cs_polarity;
159 
161 
163  // End types group
165 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
166 
171 #ifdef __cplusplus
172 extern "C"{
173 #endif
174 
184 
194 
203 
217 
227 void c3dhall6_get_adc_value ( c3dhall6_t *ctx, uint8_t channel_no, uint16_t *adc_value );
228 
238 void c3dhall6_get_volt( c3dhall6_t *ctx, uint8_t channel_no, float *channel_voltage );
239 
249 void c3dhall6_get_angle_deg ( c3dhall6_t *ctx, uint8_t die, float *angle_value );
250 
260 void c3dhall6_get_angle_rad ( c3dhall6_t *ctx, uint8_t die, float *angle_value );
261 
262 #ifdef __cplusplus
263 }
264 #endif
265 #endif // _C3DHALL6_H_
266  // End public_function group
269 
270 // ------------------------------------------------------------------------- END
c3dhall6_aux_ch_t::aux_ch1
uint16_t aux_ch1
Definition: c3dhall6.h:104
c3dhall6_t
Click ctx object definition.
Definition: c3dhall6.h:133
c3dhall6_t::chip_select
pin_name_t chip_select
Definition: c3dhall6.h:136
c3dhall6_aux_ch_t::aux_ch0
uint16_t aux_ch0
Definition: c3dhall6.h:103
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:138
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:112
c3dhall6_t::spi
spi_master_t spi
Definition: c3dhall6.h:135
c3dhall6_aux_ref_t::aux_ref_adc_ch0
float aux_ref_adc_ch0
Definition: c3dhall6.h:121
c3dhall6_aux_ch_t
Definition: c3dhall6.h:102
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:122
c3dhall6_aux_ch_t::aux_ch3
uint16_t aux_ch3
Definition: c3dhall6.h:106
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:157
c3dhall6_aux_float_ch_t::aux_float_ch1
float aux_float_ch1
Definition: c3dhall6.h:113
c3dhall6_aux_ref_t
Definition: c3dhall6.h:120
c3dhall6_cfg_t::sck
pin_name_t sck
Definition: c3dhall6.h:152
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:151
c3dhall6_aux_ref_t::aux_ref_adc_ch2
float aux_ref_adc_ch2
Definition: c3dhall6.h:123
c3dhall6_aux_float_ch_t::aux_float_ch2
float aux_float_ch2
Definition: c3dhall6.h:114
c3dhall6_t::device_float_ch
c3dhall6_aux_float_ch_t device_float_ch
Definition: c3dhall6.h:140
c3dhall6_cfg_t
Click configuration structure definition.
Definition: c3dhall6.h:148
c3dhall6_cfg_t::spi_speed
uint32_t spi_speed
Definition: c3dhall6.h:156
c3dhall6_aux_float_ch_t
Definition: c3dhall6.h:111
c3dhall6_cfg_t::cs
pin_name_t cs
Definition: c3dhall6.h:153
c3dhall6_aux_float_ch_t::aux_float_ch3
float aux_float_ch3
Definition: c3dhall6.h:115
c3dhall6_cfg_t::dev_aux_ref
c3dhall6_aux_ref_t dev_aux_ref
Definition: c3dhall6.h:160
c3dhall6_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: c3dhall6.h:158
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:139
c3dhall6_aux_ch_t::aux_ch2
uint16_t aux_ch2
Definition: c3dhall6.h:105
c3dhall6_aux_ref_t::aux_ref_volt
float aux_ref_volt
Definition: c3dhall6.h:125
c3dhall6_aux_ref_t::aux_ref_adc_ch3
float aux_ref_adc_ch3
Definition: c3dhall6.h:124
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:150