HSP2.0 P2 forked library
Dependents: Host_Software_MAX32664GWEB_HR_wrist Host_Software_MAX32664GWEC_SpO2_HR Host_Software_MAX32664GWEB_HR_EXTENDED Host_Software_MAX32664GWEC_SpO2_HR-_EXTE ... more
Diff: max32630hsp.cpp
- Revision:
- 4:8f96e309b233
- Parent:
- 3:60c0cc971d85
diff -r 60c0cc971d85 -r 8f96e309b233 max32630hsp.cpp --- a/max32630hsp.cpp Wed Apr 25 09:56:03 2018 +0300 +++ b/max32630hsp.cpp Thu Jan 03 12:08:03 2019 +0300 @@ -37,6 +37,7 @@ #include "PinNames.h" #include "max32630hsp.h" + //****************************************************************************** MAX32630HSP::MAX32630HSP() : i2c(P5_7, P6_0), max20303(&i2c) { @@ -45,30 +46,73 @@ //****************************************************************************** MAX32630HSP::MAX32630HSP(vio_t vio) : i2c(P5_7, P6_0), max20303(&i2c) { + init(vio); } //****************************************************************************** +MAX32630HSP::MAX32630HSP(vio_t vio, InterruptIn *max32630hsp3_powerButtonInterrupt) : i2c(P5_7, P6_0), max20303(&i2c), m_max32630hsp3_powerButtonInterrupt(max32630hsp3_powerButtonInterrupt) +{ + init(vio); + + m_max32630hsp3_powerButtonInterrupt->disable_irq(); + m_max32630hsp3_powerButtonInterrupt->rise(this, &MAX32630HSP::event_powerButtonReleased); + m_max32630hsp3_powerButtonInterrupt->mode(PullUp); + m_max32630hsp3_powerButtonInterrupt->enable_irq(); +} + + +//****************************************************************************** MAX32630HSP::~MAX32630HSP() { } + //****************************************************************************** int MAX32630HSP::init(vio_t hdrVio) { + /* Wait for pmic to settle down */ + wait_ms(800); + + + + /*Set LDO1 to 1.8v*/ + max20303.LDO1Config(); + + /*Set LDO2 to 3v*/ + max20303.LDO2Config(); + + //max20303.BoostEnable(); + max20303.BuckBoostEnable(); + + + max20303.led0on(0); + max20303.led1on(0); + max20303.led2on(0); + + /* Wait for pmic to settle down */ + wait_ms(200); + // Set LED pins to 3.3V vddioh(P2_4, VIO_3V3); vddioh(P2_5, VIO_3V3); vddioh(P2_6, VIO_3V3); + // set i2c pins to 1.8V + vddioh(P3_4, VIO_1V8); + vddioh(P3_5, VIO_1V8); + //ble module pins to 1.8V + vddioh(P0_0, VIO_1V8); + vddioh(P0_1, VIO_1V8); + vddioh(P0_2, VIO_1V8); + vddioh(P0_3, VIO_1V8); + // Set header pins to hdrVio vddioh(P3_0, hdrVio); vddioh(P3_1, hdrVio); vddioh(P3_2, hdrVio); vddioh(P3_3, hdrVio); - vddioh(P3_4, hdrVio); - vddioh(P3_5, hdrVio); vddioh(P4_0, hdrVio); vddioh(P4_1, hdrVio); vddioh(P4_2, hdrVio); @@ -85,16 +129,82 @@ vddioh(P5_5, hdrVio); vddioh(P5_6, hdrVio); - /* Wait for pmic to settle down */ - wait_ms(1000); - //max20303.led0on(); - /*Set LDO1 to 1.8v*/ - max20303.LDO1Config(); - max20303.BoostEnable(); - max20303.BuckBoostEnable(); + + button_longpressdetected = false; + return 0; } + +void MAX32630HSP::event_powerButtonPressed(void) { + + max20303.led0on(0); + max20303.led1on(0); + max20303.led2on(1); + + /* Button press detected. Wait for button release */ + m_max32630hsp3_powerButtonInterrupt->disable_irq(); + m_max32630hsp3_powerButtonInterrupt->rise(this, &MAX32630HSP::event_powerButtonReleased); + m_max32630hsp3_powerButtonInterrupt->mode(PullUp); + m_max32630hsp3_powerButtonInterrupt->enable_irq(); + + /* Button press detected. Start Timeout object for checking long key press event */ + button_timeout.attach( this, &MAX32630HSP::event_longpresscheck , 2.0 ); + + /* Button is pressed */ + button_status = true; +} + +//****************************************************************************** +void MAX32630HSP::event_powerButtonReleased(void) { + + + if ( button_longpressdetected ) { + + /* Power of the PMIC if long key press is detected */ + max20303.PowerOffDelaythePMIC(); + + } + else { + + /* Button released before a long key press is detected */ + button_status = false; + + } + + /* Button is released. Stop timeout object */ + button_timeout.detach(); + + max20303.led0on(0); + max20303.led1on(0); + max20303.led2on(0); + + /* Button is released. Expect for button press event next time */ + m_max32630hsp3_powerButtonInterrupt->disable_irq(); + m_max32630hsp3_powerButtonInterrupt->fall(this, &MAX32630HSP::event_powerButtonPressed); + m_max32630hsp3_powerButtonInterrupt->mode(PullUp); + m_max32630hsp3_powerButtonInterrupt->enable_irq(); + + +} + +void MAX32630HSP::event_longpresscheck(void) { + + /* This is the callback for timeout object to detect long key press for power down */ + + if ( button_status == 1 ) { + + /* If button_status is still 1 when timeout is triggered, it will be interpreted as a long key press */ + button_longpressdetected = true; + + /* The PMIC will be powered of when the button is released */ + max20303.led0on(0); + max20303.led1on(1); + max20303.led2on(0); + } + +} + void MAX32630HSP::enableDisplay(void) { vddioh(P6_4, VIO_3V3); //EXTCOM