Utility library for HSP SPo2 HR demo including user interface, board support adn accelerometer.

Committer:
gmehmet
Date:
Mon Dec 17 13:58:56 2018 +0300
Revision:
0:a12d6976d64c
create and put source to HSP demo utility repo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gmehmet 0:a12d6976d64c 1 /*******************************************************************************
gmehmet 0:a12d6976d64c 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
gmehmet 0:a12d6976d64c 3 *
gmehmet 0:a12d6976d64c 4 * Permission is hereby granted, free of charge, to any person obtaining a
gmehmet 0:a12d6976d64c 5 * copy of this software and associated documentation files (the "Software"),
gmehmet 0:a12d6976d64c 6 * to deal in the Software without restriction, including without limitation
gmehmet 0:a12d6976d64c 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
gmehmet 0:a12d6976d64c 8 * and/or sell copies of the Software, and to permit persons to whom the
gmehmet 0:a12d6976d64c 9 * Software is furnished to do so, subject to the following conditions:
gmehmet 0:a12d6976d64c 10 *
gmehmet 0:a12d6976d64c 11 * The above copyright notice and this permission notice shall be included
gmehmet 0:a12d6976d64c 12 * in all copies or substantial portions of the Software.
gmehmet 0:a12d6976d64c 13 *
gmehmet 0:a12d6976d64c 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
gmehmet 0:a12d6976d64c 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
gmehmet 0:a12d6976d64c 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
gmehmet 0:a12d6976d64c 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
gmehmet 0:a12d6976d64c 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
gmehmet 0:a12d6976d64c 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
gmehmet 0:a12d6976d64c 20 * OTHER DEALINGS IN THE SOFTWARE.
gmehmet 0:a12d6976d64c 21 *
gmehmet 0:a12d6976d64c 22 * Except as contained in this notice, the name of Maxim Integrated
gmehmet 0:a12d6976d64c 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
gmehmet 0:a12d6976d64c 24 * Products, Inc. Branding Policy.
gmehmet 0:a12d6976d64c 25 *
gmehmet 0:a12d6976d64c 26 * The mere transfer of this software does not imply any licenses
gmehmet 0:a12d6976d64c 27 * of trade secrets, proprietary technology, copyrights, patents,
gmehmet 0:a12d6976d64c 28 * trademarks, maskwork rights, or any other form of intellectual
gmehmet 0:a12d6976d64c 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
gmehmet 0:a12d6976d64c 30 * ownership rights.
gmehmet 0:a12d6976d64c 31 *******************************************************************************
gmehmet 0:a12d6976d64c 32 */
gmehmet 0:a12d6976d64c 33
gmehmet 0:a12d6976d64c 34 #ifndef _MAX32630HSP_H_
gmehmet 0:a12d6976d64c 35 #define _MAX32630HSP_H_
gmehmet 0:a12d6976d64c 36
gmehmet 0:a12d6976d64c 37 #include "mbed.h"
gmehmet 0:a12d6976d64c 38 #include "MAX20303.h"
gmehmet 0:a12d6976d64c 39
gmehmet 0:a12d6976d64c 40
gmehmet 0:a12d6976d64c 41 /**
gmehmet 0:a12d6976d64c 42 * @brief MAX32630HSP Board Support Library
gmehmet 0:a12d6976d64c 43 *
gmehmet 0:a12d6976d64c 44 * @details The MAX32630HSP is a rapid development application board for
gmehmet 0:a12d6976d64c 45 * ultra low power wearable applications. It includes common peripherals and
gmehmet 0:a12d6976d64c 46 * expansion connectors all power optimized for getting the longest life from
gmehmet 0:a12d6976d64c 47 * the battery. This library configures the power and I/O for the board.
gmehmet 0:a12d6976d64c 48 * <br>https://www.maximintegrated.com/max32630hsp
gmehmet 0:a12d6976d64c 49 *
gmehmet 0:a12d6976d64c 50 * @code
gmehmet 0:a12d6976d64c 51 * #include "mbed.h"
gmehmet 0:a12d6976d64c 52 * #include "max32630hsp.h"
gmehmet 0:a12d6976d64c 53 *
gmehmet 0:a12d6976d64c 54 * DigitalOut led1(LED1);
gmehmet 0:a12d6976d64c 55 * MAX32630HSP icarus(MAX32630HSP::VIO_3V3);
gmehmet 0:a12d6976d64c 56 *
gmehmet 0:a12d6976d64c 57 * // main() runs in its own thread in the OS
gmehmet 0:a12d6976d64c 58 * // (note the calls to Thread::wait below for delays)
gmehmet 0:a12d6976d64c 59 * int main()
gmehmet 0:a12d6976d64c 60 * {
gmehmet 0:a12d6976d64c 61 * // initialize power and I/O on MAX32630HSP board
gmehmet 0:a12d6976d64c 62 * icarus.init();
gmehmet 0:a12d6976d64c 63 *
gmehmet 0:a12d6976d64c 64 * while (true) {
gmehmet 0:a12d6976d64c 65 * led1 = !led1;
gmehmet 0:a12d6976d64c 66 * Thread::wait(500);
gmehmet 0:a12d6976d64c 67 * }
gmehmet 0:a12d6976d64c 68 * }
gmehmet 0:a12d6976d64c 69 * @endcode
gmehmet 0:a12d6976d64c 70 */
gmehmet 0:a12d6976d64c 71
gmehmet 0:a12d6976d64c 72 // Sharp LS013B7DH03 Memory Display
gmehmet 0:a12d6976d64c 73 #define SCK_PIN P6_1
gmehmet 0:a12d6976d64c 74 #define MOSI_PIN P6_2
gmehmet 0:a12d6976d64c 75 #define CS_PIN P6_5
gmehmet 0:a12d6976d64c 76 #define EXTCOM_PIN P6_4
gmehmet 0:a12d6976d64c 77 #define DISP_PIN P6_6
gmehmet 0:a12d6976d64c 78 #define DISPSEL_PIN NC
gmehmet 0:a12d6976d64c 79 #define PIN_POWERBUTTON P7_6
gmehmet 0:a12d6976d64c 80 #define PIN_UPBUTTON P2_3
gmehmet 0:a12d6976d64c 81 #define PIN_DOWNBUTTON P6_5
gmehmet 0:a12d6976d64c 82
gmehmet 0:a12d6976d64c 83 class MAX32630HSP
gmehmet 0:a12d6976d64c 84 {
gmehmet 0:a12d6976d64c 85 public:
gmehmet 0:a12d6976d64c 86 // max32630hsp configuration utilities
gmehmet 0:a12d6976d64c 87
gmehmet 0:a12d6976d64c 88 /**
gmehmet 0:a12d6976d64c 89 * @brief IO Voltage
gmehmet 0:a12d6976d64c 90 * @details Enumerated options for operating voltage
gmehmet 0:a12d6976d64c 91 */
gmehmet 0:a12d6976d64c 92 typedef enum {
gmehmet 0:a12d6976d64c 93 VIO_1V8 = 0x00, ///< 1.8V IO voltage at headers (from BUCK2)
gmehmet 0:a12d6976d64c 94 VIO_3V3 = 0x01, ///< 3.3V IO voltage at headers (from LDO2)
gmehmet 0:a12d6976d64c 95 } vio_t;
gmehmet 0:a12d6976d64c 96
gmehmet 0:a12d6976d64c 97 enum ButtonStatus {
gmehmet 0:a12d6976d64c 98 BUTTONSTATUS_RELEASED = 1,
gmehmet 0:a12d6976d64c 99 BUTTONSTATUS_PRESSED
gmehmet 0:a12d6976d64c 100 } ;
gmehmet 0:a12d6976d64c 101
gmehmet 0:a12d6976d64c 102 /**
gmehmet 0:a12d6976d64c 103 * MAX32630HSP constructor.
gmehmet 0:a12d6976d64c 104 *
gmehmet 0:a12d6976d64c 105 */
gmehmet 0:a12d6976d64c 106 MAX32630HSP();
gmehmet 0:a12d6976d64c 107
gmehmet 0:a12d6976d64c 108 /**
gmehmet 0:a12d6976d64c 109 * MAX32630HSP constructor.
gmehmet 0:a12d6976d64c 110 *
gmehmet 0:a12d6976d64c 111 */
gmehmet 0:a12d6976d64c 112 MAX32630HSP(vio_t vio);
gmehmet 0:a12d6976d64c 113
gmehmet 0:a12d6976d64c 114 /**
gmehmet 0:a12d6976d64c 115 * MAX32630HSP constructor.
gmehmet 0:a12d6976d64c 116 *
gmehmet 0:a12d6976d64c 117 */
gmehmet 0:a12d6976d64c 118 MAX32630HSP(vio_t vio, InterruptIn *max32630hsp3_powerButtonInterrupt);
gmehmet 0:a12d6976d64c 119
gmehmet 0:a12d6976d64c 120 /**
gmehmet 0:a12d6976d64c 121 * MAX32630HSP destructor.
gmehmet 0:a12d6976d64c 122 */
gmehmet 0:a12d6976d64c 123 ~MAX32630HSP();
gmehmet 0:a12d6976d64c 124
gmehmet 0:a12d6976d64c 125 //InterruptIn _interruptIn_PowerButton;
gmehmet 0:a12d6976d64c 126
gmehmet 0:a12d6976d64c 127 /**
gmehmet 0:a12d6976d64c 128 * @brief Initialize MAX32630HSP board
gmehmet 0:a12d6976d64c 129 * @details Initializes PMIC and I/O on MAX32630HSP board.
gmehmet 0:a12d6976d64c 130 * Configures PMIC to enable LDO2 and LDO3 at 3.3V.
gmehmet 0:a12d6976d64c 131 * Disables resisitive pulldown on MON(AIN_0)
gmehmet 0:a12d6976d64c 132 * Sets default I/O voltages to 3V3 for micro SD card.
gmehmet 0:a12d6976d64c 133 * Sets I/O voltage for header pins to hdrVio specified.
gmehmet 0:a12d6976d64c 134 * @param hdrVio I/O voltage for header pins
gmehmet 0:a12d6976d64c 135 * @returns 0 if no errors, -1 if error.
gmehmet 0:a12d6976d64c 136 */
gmehmet 0:a12d6976d64c 137 int init(vio_t hdrVio);
gmehmet 0:a12d6976d64c 138
gmehmet 0:a12d6976d64c 139 /**
gmehmet 0:a12d6976d64c 140 * @brief Sets I/O Voltage
gmehmet 0:a12d6976d64c 141 * @details Sets the voltage rail to be used for a given pin.
gmehmet 0:a12d6976d64c 142 * VIO_1V8 selects VDDIO which is supplied by Buck2, which is set at 1.8V,
gmehmet 0:a12d6976d64c 143 * VIO_3V3 selects VDDIOH which is supplied by LDO2, which is typically 3.3V/
gmehmet 0:a12d6976d64c 144 * @param pin Pin whose voltage supply is being assigned.
gmehmet 0:a12d6976d64c 145 * @param vio Voltage rail to be used for specified pin.
gmehmet 0:a12d6976d64c 146 * @returns 0 if no errors, -1 if error.
gmehmet 0:a12d6976d64c 147 */
gmehmet 0:a12d6976d64c 148 int vddioh(PinName pin, vio_t vio);
gmehmet 0:a12d6976d64c 149
gmehmet 0:a12d6976d64c 150 /**Interrupt Hander for Power Button Press**/
gmehmet 0:a12d6976d64c 151
gmehmet 0:a12d6976d64c 152 //InterruptIn _interruptIn_UpButton(PIN_UPBUTTON);
gmehmet 0:a12d6976d64c 153 //InterruptIn _interruptIn_DownButton(PIN_DOWNBUTTON);
gmehmet 0:a12d6976d64c 154
gmehmet 0:a12d6976d64c 155 /* Set vddio for Sharp LS013B7DH03 Display */
gmehmet 0:a12d6976d64c 156 void enableDisplay(void);
gmehmet 0:a12d6976d64c 157
gmehmet 0:a12d6976d64c 158 /// Local I2C bus for configuring PMIC and accessing BMI160 IMU.
gmehmet 0:a12d6976d64c 159 I2C i2c;
gmehmet 0:a12d6976d64c 160
gmehmet 0:a12d6976d64c 161 /// MAX20303 PMIC Instance
gmehmet 0:a12d6976d64c 162 MAX20303 max20303;
gmehmet 0:a12d6976d64c 163
gmehmet 0:a12d6976d64c 164
gmehmet 0:a12d6976d64c 165 InterruptIn *m_max32630hsp3_powerButtonInterrupt;
gmehmet 0:a12d6976d64c 166 bool button_status;
gmehmet 0:a12d6976d64c 167 bool button_longpressdetected;
gmehmet 0:a12d6976d64c 168 Timeout button_timeout;
gmehmet 0:a12d6976d64c 169
gmehmet 0:a12d6976d64c 170 ButtonStatus status_powerButton;
gmehmet 0:a12d6976d64c 171 ButtonStatus status_upButton;
gmehmet 0:a12d6976d64c 172 ButtonStatus status_downButton;
gmehmet 0:a12d6976d64c 173 void event_powerButtonPressed(void);
gmehmet 0:a12d6976d64c 174 void event_powerButtonReleased(void);
gmehmet 0:a12d6976d64c 175 void event_longpresscheck(void);
gmehmet 0:a12d6976d64c 176 };
gmehmet 0:a12d6976d64c 177
gmehmet 0:a12d6976d64c 178 #endif /* _MAX32630HSP_H_ */