angle  2.0.0.0
angle.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 ANGLE_H
36 #define ANGLE_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_i2c_master.h"
51 
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
63 #define ANGLE_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
65  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
66 
73 #define ANGLE_RETVAL uint8_t
74 
75 #define ANGLE_OK 0x00
76 #define ANGLE_INIT_ERROR 0xFF
77 
83 #define ANGLE_ERROR_REG_MASK 0x34
84 #define ANGLE_EXTENDED_ERROR_REG_MASK 0x36
85 #define ANGLE_EXTENDED_ERROR_REG 0x26
86 #define ANGLE_ERROR_REG 0x24
87 #define ANGLE_STATUS_REG 0x22
88 #define ANGLE_SETTINGS_REG 0x1E
89 
95 #define ANGLE_CDS_NO_CHANGLE 0x0000 << 13
96 #define ANGLE_CDS_IDLE_MODE 0x0002 << 13
97 #define ANGLE_CDS_RUN_MODE 0x0003 << 13
98 
104 #define ANGLE_HDR_RESET_0 0x0000 << 12
105 #define ANGLE_HDR_RESET_1 0x0001 << 12
106 
112 #define ANGLE_SFR_RESET_0 0x0000 << 11
113 #define ANGLE_SFR_RESET_1 0x0001 << 11
114 
120 #define ANGLE_CSR_STA_0 0x0000 << 9
121 #define ANGLE_CSR_STA_1 0x0001 << 9
122 
128 #define ANGLE_CXE_0 0x0000 << 8
129 #define ANGLE_CXE_1 0x0001 << 8
130 
136  #define ANGLE_CER_0 0x0000 << 7
137  #define ANGLE_CER_1 0x0001 << 7
138  // End group macro
141 // --------------------------------------------------------------- PUBLIC TYPES
150 typedef struct
151 {
152 
153  // Modules
154 
155  i2c_master_t i2c;
156 
157  // ctx variable
158 
159  uint8_t slave_address;
160 
161 } angle_t;
162 
166 typedef struct
167 {
168  // Communication gpio pins
169 
170  pin_name_t scl;
171  pin_name_t sda;
172 
173  // static variable
174 
175  uint32_t i2c_speed;
176  uint8_t i2c_address;
177 
178 } angle_cfg_t;
179  // End types group
181 
182 #ifdef __cplusplus
183 extern "C"{
184 #endif
185 
195 
205 
214 
225 void angle_generic_write ( angle_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
226 
237 void angle_generic_read ( angle_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
238 
247 uint16_t angle_get_angle ( angle_t *ctx );
248 
256 uint16_t angle_get_temperature ( angle_t *ctx );
257 
266 uint16_t angle_get_magnetics ( angle_t *ctx );
267 
276 uint16_t angle_get_status( angle_t *ctx, uint8_t reg );
277 
286 void angle_set_config ( angle_t *ctx, uint16_t set_value );
287 
288 #ifdef __cplusplus
289 }
290 #endif
291 #endif // _ANGLE_H_
292  // End public_function group
295 
296 // ------------------------------------------------------------------------- END
angle_get_status
uint16_t angle_get_status(angle_t *ctx, uint8_t reg)
Read angle status.
angle_cfg_t::sda
pin_name_t sda
Definition: angle.h:171
angle_get_angle
uint16_t angle_get_angle(angle_t *ctx)
Read angle.
angle_default_cfg
void angle_default_cfg(angle_t *ctx)
Click Default Configuration function.
angle_t::i2c
i2c_master_t i2c
Definition: angle.h:155
angle_cfg_t
Click configuration structure definition.
Definition: angle.h:167
angle_cfg_setup
void angle_cfg_setup(angle_cfg_t *cfg)
Config Object Initialization function.
angle_get_magnetics
uint16_t angle_get_magnetics(angle_t *ctx)
Read magnetics.
angle_generic_read
void angle_generic_read(angle_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
angle_t::slave_address
uint8_t slave_address
Definition: angle.h:159
angle_t
Click ctx object definition.
Definition: angle.h:151
angle_generic_write
void angle_generic_write(angle_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
ANGLE_RETVAL
#define ANGLE_RETVAL
Definition: angle.h:73
angle_get_temperature
uint16_t angle_get_temperature(angle_t *ctx)
Read temperature.
angle_set_config
void angle_set_config(angle_t *ctx, uint16_t set_value)
Setting angle configuration.
angle_cfg_t::i2c_address
uint8_t i2c_address
Definition: angle.h:176
angle_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: angle.h:175
angle_init
ANGLE_RETVAL angle_init(angle_t *ctx, angle_cfg_t *cfg)
Initialization function.
angle_cfg_t::scl
pin_name_t scl
Definition: angle.h:170