upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Data Structures | Functions | Typedefs
Include dependency graph for mma7660.h:

API Description

/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include "upm_utilities.h"
#include "mma7660.h"
int shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main(int argc, char **argv)
{
signal(SIGINT, sig_handler);
// Instantiate an MMA7660 on I2C bus 0
mma7660_context accel = mma7660_init(MMA7660_DEFAULT_I2C_BUS,
MMA7660_DEFAULT_I2C_ADDR);
if (!accel)
{
printf("mma7660_init() failed\n");
return 1;
}
// place device in standby mode so we can write registers
// enable 64 samples per second
mma7660_set_sample_rate(accel, MMA7660_AUTOSLEEP_64);
// place device into active mode
while (shouldRun)
{
float ax, ay, az;
mma7660_get_acceleration(accel, &ax, &ay, &az);
printf("Acceleration: x = %f y = %f z = %f\n\n",
ax, ay, az);
upm_delay_ms(500);
}
printf("Exiting...\n");
mma7660_close(accel);
return 0;
}

Go to the source code of this file.

Data Structures

struct  _mma7660_context
 

Functions

mma7660_context mma7660_init (int bus, uint8_t address)
 
void mma7660_close (mma7660_context dev)
 
upm_result_t mma7660_write_byte (const mma7660_context dev, uint8_t reg, uint8_t byte)
 
upm_result_t mma7660_read_byte (const mma7660_context dev, uint8_t reg, uint8_t *byte)
 
upm_result_t mma7660_get_raw_values (const mma7660_context dev, int *x, int *y, int *z)
 
upm_result_t mma7660_get_acceleration (const mma7660_context dev, float *ax, float *ay, float *az)
 
upm_result_t mma7660_get_verified_axis (const mma7660_context dev, MMA7660_REG_T axis, int *val)
 
upm_result_t mma7660_get_verified_tilt (const mma7660_context dev, uint8_t *val)
 
upm_result_t mma7660_set_mode_active (const mma7660_context dev)
 
upm_result_t mma7660_set_mode_standby (const mma7660_context dev)
 
upm_result_t mma7660_tilt_back_front (const mma7660_context dev, uint8_t *bits)
 
upm_result_t mma7660_tilt_landscape_portrait (const mma7660_context dev, uint8_t *bits)
 
upm_result_t mma7660_tilt_tap (const mma7660_context dev, bool *tap)
 
upm_result_t mma7660_tilt_shake (const mma7660_context dev, bool *shake)
 
upm_result_t mma7660_install_isr (const mma7660_context dev, int pin, void(*isr)(void *), void *arg)
 
void mma7660_uninstall_isr (const mma7660_context dev)
 
upm_result_t mma7660_set_interrupt_bits (const mma7660_context dev, uint8_t ibits)
 
upm_result_t mma7660_set_sample_rate (const mma7660_context dev, MMA7660_AUTOSLEEP_T sr)
 

Typedefs

typedef struct _mma7660_contextmma7660_context
 

Function Documentation

mma7660_context mma7660_init ( int  bus,
uint8_t  address 
)

MMA7660 initialization.

Parameters
busI2C bus to use
addressAddress for this sensor

Here is the call graph for this function:

void mma7660_close ( mma7660_context  dev)

MMA7660 destructor

Parameters
devDevice context.

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t mma7660_write_byte ( const mma7660_context  dev,
uint8_t  reg,
uint8_t  byte 
)

Writes a byte value into a register

Parameters
devDevice context.
regRegister location to write into
byteByte to write
Returns
UPM result

Here is the caller graph for this function:

upm_result_t mma7660_read_byte ( const mma7660_context  dev,
uint8_t  reg,
uint8_t *  byte 
)

Reads a byte value from a register

Parameters
devDevice context.
regRegister location to read from
byteA pointer to hold the value that was read
Returns
UPM result

Here is the caller graph for this function:

