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:
Wed Dec 14 22:35:05 2016 +0000
Revision:
9:760049f68423
Parent:
8:69740ee6903a
Child:
10:aee086319400
Replace pmic init code in max32630fthr init, low_level_init only turns on LDO2

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 8:69740ee6903a 45 MAX32630FTHR::MAX32630FTHR()
j3 8:69740ee6903a 46 : m_i2c(P5_7, P6_0), m_max14690(&m_i2c)
switches 1:15e34492fbf1 47 {
switches 1:15e34492fbf1 48 }
switches 0:8926602da648 49
j3 6:92b485e70885 50
switches 1:15e34492fbf1 51 //******************************************************************************
j3 8:69740ee6903a 52 int32_t MAX32630FTHR::init(IoVoltage vio)
switches 0:8926602da648 53 {
j3 9:760049f68423 54 int32_t rtnVal = -1;
j3 8:69740ee6903a 55 m_hdrVio = vio;
j3 6:92b485e70885 56
j3 9:760049f68423 57 // Override the default values
j3 9:760049f68423 58 m_max14690.ldo2Millivolts = 3300;
j3 9:760049f68423 59 m_max14690.ldo3Millivolts = 3300;
j3 9:760049f68423 60 m_max14690.ldo2Mode = MAX14690::LDO_ENABLED;
j3 9:760049f68423 61 m_max14690.ldo3Mode = MAX14690::LDO_ENABLED;
j3 9:760049f68423 62 m_max14690.monCfg = MAX14690::MON_HI_Z;
j3 9:760049f68423 63 // Note that writing the local value does directly affect the part
j3 9:760049f68423 64 // The buck-boost regulator will remain off until init is called
j3 9:760049f68423 65
j3 9:760049f68423 66 // Call init to apply all settings to the PMIC
j3 9:760049f68423 67 if (m_max14690.init() != MAX14690_ERROR)
j3 9:760049f68423 68 {
j3 9:760049f68423 69 // Set micro SD card pins to 3.3V
j3 9:760049f68423 70 vddioh(P0_4, VIO_3V3);
j3 9:760049f68423 71 vddioh(P0_5, VIO_3V3);
j3 9:760049f68423 72 vddioh(P0_6, VIO_3V3);
j3 9:760049f68423 73 vddioh(P0_7, VIO_3V3);
j3 9:760049f68423 74 // Set LED pins to 3.3V
j3 9:760049f68423 75 vddioh(P2_4, VIO_3V3);
j3 9:760049f68423 76 vddioh(P2_5, VIO_3V3);
j3 9:760049f68423 77 vddioh(P2_6, VIO_3V3);
j3 9:760049f68423 78 // Set header pins to hdrVio
j3 9:760049f68423 79 vddioh(P3_0, m_hdrVio);
j3 9:760049f68423 80 vddioh(P3_1, m_hdrVio);
j3 9:760049f68423 81 vddioh(P3_2, m_hdrVio);
j3 9:760049f68423 82 vddioh(P3_3, m_hdrVio);
j3 9:760049f68423 83 vddioh(P3_4, m_hdrVio);
j3 9:760049f68423 84 vddioh(P3_5, m_hdrVio);
j3 9:760049f68423 85 vddioh(P4_0, m_hdrVio);
j3 9:760049f68423 86 vddioh(P4_1, m_hdrVio);
j3 9:760049f68423 87 vddioh(P4_2, m_hdrVio);
j3 9:760049f68423 88 vddioh(P4_3, m_hdrVio);
j3 9:760049f68423 89 vddioh(P4_4, m_hdrVio);
j3 9:760049f68423 90 vddioh(P4_5, m_hdrVio);
j3 9:760049f68423 91 vddioh(P4_6, m_hdrVio);
j3 9:760049f68423 92 vddioh(P4_7, m_hdrVio);
j3 9:760049f68423 93 vddioh(P5_0, m_hdrVio);
j3 9:760049f68423 94 vddioh(P5_1, m_hdrVio);
j3 9:760049f68423 95 vddioh(P5_2, m_hdrVio);
j3 9:760049f68423 96 vddioh(P5_3, m_hdrVio);
j3 9:760049f68423 97 vddioh(P5_4, m_hdrVio);
j3 9:760049f68423 98 vddioh(P5_5, m_hdrVio);
j3 9:760049f68423 99 vddioh(P5_6, m_hdrVio);
j3 9:760049f68423 100
j3 9:760049f68423 101 if(ADC_Init() == E_NO_ERROR)
j3 9:760049f68423 102 {
j3 9:760049f68423 103 rtnVal = 0;
j3 9:760049f68423 104 }
j3 9:760049f68423 105 }
j3 6:92b485e70885 106
j3 9:760049f68423 107 return rtnVal;
switches 0:8926602da648 108 }
switches 0:8926602da648 109
j3 6:92b485e70885 110
switches 1:15e34492fbf1 111 //******************************************************************************
j3 6:92b485e70885 112 int32_t MAX32630FTHR::vddioh(PinName pin, IoVoltage vio)
switches 0:8926602da648 113 {
switches 0:8926602da648 114 __IO uint32_t *use_vddioh = &((mxc_ioman_regs_t *)MXC_IOMAN)->use_vddioh_0;
switches 0:8926602da648 115
switches 0:8926602da648 116 if (pin == NOT_CONNECTED) {
switches 0:8926602da648 117 return -1;
switches 0:8926602da648 118 }
switches 0:8926602da648 119
switches 0:8926602da648 120 use_vddioh += PINNAME_TO_PORT(pin) >> 2;
switches 1:15e34492fbf1 121 if (vio) {
switches 0:8926602da648 122 *use_vddioh |= (1 << (PINNAME_TO_PIN(pin) + ((PINNAME_TO_PORT(pin) & 0x3) << 3)));
switches 0:8926602da648 123 } else {
switches 0:8926602da648 124 *use_vddioh &= ~(1 << (PINNAME_TO_PIN(pin) + ((PINNAME_TO_PORT(pin) & 0x3) << 3)));
switches 0:8926602da648 125 }
switches 0:8926602da648 126
switches 0:8926602da648 127 return 0;
switches 0:8926602da648 128 }
j3 6:92b485e70885 129
j3 6:92b485e70885 130
j3 6:92b485e70885 131 //******************************************************************************
j3 6:92b485e70885 132 int32_t MAX32630FTHR::getBatteryVoltage(float *battVolts)
j3 6:92b485e70885 133 {
j3 6:92b485e70885 134 return readMonVoltage(MAX14690::MON_BAT, battVolts);
j3 6:92b485e70885 135 }
j3 6:92b485e70885 136
j3 6:92b485e70885 137
j3 6:92b485e70885 138 //******************************************************************************
j3 6:92b485e70885 139 int32_t MAX32630FTHR::getSysVoltage(float *sysVolts)
j3 6:92b485e70885 140 {
j3 6:92b485e70885 141 return readMonVoltage(MAX14690::MON_SYS, sysVolts);
j3 6:92b485e70885 142 }
j3 6:92b485e70885 143
j3 6:92b485e70885 144
j3 6:92b485e70885 145 //******************************************************************************
j3 6:92b485e70885 146 int32_t MAX32630FTHR::getBuck1Voltage(float *buckVolts)
j3 6:92b485e70885 147 {
j3 6:92b485e70885 148 return readMonVoltage(MAX14690::MON_BUCK1, buckVolts);
j3 6:92b485e70885 149 }
j3 6:92b485e70885 150
j3 6:92b485e70885 151
j3 6:92b485e70885 152 //******************************************************************************
j3 6:92b485e70885 153 int32_t MAX32630FTHR::getBuck2Voltage(float *buckVolts)
j3 6:92b485e70885 154 {
j3 6:92b485e70885 155 return readMonVoltage(MAX14690::MON_BUCK2, buckVolts);
j3 6:92b485e70885 156 }
j3 6:92b485e70885 157
j3 6:92b485e70885 158
j3 6:92b485e70885 159 //******************************************************************************
j3 6:92b485e70885 160 int32_t MAX32630FTHR::getLDO1Voltage(float *ldoVolts)
j3 6:92b485e70885 161 {
j3 6:92b485e70885 162 return readMonVoltage(MAX14690::MON_LDO1, ldoVolts);
j3 6:92b485e70885 163 }
j3 6:92b485e70885 164
j3 6:92b485e70885 165
j3 6:92b485e70885 166 //******************************************************************************
j3 6:92b485e70885 167 int32_t MAX32630FTHR::getLDO2Voltage(float *ldoVolts)
j3 6:92b485e70885 168 {
j3 6:92b485e70885 169 return readMonVoltage(MAX14690::MON_LDO2, ldoVolts);
j3 6:92b485e70885 170 }
j3 6:92b485e70885 171
j3 6:92b485e70885 172
j3 6:92b485e70885 173 //******************************************************************************
j3 6:92b485e70885 174 int32_t MAX32630FTHR::getLDO3Voltage(float *ldoVolts)
j3 6:92b485e70885 175 {
j3 6:92b485e70885 176 return readMonVoltage(MAX14690::MON_LDO3, ldoVolts);
j3 6:92b485e70885 177 }
j3 6:92b485e70885 178
j3 6:92b485e70885 179
j3 6:92b485e70885 180 //******************************************************************************
j3 6:92b485e70885 181 int32_t MAX32630FTHR::readMonVoltage(MAX14690::monCfg_t monCfg, float *volts)
j3 6:92b485e70885 182 {
j3 6:92b485e70885 183 int32_t rtnVal = -1;
j3 6:92b485e70885 184 uint16_t data;
j3 6:92b485e70885 185
j3 6:92b485e70885 186 if(m_max14690.monSet(monCfg, MAX14690::MON_DIV4) == 0)
j3 6:92b485e70885 187 {
j3 6:92b485e70885 188 wait_ms(1);
j3 6:92b485e70885 189 ADC_StartConvert(ADC_CH_0, 1, 0);
j3 6:92b485e70885 190 if(ADC_GetData(&data) == E_NO_ERROR)
j3 6:92b485e70885 191 {
j3 6:92b485e70885 192 *volts = ((((0x03FF & data) * 4.8F)/1023.0F));
j3 6:92b485e70885 193 rtnVal = m_max14690.monSet(MAX14690::MON_HI_Z, MAX14690::MON_DIV1);
j3 6:92b485e70885 194 }
j3 6:92b485e70885 195 }
j3 6:92b485e70885 196
j3 6:92b485e70885 197 return rtnVal;
j3 6:92b485e70885 198 }