Loading...
Searching...
No Matches
mma7660.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2016 University of California, Berkeley
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
21
22#include <stdint.h>
23#include <stdbool.h>
24#include "periph/i2c.h"
25
26#ifdef __cplusplus
27extern "C"
28{
29#endif
30
34enum {
40};
41
45typedef struct
46{
48 uint8_t addr;
49 uint8_t amsr;
50 uint8_t awsr;
51 uint8_t filt;
53
57typedef struct
58{
60} mma7660_t;
61
65typedef struct {
66 int16_t x;
67 int16_t y;
68 int16_t z;
70
75#define MODE_ACTIVE_SHIFT (0U)
76#define MODE_AUTOWAKE_SHIFT (3U)
77#define MODE_AUTOSLEEP_SHIFT (4U)
78#define MODE_PRESCALE_SHIFT (5U)
79#define MODE_INTERRUPT_DEFAULT (0x40) /* Active low, push-pull */
80
81#define MMA7660_INTSOURCE_NONE (0x00)
82#define MMA7660_INTSOURCE_FB (0x01)
83#define MMA7660_INTSOURCE_UDLR (0x02)
84#define MMA7660_INTSOURCE_TAP (0x04)
85#define MMA7660_INTSOURCE_AUTOSLEEP (0x08)
86#define MMA7660_INTSOURCE_MEASURE (0x10)
87#define MMA7660_INTSOURCE_SHX (0x20)
88#define MMA7660_INTSOURCE_SHY (0x40)
89#define MMA7660_INTSOURCE_SHZ (0x80)
90
91#define MMA7660_SR_AMPD (0x00)
92#define MMA7660_SR_AM64 (0x01)
93#define MMA7660_SR_AM32 (0x02)
94#define MMA7660_SR_AM16 (0x03)
95#define MMA7660_SR_AM8 (0x04)
96#define MMA7660_SR_AM4 (0x05)
97#define MMA7660_SR_AM2 (0x06)
98#define MMA7660_SR_AM1 (0x07)
99#define MMA7660_SR_AW32 (0x00)
100#define MMA7660_SR_AW16 (0x08)
101#define MMA7660_SR_AW8 (0x10)
102#define MMA7660_SR_AW1 (0x18)
103#define MMA7660_PDET_X (0x20)
104#define MMA7660_PDET_Y (0x40)
105#define MMA7660_PDET_Z (0x80)
106
107#define MMA7660_ADDR (0x4C)
108
109/* This is actually 46.9 but the sensor is not accurate enough
110 * for that to matter
111 */
112#define MMA7660_MG_PER_COUNT (47U)
114
125int mma7660_init(mma7660_t *dev, const mma7660_params_t *params);
126
142int mma7660_set_mode(const mma7660_t *dev, uint8_t active,
143 uint8_t autowake, uint8_t autosleep, uint8_t prescale);
144
154int mma7660_read_tilt(const mma7660_t *dev, uint8_t *res);
155
165int mma7660_write_sleep_count(const mma7660_t *dev, uint8_t sleep);
166
176int mma7660_config_interrupts(const mma7660_t *dev, uint8_t isource_flags);
177
192int mma7660_config_samplerate(const mma7660_t *dev, uint8_t amsr, uint8_t awsr, uint8_t filt);
193
207int mma7660_config_pdet(const mma7660_t *dev, uint8_t pdth, uint8_t enabled_axes);
208
221int mma7660_config_pd(const mma7660_t *dev, uint8_t pd) ;
222
232int mma7660_read(const mma7660_t *dev, mma7660_data_t *data);
233
249int mma7660_read_counts(const mma7660_t *dev, int8_t *x, int8_t *y, int8_t *z);
250
251#ifdef __cplusplus
252}
253#endif
254
int mma7660_read_tilt(const mma7660_t *dev, uint8_t *res)
Read the tilt register.
int mma7660_config_samplerate(const mma7660_t *dev, uint8_t amsr, uint8_t awsr, uint8_t filt)
Configure the sample rate.
int mma7660_set_mode(const mma7660_t *dev, uint8_t active, uint8_t autowake, uint8_t autosleep, uint8_t prescale)
Set the mode register.
int mma7660_read_counts(const mma7660_t *dev, int8_t *x, int8_t *y, int8_t *z)
Read the acceleration counts (unconverted)
int mma7660_init(mma7660_t *dev, const mma7660_params_t *params)
Initialize an MMA7660 device.
int mma7660_read(const mma7660_t *dev, mma7660_data_t *data)
Read the acceleration counts converted to mG.
int mma7660_write_sleep_count(const mma7660_t *dev, uint8_t sleep)
Write the sleep count register.
int mma7660_config_pd(const mma7660_t *dev, uint8_t pd)
Configure the tap detection debounce count.
int mma7660_config_pdet(const mma7660_t *dev, uint8_t pdth, uint8_t enabled_axes)
Configure the tap detection.
int mma7660_config_interrupts(const mma7660_t *dev, uint8_t isource_flags)
Configure the interrupt sources.
@ MMA7660_READ_ERR
error when reading counts
Definition mma7660.h:39
@ MMA7660_OK
all ok
Definition mma7660.h:35
@ MMA7660_I2C_WRITE_ERR
i2c bus cannot be written
Definition mma7660.h:38
@ MMA7660_I2C_ERR
i2c bus initialization error
Definition mma7660.h:36
@ MMA7660_I2C_READ_ERR
i2c bus cannot be read
Definition mma7660.h:37
uint_fast8_t i2c_t
Default i2c_t type definition.
Definition i2c.h:155
Low-level I2C peripheral driver interface definition.
Data type for the result data.
Definition mma7660.h:65
int16_t x
acceleration in X direction
Definition mma7660.h:66
int16_t y
acceleration in Y direction
Definition mma7660.h:67
int16_t z
acceleration in Z direction
Definition mma7660.h:68
Parameters for an MMA7660 device.
Definition mma7660.h:46
i2c_t i2c
the I2C handle
Definition mma7660.h:47
uint8_t amsr
active mode sample rate
Definition mma7660.h:49
uint8_t addr
the device I2C address
Definition mma7660.h:48
uint8_t awsr
auto wake sample rate
Definition mma7660.h:50
uint8_t filt
filter samples
Definition mma7660.h:51
Device descriptor for an MMA7660 device.
Definition mma7660.h:58
mma7660_params_t params
initialization parameters
Definition mma7660.h:59