Utility library for HSP SPo2 HR demo including user interface, board support adn accelerometer.
Embed:
(wiki syntax)
Show/hide line numbers
max32630hsp.cpp
00001 /******************************************************************************* 00002 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a 00005 * copy of this software and associated documentation files (the "Software"), 00006 * to deal in the Software without restriction, including without limitation 00007 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00008 * and/or sell copies of the Software, and to permit persons to whom the 00009 * Software is furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included 00012 * in all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00015 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00016 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00017 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES 00018 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00019 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00020 * OTHER DEALINGS IN THE SOFTWARE. 00021 * 00022 * Except as contained in this notice, the name of Maxim Integrated 00023 * Products, Inc. shall not be used except as stated in the Maxim Integrated 00024 * Products, Inc. Branding Policy. 00025 * 00026 * The mere transfer of this software does not imply any licenses 00027 * of trade secrets, proprietary technology, copyrights, patents, 00028 * trademarks, maskwork rights, or any other form of intellectual 00029 * property whatsoever. Maxim Integrated Products, Inc. retains all 00030 * ownership rights. 00031 ******************************************************************************* 00032 */ 00033 00034 #include "mbed.h" 00035 #include "max3263x.h" 00036 #include "ioman_regs.h" 00037 #include "PinNames.h" 00038 #include "max32630hsp.h" 00039 00040 00041 //****************************************************************************** 00042 MAX32630HSP::MAX32630HSP() : i2c(P5_7, P6_0), max20303(&i2c) 00043 { 00044 } 00045 00046 //****************************************************************************** 00047 MAX32630HSP::MAX32630HSP(vio_t vio) : i2c(P5_7, P6_0), max20303(&i2c) 00048 { 00049 00050 init(vio); 00051 } 00052 00053 //****************************************************************************** 00054 MAX32630HSP::MAX32630HSP(vio_t vio, InterruptIn *max32630hsp3_powerButtonInterrupt) : i2c(P5_7, P6_0), max20303(&i2c), m_max32630hsp3_powerButtonInterrupt(max32630hsp3_powerButtonInterrupt) 00055 { 00056 init(vio); 00057 00058 m_max32630hsp3_powerButtonInterrupt->disable_irq(); 00059 m_max32630hsp3_powerButtonInterrupt->rise(this, &MAX32630HSP::event_powerButtonReleased); 00060 m_max32630hsp3_powerButtonInterrupt->mode(PullUp); 00061 m_max32630hsp3_powerButtonInterrupt->enable_irq(); 00062 } 00063 00064 00065 //****************************************************************************** 00066 MAX32630HSP::~MAX32630HSP() 00067 { 00068 00069 } 00070 00071 00072 //****************************************************************************** 00073 int MAX32630HSP::init(vio_t hdrVio) 00074 { 00075 /* Wait for pmic to settle down */ 00076 wait_ms(800); 00077 00078 00079 00080 /*Set LDO1 to 1.8v*/ 00081 max20303.LDO1Config(); 00082 00083 /*Set LDO2 to 3v*/ 00084 max20303.LDO2Config(); 00085 00086 //max20303.BoostEnable(); 00087 max20303.BuckBoostEnable(); 00088 00089 00090 max20303.led0on(0); 00091 max20303.led1on(0); 00092 max20303.led2on(0); 00093 00094 /* Wait for pmic to settle down */ 00095 wait_ms(200); 00096 00097 // Set LED pins to 3.3V 00098 vddioh(P2_4, VIO_3V3); 00099 vddioh(P2_5, VIO_3V3); 00100 vddioh(P2_6, VIO_3V3); 00101 00102 // set i2c pins to 1.8V 00103 vddioh(P3_4, VIO_1V8); 00104 vddioh(P3_5, VIO_1V8); 00105 //ble module pins to 1.8V 00106 vddioh(P0_0, VIO_1V8); 00107 vddioh(P0_1, VIO_1V8); 00108 vddioh(P0_2, VIO_1V8); 00109 vddioh(P0_3, VIO_1V8); 00110 00111 // Set header pins to hdrVio 00112 vddioh(P3_0, hdrVio); 00113 vddioh(P3_1, hdrVio); 00114 vddioh(P3_2, hdrVio); 00115 vddioh(P3_3, hdrVio); 00116 vddioh(P4_0, hdrVio); 00117 vddioh(P4_1, hdrVio); 00118 vddioh(P4_2, hdrVio); 00119 vddioh(P4_3, hdrVio); 00120 vddioh(P4_4, hdrVio); 00121 vddioh(P4_5, hdrVio); 00122 vddioh(P4_6, hdrVio); 00123 vddioh(P4_7, hdrVio); 00124 vddioh(P5_0, hdrVio); 00125 vddioh(P5_1, hdrVio); 00126 vddioh(P5_2, hdrVio); 00127 vddioh(P5_3, hdrVio); 00128 vddioh(P5_4, hdrVio); 00129 vddioh(P5_5, hdrVio); 00130 vddioh(P5_6, hdrVio); 00131 00132 00133 button_longpressdetected = false; 00134 00135 return 0; 00136 } 00137 00138 00139 void MAX32630HSP::event_powerButtonPressed(void) { 00140 00141 max20303.led0on(0); 00142 max20303.led1on(0); 00143 max20303.led2on(1); 00144 00145 /* Button press detected. Wait for button release */ 00146 m_max32630hsp3_powerButtonInterrupt->disable_irq(); 00147 m_max32630hsp3_powerButtonInterrupt->rise(this, &MAX32630HSP::event_powerButtonReleased); 00148 m_max32630hsp3_powerButtonInterrupt->mode(PullUp); 00149 m_max32630hsp3_powerButtonInterrupt->enable_irq(); 00150 00151 /* Button press detected. Start Timeout object for checking long key press event */ 00152 button_timeout.attach( this, &MAX32630HSP::event_longpresscheck , 2.0 ); 00153 00154 /* Button is pressed */ 00155 button_status = true; 00156 } 00157 00158 //****************************************************************************** 00159 void MAX32630HSP::event_powerButtonReleased(void) { 00160 00161 00162 if ( button_longpressdetected ) { 00163 00164 /* Power of the PMIC if long key press is detected */ 00165 max20303.PowerOffDelaythePMIC(); 00166 00167 } 00168 else { 00169 00170 /* Button released before a long key press is detected */ 00171 button_status = false; 00172 00173 } 00174 00175 /* Button is released. Stop timeout object */ 00176 button_timeout.detach(); 00177 00178 max20303.led0on(0); 00179 max20303.led1on(0); 00180 max20303.led2on(0); 00181 00182 /* Button is released. Expect for button press event next time */ 00183 m_max32630hsp3_powerButtonInterrupt->disable_irq(); 00184 m_max32630hsp3_powerButtonInterrupt->fall(this, &MAX32630HSP::event_powerButtonPressed); 00185 m_max32630hsp3_powerButtonInterrupt->mode(PullUp); 00186 m_max32630hsp3_powerButtonInterrupt->enable_irq(); 00187 00188 00189 } 00190 00191 void MAX32630HSP::event_longpresscheck(void) { 00192 00193 /* This is the callback for timeout object to detect long key press for power down */ 00194 00195 if ( button_status == 1 ) { 00196 00197 /* If button_status is still 1 when timeout is triggered, it will be interpreted as a long key press */ 00198 button_longpressdetected = true; 00199 00200 /* The PMIC will be powered of when the button is released */ 00201 max20303.led0on(0); 00202 max20303.led1on(1); 00203 max20303.led2on(0); 00204 } 00205 00206 } 00207 00208 void MAX32630HSP::enableDisplay(void) 00209 { 00210 vddioh(P6_4, VIO_3V3); //EXTCOM 00211 vddioh(P6_1, VIO_3V3); //SCLK 00212 vddioh(P6_2, VIO_3V3); //MOSI1 00213 vddioh(P6_5, VIO_3V3); //SCS 00214 vddioh(P6_4, VIO_3V3); //EXTCOM 00215 vddioh(P6_6, VIO_3V3); //DISP 00216 } 00217 00218 //****************************************************************************** 00219 int MAX32630HSP::vddioh(PinName pin, vio_t vio) 00220 { 00221 __IO uint32_t *use_vddioh = &((mxc_ioman_regs_t *)MXC_IOMAN)->use_vddioh_0; 00222 00223 if (pin == NOT_CONNECTED) { 00224 return -1; 00225 } 00226 00227 use_vddioh += PINNAME_TO_PORT(pin) >> 2; 00228 if (vio) { 00229 *use_vddioh |= (1 << (PINNAME_TO_PIN(pin) + ((PINNAME_TO_PORT(pin) & 0x3) << 3))); 00230 } else { 00231 *use_vddioh &= ~(1 << (PINNAME_TO_PIN(pin) + ((PINNAME_TO_PORT(pin) & 0x3) << 3))); 00232 } 00233 00234 return 0; 00235 }
Generated on Fri Jul 15 2022 01:41:58 by 1.7.2