upm_result_t mma7660_get_raw_values ( const mma7660_context  dev,
int *  x,
int *  y,
int *  z 
)

Reads the current value of conversion

Parameters
devDevice context.
xReturned x value
yReturned y value
zReturned z value
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t mma7660_get_acceleration ( const mma7660_context  dev,
float *  ax,
float *  ay,
float *  az 
)

Gets the computed acceleration

Parameters
devDevice context.
axReturned computed acceleration of the X-axis
ayReturned computed acceleration of the Y-axis
azReturned computed acceleration of the Z-axis
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t mma7660_get_verified_axis ( const mma7660_context  dev,
MMA7660_REG_T  axis,
int *  val 
)

Reads an axis, verifying its validity. The value passed must be one of MMA7660_REG_XOUT, MMA7660_REG_YOUT, or MMA7660_REG_ZOUT.

Parameters
devDevice context.
axisAxis to read
valpointer containing returned value
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t mma7660_get_verified_tilt ( const mma7660_context  dev,
uint8_t *  val 
)

Reads the tilt register, verifying its validity

Parameters
devDevice context.
valPointer to returned value
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t mma7660_set_mode_active ( const mma7660_context  dev)

Puts the device in the active mode. In this mode, register writes are not allowed. Place the device in the standby mode before attempting to write registers.

Parameters
devDevice context.
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t mma7660_set_mode_standby ( const mma7660_context  dev)

Puts the device in the standby (power saving) mode. Note: when in the standby mode, there is no valid data in the registers. In addition, the only way to write a register is to put the device in the standby mode.

Parameters
devDevice context.
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t mma7660_tilt_back_front ( const mma7660_context  dev,
uint8_t *  bits 
)

Reads tiltBackFront bits

The value returned is one of the MMA7660_TILT_BF_T values

Parameters
devDevice context.
bitsPointer to returned bits corresponding to the BackFront tilt status
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t mma7660_tilt_landscape_portrait ( const mma7660_context  dev,
uint8_t *  bits 
)

Reads tiltLandscapePortrait bits

The value returned is one of the MMA7660_TILT_LP_T values

Parameters
devDevice context.
bitsPointer to returned bits corresponding to the LandscapePortrait tilt status
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t mma7660_tilt_tap ( const mma7660_context  dev,
bool *  tap 
)

Reads the tiltTap status

Parameters
devDevice context.
tapPointer to a bool indicating tap detection
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t mma7660_tilt_shake ( const mma7660_context  dev,
bool *  shake 
)

Reads the tiltShake status

Parameters
devDevice context.
shakePointer to a bool indicating shake detection
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t mma7660_install_isr ( const mma7660_context  dev,
int  pin,
void(*)(void *)  isr,
void *  arg 
)

Installs an interrupt service routine (ISR) to be called when an interrupt occurs

Parameters
devDevice context.
pinGPIO pin to use as the interrupt pin
isrPointer to a function to be called on interrupt
argPointer to an object to be supplied as an argument to the ISR.
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

void mma7660_uninstall_isr ( const mma7660_context  dev)

Uninstalls the previously installed ISR

Parameters
devDevice context.

Here is the caller graph for this function:

upm_result_t mma7660_set_interrupt_bits ( const mma7660_context  dev,
uint8_t  ibits 
)

Enables interrupt generation based on passed interrupt bits. The bits are a bitmask of the requested MMA7660_INTR_T values. Note: the device must be in the standby mode to set this register.

Parameters
devDevice context.
ibitsSets the requested interrupt bits
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t mma7660_set_sample_rate ( const mma7660_context  dev,
MMA7660_AUTOSLEEP_T  sr 
)

Sets the sampling rate of the sensor. The value supplied must be one of the MMA7660_AUTOSLEEP_T values.

Parameters
devDevice context.
srOne of the MMA7660_AUTOSLEEP_T values
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

Typedef Documentation

Device context