Fork of MAX32630FTHR utilities library
Dependents: MAX32630FTHR_BALANCE_BOT MAX32630FTHR_iButton_uSD_Logger MAX32630FTHR_DS18B20_uSD_Logger MAX32630FTHR_BALANCE_BOT
Fork of max32630fthr by
max32630fthr.cpp@8:69740ee6903a, 2016-12-14 (annotated)
- Committer:
- j3
- Date:
- Wed Dec 14 22:10:01 2016 +0000
- Revision:
- 8:69740ee6903a
- Parent:
- 6:92b485e70885
- Child:
- 9:760049f68423
Removed pmic init since done in low_level_init.c, moved hdrVio selection to init mbrfx
Who changed what in which revision?
User | Revision | Line number | New 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 | 8:69740ee6903a | 54 | m_hdrVio = vio; |
j3 | 6:92b485e70885 | 55 | |
j3 | 8:69740ee6903a | 56 | // Set micro SD card pins to 3.3V |
j3 | 8:69740ee6903a | 57 | vddioh(P0_4, VIO_3V3); |
j3 | 8:69740ee6903a | 58 | vddioh(P0_5, VIO_3V3); |
j3 | 8:69740ee6903a | 59 | vddioh(P0_6, VIO_3V3); |
j3 | 8:69740ee6903a | 60 | vddioh(P0_7, VIO_3V3); |
j3 | 8:69740ee6903a | 61 | // Set LED pins to 3.3V |
j3 | 8:69740ee6903a | 62 | vddioh(P2_4, VIO_3V3); |
j3 | 8:69740ee6903a | 63 | vddioh(P2_5, VIO_3V3); |
j3 | 8:69740ee6903a | 64 | vddioh(P2_6, VIO_3V3); |
j3 | 8:69740ee6903a | 65 | // Set header pins to hdrVio |
j3 | 8:69740ee6903a | 66 | vddioh(P3_0, m_hdrVio); |
j3 | 8:69740ee6903a | 67 | vddioh(P3_1, m_hdrVio); |
j3 | 8:69740ee6903a | 68 | vddioh(P3_2, m_hdrVio); |
j3 | 8:69740ee6903a | 69 | vddioh(P3_3, m_hdrVio); |
j3 | 8:69740ee6903a | 70 | vddioh(P3_4, m_hdrVio); |
j3 | 8:69740ee6903a | 71 | vddioh(P3_5, m_hdrVio); |
j3 | 8:69740ee6903a | 72 | vddioh(P4_0, m_hdrVio); |
j3 | 8:69740ee6903a | 73 | vddioh(P4_1, m_hdrVio); |
j3 | 8:69740ee6903a | 74 | vddioh(P4_2, m_hdrVio); |
j3 | 8:69740ee6903a | 75 | vddioh(P4_3, m_hdrVio); |
j3 | 8:69740ee6903a | 76 | vddioh(P4_4, m_hdrVio); |
j3 | 8:69740ee6903a | 77 | vddioh(P4_5, m_hdrVio); |
j3 | 8:69740ee6903a | 78 | vddioh(P4_6, m_hdrVio); |
j3 | 8:69740ee6903a | 79 | vddioh(P4_7, m_hdrVio); |
j3 | 8:69740ee6903a | 80 | vddioh(P5_0, m_hdrVio); |
j3 | 8:69740ee6903a | 81 | vddioh(P5_1, m_hdrVio); |
j3 | 8:69740ee6903a | 82 | vddioh(P5_2, m_hdrVio); |
j3 | 8:69740ee6903a | 83 | vddioh(P5_3, m_hdrVio); |
j3 | 8:69740ee6903a | 84 | vddioh(P5_4, m_hdrVio); |
j3 | 8:69740ee6903a | 85 | vddioh(P5_5, m_hdrVio); |
j3 | 8:69740ee6903a | 86 | vddioh(P5_6, m_hdrVio); |
j3 | 6:92b485e70885 | 87 | |
j3 | 8:69740ee6903a | 88 | return (ADC_Init()); |
switches | 0:8926602da648 | 89 | } |
switches | 0:8926602da648 | 90 | |
j3 | 6:92b485e70885 | 91 | |
switches | 1:15e34492fbf1 | 92 | //****************************************************************************** |
j3 | 6:92b485e70885 | 93 | int32_t MAX32630FTHR::vddioh(PinName pin, IoVoltage vio) |
switches | 0:8926602da648 | 94 | { |
switches | 0:8926602da648 | 95 | __IO uint32_t *use_vddioh = &((mxc_ioman_regs_t *)MXC_IOMAN)->use_vddioh_0; |
switches | 0:8926602da648 | 96 | |
switches | 0:8926602da648 | 97 | if (pin == NOT_CONNECTED) { |
switches | 0:8926602da648 | 98 | return -1; |
switches | 0:8926602da648 | 99 | } |
switches | 0:8926602da648 | 100 | |
switches | 0:8926602da648 | 101 | use_vddioh += PINNAME_TO_PORT(pin) >> 2; |
switches | 1:15e34492fbf1 | 102 | if (vio) { |
switches | 0:8926602da648 | 103 | *use_vddioh |= (1 << (PINNAME_TO_PIN(pin) + ((PINNAME_TO_PORT(pin) & 0x3) << 3))); |
switches | 0:8926602da648 | 104 | } else { |
switches | 0:8926602da648 | 105 | *use_vddioh &= ~(1 << (PINNAME_TO_PIN(pin) + ((PINNAME_TO_PORT(pin) & 0x3) << 3))); |
switches | 0:8926602da648 | 106 | } |
switches | 0:8926602da648 | 107 | |
switches | 0:8926602da648 | 108 | return 0; |
switches | 0:8926602da648 | 109 | } |
j3 | 6:92b485e70885 | 110 | |
j3 | 6:92b485e70885 | 111 | |
j3 | 6:92b485e70885 | 112 | //****************************************************************************** |
j3 | 6:92b485e70885 | 113 | int32_t MAX32630FTHR::getBatteryVoltage(float *battVolts) |
j3 | 6:92b485e70885 | 114 | { |
j3 | 6:92b485e70885 | 115 | return readMonVoltage(MAX14690::MON_BAT, battVolts); |
j3 | 6:92b485e70885 | 116 | } |
j3 | 6:92b485e70885 | 117 | |
j3 | 6:92b485e70885 | 118 | |
j3 | 6:92b485e70885 | 119 | //****************************************************************************** |
j3 | 6:92b485e70885 | 120 | int32_t MAX32630FTHR::getSysVoltage(float *sysVolts) |
j3 | 6:92b485e70885 | 121 | { |
j3 | 6:92b485e70885 | 122 | return readMonVoltage(MAX14690::MON_SYS, sysVolts); |
j3 | 6:92b485e70885 | 123 | } |
j3 | 6:92b485e70885 | 124 | |
j3 | 6:92b485e70885 | 125 | |
j3 | 6:92b485e70885 | 126 | //****************************************************************************** |
j3 | 6:92b485e70885 | 127 | int32_t MAX32630FTHR::getBuck1Voltage(float *buckVolts) |
j3 | 6:92b485e70885 | 128 | { |
j3 | 6:92b485e70885 | 129 | return readMonVoltage(MAX14690::MON_BUCK1, buckVolts); |
j3 | 6:92b485e70885 | 130 | } |
j3 | 6:92b485e70885 | 131 | |
j3 | 6:92b485e70885 | 132 | |
j3 | 6:92b485e70885 | 133 | //****************************************************************************** |
j3 | 6:92b485e70885 | 134 | int32_t MAX32630FTHR::getBuck2Voltage(float *buckVolts) |
j3 | 6:92b485e70885 | 135 | { |
j3 | 6:92b485e70885 | 136 | return readMonVoltage(MAX14690::MON_BUCK2, buckVolts); |
j3 | 6:92b485e70885 | 137 | } |
j3 | 6:92b485e70885 | 138 | |
j3 | 6:92b485e70885 | 139 | |
j3 | 6:92b485e70885 | 140 | //****************************************************************************** |
j3 | 6:92b485e70885 | 141 | int32_t MAX32630FTHR::getLDO1Voltage(float *ldoVolts) |
j3 | 6:92b485e70885 | 142 | { |
j3 | 6:92b485e70885 | 143 | return readMonVoltage(MAX14690::MON_LDO1, ldoVolts); |
j3 | 6:92b485e70885 | 144 | } |
j3 | 6:92b485e70885 | 145 | |
j3 | 6:92b485e70885 | 146 | |
j3 | 6:92b485e70885 | 147 | //****************************************************************************** |
j3 | 6:92b485e70885 | 148 | int32_t MAX32630FTHR::getLDO2Voltage(float *ldoVolts) |
j3 | 6:92b485e70885 | 149 | { |
j3 | 6:92b485e70885 | 150 | return readMonVoltage(MAX14690::MON_LDO2, ldoVolts); |
j3 | 6:92b485e70885 | 151 | } |
j3 | 6:92b485e70885 | 152 | |
j3 | 6:92b485e70885 | 153 | |
j3 | 6:92b485e70885 | 154 | //****************************************************************************** |
j3 | 6:92b485e70885 | 155 | int32_t MAX32630FTHR::getLDO3Voltage(float *ldoVolts) |
j3 | 6:92b485e70885 | 156 | { |
j3 | 6:92b485e70885 | 157 | return readMonVoltage(MAX14690::MON_LDO3, ldoVolts); |
j3 | 6:92b485e70885 | 158 | } |
j3 | 6:92b485e70885 | 159 | |
j3 | 6:92b485e70885 | 160 | |
j3 | 6:92b485e70885 | 161 | //****************************************************************************** |
j3 | 6:92b485e70885 | 162 | int32_t MAX32630FTHR::readMonVoltage(MAX14690::monCfg_t monCfg, float *volts) |
j3 | 6:92b485e70885 | 163 | { |
j3 | 6:92b485e70885 | 164 | int32_t rtnVal = -1; |
j3 | 6:92b485e70885 | 165 | uint16_t data; |
j3 | 6:92b485e70885 | 166 | |
j3 | 6:92b485e70885 | 167 | if(m_max14690.monSet(monCfg, MAX14690::MON_DIV4) == 0) |
j3 | 6:92b485e70885 | 168 | { |
j3 | 6:92b485e70885 | 169 | wait_ms(1); |
j3 | 6:92b485e70885 | 170 | ADC_StartConvert(ADC_CH_0, 1, 0); |
j3 | 6:92b485e70885 | 171 | if(ADC_GetData(&data) == E_NO_ERROR) |
j3 | 6:92b485e70885 | 172 | { |
j3 | 6:92b485e70885 | 173 | *volts = ((((0x03FF & data) * 4.8F)/1023.0F)); |
j3 | 6:92b485e70885 | 174 | rtnVal = m_max14690.monSet(MAX14690::MON_HI_Z, MAX14690::MON_DIV1); |
j3 | 6:92b485e70885 | 175 | } |
j3 | 6:92b485e70885 | 176 | } |
j3 | 6:92b485e70885 | 177 | |
j3 | 6:92b485e70885 | 178 | return rtnVal; |
j3 | 6:92b485e70885 | 179 | } |