HSP2.0 P2 forked library

Dependencies:   max20303

Dependents:   Host_Software_MAX32664GWEB_HR_wrist Host_Software_MAX32664GWEC_SpO2_HR Host_Software_MAX32664GWEB_HR_EXTENDED Host_Software_MAX32664GWEC_SpO2_HR-_EXTE ... more

Files at this revision

API Documentation at this revision

Comitter:
seyhmuscacina
Date:
Thu Jan 03 12:08:03 2019 +0300
Parent:
3:60c0cc971d85
Commit message:
updates board and pmic for customer example SPO2 and WHRM demo

Changed in this revision

max20303.lib Show annotated file Show diff for this revision Revisions of this file
max32630hsp.cpp Show annotated file Show diff for this revision Revisions of this file
max32630hsp.h Show annotated file Show diff for this revision Revisions of this file
--- a/max20303.lib	Wed Apr 25 09:56:03 2018 +0300
+++ b/max20303.lib	Thu Jan 03 12:08:03 2019 +0300
@@ -1,1 +1,1 @@
-https://os.mbed.com/teams/MaximIntegrated/code/max20303/#0333f77c665f
+https://os.mbed.com/users/seyhmuscacina/code/max20303/#39e05cf7ef7d
--- 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
--- a/max32630hsp.h	Wed Apr 25 09:56:03 2018 +0300
+++ b/max32630hsp.h	Thu Jan 03 12:08:03 2019 +0300
@@ -37,6 +37,7 @@
 #include "mbed.h"
 #include "MAX20303.h"
 
+
 /**
  * @brief MAX32630HSP Board Support Library
  *
@@ -69,12 +70,15 @@
  */
 
 // Sharp LS013B7DH03 Memory Display
-#define SCK_PIN     P6_1
-#define MOSI_PIN    P6_2
-#define CS_PIN      P6_5
-#define EXTCOM_PIN  P6_4
-#define DISP_PIN    P6_6
-#define DISPSEL_PIN NC
+#define SCK_PIN     		P6_1
+#define MOSI_PIN    		P6_2
+#define CS_PIN      		P6_5
+#define EXTCOM_PIN  		P6_4
+#define DISP_PIN    		P6_6
+#define DISPSEL_PIN 		NC
+#define	PIN_POWERBUTTON		P7_6
+#define	PIN_UPBUTTON		P2_3
+#define	PIN_DOWNBUTTON		P6_5
 
 class MAX32630HSP
 {
@@ -90,6 +94,11 @@
         VIO_3V3 = 0x01,    ///< 3.3V IO voltage at headers (from LDO2)
     } vio_t;
 
+    enum ButtonStatus {
+    	BUTTONSTATUS_RELEASED = 1,
+		BUTTONSTATUS_PRESSED
+    } ;
+
     /**
         * MAX32630HSP constructor.
         *
@@ -103,10 +112,18 @@
     MAX32630HSP(vio_t vio);
 
     /**
+        * MAX32630HSP constructor.
+        *
+        */
+    MAX32630HSP(vio_t vio, InterruptIn *max32630hsp3_powerButtonInterrupt);
+
+    /**
         * MAX32630HSP destructor.
         */
     ~MAX32630HSP();
 
+    //InterruptIn _interruptIn_PowerButton;
+
     /**
      * @brief   Initialize MAX32630HSP board
      * @details Initializes PMIC and I/O on MAX32630HSP board.
@@ -130,7 +147,12 @@
     */
     int vddioh(PinName pin, vio_t vio);
 
-	/* Set vddio for Sharp LS013B7DH03 Display */
+    /**Interrupt Hander for Power Button Press**/
+
+    //InterruptIn _interruptIn_UpButton(PIN_UPBUTTON);
+    //InterruptIn _interruptIn_DownButton(PIN_DOWNBUTTON);
+
+    /* Set vddio for Sharp LS013B7DH03 Display */
 	void enableDisplay(void);
 
     /// Local I2C bus for configuring PMIC and accessing BMI160 IMU.
@@ -138,6 +160,19 @@
 
     /// MAX20303 PMIC Instance
     MAX20303 max20303;
+
+
+    InterruptIn *m_max32630hsp3_powerButtonInterrupt;
+    bool	button_status;
+    bool	button_longpressdetected;
+    Timeout	button_timeout;
+
+    ButtonStatus status_powerButton;
+    ButtonStatus status_upButton;
+    ButtonStatus status_downButton;
+    void event_powerButtonPressed(void);
+    void event_powerButtonReleased(void);
+    void event_longpresscheck(void);
 };
 
 #endif /* _MAX32630HSP_H_ */