| Kinetis SDK Demo Applications User Guide 1.0.0-beta Freescale Semiconductor, Inc.

- Main Page
- Related Pages
- Demos

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
fsl_mma8451.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * o Redistributions of source code must retain the above copyright notice, this list
9 * of conditions and the following disclaimer.
10 *
11 * o Redistributions in binary form must reproduce the above copyright notice, this
12 * list of conditions and the following disclaimer in the documentation and/or
13 * other materials provided with the distribution.
14 *
15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #if !defined(__FSL_MMA8451_H__)
32 #define __FSL_MMA8451_H__
33
34 #include "i2c_master/fsl_i2c_master_driver.h"
35
39 enum _mma8451_constants
40 {
41 kMMA8451_STATUS = 0x00,
42 kMMA8451_OUT_X_MSB = 0x01,
43 kMMA8451_OUT_X_LSB = 0x02,
44 kMMA8451_OUT_Y_MSB = 0x03,
45 kMMA8451_OUT_Y_LSB = 0x04,
46 kMMA8451_OUT_Z_MSB = 0x05,
47 kMMA8451_OUT_Z_LSB = 0x06,
48 kMMA8451_F_SETUP = 0x09,
49 kMMA8451_TRIG_CFG = 0x0a,
50 kMMA8451_SYSMOD = 0x0b,
51 kMMA8451_INT_SOURCE = 0x0c,
52 kMMA8451_WHO_AM_I = 0x0d,
53 kMMA8451_WHO_AM_I_Device_ID = 0x1a,
54 kMMA8451_XYZ_DATA_CFG = 0x0e,
55 kMMA8451_CTRL_REG1 = 0x2a,
56 kMMA8451_CTRL_REG2 = 0x2b,
57 kMMA8451_CTRL_REG3 = 0x2c,
58 kMMA8451_CTRL_REG4 = 0x2d,
59 kMMA8451_CTRL_REG5 = 0x2e
60 };
61
65 typedef struct _mma8451_device {
66 i2c_device_t address;
67 } mma8451_device_t;
68
72 typedef struct _acceleration {
73 int32_t x;
74 int32_t y;
75 int32_t z;
76 } acceleration_t;
77
78 /*******************************************************************************
79 * API
80 ******************************************************************************/
81
82 #if defined(__cplusplus)
83 extern "C" {
84 #endif
85
99 int32_t mma8451_init(mma8451_device_t *device, uint8_t i2c_addr, uint32_t baud_kbps);
100
111 int32_t mma8451_get_acceleration(const mma8451_device_t * device, acceleration_t * accel);
112
121 uint8_t mma8451_read_register(const mma8451_device_t * device, uint8_t reg_addr);
122
133 int32_t mma8451_write_register(const mma8451_device_t * device, uint8_t reg_addr, uint8_t reg_val);
134
135
136 #if defined(__cplusplus)
137 }
138 #endif
139
140 #endif
kMMA8451_SYSMOD
Definition: fsl_mma8451.h:50
kMMA8451_STATUS
Definition: fsl_mma8451.h:41
mma8451_get_acceleration
int32_t mma8451_get_acceleration(const mma8451_device_t *device, acceleration_t *accel)
Read the current acceleration values.
Definition: fsl_mma8451.c:116
mma8451_device_t::address
i2c_device_t address
Definition: fsl_mma8451.h:66
kMMA8451_WHO_AM_I
Definition: fsl_mma8451.h:52
mma8451_read_register
uint8_t mma8451_read_register(const mma8451_device_t *device, uint8_t reg_addr)
Read a single register of the MMA8451.
Definition: fsl_mma8451.c:49
kMMA8451_CTRL_REG2
Definition: fsl_mma8451.h:56
kMMA8451_OUT_Z_MSB
Definition: fsl_mma8451.h:46
kMMA8451_CTRL_REG4
Definition: fsl_mma8451.h:58
kMMA8451_WHO_AM_I_Device_ID
Definition: fsl_mma8451.h:53
acceleration_t::x
int32_t x
Definition: fsl_mma8451.h:73
mma8451_device_t
MMA8451 driver instance.
Definition: fsl_mma8451.h:65
kMMA8451_CTRL_REG1
Definition: fsl_mma8451.h:55
acceleration_t
3D acceleration values.
Definition: fsl_mma8451.h:72
mma8451_init
int32_t mma8451_init(mma8451_device_t *device, uint8_t i2c_addr, uint32_t baud_kbps)
Initialize the MMA8451 driver instance.
Definition: fsl_mma8451.c:66
kMMA8451_CTRL_REG5
Definition: fsl_mma8451.h:59
kMMA8451_OUT_X_LSB
Definition: fsl_mma8451.h:43
kMMA8451_OUT_Z_LSB
Definition: fsl_mma8451.h:47
acceleration_t::z
int32_t z
Definition: fsl_mma8451.h:75
kMMA8451_TRIG_CFG
Definition: fsl_mma8451.h:49
kMMA8451_OUT_X_MSB
Definition: fsl_mma8451.h:42
kMMA8451_XYZ_DATA_CFG
Definition: fsl_mma8451.h:54
_mma8451_constants
_mma8451_constants
Register definitions for the MMA8451.
Definition: fsl_mma8451.h:39
acceleration_t::y
int32_t y
Definition: fsl_mma8451.h:74
kMMA8451_OUT_Y_MSB
Definition: fsl_mma8451.h:44
kMMA8451_OUT_Y_LSB
Definition: fsl_mma8451.h:45
kMMA8451_F_SETUP
Definition: fsl_mma8451.h:48
kMMA8451_CTRL_REG3
Definition: fsl_mma8451.h:57
mma8451_write_register
int32_t mma8451_write_register(const mma8451_device_t *device, uint8_t reg_addr, uint8_t reg_val)
Write a single register of the MMA8451.
Definition: fsl_mma8451.c:58
kMMA8451_INT_SOURCE
Definition: fsl_mma8451.h:51