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/vps2535h/vps2535h_class.cpp@5:b683e69b181c, 2016-07-28 (annotated)
- Committer:
- grussian
- Date:
- Thu Jul 28 16:05:28 2016 +0000
- Revision:
- 5:b683e69b181c
- Parent:
- Components/vps235h2/vps235h2_class.cpp@4:715dcaf74418
- Child:
- 6:c313d3a5c61a
changed component name from vps235h2 to vps2535h
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
grussian | 0:c175921ca7c3 | 1 | /** |
grussian | 4:715dcaf74418 | 2 | ****************************************************************************** |
grussian | 5:b683e69b181c | 3 | * @file vps2535h.cpp |
grussian | 5:b683e69b181c | 4 | * @author ADG |
grussian | 5:b683e69b181c | 5 | * @version V1.0.1 |
grussian | 5:b683e69b181c | 6 | * @date 01-July-2016 |
grussian | 5:b683e69b181c | 7 | * @brief implementatio for VPS2535H driver class |
grussian | 4:715dcaf74418 | 8 | ****************************************************************************** |
grussian | 4:715dcaf74418 | 9 | * @attention |
grussian | 4:715dcaf74418 | 10 | * |
grussian | 4:715dcaf74418 | 11 | * <h2><center>© COPYRIGHT(c) 2015 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 ------------------------------------------------------------------*/ |
grussian | 5:b683e69b181c | 39 | #include "vps2535h_class.h" |
grussian | 5:b683e69b181c | 40 | #include "vps2535h.h" |
grussian | 0:c175921ca7c3 | 41 | |
grussian | 0:c175921ca7c3 | 42 | |
grussian | 0:c175921ca7c3 | 43 | /* Methods -------------------------------------------------------------------*/ |
grussian | 0:c175921ca7c3 | 44 | /** |
grussian | 5:b683e69b181c | 45 | * @brief Set VPS2535H Initialization |
grussian | 5:b683e69b181c | 46 | * @param VPS2535H handel structure |
grussian | 0:c175921ca7c3 | 47 | * @retval IPS_SUCCESS |
grussian | 0:c175921ca7c3 | 48 | */ |
grussian | 0:c175921ca7c3 | 49 | |
grussian | 5:b683e69b181c | 50 | int VPS2535H :: Init(void *init_struct) { |
grussian | 5:b683e69b181c | 51 | VPS2535H_Init(); |
grussian | 0:c175921ca7c3 | 52 | return IPS_SUCCESS; |
grussian | 0:c175921ca7c3 | 53 | |
grussian | 0:c175921ca7c3 | 54 | } |
grussian | 0:c175921ca7c3 | 55 | |
grussian | 0:c175921ca7c3 | 56 | /** |
grussian | 5:b683e69b181c | 57 | * @brief Close VPS2535H |
grussian | 0:c175921ca7c3 | 58 | * @param none |
grussian | 0:c175921ca7c3 | 59 | * @retval IPS_SUCCESS |
grussian | 0:c175921ca7c3 | 60 | */ |
grussian | 0:c175921ca7c3 | 61 | |
grussian | 5:b683e69b181c | 62 | int VPS2535H :: Close(void) { |
grussian | 5:b683e69b181c | 63 | VPS2535H_Close(); |
grussian | 0:c175921ca7c3 | 64 | return IPS_SUCCESS; |
grussian | 0:c175921ca7c3 | 65 | } |
grussian | 0:c175921ca7c3 | 66 | |
grussian | 0:c175921ca7c3 | 67 | |
grussian | 0:c175921ca7c3 | 68 | /* Module Interface */ |
grussian | 0:c175921ca7c3 | 69 | /** |
grussian | 5:b683e69b181c | 70 | * @brief Initializes the VPS2535H device |
grussian | 0:c175921ca7c3 | 71 | * @param none |
grussian | 5:b683e69b181c | 72 | * @retval VPS2535H status |
grussian | 0:c175921ca7c3 | 73 | */ |
grussian | 5:b683e69b181c | 74 | IPS_StatusTypeDef VPS2535H :: VPS2535H_Init(){ |
grussian | 0:c175921ca7c3 | 75 | Fr_Stby = 1; |
grussian | 0:c175921ca7c3 | 76 | return IPS_SUCCESS; |
grussian | 0:c175921ca7c3 | 77 | } |
grussian | 0:c175921ca7c3 | 78 | |
grussian | 0:c175921ca7c3 | 79 | /** |
grussian | 5:b683e69b181c | 80 | * @brief Close (Deinitialize) the VPS2535H device and used peripheral. |
grussian | 0:c175921ca7c3 | 81 | * @param None |
grussian | 5:b683e69b181c | 82 | * @retval VPS2535H status |
grussian | 0:c175921ca7c3 | 83 | */ |
grussian | 5:b683e69b181c | 84 | IPS_StatusTypeDef VPS2535H :: VPS2535H_Close(){ |
grussian | 0:c175921ca7c3 | 85 | Fr_Stby = 1; |
grussian | 0:c175921ca7c3 | 86 | return IPS_SUCCESS; |
grussian | 0:c175921ca7c3 | 87 | } |
grussian | 0:c175921ca7c3 | 88 | |
grussian | 0:c175921ca7c3 | 89 | |
grussian | 0:c175921ca7c3 | 90 | /** |
grussian | 0:c175921ca7c3 | 91 | * @brief GetSense function gets the value of the Sense power switch output pin |
grussian | 0:c175921ca7c3 | 92 | * (for either Ch1 or Ch2) upon IO conversion. It just reads from sense pin |
grussian | 5:b683e69b181c | 93 | * @param hips: pointer to a VPS2535H_HandleTypeDef structure that contains |
grussian | 5:b683e69b181c | 94 | * the configuration information for the specified VPS2535H module. |
grussian | 0:c175921ca7c3 | 95 | * Value got from V-sense output is stored in hips->SenseValue |
grussian | 0:c175921ca7c3 | 96 | * field. Status of the operation is stored in hips->Status and |
grussian | 0:c175921ca7c3 | 97 | * hips->Status fields |
grussian | 0:c175921ca7c3 | 98 | * @retval IPS_StatusTypeDef status |
grussian | 0:c175921ca7c3 | 99 | */ |
grussian | 5:b683e69b181c | 100 | IPS_StatusTypeDef VPS2535H :: VPS2535H_GetSenseChannelDiagnostic(IPS_HandleTypeDef *hips){ |
grussian | 0:c175921ca7c3 | 101 | hips->SenseRawValue = 0; //if channel is wrong Sense value is 0 |
grussian | 5:b683e69b181c | 102 | hips->GNDSenseRawValue = 0; // VPS2535H doesn't require GND measurement compensation |
grussian | 0:c175921ca7c3 | 103 | hips-> Status =IPS_WRONG_CHANNEL; |
grussian | 0:c175921ca7c3 | 104 | hips->IO_Status = IPS_IO_FAIL; |
grussian | 0:c175921ca7c3 | 105 | if (hips ->ipsChannel == CHANNEL_1) |
grussian | 0:c175921ca7c3 | 106 | hips->SenseRawValue = CurrentSense1.read() * V_REF * ((R_D1+R_D2)/(R_D2)); |
grussian | 0:c175921ca7c3 | 107 | if (hips ->ipsChannel == CHANNEL_2) |
grussian | 0:c175921ca7c3 | 108 | hips->SenseRawValue = CurrentSense2.read() * V_REF * ((R_D1+R_D2)/(R_D2)); |
grussian | 0:c175921ca7c3 | 109 | |
grussian | 0:c175921ca7c3 | 110 | hips->IO_Status = IPS_IO_SUCCESS; |
grussian | 0:c175921ca7c3 | 111 | hips->Status =IPS_SUCCESS; |
grussian | 0:c175921ca7c3 | 112 | return hips-> Status; |
grussian | 0:c175921ca7c3 | 113 | } |
grussian | 0:c175921ca7c3 | 114 | |
grussian | 0:c175921ca7c3 | 115 | |
grussian | 0:c175921ca7c3 | 116 | /** |
grussian | 0:c175921ca7c3 | 117 | * @brief GetSecureCurrentSense function gets the I-sense switch output pin |
grussian | 0:c175921ca7c3 | 118 | * upon ADC conversion. |
grussian | 0:c175921ca7c3 | 119 | * @param hips: pointer to a IPS_HandleTypeDef structure that contains |
grussian | 5:b683e69b181c | 120 | * the configuration information for the specified VPS2535H module. |
grussian | 0:c175921ca7c3 | 121 | * Value got from V-sense output is stored in hips->SenseValue |
grussian | 0:c175921ca7c3 | 122 | * field. |
grussian | 0:c175921ca7c3 | 123 | * Status of the operation is stored in hips->Status fields |
grussian | 0:c175921ca7c3 | 124 | * @retval IPS status |
grussian | 0:c175921ca7c3 | 125 | */ |
grussian | 5:b683e69b181c | 126 | IPS_StatusTypeDef VPS2535H :: VPS2535H_GetSecureCurrentSense(IPS_HandleTypeDef *hips){ |
grussian | 0:c175921ca7c3 | 127 | |
grussian | 0:c175921ca7c3 | 128 | if ((hips ->ipsChannel != CHANNEL_1) && (hips ->ipsChannel != CHANNEL_2) ){ |
grussian | 0:c175921ca7c3 | 129 | hips->Status = IPS_WRONG_CHANNEL; |
grussian | 0:c175921ca7c3 | 130 | return IPS_WRONG_CHANNEL; |
grussian | 0:c175921ca7c3 | 131 | } |
grussian | 0:c175921ca7c3 | 132 | |
grussian | 0:c175921ca7c3 | 133 | /* Get sense feedback */ |
grussian | 5:b683e69b181c | 134 | if ((VPS2535H_GetSenseChannelDiagnostic(hips) == IPS_SUCCESS) && (hips->Status == IPS_SUCCESS)){ |
grussian | 0:c175921ca7c3 | 135 | hips->IValue= K*hips->SenseRawValue/R_SENSE; |
grussian | 0:c175921ca7c3 | 136 | return IPS_SUCCESS; |
grussian | 0:c175921ca7c3 | 137 | } |
grussian | 0:c175921ca7c3 | 138 | else |
grussian | 0:c175921ca7c3 | 139 | return IPS_FAIL; // see hips->Status |
grussian | 0:c175921ca7c3 | 140 | } |
grussian | 0:c175921ca7c3 | 141 | |
grussian | 0:c175921ca7c3 | 142 | /** |
grussian | 0:c175921ca7c3 | 143 | * @brief GetCurrent function gets the I-sense switch output pin |
grussian | 0:c175921ca7c3 | 144 | * @param Ch: Channel number. Possible value are CHANNEL_1 or CHANNEL_2 |
grussian | 0:c175921ca7c3 | 145 | * @retval Current Value |
grussian | 0:c175921ca7c3 | 146 | */ |
grussian | 5:b683e69b181c | 147 | float VPS2535H :: GetCurrent(int Ch){ |
grussian | 0:c175921ca7c3 | 148 | |
grussian | 0:c175921ca7c3 | 149 | if (Ch == CHANNEL_1) |
grussian | 0:c175921ca7c3 | 150 | return (K*CurrentSense1.read()* ((R_D1+R_D2)/(R_D2)) * V_REF/R_SENSE); |
grussian | 0:c175921ca7c3 | 151 | if (Ch == CHANNEL_2) |
grussian | 0:c175921ca7c3 | 152 | return (K*CurrentSense2.read()* ((R_D1+R_D2)/(R_D2)) * V_REF/R_SENSE); |
grussian | 0:c175921ca7c3 | 153 | return 0; |
grussian | 0:c175921ca7c3 | 154 | } |
grussian | 0:c175921ca7c3 | 155 | |
grussian | 0:c175921ca7c3 | 156 | |
grussian | 0:c175921ca7c3 | 157 | |
grussian | 0:c175921ca7c3 | 158 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
grussian | 0:c175921ca7c3 | 159 |