angle8 2.0.0.0
angle8.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 ANGLE8_H
29#define ANGLE8_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 ANGLE8_REG_ZERO_SETTING_LSB 0x00
75#define ANGLE8_REG_ZERO_SETTING_MSB 0x01
76#define ANGLE8_REG_BIAS_CURRENT_TIMING 0x02
77#define ANGLE8_REG_ENABLE_TRIMMING 0x03
78#define ANGLE8_REG_CYCLE_TIME_LSB 0x04
79#define ANGLE8_REG_CYCLE_TIME_MSB 0x05
80#define ANGLE8_REG_MAGNETIC_FIELD_CONFIG 0x06
81#define ANGLE8_REG_ND_CONFIG 0x07
82#define ANGLE8_REG_ASC_MODE_THRESHOLD 0x08
83#define ANGLE8_REG_ROTATION_DIRECTION 0x09
84#define ANGLE8_REG_ASC_MODE_REFERENCE 0x0A
85#define ANGLE8_REG_ASC_MODE_CONFIG 0x0B
86#define ANGLE8_REG_FILTER_WINDOW 0x0E
87#define ANGLE8_REG_ERROR_FLAGS 0x1A
88#define ANGLE8_REG_ALARM_FLAGS 0x1B
89
94#define ANGLE8_CMD_READ_ANGLE 0x00
95#define ANGLE8_CMD_READ_REGISTER 0x40
96#define ANGLE8_CMD_WRITE_REGISTER 0x80
97#define ANGLE8_CMD_STORE_SINGLE_REGISTER 0xE0
98#define ANGLE8_CMD_STORE_ALL_REGISTERS 0xC0
99#define ANGLE8_CMD_RESTORE_ALL_REGISTERS 0xA0
100#define ANGLE8_CMD_CLEAR_ERROR_FLAGS 0x20
101
102 // angle8_reg
103
118#define ANGLE8_ROTATION_DIRECTION_CW 0x00
119#define ANGLE8_ROTATION_DIRECTION_CCW 0x80
120
125#define ANGLE8_RESOLUTION 0xFFFF
126#define ANGLE8_FULL_CIRCLE 360.0
127
132#define ANGLE8_CYCLE_TIME_MAX 6553.5
133#define ANGLE8_CYCLE_TIME_100MS 100.0
134#define ANGLE8_CYCLE_TIME_MIN 0.2
135
149#define ANGLE8_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
150#define ANGLE8_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
151
152 // angle8_set
153
168#define ANGLE8_MAP_MIKROBUS( cfg, mikrobus ) \
169 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
170 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
171 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
172 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
173 cfg.nd = MIKROBUS( mikrobus, MIKROBUS_AN ); \
174 cfg.dv = MIKROBUS( mikrobus, MIKROBUS_RST ); \
175 cfg.en = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
176 cfg.mgl = MIKROBUS( mikrobus, MIKROBUS_INT )
177
178 // angle8_map
179 // angle8
180
185typedef struct
186{
187 // Output pins
188 digital_out_t en;
190 // Input pins
191 digital_in_t nd;
192 digital_in_t dv;
193 digital_in_t mgl;
195 // Modules
196 spi_master_t spi;
198 pin_name_t chip_select;
200} angle8_t;
201
206typedef struct
207{
208 // Communication gpio pins
209 pin_name_t miso;
210 pin_name_t mosi;
211 pin_name_t sck;
212 pin_name_t cs;
214 // Additional gpio pins
215 pin_name_t nd;
216 pin_name_t dv;
217 pin_name_t en;
218 pin_name_t mgl;
220 // static variable
221 uint32_t spi_speed;
222 spi_master_mode_t spi_mode;
223 spi_master_chip_select_polarity_t cs_polarity;
226
231typedef enum
232{
234 ANGLE8_ERROR = -1
235
237
254
268err_t angle8_init ( angle8_t *ctx, angle8_cfg_t *cfg );
269
283
296err_t angle8_write_register ( angle8_t *ctx, uint8_t reg, uint8_t data_in );
297
310err_t angle8_read_register ( angle8_t *ctx, uint8_t reg, uint8_t *data_out );
311
323err_t angle8_read_angle ( angle8_t *ctx, float *angle );
324
336
348err_t angle8_store_single_register ( angle8_t *ctx, uint8_t reg );
349
361
371
381
391
401
411
423err_t angle8_set_cycle_time ( angle8_t *ctx, float time_ms );
424
425#ifdef __cplusplus
426}
427#endif
428#endif // ANGLE8_H
429
430 // angle8
431
432// ------------------------------------------------------------------------ END
angle8_return_value_t
Angle 8 Click return value data.
Definition angle8.h:232
@ ANGLE8_OK
Definition angle8.h:233
@ ANGLE8_ERROR
Definition angle8.h:234
err_t angle8_read_register(angle8_t *ctx, uint8_t reg, uint8_t *data_out)
Angle 8 read register function.
err_t angle8_read_angle(angle8_t *ctx, float *angle)
Angle 8 read angle function.
uint8_t angle8_get_dv_pin(angle8_t *ctx)
Angle 8 get dv pin function.
void angle8_disable_device(angle8_t *ctx)
Angle 8 disable device function.
err_t angle8_store_single_register(angle8_t *ctx, uint8_t reg)
Angle 8 store single register function.
uint8_t angle8_get_nd_pin(angle8_t *ctx)
Angle 8 get nd pin function.
err_t angle8_init(angle8_t *ctx, angle8_cfg_t *cfg)
Angle 8 initialization function.
err_t angle8_default_cfg(angle8_t *ctx)
Angle 8 default configuration function.
uint8_t angle8_get_mgl_pin(angle8_t *ctx)
Angle 8 get mgl pin function.
void angle8_cfg_setup(angle8_cfg_t *cfg)
Angle 8 configuration object setup function.
err_t angle8_store_all_registers(angle8_t *ctx)
Angle 8 store all registers function.
void angle8_enable_device(angle8_t *ctx)
Angle 8 enable device function.
err_t angle8_clear_error_flags(angle8_t *ctx)
Angle 8 clear error flags function.
err_t angle8_write_register(angle8_t *ctx, uint8_t reg, uint8_t data_in)
Angle 8 write register function.
err_t angle8_set_cycle_time(angle8_t *ctx, float time_ms)
Angle 8 set cycle time function.
This file contains SPI specific macros, functions, etc.
Angle 8 Click configuration object.
Definition angle8.h:207
pin_name_t nd
Definition angle8.h:215
spi_master_chip_select_polarity_t cs_polarity
Definition angle8.h:223
pin_name_t sck
Definition angle8.h:211
spi_master_mode_t spi_mode
Definition angle8.h:222
pin_name_t mgl
Definition angle8.h:218
pin_name_t dv
Definition angle8.h:216
pin_name_t mosi
Definition angle8.h:210
uint32_t spi_speed
Definition angle8.h:221
pin_name_t en
Definition angle8.h:217
pin_name_t miso
Definition angle8.h:209
pin_name_t cs
Definition angle8.h:212
Angle 8 Click context object.
Definition angle8.h:186
digital_in_t dv
Definition angle8.h:192
spi_master_t spi
Definition angle8.h:196
digital_out_t en
Definition angle8.h:188
digital_in_t nd
Definition angle8.h:191
digital_in_t mgl
Definition angle8.h:193
pin_name_t chip_select
Definition angle8.h:198