Example for Bluetooth low energy interface
Dependencies: mbed HC_SR04_Ultrasonic_Library
Sensor_Shield/x_nucleo_iks01a1_magneto.c@3:829f081fde15, 2015-05-19 (annotated)
- Committer:
- julientiron
- Date:
- Tue May 19 20:42:25 2015 +0000
- Revision:
- 3:829f081fde15
- Parent:
- 1:bdbf36f8408d
hihi;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
julientiron | 1:bdbf36f8408d | 1 | /** |
julientiron | 1:bdbf36f8408d | 2 | ****************************************************************************** |
julientiron | 1:bdbf36f8408d | 3 | * @file x_nucleo_iks01a1_magneto.c |
julientiron | 1:bdbf36f8408d | 4 | * @author MEMS Application Team |
julientiron | 1:bdbf36f8408d | 5 | * @version V1.0.0 |
julientiron | 1:bdbf36f8408d | 6 | * @date 30-July-2014 |
julientiron | 1:bdbf36f8408d | 7 | * @brief This file provides a set of functions needed to manage the lis3mdl sensor. |
julientiron | 1:bdbf36f8408d | 8 | ****************************************************************************** |
julientiron | 1:bdbf36f8408d | 9 | * @attention |
julientiron | 1:bdbf36f8408d | 10 | * |
julientiron | 1:bdbf36f8408d | 11 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
julientiron | 1:bdbf36f8408d | 12 | * |
julientiron | 1:bdbf36f8408d | 13 | * Redistribution and use in source and binary forms, with or without modification, |
julientiron | 1:bdbf36f8408d | 14 | * are permitted provided that the following conditions are met: |
julientiron | 1:bdbf36f8408d | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
julientiron | 1:bdbf36f8408d | 16 | * this list of conditions and the following disclaimer. |
julientiron | 1:bdbf36f8408d | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
julientiron | 1:bdbf36f8408d | 18 | * this list of conditions and the following disclaimer in the documentation |
julientiron | 1:bdbf36f8408d | 19 | * and/or other materials provided with the distribution. |
julientiron | 1:bdbf36f8408d | 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
julientiron | 1:bdbf36f8408d | 21 | * may be used to endorse or promote products derived from this software |
julientiron | 1:bdbf36f8408d | 22 | * without specific prior written permission. |
julientiron | 1:bdbf36f8408d | 23 | * |
julientiron | 1:bdbf36f8408d | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
julientiron | 1:bdbf36f8408d | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
julientiron | 1:bdbf36f8408d | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
julientiron | 1:bdbf36f8408d | 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
julientiron | 1:bdbf36f8408d | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
julientiron | 1:bdbf36f8408d | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
julientiron | 1:bdbf36f8408d | 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
julientiron | 1:bdbf36f8408d | 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
julientiron | 1:bdbf36f8408d | 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
julientiron | 1:bdbf36f8408d | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
julientiron | 1:bdbf36f8408d | 34 | * |
julientiron | 1:bdbf36f8408d | 35 | ****************************************************************************** |
julientiron | 1:bdbf36f8408d | 36 | */ |
julientiron | 1:bdbf36f8408d | 37 | /* Includes ------------------------------------------------------------------*/ |
julientiron | 1:bdbf36f8408d | 38 | #include "x_nucleo_iks01a1_magneto.h" |
julientiron | 1:bdbf36f8408d | 39 | |
julientiron | 1:bdbf36f8408d | 40 | /** @addtogroup BSP |
julientiron | 1:bdbf36f8408d | 41 | * @{ |
julientiron | 1:bdbf36f8408d | 42 | */ |
julientiron | 1:bdbf36f8408d | 43 | |
julientiron | 1:bdbf36f8408d | 44 | /** @addtogroup X_NUCLEO_IKS01A1 |
julientiron | 1:bdbf36f8408d | 45 | * @{ |
julientiron | 1:bdbf36f8408d | 46 | */ |
julientiron | 1:bdbf36f8408d | 47 | |
julientiron | 1:bdbf36f8408d | 48 | /** @addtogroup X_NUCLEO_IKS01A1_MAGNETO |
julientiron | 1:bdbf36f8408d | 49 | * @{ |
julientiron | 1:bdbf36f8408d | 50 | */ |
julientiron | 1:bdbf36f8408d | 51 | |
julientiron | 1:bdbf36f8408d | 52 | /** @defgroup X_NUCLEO_IKS01A1_MAGNETO_Private_TypesDefinitions |
julientiron | 1:bdbf36f8408d | 53 | * @{ |
julientiron | 1:bdbf36f8408d | 54 | */ |
julientiron | 1:bdbf36f8408d | 55 | |
julientiron | 1:bdbf36f8408d | 56 | /** |
julientiron | 1:bdbf36f8408d | 57 | * @} |
julientiron | 1:bdbf36f8408d | 58 | */ |
julientiron | 1:bdbf36f8408d | 59 | |
julientiron | 1:bdbf36f8408d | 60 | /** @defgroup X_NUCLEO_IKS01A1_MAGNETO_Private_Defines |
julientiron | 1:bdbf36f8408d | 61 | * @{ |
julientiron | 1:bdbf36f8408d | 62 | */ |
julientiron | 1:bdbf36f8408d | 63 | |
julientiron | 1:bdbf36f8408d | 64 | /** |
julientiron | 1:bdbf36f8408d | 65 | * @} |
julientiron | 1:bdbf36f8408d | 66 | */ |
julientiron | 1:bdbf36f8408d | 67 | |
julientiron | 1:bdbf36f8408d | 68 | /** @defgroup X_NUCLEO_IKS01A1_MAGNETO_Private_Macros |
julientiron | 1:bdbf36f8408d | 69 | * @{ |
julientiron | 1:bdbf36f8408d | 70 | */ |
julientiron | 1:bdbf36f8408d | 71 | |
julientiron | 1:bdbf36f8408d | 72 | /** |
julientiron | 1:bdbf36f8408d | 73 | * @} |
julientiron | 1:bdbf36f8408d | 74 | */ |
julientiron | 1:bdbf36f8408d | 75 | |
julientiron | 1:bdbf36f8408d | 76 | /** @defgroup X_NUCLEO_IKS01A1_MAGNETO_Private_Variables |
julientiron | 1:bdbf36f8408d | 77 | * @{ |
julientiron | 1:bdbf36f8408d | 78 | */ |
julientiron | 1:bdbf36f8408d | 79 | static MAGNETO_DrvTypeDef *MagnetoDrv; |
julientiron | 1:bdbf36f8408d | 80 | static uint8_t MagnetoInitialized = 0; |
julientiron | 1:bdbf36f8408d | 81 | |
julientiron | 1:bdbf36f8408d | 82 | /** |
julientiron | 1:bdbf36f8408d | 83 | * @} |
julientiron | 1:bdbf36f8408d | 84 | */ |
julientiron | 1:bdbf36f8408d | 85 | |
julientiron | 1:bdbf36f8408d | 86 | /** @defgroup X_NUCLEO_IKS01A1_MAGNETO_Private_FunctionPrototypes |
julientiron | 1:bdbf36f8408d | 87 | * @{ |
julientiron | 1:bdbf36f8408d | 88 | */ |
julientiron | 1:bdbf36f8408d | 89 | |
julientiron | 1:bdbf36f8408d | 90 | /** |
julientiron | 1:bdbf36f8408d | 91 | * @} |
julientiron | 1:bdbf36f8408d | 92 | */ |
julientiron | 1:bdbf36f8408d | 93 | |
julientiron | 1:bdbf36f8408d | 94 | /** @defgroup X_NUCLEO_IKS01A1_MAGNETO_Private_Functions |
julientiron | 1:bdbf36f8408d | 95 | * @{ |
julientiron | 1:bdbf36f8408d | 96 | */ |
julientiron | 1:bdbf36f8408d | 97 | |
julientiron | 1:bdbf36f8408d | 98 | /** |
julientiron | 1:bdbf36f8408d | 99 | * @brief Initialization magneto sensor. |
julientiron | 1:bdbf36f8408d | 100 | * @param None |
julientiron | 1:bdbf36f8408d | 101 | * @retval MAGNETO_OK if no problem during initialization |
julientiron | 1:bdbf36f8408d | 102 | */ |
julientiron | 1:bdbf36f8408d | 103 | MAGNETO_StatusTypeDef BSP_MAGNETO_Init(void) |
julientiron | 1:bdbf36f8408d | 104 | { |
julientiron | 1:bdbf36f8408d | 105 | MAGNETO_StatusTypeDef ret = MAGNETO_ERROR; |
julientiron | 1:bdbf36f8408d | 106 | MAGNETO_InitTypeDef LIS3MDL_InitStructure; |
julientiron | 1:bdbf36f8408d | 107 | |
julientiron | 1:bdbf36f8408d | 108 | /* Initialize the magneto driver structure */ |
julientiron | 1:bdbf36f8408d | 109 | MagnetoDrv = &LIS3MDLDrv; |
julientiron | 1:bdbf36f8408d | 110 | |
julientiron | 1:bdbf36f8408d | 111 | /* Configure sensor */ |
julientiron | 1:bdbf36f8408d | 112 | LIS3MDL_InitStructure.M_FullScale = LIS3MDL_M_FS_4; |
julientiron | 1:bdbf36f8408d | 113 | LIS3MDL_InitStructure.M_OperatingMode = LIS3MDL_M_MD_CONTINUOUS; |
julientiron | 1:bdbf36f8408d | 114 | LIS3MDL_InitStructure.M_XYOperativeMode = LIS3MDL_M_OM_HP; |
julientiron | 1:bdbf36f8408d | 115 | LIS3MDL_InitStructure.M_OutputDataRate = LIS3MDL_M_DO_80; |
julientiron | 1:bdbf36f8408d | 116 | |
julientiron | 1:bdbf36f8408d | 117 | /* magneto sensor init */ |
julientiron | 1:bdbf36f8408d | 118 | MagnetoDrv->Init(&LIS3MDL_InitStructure); |
julientiron | 1:bdbf36f8408d | 119 | |
julientiron | 1:bdbf36f8408d | 120 | if(MagnetoDrv->Read_M_ID() == I_AM_LIS3MDL_M) |
julientiron | 1:bdbf36f8408d | 121 | { |
julientiron | 1:bdbf36f8408d | 122 | MagnetoInitialized = 1; |
julientiron | 1:bdbf36f8408d | 123 | ret = MAGNETO_OK; |
julientiron | 1:bdbf36f8408d | 124 | } |
julientiron | 1:bdbf36f8408d | 125 | |
julientiron | 1:bdbf36f8408d | 126 | return ret; |
julientiron | 1:bdbf36f8408d | 127 | } |
julientiron | 1:bdbf36f8408d | 128 | |
julientiron | 1:bdbf36f8408d | 129 | |
julientiron | 1:bdbf36f8408d | 130 | uint8_t BSP_MAGNETO_isInitialized(void) |
julientiron | 1:bdbf36f8408d | 131 | { |
julientiron | 1:bdbf36f8408d | 132 | return MagnetoInitialized; |
julientiron | 1:bdbf36f8408d | 133 | } |
julientiron | 1:bdbf36f8408d | 134 | |
julientiron | 1:bdbf36f8408d | 135 | |
julientiron | 1:bdbf36f8408d | 136 | /** |
julientiron | 1:bdbf36f8408d | 137 | * @brief Read ID of LIS3MDL Magnetic sensor |
julientiron | 1:bdbf36f8408d | 138 | * @param None |
julientiron | 1:bdbf36f8408d | 139 | * @retval ID |
julientiron | 1:bdbf36f8408d | 140 | */ |
julientiron | 1:bdbf36f8408d | 141 | uint8_t BSP_MAGNETO_Read_M_ID(void) |
julientiron | 1:bdbf36f8408d | 142 | { |
julientiron | 1:bdbf36f8408d | 143 | uint8_t id = 0x00; |
julientiron | 1:bdbf36f8408d | 144 | |
julientiron | 1:bdbf36f8408d | 145 | if(MagnetoDrv->Read_M_ID != NULL) |
julientiron | 1:bdbf36f8408d | 146 | { |
julientiron | 1:bdbf36f8408d | 147 | id = MagnetoDrv->Read_M_ID(); |
julientiron | 1:bdbf36f8408d | 148 | } |
julientiron | 1:bdbf36f8408d | 149 | return id; |
julientiron | 1:bdbf36f8408d | 150 | } |
julientiron | 1:bdbf36f8408d | 151 | |
julientiron | 1:bdbf36f8408d | 152 | |
julientiron | 1:bdbf36f8408d | 153 | /** |
julientiron | 1:bdbf36f8408d | 154 | * @brief Check ID of LIS3MDL Magnetic sensor |
julientiron | 1:bdbf36f8408d | 155 | * @param None |
julientiron | 1:bdbf36f8408d | 156 | * @retval Test status |
julientiron | 1:bdbf36f8408d | 157 | */ |
julientiron | 1:bdbf36f8408d | 158 | MAGNETO_StatusTypeDef BSP_MAGNETO_Check_M_ID(void) { |
julientiron | 1:bdbf36f8408d | 159 | if (BSP_MAGNETO_Read_M_ID() == I_AM_LIS3MDL_M) { |
julientiron | 1:bdbf36f8408d | 160 | return MAGNETO_OK; |
julientiron | 1:bdbf36f8408d | 161 | } else { |
julientiron | 1:bdbf36f8408d | 162 | return MAGNETO_ERROR; |
julientiron | 1:bdbf36f8408d | 163 | } |
julientiron | 1:bdbf36f8408d | 164 | } |
julientiron | 1:bdbf36f8408d | 165 | |
julientiron | 1:bdbf36f8408d | 166 | |
julientiron | 1:bdbf36f8408d | 167 | /** |
julientiron | 1:bdbf36f8408d | 168 | * @brief Get Magnetic sensor raw axes |
julientiron | 1:bdbf36f8408d | 169 | * @param pData: pointer on AxesRaw_TypeDef data |
julientiron | 1:bdbf36f8408d | 170 | * @retval None |
julientiron | 1:bdbf36f8408d | 171 | */ |
julientiron | 1:bdbf36f8408d | 172 | void BSP_MAGNETO_M_GetAxesRaw(AxesRaw_TypeDef *pData) |
julientiron | 1:bdbf36f8408d | 173 | { |
julientiron | 1:bdbf36f8408d | 174 | if(MagnetoDrv->Get_M_Axes!= NULL) |
julientiron | 1:bdbf36f8408d | 175 | { |
julientiron | 1:bdbf36f8408d | 176 | MagnetoDrv->Get_M_Axes((int32_t *)pData); |
julientiron | 1:bdbf36f8408d | 177 | } |
julientiron | 1:bdbf36f8408d | 178 | } |
julientiron | 1:bdbf36f8408d | 179 | |
julientiron | 1:bdbf36f8408d | 180 | /** |
julientiron | 1:bdbf36f8408d | 181 | * @} |
julientiron | 1:bdbf36f8408d | 182 | */ |
julientiron | 1:bdbf36f8408d | 183 | |
julientiron | 1:bdbf36f8408d | 184 | /** |
julientiron | 1:bdbf36f8408d | 185 | * @} |
julientiron | 1:bdbf36f8408d | 186 | */ |
julientiron | 1:bdbf36f8408d | 187 | |
julientiron | 1:bdbf36f8408d | 188 | /** |
julientiron | 1:bdbf36f8408d | 189 | * @} |
julientiron | 1:bdbf36f8408d | 190 | */ |
julientiron | 1:bdbf36f8408d | 191 | |
julientiron | 1:bdbf36f8408d | 192 | /** |
julientiron | 1:bdbf36f8408d | 193 | * @} |
julientiron | 1:bdbf36f8408d | 194 | */ |
julientiron | 1:bdbf36f8408d | 195 | |
julientiron | 1:bdbf36f8408d | 196 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
julientiron | 1:bdbf36f8408d | 197 |