upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
mma7660.h
Go to the documentation of this file.
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2016 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * 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
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 #pragma once
25 
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <upm.h>
29 
30 #include <mraa/i2c.h>
31 #include <mraa/gpio.h>
32 
33 #include "mma7660_regs.h"
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
50  typedef struct _mma7660_context {
51  mraa_i2c_context i2c;
52  mraa_gpio_context gpio;
53 
54  bool isrInstalled;
55  } *mma7660_context;
56 
63  mma7660_context mma7660_init(int bus, uint8_t address);
64 
71 
80  upm_result_t mma7660_write_byte(const mma7660_context dev,
81  uint8_t reg, uint8_t byte);
82 
91  upm_result_t mma7660_read_byte(const mma7660_context dev, uint8_t reg,
92  uint8_t *byte);
93 
103  upm_result_t mma7660_get_raw_values(const mma7660_context dev,
104  int *x, int *y, int *z);
105 
115  upm_result_t mma7660_get_acceleration(const mma7660_context dev,
116  float *ax, float *ay, float *az);
117 
127  upm_result_t mma7660_get_verified_axis(const mma7660_context dev,
128  MMA7660_REG_T axis, int *val);
129 
137  upm_result_t mma7660_get_verified_tilt(const mma7660_context dev,
138  uint8_t *val);
139 
148  upm_result_t mma7660_set_mode_active(const mma7660_context dev);
149 
159  upm_result_t mma7660_set_mode_standby(const mma7660_context dev);
160 
171  upm_result_t mma7660_tilt_back_front(const mma7660_context dev,
172  uint8_t *bits);
173 
184  upm_result_t mma7660_tilt_landscape_portrait(const mma7660_context dev,
185  uint8_t *bits);
186 
194  upm_result_t mma7660_tilt_tap(const mma7660_context dev, bool *tap);
195 
203  upm_result_t mma7660_tilt_shake(const mma7660_context dev, bool *shake);
204 
216  upm_result_t mma7660_install_isr(const mma7660_context dev, int pin,
217  void (*isr)(void *), void *arg);
218 
224  void mma7660_uninstall_isr(const mma7660_context dev);
225 
235  upm_result_t mma7660_set_interrupt_bits(const mma7660_context dev,
236  uint8_t ibits);
237 
246  upm_result_t mma7660_set_sample_rate(const mma7660_context dev,
247  MMA7660_AUTOSLEEP_T sr);
248 
249 #ifdef __cplusplus
250 }
251 #endif
upm_result_t mma7660_set_interrupt_bits(const mma7660_context dev, uint8_t ibits)
Definition: mma7660.c:329
upm_result_t mma7660_install_isr(const mma7660_context dev, int pin, void(*isr)(void *), void *arg)
Definition: mma7660.c:293
upm_result_t mma7660_write_byte(const mma7660_context dev, uint8_t reg, uint8_t byte)
Definition: mma7660.c:85
upm_result_t mma7660_read_byte(const mma7660_context dev, uint8_t reg, uint8_t *byte)
Definition: mma7660.c:99
upm_result_t mma7660_tilt_tap(const mma7660_context dev, bool *tap)
Definition: mma7660.c:261
upm_result_t mma7660_set_mode_standby(const mma7660_context dev)
Definition: mma7660.c:163
upm_result_t mma7660_get_verified_axis(const mma7660_context dev, MMA7660_REG_T axis, int *val)
Definition: mma7660.c:180
upm_result_t mma7660_set_sample_rate(const mma7660_context dev, MMA7660_AUTOSLEEP_T sr)
Definition: mma7660.c:337
upm_result_t mma7660_set_mode_active(const mma7660_context dev)
Definition: mma7660.c:147
mma7660_context mma7660_init(int bus, uint8_t address)
Definition: mma7660.c:29
upm_result_t mma7660_get_acceleration(const mma7660_context dev, float *ax, float *ay, float *az)
Definition: mma7660.c:345
struct _mma7660_context * mma7660_context
upm_result_t mma7660_get_raw_values(const mma7660_context dev, int *x, int *y, int *z)
Definition: mma7660.c:122
upm_result_t mma7660_tilt_back_front(const mma7660_context dev, uint8_t *bits)
Definition: mma7660.c:232
upm_result_t mma7660_tilt_shake(const mma7660_context dev, bool *shake)
Definition: mma7660.c:277
void mma7660_uninstall_isr(const mma7660_context dev)
Definition: mma7660.c:316
upm_result_t mma7660_get_verified_tilt(const mma7660_context dev, uint8_t *val)
Definition: mma7660.c:213
upm_result_t mma7660_tilt_landscape_portrait(const mma7660_context dev, uint8_t *bits)
Definition: mma7660.c:246
void mma7660_close(mma7660_context dev)
Definition: mma7660.c:70
Definition: mma7660.h:50