42#ifdef PREINIT_SUPPORTED
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_spi_master.h"
68#define GMRANGLE_MAP_MIKROBUS( cfg, mikrobus ) \
69 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
70 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
71 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
72 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
73 cfg.ifa = MIKROBUS( mikrobus, MIKROBUS_AN ); \
74 cfg.css = MIKROBUS( mikrobus, MIKROBUS_RST ); \
75 cfg.ifc = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
76 cfg.ifb = MIKROBUS( mikrobus, MIKROBUS_INT )
84#define GMRANGLE_ERROR -1
91#define GMRANGLE_REG_STAT 0x00
92#define GMRANGLE_REG_ACSTAT 0x01
93#define GMRANGLE_REG_AVAL 0x02
94#define GMRANGLE_REG_ASPD 0x03
95#define GMRANGLE_REG_AREV 0x04
96#define GMRANGLE_REG_FSYNC 0x05
97#define GMRANGLE_REG_MOD_1 0x06
98#define GMRANGLE_REG_SIL 0x07
99#define GMRANGLE_REG_MOD_2 0x08
100#define GMRANGLE_REG_MOD_3 0x09
101#define GMRANGLE_REG_OFFX 0x0A
102#define GMRANGLE_REG_OFFY 0x0B
103#define GMRANGLE_REG_SYNCH 0x0C
104#define GMRANGLE_REG_IFAB 0x0D
105#define GMRANGLE_REG_MOD_4 0x0E
106#define GMRANGLE_REG_TCO_Y 0x0F
107#define GMRANGLE_REG_ADC_X 0x10
108#define GMRANGLE_REG_ADC_Y 0x11
115#define GMRANGLE_READ_SENSOR 0x80
116#define GMRANGLE_GET_BIT_5_4 0x30
117#define GMRANGLE_GET_BIT_3_0 0x0F
124#define GMRANGLE_SYSTEM_ERROR_MASK 0x4000
125#define GMRANGLE_INTERFACE_ERROR_MASK 0x2000
126#define GMRANGLE_INV_ANGLE_ERROR_MASK 0x1000
127#define GMRANGLE_CRC_POLYNOMIAL 0x1D00
128#define GMRANGLE_CRC_SEED 0xFF00
129#define GMRANGLE_CRC_NUM_REGISTERS 0x0008
130#define GMRANGLE_MAX_REGISTER_MEM 0x0030
131#define GMRANGLE_DELETE_BIT_15 0x7FFF
132#define GMRANGLE_CHANGE_UINT_TO_INT_16 0xFFFF
133#define GMRANGLE_CHANGE_UINT_TO_INT_15 0x8000
134#define GMRANGLE_MAX_BIT_14 0x3FFF
135#define GMRANGLE_CHECK_BIT_14 0x4000
136#define GMRANGLE_GET_BIT_14_4 0x7FF0
137#define GMRANGLE_DELETE_7BITS 0x01FF
138#define GMRANGLE_CHANGE_UNIT_TO_INT_9 0x0200
139#define GMRANGLE_CHECK_BIT_9 0x0100
140#define GMRANGLE_CHECK_BIT_15 0x8000
147#define GMRANGLE_POW_2_15 32768.0f
148#define GMRANGLE_POW_2_7 128.0f
149#define GMRANGLE_ANGLE_360_VAL 360.0f
150#define GMRANGLE_TEMP_OFFSET 152.0f
151#define GMRANGLE_TEMP_DIV 2.776f
152#define GMRANGLE_DATA_RESOLUTION 0x7FFF
163#define GMRANGLE_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
164#define GMRANGLE_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
uint16_t gmrangle_get_angle_value(gmrangle_t *ctx)
Get the angle value function.
uint16_t gmrangle_read_data(gmrangle_t *ctx, uint8_t reg)
Generic read 16-bit data function.
float gmrangle_calculate_angle(gmrangle_t *ctx)
Calculate angle function.
int16_t gmrangle_get_num_revolutions(gmrangle_t *ctx)
Get the number of revolutions function.
err_t gmrangle_init(gmrangle_t *ctx, gmrangle_cfg_t *cfg)
Initialization function.
void gmrangle_set_act_status(gmrangle_t *ctx, uint16_t a_data)
Set activation status register function.
int16_t gmrangle_get_angle_speed_value(gmrangle_t *ctx)
Get the angle speed value function.
void gmrangle_cfg_setup(gmrangle_cfg_t *cfg)
Config Object Initialization function.
uint16_t gmrangle_get_status(gmrangle_t *ctx)
Get the status data function.
void gmrangle_get_angle_speed(gmrangle_t *ctx, float *final_angle_speed, int16_t *angle_speed_val)
Get the angle speed function.
void gmrangle_write_data(gmrangle_t *ctx, uint8_t reg, uint16_t tx_data)
Generic write 16-bit data function.
float gmrangle_get_angle_range(gmrangle_t *ctx)
Get the angle range function.
This file contains SPI specific macros, functions, etc.
Click configuration structure definition.
Definition gmrangle.h:197
pin_name_t ifc
Definition gmrangle.h:207
pin_name_t ifb
Definition gmrangle.h:208
spi_master_chip_select_polarity_t cs_polarity
Definition gmrangle.h:213
pin_name_t sck
Definition gmrangle.h:201
spi_master_mode_t spi_mode
Definition gmrangle.h:212
pin_name_t mosi
Definition gmrangle.h:200
uint32_t spi_speed
Definition gmrangle.h:211
pin_name_t css
Definition gmrangle.h:206
pin_name_t ifa
Definition gmrangle.h:205
pin_name_t miso
Definition gmrangle.h:199
pin_name_t cs
Definition gmrangle.h:202
Click ctx object definition.
Definition gmrangle.h:177
digital_out_t cs
Definition gmrangle.h:179
spi_master_t spi
Definition gmrangle.h:188
digital_in_t ifa
Definition gmrangle.h:183
digital_out_t css
Definition gmrangle.h:180
digital_in_t ifc
Definition gmrangle.h:185
digital_in_t ifb
Definition gmrangle.h:184
pin_name_t chip_select
Definition gmrangle.h:189