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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define ANGLE_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
56 
63 #define ANGLE_RETVAL uint8_t
64 
65 #define ANGLE_OK 0x00
66 #define ANGLE_INIT_ERROR 0xFF
67 
73 #define ANGLE_ERROR_REG_MASK 0x34
74 #define ANGLE_EXTENDED_ERROR_REG_MASK 0x36
75 #define ANGLE_EXTENDED_ERROR_REG 0x26
76 #define ANGLE_ERROR_REG 0x24
77 #define ANGLE_STATUS_REG 0x22
78 #define ANGLE_SETTINGS_REG 0x1E
79 
85 #define ANGLE_CDS_NO_CHANGLE 0x0000 << 13
86 #define ANGLE_CDS_IDLE_MODE 0x0002 << 13
87 #define ANGLE_CDS_RUN_MODE 0x0003 << 13
88 
94 #define ANGLE_HDR_RESET_0 0x0000 << 12
95 #define ANGLE_HDR_RESET_1 0x0001 << 12
96 
102 #define ANGLE_SFR_RESET_0 0x0000 << 11
103 #define ANGLE_SFR_RESET_1 0x0001 << 11
104 
110 #define ANGLE_CSR_STA_0 0x0000 << 9
111 #define ANGLE_CSR_STA_1 0x0001 << 9
112 
118 #define ANGLE_CXE_0 0x0000 << 8
119 #define ANGLE_CXE_1 0x0001 << 8
120 
126  #define ANGLE_CER_0 0x0000 << 7
127  #define ANGLE_CER_1 0x0001 << 7
128  // End group macro
131 // --------------------------------------------------------------- PUBLIC TYPES
140 typedef struct
141 {
142 
143  // Modules
144 
145  i2c_master_t i2c;
146 
147  // ctx variable
148 
149  uint8_t slave_address;
150 
151 } angle_t;
152 
156 typedef struct
157 {
158  // Communication gpio pins
159 
160  pin_name_t scl;
161  pin_name_t sda;
162 
163  // static variable
164 
165  uint32_t i2c_speed;
166  uint8_t i2c_address;
167 
168 } angle_cfg_t;
169  // End types group
171 
172 #ifdef __cplusplus
173 extern "C"{
174 #endif
175 
184 void angle_cfg_setup ( angle_cfg_t *cfg );
185 
195 
203 void angle_default_cfg ( angle_t *ctx );
204 
215 void angle_generic_write ( angle_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
216 
227 void angle_generic_read ( angle_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
228 
237 uint16_t angle_get_angle ( angle_t *ctx );
238 
246 uint16_t angle_get_temperature ( angle_t *ctx );
247 
256 uint16_t angle_get_magnetics ( angle_t *ctx );
257 
266 uint16_t angle_get_status( angle_t *ctx, uint8_t reg );
267 
276 void angle_set_config ( angle_t *ctx, uint16_t set_value );
277 
278 #ifdef __cplusplus
279 }
280 #endif
281 #endif // _ANGLE_H_
282  // End public_function group
285 
286 // ------------------------------------------------------------------------- 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:161
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:145
angle_cfg_t
Click configuration structure definition.
Definition: angle.h:156
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:149
angle_t
Click ctx object definition.
Definition: angle.h:140
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:63
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:166
angle_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: angle.h:165
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:160