angle5 2.0.0.0
angle5.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 ANGLE5_H
36#define ANGLE5_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_spi_master.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
67#define ANGLE5_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
69 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
70 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
71 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
72 cfg.mgh = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
73 cfg.mgl = MIKROBUS( mikrobus, MIKROBUS_INT )
80#define ANGLE5_RETVAL uint8_t
81
82#define ANGLE5_OK 0x00
83#define ANGLE5_INIT_ERROR 0xFF
90#define ANGLE5_REG_ZERO_SETTING_LSB 0x00
91#define ANGLE5_REG_ZERO_SETTING_MSB 0x01
92#define ANGLE5_REG_BIAS_CURRENT_TRIMMING 0x02
93#define ANGLE5_REG_ENABLE_TRIMMING_XY 0x03
94#define ANGLE5_REG_CONFIG_1 0x04
95#define ANGLE5_REG_CONFIG_2 0x05
96#define ANGLE5_REG_MAGNETIC_FIELD_THR 0x06
97#define ANGLE5_REG_NUMBER_OF_POLE_PAIRS 0x07
98#define ANGLE5_REG_ROTATION_DIRECTION 0x09
99#define ANGLE5_REG_MG_H_L 0x1B
106#define ANGLE5_CMD_READ_ANGLE 0x00
107#define ANGLE5_CMD_READ 0x40
108#define ANGLE5_CMD_WRITE 0x80
111 // End group macro
112// --------------------------------------------------------------- PUBLIC TYPES
121typedef struct
122{
123 // Output pins
124
125 digital_out_t cs;
126
127 // Input pins
128
129 digital_in_t mgh;
130 digital_in_t mgl;
131
132 // Modules
133
134 spi_master_t spi;
135 pin_name_t chip_select;
136
137} angle5_t;
138
142typedef struct
143{
144 // Communication gpio pins
145
146 pin_name_t miso;
147 pin_name_t mosi;
148 pin_name_t sck;
149 pin_name_t cs;
150
151 // Additional gpio pins
152
153 pin_name_t mgh;
154 pin_name_t mgl;
155
156 // static variable
157
158 uint32_t spi_speed;
159 spi_master_mode_t spi_mode;
160 spi_master_chip_select_polarity_t cs_polarity;
161
163
164 // End types group
165// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
166
171#ifdef __cplusplus
172extern "C"{
173#endif
174
184
194
203
216(
217 angle5_t *ctx,
218 uint8_t *wr_buf,
219 uint16_t wr_len,
220 uint8_t *rd_buf,
221 uint16_t rd_len
222);
223
234
245
257uint16_t angle5_read_register ( angle5_t *ctx, uint8_t reg_addr, uint8_t *rsp );
258
271uint16_t angle5_write_register ( angle5_t *ctx, uint8_t reg_addr, uint8_t tx_data, uint8_t *status );
272
283float angle5_calc_rpm ( float old_angle, float new_angle );
284
295
306
307#ifdef __cplusplus
308}
309#endif
310#endif // _ANGLE5_H_
311
312 // End public_function group
314
315// ------------------------------------------------------------------------- END
#define ANGLE5_RETVAL
Definition angle5.h:80
void angle5_default_cfg(angle5_t *ctx)
Click Default Configuration function.
uint16_t angle5_read_raw_angle(angle5_t *ctx)
Reads Raw Angle data.
uint16_t angle5_read_register(angle5_t *ctx, uint8_t reg_addr, uint8_t *rsp)
Generic read function.
float angle5_calc_rpm(float old_angle, float new_angle)
Calculating angle data to RPM.
ANGLE5_RETVAL angle5_init(angle5_t *ctx, angle5_cfg_t *cfg)
Initialization function.
uint16_t angle5_write_register(angle5_t *ctx, uint8_t reg_addr, uint8_t tx_data, uint8_t *status)
Generic write function.
uint8_t angle5_get_mgh_pin_state(angle5_t *ctx)
Gets MGH (PWM) pin state.
void angle5_generic_transfer(angle5_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
void angle5_cfg_setup(angle5_cfg_t *cfg)
Config Object Initialization function.
uint8_t angle5_get_mgl_pin_state(angle5_t *ctx)
Gets MGL (INT) pin state.
float angle5_read_angle_deg(angle5_t *ctx)
Reads Angle data in deg.
Click configuration structure definition.
Definition angle5.h:143
spi_master_chip_select_polarity_t cs_polarity
Definition angle5.h:160
pin_name_t sck
Definition angle5.h:148
spi_master_mode_t spi_mode
Definition angle5.h:159
pin_name_t mgl
Definition angle5.h:154
pin_name_t mosi
Definition angle5.h:147
uint32_t spi_speed
Definition angle5.h:158
pin_name_t mgh
Definition angle5.h:153
pin_name_t miso
Definition angle5.h:146
pin_name_t cs
Definition angle5.h:149
Click ctx object definition.
Definition angle5.h:122
digital_out_t cs
Definition angle5.h:125
spi_master_t spi
Definition angle5.h:134
digital_in_t mgh
Definition angle5.h:129
digital_in_t mgl
Definition angle5.h:130
pin_name_t chip_select
Definition angle5.h:135