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
38#include "drv_digital_out.h"
39#include "drv_digital_in.h"
40#include "drv_spi_master.h"
41
42
43// -------------------------------------------------------------- PUBLIC MACROS
54#define MAGNETO4_MAP_MIKROBUS( cfg, mikrobus ) \
55 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
56 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
57 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
58 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
59 cfg.a = MIKROBUS( mikrobus, MIKROBUS_AN ); \
60 cfg.b = MIKROBUS( mikrobus, MIKROBUS_RST ); \
61 cfg.ind = MIKROBUS( mikrobus, MIKROBUS_INT )
68#define MAGNETO4_RETVAL uint8_t
69
70#define MAGNETO4_OK 0x00
71#define MAGNETO4_INIT_ERROR 0xFF
78#define MAGNETO4_ENCODER_TO_ZERO_POSITION 0
85#define MAGNETO4_MAX_MAGNETIC_FIELD_VALUE 3000 // End group macro
89// --------------------------------------------------------------- PUBLIC TYPES
98typedef struct
99{
100 digital_out_t cs;
101
102 // Input pins
103
104 digital_in_t a;
105 digital_in_t b;
106 digital_in_t pwm;
107 digital_in_t ind;
108
109 // Modules
110
111 spi_master_t spi;
112 pin_name_t chip_select;
113
114 // ctx variable
115
117 uint8_t a_edge;
118 uint8_t b_edge;
119 uint8_t state_a;
120 uint8_t state_b;
121
122} magneto4_t;
123
127typedef struct
128{
129 // Communication gpio pins
130
131 pin_name_t miso;
132 pin_name_t mosi;
133 pin_name_t sck;
134 pin_name_t cs;
135
136 // Additional gpio pins
137
138 pin_name_t a;
139 pin_name_t b;
140 pin_name_t pwm;
141 pin_name_t ind;
142
143 // static variable
144
145 uint32_t spi_speed;
146 uint8_t spi_mode;
147 spi_master_chip_select_polarity_t cs_polarity;
148
150
154typedef struct
155{
156 uint8_t dec_val;
157 uint8_t inc_val;
158 uint8_t lin_val;
159 uint8_t cof_val;
160 uint8_t ocf_val;
161
163 // End types group
165
166// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
167
172#ifdef __cplusplus
173extern "C"{
174#endif
175
185
194
205
218(
219 magneto4_t *ctx,
220 uint8_t *rd_buf,
221 uint16_t rd_len
222);
223
238
253
268
279
291
303
319
330
340void magneto4_set_start_position ( magneto4_t *ctx, int32_t encoder_pos );
341
342#ifdef __cplusplus
343}
344#endif
345#endif // _MAGNETO4_H_
346 // End public_function group
349
350// ------------------------------------------------------------------------- END
#define MAGNETO4_RETVAL
Definition: magneto4.h:68
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.
uint8_t magneto4_get_encoder_direction(magneto4_t *ctx, mag_status_t *mag_status)
Encoder direction.
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.
Click magnetic status structure definition.
Definition: magneto4.h:155
uint8_t ocf_val
Definition: magneto4.h:160
uint8_t inc_val
Definition: magneto4.h:157
uint8_t cof_val
Definition: magneto4.h:159
uint8_t dec_val
Definition: magneto4.h:156
uint8_t lin_val
Definition: magneto4.h:158
Click configuration structure definition.
Definition: magneto4.h:128
uint8_t spi_mode
Definition: magneto4.h:146
spi_master_chip_select_polarity_t cs_polarity
Definition: magneto4.h:147
pin_name_t sck
Definition: magneto4.h:133
pin_name_t b
Definition: magneto4.h:139
pin_name_t a
Definition: magneto4.h:138
pin_name_t mosi
Definition: magneto4.h:132
uint32_t spi_speed
Definition: magneto4.h:145
pin_name_t pwm
Definition: magneto4.h:140
pin_name_t miso
Definition: magneto4.h:131
pin_name_t ind
Definition: magneto4.h:141
pin_name_t cs
Definition: magneto4.h:134
Click ctx object definition.
Definition: magneto4.h:99
digital_out_t cs
Definition: magneto4.h:100
spi_master_t spi
Definition: magneto4.h:111
digital_in_t b
Definition: magneto4.h:105
uint8_t state_b
Definition: magneto4.h:120
int32_t encoder_position
Definition: magneto4.h:116
uint8_t state_a
Definition: magneto4.h:119
digital_in_t pwm
Definition: magneto4.h:106
uint8_t a_edge
Definition: magneto4.h:117
digital_in_t ind
Definition: magneto4.h:107
uint8_t b_edge
Definition: magneto4.h:118
pin_name_t chip_select
Definition: magneto4.h:112
digital_in_t a
Definition: magneto4.h:104