Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
uvis3.c
00001 /** 00002 ****************************************************************************** 00003 * @file uvis3.c 00004 * @author AST Robotics Team 00005 * @version V0.0.1 00006 * @date 10-March-2014 00007 * @brief This file provides a set of functions needed to manage the uvis3. 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> 00012 * 00013 * Redistribution and use in source and binary forms, with or without modification, 00014 * are permitted provided that the following conditions are met: 00015 * 1. Redistributions of source code must retain the above copyright notice, 00016 * this list of conditions and the following disclaimer. 00017 * 2. Redistributions in binary form must reproduce the above copyright notice, 00018 * this list of conditions and the following disclaimer in the documentation 00019 * and/or other materials provided with the distribution. 00020 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00021 * may be used to endorse or promote products derived from this software 00022 * without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00025 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00026 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00028 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00029 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00030 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00032 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00033 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 ****************************************************************************** 00036 */ 00037 /* Includes ------------------------------------------------------------------*/ 00038 #include "uvis3.h" 00039 00040 /** @addtogroup BSP 00041 * @{ 00042 */ 00043 00044 /** @addtogroup STM32F439_SENSITRON 00045 * @{ 00046 */ 00047 00048 /** @addtogroup UVIS3 00049 * @{ 00050 */ 00051 00052 00053 /** @defgroup UVIS3_Private_TypesDefinitions 00054 * @{ 00055 */ 00056 00057 /** 00058 * @} 00059 */ 00060 00061 /** @defgroup UVIS3_Private_Defines 00062 * @{ 00063 */ 00064 00065 /** 00066 * @} 00067 */ 00068 00069 /** @defgroup UVIS3_Private_Macros 00070 * @{ 00071 */ 00072 00073 /** 00074 * @} 00075 */ 00076 00077 /** @defgroup UVIS3_Private_Variables 00078 * @{ 00079 */ 00080 00081 UV_DrvTypeDef Uvis3Drv = 00082 { 00083 UVIS3_Init, 00084 UVIS3_ReadID, 00085 UVIS3_RebootCmd, 00086 0,//UVIS3_INT1InterruptConfig, 00087 0,//UVIS3_EnableIT, 00088 0,//UVIS3_DisableIT, 00089 0, 00090 0, 00091 UVIS3_GetIndex 00092 }; 00093 /** 00094 * @} 00095 */ 00096 00097 /** @defgroup UVIS3_Private_FunctionPrototypes 00098 * @{ 00099 */ 00100 00101 /** 00102 * @} 00103 */ 00104 00105 /** @defgroup UVIS3_Private_Functions 00106 * @{ 00107 */ 00108 00109 /** 00110 * @brief Set UVIS3 Initialization. 00111 * @param InitStruct: it contains the configuration setting for the UVIS3. 00112 * @retval None 00113 */ 00114 void UVIS3_Init(UV_InitTypeDef *UVIS3_Init) 00115 { 00116 uint8_t ctrl = 0x00; 00117 00118 /* Configure the low level interface ---------------------------------------*/ 00119 UV_IO_Init(); 00120 00121 /* Read CTRL_REG1 register */ 00122 UV_IO_Read(&ctrl, UVIS3_ADDRESS, UVIS3_CTRL_REG1_ADDR, 1); 00123 00124 /* Power Mode selection */ 00125 ctrl &= ~(UVIS3_MODE_MASK); 00126 ctrl |= UVIS3_Init->Power_Mode; 00127 00128 // if(UVIS3_Init->Power_Mode==UVIS3_MODE_POWERDOWN) { 00129 // ctrl |= 0x80; 00130 // } else { 00131 // ctrl &= 0x7F; 00132 // } 00133 00134 /* Data Rate selection */ 00135 ctrl &= ~(UVIS3_ODR_MASK); 00136 ctrl |= UVIS3_Init->Output_DataRate; 00137 00138 // if(UVIS3_Init->Output_DataRate==UVIS3_ODR_1HZ) { 00139 // ctrl |= 0x01; 00140 // } else { 00141 // ctrl &= 0xFE; 00142 // } 00143 00144 /* Write value to MEMS CTRL_REG1 regsister */ 00145 UV_IO_Write(&ctrl, UVIS3_ADDRESS, UVIS3_CTRL_REG1_ADDR, 1); 00146 00147 /* Write value to MEMS CTRL_REG2 regsister ??*/ 00148 //ctrl = (uint8_t) InitStruct>>8; 00149 //UV_IO_Write(&ctrl, UVIS3_CTRL_REG2_ADDR, 1); 00150 } 00151 00152 /** 00153 * @brief Read ID address of UVIS3 00154 * @param Device ID address 00155 * @retval ID name 00156 */ 00157 uint8_t UVIS3_ReadID(void) 00158 { 00159 uint8_t tmp; 00160 00161 /* Read WHO I AM register */ 00162 UV_IO_Read(&tmp, UVIS3_ADDRESS, UVIS3_WHO_AM_I_ADDR, 1); 00163 00164 /* Return the ID */ 00165 return (uint8_t)tmp; 00166 } 00167 00168 /** 00169 * @brief Reboot memory content of UVIS3 00170 * @param None 00171 * @retval None 00172 */ 00173 void UVIS3_RebootCmd(void) 00174 { 00175 uint8_t tmpreg; 00176 00177 /* Read CTRL_REG5 register */ 00178 UV_IO_Read(&tmpreg, UVIS3_ADDRESS, UVIS3_CTRL_REG2_ADDR, 1); 00179 00180 /* Enable or Disable the reboot memory */ 00181 tmpreg |= UVIS3_BOOT_REBOOTMEMORY; 00182 00183 /* Write value to MEMS CTRL_REG5 regsister */ 00184 UV_IO_Write(&tmpreg, UVIS3_ADDRESS, UVIS3_CTRL_REG2_ADDR, 1); 00185 } 00186 00187 /** 00188 * @brief Set UVIS3 Interrupt INT1 configuration 00189 * @param UVIS3_InterruptConfig_TypeDef: pointer to a UVIS3_InterruptConfig_TypeDef 00190 * structure that contains the configuration setting for the UVIS3 Interrupt. 00191 * @retval None 00192 */ 00193 void UVIS3_INT1InterruptConfig(uint16_t Int1Config) 00194 { 00195 00196 } 00197 00198 /** 00199 * @brief Enable INT1 00200 * @retval None 00201 */ 00202 void UVIS3_EnableIT() 00203 { 00204 00205 } 00206 00207 /** 00208 * @brief Disable INT1 00209 * @retval None 00210 */ 00211 void UVIS3_DisableIT() 00212 { 00213 00214 } 00215 00216 00217 /** 00218 * @brief Calculate the UVIS3 UV index data. 00219 * @param pfData : Data out pointer 00220 * @retval None 00221 */ 00222 void UVIS3_GetIndex(float* pfData) 00223 { 00224 uint8_t tmpreg; 00225 /* Read UVIS3_UVDATA_OUT_ADDR register */ 00226 UV_IO_Read(&tmpreg, UVIS3_ADDRESS, UVIS3_UVDATA_OUT_ADDR, 1); 00227 //tmpreg=32; 00228 *pfData=(float)tmpreg/16.0f; 00229 00230 } 00231 00232 /** 00233 * @} 00234 */ 00235 00236 /** 00237 * @} 00238 */ 00239 00240 /** 00241 * @} 00242 */ 00243 00244 /** 00245 * @} 00246 */ 00247 00248 00249 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 00250
Generated on Thu Jul 14 2022 23:07:42 by
1.7.2