accel12 2.0.0.0
accel12.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 ACCEL12_H
36#define ACCEL12_H
37
38#include "drv_digital_in.h"
39#include "drv_i2c_master.h"
40
41// -------------------------------------------------------------- PUBLIC MACROS
51#define ACCEL12_MAP_MIKROBUS( cfg, mikrobus ) \
52 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
53 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
54 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
61#define ACCEL12_RETVAL uint8_t
62
63#define ACCEL12_OK 0x00
64#define ACCEL12_INIT_ERROR 0xFF
71#define ACCEL12_REG_GENERAL_STATUS 0x03
72#define ACCEL12_REG_DEVICE_STATUS 0x04
73#define ACCEL12_REG_INTERRUPT_ENABLE 0x06
74#define ACCEL12_REG_MODE_CONTROL 0x07
75#define ACCEL12_REG_SAMPLE_RATE_AND_TAP 0x08
76#define ACCEL12_REG_TAP_CONTROL 0x09
77#define ACCEL12_REG_TAP_X_DURATION 0x0A
78#define ACCEL12_REG_TAP_Y_DURATION 0x0B
79#define ACCEL12_REG_TAP_Z_DURATION 0x0C
80#define ACCEL12_REG_TAP_X_THRESHOLD 0x0A
81#define ACCEL12_REG_TAP_Y_THRESHOLD 0x0B
82#define ACCEL12_REG_TAP_Z_THRESHOLD 0x0C
83#define ACCEL12_REG_X_AXIS_LSB 0x0D
84#define ACCEL12_REG_X_AXIS_MSB 0x0E
85#define ACCEL12_REG_Y_AXIS_LSB 0x0F
86#define ACCEL12_REG_Y_AXIS_MSB 0x10
87#define ACCEL12_REG_Z_AXIS_LSB 0x11
88#define ACCEL12_REG_Z_AXIS_MSB 0x12
89#define ACCEL12_REG_OUTPUT_CONFIG 0x20
90#define ACCEL12_REG_X_OFFSET_LSB 0x21
91#define ACCEL12_REG_X_OFFSET_MSB 0x22
92#define ACCEL12_REG_Y_OFFSET_LSB 0x23
93#define ACCEL12_REG_Y_OFFSET_MSB 0x24
94#define ACCEL12_REG_Z_OFFSET_LSB 0x25
95#define ACCEL12_REG_Z_OFFSET_MSB 0x26
96#define ACCEL12_REG_X_GAIN 0x27
97#define ACCEL12_REG_Y_GAIN 0x28
98#define ACCEL12_REG_Z_GAIN 0x29
99#define ACCEL12_REG_PRODUCT_CODE 0x3B
106#define ACCEL12_GS_TAP_X_POSITIVE 0x01
107#define ACCEL12_GS_TAP_X_NEGATIVE 0x02
108#define ACCEL12_GS_TAP_Y_POSITIVE 0x04
109#define ACCEL12_GS_TAP_Y_NEGATIVE 0x08
110#define ACCEL12_GS_TAP_Z_POSITIVE 0x10
111#define ACCEL12_GS_TAP_Z_NEGATIVE 0x20
112#define ACCEL12_GS_ACQ_INTERRUPT 0x80
119#define ACCEL12_DS_STANDBY_STATE 0x00
120#define ACCEL12_DS_WAKE_STATE 0x01
121#define ACCEL12_DS_I2C_WDT_NO_EVENT 0x00
122#define ACCEL12_DS_I2C_WDT_EVENT_DCT 0x10
123#define ACCEL12_DS_INTERNAL_MEMORY_NO_USE 0x00
124#define ACCEL12_DS_INTERNAL_MEMORY_USE 0x80
131#define ACCEL12_EINT_TAP_XP_ENABLE 0x01
132#define ACCEL12_EINT_TAP_XP_DISABLE 0x00
133#define ACCEL12_EINT_TAP_XN_ENABLE 0x02
134#define ACCEL12_EINT_TAP_XN_DISABLE 0x00
135#define ACCEL12_EINT_TAP_YP_ENABLE 0x04
136#define ACCEL12_EINT_TAP_YP_DISABLE 0x00
137#define ACCEL12_EINT_TAP_YN_ENABLE 0x08
138#define ACCEL12_EINT_TAP_YN_DISABLE 0x00
139#define ACCEL12_EINT_TAP_ZP_ENABLE 0x10
140#define ACCEL12_EINT_TAP_ZP_DISABLE 0x00
141#define ACCEL12_EINT_TAP_ZN_ENABLE 0x20
142#define ACCEL12_EINT_TAP_ZN_DISABLE 0x00
143#define ACCEL12_EINT_ACQ_INT_ENABLE 0x80
144#define ACCEL12_EINT_ACQ_INT_DISABLE 0x00
151#define ACCEL12_MODE_STANDBY_STATE 0x00
152#define ACCEL12_MODE_WAKE_STATE 0x01
153#define ACCEL12_MODE_I2C_WDT_NEG_DISABLE 0x00
154#define ACCEL12_MODE_I2C_WDT_NEG_ENABLE 0x10
155#define ACCEL12_MODE_I2C_WDT_POS_DISABLE 0x00
156#define ACCEL12_MODE_I2C_WDT_POS_ENABLE 0x20
157#define ACCEL12_MODE_IPP_OPEN_DRAIN 0x00
158#define ACCEL12_MODE_IPP_PUSH_PULL 0x40
159#define ACCEL12_MODE_IAH_ACTIVE_LOW 0x00
160#define ACCEL12_MODE_IAH_ACTIVE_HIGH 0x80
167#define ACCEL12_SRTFR_RATE_32Hz 0x00
168#define ACCEL12_SRTFR_RATE_16Hz 0x01
169#define ACCEL12_SRTFR_RATE_8Hz 0x02
170#define ACCEL12_SRTFR_RATE_4Hz 0x03
171#define ACCEL12_SRTFR_RATE_2Hz 0x04
172#define ACCEL12_SRTFR_RATE_1Hz 0x05
173#define ACCEL12_SRTFR_RATE_0p5Hz 0x06
174#define ACCEL12_SRTFR_RATE_0p25Hz 0x07
175#define ACCEL12_SRTFR_RATE_64Hz 0x08
176#define ACCEL12_SRTFR_RATE_128Hz 0x09
177#define ACCEL12_SRTFR_RATE_256Hz 0x0A
178#define ACCEL12_SRTFR_FLIP_TAPX_DISABLE 0x00
179#define ACCEL12_SRTFR_FLIP_TAPX_ENABLE 0x10
180#define ACCEL12_SRTFR_FLIP_TAPY_DISABLE 0x00
181#define ACCEL12_SRTFR_FLIP_TAPY_ENABLE 0x20
182#define ACCEL12_SRTFR_FLIP_TAPZ_DISABLE 0x00
183#define ACCEL12_SRTFR_FLIP_TAPZ_ENABLE 0x40
184#define ACCEL12_SRTFR_TAP_LATCH_ENABLE 0x00
185#define ACCEL12_SRTFR_TAP_LATCH_DISABLE 0x80
192#define ACCEL12_TAPEN_TAP_X_POS_DISABLE 0x00
193#define ACCEL12_TAPEN_TAP_X_POS_ENABLE 0x01
194#define ACCEL12_TAPEN_TAP_X_NEG_DISABLE 0x00
195#define ACCEL12_TAPEN_TAP_X_NEG_ENABLE 0x02
196#define ACCEL12_TAPEN_TAP_Y_POS_DISABLE 0x00
197#define ACCEL12_TAPEN_TAP_Y_POS_ENABLE 0x04
198#define ACCEL12_TAPEN_TAP_Y_NEG_DISABLE 0x00
199#define ACCEL12_TAPEN_TAP_Y_NEG_ENABLE 0x08
200#define ACCEL12_TAPEN_TAP_Z_POS_DISABLE 0x00
201#define ACCEL12_TAPEN_TAP_Z_POS_ENABLE 0x10
202#define ACCEL12_TAPEN_TAP_Z_NEG_DISABLE 0x00
203#define ACCEL12_TAPEN_TAP_Z_NEG_ENABLE 0x20
204#define ACCEL12_TAPEN_TAP_DURATION 0x00
205#define ACCEL12_TAPEN_TAP_THRESHOLD 0x40
206#define ACCEL12_TAPEN_ALL_TAP_ENABLE 0x00
207#define ACCEL12_TAPEN_ALL_TAP_DISABLE 0x80
214#define ACCEL12_OUTCFG_RESOLUTION_6_bit 0x00
215#define ACCEL12_OUTCFG_RESOLUTION_7_bit 0x01
216#define ACCEL12_OUTCFG_RESOLUTION_8_bit 0x02
217#define ACCEL12_OUTCFG_RESOLUTION_10_bit 0x03
218#define ACCEL12_OUTCFG_RESOLUTION_12_bit 0x04
219#define ACCEL12_OUTCFG_RESOLUTION_14_bit 0x05
220#define ACCEL12_OUTCFG_RANGE_2g 0x00
221#define ACCEL12_OUTCFG_RANGE_4g 0x10
222#define ACCEL12_OUTCFG_RANGE_8g 0x20
223#define ACCEL12_OUTCFG_RANGE_16g 0x30
224#define ACCEL12_OUTCFG_RANGE_12g 0x40 // End group macro
228// --------------------------------------------------------------- PUBLIC TYPES
237typedef struct
238{
239 // Input pins
240
241 digital_in_t int_pin;
242
243 // Modules
244
245 i2c_master_t i2c;
246
247 // ctx variable
248
250
251} accel12_t;
252
256typedef struct
257{
258 // Communication gpio pins
259
260 pin_name_t scl;
261 pin_name_t sda;
262
263 // Additional gpio pins
264
265 pin_name_t int_pin;
266
267 // static variable
268
269 uint32_t i2c_speed;
270 uint8_t i2c_address;
271
273 // End types group
275// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
276
282#ifdef __cplusplus
283extern "C"{
284#endif
285
295
305
350
361void accel12_generic_write ( accel12_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
362
373void accel12_generic_read ( accel12_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
374
385void accel12_configuration ( accel12_t *ctx, uint8_t reg, uint8_t data_in );
386
397int16_t accel12_get_one_axis ( accel12_t *ctx, uint8_t axis );
398
409void accel12_get_axis_data ( accel12_t *ctx, int16_t *x_axis, int16_t *y_axis, int16_t *z_axis);
410
426
436
437#ifdef __cplusplus
438}
439#endif
440#endif // _ACCEL12_H_
441 // End public_function group
444
445// ------------------------------------------------------------------------- END
#define ACCEL12_RETVAL
Definition: accel12.h:61
uint8_t accel12_get_interrupt_state(accel12_t *ctx)
Functions for read INT pin state.
int16_t accel12_get_one_axis(accel12_t *ctx, uint8_t axis)
Functions for read one Accel axis data.
void accel12_get_axis_data(accel12_t *ctx, int16_t *x_axis, int16_t *y_axis, int16_t *z_axis)
Functions for read Accel axis data.
void accel12_configuration(accel12_t *ctx, uint8_t reg, uint8_t data_in)
Functions for configuration one register.
void accel12_default_cfg(accel12_t *ctx)
Click Default Configuration function.
void accel12_generic_read(accel12_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void accel12_cfg_setup(accel12_cfg_t *cfg)
Config Object Initialization function.
ACCEL12_RETVAL accel12_init(accel12_t *ctx, accel12_cfg_t *cfg)
Initialization function.
void accel12_generic_write(accel12_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
uint8_t accel12_get_tap_detection(accel12_t *ctx)
TAP detection.
Click configuration structure definition.
Definition: accel12.h:257
uint32_t i2c_speed
Definition: accel12.h:269
pin_name_t scl
Definition: accel12.h:260
pin_name_t int_pin
Definition: accel12.h:265
pin_name_t sda
Definition: accel12.h:261
uint8_t i2c_address
Definition: accel12.h:270
Click ctx object definition.
Definition: accel12.h:238
digital_in_t int_pin
Definition: accel12.h:241
i2c_master_t i2c
Definition: accel12.h:245
uint8_t slave_address
Definition: accel12.h:249