System print
Dependencies: max32625pico SerialInterface USBDevice
Diff: main.cpp
- Revision:
- 8:26dc73d09bd9
- Parent:
- 7:62efbc5411c8
- Child:
- 9:674b1077b3ec
--- a/main.cpp Mon Dec 19 22:45:22 2016 +0000 +++ b/main.cpp Mon Mar 20 23:27:27 2017 +0000 @@ -1,59 +1,46 @@ #include "mbed.h" -#include "max32630fthr.h" -#include "SDFileSystem.h" +#include "rtos.h" #include "USBKeyboard.h" -MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); - // Hardware serial port over DAPLink Serial daplink(P2_1, P2_0); DigitalOut rLED(LED1, LED_ON); DigitalOut gLED(LED2, LED_OFF); DigitalOut bLED(LED3, LED_OFF); -DigitalIn button(SW1, PullUp); -AnalogIn monIn(AIN_0); +DigitalIn button(P0_7, PullUp); +DigitalOut en3V3(P3_6, 0); +DigitalOut enIOH(P2_2, 0); +DigitalOut selSWD(P2_3, 0); +AnalogIn dipIOH(AIN_4); +AnalogIn swdIOH(AIN_5); AnalogIn vddbIn(AIN_6); AnalogIn vdd18In(AIN_7); AnalogIn vdd12In(AIN_8); AnalogIn vrtcIn(AIN_9); -SDFileSystem sd(P0_5, P0_6, P0_4, P0_7, "sd"); // mosi, miso, sclk, cs USBKeyboard keyboard; -#define BMI160_I2C_ADDR 0xD0 - // Function to report failure void testFailed() { daplink.printf("\r\n! Test Failed !\r\n"); - rLED = LED_ON; - gLED = LED_OFF; - bLED = LED_OFF; +// rLED = LED_ON; +// gLED = LED_OFF; +// bLED = LED_OFF; while(1) { Thread::wait(500); - gLED = !gLED; + rLED = !rLED; } } -// Function to read monitor port -float readMon(MAX14690::monCfg_t monCfg) -{ - pegasus.max14690.monSet(monCfg, MAX14690::MON_DIV4); - Thread::wait(5); - return (4.8f * monIn); -} - // main() runs in its own thread in the OS // (note the calls to Thread::wait below for delays) int main() { float aIn; - char dataBuf[2]; int ledCnt = 0; - - daplink.printf("Initializing MAX32630FTHR\r\n"); -// pegasus.init(MAX32630FTHR::VIO_3V3); + daplink.printf("Checking Supplies\r\n"); aIn = 2.4f * vdd12In; daplink.printf("vdd12 = %f\r\n", aIn); @@ -75,55 +62,57 @@ if ((aIn < 1.6f) || (aIn > 2.0f)) { testFailed(); } - aIn = readMon(MAX14690::MON_SYS); - daplink.printf("sys = %f\r\n", aIn); - if ((aIn < 3.0f) || (aIn > 5.0f)) { + + en3V3 = 1; + bLED = LED_ON; + Thread::wait(100); + + daplink.printf("Checking Switches\r\n"); + aIn = 6.0f * dipIOH; + Thread::wait(100); + aIn = 6.0f * dipIOH; + daplink.printf("dipIOH(open) = %f\r\n", aIn); + if (aIn > 0.1f) { testFailed(); } - aIn = readMon(MAX14690::MON_BUCK1); - daplink.printf("buck1 = %f\r\n", aIn); - if ((aIn < 1.0f) || (aIn > 1.4f)) { + aIn = 6.0f * swdIOH; + Thread::wait(100); + aIn = 6.0f * swdIOH; + daplink.printf("swdIOH(open) = %f\r\n", aIn); + if (aIn > 0.1f) { testFailed(); } - aIn = readMon(MAX14690::MON_BUCK2); - daplink.printf("buck2 = %f\r\n", aIn); - if ((aIn < 1.6f) || (aIn > 2.0f)) { - testFailed(); + + enIOH = 1; + rLED = LED_OFF; + Thread::wait(100); + + aIn = 6.0f * dipIOH; + Thread::wait(100); + aIn = 6.0f * dipIOH; + daplink.printf("dipIOH(closed) = %f\r\n", aIn); +// aIn = 6.0f * swdIOH; +// daplink.printf("swdIOH(closed) = %f\r\n", aIn); + if ((aIn < 3.0f) || (aIn > 3.6f)) { +// testFailed(); } - aIn = readMon(MAX14690::MON_LDO1); - daplink.printf("ldo1 = %f\r\n", aIn); - if ((aIn < 1.6f) || (aIn > 2.0f)) { - testFailed(); - } - aIn = readMon(MAX14690::MON_LDO2); - daplink.printf("ldo2 = %f\r\n", aIn); + + selSWD = 1; + gLED = LED_ON; + Thread::wait(100); + + aIn = 6.0f * swdIOH; + Thread::wait(100); + aIn = 6.0f * swdIOH; + daplink.printf("swdIOH(closed) = %f\r\n", aIn); +// aIn = 6.0f * dipIOH; +// daplink.printf("dipIOH(closed) = %f\r\n", aIn); if ((aIn < 3.0f) || (aIn > 3.6f)) { testFailed(); } - aIn = readMon(MAX14690::MON_LDO3); - daplink.printf("ldo3 = %f\r\n", aIn); - aIn = readMon(MAX14690::MON_LDO3); - bLED = LED_ON; - - daplink.printf("Checking micro SD Card\r\n"); - FILE *fp = fopen("/sd/myfile.txt", "r"); - if(fp == NULL) { - daplink.printf("Unable to open 'myfile.txt'\r\n"); - testFailed(); - } - daplink.printf("micro SD Card present\r\n"); - rLED = LED_OFF; - - daplink.printf("Checking BMI160\r\n"); - dataBuf[0] = 0x00; - if (pegasus.i2c.write(BMI160_I2C_ADDR, dataBuf, 1, 1) != 0) testFailed(); - if (pegasus.i2c.read(BMI160_I2C_ADDR, dataBuf, 1) != 0) testFailed(); - if (dataBuf[0] != 0xD1) testFailed(); - daplink.printf("BMI160 present\r\n"); - gLED = LED_ON; - - + bLED = LED_OFF; + Thread::wait(250); daplink.printf("Self Test Passed\r\n"); rLED = LED_ON; @@ -134,9 +123,9 @@ if (!button) { keyboard.mediaControl(KEY_MUTE); ledCnt++; - rLED = (ledCnt & 1); - gLED = (ledCnt & 2); - bLED = (ledCnt & 4); + gLED = (ledCnt & 1); + bLED = (ledCnt & 2); + rLED = gLED ^ bLED; Thread::wait(500); } else { Thread::wait(50);