Firmware to manage X-Nucleo-IPS02A1 (24V) Intelligent Power Switch.
Dependents: HelloWorld_IPS02A1
Fork of X_NUCLEO_IPS02A1 by
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);
Components/vps235h2/vps235h2_class.h@2:06d0eb54630a, 2016-04-07 (annotated)
- Committer:
- grussian
- Date:
- Thu Apr 07 15:38:10 2016 +0000
- Revision:
- 2:06d0eb54630a
- Parent:
- 0:c175921ca7c3
- Child:
- 3:9edf6b8f3b2f
added Component-class and ReadId
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
grussian | 0:c175921ca7c3 | 1 | /** |
grussian | 0:c175921ca7c3 | 2 | ******************************************************************************* |
grussian | 0:c175921ca7c3 | 3 | * @file vps235h2_class.h |
grussian | 0:c175921ca7c3 | 4 | * @author APG Mass Market |
grussian | 0:c175921ca7c3 | 5 | * @version V1.0.1 |
grussian | 0:c175921ca7c3 | 6 | * @date 01-Feb-2015 |
grussian | 0:c175921ca7c3 | 7 | * @brief vps235h2 module driver. |
grussian | 0:c175921ca7c3 | 8 | * This file provides firmware functions to manage the following |
grussian | 0:c175921ca7c3 | 9 | * functionalities of the vps235h2 power switch: |
grussian | 0:c175921ca7c3 | 10 | * + Initialization and de-initialization functions |
grussian | 0:c175921ca7c3 | 11 | * + Diagnostic Sense Pin Configuration |
grussian | 0:c175921ca7c3 | 12 | * + Get Sense Diagnostic Values |
grussian | 0:c175921ca7c3 | 13 | ******************************************************************************* |
grussian | 0:c175921ca7c3 | 14 | * @attention |
grussian | 0:c175921ca7c3 | 15 | * |
grussian | 0:c175921ca7c3 | 16 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
grussian | 0:c175921ca7c3 | 17 | * |
grussian | 0:c175921ca7c3 | 18 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); |
grussian | 0:c175921ca7c3 | 19 | * You may not use this file except in compliance with the License. |
grussian | 0:c175921ca7c3 | 20 | * You may obtain a copy of the License at: |
grussian | 0:c175921ca7c3 | 21 | * |
grussian | 0:c175921ca7c3 | 22 | * http://www.st.com/software_license_agreement_liberty_v2 |
grussian | 0:c175921ca7c3 | 23 | * |
grussian | 0:c175921ca7c3 | 24 | * Redistribution and use in source and binary forms, with or without modification, |
grussian | 0:c175921ca7c3 | 25 | * are permitted provided that the following conditions are met: |
grussian | 0:c175921ca7c3 | 26 | * 1. Redistributions of source code must retain the above copyright notice, |
grussian | 0:c175921ca7c3 | 27 | * this list of conditions and the following disclaimer. |
grussian | 0:c175921ca7c3 | 28 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
grussian | 0:c175921ca7c3 | 29 | * this list of conditions and the following disclaimer in the documentation |
grussian | 0:c175921ca7c3 | 30 | * and/or other materials provided with the distribution. |
grussian | 0:c175921ca7c3 | 31 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
grussian | 0:c175921ca7c3 | 32 | * may be used to endorse or promote products derived from this software |
grussian | 0:c175921ca7c3 | 33 | * without specific prior written permission. |
grussian | 0:c175921ca7c3 | 34 | * |
grussian | 0:c175921ca7c3 | 35 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
grussian | 0:c175921ca7c3 | 36 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
grussian | 0:c175921ca7c3 | 37 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
grussian | 0:c175921ca7c3 | 38 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
grussian | 0:c175921ca7c3 | 39 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
grussian | 0:c175921ca7c3 | 40 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
grussian | 0:c175921ca7c3 | 41 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
grussian | 0:c175921ca7c3 | 42 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
grussian | 0:c175921ca7c3 | 43 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
grussian | 0:c175921ca7c3 | 44 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
grussian | 0:c175921ca7c3 | 45 | * |
grussian | 0:c175921ca7c3 | 46 | ******************************************************************************** |
grussian | 0:c175921ca7c3 | 47 | */ |
grussian | 0:c175921ca7c3 | 48 | |
grussian | 0:c175921ca7c3 | 49 | /* Define to prevent recursive inclusion -------------------------------------*/ |
grussian | 0:c175921ca7c3 | 50 | #ifndef __VPS220H1_CLASS_H |
grussian | 0:c175921ca7c3 | 51 | #define __VPS220H1_CLASS_H |
grussian | 0:c175921ca7c3 | 52 | |
grussian | 0:c175921ca7c3 | 53 | /* Includes ------------------------------------------------------------------*/ |
grussian | 0:c175921ca7c3 | 54 | #include "mbed.h" |
grussian | 0:c175921ca7c3 | 55 | #include "PowerSwitch.h" |
grussian | 0:c175921ca7c3 | 56 | #include "IPS.h" |
grussian | 0:c175921ca7c3 | 57 | #include "vps235h2.h" |
grussian | 0:c175921ca7c3 | 58 | |
grussian | 0:c175921ca7c3 | 59 | |
grussian | 0:c175921ca7c3 | 60 | |
grussian | 0:c175921ca7c3 | 61 | /* Classes -------------------------------------------------------------------*/ |
grussian | 0:c175921ca7c3 | 62 | /** Class representing a VPS235H2 power switch component |
grussian | 0:c175921ca7c3 | 63 | */ |
grussian | 0:c175921ca7c3 | 64 | |
grussian | 0:c175921ca7c3 | 65 | class VPS235H2 : public PowerSwitch { |
grussian | 0:c175921ca7c3 | 66 | |
grussian | 0:c175921ca7c3 | 67 | public: |
grussian | 0:c175921ca7c3 | 68 | DigitalOut In_1,In_2,Fr_Stby; |
grussian | 0:c175921ca7c3 | 69 | |
grussian | 0:c175921ca7c3 | 70 | |
grussian | 0:c175921ca7c3 | 71 | |
grussian | 0:c175921ca7c3 | 72 | /** Constructor |
grussian | 0:c175921ca7c3 | 73 | * @param[in] input Pin for the power switch |
grussian | 0:c175921ca7c3 | 74 | * @param[out] sense1 and sense2, outputs from Ch1 and Ch2 |
grussian | 0:c175921ca7c3 | 75 | * @param[in] vref, reference voltage |
grussian | 0:c175921ca7c3 | 76 | * @param[in] rsense, sense resistor ouside of chip |
grussian | 0:c175921ca7c3 | 77 | * @param[in] rd1, upper partitor resistor (=R6 in schematic) to protect ADC |
grussian | 0:c175921ca7c3 | 78 | * @param[in] rd1, lower partitor resistor (=R7 in schematic) to protect ADC |
grussian | 0:c175921ca7c3 | 79 | |
grussian | 0:c175921ca7c3 | 80 | */ |
grussian | 0:c175921ca7c3 | 81 | VPS235H2(PinName in1, PinName in2, PinName frStdby, |
grussian | 0:c175921ca7c3 | 82 | PinName sense1, PinName sense2, float vref,float rsense,float rd1,float rd2): |
grussian | 0:c175921ca7c3 | 83 | PowerSwitch(), |
grussian | 0:c175921ca7c3 | 84 | In_1 (in1), |
grussian | 0:c175921ca7c3 | 85 | In_2 (in2), |
grussian | 0:c175921ca7c3 | 86 | Fr_Stby(frStdby), |
grussian | 0:c175921ca7c3 | 87 | V_REF(vref), |
grussian | 0:c175921ca7c3 | 88 | R_SENSE(rsense), |
grussian | 0:c175921ca7c3 | 89 | R_D1(rd1), |
grussian | 0:c175921ca7c3 | 90 | R_D2(rd2), |
grussian | 0:c175921ca7c3 | 91 | CurrentSense1(sense1), |
grussian | 0:c175921ca7c3 | 92 | CurrentSense2(sense2) |
grussian | 0:c175921ca7c3 | 93 | { |
grussian | 0:c175921ca7c3 | 94 | |
grussian | 0:c175921ca7c3 | 95 | In_1 = In_2 = Fr_Stby = 0; |
grussian | 0:c175921ca7c3 | 96 | |
grussian | 0:c175921ca7c3 | 97 | } |
grussian | 0:c175921ca7c3 | 98 | |
grussian | 0:c175921ca7c3 | 99 | /** Destructor |
grussian | 0:c175921ca7c3 | 100 | */ |
grussian | 0:c175921ca7c3 | 101 | virtual ~VPS235H2() {} |
grussian | 0:c175921ca7c3 | 102 | |
grussian | 0:c175921ca7c3 | 103 | /*** Interface Methods ***/ |
grussian | 2:06d0eb54630a | 104 | virtual int Init(void *init_struct); |
grussian | 0:c175921ca7c3 | 105 | virtual int Close(void); |
grussian | 2:06d0eb54630a | 106 | /* Getting the ID of the component */ |
grussian | 2:06d0eb54630a | 107 | virtual int ReadID(uint8_t *id) { return (int) 235; } |
grussian | 0:c175921ca7c3 | 108 | /* Provide Ch current w/o checking status of convertion */ |
grussian | 0:c175921ca7c3 | 109 | float GetCurrent(int Ch); |
grussian | 0:c175921ca7c3 | 110 | /* Provide Ch current Value with status of convertion */ |
grussian | 0:c175921ca7c3 | 111 | IPS_StatusTypeDef VPS235H2_GetSecureCurrentSense(IPS_HandleTypeDef *hips); |
grussian | 2:06d0eb54630a | 112 | /** |
grussian | 2:06d0eb54630a | 113 | * @brief Getting the ID of the component. |
grussian | 2:06d0eb54630a | 114 | * @param id Pointer to an allocated variable to store the ID into. |
grussian | 2:06d0eb54630a | 115 | * @retval "0" in case of success, an error code otherwise. |
grussian | 2:06d0eb54630a | 116 | */ |
grussian | 2:06d0eb54630a | 117 | |
grussian | 0:c175921ca7c3 | 118 | protected: |
grussian | 0:c175921ca7c3 | 119 | /*** Methods ***/ |
grussian | 0:c175921ca7c3 | 120 | IPS_StatusTypeDef VPS235H2_Close(void); |
grussian | 0:c175921ca7c3 | 121 | IPS_StatusTypeDef VPS235H2_Init(void); |
grussian | 0:c175921ca7c3 | 122 | IPS_StatusTypeDef VPS235H2_GetSenseChannelDiagnostic(IPS_HandleTypeDef *); |
grussian | 0:c175921ca7c3 | 123 | |
grussian | 0:c175921ca7c3 | 124 | private: |
grussian | 0:c175921ca7c3 | 125 | const float V_REF; // Reference voltage for V-sense measurement |
grussian | 0:c175921ca7c3 | 126 | const float R_SENSE; // R-sense value depending on resistor connected to V-sense output |
grussian | 0:c175921ca7c3 | 127 | const float R_D1; // R_D1 upper divisor partitor resistor (=R6 in schematic) |
grussian | 0:c175921ca7c3 | 128 | const float R_D2; // R_D2 lower divisor partitor resistor (=R7 in schematic) |
grussian | 0:c175921ca7c3 | 129 | AnalogIn CurrentSense1; // V-Sense Output from Ch1 |
grussian | 0:c175921ca7c3 | 130 | AnalogIn CurrentSense2; // V-Sense Output from Ch2 |
grussian | 0:c175921ca7c3 | 131 | |
grussian | 0:c175921ca7c3 | 132 | }; |
grussian | 0:c175921ca7c3 | 133 | #endif /* __VPS235H2_CLASS_H */ |
grussian | 0:c175921ca7c3 | 134 | |
grussian | 0:c175921ca7c3 | 135 | |
grussian | 0:c175921ca7c3 | 136 | |
grussian | 0:c175921ca7c3 | 137 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
grussian | 0:c175921ca7c3 | 138 | |
grussian | 0:c175921ca7c3 | 139 | |
grussian | 0:c175921ca7c3 | 140 | |
grussian | 0:c175921ca7c3 | 141 |