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 "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_in.h"
49 #include "drv_i2c_master.h"
50 
51 // -------------------------------------------------------------- PUBLIC MACROS
61 #define ACCEL12_MAP_MIKROBUS( cfg, mikrobus ) \
62  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
63  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
64  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
65 
71 #define ACCEL12_RETVAL uint8_t
72 
73 #define ACCEL12_OK 0x00
74 #define ACCEL12_INIT_ERROR 0xFF
75 
81 #define ACCEL12_REG_GENERAL_STATUS 0x03
82 #define ACCEL12_REG_DEVICE_STATUS 0x04
83 #define ACCEL12_REG_INTERRUPT_ENABLE 0x06
84 #define ACCEL12_REG_MODE_CONTROL 0x07
85 #define ACCEL12_REG_SAMPLE_RATE_AND_TAP 0x08
86 #define ACCEL12_REG_TAP_CONTROL 0x09
87 #define ACCEL12_REG_TAP_X_DURATION 0x0A
88 #define ACCEL12_REG_TAP_Y_DURATION 0x0B
89 #define ACCEL12_REG_TAP_Z_DURATION 0x0C
90 #define ACCEL12_REG_TAP_X_THRESHOLD 0x0A
91 #define ACCEL12_REG_TAP_Y_THRESHOLD 0x0B
92 #define ACCEL12_REG_TAP_Z_THRESHOLD 0x0C
93 #define ACCEL12_REG_X_AXIS_LSB 0x0D
94 #define ACCEL12_REG_X_AXIS_MSB 0x0E
95 #define ACCEL12_REG_Y_AXIS_LSB 0x0F
96 #define ACCEL12_REG_Y_AXIS_MSB 0x10
97 #define ACCEL12_REG_Z_AXIS_LSB 0x11
98 #define ACCEL12_REG_Z_AXIS_MSB 0x12
99 #define ACCEL12_REG_OUTPUT_CONFIG 0x20
100 #define ACCEL12_REG_X_OFFSET_LSB 0x21
101 #define ACCEL12_REG_X_OFFSET_MSB 0x22
102 #define ACCEL12_REG_Y_OFFSET_LSB 0x23
103 #define ACCEL12_REG_Y_OFFSET_MSB 0x24
104 #define ACCEL12_REG_Z_OFFSET_LSB 0x25
105 #define ACCEL12_REG_Z_OFFSET_MSB 0x26
106 #define ACCEL12_REG_X_GAIN 0x27
107 #define ACCEL12_REG_Y_GAIN 0x28
108 #define ACCEL12_REG_Z_GAIN 0x29
109 #define ACCEL12_REG_PRODUCT_CODE 0x3B
110 
116 #define ACCEL12_GS_TAP_X_POSITIVE 0x01
117 #define ACCEL12_GS_TAP_X_NEGATIVE 0x02
118 #define ACCEL12_GS_TAP_Y_POSITIVE 0x04
119 #define ACCEL12_GS_TAP_Y_NEGATIVE 0x08
120 #define ACCEL12_GS_TAP_Z_POSITIVE 0x10
121 #define ACCEL12_GS_TAP_Z_NEGATIVE 0x20
122 #define ACCEL12_GS_ACQ_INTERRUPT 0x80
123 
129 #define ACCEL12_DS_STANDBY_STATE 0x00
130 #define ACCEL12_DS_WAKE_STATE 0x01
131 #define ACCEL12_DS_I2C_WDT_NO_EVENT 0x00
132 #define ACCEL12_DS_I2C_WDT_EVENT_DCT 0x10
133 #define ACCEL12_DS_INTERNAL_MEMORY_NO_USE 0x00
134 #define ACCEL12_DS_INTERNAL_MEMORY_USE 0x80
135 
141 #define ACCEL12_EINT_TAP_XP_ENABLE 0x01
142 #define ACCEL12_EINT_TAP_XP_DISABLE 0x00
143 #define ACCEL12_EINT_TAP_XN_ENABLE 0x02
144 #define ACCEL12_EINT_TAP_XN_DISABLE 0x00
145 #define ACCEL12_EINT_TAP_YP_ENABLE 0x04
146 #define ACCEL12_EINT_TAP_YP_DISABLE 0x00
147 #define ACCEL12_EINT_TAP_YN_ENABLE 0x08
148 #define ACCEL12_EINT_TAP_YN_DISABLE 0x00
149 #define ACCEL12_EINT_TAP_ZP_ENABLE 0x10
150 #define ACCEL12_EINT_TAP_ZP_DISABLE 0x00
151 #define ACCEL12_EINT_TAP_ZN_ENABLE 0x20
152 #define ACCEL12_EINT_TAP_ZN_DISABLE 0x00
153 #define ACCEL12_EINT_ACQ_INT_ENABLE 0x80
154 #define ACCEL12_EINT_ACQ_INT_DISABLE 0x00
155 
161 #define ACCEL12_MODE_STANDBY_STATE 0x00
162 #define ACCEL12_MODE_WAKE_STATE 0x01
163 #define ACCEL12_MODE_I2C_WDT_NEG_DISABLE 0x00
164 #define ACCEL12_MODE_I2C_WDT_NEG_ENABLE 0x10
165 #define ACCEL12_MODE_I2C_WDT_POS_DISABLE 0x00
166 #define ACCEL12_MODE_I2C_WDT_POS_ENABLE 0x20
167 #define ACCEL12_MODE_IPP_OPEN_DRAIN 0x00
168 #define ACCEL12_MODE_IPP_PUSH_PULL 0x40
169 #define ACCEL12_MODE_IAH_ACTIVE_LOW 0x00
170 #define ACCEL12_MODE_IAH_ACTIVE_HIGH 0x80
171 
177 #define ACCEL12_SRTFR_RATE_32Hz 0x00
178 #define ACCEL12_SRTFR_RATE_16Hz 0x01
179 #define ACCEL12_SRTFR_RATE_8Hz 0x02
180 #define ACCEL12_SRTFR_RATE_4Hz 0x03
181 #define ACCEL12_SRTFR_RATE_2Hz 0x04
182 #define ACCEL12_SRTFR_RATE_1Hz 0x05
183 #define ACCEL12_SRTFR_RATE_0p5Hz 0x06
184 #define ACCEL12_SRTFR_RATE_0p25Hz 0x07
185 #define ACCEL12_SRTFR_RATE_64Hz 0x08
186 #define ACCEL12_SRTFR_RATE_128Hz 0x09
187 #define ACCEL12_SRTFR_RATE_256Hz 0x0A
188 #define ACCEL12_SRTFR_FLIP_TAPX_DISABLE 0x00
189 #define ACCEL12_SRTFR_FLIP_TAPX_ENABLE 0x10
190 #define ACCEL12_SRTFR_FLIP_TAPY_DISABLE 0x00
191 #define ACCEL12_SRTFR_FLIP_TAPY_ENABLE 0x20
192 #define ACCEL12_SRTFR_FLIP_TAPZ_DISABLE 0x00
193 #define ACCEL12_SRTFR_FLIP_TAPZ_ENABLE 0x40
194 #define ACCEL12_SRTFR_TAP_LATCH_ENABLE 0x00
195 #define ACCEL12_SRTFR_TAP_LATCH_DISABLE 0x80
196 
202 #define ACCEL12_TAPEN_TAP_X_POS_DISABLE 0x00
203 #define ACCEL12_TAPEN_TAP_X_POS_ENABLE 0x01
204 #define ACCEL12_TAPEN_TAP_X_NEG_DISABLE 0x00
205 #define ACCEL12_TAPEN_TAP_X_NEG_ENABLE 0x02
206 #define ACCEL12_TAPEN_TAP_Y_POS_DISABLE 0x00
207 #define ACCEL12_TAPEN_TAP_Y_POS_ENABLE 0x04
208 #define ACCEL12_TAPEN_TAP_Y_NEG_DISABLE 0x00
209 #define ACCEL12_TAPEN_TAP_Y_NEG_ENABLE 0x08
210 #define ACCEL12_TAPEN_TAP_Z_POS_DISABLE 0x00
211 #define ACCEL12_TAPEN_TAP_Z_POS_ENABLE 0x10
212 #define ACCEL12_TAPEN_TAP_Z_NEG_DISABLE 0x00
213 #define ACCEL12_TAPEN_TAP_Z_NEG_ENABLE 0x20
214 #define ACCEL12_TAPEN_TAP_DURATION 0x00
215 #define ACCEL12_TAPEN_TAP_THRESHOLD 0x40
216 #define ACCEL12_TAPEN_ALL_TAP_ENABLE 0x00
217 #define ACCEL12_TAPEN_ALL_TAP_DISABLE 0x80
218 
224 #define ACCEL12_OUTCFG_RESOLUTION_6_bit 0x00
225 #define ACCEL12_OUTCFG_RESOLUTION_7_bit 0x01
226 #define ACCEL12_OUTCFG_RESOLUTION_8_bit 0x02
227 #define ACCEL12_OUTCFG_RESOLUTION_10_bit 0x03
228 #define ACCEL12_OUTCFG_RESOLUTION_12_bit 0x04
229 #define ACCEL12_OUTCFG_RESOLUTION_14_bit 0x05
230 #define ACCEL12_OUTCFG_RANGE_2g 0x00
231 #define ACCEL12_OUTCFG_RANGE_4g 0x10
232 #define ACCEL12_OUTCFG_RANGE_8g 0x20
233 #define ACCEL12_OUTCFG_RANGE_16g 0x30
234 #define ACCEL12_OUTCFG_RANGE_12g 0x40
235  // End group macro
238 // --------------------------------------------------------------- PUBLIC TYPES
247 typedef struct
248 {
249  // Input pins
250 
251  digital_in_t int_pin;
252 
253  // Modules
254 
255  i2c_master_t i2c;
256 
257  // ctx variable
258 
259  uint8_t slave_address;
260 
261 } accel12_t;
262 
266 typedef struct
267 {
268  // Communication gpio pins
269 
270  pin_name_t scl;
271  pin_name_t sda;
272 
273  // Additional gpio pins
274 
275  pin_name_t int_pin;
276 
277  // static variable
278 
279  uint32_t i2c_speed;
280  uint8_t i2c_address;
281 
282 } accel12_cfg_t;
283  // End types group
285 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
286 
292 #ifdef __cplusplus
293 extern "C"{
294 #endif
295 
305 
315 
360 
371 void accel12_generic_write ( accel12_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
372 
383 void accel12_generic_read ( accel12_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
384 
395 void accel12_configuration ( accel12_t *ctx, uint8_t reg, uint8_t data_in );
396 
407 int16_t accel12_get_one_axis ( accel12_t *ctx, uint8_t axis );
408 
419 void accel12_get_axis_data ( accel12_t *ctx, int16_t *x_axis, int16_t *y_axis, int16_t *z_axis);
420 
436 
446 
447 #ifdef __cplusplus
448 }
449 #endif
450 #endif // _ACCEL12_H_
451  // End public_function group
454 
455 // ------------------------------------------------------------------------- END
accel12_get_interrupt_state
uint8_t accel12_get_interrupt_state(accel12_t *ctx)
Functions for read INT pin state.
accel12_t
Click ctx object definition.
Definition: accel12.h:248
accel12_cfg_t::sda
pin_name_t sda
Definition: accel12.h:271
accel12_cfg_t::int_pin
pin_name_t int_pin
Definition: accel12.h:275
accel12_cfg_t::i2c_address
uint8_t i2c_address
Definition: accel12.h:280
accel12_cfg_t::scl
pin_name_t scl
Definition: accel12.h:270
accel12_generic_write
void accel12_generic_write(accel12_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
accel12_default_cfg
void accel12_default_cfg(accel12_t *ctx)
Click Default Configuration function.
accel12_get_one_axis
int16_t accel12_get_one_axis(accel12_t *ctx, uint8_t axis)
Functions for read one Accel axis data.
accel12_get_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.
accel12_cfg_t
Click configuration structure definition.
Definition: accel12.h:267
ACCEL12_RETVAL
#define ACCEL12_RETVAL
Definition: accel12.h:71
accel12_t::slave_address
uint8_t slave_address
Definition: accel12.h:259
accel12_init
ACCEL12_RETVAL accel12_init(accel12_t *ctx, accel12_cfg_t *cfg)
Initialization function.
accel12_configuration
void accel12_configuration(accel12_t *ctx, uint8_t reg, uint8_t data_in)
Functions for configuration one register.
accel12_t::i2c
i2c_master_t i2c
Definition: accel12.h:255
accel12_cfg_setup
void accel12_cfg_setup(accel12_cfg_t *cfg)
Config Object Initialization function.
accel12_get_tap_detection
uint8_t accel12_get_tap_detection(accel12_t *ctx)
TAP detection.
accel12_t::int_pin
digital_in_t int_pin
Definition: accel12.h:251
accel12_generic_read
void accel12_generic_read(accel12_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
accel12_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: accel12.h:279