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 TMRANGLE_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 )
79#define TMRANGLE_RETVAL uint8_t
81#define TMRANGLE_OK 0x00
82#define TMRANGLE_INIT_ERROR 0xFF
89#define TMRANGLE_COS_N 0x00
90#define TMRANGLE_COS_P 0x01
91#define TMRANGLE_SIN_P 0x02
92#define TMRANGLE_SIN_N 0x03
99#define TMRANGLE_RAD2DEGFACTOR 57.3248
100#define TMRANGLE_ROTATION_VALID 1
101#define TMRANGLE_ANGLE45_H 0.7894
102#define TMRANGLE_ANGLE45_L 0.7806
103#define TMRANGLE_ANGLE135_H 2.3594
104#define TMRANGLE_ANGLE135_L 2.3506
111#define TMRANGLE_MAX_DIFF_SIN 1251
112#define TMRANGLE_MAX_DIFF_COS 1217
113#define TMRANGLE_MIN_DIFF_SIN -1200
114#define TMRANGLE_MIN_DIFF_COS -1206
115#define TMRANGLE_SIN_45 854.0
116#define TMRANGLE_COS_45 864.0
117#define TMRANGLE_SIN_135 873.0
118#define TMRANGLE_COS_135 -865.0
#define TMRANGLE_RETVAL
Definition tmrangle.h:79
void tmrangle_calculate_diff(tmrangle_t *ctx)
Calculate the differential values of sin,cos signal and angle function.
void tmrangle_calibration_find_param(tmrangle_t *ctx, tmrangle_calib_data_t *calib_param)
Get new calibration rotation parameters function.
float tmrangle_get_calib_deff_angle(tmrangle_t *ctx, tmrangle_calib_data_t *calib_param)
Calculate the calibrated angle ( radians ) function.
void tmrangle_cfg_setup(tmrangle_cfg_t *cfg)
Config Object Initialization function.
void tmrangle_init_sensor_data(tmrangle_t *ctx)
Read and stores parameters data function.
void tmrangle_init_calib_data(tmrangle_t *ctx, tmrangle_calib_data_t *calib_param, trigonometry_t *dev)
Initialization and stores calibration parameters function.
float tmrangle_get_calib_angle(tmrangle_t *ctx, tmrangle_calib_data_t *calib_param)
Calculate the calibrated angle ( degree ) function.
void tmrangle_calib_calculate_one_direction(tmrangle_t *ctx, tmrangle_rotation_data_store_t *rotation_data_store)
Calculates and stores parameters, based on found parameters function.
uint16_t tmrangle_read_channel_adc(tmrangle_t *ctx, uint8_t channel)
Read the ADC value of the selected channel function.
TMRANGLE_RETVAL tmrangle_init(tmrangle_t *ctx, tmrangle_cfg_t *cfg)
Initialization function.
void tmrangle_calib_one_direction_min_max(tmrangle_t *ctx, tmrangle_rotation_data_store_t *rotation_data_store)
Find and stores rotation parameters ( min, max ) function.
void tmrangle_calib_calculate_ortho(tmrangle_calib_data_t *calib_param)
Calculates and stores parameters, based on found parameters from both CW and CCW function.
void tmrangle_calib_find_min_max(tmrangle_t *ctx, tmrangle_rotation_data_store_t *rotation_data_store)
Compare and stores rotation parameters function.
Click ctx object definition.
Definition tmrangle.h:132
int16_t diff_x
Definition tmrangle.h:141
uint16_t cos_p
Definition tmrangle.h:135
float uncalibrated_angle
Definition tmrangle.h:145
int16_t diff_y
Definition tmrangle.h:143
uint16_t sin_n
Definition tmrangle.h:137
uint16_t cos_n
Definition tmrangle.h:139
uint16_t sin_p
Definition tmrangle.h:133
Definition tmrangle.h:230
float cos_ortho
Definition tmrangle.h:235
tmrangle_rotation_data_store_t rotation_data
Definition tmrangle.h:231
float sin_ortho
Definition tmrangle.h:233
Click configuration structure definition.
Definition tmrangle.h:165
uint8_t spi_mode
Definition tmrangle.h:177
spi_master_chip_select_polarity_t cs_polarity
Definition tmrangle.h:178
pin_name_t sck
Definition tmrangle.h:170
pin_name_t mosi
Definition tmrangle.h:169
uint32_t spi_speed
Definition tmrangle.h:176
pin_name_t miso
Definition tmrangle.h:168
pin_name_t cs
Definition tmrangle.h:171
Definition tmrangle.h:184
int32_t max_cos
Definition tmrangle.h:189
float magnitude_135
Definition tmrangle.h:223
float amplitude_y
Definition tmrangle.h:215
float y_135
Definition tmrangle.h:203
float x_135_corr
Definition tmrangle.h:207
int32_t min_cos
Definition tmrangle.h:191
float amplitude_x
Definition tmrangle.h:213
uint8_t angle_45_found
Definition tmrangle.h:185
float offset_x
Definition tmrangle.h:217
float ortho_one_dir
Definition tmrangle.h:225
float x_45
Definition tmrangle.h:197
float y_45_corr
Definition tmrangle.h:209
float y_45
Definition tmrangle.h:201
float magnitude_45
Definition tmrangle.h:221
uint32_t nr_valid_rotations
Definition tmrangle.h:187
float x_45_corr
Definition tmrangle.h:205
uint8_t angle_135_found
Definition tmrangle.h:186
float y_135_corr
Definition tmrangle.h:211
int32_t max_sin
Definition tmrangle.h:193
float x_135
Definition tmrangle.h:199
int32_t min_sin
Definition tmrangle.h:195
float offset_y
Definition tmrangle.h:219
Definition tmrangle.h:149
digital_out_t cs
Definition tmrangle.h:150
spi_master_t spi
Definition tmrangle.h:154
tmrangle_analog_sensor_data_t sensor_data
Definition tmrangle.h:157
pin_name_t chip_select
Definition tmrangle.h:155
Definition tmrangle.h:240
float sin_45
Definition tmrangle.h:245
int32_t max_diff_sin
Definition tmrangle.h:241
int32_t min_diff_cos
Definition tmrangle.h:244
float cos_45
Definition tmrangle.h:246
float sin_135
Definition tmrangle.h:247
int32_t max_diff_cos
Definition tmrangle.h:242
int32_t min_diff_sin
Definition tmrangle.h:243
float cos_135
Definition tmrangle.h:248