angle9 2.1.0.0
angle9.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 ANGLE9_H
29#define ANGLE9_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_spi_master.h"
52#include "spi_specifics.h"
53
74#define ANGLE9_REG_EWA 0x02
75#define ANGLE9_REG_EWDH 0x04
76#define ANGLE9_REG_EWDL 0x06
77#define ANGLE9_REG_EWCS 0x08
78#define ANGLE9_REG_ERA 0x0A
79#define ANGLE9_REG_ERCS 0x0C
80#define ANGLE9_REG_ERDH 0x0E
81#define ANGLE9_REG_ERDL 0x10
82#define ANGLE9_REG_CTRL 0x1E
83#define ANGLE9_REG_ANG 0x20
84#define ANGLE9_REG_STA 0x22
85#define ANGLE9_REG_ERR 0x24
86#define ANGLE9_REG_WARN 0x26
87#define ANGLE9_REG_TSEN 0x28
88#define ANGLE9_REG_FIELD 0x2A
89#define ANGLE9_REG_HANG 0x30
90#define ANGLE9_REG_ANG15 0x32
91#define ANGLE9_REG_ZANG 0x34
92#define ANGLE9_REG_KEY 0x3C
93
94 // angle9_reg
95
110#define ANGLE9_WRITE_BIT 0x40
111
116#define ANGLE9_DATA_RESOLUTION 0x0FFFu
117#define ANGLE9_FULL_CIRCLE 360.0f
118#define ANGLE9_TEMP_RESOLUTION 8.0f
119#define ANGLE9_TEMP_OFFSET 25.0f
120
125#define ANGLE9_ODD_PARITY 0x01
126
135#define ANGLE9_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
136#define ANGLE9_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
137
138 // angle9_set
139
154#define ANGLE9_MAP_MIKROBUS( cfg, mikrobus ) \
155 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
156 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
157 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
158 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
159 cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM );
160
161 // angle9_map
162 // angle9
163
168typedef struct
169{
170 // Input pins
171 digital_in_t pwm;
173 // Modules
174 spi_master_t spi;
176 pin_name_t chip_select;
178} angle9_t;
179
184typedef struct
185{
186 // Communication gpio pins
187 pin_name_t miso;
188 pin_name_t mosi;
189 pin_name_t sck;
190 pin_name_t cs;
192 // Additional gpio pins
193 pin_name_t pwm;
195 // static variable
196 uint32_t spi_speed;
197 spi_master_mode_t spi_mode;
198 spi_master_chip_select_polarity_t cs_polarity;
201
206typedef enum
207{
209 ANGLE9_ERROR = -1
210
212
229
243err_t angle9_init ( angle9_t *ctx, angle9_cfg_t *cfg );
244
258err_t angle9_write_register ( angle9_t *ctx, uint8_t reg, uint16_t data_in );
259
273err_t angle9_read_register ( angle9_t *ctx, uint8_t reg, uint16_t *data_out );
274
284
296err_t angle9_read_angle ( angle9_t *ctx, float *angle );
297
309err_t angle9_read_temperature ( angle9_t *ctx, float *temperature );
310
322err_t angle9_read_field_strength ( angle9_t *ctx, uint16_t *field_str );
323
324#ifdef __cplusplus
325}
326#endif
327#endif // ANGLE9_H
328
329 // angle9
330
331// ------------------------------------------------------------------------ END
angle9_return_value_t
Angle 9 Click return value data.
Definition angle9.h:207
@ ANGLE9_ERROR
Definition angle9.h:209
@ ANGLE9_OK
Definition angle9.h:208
err_t angle9_write_register(angle9_t *ctx, uint8_t reg, uint16_t data_in)
Angle 9 write register function.
void angle9_cfg_setup(angle9_cfg_t *cfg)
Angle 9 configuration object setup function.
err_t angle9_read_register(angle9_t *ctx, uint8_t reg, uint16_t *data_out)
Angle 9 read register function.
err_t angle9_init(angle9_t *ctx, angle9_cfg_t *cfg)
Angle 9 initialization function.
uint8_t angle9_get_pwm_pin(angle9_t *ctx)
Angle 9 get pwm pin function.
err_t angle9_read_temperature(angle9_t *ctx, float *temperature)
Angle 9 read temperature function.
err_t angle9_read_field_strength(angle9_t *ctx, uint16_t *field_str)
Angle 9 read field strength function.
err_t angle9_read_angle(angle9_t *ctx, float *angle)
Angle 9 read angle function.
This file contains SPI specific macros, functions, etc.
Angle 9 Click configuration object.
Definition angle9.h:185
spi_master_chip_select_polarity_t cs_polarity
Definition angle9.h:198
pin_name_t sck
Definition angle9.h:189
spi_master_mode_t spi_mode
Definition angle9.h:197
pin_name_t mosi
Definition angle9.h:188
uint32_t spi_speed
Definition angle9.h:196
pin_name_t pwm
Definition angle9.h:193
pin_name_t miso
Definition angle9.h:187
pin_name_t cs
Definition angle9.h:190
Angle 9 Click context object.
Definition angle9.h:169
spi_master_t spi
Definition angle9.h:174
digital_in_t pwm
Definition angle9.h:171
pin_name_t chip_select
Definition angle9.h:176