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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
53 #define C3DHALL_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 C3DHALL_RETVAL uint8_t
65 
66 #define C3DHALL_OK 0x00
67 #define C3DHALL_INIT_ERROR 0xFF
68 
74 #define C3DHALL_NO_ERRORS 0x0000
75 #define C3DHALL_F_ADCMONITOR 0x0004
76 #define C3DHALL_F_ADCSATURA 0x0008
77 #define C3DHALL_F_GAINTOOLOW 0x0010
78 #define C3DHALL_F_GAINTOOHIGH 0x0020
79 #define C3DHALL_F_NORMTOOLOW 0x0040
80 #define C3DHALL_F_FIELDTOOLOW 0x0080
81 #define C3DHALL_F_FIELDTOOHIGH 0x0100
82 #define C3DHALL_F_ROCLAMP 0x0200
83 #define C3DHALL_F_DEADZONEALPHA 0x0800
84 #define C3DHALL_F_DEADZONEBETA 0x8000
85 #define C3DHALL_MULTIPLE_ERRORS 0xFFFF
86 #define C3DHALL_START_COMMUNICATION_BYTE 0xFF
87  // End group macro
90 // --------------------------------------------------------------- PUBLIC TYPES
99 typedef struct
100 {
101  digital_out_t cs;
102 
103  // Modules
104 
105  spi_master_t spi;
106  pin_name_t chip_select;
107 
108 } c3dhall_t;
109 
113 typedef struct
114 {
115  // Communication gpio pins
116 
117  pin_name_t miso;
118  pin_name_t mosi;
119  pin_name_t sck;
120  pin_name_t cs;
121 
122  // static variable
123 
124  uint32_t spi_speed;
125  spi_master_mode_t spi_mode;
126  spi_master_chip_select_polarity_t cs_polarity;
127 
128 } c3dhall_cfg_t;
129 
133 typedef struct
134 {
135  uint16_t data_angle_a;
136  uint16_t data_angle_b;
137  uint16_t data_error;
138  uint8_t data_sum;
139 
141  // End types group
143 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
144 
149 #ifdef __cplusplus
150 extern "C"{
151 #endif
152 
161 void c3dhall_cfg_setup ( c3dhall_cfg_t *cfg );
162 
172 
181 void c3dhall_read_all_data ( c3dhall_t *ctx, c3dhall_all_data_t *all_data );
182 
191 uint8_t c3dhall_calculate_angle ( c3dhall_t *ctx, uint16_t data_angle );
192 
193 #ifdef __cplusplus
194 }
195 #endif
196 #endif // _C3DHALL_H_
197  // End public_function group
200 
201 // ------------------------------------------------------------------------- END
c3dhall_cfg_t::mosi
pin_name_t mosi
Definition: c3dhall.h:118
c3dhall_all_data_t::data_angle_a
uint16_t data_angle_a
Definition: c3dhall.h:135
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:120
c3dhall_t::spi
spi_master_t spi
Definition: c3dhall.h:105
c3dhall_t::chip_select
pin_name_t chip_select
Definition: c3dhall.h:106
c3dhall_cfg_t
Click configuration structure definition.
Definition: c3dhall.h:113
c3dhall_all_data_t::data_angle_b
uint16_t data_angle_b
Definition: c3dhall.h:136
c3dhall_all_data_t::data_sum
uint8_t data_sum
Definition: c3dhall.h:138
C3DHALL_RETVAL
#define C3DHALL_RETVAL
Definition: c3dhall.h:64
c3dhall_cfg_t::spi_speed
uint32_t spi_speed
Definition: c3dhall.h:124
c3dhall_all_data_t::data_error
uint16_t data_error
Definition: c3dhall.h:137
c3dhall_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: c3dhall.h:125
c3dhall_cfg_t::miso
pin_name_t miso
Definition: c3dhall.h:117
c3dhall_cfg_t::sck
pin_name_t sck
Definition: c3dhall.h:119
c3dhall_init
C3DHALL_RETVAL c3dhall_init(c3dhall_t *ctx, c3dhall_cfg_t *cfg)
Initialization function.
c3dhall_t
Click ctx object definition.
Definition: c3dhall.h:99
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:126
c3dhall_all_data_t
All data structure definition.
Definition: c3dhall.h:133
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:101