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 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_spi_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
63 #define C3DHALL_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
65  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
66  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
67  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
68 
74 #define C3DHALL_RETVAL uint8_t
75 
76 #define C3DHALL_OK 0x00
77 #define C3DHALL_INIT_ERROR 0xFF
78 
84 #define C3DHALL_NO_ERRORS 0x0000
85 #define C3DHALL_F_ADCMONITOR 0x0004
86 #define C3DHALL_F_ADCSATURA 0x0008
87 #define C3DHALL_F_GAINTOOLOW 0x0010
88 #define C3DHALL_F_GAINTOOHIGH 0x0020
89 #define C3DHALL_F_NORMTOOLOW 0x0040
90 #define C3DHALL_F_FIELDTOOLOW 0x0080
91 #define C3DHALL_F_FIELDTOOHIGH 0x0100
92 #define C3DHALL_F_ROCLAMP 0x0200
93 #define C3DHALL_F_DEADZONEALPHA 0x0800
94 #define C3DHALL_F_DEADZONEBETA 0x8000
95 #define C3DHALL_MULTIPLE_ERRORS 0xFFFF
96 #define C3DHALL_START_COMMUNICATION_BYTE 0xFF
97  // End group macro
100 // --------------------------------------------------------------- PUBLIC TYPES
109 typedef struct
110 {
111  digital_out_t cs;
112 
113  // Modules
114 
115  spi_master_t spi;
116  pin_name_t chip_select;
117 
118 } c3dhall_t;
119 
123 typedef struct
124 {
125  // Communication gpio pins
126 
127  pin_name_t miso;
128  pin_name_t mosi;
129  pin_name_t sck;
130  pin_name_t cs;
131 
132  // static variable
133 
134  uint32_t spi_speed;
135  spi_master_mode_t spi_mode;
136  spi_master_chip_select_polarity_t cs_polarity;
137 
138 } c3dhall_cfg_t;
139 
143 typedef struct
144 {
145  uint16_t data_angle_a;
146  uint16_t data_angle_b;
147  uint16_t data_error;
148  uint8_t data_sum;
149 
151  // End types group
153 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
154 
159 #ifdef __cplusplus
160 extern "C"{
161 #endif
162 
172 
182 
192 
201 uint8_t c3dhall_calculate_angle ( c3dhall_t *ctx, uint16_t data_angle );
202 
203 #ifdef __cplusplus
204 }
205 #endif
206 #endif // _C3DHALL_H_
207  // End public_function group
210 
211 // ------------------------------------------------------------------------- END
c3dhall_cfg_t::mosi
pin_name_t mosi
Definition: c3dhall.h:128
c3dhall_all_data_t::data_angle_a
uint16_t data_angle_a
Definition: c3dhall.h:145
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:130
c3dhall_t::spi
spi_master_t spi
Definition: c3dhall.h:115
c3dhall_t::chip_select
pin_name_t chip_select
Definition: c3dhall.h:116
c3dhall_cfg_t
Click configuration structure definition.
Definition: c3dhall.h:124
c3dhall_all_data_t::data_angle_b
uint16_t data_angle_b
Definition: c3dhall.h:146
c3dhall_all_data_t::data_sum
uint8_t data_sum
Definition: c3dhall.h:148
C3DHALL_RETVAL
#define C3DHALL_RETVAL
Definition: c3dhall.h:74
c3dhall_cfg_t::spi_speed
uint32_t spi_speed
Definition: c3dhall.h:134
c3dhall_all_data_t::data_error
uint16_t data_error
Definition: c3dhall.h:147
c3dhall_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: c3dhall.h:135
c3dhall_cfg_t::miso
pin_name_t miso
Definition: c3dhall.h:127
c3dhall_cfg_t::sck
pin_name_t sck
Definition: c3dhall.h:129
c3dhall_init
C3DHALL_RETVAL c3dhall_init(c3dhall_t *ctx, c3dhall_cfg_t *cfg)
Initialization function.
c3dhall_t
Click ctx object definition.
Definition: c3dhall.h:110
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:136
c3dhall_all_data_t
All data structure definition.
Definition: c3dhall.h:144
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:111