accel17 2.0.0.0
accel17.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 ACCEL17_H
29#define ACCEL17_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_i2c_master.h"
52
73#define ACCEL17_REG_ACCEL_CONFIG 0x00
74#define ACCEL17_REG_ACCEL_X_MSB 0x01
75#define ACCEL17_REG_ACCEL_X_LSB 0x02
76#define ACCEL17_REG_ACCEL_Y_MSB 0x03
77#define ACCEL17_REG_ACCEL_Y_LSB 0x04
78
79 // accel17_reg
80
95#define ACCEL17_TOEN_MASK 0x08 // Temperature Out Status
96#define ACCEL17_TOEN_DISABLE 0x00 // Temperature Out Disable
97#define ACCEL17_TOEN_ENABLE 0x08 // Temperature Out Enable
98#define ACCEL17_BGTST_MASK 0x04 // BandGap Test Status
99#define ACCEL17_BGTST_NORMAL 0x00 // Normal Test
100#define ACCEL17_BGTST_BANDGAP 0x04 // Bandga Test
101#define ACCEL17_ST_MASK 0x02 // Self Test Status
102#define ACCEL17_ST_OFF 0x00 // Self Test Off
103#define ACCEL17_ST_ON 0x02 // Self Test On
104#define ACCEL17_PD_MASK 0x01 // Power Status
105#define ACCEL17_PD_ON 0x00 // Power On
106#define ACCEL17_PD_DOWN 0x01 // Power Down
107
112#define ACCEL17_OFFSET 2048
113#define ACCEL17_SENSITIVITY 512.0
114#define ACCEL17_DEGREE_RES 90
115
121#define ACCEL17_SET_DEV_ADDR 0x10
122
123 // accel17_set
124
139#define ACCEL17_MAP_MIKROBUS( cfg, mikrobus ) \
140 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
141 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
142
143 // accel17_map
144 // accel17
145
150typedef struct
151{
152 // Modules
153 i2c_master_t i2c;
155 // I2C slave address
158} accel17_t;
159
164typedef struct
165{
166 pin_name_t scl;
167 pin_name_t sda;
169 uint32_t i2c_speed;
170 uint8_t i2c_address;
173
178typedef struct
179{
180 float x;
181 float y;
184
189typedef enum
190{
192 ACCEL17_ERROR = -1
193
195
212
228
243
256err_t accel17_generic_write ( accel17_t *ctx, uint8_t reg, uint8_t tx_data );
257
272err_t accel17_generic_read ( accel17_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
273
288
289#ifdef __cplusplus
290}
291#endif
292#endif // ACCEL17_H
293
294 // accel17
295
296// ------------------------------------------------------------------------ END
accel17_return_value_t
Accel 17 Click return value data.
Definition accel17.h:190
@ ACCEL17_OK
Definition accel17.h:191
@ ACCEL17_ERROR
Definition accel17.h:192
err_t accel17_generic_write(accel17_t *ctx, uint8_t reg, uint8_t tx_data)
Accel 17 I2C writing function.
void accel17_cfg_setup(accel17_cfg_t *cfg)
Accel 17 configuration object setup function.
err_t accel17_init(accel17_t *ctx, accel17_cfg_t *cfg)
Accel 17 initialization function.
err_t accel17_default_cfg(accel17_t *ctx)
Accel 17 default configuration function.
err_t accel17_generic_read(accel17_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Accel 17 I2C reading function.
err_t accel17_get_axes_data(accel17_t *ctx, accel17_axes_t *axes)
Accel data reading.
Accel 17 Click axes data.
Definition accel17.h:179
float y
Definition accel17.h:181
float x
Definition accel17.h:180
Accel 17 Click configuration object.
Definition accel17.h:165
uint32_t i2c_speed
Definition accel17.h:169
pin_name_t scl
Definition accel17.h:166
pin_name_t sda
Definition accel17.h:167
uint8_t i2c_address
Definition accel17.h:170
Accel 17 Click context object.
Definition accel17.h:151
i2c_master_t i2c
Definition accel17.h:153
uint8_t slave_address
Definition accel17.h:156