c3dhall  2.0.0.0
c3dhall.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 C3DHALL_H
36 #define C3DHALL_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 C3DHALL_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 C3DHALL_RETVAL uint8_t
79 
80 #define C3DHALL_OK 0x00
81 #define C3DHALL_INIT_ERROR 0xFF
82 
88 #define C3DHALL_NO_ERRORS 0x0000
89 #define C3DHALL_F_ADCMONITOR 0x0004
90 #define C3DHALL_F_ADCSATURA 0x0008
91 #define C3DHALL_F_GAINTOOLOW 0x0010
92 #define C3DHALL_F_GAINTOOHIGH 0x0020
93 #define C3DHALL_F_NORMTOOLOW 0x0040
94 #define C3DHALL_F_FIELDTOOLOW 0x0080
95 #define C3DHALL_F_FIELDTOOHIGH 0x0100
96 #define C3DHALL_F_ROCLAMP 0x0200
97 #define C3DHALL_F_DEADZONEALPHA 0x0800
98 #define C3DHALL_F_DEADZONEBETA 0x8000
99 #define C3DHALL_MULTIPLE_ERRORS 0xFFFF
100 #define C3DHALL_START_COMMUNICATION_BYTE 0xFF
101  // End group macro
104 // --------------------------------------------------------------- PUBLIC TYPES
113 typedef struct
114 {
115  digital_out_t cs;
116 
117  // Modules
118 
119  spi_master_t spi;
120  pin_name_t chip_select;
121 
122 } c3dhall_t;
123 
127 typedef struct
128 {
129  // Communication gpio pins
130 
131  pin_name_t miso;
132  pin_name_t mosi;
133  pin_name_t sck;
134  pin_name_t cs;
135 
136  // static variable
137 
138  uint32_t spi_speed;
139  spi_master_mode_t spi_mode;
140  spi_master_chip_select_polarity_t cs_polarity;
141 
142 } c3dhall_cfg_t;
143 
147 typedef struct
148 {
149  uint16_t data_angle_a;
150  uint16_t data_angle_b;
151  uint16_t data_error;
152  uint8_t data_sum;
153 
155  // End types group
157 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
158 
163 #ifdef __cplusplus
164 extern "C"{
165 #endif
166 
176 
186 
196 
205 uint8_t c3dhall_calculate_angle ( c3dhall_t *ctx, uint16_t data_angle );
206 
207 #ifdef __cplusplus
208 }
209 #endif
210 #endif // _C3DHALL_H_
211  // End public_function group
214 
215 // ------------------------------------------------------------------------- END
c3dhall_cfg_t::mosi
pin_name_t mosi
Definition: c3dhall.h:132
c3dhall_all_data_t::data_angle_a
uint16_t data_angle_a
Definition: c3dhall.h:149
c3dhall_cfg_setup
void c3dhall_cfg_setup(c3dhall_cfg_t *cfg)
Config Object Initialization function.
c3dhall_cfg_t::cs
pin_name_t cs
Definition: c3dhall.h:134
c3dhall_t::spi
spi_master_t spi
Definition: c3dhall.h:119
c3dhall_t::chip_select
pin_name_t chip_select
Definition: c3dhall.h:120
c3dhall_cfg_t
Click configuration structure definition.
Definition: c3dhall.h:128
c3dhall_all_data_t::data_angle_b
uint16_t data_angle_b
Definition: c3dhall.h:150
c3dhall_all_data_t::data_sum
uint8_t data_sum
Definition: c3dhall.h:152
C3DHALL_RETVAL
#define C3DHALL_RETVAL
Definition: c3dhall.h:78
c3dhall_cfg_t::spi_speed
uint32_t spi_speed
Definition: c3dhall.h:138
c3dhall_all_data_t::data_error
uint16_t data_error
Definition: c3dhall.h:151
c3dhall_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: c3dhall.h:139
c3dhall_cfg_t::miso
pin_name_t miso
Definition: c3dhall.h:131
c3dhall_cfg_t::sck
pin_name_t sck
Definition: c3dhall.h:133
c3dhall_init
C3DHALL_RETVAL c3dhall_init(c3dhall_t *ctx, c3dhall_cfg_t *cfg)
Initialization function.
c3dhall_t
Click ctx object definition.
Definition: c3dhall.h:114
c3dhall_read_all_data
void c3dhall_read_all_data(c3dhall_t *ctx, c3dhall_all_data_t *all_data)
Read 8 bytes data from sensor function.
c3dhall_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: c3dhall.h:140
c3dhall_all_data_t
All data structure definition.
Definition: c3dhall.h:148
c3dhall_calculate_angle
uint8_t c3dhall_calculate_angle(c3dhall_t *ctx, uint16_t data_angle)
Calculate angle function.
c3dhall_t::cs
digital_out_t cs
Definition: c3dhall.h:115