angle2  2.0.0.0
angle2.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 ANGLE2_H
36 #define ANGLE2_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_spi_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
63 #define ANGLE2_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
65  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
66  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
67  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
68 
74 #define ANGLE2_RETVAL uint8_t
75 
76 #define ANGLE2_OK 0x00
77 #define ANGLE2_INIT_ERROR 0xFF
78 
84 #define ANGLE2_WRITE_CMD 0x20
85 #define ANGLE2_READ_CMD 0x10
86 #define ANGLE2_DUMMY_BYTE 0x00
87 #define ANGLE2_REG_ADDR_MASK 0x0F
88 
89 #define ANGLE2_BIAS_CURR_TRIMM_REG_3 0x03
90 #define ANGLE2_ZERO_POS_MSB_REG_4 0x04
91 #define ANGLE2_AXIS_TRIMM_AND_ZERO_LSB_REG_5 0x05
92 #define ANGLE2_FLASH_N_REG_9 0x09
93 
94 #define ANGLE2_X_AXIS_TRIMM_EN 0x10
95 #define ANGLE2_Y_AXIS_TRIMM_EN 0x20
96 #define ANGLE2_AXIS_TRIMM_DIS 0x00
97 
98 #define ANGLE2_FLASH_REG_3 0x08
99 #define ANGLE2_FLASH_REG_4 0x10
100 #define ANGLE2_FLASH_REG_5 0x20
101 #define ANGLE2_NO_FLASH 0x00
102 
103 #define ANGLE2_DEG_LSB 0.08789
104 #define ANGLE2_MAX_SCALE_359_91_DEG 359.91211
105 #define ANGLE2_MIN_SCALE_0_DEG 0
106  // End group macro
109 // --------------------------------------------------------------- PUBLIC TYPES
118 typedef struct
119 {
120  // Output pins
121 
122  digital_out_t cs;
123 
124  // Modules
125 
126  spi_master_t spi;
127  pin_name_t chip_select;
128 
129 } angle2_t;
130 
134 typedef struct
135 {
136  // Communication gpio pins
137 
138  pin_name_t miso;
139  pin_name_t mosi;
140  pin_name_t sck;
141  pin_name_t cs;
142 
143  // static variable
144 
145  uint32_t spi_speed;
146  spi_master_mode_t spi_mode;
147  spi_master_chip_select_polarity_t cs_polarity;
148 
149 } angle2_cfg_t;
150  // End types group
152 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
153 
158 #ifdef __cplusplus
159 extern "C"{
160 #endif
161 
171 
181 
190 
202 void angle2_generic_transfer ( angle2_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
203 
213 double angle2_write_reg ( angle2_t *ctx, uint8_t addr, uint8_t input );
214 
224 double angle2_read_reg ( angle2_t *ctx, uint8_t addr, uint8_t *output );
225 
233 double angle2_get_angle ( angle2_t *ctx );
234 
242 double angle2_get_angle_with_time_index ( angle2_t *ctx, uint8_t *time_index );
243 
252 void angle2_set_zero_scale ( angle2_t *ctx, double zero_deg );
253 
262 void angle2_enable_trimming ( angle2_t *ctx, uint8_t state );
263 
272 void angle2_flash_reg ( angle2_t *ctx, uint8_t reg_sel );
273 
274 #ifdef __cplusplus
275 }
276 #endif
277 #endif // _ANGLE2_H_
278  // End public_function group
281 
282 // ------------------------------------------------------------------------- END
angle2_cfg_t::sck
pin_name_t sck
Definition: angle2.h:140
angle2_cfg_t::spi_speed
uint32_t spi_speed
Definition: angle2.h:145
angle2_generic_transfer
void angle2_generic_transfer(angle2_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
angle2_write_reg
double angle2_write_reg(angle2_t *ctx, uint8_t addr, uint8_t input)
Register write function.
angle2_cfg_t
Click configuration structure definition.
Definition: angle2.h:135
angle2_cfg_t::miso
pin_name_t miso
Definition: angle2.h:138
angle2_cfg_t::cs
pin_name_t cs
Definition: angle2.h:141
angle2_enable_trimming
void angle2_enable_trimming(angle2_t *ctx, uint8_t state)
Enable trimming function.
angle2_get_angle
double angle2_get_angle(angle2_t *ctx)
Angle read function.
angle2_init
ANGLE2_RETVAL angle2_init(angle2_t *ctx, angle2_cfg_t *cfg)
Initialization function.
angle2_set_zero_scale
void angle2_set_zero_scale(angle2_t *ctx, double zero_deg)
Set zero scale function.
angle2_t::chip_select
pin_name_t chip_select
Definition: angle2.h:127
angle2_flash_reg
void angle2_flash_reg(angle2_t *ctx, uint8_t reg_sel)
Flash register function.
angle2_t
Click ctx object definition.
Definition: angle2.h:119
angle2_t::spi
spi_master_t spi
Definition: angle2.h:126
angle2_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: angle2.h:147
ANGLE2_RETVAL
#define ANGLE2_RETVAL
Definition: angle2.h:74
angle2_cfg_setup
void angle2_cfg_setup(angle2_cfg_t *cfg)
Config Object Initialization function.
angle2_read_reg
double angle2_read_reg(angle2_t *ctx, uint8_t addr, uint8_t *output)
Register read function.
angle2_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: angle2.h:146
angle2_default_cfg
void angle2_default_cfg(angle2_t *ctx)
Click Default Configuration function.
angle2_get_angle_with_time_index
double angle2_get_angle_with_time_index(angle2_t *ctx, uint8_t *time_index)
Angle with time index read function.
angle2_cfg_t::mosi
pin_name_t mosi
Definition: angle2.h:139
angle2_t::cs
digital_out_t cs
Definition: angle2.h:122