ST / X_NUCLEO_IPS02A1

Dependents:   HelloWorld_IPS02A1

Fork of X_NUCLEO_IPS02A1 by ST Expansion SW Team

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers XNucleoIPS02A1.cpp Source File

XNucleoIPS02A1.cpp

Go to the documentation of this file.
00001 /**
00002  ******************************************************************************
00003  * @file    XNucleoIPS02A1.cpp
00004  * @author  ADG
00005  * @version V1.0.1
00006  * @date    01-July-2016
00007  * @brief   Implementation file for the XNucleoIPS02A1 singleton class
00008  ******************************************************************************
00009  * @attention
00010  *
00011  * <h2><center>&copy; COPYRIGHT(c) 2016 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 
00038 /* Includes ------------------------------------------------------------------*/
00039 
00040 #include "mbed.h"
00041 #include "XNucleoIPS02A1.h"
00042 
00043 
00044 /* Static variables ----------------------------------------------------------*/
00045 
00046 XNucleoIPS02A1* XNucleoIPS02A1::_instance = NULL;
00047 
00048 
00049 /* Methods -------------------------------------------------------------------*/
00050 
00051 /**
00052  * @brief  Constructor
00053  * @return    a pointer to the initialized singleton instance of class X_NUCLEO_IPS02A1
00054  * @param[in] in1, input1 Pin for the power switch
00055  * @param[in] in2, input1 Pin for the power switch
00056  * @param[in] frstdby ,stand-by Pin
00057  * @param[in] sense1 and sense2, outputs from Ch1 and Ch2
00058  * @param[in] vref, reference voltage
00059  * @param[in] rsense, sense resistor ouside of chip
00060  * @param[in] rd1, upper partitor resistor (=R6 in schematic) to protect ADC 
00061  * @param[in] rd1, lower partitor resistor (=R7 in schematic) to protect ADC
00062  */
00063  
00064 XNucleoIPS02A1::XNucleoIPS02A1(PinName in1, PinName in2, PinName frstdby,
00065              PinName sense1, PinName sense2, float vref, float rsense, float rd1, float rd2) :
00066              vps2535h( *(new VPS2535H(in1, in2, frstdby, sense1, sense2, vref,rsense,rd1,rd2)))
00067 {
00068 }
00069 
00070 /**
00071  * @brief     Get singleton instance
00072  * @return    a pointer to the initialized singleton instance of class XNucleoIPS02A1
00073  * @param[in] none
00074  */
00075 XNucleoIPS02A1 &XNucleoIPS02A1::instance(PinName in1, PinName in2, PinName frstdby,
00076     PinName sense1, PinName sense2, float vref, float rsense, float rd1, float rd2) {
00077     if (_instance == NULL) {
00078         _instance = new XNucleoIPS02A1(in1,in2,frstdby,sense1,sense2,vref,rsense,rd1,rd2);
00079 
00080         if (_instance != NULL) {
00081             bool ret = _instance->init();
00082             if (!ret) {
00083                 error("Failed to init X_NUCLEO_IPS02A1 expansion board!\n");
00084             }
00085         }
00086     }
00087 
00088     return (*_instance);
00089 }
00090 
00091 /**
00092  * @brief  Initialize the singleton's power switch
00093  * @retval true if initialization successful, 
00094  * @retval false otherwise
00095  */
00096 bool XNucleoIPS02A1::init_VPS2535H(void) {
00097     vps2535h.init(NULL);
00098     return true;
00099 }
00100 
00101  
00102 /**
00103  * @brief    get current measurement from singleton's power switch
00104  * @retval   *hips contain status of the operation
00105  * param[in] Channel number: CHANNEL_1 or CHANNEL_2
00106  */
00107 float  XNucleoIPS02A1::get_current(int ch){
00108     return vps2535h.get_current(ch);
00109 }
00110 
00111 
00112 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
00113