Class to drive the Compass (LSM303 device with Accelerometer and Magnetometer) present on DISCO_L476VG board.

Dependents:   DiscoLogger vcdMaker_Demo_DISCO_L476 DISCO_L476VG_Compass_Lab_6 Final_project_Compass ... more

Committer:
bcostm
Date:
Tue Sep 22 14:53:31 2015 +0000
Revision:
0:6508fa5521e0
Initial version.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:6508fa5521e0 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
bcostm 0:6508fa5521e0 2 *
bcostm 0:6508fa5521e0 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
bcostm 0:6508fa5521e0 4 * and associated documentation files (the "Software"), to deal in the Software without
bcostm 0:6508fa5521e0 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
bcostm 0:6508fa5521e0 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
bcostm 0:6508fa5521e0 7 * Software is furnished to do so, subject to the following conditions:
bcostm 0:6508fa5521e0 8 *
bcostm 0:6508fa5521e0 9 * The above copyright notice and this permission notice shall be included in all copies or
bcostm 0:6508fa5521e0 10 * substantial portions of the Software.
bcostm 0:6508fa5521e0 11 *
bcostm 0:6508fa5521e0 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
bcostm 0:6508fa5521e0 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
bcostm 0:6508fa5521e0 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
bcostm 0:6508fa5521e0 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
bcostm 0:6508fa5521e0 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
bcostm 0:6508fa5521e0 17 */
bcostm 0:6508fa5521e0 18
bcostm 0:6508fa5521e0 19 #ifndef __COMPASS_DISCO_L476VG_H
bcostm 0:6508fa5521e0 20 #define __COMPASS_DISCO_L476VG_H
bcostm 0:6508fa5521e0 21
bcostm 0:6508fa5521e0 22 #ifdef TARGET_DISCO_L476VG
bcostm 0:6508fa5521e0 23
bcostm 0:6508fa5521e0 24 #include "mbed.h"
bcostm 0:6508fa5521e0 25 #include "stm32l476g_discovery_compass.h"
bcostm 0:6508fa5521e0 26
bcostm 0:6508fa5521e0 27 /*
bcostm 0:6508fa5521e0 28 Class to drive the Compass (LSM303 device with Accelerometer and Magnetometer)
bcostm 0:6508fa5521e0 29 present on DISCO_L476VG board.
bcostm 0:6508fa5521e0 30
bcostm 0:6508fa5521e0 31 Usage:
bcostm 0:6508fa5521e0 32
bcostm 0:6508fa5521e0 33 #include "mbed.h"
bcostm 0:6508fa5521e0 34 #include "COMPASS_DISCO_L476VG.h"
bcostm 0:6508fa5521e0 35
bcostm 0:6508fa5521e0 36 COMPASS_DISCO_L476VG compass;
bcostm 0:6508fa5521e0 37
bcostm 0:6508fa5521e0 38 int main()
bcostm 0:6508fa5521e0 39 {
bcostm 0:6508fa5521e0 40 int16_t MagBuffer[3];
bcostm 0:6508fa5521e0 41 int16_t AccBuffer[3];
bcostm 0:6508fa5521e0 42 while(1)
bcostm 0:6508fa5521e0 43 {
bcostm 0:6508fa5521e0 44 // Read acceleremoter and magnetometer values
bcostm 0:6508fa5521e0 45 compass.AccGetXYZ(AccBuffer);
bcostm 0:6508fa5521e0 46 compass.MagGetXYZ(MagBuffer);
bcostm 0:6508fa5521e0 47 // Display values
bcostm 0:6508fa5521e0 48 printf("Acc X = %d\n", AccBuffer[0]);
bcostm 0:6508fa5521e0 49 printf("Acc Y = %d\n", AccBuffer[1]);
bcostm 0:6508fa5521e0 50 printf("Acc Z = %d\n", AccBuffer[2]);
bcostm 0:6508fa5521e0 51 printf("Mag X = %d\n", MagBuffer[0]);
bcostm 0:6508fa5521e0 52 printf("Mag Y = %d\n", MagBuffer[1]);
bcostm 0:6508fa5521e0 53 printf("Mag Z = %d\n", MagBuffer[2]);
bcostm 0:6508fa5521e0 54 }
bcostm 0:6508fa5521e0 55 }
bcostm 0:6508fa5521e0 56 */
bcostm 0:6508fa5521e0 57 class COMPASS_DISCO_L476VG
bcostm 0:6508fa5521e0 58 {
bcostm 0:6508fa5521e0 59
bcostm 0:6508fa5521e0 60 public:
bcostm 0:6508fa5521e0 61 //! Constructor
bcostm 0:6508fa5521e0 62 COMPASS_DISCO_L476VG();
bcostm 0:6508fa5521e0 63
bcostm 0:6508fa5521e0 64 //! Destructor
bcostm 0:6508fa5521e0 65 ~COMPASS_DISCO_L476VG();
bcostm 0:6508fa5521e0 66
bcostm 0:6508fa5521e0 67 /**
bcostm 0:6508fa5521e0 68 * @brief Initialize the COMPASS.
bcostm 0:6508fa5521e0 69 * @retval COMPASS_OK or COMPASS_ERROR
bcostm 0:6508fa5521e0 70 */
bcostm 0:6508fa5521e0 71 COMPASS_StatusTypeDef Init(void);
bcostm 0:6508fa5521e0 72
bcostm 0:6508fa5521e0 73 /**
bcostm 0:6508fa5521e0 74 * @brief DeInitialize the COMPASS.
bcostm 0:6508fa5521e0 75 * @retval None.
bcostm 0:6508fa5521e0 76 */
bcostm 0:6508fa5521e0 77 void DeInit(void);
bcostm 0:6508fa5521e0 78
bcostm 0:6508fa5521e0 79 /**
bcostm 0:6508fa5521e0 80 * @brief Put the COMPASS in low power mode.
bcostm 0:6508fa5521e0 81 * @retval None
bcostm 0:6508fa5521e0 82 */
bcostm 0:6508fa5521e0 83 void LowPower(void);
bcostm 0:6508fa5521e0 84
bcostm 0:6508fa5521e0 85 /**
bcostm 0:6508fa5521e0 86 * @brief Get XYZ acceleration values.
bcostm 0:6508fa5521e0 87 * @param pDataXYZ Pointer on 3 angular accelerations table with
bcostm 0:6508fa5521e0 88 * pDataXYZ[0] = X axis, pDataXYZ[1] = Y axis, pDataXYZ[2] = Z axis
bcostm 0:6508fa5521e0 89 * @retval None
bcostm 0:6508fa5521e0 90 */
bcostm 0:6508fa5521e0 91 void AccGetXYZ(int16_t *pDataXYZ);
bcostm 0:6508fa5521e0 92
bcostm 0:6508fa5521e0 93 /**
bcostm 0:6508fa5521e0 94 * @brief Get XYZ magnetometer values.
bcostm 0:6508fa5521e0 95 * @param pDataXYZ Pointer on 3 magnetometer values table with
bcostm 0:6508fa5521e0 96 * pDataXYZ[0] = X axis, pDataXYZ[1] = Y axis, pDataXYZ[2] = Z axis
bcostm 0:6508fa5521e0 97 * @retval None
bcostm 0:6508fa5521e0 98 */
bcostm 0:6508fa5521e0 99 void MagGetXYZ(int16_t *pDataXYZ);
bcostm 0:6508fa5521e0 100
bcostm 0:6508fa5521e0 101 private:
bcostm 0:6508fa5521e0 102
bcostm 0:6508fa5521e0 103 };
bcostm 0:6508fa5521e0 104
bcostm 0:6508fa5521e0 105 #else
bcostm 0:6508fa5521e0 106 #error "This class must be used with DISCO_L476VG board only."
bcostm 0:6508fa5521e0 107 #endif // TARGET_DISCO_L476VG
bcostm 0:6508fa5521e0 108
bcostm 0:6508fa5521e0 109 #endif