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 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 config; 00066 00067 /* Change the following pointer to select any of the configurations above */ 00068 static ADI_SENSE_CONFIG *pSelectedConfig = &config; 00069 00070 static ADI_SENSE_CONNECTION connectionInfo = { 00071 .type = ADI_SENSE_CONNECTION_TYPE_SPI , 00072 .spi = { 00073 .mosiPin = SPI_MOSI, 00074 .misoPin = SPI_MISO, 00075 .sckPin = SPI_SCK, 00076 .csPin = D10, 00077 .maxSpeedHz = 2000000, 00078 }, 00079 .gpio = { 00080 .resetPin = D6, 00081 .errorPin = D3, 00082 .alertPin = D4, 00083 .datareadyPin = D5, 00084 }, 00085 .log = { 00086 .txPin = D1, 00087 .rxPin = D0, 00088 .baudRate = 115200, 00089 .disableLogs = false, 00090 }, 00091 }; 00092 00093 int main() 00094 { 00095 ADI_SENSE_RESULT res; 00096 ADI_SENSE_STATUS status; 00097 ADI_SENSE_DEVICE_HANDLE hDevice; 00098 ADI_SENSE_MEASUREMENT_MODE eMeasurementMode = ADI_SENSE_MEASUREMENT_MODE_NORMAL ; 00099 bool_t bDeviceReady; 00100 00101 /* 00102 * Open an ADI Sense device instance. 00103 */ 00104 res = adi_sense_Open(0, &connectionInfo, &hDevice); 00105 if (res != ADI_SENSE_SUCCESS ) 00106 { 00107 ADI_SENSE_LOG_ERROR("Failed to open device instance"); 00108 return res; 00109 } 00110 00111 /* 00112 * Reset the given ADI Sense device.... 00113 */ 00114 ADI_SENSE_LOG_INFO("Resetting ADI Sense device, please wait..."); 00115 res = adi_sense_Reset(hDevice); 00116 if (res != ADI_SENSE_SUCCESS ) 00117 { 00118 ADI_SENSE_LOG_ERROR("Failed to reset device"); 00119 return res; 00120 } 00121 /* 00122 * ...and wait until the device is ready. 00123 */ 00124 do { 00125 wait_ms(100); 00126 res = adi_sense_GetDeviceReadyState(hDevice, &bDeviceReady); 00127 if (res != ADI_SENSE_SUCCESS ) 00128 { 00129 ADI_SENSE_LOG_ERROR("Failed to get device ready-state"); 00130 return res; 00131 } 00132 } while (! bDeviceReady); 00133 ADI_SENSE_LOG_INFO("ADI Sense device ready"); 00134 00135 /* 00136 * Write configuration settings to the device registers. 00137 * Settings are not applied until adi_sense_ApplyConfigUpdates() is called. 00138 */ 00139 ADI_SENSE_LOG_INFO("Setting device configuration"); 00140 res = adi_sense_SetConfig(hDevice, pSelectedConfig); 00141 if (res != ADI_SENSE_SUCCESS ) 00142 { 00143 ADI_SENSE_LOG_ERROR("Failed to set device configuration"); 00144 return res; 00145 } 00146 res = adi_sense_ApplyConfigUpdates(hDevice); 00147 if (res != ADI_SENSE_SUCCESS ) 00148 { 00149 ADI_SENSE_LOG_ERROR("Failed to apply device configuration"); 00150 return res; 00151 } 00152 /* 00153 * Check device status after updating the configuration 00154 */ 00155 res = adi_sense_GetStatus(hDevice, &status); 00156 if (res != ADI_SENSE_SUCCESS ) 00157 { 00158 ADI_SENSE_LOG_ERROR("Failed to retrieve device status"); 00159 return res; 00160 } 00161 if (status.deviceStatus & 00162 (ADI_SENSE_DEVICE_STATUS_ERROR | ADI_SENSE_DEVICE_STATUS_ALERT )) 00163 { 00164 utils_printStatus(&status); 00165 } 00166 00167 /* 00168 * Kick off the measurement cycle here 00169 */ 00170 ADI_SENSE_LOG_INFO("Configuration completed, starting measurement cycles"); 00171 utils_runMeasurement(hDevice, eMeasurementMode); 00172 00173 /* 00174 * Clean up and exit 00175 */ 00176 res = adi_sense_Close(hDevice); 00177 if (res != ADI_SENSE_SUCCESS ) 00178 { 00179 ADI_SENSE_LOG_ERROR("Failed to close device instance"); 00180 return res; 00181 } 00182 00183 return 0; 00184 }
Generated on Wed Jul 13 2022 13:02:04 by
