hattori&ide

Dependencies:   mbed

Committer:
hattori_atsushi
Date:
Sun Dec 18 08:16:01 2022 +0000
Revision:
0:f77369cabd75
hattori

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hattori_atsushi 0:f77369cabd75 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
hattori_atsushi 0:f77369cabd75 2 *
hattori_atsushi 0:f77369cabd75 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
hattori_atsushi 0:f77369cabd75 4 * and associated documentation files (the "Software"), to deal in the Software without
hattori_atsushi 0:f77369cabd75 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
hattori_atsushi 0:f77369cabd75 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
hattori_atsushi 0:f77369cabd75 7 * Software is furnished to do so, subject to the following conditions:
hattori_atsushi 0:f77369cabd75 8 *
hattori_atsushi 0:f77369cabd75 9 * The above copyright notice and this permission notice shall be included in all copies or
hattori_atsushi 0:f77369cabd75 10 * substantial portions of the Software.
hattori_atsushi 0:f77369cabd75 11 *
hattori_atsushi 0:f77369cabd75 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
hattori_atsushi 0:f77369cabd75 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
hattori_atsushi 0:f77369cabd75 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
hattori_atsushi 0:f77369cabd75 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
hattori_atsushi 0:f77369cabd75 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
hattori_atsushi 0:f77369cabd75 17 */
hattori_atsushi 0:f77369cabd75 18
hattori_atsushi 0:f77369cabd75 19 #ifndef MMA8652_H
hattori_atsushi 0:f77369cabd75 20 #define MMA8652_H
hattori_atsushi 0:f77369cabd75 21
hattori_atsushi 0:f77369cabd75 22 #include "mbed.h"
hattori_atsushi 0:f77369cabd75 23
hattori_atsushi 0:f77369cabd75 24
hattori_atsushi 0:f77369cabd75 25 // MMA8652 Slave Address
hattori_atsushi 0:f77369cabd75 26 #define MMA8652_SLAVE_ADDR 0x38
hattori_atsushi 0:f77369cabd75 27
hattori_atsushi 0:f77369cabd75 28 // MMA8652 internal register addresses
hattori_atsushi 0:f77369cabd75 29 #define MMA8652_STATUS 0x00
hattori_atsushi 0:f77369cabd75 30 #define MMA8652_OUT_X_MSB 0x01
hattori_atsushi 0:f77369cabd75 31 #define MMA8652_WHOAMI 0x0D
hattori_atsushi 0:f77369cabd75 32 #define MMA8652_XYZ_DATA_CFG 0x0E
hattori_atsushi 0:f77369cabd75 33 #define MMA8652_CTRL_REG1 0x2A
hattori_atsushi 0:f77369cabd75 34 #define MMA8652_WHOAMI_VAL 0x4A
hattori_atsushi 0:f77369cabd75 35
hattori_atsushi 0:f77369cabd75 36 /**
hattori_atsushi 0:f77369cabd75 37 * MMA8652 Xtrinsic accelerometer on I2C
hattori_atsushi 0:f77369cabd75 38 */
hattori_atsushi 0:f77369cabd75 39 class MMA8652
hattori_atsushi 0:f77369cabd75 40 {
hattori_atsushi 0:f77369cabd75 41 public:
hattori_atsushi 0:f77369cabd75 42 /**
hattori_atsushi 0:f77369cabd75 43 * MMA8652 constructor
hattori_atsushi 0:f77369cabd75 44 *
hattori_atsushi 0:f77369cabd75 45 * @param sda SDA pin
hattori_atsushi 0:f77369cabd75 46 * @param sdl SCL pin
hattori_atsushi 0:f77369cabd75 47 */
hattori_atsushi 0:f77369cabd75 48 MMA8652(PinName sda, PinName scl);
hattori_atsushi 0:f77369cabd75 49
hattori_atsushi 0:f77369cabd75 50 /**
hattori_atsushi 0:f77369cabd75 51 * MMA8652 destructor
hattori_atsushi 0:f77369cabd75 52 */
hattori_atsushi 0:f77369cabd75 53 ~MMA8652();
hattori_atsushi 0:f77369cabd75 54
hattori_atsushi 0:f77369cabd75 55 /**
hattori_atsushi 0:f77369cabd75 56 * Get XYZ axis acceleration in floating point G's
hattori_atsushi 0:f77369cabd75 57 *
hattori_atsushi 0:f77369cabd75 58 * @param res array where acceleration data will be stored
hattori_atsushi 0:f77369cabd75 59 */
hattori_atsushi 0:f77369cabd75 60 void ReadXYZ(float * a);
hattori_atsushi 0:f77369cabd75 61
hattori_atsushi 0:f77369cabd75 62 /**
hattori_atsushi 0:f77369cabd75 63 * Get XYZ axis acceleration, signed 16 bit values
hattori_atsushi 0:f77369cabd75 64 *
hattori_atsushi 0:f77369cabd75 65 * @param res array where acceleration data will be stored
hattori_atsushi 0:f77369cabd75 66 */
hattori_atsushi 0:f77369cabd75 67 void ReadXYZraw(int16_t * d);
hattori_atsushi 0:f77369cabd75 68
hattori_atsushi 0:f77369cabd75 69 /**
hattori_atsushi 0:f77369cabd75 70 * Get the value of the WHO_AM_I register
hattori_atsushi 0:f77369cabd75 71 *
hattori_atsushi 0:f77369cabd75 72 * @returns DEVICE_ID value == 0x3A
hattori_atsushi 0:f77369cabd75 73 */
hattori_atsushi 0:f77369cabd75 74 char getWhoAmI(void);
hattori_atsushi 0:f77369cabd75 75
hattori_atsushi 0:f77369cabd75 76 private:
hattori_atsushi 0:f77369cabd75 77 I2C _i2c;
hattori_atsushi 0:f77369cabd75 78
hattori_atsushi 0:f77369cabd75 79 /**
hattori_atsushi 0:f77369cabd75 80 * Set the device in active mode
hattori_atsushi 0:f77369cabd75 81 */
hattori_atsushi 0:f77369cabd75 82 void begin( void);
hattori_atsushi 0:f77369cabd75 83
hattori_atsushi 0:f77369cabd75 84 void RegRead( char reg, char * d, int len);
hattori_atsushi 0:f77369cabd75 85
hattori_atsushi 0:f77369cabd75 86 };
hattori_atsushi 0:f77369cabd75 87
hattori_atsushi 0:f77369cabd75 88 #endif