mma7660.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 University of California, Berkeley
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
23 #ifndef MMA7660_H
24 #define MMA7660_H
25 
26 #include <stdint.h>
27 #include <stdbool.h>
28 #include "periph/i2c.h"
29 
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #endif
34 
38 enum {
44 };
45 
49 typedef struct
50 {
52  uint8_t addr;
53  uint8_t amsr;
54  uint8_t awsr;
55  uint8_t filt;
57 
61 typedef struct
62 {
64 } mma7660_t;
65 
69 typedef struct {
70  int16_t x;
71  int16_t y;
72  int16_t z;
74 
79 #define MODE_ACTIVE_SHIFT (0U)
80 #define MODE_AUTOWAKE_SHIFT (3U)
81 #define MODE_AUTOSLEEP_SHIFT (4U)
82 #define MODE_PRESCALE_SHIFT (5U)
83 #define MODE_INTERRUPT_DEFAULT (0x40) /* Active low, push-pull */
84 
85 #define MMA7660_INTSOURCE_NONE (0x00)
86 #define MMA7660_INTSOURCE_FB (0x01)
87 #define MMA7660_INTSOURCE_UDLR (0x02)
88 #define MMA7660_INTSOURCE_TAP (0x04)
89 #define MMA7660_INTSOURCE_AUTOSLEEP (0x08)
90 #define MMA7660_INTSOURCE_MEASURE (0x10)
91 #define MMA7660_INTSOURCE_SHX (0x20)
92 #define MMA7660_INTSOURCE_SHY (0x40)
93 #define MMA7660_INTSOURCE_SHZ (0x80)
94 
95 #define MMA7660_SR_AMPD (0x00)
96 #define MMA7660_SR_AM64 (0x01)
97 #define MMA7660_SR_AM32 (0x02)
98 #define MMA7660_SR_AM16 (0x03)
99 #define MMA7660_SR_AM8 (0x04)
100 #define MMA7660_SR_AM4 (0x05)
101 #define MMA7660_SR_AM2 (0x06)
102 #define MMA7660_SR_AM1 (0x07)
103 #define MMA7660_SR_AW32 (0x00)
104 #define MMA7660_SR_AW16 (0x08)
105 #define MMA7660_SR_AW8 (0x10)
106 #define MMA7660_SR_AW1 (0x18)
107 #define MMA7660_PDET_X (0x20)
108 #define MMA7660_PDET_Y (0x40)
109 #define MMA7660_PDET_Z (0x80)
110 
111 #define MMA7660_ADDR (0x4C)
112 
113 /* This is actually 46.9 but the sensor is not accurate enough
114  * for that to matter
115  */
116 #define MMA7660_MG_PER_COUNT (47U)
117 
129 int mma7660_init(mma7660_t *dev, const mma7660_params_t *params);
130 
131 
147 int mma7660_set_mode(const mma7660_t *dev, uint8_t active,
148  uint8_t autowake, uint8_t autosleep, uint8_t prescale);
149 
159 int mma7660_read_tilt(const mma7660_t *dev, uint8_t *res);
160 
170 int mma7660_write_sleep_count(const mma7660_t *dev, uint8_t sleep);
171 
181 int mma7660_config_interrupts(const mma7660_t *dev, uint8_t isource_flags);
182 
197 int mma7660_config_samplerate(const mma7660_t *dev, uint8_t amsr, uint8_t awsr, uint8_t filt);
198 
212 int mma7660_config_pdet(const mma7660_t *dev, uint8_t pdth, uint8_t enabled_axes);
213 
226 int mma7660_config_pd(const mma7660_t *dev, uint8_t pd) ;
227 
237 int mma7660_read(const mma7660_t *dev, mma7660_data_t *data);
238 
254 int mma7660_read_counts(const mma7660_t *dev, int8_t *x, int8_t *y, int8_t *z);
255 
256 #ifdef __cplusplus
257 }
258 #endif
259 
260 #endif /* MMA7660_H */
261 
mma7660_params_t::addr
uint8_t addr
the device I2C address
Definition: mma7660.h:52
mma7660_t
Device descriptor for an MMA7660 device.
Definition: mma7660.h:61
mma7660_set_mode
int mma7660_set_mode(const mma7660_t *dev, uint8_t active, uint8_t autowake, uint8_t autosleep, uint8_t prescale)
Set the mode register.
mma7660_data_t::x
int16_t x
acceleration in X direction
Definition: mma7660.h:70
mma7660_config_interrupts
int mma7660_config_interrupts(const mma7660_t *dev, uint8_t isource_flags)
Configure the interrupt sources.
mma7660_read_counts
int mma7660_read_counts(const mma7660_t *dev, int8_t *x, int8_t *y, int8_t *z)
Read the acceleration counts (unconverted)
mma7660_write_sleep_count
int mma7660_write_sleep_count(const mma7660_t *dev, uint8_t sleep)
Write the sleep count register.
i2c_t
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:151
mma7660_params_t::filt
uint8_t filt
filter samples
Definition: mma7660.h:55
mma7660_config_samplerate
int mma7660_config_samplerate(const mma7660_t *dev, uint8_t amsr, uint8_t awsr, uint8_t filt)
Configure the sample rate.
mma7660_config_pdet
int mma7660_config_pdet(const mma7660_t *dev, uint8_t pdth, uint8_t enabled_axes)
Configure the tap detection.
mma7660_params_t::awsr
uint8_t awsr
auto wake sample rate
Definition: mma7660.h:54
mma7660_data_t::z
int16_t z
acceleration in Z direction
Definition: mma7660.h:72
MMA7660_I2C_READ_ERR
@ MMA7660_I2C_READ_ERR
i2c bus cannot be read
Definition: mma7660.h:41
mma7660_config_pd
int mma7660_config_pd(const mma7660_t *dev, uint8_t pd)
Configure the tap detection debounce count.
mma7660_read_tilt
int mma7660_read_tilt(const mma7660_t *dev, uint8_t *res)
Read the tilt register.
mma7660_t::params
mma7660_params_t params
initialization parameters
Definition: mma7660.h:63
mma7660_data_t
Data type for the result data.
Definition: mma7660.h:69
mma7660_params_t::amsr
uint8_t amsr
active mode sample rate
Definition: mma7660.h:53
MMA7660_OK
@ MMA7660_OK
all ok
Definition: mma7660.h:39
mma7660_data_t::y
int16_t y
acceleration in Y direction
Definition: mma7660.h:71
mma7660_params_t
Parameters for an MMA7660 device.
Definition: mma7660.h:49
MMA7660_I2C_WRITE_ERR
@ MMA7660_I2C_WRITE_ERR
i2c bus cannot be written
Definition: mma7660.h:42
MMA7660_I2C_ERR
@ MMA7660_I2C_ERR
i2c bus initialization error
Definition: mma7660.h:40
MMA7660_READ_ERR
@ MMA7660_READ_ERR
error when reading counts
Definition: mma7660.h:43
mma7660_init
int mma7660_init(mma7660_t *dev, const mma7660_params_t *params)
Initialize an MMA7660 device.
mma7660_read
int mma7660_read(const mma7660_t *dev, mma7660_data_t *data)
Read the acceleration counts converted to mG.
mma7660_params_t::i2c
i2c_t i2c
the I2C handle
Definition: mma7660.h:51
i2c.h
Low-level I2C peripheral driver interface definition.