practice

Dependencies:   max32625pico USBDevice

Committer:
mjoun
Date:
Thu Jan 23 23:44:25 2020 +0000
Revision:
14:894c1c8a4355
Parent:
10:227698c63531
Hello

Who changed what in which revision?

UserRevisionLine numberNew contents of line
switches 0:60a522ae2e35 1 #include "mbed.h"
switches 8:26dc73d09bd9 2 #include "rtos.h"
switches 10:227698c63531 3 #include "max32625pico.h"
switches 7:62efbc5411c8 4 #include "USBKeyboard.h"
switches 0:60a522ae2e35 5
switches 4:1c6819a42db0 6 // Hardware serial port over DAPLink
switches 4:1c6819a42db0 7 Serial daplink(P2_1, P2_0);
mjoun 14:894c1c8a4355 8 Serial pc(USBTX, USBRX);
switches 4:1c6819a42db0 9
switches 10:227698c63531 10 DigitalOut rLED(LED1, LED_OFF);
switches 4:1c6819a42db0 11 DigitalOut gLED(LED2, LED_OFF);
switches 4:1c6819a42db0 12 DigitalOut bLED(LED3, LED_OFF);
switches 9:674b1077b3ec 13 DigitalIn button(P2_7, PullUp);
switches 8:26dc73d09bd9 14 AnalogIn dipIOH(AIN_4);
switches 8:26dc73d09bd9 15 AnalogIn swdIOH(AIN_5);
switches 4:1c6819a42db0 16 AnalogIn vddbIn(AIN_6);
switches 4:1c6819a42db0 17 AnalogIn vdd18In(AIN_7);
switches 4:1c6819a42db0 18 AnalogIn vdd12In(AIN_8);
switches 4:1c6819a42db0 19 AnalogIn vrtcIn(AIN_9);
switches 4:1c6819a42db0 20
switches 7:62efbc5411c8 21 USBKeyboard keyboard;
switches 7:62efbc5411c8 22
switches 10:227698c63531 23 MAX32625PICO pico(MAX32625PICO::IOH_DIP_IN, MAX32625PICO::VIO_IOH, MAX32625PICO::VIO_1V8);
switches 10:227698c63531 24
switches 4:1c6819a42db0 25 // Function to report failure
switches 4:1c6819a42db0 26 void testFailed()
switches 4:1c6819a42db0 27 {
switches 4:1c6819a42db0 28 daplink.printf("\r\n! Test Failed !\r\n");
switches 10:227698c63531 29 rLED = LED_ON;
switches 10:227698c63531 30 gLED = LED_OFF;
switches 10:227698c63531 31 bLED = LED_OFF;
switches 4:1c6819a42db0 32 while(1) {
switches 4:1c6819a42db0 33 Thread::wait(500);
switches 10:227698c63531 34 gLED = !gLED;
switches 7:62efbc5411c8 35 }
switches 4:1c6819a42db0 36 }
switches 4:1c6819a42db0 37
switches 0:60a522ae2e35 38 // main() runs in its own thread in the OS
switches 0:60a522ae2e35 39 // (note the calls to Thread::wait below for delays)
switches 0:60a522ae2e35 40 int main()
switches 0:60a522ae2e35 41 {
mjoun 14:894c1c8a4355 42 // device.baud(19200);
mjoun 14:894c1c8a4355 43 // while(true){
mjoun 14:894c1c8a4355 44 // device.printf("Hello World\n");
mjoun 14:894c1c8a4355 45 pc.baud(115200);
switches 4:1c6819a42db0 46 float aIn;
switches 7:62efbc5411c8 47 int ledCnt = 0;
switches 8:26dc73d09bd9 48
switches 10:227698c63531 49 rLED = LED_ON;
switches 10:227698c63531 50 gLED = LED_ON;
switches 10:227698c63531 51 bLED = LED_OFF;
switches 10:227698c63531 52
switches 4:1c6819a42db0 53 daplink.printf("Checking Supplies\r\n");
switches 4:1c6819a42db0 54 aIn = 2.4f * vdd12In;
switches 4:1c6819a42db0 55 daplink.printf("vdd12 = %f\r\n", aIn);
switches 7:62efbc5411c8 56 if ((aIn < 1.0f) || (aIn > 1.4f)) {
switches 7:62efbc5411c8 57 testFailed();
switches 7:62efbc5411c8 58 }
switches 4:1c6819a42db0 59 aIn = 2.4f * vdd18In;
switches 4:1c6819a42db0 60 daplink.printf("vdd18 = %f\r\n", aIn);
switches 7:62efbc5411c8 61 if ((aIn < 1.6f) || (aIn > 2.0f)) {
switches 7:62efbc5411c8 62 testFailed();
switches 7:62efbc5411c8 63 }
switches 4:1c6819a42db0 64 aIn = 4.8f * vddbIn;
switches 4:1c6819a42db0 65 daplink.printf("vddb = %f\r\n", aIn);
switches 7:62efbc5411c8 66 if ((aIn < 3.0f) || (aIn > 3.6f)) {
switches 7:62efbc5411c8 67 testFailed();
switches 7:62efbc5411c8 68 }
switches 4:1c6819a42db0 69 aIn = 2.4f * vrtcIn;
switches 4:1c6819a42db0 70 daplink.printf("vrtc = %f\r\n", aIn);
switches 7:62efbc5411c8 71 if ((aIn < 1.6f) || (aIn > 2.0f)) {
switches 7:62efbc5411c8 72 testFailed();
switches 7:62efbc5411c8 73 }
switches 8:26dc73d09bd9 74
switches 8:26dc73d09bd9 75 aIn = 6.0f * dipIOH;
switches 10:227698c63531 76 daplink.printf("dipIOH = %f\r\n", aIn);
switches 8:26dc73d09bd9 77
switches 8:26dc73d09bd9 78 aIn = 6.0f * swdIOH;
switches 10:227698c63531 79 daplink.printf("swdIOH = %f\r\n", aIn);
switches 10:227698c63531 80
switches 1:464c8b3634dc 81
switches 10:227698c63531 82
switches 10:227698c63531 83 rLED = LED_OFF;
switches 8:26dc73d09bd9 84 Thread::wait(250);
switches 7:62efbc5411c8 85
switches 4:1c6819a42db0 86 daplink.printf("Self Test Passed\r\n");
switches 7:62efbc5411c8 87 rLED = LED_ON;
switches 7:62efbc5411c8 88 gLED = LED_ON;
switches 7:62efbc5411c8 89 bLED = LED_ON;
mjoun 14:894c1c8a4355 90
switches 0:60a522ae2e35 91 while (true) {
switches 7:62efbc5411c8 92 if (!button) {
switches 7:62efbc5411c8 93 keyboard.mediaControl(KEY_MUTE);
switches 7:62efbc5411c8 94 ledCnt++;
switches 10:227698c63531 95 gLED = ((ledCnt % 4) != 1);
switches 10:227698c63531 96 bLED = ((ledCnt % 4) != 2);
switches 10:227698c63531 97 rLED = ((ledCnt % 4) != 3);
switches 7:62efbc5411c8 98 Thread::wait(500);
mjoun 14:894c1c8a4355 99 pc.printf("Hello World");
switches 7:62efbc5411c8 100 } else {
switches 7:62efbc5411c8 101 Thread::wait(50);
switches 7:62efbc5411c8 102 }
mjoun 14:894c1c8a4355 103
mjoun 14:894c1c8a4355 104
switches 0:60a522ae2e35 105 }
switches 0:60a522ae2e35 106 }
switches 0:60a522ae2e35 107