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