Board library for MAX32630FTHR platform

Dependencies:   MAX14690

Dependents:   FTHR_OLED MAX32630FTHR_ADC_Example Test_TFT_RT MAX32630FTHR_RGB ... more

Fork of max32630fthr by Greg Steiert

Files at this revision

API Documentation at this revision

Comitter:
switches
Date:
Sun Nov 20 23:31:36 2016 +0000
Parent:
0:8926602da648
Child:
2:7a1d7d6d520e
Commit message:
Created MAX32630FTHR class for board support functions

Changed in this revision

MAX14690.lib Show annotated file Show diff for this revision Revisions of this file
max32630fthr.cpp Show annotated file Show diff for this revision Revisions of this file
max32630fthr.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MAX14690.lib	Sun Nov 20 23:31:36 2016 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/switches/code/MAX14690/#1ca110017930
--- a/max32630fthr.cpp	Wed Nov 16 01:01:28 2016 +0000
+++ b/max32630fthr.cpp	Sun Nov 20 23:31:36 2016 +0000
@@ -1,29 +1,107 @@
+/*******************************************************************************
+ * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Maxim Integrated
+ * Products, Inc. shall not be used except as stated in the Maxim Integrated
+ * Products, Inc. Branding Policy.
+ *
+ * The mere transfer of this software does not imply any licenses
+ * of trade secrets, proprietary technology, copyrights, patents,
+ * trademarks, maskwork rights, or any other form of intellectual
+ * property whatsoever. Maxim Integrated Products, Inc. retains all
+ * ownership rights.
+ *******************************************************************************
+ */
+
 #include "mbed.h"
 #include "max3263x.h"
 #include "ioman_regs.h"
 #include "PinNames.h"
 #include "max32630fthr.h"
 
-#define MAX14690_I2C_ADDR    0x50
+//******************************************************************************
+MAX32630FTHR::MAX32630FTHR(vio_t vio) : i2c(P5_7, P6_0), max14690(&i2c)
+{
+    hdrVio = vio;
+}
 
+//******************************************************************************
+MAX32630FTHR::~MAX32630FTHR()
+{
+}
 
-int max32630fthrInit()
+//******************************************************************************
+int MAX32630FTHR::init()
 {
-    I2C __i2cm2(P5_7, P6_0);
-    char data[5];
-    data[0] = 0x14; // I2C address for first register (LDO2 CFG)
-    data[1] = 0x00; // Dissable LDO2
-    data[2] = 0x19; // Set voltage to 3.3V
-    data[3] = 0x00; // Dissable LDO3
-    data[4] = 0x19; // Set voltage to 3.3V
-    __i2cm2.write(MAX14690_I2C_ADDR, data, 5);
-    data[1] = 0x02; // Enable LDO2
-    data[3] = 0x02; // Enable LDO3
-    __i2cm2.write(MAX14690_I2C_ADDR, data, 5);
+    // Override the default values
+    max14690.ldo2Millivolts = 3300;
+    max14690.ldo3Millivolts = 3300;
+    max14690.ldo2Mode = MAX14690::LDO_ENABLED;
+    max14690.ldo3Mode = MAX14690::LDO_ENABLED;
+    max14690.monCfg = MAX14690::MON_HI_Z;
+    // Note that writing the local value does directly affect the part
+    // The buck-boost regulator will remain off until init is called
+
+    // Call init to apply all settings to the PMIC
+    if (max14690.init() == MAX14690_ERROR) {
+        printf("Error initializing MAX14690");
+    }
+
+    // Set micro SD card pins to 3.3V
+    vddioh(P0_4, VIO_3V3);
+    vddioh(P0_5, VIO_3V3);
+    vddioh(P0_6, VIO_3V3);
+    vddioh(P0_7, VIO_3V3);
+    // Set LED pins to 3.3V
+    vddioh(P2_4, VIO_3V3);
+    vddioh(P2_5, VIO_3V3);
+    vddioh(P2_6, VIO_3V3);
+    // 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);
+    vddioh(P4_3, hdrVio);
+    vddioh(P4_4, hdrVio);
+    vddioh(P4_5, hdrVio);
+    vddioh(P4_6, hdrVio);
+    vddioh(P4_7, hdrVio);
+    vddioh(P5_0, hdrVio);
+    vddioh(P5_1, hdrVio);
+    vddioh(P5_2, hdrVio);
+    vddioh(P5_3, hdrVio);
+    vddioh(P5_4, hdrVio);
+    vddioh(P5_5, hdrVio);
+    vddioh(P5_6, hdrVio);
+
     return 0;
 }
 
