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
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_i2c_master.h"
55
56
57// -------------------------------------------------------------- PUBLIC MACROS
67#define ANGLE_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
69 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
70
77#define ANGLE_RETVAL uint8_t
78
79#define ANGLE_OK 0x00
80#define ANGLE_INIT_ERROR 0xFF
87#define ANGLE_ERROR_REG_MASK 0x34
88#define ANGLE_EXTENDED_ERROR_REG_MASK 0x36
89#define ANGLE_EXTENDED_ERROR_REG 0x26
90#define ANGLE_ERROR_REG 0x24
91#define ANGLE_STATUS_REG 0x22
92#define ANGLE_SETTINGS_REG 0x1E
99#define ANGLE_CDS_NO_CHANGLE 0x0000 << 13
100#define ANGLE_CDS_IDLE_MODE 0x0002 << 13
101#define ANGLE_CDS_RUN_MODE 0x0003 << 13
108#define ANGLE_HDR_RESET_0 0x0000 << 12
109#define ANGLE_HDR_RESET_1 0x0001 << 12
116#define ANGLE_SFR_RESET_0 0x0000 << 11
117#define ANGLE_SFR_RESET_1 0x0001 << 11
124#define ANGLE_CSR_STA_0 0x0000 << 9
125#define ANGLE_CSR_STA_1 0x0001 << 9
132#define ANGLE_CXE_0 0x0000 << 8
133#define ANGLE_CXE_1 0x0001 << 8
140 #define ANGLE_CER_0 0x0000 << 7
141 #define ANGLE_CER_1 0x0001 << 7
144 // End group macro
145// --------------------------------------------------------------- PUBLIC TYPES
154typedef struct
155{
156
157 // Modules
158
159 i2c_master_t i2c;
160
161 // ctx variable
162
164
165} angle_t;
166
170typedef struct
171{
172 // Communication gpio pins
173
174 pin_name_t scl;
175 pin_name_t sda;
176
177 // static variable
178
179 uint32_t i2c_speed;
180 uint8_t i2c_address;
181
183
184 // End types group
185
186#ifdef __cplusplus
187extern "C"{
188#endif
189
199
209
218
229void angle_generic_write ( angle_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
230
241void angle_generic_read ( angle_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
242
251uint16_t angle_get_angle ( angle_t *ctx );
252
261
270uint16_t angle_get_magnetics ( angle_t *ctx );
271
280uint16_t angle_get_status( angle_t *ctx, uint8_t reg );
281
290void angle_set_config ( angle_t *ctx, uint16_t set_value );
291
292#ifdef __cplusplus
293}
294#endif
295#endif // _ANGLE_H_
296
297 // End public_function group
299
300// ------------------------------------------------------------------------- END
#define ANGLE_RETVAL
Definition angle.h:77
void angle_set_config(angle_t *ctx, uint16_t set_value)
Setting angle configuration.
uint16_t angle_get_angle(angle_t *ctx)
Read angle.
void angle_generic_write(angle_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
uint16_t angle_get_temperature(angle_t *ctx)
Read temperature.
ANGLE_RETVAL angle_init(angle_t *ctx, angle_cfg_t *cfg)
Initialization function.
void angle_default_cfg(angle_t *ctx)
Click Default Configuration function.
void angle_generic_read(angle_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
uint16_t angle_get_magnetics(angle_t *ctx)
Read magnetics.
uint16_t angle_get_status(angle_t *ctx, uint8_t reg)
Read angle status.
void angle_cfg_setup(angle_cfg_t *cfg)
Config Object Initialization function.
Click configuration structure definition.
Definition angle.h:171
uint32_t i2c_speed
Definition angle.h:179
pin_name_t scl
Definition angle.h:174
pin_name_t sda
Definition angle.h:175
uint8_t i2c_address
Definition angle.h:180
Click ctx object definition.
Definition angle.h:155
i2c_master_t i2c
Definition angle.h:159
uint8_t slave_address
Definition angle.h:163