TEST

Dependencies:   max32630fthr Adafruit_FeatherOLED USBDevice

Committer:
gmehmet
Date:
Wed Apr 10 14:56:25 2019 +0300
Revision:
1:f60eafbf009a
upload from local

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gmehmet 1:f60eafbf009a 1 /*******************************************************************************
gmehmet 1:f60eafbf009a 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
gmehmet 1:f60eafbf009a 3 *
gmehmet 1:f60eafbf009a 4 * Permission is hereby granted, free of charge, to any person obtaining a
gmehmet 1:f60eafbf009a 5 * copy of this software and associated documentation files (the "Software"),
gmehmet 1:f60eafbf009a 6 * to deal in the Software without restriction, including without limitation
gmehmet 1:f60eafbf009a 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
gmehmet 1:f60eafbf009a 8 * and/or sell copies of the Software, and to permit persons to whom the
gmehmet 1:f60eafbf009a 9 * Software is furnished to do so, subject to the following conditions:
gmehmet 1:f60eafbf009a 10 *
gmehmet 1:f60eafbf009a 11 * The above copyright notice and this permission notice shall be included
gmehmet 1:f60eafbf009a 12 * in all copies or substantial portions of the Software.
gmehmet 1:f60eafbf009a 13 *
gmehmet 1:f60eafbf009a 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
gmehmet 1:f60eafbf009a 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
gmehmet 1:f60eafbf009a 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
gmehmet 1:f60eafbf009a 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
gmehmet 1:f60eafbf009a 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
gmehmet 1:f60eafbf009a 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
gmehmet 1:f60eafbf009a 20 * OTHER DEALINGS IN THE SOFTWARE.
gmehmet 1:f60eafbf009a 21 *
gmehmet 1:f60eafbf009a 22 * Except as contained in this notice, the name of Maxim Integrated
gmehmet 1:f60eafbf009a 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
gmehmet 1:f60eafbf009a 24 * Products, Inc. Branding Policy.
gmehmet 1:f60eafbf009a 25 *
gmehmet 1:f60eafbf009a 26 * The mere transfer of this software does not imply any licenses
gmehmet 1:f60eafbf009a 27 * of trade secrets, proprietary technology, copyrights, patents,
gmehmet 1:f60eafbf009a 28 * trademarks, maskwork rights, or any other form of intellectual
gmehmet 1:f60eafbf009a 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
gmehmet 1:f60eafbf009a 30 * ownership rights.
gmehmet 1:f60eafbf009a 31 *******************************************************************************
gmehmet 1:f60eafbf009a 32 */
gmehmet 1:f60eafbf009a 33
gmehmet 1:f60eafbf009a 34 #include "mbed.h"
gmehmet 1:f60eafbf009a 35 #include "max3263x.h"
gmehmet 1:f60eafbf009a 36 #include "ioman_regs.h"
gmehmet 1:f60eafbf009a 37 #include "PinNames.h"
gmehmet 1:f60eafbf009a 38 #include "max32630hsp.h"
gmehmet 1:f60eafbf009a 39
gmehmet 1:f60eafbf009a 40
gmehmet 1:f60eafbf009a 41 //******************************************************************************
gmehmet 1:f60eafbf009a 42 MAX32630HSP::MAX32630HSP() : i2c(P5_7, P6_0), max20303(&i2c)
gmehmet 1:f60eafbf009a 43 {
gmehmet 1:f60eafbf009a 44 }
gmehmet 1:f60eafbf009a 45
gmehmet 1:f60eafbf009a 46 //******************************************************************************
gmehmet 1:f60eafbf009a 47 MAX32630HSP::MAX32630HSP(vio_t vio) : i2c(P5_7, P6_0), max20303(&i2c)
gmehmet 1:f60eafbf009a 48 {
gmehmet 1:f60eafbf009a 49
gmehmet 1:f60eafbf009a 50 init(vio);
gmehmet 1:f60eafbf009a 51 }
gmehmet 1:f60eafbf009a 52
gmehmet 1:f60eafbf009a 53 //******************************************************************************
gmehmet 1:f60eafbf009a 54 MAX32630HSP::MAX32630HSP(vio_t vio, InterruptIn *max32630hsp3_powerButtonInterrupt) : i2c(P5_7, P6_0), max20303(&i2c), m_max32630hsp3_powerButtonInterrupt(max32630hsp3_powerButtonInterrupt)
gmehmet 1:f60eafbf009a 55 {
gmehmet 1:f60eafbf009a 56 init(vio);
gmehmet 1:f60eafbf009a 57
gmehmet 1:f60eafbf009a 58 status_powerButton = BUTTONSTATUS_INACTIVE;
gmehmet 1:f60eafbf009a 59 m_max32630hsp3_powerButtonInterrupt->disable_irq();
gmehmet 1:f60eafbf009a 60 m_max32630hsp3_powerButtonInterrupt->rise(this, &MAX32630HSP::event_powerButtonReleased);
gmehmet 1:f60eafbf009a 61 m_max32630hsp3_powerButtonInterrupt->mode(PullUp);
gmehmet 1:f60eafbf009a 62 m_max32630hsp3_powerButtonInterrupt->enable_irq();
gmehmet 1:f60eafbf009a 63 }
gmehmet 1:f60eafbf009a 64
gmehmet 1:f60eafbf009a 65
gmehmet 1:f60eafbf009a 66 //******************************************************************************
gmehmet 1:f60eafbf009a 67 MAX32630HSP::~MAX32630HSP()
gmehmet 1:f60eafbf009a 68 {
gmehmet 1:f60eafbf009a 69
gmehmet 1:f60eafbf009a 70 }
gmehmet 1:f60eafbf009a 71
gmehmet 1:f60eafbf009a 72
gmehmet 1:f60eafbf009a 73 //******************************************************************************
gmehmet 1:f60eafbf009a 74 int MAX32630HSP::init(vio_t hdrVio)
gmehmet 1:f60eafbf009a 75 {
gmehmet 1:f60eafbf009a 76 /* Wait for pmic to settle down */
gmehmet 1:f60eafbf009a 77 wait_ms(800);
gmehmet 1:f60eafbf009a 78
gmehmet 1:f60eafbf009a 79 set_time(1544787300); // Set RTC time to Wed, 28 Oct 2009 11:35:37
gmehmet 1:f60eafbf009a 80
gmehmet 1:f60eafbf009a 81 /*Set LDO1 to 1.8v*/
gmehmet 1:f60eafbf009a 82 max20303.LDO1Config();
gmehmet 1:f60eafbf009a 83
gmehmet 1:f60eafbf009a 84 /*Set LDO2 to 3v*/
gmehmet 1:f60eafbf009a 85 max20303.LDO2Config();
gmehmet 1:f60eafbf009a 86
gmehmet 1:f60eafbf009a 87 //max20303.BoostEnable();
gmehmet 1:f60eafbf009a 88 max20303.BuckBoostEnable();
gmehmet 1:f60eafbf009a 89
gmehmet 1:f60eafbf009a 90
gmehmet 1:f60eafbf009a 91 max20303.led0on(0);
gmehmet 1:f60eafbf009a 92 max20303.led1on(0);
gmehmet 1:f60eafbf009a 93 max20303.led2on(0);
gmehmet 1:f60eafbf009a 94
gmehmet 1:f60eafbf009a 95 /* Wait for pmic to settle down */
gmehmet 1:f60eafbf009a 96 wait_ms(200);
gmehmet 1:f60eafbf009a 97
gmehmet 1:f60eafbf009a 98 // Set LED pins to 3.3V
gmehmet 1:f60eafbf009a 99 vddioh(P2_4, VIO_3V3);
gmehmet 1:f60eafbf009a 100 vddioh(P2_5, VIO_3V3);
gmehmet 1:f60eafbf009a 101 vddioh(P2_6, VIO_3V3);
gmehmet 1:f60eafbf009a 102
gmehmet 1:f60eafbf009a 103 // set i2c pins to 1.8V
gmehmet 1:f60eafbf009a 104 vddioh(P3_4, VIO_1V8);
gmehmet 1:f60eafbf009a 105 vddioh(P3_5, VIO_1V8);
gmehmet 1:f60eafbf009a 106 //ble module pins to 1.8V
gmehmet 1:f60eafbf009a 107 vddioh(P0_0, VIO_1V8);
gmehmet 1:f60eafbf009a 108 vddioh(P0_1, VIO_1V8);
gmehmet 1:f60eafbf009a 109 vddioh(P0_2, VIO_1V8);
gmehmet 1:f60eafbf009a 110 vddioh(P0_3, VIO_1V8);
gmehmet 1:f60eafbf009a 111
gmehmet 1:f60eafbf009a 112 // Set header pins to hdrVio
gmehmet 1:f60eafbf009a 113 vddioh(P3_0, hdrVio);
gmehmet 1:f60eafbf009a 114 vddioh(P3_1, hdrVio);
gmehmet 1:f60eafbf009a 115 vddioh(P3_2, hdrVio);
gmehmet 1:f60eafbf009a 116 vddioh(P3_3, hdrVio);
gmehmet 1:f60eafbf009a 117 vddioh(P4_0, hdrVio);
gmehmet 1:f60eafbf009a 118 vddioh(P4_1, hdrVio);
gmehmet 1:f60eafbf009a 119 vddioh(P4_2, hdrVio);
gmehmet 1:f60eafbf009a 120 vddioh(P4_3, hdrVio);
gmehmet 1:f60eafbf009a 121 vddioh(P4_4, hdrVio);
gmehmet 1:f60eafbf009a 122 vddioh(P4_5, hdrVio);
gmehmet 1:f60eafbf009a 123 vddioh(P4_6, hdrVio);
gmehmet 1:f60eafbf009a 124 vddioh(P4_7, hdrVio);
gmehmet 1:f60eafbf009a 125 vddioh(P5_0, hdrVio);
gmehmet 1:f60eafbf009a 126 vddioh(P5_1, hdrVio);
gmehmet 1:f60eafbf009a 127 vddioh(P5_2, hdrVio);
gmehmet 1:f60eafbf009a 128 vddioh(P5_3, hdrVio);
gmehmet 1:f60eafbf009a 129 vddioh(P5_4, hdrVio);
gmehmet 1:f60eafbf009a 130 vddioh(P5_5, hdrVio);
gmehmet 1:f60eafbf009a 131 vddioh(P5_6, hdrVio);
gmehmet 1:f60eafbf009a 132
gmehmet 1:f60eafbf009a 133
gmehmet 1:f60eafbf009a 134
gmehmet 1:f60eafbf009a 135 return 0;
gmehmet 1:f60eafbf009a 136 }
gmehmet 1:f60eafbf009a 137
gmehmet 1:f60eafbf009a 138 //******************************************************************************
gmehmet 1:f60eafbf009a 139 void MAX32630HSP::event_powerButtonPressed(void) {
gmehmet 1:f60eafbf009a 140 status_powerButton = BUTTONSTATUS_PRESSED;
gmehmet 1:f60eafbf009a 141 }
gmehmet 1:f60eafbf009a 142
gmehmet 1:f60eafbf009a 143 //******************************************************************************
gmehmet 1:f60eafbf009a 144 void MAX32630HSP::event_powerButtonReleased(void) {
gmehmet 1:f60eafbf009a 145 if(status_powerButton == BUTTONSTATUS_LONG_PRESS_WAITING_RED) {
gmehmet 1:f60eafbf009a 146 status_powerButton = BUTTONSTATUS_LONG_PRESS;
gmehmet 1:f60eafbf009a 147 } else {
gmehmet 1:f60eafbf009a 148 status_powerButton = BUTTONSTATUS_RELEASED;
gmehmet 1:f60eafbf009a 149 }
gmehmet 1:f60eafbf009a 150 }
gmehmet 1:f60eafbf009a 151
gmehmet 1:f60eafbf009a 152 //******************************************************************************
gmehmet 1:f60eafbf009a 153 void MAX32630HSP::event_longpresscheck(void) {
gmehmet 1:f60eafbf009a 154 status_powerButton = BUTTONSTATUS_LONG_PRESS_WAITING;
gmehmet 1:f60eafbf009a 155 }
gmehmet 1:f60eafbf009a 156
gmehmet 1:f60eafbf009a 157 //******************************************************************************
gmehmet 1:f60eafbf009a 158 void MAX32630HSP::enableDisplay(void)
gmehmet 1:f60eafbf009a 159 {
gmehmet 1:f60eafbf009a 160 vddioh(P6_4, VIO_3V3); //EXTCOM
gmehmet 1:f60eafbf009a 161 vddioh(P6_1, VIO_3V3); //SCLK
gmehmet 1:f60eafbf009a 162 vddioh(P6_2, VIO_3V3); //MOSI1
gmehmet 1:f60eafbf009a 163 vddioh(P6_5, VIO_3V3); //SCS
gmehmet 1:f60eafbf009a 164 vddioh(P6_4, VIO_3V3); //EXTCOM
gmehmet 1:f60eafbf009a 165 vddioh(P6_6, VIO_3V3); //DISP
gmehmet 1:f60eafbf009a 166 }
gmehmet 1:f60eafbf009a 167
gmehmet 1:f60eafbf009a 168 //******************************************************************************
gmehmet 1:f60eafbf009a 169 void MAX32630HSP::Max32630HSP_CheckInterrupt_Status(void) {
gmehmet 1:f60eafbf009a 170
gmehmet 1:f60eafbf009a 171 switch (status_powerButton) {
gmehmet 1:f60eafbf009a 172 case BUTTONSTATUS_PRESSED: {
gmehmet 1:f60eafbf009a 173 max20303.led0on(0);
gmehmet 1:f60eafbf009a 174 max20303.led1on(0);
gmehmet 1:f60eafbf009a 175 max20303.led2on(1);
gmehmet 1:f60eafbf009a 176 /* Button press detected. Wait for button release */
gmehmet 1:f60eafbf009a 177 m_max32630hsp3_powerButtonInterrupt->disable_irq();
gmehmet 1:f60eafbf009a 178 m_max32630hsp3_powerButtonInterrupt->rise(this, &MAX32630HSP::event_powerButtonReleased);
gmehmet 1:f60eafbf009a 179 m_max32630hsp3_powerButtonInterrupt->mode(PullUp);
gmehmet 1:f60eafbf009a 180 m_max32630hsp3_powerButtonInterrupt->enable_irq();
gmehmet 1:f60eafbf009a 181 /* Button press detected. Start Timeout object for checking long key press event */
gmehmet 1:f60eafbf009a 182 button_timeout.attach( this, &MAX32630HSP::event_longpresscheck , 2.0 );
gmehmet 1:f60eafbf009a 183 /* Button is pressed */
gmehmet 1:f60eafbf009a 184 status_powerButton = BUTTONSTATUS_PRESSED_WAITING;
gmehmet 1:f60eafbf009a 185
gmehmet 1:f60eafbf009a 186 } break;
gmehmet 1:f60eafbf009a 187 case BUTTONSTATUS_RELEASED: {
gmehmet 1:f60eafbf009a 188 /* Button is released. Stop timeout object */
gmehmet 1:f60eafbf009a 189 button_timeout.detach();
gmehmet 1:f60eafbf009a 190 max20303.led0on(0);
gmehmet 1:f60eafbf009a 191 max20303.led1on(0);
gmehmet 1:f60eafbf009a 192 max20303.led2on(0);
gmehmet 1:f60eafbf009a 193 /* Button is released. Expect for button press event next time */
gmehmet 1:f60eafbf009a 194 m_max32630hsp3_powerButtonInterrupt->disable_irq();
gmehmet 1:f60eafbf009a 195 m_max32630hsp3_powerButtonInterrupt->fall(this, &MAX32630HSP::event_powerButtonPressed);
gmehmet 1:f60eafbf009a 196 m_max32630hsp3_powerButtonInterrupt->mode(PullUp);
gmehmet 1:f60eafbf009a 197 m_max32630hsp3_powerButtonInterrupt->enable_irq();
gmehmet 1:f60eafbf009a 198 status_powerButton = BUTTONSTATUS_INACTIVE;
gmehmet 1:f60eafbf009a 199 } break;
gmehmet 1:f60eafbf009a 200 case BUTTONSTATUS_LONG_PRESS_WAITING: {
gmehmet 1:f60eafbf009a 201 max20303.led0on(0);
gmehmet 1:f60eafbf009a 202 max20303.led1on(1);
gmehmet 1:f60eafbf009a 203 max20303.led2on(0);
gmehmet 1:f60eafbf009a 204 status_powerButton = BUTTONSTATUS_LONG_PRESS_WAITING_RED;
gmehmet 1:f60eafbf009a 205 } break;
gmehmet 1:f60eafbf009a 206 case BUTTONSTATUS_LONG_PRESS: {
gmehmet 1:f60eafbf009a 207 max20303.PowerOffDelaythePMIC();
gmehmet 1:f60eafbf009a 208 wait_ms(250);
gmehmet 1:f60eafbf009a 209 status_powerButton = BUTTONSTATUS_INACTIVE;
gmehmet 1:f60eafbf009a 210 } break;
gmehmet 1:f60eafbf009a 211 default:
gmehmet 1:f60eafbf009a 212 break;
gmehmet 1:f60eafbf009a 213 }
gmehmet 1:f60eafbf009a 214 }
gmehmet 1:f60eafbf009a 215
gmehmet 1:f60eafbf009a 216 //******************************************************************************
gmehmet 1:f60eafbf009a 217 int MAX32630HSP::vddioh(PinName pin, vio_t vio)
gmehmet 1:f60eafbf009a 218 {
gmehmet 1:f60eafbf009a 219 __IO uint32_t *use_vddioh = &((mxc_ioman_regs_t *)MXC_IOMAN)->use_vddioh_0;
gmehmet 1:f60eafbf009a 220
gmehmet 1:f60eafbf009a 221 if (pin == NOT_CONNECTED) {
gmehmet 1:f60eafbf009a 222 return -1;
gmehmet 1:f60eafbf009a 223 }
gmehmet 1:f60eafbf009a 224
gmehmet 1:f60eafbf009a 225 use_vddioh += PINNAME_TO_PORT(pin) >> 2;
gmehmet 1:f60eafbf009a 226 if (vio) {
gmehmet 1:f60eafbf009a 227 *use_vddioh |= (1 << (PINNAME_TO_PIN(pin) + ((PINNAME_TO_PORT(pin) & 0x3) << 3)));
gmehmet 1:f60eafbf009a 228 } else {
gmehmet 1:f60eafbf009a 229 *use_vddioh &= ~(1 << (PINNAME_TO_PIN(pin) + ((PINNAME_TO_PORT(pin) & 0x3) << 3)));
gmehmet 1:f60eafbf009a 230 }
gmehmet 1:f60eafbf009a 231
gmehmet 1:f60eafbf009a 232 return 0;
gmehmet 1:f60eafbf009a 233 }