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 VPS2535H.cpp Source File

VPS2535H.cpp

Go to the documentation of this file.
00001 /**
00002  ******************************************************************************
00003  * @file    VPS2535H.cpp
00004  * @author  ADG
00005  * @version V1.0.1
00006  * @date    01-July-2016
00007  * @brief   implementatio for VPS2535H driver 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 
00039 /* Includes ------------------------------------------------------------------*/
00040 #include "VPS2535H.h"
00041 
00042 
00043 /* Methods -------------------------------------------------------------------*/
00044 
00045 /**
00046  * @brief  Set VPS2535H Initialization
00047  * @param  VPS2535H handel structure
00048  * @retval IPS_SUCCESS
00049  */
00050 int VPS2535H::init(void *init_struct) {
00051     VPS2535H_init();
00052     return IPS_SUCCESS; 
00053 }
00054 
00055 /**
00056  * @brief  Close VPS2535H
00057  * @param  none
00058  * @retval IPS_SUCCESS
00059  */
00060 int VPS2535H::close(void) {
00061     VPS2535H_close();
00062     return IPS_SUCCESS; 
00063 }
00064 
00065 /* Module Interface */
00066 /**
00067   * @brief  Initializes the VPS2535H device
00068   * @param  none
00069   * @retval VPS2535H status
00070   */
00071 IPS_StatusTypeDef VPS2535H::VPS2535H_init() {
00072     Fr_Stby = 1;
00073     return IPS_SUCCESS;
00074 }
00075 
00076 /**
00077   * @brief  Close (Deinitialize) the VPS2535H device and used peripheral.
00078   * @param  None
00079   * @retval VPS2535H status
00080   */
00081 IPS_StatusTypeDef VPS2535H::VPS2535H_close(){
00082     Fr_Stby = 1;
00083     return IPS_SUCCESS;
00084 }
00085 
00086 /**
00087   * @brief  GetSense function gets the value of the Sense power switch output pin 
00088   * (for either Ch1 or Ch2) upon IO conversion. It just reads from sense pin
00089   * @param  hips: pointer to a VPS2535H_HandleTypeDef structure that contains
00090   *                the configuration information for the specified VPS2535H module.
00091   *                Value got from V-sense output is stored in hips->SenseValue
00092   *                field. Status of the operation is stored in hips->Status and 
00093   *                hips->Status fields
00094   * @retval IPS_StatusTypeDef status
00095   */
00096 IPS_StatusTypeDef VPS2535H::VPS2535H_get_sense_channel_diagnostic(IPS_HandleTypeDef *hips){
00097     hips->SenseRawValue = 0; //if channel is wrong Sense value is 0
00098     hips->GNDSenseRawValue = 0; // VPS2535H doesn't require GND measurement compensation
00099     hips-> Status =IPS_WRONG_CHANNEL;
00100     hips->IO_Status = IPS_IO_FAIL;
00101     if (hips ->ipsChannel == CHANNEL_1) {
00102         hips->SenseRawValue = CurrentSense1.read() * V_REF * ((R_D1+R_D2)/(R_D2));
00103     }
00104     if (hips ->ipsChannel == CHANNEL_2) {
00105         hips->SenseRawValue = CurrentSense2.read() * V_REF * ((R_D1+R_D2)/(R_D2));
00106     }
00107  
00108     hips->IO_Status = IPS_IO_SUCCESS;
00109     hips->Status =IPS_SUCCESS;
00110     return hips-> Status;
00111 }
00112 
00113 /**
00114   * @brief  GetSecureCurrentSense  function gets the I-sense switch output pin
00115   *         upon ADC conversion. 
00116   * @param  hips: pointer to a IPS_HandleTypeDef structure that contains
00117   *         the configuration information for the specified VPS2535H module.
00118   *         Value got from V-sense output is stored in hips->SenseValue
00119   *         field.
00120   *         Status of the operation is stored in hips->Status fields   
00121   * @retval IPS status
00122   */
00123 IPS_StatusTypeDef VPS2535H::VPS2535H_get_secure_current_sense(IPS_HandleTypeDef *hips){
00124   
00125     if ((hips ->ipsChannel != CHANNEL_1) && (hips ->ipsChannel != CHANNEL_2)) {
00126         hips->Status = IPS_WRONG_CHANNEL;
00127         return IPS_WRONG_CHANNEL; 
00128     }
00129   
00130     /* Get sense feedback */
00131     if ((VPS2535H_get_sense_channel_diagnostic(hips) == IPS_SUCCESS) && (hips->Status == IPS_SUCCESS)) {
00132         hips->IValue= K*hips->SenseRawValue/R_SENSE;
00133         return IPS_SUCCESS;
00134     } else {
00135         return IPS_FAIL; // see hips->Status
00136     }
00137 }
00138 
00139 /**
00140   * @brief  GetCurrent  function gets the I-sense switch output pin
00141   * @param  Ch: Channel number. Possible value are CHANNEL_1 or CHANNEL_2
00142   * @retval Current Value
00143   */
00144 float VPS2535H::get_current(int Ch) {
00145  
00146     if (Ch == CHANNEL_1) {
00147         return (K*CurrentSense1.read()* ((R_D1+R_D2)/(R_D2)) * V_REF/R_SENSE);
00148     }
00149     if (Ch == CHANNEL_2) {
00150         return (K*CurrentSense2.read()* ((R_D1+R_D2)/(R_D2)) * V_REF/R_SENSE);
00151     }
00152     return 0;
00153 }
00154 
00155 
00156 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/