Ben Bance / Mbed OS MAX32630FTHR_Blinky_OS6

main.cpp

Committer:
bjbance
Date:
2021-03-12
Branch:
Lib_Development
Revision:
2:ef0ee9c2a551
Parent:
0:bf54a250aa28

File content as of revision 2:ef0ee9c2a551:

// ********************************************************************************************
// PMIC Buck1/Buck2 Monitor
#include "mbed.h"
#include "ThisThread.h"
#include "MAX14690.h"
#include "mxc_sys.h"
//#include "max32630fthr.h"
//#include "ESP8266Interface.h"



//MAX32630FTHR fthr(MAX32630FTHR::VIO_3V3);

DigitalOut  rLED(LED1);

InterruptIn pBUTTON(SW1);
AnalogIn    monPMIC(AIN_0);
MAX14690 pmic(P5_7,P6_0);

const int address = 0x50;
char command;

void monSwitch(){
    if (command == 0x03) {
        command = 0x04;    // MONRatioCfg 00 | MONtHiZ 0 | MONCTR 100       (0000 0100)(0x04)   Connect MON to Buck2
    }
    else {
        command = 0x03;    // MONRatioCfg 00 | MONtHiZ 0 | MONCTR 011       (0000 0100)(0x03)   Connect MON to Buck1
    }
}

int main()
{
char ldo3[2];

printf("\n\n");
pmic.setLDO(pmic.LDO3, true, 3.3);

ldo3[0] = pmic.readStatus(0x16);
ldo3[1] = pmic.readStatus(0x17);

printf("Register [%02X] Content : %02X \n", 0x16, ldo3[0]);
printf("Register [%02X] Content : %02X \n", 0x17, ldo3[1]);

rLED = LED_OFF;

while(true){

}



/*
    char cmd[3];
    char readback[3];
    int       voltage;
    char regadr;
    cmd[0] = 0x19;  // MonCFG address
    cmd[1] = 0x03;  // Connect MON pin to Buck1 Output

    pBUTTON.rise(&monSwitch);

    ThisThread::sleep_for(1000ms);
    
    printf("\n\n\n\n");
    cmd[0] = 0;
    while (true) {
        rLED = LED_ON;
        
        cmd[1] = command;
        //pmic.write(address, cmd, 2);
        //ThisThread::sleep_for(2ms);
        //pmic.write(address, cmd, 1);
        //pmic.read(address, readback, 1);

        //voltage = ctoint(readback[0]);
        printf("Register [%02X] Content : %02X \n", cmd[0], readback[0]);
        //monPMIC.set_reference_voltage(1.2);    //Reference Voltage is 1.25V | Resistive Partition is 4:1
        //voltage = 1000 * monPMIC.read_voltage();
        //printf("Voltage : %i mV\n",voltage);
        //rLED = LED_OFF
        cmd[0] = cmd[0] +1;
        ThisThread::sleep_for(5000ms);
    }
    */
}