Firmware to manage X-Nucleo-IPS02A1 (24V) Intelligent Power Switch.

Dependents:   HelloWorld_IPS02A1

Fork of X_NUCLEO_IPS02A1 by ST Expansion SW Team

X_NUCLEO_IPS02A1 24V Intelligent Power Switch (IPS) Nucleo Expansion Board Firmware Package

Introduction

This firmware package includes Components Device Drivers and Board Support Package for STMicroelectronics X-NUCLEO-IPS02A1 IPS Expansion Board.

Firmware Library

Class X_NUCLEO_IPS02A1 is intended to represent the Intelligent Power Switch expansion board with the same name.

The expansion board is basically featuring by one IP:

  • vps2535h vertical power switch.

It is intentionally implemented as a singleton because only one X-NUCLEO-IPS02A1 at a time might be deployed in a HW component stack. In order to get the singleton instance you have to call class method `Instance()`, e.g.:

// IPS expansion board singleton instance
static X_NUCLEO_IPS02A1 *ips_expansion_board = X_NUCLEO_IPS02A1::Instance();

How to use the firmware package

The basic operations to deal with the firmware pkg and use the IPS are the following :

1) instantiate the X_NUCLEO by calling class method `Instance()`:

// Sensors expansion board singleton instance
static X_NUCLEO_IPS02A1 *sensors_expansion_board = X_NUCLEO_IPS02A1::Instance();

2) Switch-on or Switch-off loads output (Channel 1 or Channel 2) by setting or clearing associated digital input :

            ips_expansion_board.vps2535h.Fr_Stby = 1; // set Fr_Stby pin
            ips_expansion_board.vps2535h.In_1 = 1; // switch-on Channel 1
            ips_expansion_board.vps2535h.In_2 = 0; // switch-off Channle 2 

3) Read Current circulating on Channel 1 or Channel 2 and print on the Terminal

            Multisense_Signal= ips_expansion_board.GetCurrent(CHANNEL_1);
            printf("Current Ch1 = %2.3fA \n\r", Multisense_Signal);
            Multisense_Signal= ips_expansion_board.GetCurrent(CHANNEL_2);
            printf("Current Ch2 = %2.3fA \n\r", Multisense_Signal);
