magneto4 2.0.0.0
magneto4.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 MAGNETO4_H
36#define MAGNETO4_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
57// -------------------------------------------------------------- PUBLIC MACROS
68#define MAGNETO4_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.a = MIKROBUS( mikrobus, MIKROBUS_AN ); \
74 cfg.b = MIKROBUS( mikrobus, MIKROBUS_RST ); \
75 cfg.ind = MIKROBUS( mikrobus, MIKROBUS_INT )
82#define MAGNETO4_RETVAL uint8_t
83
84#define MAGNETO4_OK 0x00
85#define MAGNETO4_INIT_ERROR 0xFF
92#define MAGNETO4_ENCODER_TO_ZERO_POSITION 0
99#define MAGNETO4_MAX_MAGNETIC_FIELD_VALUE 3000
102 // End group macro
103// --------------------------------------------------------------- PUBLIC TYPES
112typedef struct
113{
114 digital_out_t cs;
115
116 // Input pins
117
118 digital_in_t a;
119 digital_in_t b;
120 digital_in_t pwm;
121 digital_in_t ind;
122
123 // Modules
124
125 spi_master_t spi;
126 pin_name_t chip_select;
127
128 // ctx variable
129
131 uint8_t a_edge;
132 uint8_t b_edge;
133 uint8_t state_a;
134 uint8_t state_b;
135
136} magneto4_t;
137
141typedef struct
142{
143 // Communication gpio pins
144
145 pin_name_t miso;
146 pin_name_t mosi;
147 pin_name_t sck;
148 pin_name_t cs;
149
150 // Additional gpio pins
151
152 pin_name_t a;
153 pin_name_t b;
154 pin_name_t pwm;
155 pin_name_t ind;
156
157 // static variable
158
159 uint32_t spi_speed;
160 uint8_t spi_mode;
161 spi_master_chip_select_polarity_t cs_polarity;
162
164
168typedef struct
169{
170 uint8_t dec_val;
171 uint8_t inc_val;
172 uint8_t lin_val;
173 uint8_t cof_val;
174 uint8_t ocf_val;
175
177
178 // End types group
179
180// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
181
186#ifdef __cplusplus
187extern "C"{
188#endif
189
199
208
219
232(
233 magneto4_t *ctx,
234 uint8_t *rd_buf,
235 uint16_t rd_len
236);
237
252
267
282
293
305
317
333
344
354void magneto4_set_start_position ( magneto4_t *ctx, int32_t encoder_pos );
355
356#ifdef __cplusplus
357}
358#endif
359#endif // _MAGNETO4_H_
360
361 // End public_function group
363
364// ------------------------------------------------------------------------- END
#define MAGNETO4_RETVAL
Definition magneto4.h:82
void magneto4_cfg_setup(magneto4_cfg_t *cfg)
Config Object Initialization function.
uint8_t magneto4_get_out_b(magneto4_t *ctx)
Get B ( RST ) pin status.
uint8_t magneto4_get_out_a(magneto4_t *ctx)
Get A ( AN ) pin status.
uint8_t magneto4_get_index(magneto4_t *ctx)
Get IND ( interrupt ) pin status.
void magneto4_get_encoder_position(magneto4_t *ctx)
Encoder position.
void magneto4_set_start_position(magneto4_t *ctx, int32_t encoder_pos)
Set start encoder position.
MAGNETO4_RETVAL magneto4_init(magneto4_t *ctx, magneto4_cfg_t *cfg)
Initialization function.
void magneto4_generic_transfer(magneto4_t *ctx, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
void magneto4_default_cfg(magneto4_t *ctx)
Click Default Configuration function.
uint32_t magneto4_start_measurement(magneto4_t *ctx)
Measurement function.
uint16_t magneto4_get_magnetic_field(magneto4_t *ctx)
Measurement Field.
uint8_t magneto4_get_magnetic_status(magneto4_t *ctx, mag_status_t *mag_status)
Get Magnetic measurement status.
uint8_t magneto4_get_encoder_direction(magneto4_t *ctx)
Encoder direction.
Click magnetic status structure definition.
Definition magneto4.h:169
uint8_t ocf_val
Definition magneto4.h:174
uint8_t inc_val
Definition magneto4.h:171
uint8_t cof_val
Definition magneto4.h:173
uint8_t dec_val
Definition magneto4.h:170
uint8_t lin_val
Definition magneto4.h:172
Click configuration structure definition.
Definition magneto4.h:142
uint8_t spi_mode
Definition magneto4.h:160
spi_master_chip_select_polarity_t cs_polarity
Definition magneto4.h:161
pin_name_t sck
Definition magneto4.h:147
pin_name_t b
Definition magneto4.h:153
pin_name_t a
Definition magneto4.h:152
pin_name_t mosi
Definition magneto4.h:146
uint32_t spi_speed
Definition magneto4.h:159
pin_name_t pwm
Definition magneto4.h:154
pin_name_t miso
Definition magneto4.h:145
pin_name_t ind
Definition magneto4.h:155
pin_name_t cs
Definition magneto4.h:148
Click ctx object definition.
Definition magneto4.h:113
digital_out_t cs
Definition magneto4.h:114
spi_master_t spi
Definition magneto4.h:125
digital_in_t b
Definition magneto4.h:119
uint8_t state_b
Definition magneto4.h:134
int32_t encoder_position
Definition magneto4.h:130
uint8_t state_a
Definition magneto4.h:133
digital_in_t pwm
Definition magneto4.h:120
uint8_t a_edge
Definition magneto4.h:131
digital_in_t ind
Definition magneto4.h:121
uint8_t b_edge
Definition magneto4.h:132
pin_name_t chip_select
Definition magneto4.h:126
digital_in_t a
Definition magneto4.h:118