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
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_in.h"
53#include "drv_i2c_master.h"
54
55// -------------------------------------------------------------- PUBLIC MACROS
65#define ACCEL12_MAP_MIKROBUS( cfg, mikrobus ) \
66 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
67 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
68 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
75#define ACCEL12_RETVAL uint8_t
76
77#define ACCEL12_OK 0x00
78#define ACCEL12_INIT_ERROR 0xFF
85#define ACCEL12_REG_GENERAL_STATUS 0x03
86#define ACCEL12_REG_DEVICE_STATUS 0x04
87#define ACCEL12_REG_INTERRUPT_ENABLE 0x06
88#define ACCEL12_REG_MODE_CONTROL 0x07
89#define ACCEL12_REG_SAMPLE_RATE_AND_TAP 0x08
90#define ACCEL12_REG_TAP_CONTROL 0x09
91#define ACCEL12_REG_TAP_X_DURATION 0x0A
92#define ACCEL12_REG_TAP_Y_DURATION 0x0B
93#define ACCEL12_REG_TAP_Z_DURATION 0x0C
94#define ACCEL12_REG_TAP_X_THRESHOLD 0x0A
95#define ACCEL12_REG_TAP_Y_THRESHOLD 0x0B
96#define ACCEL12_REG_TAP_Z_THRESHOLD 0x0C
97#define ACCEL12_REG_X_AXIS_LSB 0x0D
98#define ACCEL12_REG_X_AXIS_MSB 0x0E
99#define ACCEL12_REG_Y_AXIS_LSB 0x0F
100#define ACCEL12_REG_Y_AXIS_MSB 0x10
101#define ACCEL12_REG_Z_AXIS_LSB 0x11
102#define ACCEL12_REG_Z_AXIS_MSB 0x12
103#define ACCEL12_REG_OUTPUT_CONFIG 0x20
104#define ACCEL12_REG_X_OFFSET_LSB 0x21
105#define ACCEL12_REG_X_OFFSET_MSB 0x22
106#define ACCEL12_REG_Y_OFFSET_LSB 0x23
107#define ACCEL12_REG_Y_OFFSET_MSB 0x24
108#define ACCEL12_REG_Z_OFFSET_LSB 0x25
109#define ACCEL12_REG_Z_OFFSET_MSB 0x26
110#define ACCEL12_REG_X_GAIN 0x27
111#define ACCEL12_REG_Y_GAIN 0x28
112#define ACCEL12_REG_Z_GAIN 0x29
113#define ACCEL12_REG_PRODUCT_CODE 0x3B
120#define ACCEL12_GS_TAP_X_POSITIVE 0x01
121#define ACCEL12_GS_TAP_X_NEGATIVE 0x02
122#define ACCEL12_GS_TAP_Y_POSITIVE 0x04
123#define ACCEL12_GS_TAP_Y_NEGATIVE 0x08
124#define ACCEL12_GS_TAP_Z_POSITIVE 0x10
125#define ACCEL12_GS_TAP_Z_NEGATIVE 0x20
126#define ACCEL12_GS_ACQ_INTERRUPT 0x80
133#define ACCEL12_DS_STANDBY_STATE 0x00
134#define ACCEL12_DS_WAKE_STATE 0x01
135#define ACCEL12_DS_I2C_WDT_NO_EVENT 0x00
136#define ACCEL12_DS_I2C_WDT_EVENT_DCT 0x10
137#define ACCEL12_DS_INTERNAL_MEMORY_NO_USE 0x00
138#define ACCEL12_DS_INTERNAL_MEMORY_USE 0x80
145#define ACCEL12_EINT_TAP_XP_ENABLE 0x01
146#define ACCEL12_EINT_TAP_XP_DISABLE 0x00
147#define ACCEL12_EINT_TAP_XN_ENABLE 0x02
148#define ACCEL12_EINT_TAP_XN_DISABLE 0x00
149#define ACCEL12_EINT_TAP_YP_ENABLE 0x04
150#define ACCEL12_EINT_TAP_YP_DISABLE 0x00
151#define ACCEL12_EINT_TAP_YN_ENABLE 0x08
152#define ACCEL12_EINT_TAP_YN_DISABLE 0x00
153#define ACCEL12_EINT_TAP_ZP_ENABLE 0x10
154#define ACCEL12_EINT_TAP_ZP_DISABLE 0x00
155#define ACCEL12_EINT_TAP_ZN_ENABLE 0x20
156#define ACCEL12_EINT_TAP_ZN_DISABLE 0x00
157#define ACCEL12_EINT_ACQ_INT_ENABLE 0x80
158#define ACCEL12_EINT_ACQ_INT_DISABLE 0x00
165#define ACCEL12_MODE_STANDBY_STATE 0x00
166#define ACCEL12_MODE_WAKE_STATE 0x01
167#define ACCEL12_MODE_I2C_WDT_NEG_DISABLE 0x00
168#define ACCEL12_MODE_I2C_WDT_NEG_ENABLE 0x10
169#define ACCEL12_MODE_I2C_WDT_POS_DISABLE 0x00
170#define ACCEL12_MODE_I2C_WDT_POS_ENABLE 0x20
171#define ACCEL12_MODE_IPP_OPEN_DRAIN 0x00
172#define ACCEL12_MODE_IPP_PUSH_PULL 0x40
173#define ACCEL12_MODE_IAH_ACTIVE_LOW 0x00
174#define ACCEL12_MODE_IAH_ACTIVE_HIGH 0x80
181#define ACCEL12_SRTFR_RATE_32Hz 0x00
182#define ACCEL12_SRTFR_RATE_16Hz 0x01
183#define ACCEL12_SRTFR_RATE_8Hz 0x02
184#define ACCEL12_SRTFR_RATE_4Hz 0x03
185#define ACCEL12_SRTFR_RATE_2Hz 0x04
186#define ACCEL12_SRTFR_RATE_1Hz 0x05
187#define ACCEL12_SRTFR_RATE_0p5Hz 0x06
188#define ACCEL12_SRTFR_RATE_0p25Hz 0x07
189#define ACCEL12_SRTFR_RATE_64Hz 0x08
190#define ACCEL12_SRTFR_RATE_128Hz 0x09
191#define ACCEL12_SRTFR_RATE_256Hz 0x0A
192#define ACCEL12_SRTFR_FLIP_TAPX_DISABLE 0x00
193#define ACCEL12_SRTFR_FLIP_TAPX_ENABLE 0x10
194#define ACCEL12_SRTFR_FLIP_TAPY_DISABLE 0x00
195#define ACCEL12_SRTFR_FLIP_TAPY_ENABLE 0x20
196#define ACCEL12_SRTFR_FLIP_TAPZ_DISABLE 0x00
197#define ACCEL12_SRTFR_FLIP_TAPZ_ENABLE 0x40
198#define ACCEL12_SRTFR_TAP_LATCH_ENABLE 0x00
199#define ACCEL12_SRTFR_TAP_LATCH_DISABLE 0x80
206#define ACCEL12_TAPEN_TAP_X_POS_DISABLE 0x00
207#define ACCEL12_TAPEN_TAP_X_POS_ENABLE 0x01
208#define ACCEL12_TAPEN_TAP_X_NEG_DISABLE 0x00
209#define ACCEL12_TAPEN_TAP_X_NEG_ENABLE 0x02
210#define ACCEL12_TAPEN_TAP_Y_POS_DISABLE 0x00
211#define ACCEL12_TAPEN_TAP_Y_POS_ENABLE 0x04
212#define ACCEL12_TAPEN_TAP_Y_NEG_DISABLE 0x00
213#define ACCEL12_TAPEN_TAP_Y_NEG_ENABLE 0x08
214#define ACCEL12_TAPEN_TAP_Z_POS_DISABLE 0x00
215#define ACCEL12_TAPEN_TAP_Z_POS_ENABLE 0x10
216#define ACCEL12_TAPEN_TAP_Z_NEG_DISABLE 0x00
217#define ACCEL12_TAPEN_TAP_Z_NEG_ENABLE 0x20
218#define ACCEL12_TAPEN_TAP_DURATION 0x00
219#define ACCEL12_TAPEN_TAP_THRESHOLD 0x40
220#define ACCEL12_TAPEN_ALL_TAP_ENABLE 0x00
221#define ACCEL12_TAPEN_ALL_TAP_DISABLE 0x80
228#define ACCEL12_OUTCFG_RESOLUTION_6_bit 0x00
229#define ACCEL12_OUTCFG_RESOLUTION_7_bit 0x01
230#define ACCEL12_OUTCFG_RESOLUTION_8_bit 0x02
231#define ACCEL12_OUTCFG_RESOLUTION_10_bit 0x03
232#define ACCEL12_OUTCFG_RESOLUTION_12_bit 0x04
233#define ACCEL12_OUTCFG_RESOLUTION_14_bit 0x05
234#define ACCEL12_OUTCFG_RANGE_2g 0x00
235#define ACCEL12_OUTCFG_RANGE_4g 0x10
236#define ACCEL12_OUTCFG_RANGE_8g 0x20
237#define ACCEL12_OUTCFG_RANGE_16g 0x30
238#define ACCEL12_OUTCFG_RANGE_12g 0x40
241 // End group macro
242// --------------------------------------------------------------- PUBLIC TYPES
251typedef struct
252{
253 // Input pins
254
255 digital_in_t int_pin;
256
257 // Modules
258
259 i2c_master_t i2c;
260
261 // ctx variable
262
264
265} accel12_t;
266
270typedef struct
271{
272 // Communication gpio pins
273
274 pin_name_t scl;
275 pin_name_t sda;
276
277 // Additional gpio pins
278
279 pin_name_t int_pin;
280
281 // static variable
282
283 uint32_t i2c_speed;
284 uint8_t i2c_address;
285
287
288 // End types group
289// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
290
296#ifdef __cplusplus
297extern "C"{
298#endif
299
309
319
364
375void accel12_generic_write ( accel12_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
376
387void accel12_generic_read ( accel12_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
388
399void accel12_configuration ( accel12_t *ctx, uint8_t reg, uint8_t data_in );
400
411int16_t accel12_get_one_axis ( accel12_t *ctx, uint8_t axis );
412
423void accel12_get_axis_data ( accel12_t *ctx, int16_t *x_axis, int16_t *y_axis, int16_t *z_axis);
424
440
450
451#ifdef __cplusplus
452}
453#endif
454#endif // _ACCEL12_H_
455
456 // End public_function group
458
459// ------------------------------------------------------------------------- END
#define ACCEL12_RETVAL
Definition accel12.h:75
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:271
uint32_t i2c_speed
Definition accel12.h:283
pin_name_t scl
Definition accel12.h:274
pin_name_t int_pin
Definition accel12.h:279
pin_name_t sda
Definition accel12.h:275
uint8_t i2c_address
Definition accel12.h:284
Click ctx object definition.
Definition accel12.h:252
digital_in_t int_pin
Definition accel12.h:255
i2c_master_t i2c
Definition accel12.h:259
uint8_t slave_address
Definition accel12.h:263