Committer:
Davidroid
Date:
Thu Jul 13 16:12:04 2017 +0000
Revision:
8:73df2d2b721c
Parent:
7:10e489682b80
Aligning to ARM mbed coding style.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
grussian 0:c175921ca7c3 1 /**
grussian 4:715dcaf74418 2 ******************************************************************************
Davidroid 7:10e489682b80 3 * @file XNucleoIPS02A1.cpp
grussian 5:b683e69b181c 4 * @author ADG
grussian 4:715dcaf74418 5 * @version V1.0.1
grussian 5:b683e69b181c 6 * @date 01-July-2016
Davidroid 7:10e489682b80 7 * @brief Implementation file for the XNucleoIPS02A1 singleton class
grussian 4:715dcaf74418 8 ******************************************************************************
grussian 4:715dcaf74418 9 * @attention
grussian 4:715dcaf74418 10 *
grussian 6:c313d3a5c61a 11 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
grussian 4:715dcaf74418 12 *
grussian 4:715dcaf74418 13 * Redistribution and use in source and binary forms, with or without modification,
grussian 4:715dcaf74418 14 * are permitted provided that the following conditions are met:
grussian 4:715dcaf74418 15 * 1. Redistributions of source code must retain the above copyright notice,
grussian 4:715dcaf74418 16 * this list of conditions and the following disclaimer.
grussian 4:715dcaf74418 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
grussian 4:715dcaf74418 18 * this list of conditions and the following disclaimer in the documentation
grussian 4:715dcaf74418 19 * and/or other materials provided with the distribution.
grussian 4:715dcaf74418 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
grussian 4:715dcaf74418 21 * may be used to endorse or promote products derived from this software
grussian 4:715dcaf74418 22 * without specific prior written permission.
grussian 4:715dcaf74418 23 *
grussian 4:715dcaf74418 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
grussian 4:715dcaf74418 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
grussian 4:715dcaf74418 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
grussian 4:715dcaf74418 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
grussian 4:715dcaf74418 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
grussian 4:715dcaf74418 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
grussian 4:715dcaf74418 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
grussian 4:715dcaf74418 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
grussian 4:715dcaf74418 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
grussian 4:715dcaf74418 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
grussian 4:715dcaf74418 34 *
grussian 4:715dcaf74418 35 ******************************************************************************
grussian 4:715dcaf74418 36 */
grussian 0:c175921ca7c3 37
grussian 0:c175921ca7c3 38 /* Includes ------------------------------------------------------------------*/
Davidroid 7:10e489682b80 39
grussian 0:c175921ca7c3 40 #include "mbed.h"
Davidroid 7:10e489682b80 41 #include "XNucleoIPS02A1.h"
Davidroid 7:10e489682b80 42
grussian 0:c175921ca7c3 43
grussian 0:c175921ca7c3 44 /* Static variables ----------------------------------------------------------*/
Davidroid 7:10e489682b80 45
Davidroid 7:10e489682b80 46 XNucleoIPS02A1* XNucleoIPS02A1::_instance = NULL;
grussian 0:c175921ca7c3 47
grussian 0:c175921ca7c3 48
grussian 0:c175921ca7c3 49 /* Methods -------------------------------------------------------------------*/
Davidroid 7:10e489682b80 50
grussian 0:c175921ca7c3 51 /**
grussian 0:c175921ca7c3 52 * @brief Constructor
grussian 4:715dcaf74418 53 * @return a pointer to the initialized singleton instance of class X_NUCLEO_IPS02A1
grussian 4:715dcaf74418 54 * @param[in] in1, input1 Pin for the power switch
grussian 4:715dcaf74418 55 * @param[in] in2, input1 Pin for the power switch
grussian 4:715dcaf74418 56 * @param[in] frstdby ,stand-by Pin
grussian 4:715dcaf74418 57 * @param[in] sense1 and sense2, outputs from Ch1 and Ch2
grussian 4:715dcaf74418 58 * @param[in] vref, reference voltage
grussian 4:715dcaf74418 59 * @param[in] rsense, sense resistor ouside of chip
grussian 4:715dcaf74418 60 * @param[in] rd1, upper partitor resistor (=R6 in schematic) to protect ADC
grussian 4:715dcaf74418 61 * @param[in] rd1, lower partitor resistor (=R7 in schematic) to protect ADC
grussian 0:c175921ca7c3 62 */
grussian 4:715dcaf74418 63
Davidroid 7:10e489682b80 64 XNucleoIPS02A1::XNucleoIPS02A1(PinName in1, PinName in2, PinName frstdby,
Davidroid 7:10e489682b80 65 PinName sense1, PinName sense2, float vref, float rsense, float rd1, float rd2) :
Davidroid 7:10e489682b80 66 vps2535h( *(new VPS2535H(in1, in2, frstdby, sense1, sense2, vref,rsense,rd1,rd2)))
grussian 0:c175921ca7c3 67 {
grussian 0:c175921ca7c3 68 }
grussian 0:c175921ca7c3 69
grussian 0:c175921ca7c3 70 /**
grussian 0:c175921ca7c3 71 * @brief Get singleton instance
Davidroid 7:10e489682b80 72 * @return a pointer to the initialized singleton instance of class XNucleoIPS02A1
grussian 0:c175921ca7c3 73 * @param[in] none
grussian 0:c175921ca7c3 74 */
Davidroid 7:10e489682b80 75 XNucleoIPS02A1 &XNucleoIPS02A1::instance(PinName in1, PinName in2, PinName frstdby,
Davidroid 7:10e489682b80 76 PinName sense1, PinName sense2, float vref, float rsense, float rd1, float rd2) {
Davidroid 7:10e489682b80 77 if (_instance == NULL) {
Davidroid 7:10e489682b80 78 _instance = new XNucleoIPS02A1(in1,in2,frstdby,sense1,sense2,vref,rsense,rd1,rd2);
grussian 0:c175921ca7c3 79
Davidroid 7:10e489682b80 80 if (_instance != NULL) {
Davidroid 7:10e489682b80 81 bool ret = _instance->init();
Davidroid 7:10e489682b80 82 if (!ret) {
grussian 0:c175921ca7c3 83 error("Failed to init X_NUCLEO_IPS02A1 expansion board!\n");
grussian 0:c175921ca7c3 84 }
grussian 0:c175921ca7c3 85 }
grussian 0:c175921ca7c3 86 }
grussian 0:c175921ca7c3 87
grussian 0:c175921ca7c3 88 return (*_instance);
grussian 0:c175921ca7c3 89 }
grussian 0:c175921ca7c3 90
grussian 0:c175921ca7c3 91 /**
grussian 0:c175921ca7c3 92 * @brief Initialize the singleton's power switch
grussian 0:c175921ca7c3 93 * @retval true if initialization successful,
grussian 0:c175921ca7c3 94 * @retval false otherwise
grussian 0:c175921ca7c3 95 */
Davidroid 7:10e489682b80 96 bool XNucleoIPS02A1::init_VPS2535H(void) {
Davidroid 7:10e489682b80 97 vps2535h.init(NULL);
Davidroid 7:10e489682b80 98 return true;
grussian 0:c175921ca7c3 99 }
grussian 0:c175921ca7c3 100
grussian 0:c175921ca7c3 101
grussian 0:c175921ca7c3 102 /**
grussian 0:c175921ca7c3 103 * @brief get current measurement from singleton's power switch
grussian 0:c175921ca7c3 104 * @retval *hips contain status of the operation
grussian 0:c175921ca7c3 105 * param[in] Channel number: CHANNEL_1 or CHANNEL_2
grussian 0:c175921ca7c3 106 */
Davidroid 7:10e489682b80 107 float XNucleoIPS02A1::get_current(int ch){
Davidroid 7:10e489682b80 108 return vps2535h.get_current(ch);
grussian 0:c175921ca7c3 109 }
grussian 0:c175921ca7c3 110
grussian 0:c175921ca7c3 111
grussian 0:c175921ca7c3 112 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
grussian 0:c175921ca7c3 113