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.
Fork of AdiSense1000_V21 by
main.cpp
00001 /* 00002 CONFIDENTIAL AND PROPRIETARY INFORMATION 00003 00004 Copyright (c) 2018 Emutex Ltd. All rights reserved. 00005 This software and documentation contain confidential and 00006 proprietary information that is the property of 00007 Emutex Ltd. The software and documentation are 00008 furnished under a license agreement and may be used 00009 or copied only in accordance with the terms of the license 00010 agreement. No part of the software and documentation 00011 may be reproduced, transmitted, or translated, in any 00012 form or by any means, electronic, mechanical, manual, 00013 optical, or otherwise, without prior written permission 00014 of Emutex Ltd., or as expressly provided by the license agreement. 00015 Reverse engineering is prohibited, and reproduction, 00016 disclosure or use without specific written authorization 00017 of Emutex Ltd. is strictly forbidden. 00018 * 00019 Copyright 2017 (c) Analog Devices, Inc. 00020 00021 All rights reserved. 00022 00023 Redistribution and use in source and binary forms, with or without 00024 modification, are permitted provided that the following conditions are met: 00025 - Redistributions of source code must retain the above copyright 00026 notice, this list of conditions and the following disclaimer. 00027 - Redistributions in binary form must reproduce the above copyright 00028 notice, this list of conditions and the following disclaimer in 00029 the documentation and/or other materials provided with the 00030 distribution. 00031 - Neither the name of Analog Devices, Inc. nor the names of its 00032 contributors may be used to endorse or promote products derived 00033 from this software without specific prior written permission. 00034 - The use of this software may or may not infringe the patent rights 00035 of one or more patent holders. This license does not release you 00036 from the requirement that you obtain separate licenses from these 00037 patent holders to use this software. 00038 - Use of the software either in source or binary form, must be run 00039 on or directly connected to an Analog Devices Inc. component. 00040 00041 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR 00042 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 00043 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00044 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, 00045 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00046 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR 00047 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00048 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00049 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00050 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00051 * 00052 *****************************************************************************/ 00053 /*! 00054 ****************************************************************************** 00055 * @file: 00056 *----------------------------------------------------------------------------- 00057 * 00058 */ 00059 #include "mbed.h" 00060 #include "inc/adi_sense_api.h" 00061 #include "inc/adi_sense_1000/adi_sense_1000_api.h" 00062 #include "inc/adi_sense_log.h" 00063 #include "common/utils.h" 00064 00065 extern ADI_SENSE_CONFIG sensor2_bridge_6w_pressure_config; 00066 00067 extern ADI_SENSE_1000_LUT_DESCRIPTOR *sample_lut_desc_list[]; 00068 extern ADI_SENSE_1000_LUT_TABLE_DATA *sample_lut_data_list[]; 00069 extern unsigned sample_lut_num_tables; 00070 00071 /* Change the following pointer to select any of the configurations above */ 00072 static ADI_SENSE_CONFIG *pSelectedConfig = &sensor2_bridge_6w_pressure_config; 00073 00074 static ADI_SENSE_CONNECTION connectionInfo = { 00075 .type = ADI_SENSE_CONNECTION_TYPE_SPI , 00076 .spi = { 00077 .mosiPin = SPI_MOSI, 00078 .misoPin = SPI_MISO, 00079 .sckPin = SPI_SCK, 00080 .csPin = D10, 00081 .maxSpeedHz = 2000000, 00082 }, 00083 .gpio = { 00084 .resetPin = D6, 00085 .errorPin = D3, 00086 .alertPin = D4, 00087 .datareadyPin = D5, 00088 }, 00089 .log = { 00090 .txPin = D1, 00091 .rxPin = D0, 00092 .baudRate = 115200, 00093 .disableLogs = false, 00094 }, 00095 }; 00096 00097 int main() 00098 { 00099 ADI_SENSE_RESULT res; 00100 ADI_SENSE_STATUS status; 00101 ADI_SENSE_DEVICE_HANDLE hDevice; 00102 ADI_SENSE_MEASUREMENT_MODE eMeasurementMode = ADI_SENSE_MEASUREMENT_MODE_NORMAL ; 00103 bool_t bDeviceReady; 00104 00105 /* 00106 * Open an ADI Sense device instance. 00107 */ 00108 res = adi_sense_Open(0, &connectionInfo, &hDevice); 00109 if (res != ADI_SENSE_SUCCESS ) 00110 { 00111 ADI_SENSE_LOG_ERROR("Failed to open device instance"); 00112 return res; 00113 } 00114 00115 /* 00116 * Reset the given ADI Sense device.... 00117 */ 00118 ADI_SENSE_LOG_INFO("Resetting ADI Sense device, please wait..."); 00119 res = adi_sense_Reset(hDevice); 00120 if (res != ADI_SENSE_SUCCESS ) 00121 { 00122 ADI_SENSE_LOG_ERROR("Failed to reset device"); 00123 return res; 00124 } 00125 /* 00126 * ...and wait until the device is ready. 00127 */ 00128 do { 00129 wait_ms(100); 00130 res = adi_sense_GetDeviceReadyState(hDevice, &bDeviceReady); 00131 if (res != ADI_SENSE_SUCCESS ) 00132 { 00133 ADI_SENSE_LOG_ERROR("Failed to get device ready-state"); 00134 return res; 00135 } 00136 } while (! bDeviceReady); 00137 ADI_SENSE_LOG_INFO("ADI Sense device ready"); 00138 00139 /* 00140 * Write configuration settings to the device registers. 00141 * Settings are not applied until adi_sense_ApplyConfigUpdates() is called. 00142 */ 00143 ADI_SENSE_LOG_INFO("Setting device configuration"); 00144 res = adi_sense_SetConfig(hDevice, pSelectedConfig); 00145 if (res != ADI_SENSE_SUCCESS ) 00146 { 00147 ADI_SENSE_LOG_ERROR("Failed to set device configuration"); 00148 return res; 00149 } 00150 00151 unsigned lutBufferSize = ADI_SENSE_LUT_MAX_SIZE; 00152 ADI_SENSE_1000_LUT *pLutBuffer = (ADI_SENSE_1000_LUT *) ::operator new (lutBufferSize); 00153 if (pLutBuffer == NULL) 00154 { 00155 ADI_SENSE_LOG_ERROR("Failed to allocate memory for user-defined LUT data buffer"); 00156 return ADI_SENSE_NO_MEM ; 00157 } 00158 00159 ADI_SENSE_LOG_INFO("Assembling LUT data"); 00160 res = adi_sense_1000_AssembleLutData(pLutBuffer, lutBufferSize, 00161 sample_lut_num_tables, 00162 sample_lut_desc_list, 00163 sample_lut_data_list); 00164 if (res != ADI_SENSE_SUCCESS ) 00165 { 00166 ADI_SENSE_LOG_ERROR("Failed to assemble user-defined LUT data"); 00167 return res; 00168 } 00169 00170 /* 00171 * Write assembled user-defined Look-Up Table data structure to the device 00172 * User-defined LUT data is not applied until adi_sense_ApplyConfigUpdates() is called. 00173 */ 00174 ADI_SENSE_LOG_INFO("Setting LUT data"); 00175 res = adi_sense_1000_SetLutData(hDevice, pLutBuffer); 00176 if (res != ADI_SENSE_SUCCESS ) 00177 { 00178 ADI_SENSE_LOG_ERROR("Failed to set user-defined LUT data"); 00179 return res; 00180 } 00181 00182 delete pLutBuffer; 00183 00184 00185 res = adi_sense_ApplyConfigUpdates(hDevice); 00186 if (res != ADI_SENSE_SUCCESS ) 00187 { 00188 ADI_SENSE_LOG_ERROR("Failed to apply device configuration"); 00189 return res; 00190 } 00191 /* 00192 * Check device status after updating the configuration 00193 */ 00194 res = adi_sense_GetStatus(hDevice, &status); 00195 if (res != ADI_SENSE_SUCCESS ) 00196 { 00197 ADI_SENSE_LOG_ERROR("Failed to retrieve device status"); 00198 return res; 00199 } 00200 if (status.deviceStatus & 00201 (ADI_SENSE_DEVICE_STATUS_ERROR | ADI_SENSE_DEVICE_STATUS_ALERT )) 00202 { 00203 utils_printStatus(&status); 00204 } 00205 00206 /* 00207 * Kick off the measurement cycle here 00208 */ 00209 ADI_SENSE_LOG_INFO("Configuration completed, starting measurement cycles"); 00210 utils_runMeasurement(hDevice, eMeasurementMode); 00211 00212 /* 00213 * Clean up and exit 00214 */ 00215 res = adi_sense_Close(hDevice); 00216 if (res != ADI_SENSE_SUCCESS ) 00217 { 00218 ADI_SENSE_LOG_ERROR("Failed to close device instance"); 00219 return res; 00220 } 00221 00222 return 0; 00223 }
Generated on Wed Jul 13 2022 04:26:17 by
1.7.2
