A library with drivers for different peripherals on the LPC4088 QuickStart Board or related add-on boards.
Dependents: LPC4088test LPC4088test_ledonly LPC4088test_deleteall LPC4088_RAMtest ... more
MMA7455.h@4:b32cf4ef45c5, 2013-10-18 (annotated)
- Committer:
- embeddedartists
- Date:
- Fri Oct 18 12:48:58 2013 +0200
- Revision:
- 4:b32cf4ef45c5
- Child:
- 12:15597e45eea0
Added AR1021 touch controller
Added MMA7455 accelerometer
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
embeddedartists | 4:b32cf4ef45c5 | 1 | |
embeddedartists | 4:b32cf4ef45c5 | 2 | #ifndef MMA7455_H |
embeddedartists | 4:b32cf4ef45c5 | 3 | #define MMA7455_H |
embeddedartists | 4:b32cf4ef45c5 | 4 | |
embeddedartists | 4:b32cf4ef45c5 | 5 | |
embeddedartists | 4:b32cf4ef45c5 | 6 | /** |
embeddedartists | 4:b32cf4ef45c5 | 7 | * Freescale Accelerometer MMA7455. |
embeddedartists | 4:b32cf4ef45c5 | 8 | */ |
embeddedartists | 4:b32cf4ef45c5 | 9 | class MMA7455 { |
embeddedartists | 4:b32cf4ef45c5 | 10 | public: |
embeddedartists | 4:b32cf4ef45c5 | 11 | |
embeddedartists | 4:b32cf4ef45c5 | 12 | enum Mode { |
embeddedartists | 4:b32cf4ef45c5 | 13 | ModeStandby = 0, |
embeddedartists | 4:b32cf4ef45c5 | 14 | ModeMeasurement = 1, |
embeddedartists | 4:b32cf4ef45c5 | 15 | }; |
embeddedartists | 4:b32cf4ef45c5 | 16 | |
embeddedartists | 4:b32cf4ef45c5 | 17 | /** Acceleration range */ |
embeddedartists | 4:b32cf4ef45c5 | 18 | enum Range { |
embeddedartists | 4:b32cf4ef45c5 | 19 | Range_8g = 0, |
embeddedartists | 4:b32cf4ef45c5 | 20 | Range_2g = 1, |
embeddedartists | 4:b32cf4ef45c5 | 21 | Range_4g = 2 |
embeddedartists | 4:b32cf4ef45c5 | 22 | }; |
embeddedartists | 4:b32cf4ef45c5 | 23 | |
embeddedartists | 4:b32cf4ef45c5 | 24 | /** |
embeddedartists | 4:b32cf4ef45c5 | 25 | * Create an interface to the MMA7455 accelerometer |
embeddedartists | 4:b32cf4ef45c5 | 26 | * |
embeddedartists | 4:b32cf4ef45c5 | 27 | * @param sda I2C data line pin |
embeddedartists | 4:b32cf4ef45c5 | 28 | * @param scl I2C clock line pin |
embeddedartists | 4:b32cf4ef45c5 | 29 | */ |
embeddedartists | 4:b32cf4ef45c5 | 30 | MMA7455(PinName sda, PinName scl); |
embeddedartists | 4:b32cf4ef45c5 | 31 | |
embeddedartists | 4:b32cf4ef45c5 | 32 | bool setMode(Mode mode); |
embeddedartists | 4:b32cf4ef45c5 | 33 | bool setRange(Range range); |
embeddedartists | 4:b32cf4ef45c5 | 34 | |
embeddedartists | 4:b32cf4ef45c5 | 35 | bool read(int32_t& x, int32_t& y, int32_t& z); |
embeddedartists | 4:b32cf4ef45c5 | 36 | |
embeddedartists | 4:b32cf4ef45c5 | 37 | /** |
embeddedartists | 4:b32cf4ef45c5 | 38 | * Calibrate for 0g, that is, calculate offset to achieve |
embeddedartists | 4:b32cf4ef45c5 | 39 | * 0g values when accelerometer is placed on flat surface. |
embeddedartists | 4:b32cf4ef45c5 | 40 | * |
embeddedartists | 4:b32cf4ef45c5 | 41 | * Please make sure the accelerometer is placed on a flat surface before |
embeddedartists | 4:b32cf4ef45c5 | 42 | * calling this function. |
embeddedartists | 4:b32cf4ef45c5 | 43 | * |
embeddedartists | 4:b32cf4ef45c5 | 44 | * @return true if request was successful; otherwise false |
embeddedartists | 4:b32cf4ef45c5 | 45 | */ |
embeddedartists | 4:b32cf4ef45c5 | 46 | bool calibrate(); |
embeddedartists | 4:b32cf4ef45c5 | 47 | |
embeddedartists | 4:b32cf4ef45c5 | 48 | /** |
embeddedartists | 4:b32cf4ef45c5 | 49 | * Get calculated offset values. Offsets will be calculated by the |
embeddedartists | 4:b32cf4ef45c5 | 50 | * calibrate() method. |
embeddedartists | 4:b32cf4ef45c5 | 51 | * |
embeddedartists | 4:b32cf4ef45c5 | 52 | * Use these values and put them in persistent storage to avoid |
embeddedartists | 4:b32cf4ef45c5 | 53 | * having to calibrate the accelerometer after a reset/power cycle. |
embeddedartists | 4:b32cf4ef45c5 | 54 | * |
embeddedartists | 4:b32cf4ef45c5 | 55 | * @param xOff x offset is written to this argument |
embeddedartists | 4:b32cf4ef45c5 | 56 | * @param yOff y offset is written to this argument |
embeddedartists | 4:b32cf4ef45c5 | 57 | * @param zOff z offset is written to this argument |
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 getCalibrationOffsets(int32_t& xOff, int32_t& yOff, int32_t& zOff); |
embeddedartists | 4:b32cf4ef45c5 | 62 | |
embeddedartists | 4:b32cf4ef45c5 | 63 | /** |
embeddedartists | 4:b32cf4ef45c5 | 64 | * Set calibration offset values. These values should normally |
embeddedartists | 4:b32cf4ef45c5 | 65 | * at one point in time have been retrieved by calling the |
embeddedartists | 4:b32cf4ef45c5 | 66 | * getCalibrationOffsets method. |
embeddedartists | 4:b32cf4ef45c5 | 67 | * |
embeddedartists | 4:b32cf4ef45c5 | 68 | * |
embeddedartists | 4:b32cf4ef45c5 | 69 | * @param xOff x offset |
embeddedartists | 4:b32cf4ef45c5 | 70 | * @param yOff y offset |
embeddedartists | 4:b32cf4ef45c5 | 71 | * @param zOff z offset |
embeddedartists | 4:b32cf4ef45c5 | 72 | * |
embeddedartists | 4:b32cf4ef45c5 | 73 | * @return true if request was successful; otherwise false |
embeddedartists | 4:b32cf4ef45c5 | 74 | */ |
embeddedartists | 4:b32cf4ef45c5 | 75 | bool setCalibrationOffsets(int32_t xOff, int32_t yOff, int32_t zOff); |
embeddedartists | 4:b32cf4ef45c5 | 76 | |
embeddedartists | 4:b32cf4ef45c5 | 77 | |
embeddedartists | 4:b32cf4ef45c5 | 78 | |
embeddedartists | 4:b32cf4ef45c5 | 79 | private: |
embeddedartists | 4:b32cf4ef45c5 | 80 | |
embeddedartists | 4:b32cf4ef45c5 | 81 | I2C _i2c; |
embeddedartists | 4:b32cf4ef45c5 | 82 | Mode _mode; |
embeddedartists | 4:b32cf4ef45c5 | 83 | Range _range; |
embeddedartists | 4:b32cf4ef45c5 | 84 | int32_t _xOff; |
embeddedartists | 4:b32cf4ef45c5 | 85 | int32_t _yOff; |
embeddedartists | 4:b32cf4ef45c5 | 86 | int32_t _zOff; |
embeddedartists | 4:b32cf4ef45c5 | 87 | |
embeddedartists | 4:b32cf4ef45c5 | 88 | int getStatus(); |
embeddedartists | 4:b32cf4ef45c5 | 89 | int getModeControl(); |
embeddedartists | 4:b32cf4ef45c5 | 90 | int setModeControl(uint8_t mctl); |
embeddedartists | 4:b32cf4ef45c5 | 91 | |
embeddedartists | 4:b32cf4ef45c5 | 92 | }; |
embeddedartists | 4:b32cf4ef45c5 | 93 | |
embeddedartists | 4:b32cf4ef45c5 | 94 | #endif |