lsm303agr 2.0.0.0
lsm303agr.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 LSM303AGR_H
36#define LSM303AGR_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_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55
56
57// -------------------------------------------------------------- PUBLIC MACROS
67#define LSM303AGR_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
69 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
70 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
77#define LSM303AGR_RETVAL uint8_t
78
79#define LSM303AGR_OK 0x00
80#define LSM303AGR_INIT_ERROR 0xFF
83 // End group macro
84// --------------------------------------------------------------- PUBLIC TYPES
93typedef struct
94{
95 // Input pins
96
97 digital_in_t int_pin;
98
99 // Modules
100
101 i2c_master_t i2c;
102
103 // ctx variable
104
106
108
112typedef struct
113{
114 // Communication gpio pins
115
116 pin_name_t scl;
117 pin_name_t sda;
118
119 // Additional gpio pins
120
121 pin_name_t int_pin;
122
123 // static variable
124
125 uint32_t i2c_speed;
126 uint8_t i2c_address;
127
129
130 // End types group
131
132// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
133
139#ifdef __cplusplus
140extern "C"{
141#endif
142
152
161
170
171
182void lsm303agr_read_data ( lsm303agr_t* ctx, uint8_t reg_addr, uint8_t *read_buf, uint8_t read_len );
183
195void lsm303agr_write_data ( lsm303agr_t* ctx, uint8_t reg_addr, uint8_t *write_buf, uint8_t write_len );
196
197
207
217
228
239
250
261
274
286
287#ifdef __cplusplus
288}
289#endif
290#endif // _LSM303AGR_H_
291
292 // End public_function group
294
295// ------------------------------------------------------------------------- END
#define LSM303AGR_RETVAL
Definition lsm303agr.h:77
void lsm303agr_default_cfg(lsm303agr_t *ctx)
Click Default Configuration function.
float lsm303agr_get_acc_axis_x(lsm303agr_t *ctx)
Reading the raw X axis data and calculating the value :
float lsm303agr_get_mag_axis_x(lsm303agr_t *ctx)
Reading the raw X axis data and calculating the value :
void lsm303agr_read_data(lsm303agr_t *ctx, uint8_t reg_addr, uint8_t *read_buf, uint8_t read_len)
Generic read data function.
float lsm303agr_get_mag_axis_y(lsm303agr_t *ctx)
Reading the raw Y axis data and calculating the value :
void lsm303agr_cfg_setup(lsm303agr_cfg_t *cfg)
Config Object Initialization function.
void lsm303agr_accelerometer_init(lsm303agr_t *ctx)
Accelerometer init.
float lsm303agr_get_acc_axis_z(lsm303agr_t *ctx)
Reading the raw Z axis data and calculating the value :
LSM303AGR_RETVAL lsm303agr_init(lsm303agr_t *ctx, lsm303agr_cfg_t *cfg)
Initialization function.
void lsm303agr_magnetometer_init(lsm303agr_t *ctx)
Magnetometer init.
void lsm303agr_write_data(lsm303agr_t *ctx, uint8_t reg_addr, uint8_t *write_buf, uint8_t write_len)
Generic write data function.
float lsm303agr_get_mag_axis_z(lsm303agr_t *ctx)
Reading the raw Z axis data and calculating the value :
float lsm303agr_get_acc_axis_y(lsm303agr_t *ctx)
Reading the raw Y axis data and calculating the value :
Click configuration structure definition.
Definition lsm303agr.h:113
uint32_t i2c_speed
Definition lsm303agr.h:125
pin_name_t scl
Definition lsm303agr.h:116
pin_name_t int_pin
Definition lsm303agr.h:121
pin_name_t sda
Definition lsm303agr.h:117
uint8_t i2c_address
Definition lsm303agr.h:126
Click ctx object definition.
Definition lsm303agr.h:94
digital_in_t int_pin
Definition lsm303agr.h:97
i2c_master_t i2c
Definition lsm303agr.h:101
uint8_t slave_address
Definition lsm303agr.h:105