accel25  2.1.0.0
accel25.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 ACCEL25_H
29 #define ACCEL25_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define ACCEL25_REG_INT_SRC0 0x00
70 #define ACCEL25_REG_INT_CLR0 0x00
71 #define ACCEL25_REG_INT_SRC1 0x01
72 #define ACCEL25_REG_INT_CLR1 0x01
73 #define ACCEL25_REG_STATUS 0x02
74 #define ACCEL25_REG_XOUT_MSB 0x03
75 #define ACCEL25_REG_XOUT_LSB 0x04
76 #define ACCEL25_REG_YOUT_MSB 0x05
77 #define ACCEL25_REG_YOUT_LSB 0x06
78 #define ACCEL25_REG_ZOUT_MSB 0x07
79 #define ACCEL25_REG_ZOUT_LSB 0x08
80 #define ACCEL25_REG_TOUT 0x09
81 #define ACCEL25_REG_INT_MASK0 0x0A
82 #define ACCEL25_REG_INT_MASK1 0x0B
83 #define ACCEL25_REG_DETECTION 0x0C
84 #define ACCEL25_REG_CONTROL 0x0D
85 #define ACCEL25_REG_DEVICE_ID 0x0E
86 #define ACCEL25_REG_WHO_AM_I 0x0F
87  // accel25_reg
89 
108 #define ACCEL25_INT_SRC0_CHORZ 0x80
109 #define ACCEL25_INT_SRC0_CHORXY 0x40
110 #define ACCEL25_INT_SRC0_SHYM 0x08
111 #define ACCEL25_INT_SRC0_SHYP 0x04
112 #define ACCEL25_INT_SRC0_SHXM 0x02
113 #define ACCEL25_INT_SRC0_SHXP 0x01
114 
119 #define ACCEL25_INT_CLR0_ORZC 0x80
120 #define ACCEL25_INT_CLR0_ORXYC 0x40
121 #define ACCEL25_INT_CLR0_SHYMC 0x08
122 #define ACCEL25_INT_CLR0_SHYPC 0x04
123 #define ACCEL25_INT_CLR0_SHXMC 0x02
124 #define ACCEL25_INT_CLR0_SHXPC 0x01
125 #define ACCEL25_INT_CLR0_ALL 0xCF
126 
131 #define ACCEL25_INT_SRC1_TILT 0x80
132 #define ACCEL25_INT_SRC1_ORZ 0x40
133 #define ACCEL25_INT_SRC1_ORXY_X_PLUS 0x00
134 #define ACCEL25_INT_SRC1_ORXY_Y_PLUS 0x10
135 #define ACCEL25_INT_SRC1_ORXY_X_MINUS 0x20
136 #define ACCEL25_INT_SRC1_ORXY_Y_MINUS 0x30
137 #define ACCEL25_INT_SRC1_ORXY_MASK 0x30
138 #define ACCEL25_INT_SRC1_DRDY 0x01
139 
144 #define ACCEL25_INT_CLR1_SW_RST 0x10
145 #define ACCEL25_INT_CLR1_DRDYC 0x01
146 
151 #define ACCEL25_STATUS_ORD 0x10
152 #define ACCEL25_STATUS_ORIZ_MSB 0x08
153 #define ACCEL25_STATUS_ORIZ_LSB 0x04
154 #define ACCEL25_STATUS_ORIXY_MSB 0x02
155 #define ACCEL25_STATUS_ORIXY_LSB 0x01
156 
161 #define ACCEL25_INT_MASK0_ORZE 0x80
162 #define ACCEL25_INT_MASK0_ORXYE 0x40
163 #define ACCEL25_INT_MASK0_SHYME 0x08
164 #define ACCEL25_INT_MASK0_SHYPE 0x04
165 #define ACCEL25_INT_MASK0_SHXME 0x02
166 #define ACCEL25_INT_MASK0_SHXPE 0x01
167 #define ACCEL25_INT_MASK0_NONE 0x00
168 #define ACCEL25_INT_MASK0_ALL 0xCF
169 
174 #define ACCEL25_INT_MASK1_DRDYE 0x01
175 
180 #define ACCEL25_DETECTION_SHM 0x80
181 #define ACCEL25_DETECTION_SHTH_0p25G 0x00
182 #define ACCEL25_DETECTION_SHTH_0p5G 0x10
183 #define ACCEL25_DETECTION_SHTH_0p75G 0x20
184 #define ACCEL25_DETECTION_SHTH_1G 0x30
185 #define ACCEL25_DETECTION_SHTH_1p25G 0x40
186 #define ACCEL25_DETECTION_SHTH_1p5G 0x50
187 #define ACCEL25_DETECTION_SHTH_1p75G 0x60
188 #define ACCEL25_DETECTION_SHTH_2G 0x70
189 #define ACCEL25_DETECTION_SHTH_MASK 0x70
190 #define ACCEL25_DETECTION_SHC_8 0x00
191 #define ACCEL25_DETECTION_SHC_16 0x04
192 #define ACCEL25_DETECTION_SHC_32 0x08
193 #define ACCEL25_DETECTION_SHC_64 0x0C
194 #define ACCEL25_DETECTION_SHC_MASK 0x0C
195 #define ACCEL25_DETECTION_ORC_16 0x00
196 #define ACCEL25_DETECTION_ORC_32 0x01
197 #define ACCEL25_DETECTION_ORC_64 0x02
198 #define ACCEL25_DETECTION_ORC_128 0x03
199 #define ACCEL25_DETECTION_ORC_MASK 0x03
200 #define ACCEL25_DETECTION_NONE 0x00
201 
206 #define ACCEL25_CONTROL_FSR_2G 0x00
207 #define ACCEL25_CONTROL_FSR_4G 0x20
208 #define ACCEL25_CONTROL_FSR_8G 0x40
209 #define ACCEL25_CONTROL_FSR_UNDEFINED 0x60
210 #define ACCEL25_CONTROL_FSR_MASK 0x60
211 #define ACCEL25_CONTROL_PD 0x01
212 
217 #define ACCEL25_ACCEL_RESOLUTION 2048.0f
218 #define ACCEL25_TEMP_SENSITIVITY 0.586f
219 #define ACCEL25_TEMP_NOMINAL 25.0f
220 
225 #define ACCEL25_FSR_2G 0
226 #define ACCEL25_FSR_4G 1
227 #define ACCEL25_FSR_8G 2
228 
233 #define ACCEL25_DEVICE_ID 0x02
234 
239 #define ACCEL25_PIN_STATE_LOW 0x00
240 #define ACCEL25_PIN_STATE_HIGH 0x01
241 
247 #define ACCEL25_DEVICE_ADDRESS 0x15
248  // accel25_set
250 
265 #define ACCEL25_MAP_MIKROBUS( cfg, mikrobus ) \
266  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
267  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
268  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
269  // accel25_map // accel25
272 
277 typedef struct
278 {
279  // Input pins
280  digital_in_t int_pin;
282  // Modules
283  i2c_master_t i2c;
285  // I2C slave address
286  uint8_t slave_address;
288  uint8_t fsr_sens;
290 } accel25_t;
291 
296 typedef struct
297 {
298  pin_name_t scl;
299  pin_name_t sda;
301  pin_name_t int_pin;
303  uint32_t i2c_speed;
304  uint8_t i2c_address;
306 } accel25_cfg_t;
307 
312 typedef struct
313 {
314  float x;
315  float y;
316  float z;
317  float temperature;
320 
325 typedef enum
326 {
328  ACCEL25_ERROR = -1
329 
331 
348 
362 err_t accel25_init ( accel25_t *ctx, accel25_cfg_t *cfg );
363 
377 
392 err_t accel25_generic_write ( accel25_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
393 
408 err_t accel25_generic_read ( accel25_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
409 
422 err_t accel25_write_register ( accel25_t *ctx, uint8_t reg, uint8_t data_in );
423 
436 err_t accel25_read_register ( accel25_t *ctx, uint8_t reg, uint8_t *data_out );
437 
449 
459 
471 
485 err_t accel25_set_full_scale_range ( accel25_t *ctx, uint8_t fsr );
486 
500 err_t accel25_read_data ( accel25_t *ctx, accel25_data_t *data_out );
501 
502 #ifdef __cplusplus
503 }
504 #endif
505 #endif // ACCEL25_H
506  // accel25
508 
509 // ------------------------------------------------------------------------ END
accel25_data_t::y
float y
Definition: accel25.h:315
accel25_set_full_scale_range
err_t accel25_set_full_scale_range(accel25_t *ctx, uint8_t fsr)
Accel 25 set full scale range function.
accel25_get_int_pin
uint8_t accel25_get_int_pin(accel25_t *ctx)
Accel 25 get int pin function.
accel25_generic_write
err_t accel25_generic_write(accel25_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Accel 25 I2C writing function.
accel25_write_register
err_t accel25_write_register(accel25_t *ctx, uint8_t reg, uint8_t data_in)
Accel 25 write register function.
accel25_data_t::z
float z
Definition: accel25.h:316
accel25_check_communication
err_t accel25_check_communication(accel25_t *ctx)
Accel 25 check communication function.
accel25_cfg_t::sda
pin_name_t sda
Definition: accel25.h:299
accel25_read_data
err_t accel25_read_data(accel25_t *ctx, accel25_data_t *data_out)
Accel 25 read data function.
accel25_cfg_t::i2c_address
uint8_t i2c_address
Definition: accel25.h:304
accel25_t::i2c
i2c_master_t i2c
Definition: accel25.h:283
accel25_t::int_pin
digital_in_t int_pin
Definition: accel25.h:280
accel25_read_register
err_t accel25_read_register(accel25_t *ctx, uint8_t reg, uint8_t *data_out)
Accel 25 read register function.
accel25_t::fsr_sens
uint8_t fsr_sens
Definition: accel25.h:288
accel25_data_t
Accel 25 Click data structure.
Definition: accel25.h:313
accel25_soft_reset
err_t accel25_soft_reset(accel25_t *ctx)
Accel 25 soft reset function.
accel25_cfg_t
Accel 25 Click configuration object.
Definition: accel25.h:297
accel25_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: accel25.h:303
accel25_return_value_t
accel25_return_value_t
Accel 25 Click return value data.
Definition: accel25.h:326
accel25_data_t::x
float x
Definition: accel25.h:314
ACCEL25_ERROR
@ ACCEL25_ERROR
Definition: accel25.h:328
accel25_generic_read
err_t accel25_generic_read(accel25_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Accel 25 I2C reading function.
accel25_data_t::temperature
float temperature
Definition: accel25.h:317
accel25_cfg_t::int_pin
pin_name_t int_pin
Definition: accel25.h:301
accel25_default_cfg
err_t accel25_default_cfg(accel25_t *ctx)
Accel 25 default configuration function.
accel25_cfg_t::scl
pin_name_t scl
Definition: accel25.h:298
accel25_init
err_t accel25_init(accel25_t *ctx, accel25_cfg_t *cfg)
Accel 25 initialization function.
accel25_t
Accel 25 Click context object.
Definition: accel25.h:278
accel25_cfg_setup
void accel25_cfg_setup(accel25_cfg_t *cfg)
Accel 25 configuration object setup function.
ACCEL25_OK
@ ACCEL25_OK
Definition: accel25.h:327
accel25_t::slave_address
uint8_t slave_address
Definition: accel25.h:286