-int vddioh(PinName pin, bool en)
+//******************************************************************************
+int MAX32630FTHR::vddioh(PinName pin, vio_t vio)
 {
     __IO uint32_t *use_vddioh = &((mxc_ioman_regs_t *)MXC_IOMAN)->use_vddioh_0;
 
@@ -32,7 +110,7 @@
     }
 
     use_vddioh += PINNAME_TO_PORT(pin) >> 2;
-    if (en) {
+    if (vio) {
         *use_vddioh |= (1 << (PINNAME_TO_PIN(pin) + ((PINNAME_TO_PORT(pin) & 0x3) << 3)));
     } else {
         *use_vddioh &= ~(1 << (PINNAME_TO_PIN(pin) + ((PINNAME_TO_PORT(pin) & 0x3) << 3)));
--- a/max32630fthr.h	Wed Nov 16 01:01:28 2016 +0000
+++ b/max32630fthr.h	Sun Nov 20 23:31:36 2016 +0000
@@ -1,7 +1,99 @@
+/*******************************************************************************
+ * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Maxim Integrated
+ * Products, Inc. shall not be used except as stated in the Maxim Integrated
+ * Products, Inc. Branding Policy.
+ *
+ * The mere transfer of this software does not imply any licenses
+ * of trade secrets, proprietary technology, copyrights, patents,
+ * trademarks, maskwork rights, or any other form of intellectual
+ * property whatsoever. Maxim Integrated Products, Inc. retains all
+ * ownership rights.
+ *******************************************************************************
+ */
+
+#ifndef _MAX32630FTHR_H_
+#define _MAX32630FTHR_H_
+
+#include "mbed.h"
+#include "MAX14690.h"
+
+class MAX32630FTHR
+{
+public:
 // max32630fthr configuration utilities
 
-// max32630fthr initialization
-int max32630fthrInit();
+    /**
+      * @brief   IO Voltage
+      * @details Enumerated options for operating voltage
+      */
+    typedef enum {
+        VIO_1V8 = 0x00,    ///< 1.8V IO voltage at headers (from BUCK2)
+        VIO_3V3 = 0x01,    ///< 3.3V IO voltage at headers (from LDO2)
+    } vio_t;
+
+    /**
+        * MAX32630FTHR constructor.
+        *
+        * @param vio I/O voltage for header pins
+        */
+    MAX32630FTHR(vio_t vio);
+
+    /**
+        * MAX32630FTHR destructor.
+        */
+    ~MAX32630FTHR();
 
-// max32630fthr pin voltage configuration
-int vddioh(PinName pin, bool en);
\ No newline at end of file
+    /**
+     * @brief   Initialize MAX32630FTHR board
+     * @details Initializes PMIC and I/O on MAX32630FTHR board.
+     *  Configures PMIC to enable LDO2 and LDO3 at 3.3V.
+     *  Disables resisitive pulldown on MON(AIN_0)
+     *  Sets default I/O voltages to 3V3 for micro SD card.
+     *  Sets I/O voltage for header pins to hdrVio specified.
+     * @returns 0 if no errors, -1 if error.
+    */
+    int init();
+
+    /**
+     * @brief   Sets I/O Voltage
+     * @details Sets the voltage rail to be used for a given pin.
+     *  VIO_1V8 selects VDDIO which is supplied by Buck2, which is set at 1.8V,   
+     *  VIO_3V3 selects VDDIOH which is supplied by LDO2, which is typically 3.3V/
+     * @param   pin Pin whose voltage supply is being assigned.
+     * @param   vio Voltage rail to be used for specified pin.
+     * @returns 0 if no errors, -1 if error.
+    */
+    int vddioh(PinName pin, vio_t vio);
+    
+    /// Local I2C bus for configuring PMIC and accessing BMI160 IMU.
+    I2C i2c;
+
+    /// MAX14690 PMIC Instance
+    MAX14690 max14690;
+
+    /// The default I/O voltage to be used for header pins.
+    vio_t hdrVio;    
+
+};
+
+#endif /* _MAX32630FTHR_H_ */