mma8x5x.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 PHYTEC Messtechnik GmbH
3  * 2016 Freie Universität Berlin
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser
6  * General Public License v2.1. See the file LICENSE in the top level
7  * directory for more details.
8  */
9 
33 #ifndef MMA8X5X_H
34 #define MMA8X5X_H
35 
36 #include <stdint.h>
37 #include "periph/i2c.h"
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
54 #ifndef CONFIG_MMA8X5X_I2C_ADDRESS
55 #define CONFIG_MMA8X5X_I2C_ADDRESS 0x1D
56 #endif
57 
62 enum {
68 };
69 
73 enum {
74  MMA8X5X_RATE_800HZ = (0 << 3),
75  MMA8X5X_RATE_400HZ = (1 << 3),
76  MMA8X5X_RATE_200HZ = (2 << 3),
77  MMA8X5X_RATE_100HZ = (3 << 3),
78  MMA8X5X_RATE_50HZ = (4 << 3),
79  MMA8X5X_RATE_1HZ25 = (5 << 3),
80  MMA8X5X_RATE_6HZ25 = (6 << 3),
81  MMA8X5X_RATE_1HZ56 = (7 << 3)
82 };
83 
87 enum {
91 };
92 
96 enum {
97  MMA8X5X_OK = 0,
102 };
103 
107 typedef struct {
109  uint8_t addr;
110  uint8_t rate;
111  uint8_t range;
112  uint8_t offset[3];
114 
118 typedef struct {
120 } mma8x5x_t;
121 
125 typedef struct {
126  int16_t x;
127  int16_t y;
128  int16_t z;
130 
141 int mma8x5x_init(mma8x5x_t *dev, const mma8x5x_params_t *params);
142 
153 void mma8x5x_set_user_offset(const mma8x5x_t *dev, int8_t x, int8_t y, int8_t z);
154 
160 void mma8x5x_set_active(const mma8x5x_t *dev);
161 
167 void mma8x5x_set_standby(const mma8x5x_t *dev);
168 
177 int mma8x5x_is_ready(const mma8x5x_t *dev);
178 
193 void mma8x5x_read(const mma8x5x_t *dev, mma8x5x_data_t *data);
194 
206 void mma8x5x_set_motiondetect(const mma8x5x_t *dev, uint8_t int_pin, uint8_t threshold);
207 
219 void mma8x5x_ack_int(const mma8x5x_t *dev);
220 
221 #ifdef __cplusplus
222 }
223 #endif
224 
225 #endif /* MMA8X5X_H */
226 
MMA8X5X_RATE_400HZ
@ MMA8X5X_RATE_400HZ
400 Hz Output Data Rate in WAKE mode
Definition: mma8x5x.h:75
MMA8X5X_TYPE_MMA8451
@ MMA8X5X_TYPE_MMA8451
MMA8451.
Definition: mma8x5x.h:65
MMA8X5X_RATE_100HZ
@ MMA8X5X_RATE_100HZ
100 Hz Output Data Rate in WAKE mode
Definition: mma8x5x.h:77
mma8x5x_params_t::i2c
i2c_t i2c
I2C bus the device is connected to.
Definition: mma8x5x.h:108
mma8x5x_params_t
Configuration parameters.
Definition: mma8x5x.h:107
mma8x5x_read
void mma8x5x_read(const mma8x5x_t *dev, mma8x5x_data_t *data)
Read accelerometer's data.
mma8x5x_is_ready
int mma8x5x_is_ready(const mma8x5x_t *dev)
Check for new set of measurement data.
mma8x5x_data_t::y
int16_t y
acceleration in Y direction
Definition: mma8x5x.h:127
MMA8X5X_RANGE_4G
@ MMA8X5X_RANGE_4G
+/- 4 g Full Scale Range
Definition: mma8x5x.h:89
mma8x5x_t
Device descriptor for MMA8x5x accelerometers.
Definition: mma8x5x.h:118
mma8x5x_set_user_offset
void mma8x5x_set_user_offset(const mma8x5x_t *dev, int8_t x, int8_t y, int8_t z)
Set user offset correction.
MMA8X5X_TYPE_MMA8652
@ MMA8X5X_TYPE_MMA8652
MMA8652.
Definition: mma8x5x.h:63
mma8x5x_t::params
mma8x5x_params_t params
device configuration parameters
Definition: mma8x5x.h:119
i2c_t
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:151
MMA8X5X_RANGE_2G
@ MMA8X5X_RANGE_2G
+/- 2 g Full Scale Range
Definition: mma8x5x.h:88
mma8x5x_set_active
void mma8x5x_set_active(const mma8x5x_t *dev)
Set active mode, this enables periodic measurements.
MMA8X5X_RATE_1HZ25
@ MMA8X5X_RATE_1HZ25
12.5 Hz Output Data Rate in WAKE mode
Definition: mma8x5x.h:79
mma8x5x_ack_int
void mma8x5x_ack_int(const mma8x5x_t *dev)
Acknowledge motion detection interrupt.
MMA8X5X_NOI2C
@ MMA8X5X_NOI2C
I2C communication failed.
Definition: mma8x5x.h:99
MMA8X5X_RATE_1HZ56
@ MMA8X5X_RATE_1HZ56
1.56 Hz Output Data Rate in WAKE mode
Definition: mma8x5x.h:81
mma8x5x_data_t::x
int16_t x
acceleration in X direction
Definition: mma8x5x.h:126
mma8x5x_data_t::z
int16_t z
acceleration in Z direction
Definition: mma8x5x.h:128
mma8x5x_params_t::range
uint8_t range
scale range to use
Definition: mma8x5x.h:111
MMA8X5X_DATA_READY
@ MMA8X5X_DATA_READY
new data ready to be read
Definition: mma8x5x.h:98
MMA8X5X_TYPE_MMA8452
@ MMA8X5X_TYPE_MMA8452
MMA8452.
Definition: mma8x5x.h:66
MMA8X5X_NODEV
@ MMA8X5X_NODEV
no MMA8X5X device found on the bus
Definition: mma8x5x.h:100
mma8x5x_params_t::addr
uint8_t addr
I2C bus address of the device.
Definition: mma8x5x.h:109
MMA8X5X_TYPE_MMA8653
@ MMA8X5X_TYPE_MMA8653
MMA8653.
Definition: mma8x5x.h:64
MMA8X5X_RATE_800HZ
@ MMA8X5X_RATE_800HZ
800 Hz Output Data Rate in WAKE mode
Definition: mma8x5x.h:74
MMA8X5X_TYPE_MMA8453
@ MMA8X5X_TYPE_MMA8453
MMA8453.
Definition: mma8x5x.h:67
mma8x5x_data_t
Data type for the result data.
Definition: mma8x5x.h:125
mma8x5x_set_motiondetect
void mma8x5x_set_motiondetect(const mma8x5x_t *dev, uint8_t int_pin, uint8_t threshold)
Configure motion detection interrupt.
MMA8X5X_NODATA
@ MMA8X5X_NODATA
no data available
Definition: mma8x5x.h:101
MMA8X5X_RATE_200HZ
@ MMA8X5X_RATE_200HZ
200 Hz Output Data Rate in WAKE mode
Definition: mma8x5x.h:76
mma8x5x_init
int mma8x5x_init(mma8x5x_t *dev, const mma8x5x_params_t *params)
Initialize the MMA8x5x accelerometer driver.
MMA8X5X_RANGE_8G
@ MMA8X5X_RANGE_8G
+/- 8 g Full Scale Range
Definition: mma8x5x.h:90
mma8x5x_set_standby
void mma8x5x_set_standby(const mma8x5x_t *dev)
Set standby mode.
i2c.h
Low-level I2C peripheral driver interface definition.
mma8x5x_params_t::rate
uint8_t rate
sampling rate to use
Definition: mma8x5x.h:110
MMA8X5X_RATE_50HZ
@ MMA8X5X_RATE_50HZ
50 Hz Output Data Rate in WAKE mode
Definition: mma8x5x.h:78
MMA8X5X_OK
@ MMA8X5X_OK
everything was fine
Definition: mma8x5x.h:97
MMA8X5X_RATE_6HZ25
@ MMA8X5X_RATE_6HZ25
6.25 Hz Output Data Rate in WAKE mode
Definition: mma8x5x.h:80