angle6 2.0.0.0
angle6.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef ANGLE6_H
29#define ANGLE6_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_spi_master.h"
52#include "spi_specifics.h"
53
74#define ANGLE6_REG_ZERO_SETTING_LSB 0x00
75#define ANGLE6_REG_ZERO_SETTING_MSB 0x01
76#define ANGLE6_REG_BIAS_CURRENT_TIMING 0x02
77#define ANGLE6_REG_ENABLE_TRIMMING 0x03
78#define ANGLE6_REG_ABZ_SETTING_LSB 0x04
79#define ANGLE6_REG_ABZ_SETTING_MSB 0x05
80#define ANGLE6_REG_MAGNETIC_FIELD_CONFIG 0x06
81#define ANGLE6_REG_ROTATION_DIRECTION 0x09
82#define ANGLE6_REG_ALARM_FLAGS 0x1B
83
88#define ANGLE6_CMD_READ_ANGLE 0x00
89#define ANGLE6_CMD_READ_REGISTER 0x40
90#define ANGLE6_CMD_WRITE_REGISTER 0x80
91
92 // angle6_reg
93
108#define ANGLE6_ROTATION_DIRECTION_CW 0x00
109#define ANGLE6_ROTATION_DIRECTION_CCW 0x80
110
115#define ANGLE6_RESOLUTION 0xFFFF
116#define ANGLE6_FULL_CIRCLE 360.0
117
126#define ANGLE6_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
127#define ANGLE6_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
128
129 // angle6_set
130
145#define ANGLE6_MAP_MIKROBUS( cfg, mikrobus ) \
146 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
147 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
148 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
149 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
150 cfg.mgh = MIKROBUS( mikrobus, MIKROBUS_RST ); \
151 cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
152 cfg.mgl = MIKROBUS( mikrobus, MIKROBUS_INT )
153
154 // angle6_map
155 // angle6
156
161typedef struct
162{
163 // Input pins
164 digital_in_t mgh;
165 digital_in_t pwm;
166 digital_in_t mgl;
168 // Modules
169 spi_master_t spi;
171 pin_name_t chip_select;
173} angle6_t;
174
179typedef struct
180{
181 // Communication gpio pins
182 pin_name_t miso;
183 pin_name_t mosi;
184 pin_name_t sck;
185 pin_name_t cs;
187 // Additional gpio pins
188 pin_name_t mgh;
189 pin_name_t pwm;
190 pin_name_t mgl;
192 // static variable
193 uint32_t spi_speed;
194 spi_master_mode_t spi_mode;
195 spi_master_chip_select_polarity_t cs_polarity;
198
203typedef enum
204{
206 ANGLE6_ERROR = -1
207
209
226
241err_t angle6_init ( angle6_t *ctx, angle6_cfg_t *cfg );
242
257
270err_t angle6_write_register ( angle6_t *ctx, uint8_t reg, uint8_t data_in );
271
284err_t angle6_read_register ( angle6_t *ctx, uint8_t reg, uint8_t *data_out );
285
297err_t angle6_read_angle ( angle6_t *ctx, float *angle );
298
308
318
328
329#ifdef __cplusplus
330}
331#endif
332#endif // ANGLE6_H
333
334 // angle6
335
336// ------------------------------------------------------------------------ END
angle6_return_value_t
Angle 6 Click return value data.
Definition angle6.h:204
@ ANGLE6_ERROR
Definition angle6.h:206
@ ANGLE6_OK
Definition angle6.h:205
err_t angle6_init(angle6_t *ctx, angle6_cfg_t *cfg)
Angle 6 initialization function.
err_t angle6_default_cfg(angle6_t *ctx)
Angle 6 default configuration function.
err_t angle6_write_register(angle6_t *ctx, uint8_t reg, uint8_t data_in)
Angle 6 write register function.
err_t angle6_read_register(angle6_t *ctx, uint8_t reg, uint8_t *data_out)
Angle 6 read register function.
void angle6_cfg_setup(angle6_cfg_t *cfg)
Angle 6 configuration object setup function.
err_t angle6_read_angle(angle6_t *ctx, float *angle)
Angle 6 read angle function.
uint8_t angle6_get_mgh_pin(angle6_t *ctx)
Angle 6 get mgh pin function.
uint8_t angle6_get_mgl_pin(angle6_t *ctx)
Angle 6 get mgl pin function.
uint8_t angle6_get_pwm_pin(angle6_t *ctx)
Angle 6 get pwm pin function.
This file contains SPI specific macros, functions, etc.
Angle 6 Click configuration object.
Definition angle6.h:180
spi_master_chip_select_polarity_t cs_polarity
Definition angle6.h:195
pin_name_t sck
Definition angle6.h:184
spi_master_mode_t spi_mode
Definition angle6.h:194
pin_name_t mgl
Definition angle6.h:190
pin_name_t mosi
Definition angle6.h:183
uint32_t spi_speed
Definition angle6.h:193
pin_name_t mgh
Definition angle6.h:188
pin_name_t pwm
Definition angle6.h:189
pin_name_t miso
Definition angle6.h:182
pin_name_t cs
Definition angle6.h:185
Angle 6 Click context object.
Definition angle6.h:162
spi_master_t spi
Definition angle6.h:169
digital_in_t pwm
Definition angle6.h:165
digital_in_t mgh
Definition angle6.h:164
digital_in_t mgl
Definition angle6.h:166
pin_name_t chip_select
Definition angle6.h:171