Class to drive the Gyroscope (L3GD20 device) present on DISCO_L476VG board.

Dependents:   DISCO_L476VG_Gyro DISCO_L476VG_AccGy1 DISCO_AcGy1_OK DISCO_L476VG_AccGy2 ... more

Committer:
bcostm
Date:
Thu Sep 24 06:56:41 2015 +0000
Revision:
0:9dc4ecb46a75
Initial version.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:9dc4ecb46a75 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
bcostm 0:9dc4ecb46a75 2 *
bcostm 0:9dc4ecb46a75 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
bcostm 0:9dc4ecb46a75 4 * and associated documentation files (the "Software"), to deal in the Software without
bcostm 0:9dc4ecb46a75 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
bcostm 0:9dc4ecb46a75 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
bcostm 0:9dc4ecb46a75 7 * Software is furnished to do so, subject to the following conditions:
bcostm 0:9dc4ecb46a75 8 *
bcostm 0:9dc4ecb46a75 9 * The above copyright notice and this permission notice shall be included in all copies or
bcostm 0:9dc4ecb46a75 10 * substantial portions of the Software.
bcostm 0:9dc4ecb46a75 11 *
bcostm 0:9dc4ecb46a75 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
bcostm 0:9dc4ecb46a75 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
bcostm 0:9dc4ecb46a75 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
bcostm 0:9dc4ecb46a75 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
bcostm 0:9dc4ecb46a75 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
bcostm 0:9dc4ecb46a75 17 */
bcostm 0:9dc4ecb46a75 18
bcostm 0:9dc4ecb46a75 19 #ifndef __GYRO_DISCO_L476VG_H
bcostm 0:9dc4ecb46a75 20 #define __GYRO_DISCO_L476VG_H
bcostm 0:9dc4ecb46a75 21
bcostm 0:9dc4ecb46a75 22 #ifdef TARGET_DISCO_L476VG
bcostm 0:9dc4ecb46a75 23
bcostm 0:9dc4ecb46a75 24 #include "mbed.h"
bcostm 0:9dc4ecb46a75 25 #include "stm32l476g_discovery_gyroscope.h"
bcostm 0:9dc4ecb46a75 26
bcostm 0:9dc4ecb46a75 27 /*
bcostm 0:9dc4ecb46a75 28 Class to drive the Gyroscope (L3GD20 device)
bcostm 0:9dc4ecb46a75 29 present on DISCO_L476VG board.
bcostm 0:9dc4ecb46a75 30
bcostm 0:9dc4ecb46a75 31 Usage:
bcostm 0:9dc4ecb46a75 32
bcostm 0:9dc4ecb46a75 33 #include "mbed.h"
bcostm 0:9dc4ecb46a75 34 #include "GYRO_DISCO_L476VG.h"
bcostm 0:9dc4ecb46a75 35
bcostm 0:9dc4ecb46a75 36 GYRO_DISCO_L476VG gyro;
bcostm 0:9dc4ecb46a75 37
bcostm 0:9dc4ecb46a75 38 int main()
bcostm 0:9dc4ecb46a75 39 {
bcostm 0:9dc4ecb46a75 40 float GyroBuffer[3];
bcostm 0:9dc4ecb46a75 41 while(1) {
bcostm 0:9dc4ecb46a75 42 // Read Gyroscope values
bcostm 0:9dc4ecb46a75 43 gyro.GetXYZ(GyroBuffer);
bcostm 0:9dc4ecb46a75 44 // Display values
bcostm 0:9dc4ecb46a75 45 printf("X = %f\n", GyroBuffer[0]);
bcostm 0:9dc4ecb46a75 46 printf("Y = %f\n", GyroBuffer[1]);
bcostm 0:9dc4ecb46a75 47 printf("Z = %f\n", GyroBuffer[2]);
bcostm 0:9dc4ecb46a75 48 wait(1);
bcostm 0:9dc4ecb46a75 49 }
bcostm 0:9dc4ecb46a75 50 }
bcostm 0:9dc4ecb46a75 51 */
bcostm 0:9dc4ecb46a75 52 class GYRO_DISCO_L476VG
bcostm 0:9dc4ecb46a75 53 {
bcostm 0:9dc4ecb46a75 54
bcostm 0:9dc4ecb46a75 55 public:
bcostm 0:9dc4ecb46a75 56 //! Constructor
bcostm 0:9dc4ecb46a75 57 GYRO_DISCO_L476VG();
bcostm 0:9dc4ecb46a75 58
bcostm 0:9dc4ecb46a75 59 //! Destructor
bcostm 0:9dc4ecb46a75 60 ~GYRO_DISCO_L476VG();
bcostm 0:9dc4ecb46a75 61
bcostm 0:9dc4ecb46a75 62 /**
bcostm 0:9dc4ecb46a75 63 * @brief Initialize Gyroscope.
bcostm 0:9dc4ecb46a75 64 * @retval GYRO_OK or GYRO_ERROR
bcostm 0:9dc4ecb46a75 65 */
bcostm 0:9dc4ecb46a75 66 uint8_t Init(void);
bcostm 0:9dc4ecb46a75 67
bcostm 0:9dc4ecb46a75 68 /**
bcostm 0:9dc4ecb46a75 69 * @brief DeInitialize Gyroscope.
bcostm 0:9dc4ecb46a75 70 * @retval None
bcostm 0:9dc4ecb46a75 71 */
bcostm 0:9dc4ecb46a75 72 void DeInit(void);
bcostm 0:9dc4ecb46a75 73
bcostm 0:9dc4ecb46a75 74 /**
bcostm 0:9dc4ecb46a75 75 * @brief Put Gyroscope in low power mode.
bcostm 0:9dc4ecb46a75 76 * @retval None
bcostm 0:9dc4ecb46a75 77 */
bcostm 0:9dc4ecb46a75 78 void LowPower(void);
bcostm 0:9dc4ecb46a75 79
bcostm 0:9dc4ecb46a75 80 /**
bcostm 0:9dc4ecb46a75 81 * @brief Reboot memory content of Gyroscope.
bcostm 0:9dc4ecb46a75 82 * @retval None
bcostm 0:9dc4ecb46a75 83 */
bcostm 0:9dc4ecb46a75 84 void Reset(void);
bcostm 0:9dc4ecb46a75 85
bcostm 0:9dc4ecb46a75 86 /**
bcostm 0:9dc4ecb46a75 87 * @brief Read ID of Gyroscope component.
bcostm 0:9dc4ecb46a75 88 * @retval ID
bcostm 0:9dc4ecb46a75 89 */
bcostm 0:9dc4ecb46a75 90 uint8_t ReadID(void);
bcostm 0:9dc4ecb46a75 91
bcostm 0:9dc4ecb46a75 92 /**
bcostm 0:9dc4ecb46a75 93 * @brief Configure Gyroscope interrupts (INT1 or INT2).
bcostm 0:9dc4ecb46a75 94 * @param pIntConfig: pointer to a GYRO_InterruptConfigTypeDef
bcostm 0:9dc4ecb46a75 95 * structure that contains the configuration setting for the L3GD20 Interrupt.
bcostm 0:9dc4ecb46a75 96 * @retval None
bcostm 0:9dc4ecb46a75 97 */
bcostm 0:9dc4ecb46a75 98 void ITConfig(GYRO_InterruptConfigTypeDef *pIntConfigStruct);
bcostm 0:9dc4ecb46a75 99
bcostm 0:9dc4ecb46a75 100 /**
bcostm 0:9dc4ecb46a75 101 * @brief Enable Gyroscope interrupts (INT1 or INT2).
bcostm 0:9dc4ecb46a75 102 * @param IntPin: Interrupt pin
bcostm 0:9dc4ecb46a75 103 * This parameter can be:
bcostm 0:9dc4ecb46a75 104 * @arg L3GD20_INT1
bcostm 0:9dc4ecb46a75 105 * @arg L3GD20_INT2
bcostm 0:9dc4ecb46a75 106 * @retval None
bcostm 0:9dc4ecb46a75 107 */
bcostm 0:9dc4ecb46a75 108 void EnableIT(uint8_t IntPin);
bcostm 0:9dc4ecb46a75 109
bcostm 0:9dc4ecb46a75 110 /**
bcostm 0:9dc4ecb46a75 111 * @brief Disable Gyroscope interrupts (INT1 or INT2).
bcostm 0:9dc4ecb46a75 112 * @param IntPin: Interrupt pin
bcostm 0:9dc4ecb46a75 113 * This parameter can be:
bcostm 0:9dc4ecb46a75 114 * @arg L3GD20_INT1
bcostm 0:9dc4ecb46a75 115 * @arg L3GD20_INT2
bcostm 0:9dc4ecb46a75 116 * @retval None
bcostm 0:9dc4ecb46a75 117 */
bcostm 0:9dc4ecb46a75 118 void DisableIT(uint8_t IntPin);
bcostm 0:9dc4ecb46a75 119
bcostm 0:9dc4ecb46a75 120 /**
bcostm 0:9dc4ecb46a75 121 * @brief Get XYZ angular acceleration from the Gyroscope.
bcostm 0:9dc4ecb46a75 122 * @param pfData: pointer on floating array
bcostm 0:9dc4ecb46a75 123 * @retval None
bcostm 0:9dc4ecb46a75 124 */
bcostm 0:9dc4ecb46a75 125 void GetXYZ(float* pfData);
bcostm 0:9dc4ecb46a75 126
bcostm 0:9dc4ecb46a75 127 private:
bcostm 0:9dc4ecb46a75 128
bcostm 0:9dc4ecb46a75 129 };
bcostm 0:9dc4ecb46a75 130
bcostm 0:9dc4ecb46a75 131 #else
bcostm 0:9dc4ecb46a75 132 #error "This class must be used with DISCO_L476VG board only."
bcostm 0:9dc4ecb46a75 133 #endif // TARGET_DISCO_L476VG
bcostm 0:9dc4ecb46a75 134
bcostm 0:9dc4ecb46a75 135 #endif