Fork of MAX32630FTHR utilities library

Dependencies:   MAX14690

Dependents:   MAX32630FTHR_BALANCE_BOT MAX32630FTHR_iButton_uSD_Logger MAX32630FTHR_DS18B20_uSD_Logger MAX32630FTHR_BALANCE_BOT

Fork of max32630fthr by Greg Steiert

Committer:
j3
Date:
Thu Dec 08 03:33:50 2016 +0000
Revision:
6:92b485e70885
Parent:
1:15e34492fbf1
Child:
8:69740ee6903a
Added getVoltage member functions for pmic outputs.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
switches 1:15e34492fbf1 1 /*******************************************************************************
switches 1:15e34492fbf1 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
switches 1:15e34492fbf1 3 *
switches 1:15e34492fbf1 4 * Permission is hereby granted, free of charge, to any person obtaining a
switches 1:15e34492fbf1 5 * copy of this software and associated documentation files (the "Software"),
switches 1:15e34492fbf1 6 * to deal in the Software without restriction, including without limitation
switches 1:15e34492fbf1 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
switches 1:15e34492fbf1 8 * and/or sell copies of the Software, and to permit persons to whom the
switches 1:15e34492fbf1 9 * Software is furnished to do so, subject to the following conditions:
switches 1:15e34492fbf1 10 *
switches 1:15e34492fbf1 11 * The above copyright notice and this permission notice shall be included
switches 1:15e34492fbf1 12 * in all copies or substantial portions of the Software.
switches 1:15e34492fbf1 13 *
switches 1:15e34492fbf1 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
switches 1:15e34492fbf1 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
switches 1:15e34492fbf1 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
switches 1:15e34492fbf1 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
switches 1:15e34492fbf1 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
switches 1:15e34492fbf1 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
switches 1:15e34492fbf1 20 * OTHER DEALINGS IN THE SOFTWARE.
switches 1:15e34492fbf1 21 *
switches 1:15e34492fbf1 22 * Except as contained in this notice, the name of Maxim Integrated
switches 1:15e34492fbf1 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
switches 1:15e34492fbf1 24 * Products, Inc. Branding Policy.
switches 1:15e34492fbf1 25 *
switches 1:15e34492fbf1 26 * The mere transfer of this software does not imply any licenses
switches 1:15e34492fbf1 27 * of trade secrets, proprietary technology, copyrights, patents,
switches 1:15e34492fbf1 28 * trademarks, maskwork rights, or any other form of intellectual
switches 1:15e34492fbf1 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
switches 1:15e34492fbf1 30 * ownership rights.
switches 1:15e34492fbf1 31 *******************************************************************************
switches 1:15e34492fbf1 32 */
switches 1:15e34492fbf1 33
j3 6:92b485e70885 34
switches 0:8926602da648 35 #include "mbed.h"
j3 6:92b485e70885 36 #include "PinNames.h"
j3 6:92b485e70885 37 #include "max32630fthr.h"
switches 0:8926602da648 38 #include "max3263x.h"
switches 0:8926602da648 39 #include "ioman_regs.h"
j3 6:92b485e70885 40 #include "adc.h"
j3 6:92b485e70885 41 #include "mxc_errors.h"
j3 6:92b485e70885 42
switches 0:8926602da648 43
switches 1:15e34492fbf1 44 //******************************************************************************
j3 6:92b485e70885 45 MAX32630FTHR::MAX32630FTHR(IoVoltage vio)
j3 6:92b485e70885 46 : m_i2c(P5_7, P6_0), m_max14690(&m_i2c), m_hdrVio(vio)
switches 1:15e34492fbf1 47 {
switches 1:15e34492fbf1 48 }
switches 0:8926602da648 49
j3 6:92b485e70885 50
switches 1:15e34492fbf1 51 //******************************************************************************
j3 6:92b485e70885 52 int32_t MAX32630FTHR::init()
switches 0:8926602da648 53 {
j3 6:92b485e70885 54 int32_t rtnVal = -1;
j3 6:92b485e70885 55
switches 1:15e34492fbf1 56 // Override the default values
j3 6:92b485e70885 57 m_max14690.ldo2Millivolts = 3300;
j3 6:92b485e70885 58 m_max14690.ldo3Millivolts = 3300;
j3 6:92b485e70885 59 m_max14690.ldo2Mode = MAX14690::LDO_ENABLED;
j3 6:92b485e70885 60 m_max14690.ldo3Mode = MAX14690::LDO_ENABLED;
j3 6:92b485e70885 61 m_max14690.monCfg = MAX14690::MON_HI_Z;
switches 1:15e34492fbf1 62 // Note that writing the local value does directly affect the part
switches 1:15e34492fbf1 63 // The buck-boost regulator will remain off until init is called
switches 1:15e34492fbf1 64
switches 1:15e34492fbf1 65 // Call init to apply all settings to the PMIC
j3 6:92b485e70885 66 if (m_max14690.init() != MAX14690_ERROR)
j3 6:92b485e70885 67 {
j3 6:92b485e70885 68 // Set micro SD card pins to 3.3V
j3 6:92b485e70885 69 vddioh(P0_4, VIO_3V3);
j3 6:92b485e70885 70 vddioh(P0_5, VIO_3V3);
j3 6:92b485e70885 71 vddioh(P0_6, VIO_3V3);
j3 6:92b485e70885 72 vddioh(P0_7, VIO_3V3);
j3 6:92b485e70885 73 // Set LED pins to 3.3V
j3 6:92b485e70885 74 vddioh(P2_4, VIO_3V3);
j3 6:92b485e70885 75 vddioh(P2_5, VIO_3V3);
j3 6:92b485e70885 76 vddioh(P2_6, VIO_3V3);
j3 6:92b485e70885 77 // Set header pins to hdrVio
j3 6:92b485e70885 78 vddioh(P3_0, m_hdrVio);
j3 6:92b485e70885 79 vddioh(P3_1, m_hdrVio);
j3 6:92b485e70885 80 vddioh(P3_2, m_hdrVio);
j3 6:92b485e70885 81 vddioh(P3_3, m_hdrVio);
j3 6:92b485e70885 82 vddioh(P3_4, m_hdrVio);
j3 6:92b485e70885 83 vddioh(P3_5, m_hdrVio);
j3 6:92b485e70885 84 vddioh(P4_0, m_hdrVio);
j3 6:92b485e70885 85 vddioh(P4_1, m_hdrVio);
j3 6:92b485e70885 86 vddioh(P4_2, m_hdrVio);
j3 6:92b485e70885 87 vddioh(P4_3, m_hdrVio);
j3 6:92b485e70885 88 vddioh(P4_4, m_hdrVio);
j3 6:92b485e70885 89 vddioh(P4_5, m_hdrVio);
j3 6:92b485e70885 90 vddioh(P4_6, m_hdrVio);
j3 6:92b485e70885 91 vddioh(P4_7, m_hdrVio);
j3 6:92b485e70885 92 vddioh(P5_0, m_hdrVio);
j3 6:92b485e70885 93 vddioh(P5_1, m_hdrVio);
j3 6:92b485e70885 94 vddioh(P5_2, m_hdrVio);
j3 6:92b485e70885 95 vddioh(P5_3, m_hdrVio);
j3 6:92b485e70885 96 vddioh(P5_4, m_hdrVio);
j3 6:92b485e70885 97 vddioh(P5_5, m_hdrVio);
j3 6:92b485e70885 98 vddioh(P5_6, m_hdrVio);
j3 6:92b485e70885 99
j3 6:92b485e70885 100 if(ADC_Init() == E_NO_ERROR)
j3 6:92b485e70885 101 {
j3 6:92b485e70885 102 rtnVal = 0;
j3 6:92b485e70885 103 }
switches 1:15e34492fbf1 104 }
j3 6:92b485e70885 105
j3 6:92b485e70885 106 return rtnVal;
switches 0:8926602da648 107 }
switches 0:8926602da648 108
j3 6:92b485e70885 109
switches 1:15e34492fbf1 110 //******************************************************************************
j3 6:92b485e70885 111 int32_t MAX32630FTHR::vddioh(PinName pin, IoVoltage vio)
switches 0:8926602da648 112 {
switches 0:8926602da648 113 __IO uint32_t *use_vddioh = &((mxc_ioman_regs_t *)MXC_IOMAN)->use_vddioh_0;
switches 0:8926602da648 114
switches 0:8926602da648 115 if (pin == NOT_CONNECTED) {
switches 0:8926602da648 116 return -1;
switches 0:8926602da648 117 }
switches 0:8926602da648 118
switches 0:8926602da648 119 use_vddioh += PINNAME_TO_PORT(pin) >> 2;
switches 1:15e34492fbf1 120 if (vio) {
switches 0:8926602da648 121 *use_vddioh |= (1 << (PINNAME_TO_PIN(pin) + ((PINNAME_TO_PORT(pin) & 0x3) << 3)));
switches 0:8926602da648 122 } else {
switches 0:8926602da648 123 *use_vddioh &= ~(1 << (PINNAME_TO_PIN(pin) + ((PINNAME_TO_PORT(pin) & 0x3) << 3)));
switches 0:8926602da648 124 }
switches 0:8926602da648 125
switches 0:8926602da648 126 return 0;
switches 0:8926602da648 127 }
j3 6:92b485e70885 128
j3 6:92b485e70885 129
j3 6:92b485e70885 130 //******************************************************************************
j3 6:92b485e70885 131 int32_t MAX32630FTHR::getBatteryVoltage(float *battVolts)
j3 6:92b485e70885 132 {
j3 6:92b485e70885 133 return readMonVoltage(MAX14690::MON_BAT, battVolts);
j3 6:92b485e70885 134 }
j3 6:92b485e70885 135
j3 6:92b485e70885 136
j3 6:92b485e70885 137 //******************************************************************************
j3 6:92b485e70885 138 int32_t MAX32630FTHR::getSysVoltage(float *sysVolts)
j3 6:92b485e70885 139 {
j3 6:92b485e70885 140 return readMonVoltage(MAX14690::MON_SYS, sysVolts);
j3 6:92b485e70885 141 }
j3 6:92b485e70885 142
j3 6:92b485e70885 143
j3 6:92b485e70885 144 //******************************************************************************
j3 6:92b485e70885 145 int32_t MAX32630FTHR::getBuck1Voltage(float *buckVolts)
j3 6:92b485e70885 146 {
j3 6:92b485e70885 147 return readMonVoltage(MAX14690::MON_BUCK1, buckVolts);
j3 6:92b485e70885 148 }
j3 6:92b485e70885 149
j3 6:92b485e70885 150
j3 6:92b485e70885 151 //******************************************************************************
j3 6:92b485e70885 152 int32_t MAX32630FTHR::getBuck2Voltage(float *buckVolts)
j3 6:92b485e70885 153 {
j3 6:92b485e70885 154 return readMonVoltage(MAX14690::MON_BUCK2, buckVolts);
j3 6:92b485e70885 155 }
j3 6:92b485e70885 156
j3 6:92b485e70885 157
j3 6:92b485e70885 158 //******************************************************************************
j3 6:92b485e70885 159 int32_t MAX32630FTHR::getLDO1Voltage(float *ldoVolts)
j3 6:92b485e70885 160 {
j3 6:92b485e70885 161 return readMonVoltage(MAX14690::MON_LDO1, ldoVolts);
j3 6:92b485e70885 162 }
j3 6:92b485e70885 163
j3 6:92b485e70885 164
j3 6:92b485e70885 165 //******************************************************************************
j3 6:92b485e70885 166 int32_t MAX32630FTHR::getLDO2Voltage(float *ldoVolts)
j3 6:92b485e70885 167 {
j3 6:92b485e70885 168 return readMonVoltage(MAX14690::MON_LDO2, ldoVolts);
j3 6:92b485e70885 169 }
j3 6:92b485e70885 170
j3 6:92b485e70885 171
j3 6:92b485e70885 172 //******************************************************************************
j3 6:92b485e70885 173 int32_t MAX32630FTHR::getLDO3Voltage(float *ldoVolts)
j3 6:92b485e70885 174 {
j3 6:92b485e70885 175 return readMonVoltage(MAX14690::MON_LDO3, ldoVolts);
j3 6:92b485e70885 176 }
j3 6:92b485e70885 177
j3 6:92b485e70885 178
j3 6:92b485e70885 179 //******************************************************************************
j3 6:92b485e70885 180 int32_t MAX32630FTHR::readMonVoltage(MAX14690::monCfg_t monCfg, float *volts)
j3 6:92b485e70885 181 {
j3 6:92b485e70885 182 int32_t rtnVal = -1;
j3 6:92b485e70885 183 uint16_t data;
j3 6:92b485e70885 184
j3 6:92b485e70885 185 if(m_max14690.monSet(monCfg, MAX14690::MON_DIV4) == 0)
j3 6:92b485e70885 186 {
j3 6:92b485e70885 187 wait_ms(1);
j3 6:92b485e70885 188 ADC_StartConvert(ADC_CH_0, 1, 0);
j3 6:92b485e70885 189 if(ADC_GetData(&data) == E_NO_ERROR)
j3 6:92b485e70885 190 {
j3 6:92b485e70885 191 *volts = ((((0x03FF & data) * 4.8F)/1023.0F));
j3 6:92b485e70885 192 rtnVal = m_max14690.monSet(MAX14690::MON_HI_Z, MAX14690::MON_DIV1);
j3 6:92b485e70885 193 }
j3 6:92b485e70885 194 }
j3 6:92b485e70885 195
j3 6:92b485e70885 196 return rtnVal;
j3 6:92b485e70885 197 }