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
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define ACCEL17_REG_ACCEL_CONFIG 0x00
60 #define ACCEL17_REG_ACCEL_X_MSB 0x01
61 #define ACCEL17_REG_ACCEL_X_LSB 0x02
62 #define ACCEL17_REG_ACCEL_Y_MSB 0x03
63 #define ACCEL17_REG_ACCEL_Y_LSB 0x04
64  // accel17_reg
66 
81 #define ACCEL17_TOEN_MASK 0x08 // Temperature Out Status
82 #define ACCEL17_TOEN_DISABLE 0x00 // Temperature Out Disable
83 #define ACCEL17_TOEN_ENABLE 0x08 // Temperature Out Enable
84 #define ACCEL17_BGTST_MASK 0x04 // BandGap Test Status
85 #define ACCEL17_BGTST_NORMAL 0x00 // Normal Test
86 #define ACCEL17_BGTST_BANDGAP 0x04 // Bandga Test
87 #define ACCEL17_ST_MASK 0x02 // Self Test Status
88 #define ACCEL17_ST_OFF 0x00 // Self Test Off
89 #define ACCEL17_ST_ON 0x02 // Self Test On
90 #define ACCEL17_PD_MASK 0x01 // Power Status
91 #define ACCEL17_PD_ON 0x00 // Power On
92 #define ACCEL17_PD_DOWN 0x01 // Power Down
93 
98 #define ACCEL17_OFFSET 2048
99 #define ACCEL17_SENSITIVITY 512.0
100 #define ACCEL17_DEGREE_RES 90
101 
107 #define ACCEL17_SET_DEV_ADDR 0x10
108  // accel17_set
110 
125 #define ACCEL17_MAP_MIKROBUS( cfg, mikrobus ) \
126  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
127  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
128  // accel17_map // accel17
131 
136 typedef struct
137 {
138  // Modules
139  i2c_master_t i2c;
141  // I2C slave address
142  uint8_t slave_address;
144 } accel17_t;
145 
150 typedef struct
151 {
152  pin_name_t scl;
153  pin_name_t sda;
155  uint32_t i2c_speed;
156  uint8_t i2c_address;
158 } accel17_cfg_t;
159 
164 typedef struct
165 {
166  float x;
167  float y;
170 
175 typedef enum
176 {
178  ACCEL17_ERROR = -1
179 
181 
197 void accel17_cfg_setup ( accel17_cfg_t *cfg );
198 
213 err_t accel17_init ( accel17_t *ctx, accel17_cfg_t *cfg );
214 
228 err_t accel17_default_cfg ( accel17_t *ctx );
229 
242 err_t accel17_generic_write ( accel17_t *ctx, uint8_t reg, uint8_t tx_data );
243 
258 err_t accel17_generic_read ( accel17_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
259 
273 err_t accel17_get_axes_data ( accel17_t *ctx, accel17_axes_t *axes );
274 
275 #ifdef __cplusplus
276 }
277 #endif
278 #endif // ACCEL17_H
279  // accel17
281 
282 // ------------------------------------------------------------------------ END
accel17_default_cfg
err_t accel17_default_cfg(accel17_t *ctx)
Accel 17 default configuration function.
accel17_t
Accel 17 Click context object.
Definition: accel17.h:135
accel17_cfg_t
Accel 17 Click configuration object.
Definition: accel17.h:149
accel17_return_value_t
accel17_return_value_t
Accel 17 Click return value data.
Definition: accel17.h:174
accel17_init
err_t accel17_init(accel17_t *ctx, accel17_cfg_t *cfg)
Accel 17 initialization function.
ACCEL17_OK
Definition: accel17.h:176
ACCEL17_ERROR
Definition: accel17.h:177
accel17_axes_t
Accel 17 Click axes data.
Definition: accel17.h:163
accel17_cfg_setup
void accel17_cfg_setup(accel17_cfg_t *cfg)
Accel 17 configuration object setup function.
accel17_generic_write
err_t accel17_generic_write(accel17_t *ctx, uint8_t reg, uint8_t tx_data)
Accel 17 I2C writing function.
accel17_get_axes_data
err_t accel17_get_axes_data(accel17_t *ctx, accel17_axes_t *axes)
Accel data reading.
accel17_generic_read
err_t accel17_generic_read(accel17_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Accel 17 I2C reading function.