Arun Raj / Mbed OS MAXREFDES101_SOURCE

Dependencies:   max32630fthr Adafruit_FeatherOLED USBDevice

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers max32630hsp.cpp Source File

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     status_powerButton = BUTTONSTATUS_INACTIVE;
00059     m_max32630hsp3_powerButtonInterrupt->disable_irq();
00060     m_max32630hsp3_powerButtonInterrupt->rise(this, &MAX32630HSP::event_powerButtonReleased);
00061     m_max32630hsp3_powerButtonInterrupt->mode(PullUp);
00062     m_max32630hsp3_powerButtonInterrupt->enable_irq();
00063 }
00064 
00065 
00066 //******************************************************************************
00067 MAX32630HSP::~MAX32630HSP()
00068 {
00069 
00070 }
00071 
00072 
00073 //******************************************************************************
00074 int MAX32630HSP::init(vio_t hdrVio)
00075 {
00076     /* Wait for pmic to settle down */
00077     wait_ms(800);
00078 
00079     set_time(1544787300);  // Set RTC time to Wed, 28 Oct 2009 11:35:37
00080 
00081     /*Set LDO1 to 1.8v*/
00082     max20303.LDO1Config();
00083 
00084     /*Set LDO2 to 3v*/
00085     max20303.LDO2Config();
00086 
00087     //max20303.BoostEnable();
00088     max20303.BuckBoostEnable();
00089 
00090 
00091     max20303.led0on(0);
00092     max20303.led1on(0);
00093     max20303.led2on(0);
00094 
00095     /* Wait for pmic to settle down */
00096     wait_ms(200);
00097 
00098     // Set LED pins to 3.3V
00099     vddioh(P2_4, VIO_3V3);
00100     vddioh(P2_5, VIO_3V3);
00101     vddioh(P2_6, VIO_3V3);
00102 
00103     // set i2c pins to 1.8V
00104     vddioh(P3_4, VIO_1V8);
00105     vddioh(P3_5, VIO_1V8);
00106     //ble module pins to 1.8V
00107     vddioh(P0_0, VIO_1V8);
00108     vddioh(P0_1, VIO_1V8);
00109     vddioh(P0_2, VIO_1V8);
00110     vddioh(P0_3, VIO_1V8);
00111 
00112     // Set header pins to hdrVio
00113     vddioh(P3_0, hdrVio);
00114     vddioh(P3_1, hdrVio);
00115     vddioh(P3_2, hdrVio);
00116     vddioh(P3_3, hdrVio);
00117     vddioh(P4_0, hdrVio);
00118     vddioh(P4_1, hdrVio);
00119     vddioh(P4_2, hdrVio);
00120     vddioh(P4_3, hdrVio);
00121     vddioh(P4_4, hdrVio);
00122     vddioh(P4_5, hdrVio);
00123     vddioh(P4_6, hdrVio);
00124     vddioh(P4_7, hdrVio);
00125     vddioh(P5_0, hdrVio);
00126     vddioh(P5_1, hdrVio);
00127     vddioh(P5_2, hdrVio);
00128     vddioh(P5_3, hdrVio);
00129     vddioh(P5_4, hdrVio);
00130     vddioh(P5_5, hdrVio);
00131     vddioh(P5_6, hdrVio);
00132 
00133 
00134 
00135     return 0;
00136 }
00137 
00138 //******************************************************************************
00139 void MAX32630HSP::event_powerButtonPressed(void) {
00140     status_powerButton = BUTTONSTATUS_PRESSED;
00141 }
00142 
00143 //******************************************************************************
00144 void MAX32630HSP::event_powerButtonReleased(void) {
00145     if(status_powerButton == BUTTONSTATUS_LONG_PRESS_WAITING_RED) {
00146         status_powerButton = BUTTONSTATUS_LONG_PRESS;
00147     } else {
00148         status_powerButton = BUTTONSTATUS_RELEASED;
00149     }
00150 }
00151 
00152 //******************************************************************************
00153 void MAX32630HSP::event_longpresscheck(void) {
00154     status_powerButton = BUTTONSTATUS_LONG_PRESS_WAITING;
00155 }
00156 
00157 //******************************************************************************
00158 void MAX32630HSP::enableDisplay(void)
00159 {
00160     vddioh(P6_4, VIO_3V3); //EXTCOM
00161     vddioh(P6_1, VIO_3V3); //SCLK
00162     vddioh(P6_2, VIO_3V3); //MOSI1
00163     vddioh(P6_5, VIO_3V3); //SCS
00164     vddioh(P6_4, VIO_3V3); //EXTCOM
00165     vddioh(P6_6, VIO_3V3); //DISP
00166 }
00167 
00168 //******************************************************************************
00169 void MAX32630HSP::Max32630HSP_CheckInterrupt_Status(void) {
00170 
00171     switch (status_powerButton) {
00172     case BUTTONSTATUS_PRESSED: {
00173         max20303.led0on(0);
00174         max20303.led1on(0);
00175         max20303.led2on(1);
00176         /* Button press detected. Wait for button release */
00177         m_max32630hsp3_powerButtonInterrupt->disable_irq();
00178         m_max32630hsp3_powerButtonInterrupt->rise(this, &MAX32630HSP::event_powerButtonReleased);
00179         m_max32630hsp3_powerButtonInterrupt->mode(PullUp);
00180         m_max32630hsp3_powerButtonInterrupt->enable_irq();
00181         /* Button press detected. Start Timeout object for checking long key press event */
00182         button_timeout.attach( this, &MAX32630HSP::event_longpresscheck , 2.0 );
00183         /* Button is pressed */
00184         status_powerButton = BUTTONSTATUS_PRESSED_WAITING;
00185 
00186     } break;
00187     case BUTTONSTATUS_RELEASED: {
00188         /* Button is released. Stop timeout object */
00189         button_timeout.detach();
00190         max20303.led0on(0);
00191         max20303.led1on(0);
00192         max20303.led2on(0);
00193         /* Button is released. Expect for button press event next time */
00194         m_max32630hsp3_powerButtonInterrupt->disable_irq();
00195         m_max32630hsp3_powerButtonInterrupt->fall(this, &MAX32630HSP::event_powerButtonPressed);
00196         m_max32630hsp3_powerButtonInterrupt->mode(PullUp);
00197         m_max32630hsp3_powerButtonInterrupt->enable_irq();
00198         status_powerButton = BUTTONSTATUS_INACTIVE;
00199     } break;
00200     case BUTTONSTATUS_LONG_PRESS_WAITING: {
00201         max20303.led0on(0);
00202         max20303.led1on(1);
00203         max20303.led2on(0);
00204         status_powerButton = BUTTONSTATUS_LONG_PRESS_WAITING_RED;
00205     } break;
00206     case BUTTONSTATUS_LONG_PRESS: {
00207         max20303.PowerOffDelaythePMIC();
00208         wait_ms(250);
00209         status_powerButton = BUTTONSTATUS_INACTIVE;
00210     } break;
00211     default:
00212         break;
00213     }
00214 }
00215 
00216 //******************************************************************************
00217 int MAX32630HSP::vddioh(PinName pin, vio_t vio)
00218 {
00219     __IO uint32_t *use_vddioh = &((mxc_ioman_regs_t *)MXC_IOMAN)->use_vddioh_0;
00220 
00221     if (pin == NOT_CONNECTED) {
00222         return -1;
00223     }
00224 
00225     use_vddioh += PINNAME_TO_PORT(pin) >> 2;
00226     if (vio) {
00227         *use_vddioh |= (1 << (PINNAME_TO_PIN(pin) + ((PINNAME_TO_PORT(pin) & 0x3) << 3)));
00228     } else {
00229         *use_vddioh &= ~(1 << (PINNAME_TO_PIN(pin) + ((PINNAME_TO_PORT(pin) & 0x3) << 3)));
00230     }
00231 
00232     return 0;
00233 }