angle3 2.0.0.0
angle3.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 */
32// ----------------------------------------------------------------------------
33
34#ifndef ANGLE3_H
35#define ANGLE3_H
36
41#ifdef PREINIT_SUPPORTED
42#include "preinit.h"
43#endif
44
45#ifdef MikroCCoreVersion
46 #if MikroCCoreVersion >= 1
47 #include "delays.h"
48 #endif
49#endif
50
51#include "drv_digital_out.h"
52#include "drv_digital_in.h"
53#include "drv_spi_master.h"
54#include "spi_specifics.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
66#define ANGLE3_OK 0
67#define ANGLE3_ERROR -1
74#define ANGLE3_REG_ANG 0x00
75#define ANGLE3_REG_MAG 0x01
76#define ANGLE3_REG_CHMD 0x02
77#define ANGLE3_REG_ERRMON 0x03
78#define ANGLE3_REG_ZP 0x06
79#define ANGLE3_REG_RDABZ 0x07
80#define ANGLE3_REG_MLK 0x08
81#define ANGLE3_REG_EBDIS 0x09
82#define ANGLE3_REG_UVW 0x0A
83 // End group register
84
89#define ANGLE3_EEPROM_ID1 0x04
90#define ANGLE3_EEPROM_ID2 0x05
91#define ANGLE3_EEPROM_ZP 0x06
92#define ANGLE3_EEPROM_RDABZ 0x07
93#define ANGLE3_EEPROM_MLK 0x08
94#define ANGLE3_EEPROM_EBDIS 0x09
95#define ANGLE3_EEPROM_UVW 0x0A
96 // End group EEPROM_locations
97
102#define ANGLE3_OPCODE_LOCK_EEPROM 0x00
103#define ANGLE3_OPCODE_WRITE_EEPROM 0x01
104#define ANGLE3_OPCODE_READ_EEPROM 0x02
105#define ANGLE3_OPCODE_WRITE_REG 0x03
106#define ANGLE3_OPCODE_READ_REG 0x04
107#define ANGLE3_OPCODE_CHANGE_MODE 0x05
108#define ANGLE3_OPCODE_ANGLE_DATA_RENEW 0x08
109#define ANGLE3_OPCODE_READ_ANGLE 0x09
110 // End group operation_code
111
116#define ANGLE3_NORMAL_MODE 0x0000
117#define ANGLE3_USER_MODE 0x050F
118 // End group command
119
128#define ANGLE3_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
129#define ANGLE3_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
130
136#define ANGLE3_MAP_MIKROBUS( cfg, mikrobus ) \
137 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
138 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
139 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
140 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
141 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
143 // End group macro
144// --------------------------------------------------------------- PUBLIC TYPES
153typedef struct
154{
155 // Input pins
156 digital_in_t int_pin;
157
158 // Modules
159 spi_master_t spi;
160 pin_name_t chip_select;
161
162} angle3_t;
163
167typedef struct
168{
169 // Communication gpio pins
170 pin_name_t miso;
171 pin_name_t mosi;
172 pin_name_t sck;
173 pin_name_t cs;
174
175 // Additional gpio pins
176 pin_name_t int_pin;
177
178 // static variable
179 uint32_t spi_speed;
180 spi_master_mode_t spi_mode;
181 spi_master_chip_select_polarity_t cs_polarity;
182
184
185 // End types group
186// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
187
193#ifdef __cplusplus
194extern "C"{
195#endif
196
206
218
227err_t angle3_init ( angle3_t *ctx, angle3_cfg_t *cfg );
228
239void angle3_write_data ( angle3_t* ctx, uint8_t opcode, uint8_t reg, uint16_t write_data );
251uint16_t angle3_read_data ( angle3_t* ctx, uint8_t opcode, uint8_t reg );
252
264void angle3_write_eeprom ( angle3_t* ctx, uint8_t reg_addr, uint16_t write_data );
265
276uint16_t angle3_read_eeprom ( angle3_t* ctx, uint8_t reg_addr );
277
289
300void angle3_write_register ( angle3_t* ctx, uint8_t reg_addr, uint16_t write_data );
301
313uint16_t angle3_read_register ( angle3_t* ctx, uint8_t reg_addr );
314
326void angle3_set_mode( angle3_t* ctx, uint16_t set_mode );
327
338
349
360
361
373float angle3_calculate_degrees ( angle3_t* ctx, uint16_t angle );
374
385
386#ifdef __cplusplus
387}
388#endif
389#endif // ANGLE3_H
390
391 // End public_function group
393
394// ------------------------------------------------------------------------ END
uint8_t angle3_read_error(angle3_t *ctx)
Read state of Error INT Pin.
void angle3_set_user_mode(angle3_t *ctx)
Set user mode function.
uint16_t angle3_read_eeprom(angle3_t *ctx, uint8_t reg_addr)
Read EEPROM function.
void angle3_set_mode(angle3_t *ctx, uint16_t set_mode)
Set mode function.
uint16_t angle3_read_data(angle3_t *ctx, uint8_t opcode, uint8_t reg)
Generic read function.
void angle3_write_register(angle3_t *ctx, uint8_t reg_addr, uint16_t write_data)
Write register function.
void angle3_write_eeprom(angle3_t *ctx, uint8_t reg_addr, uint16_t write_data)
Write EEPROM function.
float angle3_calculate_degrees(angle3_t *ctx, uint16_t angle)
Degrees Calculation function.
uint16_t angle3_read_angle_data(angle3_t *ctx)
Read angle data function.
void angle3_set_normal_mode(angle3_t *ctx)
Set normal mode function.
void angle3_cfg_setup(angle3_cfg_t *cfg)
Config Object Initialization function.
void angle3_default_cfg(angle3_t *ctx)
Default Config Object Initialization function.
err_t angle3_init(angle3_t *ctx, angle3_cfg_t *cfg)
Initialization function.
uint16_t angle3_read_register(angle3_t *ctx, uint8_t reg_addr)
Read register function.
void angle3_write_data(angle3_t *ctx, uint8_t opcode, uint8_t reg, uint16_t write_data)
Generic write function.
void angle3_lock_eeprom(angle3_t *ctx)
EEPROM lock function.
This file contains SPI specific macros, functions, etc.
Click configuration structure definition.
Definition angle3.h:168
spi_master_chip_select_polarity_t cs_polarity
Definition angle3.h:181
pin_name_t sck
Definition angle3.h:172
spi_master_mode_t spi_mode
Definition angle3.h:180
pin_name_t mosi
Definition angle3.h:171
uint32_t spi_speed
Definition angle3.h:179
pin_name_t int_pin
Definition angle3.h:176
pin_name_t miso
Definition angle3.h:170
pin_name_t cs
Definition angle3.h:173
Click ctx object definition.
Definition angle3.h:154
spi_master_t spi
Definition angle3.h:159
digital_in_t int_pin
Definition angle3.h:156
pin_name_t chip_select
Definition angle3.h:160