A library with drivers for different peripherals on the LPC4088 QuickStart Board or related add-on boards.
Dependencies: FATFileSystem
Fork of EALib by
MMA7455.h@12:15597e45eea0, 2014-01-30 (annotated)
- Committer:
- embeddedartists
- Date:
- Thu Jan 30 08:50:47 2014 +0100
- Revision:
- 12:15597e45eea0
- Parent:
- 4:b32cf4ef45c5
Added license information
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
embeddedartists | 12:15597e45eea0 | 1 | /* |
embeddedartists | 12:15597e45eea0 | 2 | * Copyright 2013 Embedded Artists AB |
embeddedartists | 12:15597e45eea0 | 3 | * |
embeddedartists | 12:15597e45eea0 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
embeddedartists | 12:15597e45eea0 | 5 | * you may not use this file except in compliance with the License. |
embeddedartists | 12:15597e45eea0 | 6 | * You may obtain a copy of the License at |
embeddedartists | 12:15597e45eea0 | 7 | * |
embeddedartists | 12:15597e45eea0 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
embeddedartists | 12:15597e45eea0 | 9 | * |
embeddedartists | 12:15597e45eea0 | 10 | * Unless required by applicable law or agreed to in writing, software |
embeddedartists | 12:15597e45eea0 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
embeddedartists | 12:15597e45eea0 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
embeddedartists | 12:15597e45eea0 | 13 | * See the License for the specific language governing permissions and |
embeddedartists | 12:15597e45eea0 | 14 | * limitations under the License. |
embeddedartists | 12:15597e45eea0 | 15 | */ |
embeddedartists | 4:b32cf4ef45c5 | 16 | |
embeddedartists | 4:b32cf4ef45c5 | 17 | #ifndef MMA7455_H |
embeddedartists | 4:b32cf4ef45c5 | 18 | #define MMA7455_H |
embeddedartists | 4:b32cf4ef45c5 | 19 | |
embeddedartists | 4:b32cf4ef45c5 | 20 | |
embeddedartists | 4:b32cf4ef45c5 | 21 | /** |
embeddedartists | 4:b32cf4ef45c5 | 22 | * Freescale Accelerometer MMA7455. |
embeddedartists | 4:b32cf4ef45c5 | 23 | */ |
embeddedartists | 4:b32cf4ef45c5 | 24 | class MMA7455 { |
embeddedartists | 4:b32cf4ef45c5 | 25 | public: |
embeddedartists | 4:b32cf4ef45c5 | 26 | |
embeddedartists | 4:b32cf4ef45c5 | 27 | enum Mode { |
embeddedartists | 4:b32cf4ef45c5 | 28 | ModeStandby = 0, |
embeddedartists | 4:b32cf4ef45c5 | 29 | ModeMeasurement = 1, |
embeddedartists | 4:b32cf4ef45c5 | 30 | }; |
embeddedartists | 4:b32cf4ef45c5 | 31 | |
embeddedartists | 4:b32cf4ef45c5 | 32 | /** Acceleration range */ |
embeddedartists | 4:b32cf4ef45c5 | 33 | enum Range { |
embeddedartists | 4:b32cf4ef45c5 | 34 | Range_8g = 0, |
embeddedartists | 4:b32cf4ef45c5 | 35 | Range_2g = 1, |
embeddedartists | 4:b32cf4ef45c5 | 36 | Range_4g = 2 |
embeddedartists | 4:b32cf4ef45c5 | 37 | }; |
embeddedartists | 4:b32cf4ef45c5 | 38 | |
embeddedartists | 4:b32cf4ef45c5 | 39 | /** |
embeddedartists | 4:b32cf4ef45c5 | 40 | * Create an interface to the MMA7455 accelerometer |
embeddedartists | 4:b32cf4ef45c5 | 41 | * |
embeddedartists | 4:b32cf4ef45c5 | 42 | * @param sda I2C data line pin |
embeddedartists | 4:b32cf4ef45c5 | 43 | * @param scl I2C clock line pin |
embeddedartists | 4:b32cf4ef45c5 | 44 | */ |
embeddedartists | 4:b32cf4ef45c5 | 45 | MMA7455(PinName sda, PinName scl); |
embeddedartists | 4:b32cf4ef45c5 | 46 | |
embeddedartists | 4:b32cf4ef45c5 | 47 | bool setMode(Mode mode); |
embeddedartists | 4:b32cf4ef45c5 | 48 | bool setRange(Range range); |
embeddedartists | 4:b32cf4ef45c5 | 49 | |
embeddedartists | 4:b32cf4ef45c5 | 50 | bool read(int32_t& x, int32_t& y, int32_t& z); |
embeddedartists | 4:b32cf4ef45c5 | 51 | |
embeddedartists | 4:b32cf4ef45c5 | 52 | /** |
embeddedartists | 4:b32cf4ef45c5 | 53 | * Calibrate for 0g, that is, calculate offset to achieve |
embeddedartists | 4:b32cf4ef45c5 | 54 | * 0g values when accelerometer is placed on flat surface. |
embeddedartists | 4:b32cf4ef45c5 | 55 | * |
embeddedartists | 4:b32cf4ef45c5 | 56 | * Please make sure the accelerometer is placed on a flat surface before |
embeddedartists | 4:b32cf4ef45c5 | 57 | * calling this function. |
embeddedartists | 4:b32cf4ef45c5 | 58 | * |
embeddedartists | 4:b32cf4ef45c5 | 59 | * @return true if request was successful; otherwise false |
embeddedartists | 4:b32cf4ef45c5 | 60 | */ |
embeddedartists | 4:b32cf4ef45c5 | 61 | bool calibrate(); |
embeddedartists | 4:b32cf4ef45c5 | 62 | |
embeddedartists | 4:b32cf4ef45c5 | 63 | /** |
embeddedartists | 4:b32cf4ef45c5 | 64 | * Get calculated offset values. Offsets will be calculated by the |
embeddedartists | 4:b32cf4ef45c5 | 65 | * calibrate() method. |
embeddedartists | 4:b32cf4ef45c5 | 66 | * |
embeddedartists | 4:b32cf4ef45c5 | 67 | * Use these values and put them in persistent storage to avoid |
embeddedartists | 4:b32cf4ef45c5 | 68 | * having to calibrate the accelerometer after a reset/power cycle. |
embeddedartists | 4:b32cf4ef45c5 | 69 | * |
embeddedartists | 4:b32cf4ef45c5 | 70 | * @param xOff x offset is written to this argument |
embeddedartists | 4:b32cf4ef45c5 | 71 | * @param yOff y offset is written to this argument |
embeddedartists | 4:b32cf4ef45c5 | 72 | * @param zOff z offset is written to this argument |
embeddedartists | 4:b32cf4ef45c5 | 73 | * |
embeddedartists | 4:b32cf4ef45c5 | 74 | * @return true if request was successful; otherwise false |
embeddedartists | 4:b32cf4ef45c5 | 75 | */ |
embeddedartists | 4:b32cf4ef45c5 | 76 | bool getCalibrationOffsets(int32_t& xOff, int32_t& yOff, int32_t& zOff); |
embeddedartists | 4:b32cf4ef45c5 | 77 | |
embeddedartists | 4:b32cf4ef45c5 | 78 | /** |
embeddedartists | 4:b32cf4ef45c5 | 79 | * Set calibration offset values. These values should normally |
embeddedartists | 4:b32cf4ef45c5 | 80 | * at one point in time have been retrieved by calling the |
embeddedartists | 4:b32cf4ef45c5 | 81 | * getCalibrationOffsets method. |
embeddedartists | 4:b32cf4ef45c5 | 82 | * |
embeddedartists | 4:b32cf4ef45c5 | 83 | * |
embeddedartists | 4:b32cf4ef45c5 | 84 | * @param xOff x offset |
embeddedartists | 4:b32cf4ef45c5 | 85 | * @param yOff y offset |
embeddedartists | 4:b32cf4ef45c5 | 86 | * @param zOff z offset |
embeddedartists | 4:b32cf4ef45c5 | 87 | * |
embeddedartists | 4:b32cf4ef45c5 | 88 | * @return true if request was successful; otherwise false |
embeddedartists | 4:b32cf4ef45c5 | 89 | */ |
embeddedartists | 4:b32cf4ef45c5 | 90 | bool setCalibrationOffsets(int32_t xOff, int32_t yOff, int32_t zOff); |
embeddedartists | 4:b32cf4ef45c5 | 91 | |
embeddedartists | 4:b32cf4ef45c5 | 92 | |
embeddedartists | 4:b32cf4ef45c5 | 93 | |
embeddedartists | 4:b32cf4ef45c5 | 94 | private: |
embeddedartists | 4:b32cf4ef45c5 | 95 | |
embeddedartists | 4:b32cf4ef45c5 | 96 | I2C _i2c; |
embeddedartists | 4:b32cf4ef45c5 | 97 | Mode _mode; |
embeddedartists | 4:b32cf4ef45c5 | 98 | Range _range; |
embeddedartists | 4:b32cf4ef45c5 | 99 | int32_t _xOff; |
embeddedartists | 4:b32cf4ef45c5 | 100 | int32_t _yOff; |
embeddedartists | 4:b32cf4ef45c5 | 101 | int32_t _zOff; |
embeddedartists | 4:b32cf4ef45c5 | 102 | |
embeddedartists | 4:b32cf4ef45c5 | 103 | int getStatus(); |
embeddedartists | 4:b32cf4ef45c5 | 104 | int getModeControl(); |
embeddedartists | 4:b32cf4ef45c5 | 105 | int setModeControl(uint8_t mctl); |
embeddedartists | 4:b32cf4ef45c5 | 106 | |
embeddedartists | 4:b32cf4ef45c5 | 107 | }; |
embeddedartists | 4:b32cf4ef45c5 | 108 | |
embeddedartists | 4:b32cf4ef45c5 | 109 | #endif |