Library for MMA7660FC Accelerometer device

Dependents:   TestCode_MMA7660FC 3D_Accelerometer_Tester RTOS-aap-board-modules embed_Grove_3-Axis_Digital_Accelerometer ... more

Committer:
edodm85
Date:
Sun Jul 01 09:35:40 2012 +0000
Revision:
1:6e7a2df4f149
Parent:
0:eb135a8de811
Child:
2:88fd58f262c6
Rev 2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
edodm85 0:eb135a8de811 1 // Author: Edoardo De Marchi
edodm85 0:eb135a8de811 2 /* Copyright (C) 2012 mbed.org, MIT License
edodm85 0:eb135a8de811 3 *
edodm85 0:eb135a8de811 4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
edodm85 0:eb135a8de811 5 * and associated documentation files (the "Software"), to deal in the Software without restriction,
edodm85 0:eb135a8de811 6 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
edodm85 0:eb135a8de811 7 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
edodm85 0:eb135a8de811 8 * furnished to do so, subject to the following conditions:
edodm85 0:eb135a8de811 9 *
edodm85 0:eb135a8de811 10 * The above copyright notice and this permission notice shall be included in all copies or
edodm85 0:eb135a8de811 11 * substantial portions of the Software.
edodm85 0:eb135a8de811 12 *
edodm85 0:eb135a8de811 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
edodm85 0:eb135a8de811 14 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
edodm85 0:eb135a8de811 15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
edodm85 0:eb135a8de811 16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
edodm85 0:eb135a8de811 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
edodm85 0:eb135a8de811 18 */
edodm85 0:eb135a8de811 19
edodm85 0:eb135a8de811 20
edodm85 0:eb135a8de811 21 #ifndef MBED_MMA7660FC_H
edodm85 0:eb135a8de811 22 #define MBED_MMA7660FC_H
edodm85 0:eb135a8de811 23
edodm85 0:eb135a8de811 24 #include "mbed.h"
edodm85 0:eb135a8de811 25
edodm85 0:eb135a8de811 26 /** Accelerometer MMA7660FC class
edodm85 0:eb135a8de811 27 *
edodm85 0:eb135a8de811 28 * Example:
edodm85 0:eb135a8de811 29 * @code
edodm85 0:eb135a8de811 30 *
edodm85 0:eb135a8de811 31 * #include "mbed.h"
edodm85 0:eb135a8de811 32 * #include "MMA7660FC.h"
edodm85 0:eb135a8de811 33 *
edodm85 0:eb135a8de811 34 * #define ADDR_MMA7660 0x98
edodm85 0:eb135a8de811 35 *
edodm85 0:eb135a8de811 36 * MMA7660FC Acc(p28, p27, ADDR_MMA7660);
edodm85 0:eb135a8de811 37 * serial pc(USBTX, USBRX);
edodm85 0:eb135a8de811 38 *
edodm85 0:eb135a8de811 39 * int main()
edodm85 0:eb135a8de811 40 * {
edodm85 0:eb135a8de811 41 * Acc.init();
edodm85 0:eb135a8de811 42 * while(1)
edodm85 0:eb135a8de811 43 * {
edodm85 0:eb135a8de811 44 * int x=0, y=0, z=0;
edodm85 0:eb135a8de811 45 * Acc.read_g(&x, &y, &z);
edodm85 0:eb135a8de811 46 * pc.printf("x: \n", x);
edodm85 0:eb135a8de811 47 * pc.printf("x: \n", y);
edodm85 0:eb135a8de811 48 * pc.printf("x: \n", z);
edodm85 0:eb135a8de811 49 * wait(1);
edodm85 0:eb135a8de811 50 * }
edodm85 0:eb135a8de811 51 * }
edodm85 0:eb135a8de811 52 * @endcode
edodm85 0:eb135a8de811 53 */
edodm85 0:eb135a8de811 54 class MMA7660FC
edodm85 0:eb135a8de811 55 {
edodm85 0:eb135a8de811 56 public:
edodm85 0:eb135a8de811 57
edodm85 0:eb135a8de811 58
edodm85 0:eb135a8de811 59 /** Create an MMA7660FC object connected to the specified I2C object
edodm85 0:eb135a8de811 60 *
edodm85 0:eb135a8de811 61 * @param sda I2C data port
edodm85 0:eb135a8de811 62 * @param scl I2C clock port
edodm85 0:eb135a8de811 63 * @param addr The address of the MMA7660FC
edodm85 0:eb135a8de811 64 */
edodm85 0:eb135a8de811 65 MMA7660FC(PinName sda, PinName scl, int addr);
edodm85 0:eb135a8de811 66
edodm85 0:eb135a8de811 67 /** Destroys an MMA7660FC object
edodm85 0:eb135a8de811 68 *
edodm85 0:eb135a8de811 69 */
edodm85 0:eb135a8de811 70 ~MMA7660FC();
edodm85 0:eb135a8de811 71
edodm85 1:6e7a2df4f149 72 /** Initialization of device MMA7660FC (required)
edodm85 0:eb135a8de811 73 *
edodm85 0:eb135a8de811 74 */
edodm85 0:eb135a8de811 75 void init();
edodm85 0:eb135a8de811 76
edodm85 1:6e7a2df4f149 77 /** Read the x,y,z axes acceleration and return a 6bit unsigned data
edodm85 0:eb135a8de811 78 *
edodm85 0:eb135a8de811 79 * @param *x Value of X acceleration
edodm85 0:eb135a8de811 80 * @param *y Value of Y acceleration
edodm85 0:eb135a8de811 81 * @param *z Value of Z acceleration
edodm85 0:eb135a8de811 82 */
edodm85 0:eb135a8de811 83 void read_g(int *x, int *y, int *z);
edodm85 0:eb135a8de811 84
edodm85 0:eb135a8de811 85 /** Read from specified MMA7660FC register
edodm85 0:eb135a8de811 86 *
edodm85 0:eb135a8de811 87 * @param addr The internal registeraddress of the MMA7660FC
edodm85 0:eb135a8de811 88 * @returns The value of the register
edodm85 0:eb135a8de811 89 */
edodm85 0:eb135a8de811 90 char read_reg(char addr);
edodm85 0:eb135a8de811 91
edodm85 0:eb135a8de811 92 /** Write to specified MMA7660FC register
edodm85 0:eb135a8de811 93 *
edodm85 0:eb135a8de811 94 * @param addr The internal registeraddress of the MMA7660FC
edodm85 0:eb135a8de811 95 * @param data New value of the register
edodm85 0:eb135a8de811 96 */
edodm85 0:eb135a8de811 97 void write_reg(char addr, char data);
edodm85 0:eb135a8de811 98
edodm85 0:eb135a8de811 99
edodm85 0:eb135a8de811 100 private:
edodm85 0:eb135a8de811 101 I2C m_i2c;
edodm85 0:eb135a8de811 102 int m_addr;
edodm85 0:eb135a8de811 103 };
edodm85 0:eb135a8de811 104
edodm85 0:eb135a8de811 105 #endif