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 
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_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
63 #define LSM303AGR_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
65  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
66  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
67 
73 #define LSM303AGR_RETVAL uint8_t
74 
75 #define LSM303AGR_OK 0x00
76 #define LSM303AGR_INIT_ERROR 0xFF
77  // End group macro
80 // --------------------------------------------------------------- PUBLIC TYPES
89 typedef struct
90 {
91  // Input pins
92 
93  digital_in_t int_pin;
94 
95  // Modules
96 
97  i2c_master_t i2c;
98 
99  // ctx variable
100 
101  uint8_t slave_address;
102 
103 } lsm303agr_t;
104 
108 typedef struct
109 {
110  // Communication gpio pins
111 
112  pin_name_t scl;
113  pin_name_t sda;
114 
115  // Additional gpio pins
116 
117  pin_name_t int_pin;
118 
119  // static variable
120 
121  uint32_t i2c_speed;
122  uint8_t i2c_address;
123 
125  // End types group
127 
128 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
129 
135 #ifdef __cplusplus
136 extern "C"{
137 #endif
138 
148 
157 
166 
167 
178 void lsm303agr_read_data ( lsm303agr_t* ctx, uint8_t reg_addr, uint8_t *read_buf, uint8_t read_len );
179 
191 void lsm303agr_write_data ( lsm303agr_t* ctx, uint8_t reg_addr, uint8_t *write_buf, uint8_t write_len );
192 
193 
203 
213 
224 
235 
246 
257 
270 
282 
283 #ifdef __cplusplus
284 }
285 #endif
286 #endif // _LSM303AGR_H_
287  // End public_function group
290 
291 // ------------------------------------------------------------------------- END
lsm303agr_accelerometer_init
void lsm303agr_accelerometer_init(lsm303agr_t *ctx)
Accelerometer init.
lsm303agr_t
Click ctx object definition.
Definition: lsm303agr.h:90
lsm303agr_get_mag_axis_y
float lsm303agr_get_mag_axis_y(lsm303agr_t *ctx)
Reading the raw Y axis data and calculating the value :
lsm303agr_write_data
void lsm303agr_write_data(lsm303agr_t *ctx, uint8_t reg_addr, uint8_t *write_buf, uint8_t write_len)
Generic write data function.
lsm303agr_get_mag_axis_x
float lsm303agr_get_mag_axis_x(lsm303agr_t *ctx)
Reading the raw X axis data and calculating the value :
lsm303agr_cfg_t::sda
pin_name_t sda
Definition: lsm303agr.h:113
lsm303agr_read_data
void lsm303agr_read_data(lsm303agr_t *ctx, uint8_t reg_addr, uint8_t *read_buf, uint8_t read_len)
Generic read data function.
lsm303agr_cfg_setup
void lsm303agr_cfg_setup(lsm303agr_cfg_t *cfg)
Config Object Initialization function.
lsm303agr_t::int_pin
digital_in_t int_pin
Definition: lsm303agr.h:93
LSM303AGR_RETVAL
#define LSM303AGR_RETVAL
Definition: lsm303agr.h:73
lsm303agr_magnetometer_init
void lsm303agr_magnetometer_init(lsm303agr_t *ctx)
Magnetometer init.
lsm303agr_get_mag_axis_z
float lsm303agr_get_mag_axis_z(lsm303agr_t *ctx)
Reading the raw Z axis data and calculating the value :
lsm303agr_init
LSM303AGR_RETVAL lsm303agr_init(lsm303agr_t *ctx, lsm303agr_cfg_t *cfg)
Initialization function.
lsm303agr_cfg_t
Click configuration structure definition.
Definition: lsm303agr.h:109
lsm303agr_t::i2c
i2c_master_t i2c
Definition: lsm303agr.h:97
lsm303agr_cfg_t::int_pin
pin_name_t int_pin
Definition: lsm303agr.h:117
lsm303agr_get_acc_axis_z
float lsm303agr_get_acc_axis_z(lsm303agr_t *ctx)
Reading the raw Z axis data and calculating the value :
lsm303agr_cfg_t::scl
pin_name_t scl
Definition: lsm303agr.h:112
lsm303agr_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: lsm303agr.h:121
lsm303agr_get_acc_axis_y
float lsm303agr_get_acc_axis_y(lsm303agr_t *ctx)
Reading the raw Y axis data and calculating the value :
lsm303agr_get_acc_axis_x
float lsm303agr_get_acc_axis_x(lsm303agr_t *ctx)
Reading the raw X axis data and calculating the value :
lsm303agr_t::slave_address
uint8_t slave_address
Definition: lsm303agr.h:101
lsm303agr_cfg_t::i2c_address
uint8_t i2c_address
Definition: lsm303agr.h:122
lsm303agr_default_cfg
void lsm303agr_default_cfg(lsm303agr_t *ctx)
Click Default Configuration function.