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.
ADxxxx.cpp
00001 /***************************************************************************//** 00002 * @file AD1234.cpp 00003 * @brief Implementation of Ad1234 Driver. 00004 * @author FirstName LastName (email ID) 00005 ******************************************************************************* 00006 * Copyright 2013(c) Analog Devices, Inc. 00007 * 00008 * All rights reserved. 00009 * 00010 * Redistribution and use in source and binary forms, with or without 00011 * modification, 00012 * are permitted provided that the following conditions are met: 00013 * - Redistributions of source code must retain the above copyright 00014 * notice, this list of conditions and the following disclaimer. 00015 * - Redistributions in binary form must reproduce the above copyright 00016 * notice, this list of conditions and the following disclaimer in 00017 * the documentation and/or other materials provided with the 00018 * distribution. 00019 * - Neither the name of Analog Devices, Inc. nor the names of its 00020 * contributors may be used to endorse or promote products derived 00021 * from this software without specific prior written permission. 00022 * - The use of this software may or may not infringe the patent rights 00023 * of one or more patent holders. This license does not release you 00024 * from the requirement that you obtain separate licenses from these 00025 * patent holders to use this software. 00026 * - Use of the software either in source or binary form, must be run 00027 * on or directly connected to an Analog Devices Inc. component. 00028 * 00029 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR 00030 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 00031 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00032 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, 00033 * INCIDENTAL,SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00034 * * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS 00035 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00036 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00037 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00038 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00039 * DAMAGE. 00040 * 00041 ******************************************************************************/ 00042 #include "mbed.h" /*Neccessary Include Files*/ 00043 #include "ADxxxx.h" 00044 00045 /*Actual Declaration of all registers 00046 based on the four fields declared in 00047 the header file 00048 {Address, Value, Size, Read or Write}*/ 00049 struct adxxxx_reg adxxxx_all_regs[ADXXXX_REG_NUM] = { 00050 {0x00, 0x00, 1, 1}, /*EX_ADXXXX_POWER_ON*/ 00051 {0x01, 0x00, 1, 1}, /*EX_ADXXXX_POWER_LEVEL*/ 00052 {0x02, 0x00, 1, 1}, /*EX_ADXXXX_CALIBRATION*/ 00053 }; 00054 00055 /*Function to malloc space for descriptor as well 00056 as start the proper serial communication 00057 **You should only be using either SPI or I2C at once** 00058 Parameters: Pointer to a pointer to the device descriptor 00059 Return Value: SUCCESS, FAILURE (You can make these more appropriate return 00060 values if you would like, making it more 00061 readable)*/ 00062 int adxxxx_setup(struct adxxxx_descriptor **device, struct adxxxx_init_params init_param) { 00063 00064 int8_t return_val = 1; 00065 struct adxxxx_descriptor * desc; 00066 extern struct adxxxx_reg adxxxx_all_regs[ADXXXX_REG_NUM]; 00067 00068 desc = (struct adxxxx_descriptor *)malloc(sizeof(*desc)); 00069 if (!desc) 00070 return FAILURE; 00071 00072 desc->all_regs = adxxxx_all_regs; 00073 00074 /*Example of turning the device on and calibrating 00075 it, but clearly this is device specific*/ 00076 desc->is_calibrated = ADXXXX_NOT_CALIBRATED; 00077 desc->power_level = ADXXXX_POW_IDLE; 00078 00079 /*Uncomment the protocol your device uses*/ 00080 //return_val = spi_init(&desc->spi_desc, &init_params.spi_init); 00081 //return_val = i2c_init(&desc->i2c_desc, &init_params.i2c_init); 00082 if (return_val < 1) 00083 return FAILURE; 00084 00085 *device = desc; 00086 return SUCCESS; 00087 } 00088 00089 /*Function to sweep through all of the registers and set them 00090 to their initial values 00091 Parameters: Pointer to adxxxx's descriptor 00092 Return Value: SUCCESS, FAILURE*/ 00093 int adxxxx_init_regs(struct adxxxx_descriptor *device) { 00094 /*Sweep through all of the registers that you initialized 00095 in the struct above and write all the values to the device 00096 (Could return register that failed to be written to may be 00097 helpful for debugging)*/ 00098 return SUCCESS; 00099 } 00100 00101 /*Function to make a single or multi read from the device, based off 00102 the registers size which you can find in the devices data sheet 00103 Parameters: Pointer to adxxxx's descriptor, register struct to read from 00104 Return Value: SUCCESS, FAILURE*/ 00105 int adxxx_read(struct adxxxx_descriptor *device, struct adxxxx_reg* reg) { 00106 /*Follow your devices specific write protocol (I2C, SPI) in conjunction 00107 with the platform specific drivers to effectively communicate with your 00108 device (A good first step is perhaps reading your devices ID register 00109 or something else that is easy to get to)*/ 00110 return SUCCESS; 00111 } 00112 00113 /*Function to make a single or multi write to the device, based off 00114 the registers size which you can find in the devices data sheet 00115 Parameters: Pointer to adxxxx's descriptor, register struct to read from 00116 Return Value: SUCCESS, FAILURE*/ 00117 int adxxx_write(struct adxxxx_descriptor *device, struct adxxxx_reg* reg, uint32_t data) { 00118 /*Follow your devices specific write protocol (I2C, SPI) in conjunction 00119 with the platform specific drivers to effectively communicate with your 00120 device (Try and write to a read-enabled register and then immediately 00121 read back the value you wrote)*/ 00122 reg->value = data; 00123 return SUCCESS; 00124 }
Generated on Thu Jul 14 2022 02:41:57 by
