magneto13  2.1.0.0
magneto13.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef MAGNETO13_H
29 #define MAGNETO13_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
38 #include "spi_specifics.h"
39 
60 #define MAGNETO13_REG_ZERO_0 0x00
61 #define MAGNETO13_REG_ZERO_1 0x01
62 #define MAGNETO13_REG_BCT 0x02
63 #define MAGNETO13_REG_ET_YX 0x03
64 #define MAGNETO13_REG_MG_LT_HT_MG 0x06
65 #define MAGNETO13_REG_IRQM_RAR_HYST 0x07
66 #define MAGNETO13_REG_THR 0x08
67 #define MAGNETO13_REG_RD 0x09
68 #define MAGNETO13_REG_REF 0x0A
69 #define MAGNETO13_REG_TRISTATE_SPI_PULL 0x0D
70 #define MAGNETO13_REG_FW 0x0E
71 #define MAGNETO13_REG_ERR_PAR_MEM_NVM 0x1A
72 #define MAGNETO13_REG_M_GH_GL 0x1B
73  // magneto13_reg
75 
85 #define MAGNETO13_CMD_READ_ANGLE 0x00
86 #define MAGNETO13_CMD_CLEAR_ERR_FLAGS 0x01
87 #define MAGNETO13_CMD_READ_REGISTER 0x02
88 #define MAGNETO13_CMD_WRITE_REGISTER 0x04
89 #define MAGNETO13_CMD_RESTORE_ALL_NVM 0x05
90 #define MAGNETO13_CMD_STORE_ALL_NVM 0x06
91 #define MAGNETO13_CMD_STORE_SINGLE_NVM 0x07
92  // magneto13_cmd
94 
109 #define MAGNETO13_CMD_BIT_MASK 0x07
110 #define MAGNETO13_REG_BIT_MASK 0x1F
111 
116 #define MAGNETO13_TRIMMING_X_DIS 0x00
117 #define MAGNETO13_TRIMMING_X_EN 0x01
118 #define MAGNETO13_TRIMMING_Y_DIS 0x00
119 #define MAGNETO13_TRIMMING_Y_EN 0x02
120 
125 #define MAGNETO13_MG_LT_LVL_0 0x00
126 #define MAGNETO13_MG_LT_LVL_1 0x40
127 #define MAGNETO13_MG_LT_LVL_2 0x80
128 #define MAGNETO13_MG_LT_LVL_3 0xC0
129 #define MAGNETO13_MG_HT_LVL_0 0x00
130 #define MAGNETO13_MG_HT_LVL_1 0x10
131 #define MAGNETO13_MG_HT_LVL_2 0x20
132 #define MAGNETO13_MG_HT_LVL_3 0x30
133 #define MAGNETO13_MG_BIT_MASK 0xF0
134 #define MAGNETO13_MG_FLD_THD_DIS 0x00
135 #define MAGNETO13_MG_FLD_THD_EN 0x01
136 
141 #define MAGNETO13_FLD_ST_OK 0x00
142 #define MAGNETO13_FLD_ST_MGL 0x01
143 #define MAGNETO13_FLD_ST_MGH 0x02
144 #define MAGNETO13_FLD_ST_BIT_MASK 0x03
145 
154 #define MAGNETO13_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
155 #define MAGNETO13_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
156  // magneto13_set
158 
173 #define MAGNETO13_MAP_MIKROBUS( cfg, mikrobus ) \
174  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
175  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
176  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
177  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
178  cfg.err = MIKROBUS( mikrobus, MIKROBUS_AN ); \
179  cfg.nvm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
180  cfg.irq = MIKROBUS( mikrobus, MIKROBUS_INT )
181  // magneto13_map // magneto13
184 
189 typedef struct
190 {
191  // Input pins
192  digital_in_t err;
193  digital_in_t nvm;
194  digital_in_t irq;
196  // Modules
197  spi_master_t spi;
199  pin_name_t chip_select;
201 } magneto13_t;
202 
207 typedef struct
208 {
209  // Communication gpio pins
210  pin_name_t miso;
211  pin_name_t mosi;
212  pin_name_t sck;
213  pin_name_t cs;
215  // Additional gpio pins
216  pin_name_t err;
217  pin_name_t nvm;
218  pin_name_t irq;
220  // static variable
221  uint32_t spi_speed;
222  spi_master_mode_t spi_mode;
223  spi_master_chip_select_polarity_t cs_polarity;
226 
231 typedef enum
232 {
234  MAGNETO13_ERROR = -1
235 
237 
254 
269 
283 
298 err_t magneto13_write_reg ( magneto13_t *ctx, uint8_t cmd, uint8_t reg, uint8_t data_in );
299 
314 err_t magneto13_read_reg ( magneto13_t *ctx, uint8_t cmd, uint8_t reg, uint8_t *data_out );
315 
329 err_t magneto13_get_angle_raw_data ( magneto13_t *ctx, uint16_t *raw_data );
330 
344 err_t magneto13_get_angle ( magneto13_t *ctx, float *angle );
345 
360 err_t magneto13_set_mag_field_thd ( magneto13_t *ctx, uint8_t mglt, uint8_t mght );
361 
375 
392 err_t magneto13_get_field_strength ( magneto13_t *ctx, uint8_t *field_strength );
393 
406 
419 
433 
434 
435 
436 #ifdef __cplusplus
437 }
438 #endif
439 #endif // MAGNETO13_H
440  // magneto13
442 
443 // ------------------------------------------------------------------------ END
magneto13_cfg_t::sck
pin_name_t sck
Definition: magneto13.h:212
magneto13_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: magneto13.h:223
magneto13_t
Magneto 13 Click context object.
Definition: magneto13.h:190
magneto13_cfg_t::spi_speed
uint32_t spi_speed
Definition: magneto13.h:221
spi_specifics.h
This file contains SPI specific macros, functions, etc.
magneto13_write_reg
err_t magneto13_write_reg(magneto13_t *ctx, uint8_t cmd, uint8_t reg, uint8_t data_in)
Magneto 13 data writing function.
magneto13_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: magneto13.h:222
magneto13_get_interrupt
uint8_t magneto13_get_interrupt(magneto13_t *ctx)
Magneto 13 gets the interrupt on the angle change state function.
magneto13_t::chip_select
pin_name_t chip_select
Definition: magneto13.h:199
magneto13_enable_fld_thd_det
err_t magneto13_enable_fld_thd_det(magneto13_t *ctx)
Magneto 13 enables the magnetic field threshold detection function.
magneto13_t::irq
digital_in_t irq
Definition: magneto13.h:194
magneto13_init
err_t magneto13_init(magneto13_t *ctx, magneto13_cfg_t *cfg)
Magneto 13 initialization function.
magneto13_cfg_t::nvm
pin_name_t nvm
Definition: magneto13.h:217
magneto13_cfg_t::irq
pin_name_t irq
Definition: magneto13.h:218
MAGNETO13_ERROR
@ MAGNETO13_ERROR
Definition: magneto13.h:234
magneto13_set_mag_field_thd
err_t magneto13_set_mag_field_thd(magneto13_t *ctx, uint8_t mglt, uint8_t mght)
Magneto 13 sets the magnetic field threshold function.
magneto13_cfg_t::cs
pin_name_t cs
Definition: magneto13.h:213
magneto13_cfg_t::miso
pin_name_t miso
Definition: magneto13.h:210
magneto13_get_field_strength
err_t magneto13_get_field_strength(magneto13_t *ctx, uint8_t *field_strength)
Magneto 13 gets the magnetic field strength function.
MAGNETO13_OK
@ MAGNETO13_OK
Definition: magneto13.h:233
magneto13_read_reg
err_t magneto13_read_reg(magneto13_t *ctx, uint8_t cmd, uint8_t reg, uint8_t *data_out)
Magneto 13 data reading function.
magneto13_get_nvm_access_state
uint8_t magneto13_get_nvm_access_state(magneto13_t *ctx)
Magneto 13 checks the access to the NVM function.
magneto13_get_angle
err_t magneto13_get_angle(magneto13_t *ctx, float *angle)
Magneto 13 gets the angular position function.
magneto13_cfg_t::mosi
pin_name_t mosi
Definition: magneto13.h:211
magneto13_cfg_setup
void magneto13_cfg_setup(magneto13_cfg_t *cfg)
Magneto 13 configuration object setup function.
magneto13_return_value_t
magneto13_return_value_t
Magneto 13 Click return value data.
Definition: magneto13.h:232
magneto13_cfg_t
Magneto 13 Click configuration object.
Definition: magneto13.h:208
magneto13_t::spi
spi_master_t spi
Definition: magneto13.h:197
magneto13_default_cfg
err_t magneto13_default_cfg(magneto13_t *ctx)
Magneto 13 default configuration function.
magneto13_t::err
digital_in_t err
Definition: magneto13.h:192
magneto13_get_error_flag
uint8_t magneto13_get_error_flag(magneto13_t *ctx)
Magneto 13 gets the error flag function.
magneto13_cfg_t::err
pin_name_t err
Definition: magneto13.h:216
magneto13_t::nvm
digital_in_t nvm
Definition: magneto13.h:193
magneto13_get_angle_raw_data
err_t magneto13_get_angle_raw_data(magneto13_t *ctx, uint16_t *raw_data)
Magneto 13 gets the angle raw data function.