Internal_Datalogger but with USB support removed (for MAX40108 Demo board), proof of concept that MAX32625 can be used successfully with VDDB(USB) left unpowered, as long as the USB library is not used.

Dependencies:   max32625pico CmdLine

Revision:
21:ac062a97a71d
Parent:
20:78ef670955d4
Child:
22:d6dc8a85f435
diff -r 78ef670955d4 -r ac062a97a71d DataLogger_Internal.cpp
--- a/DataLogger_Internal.cpp	Fri Apr 23 00:22:00 2021 -0700
+++ b/DataLogger_Internal.cpp	Fri Apr 23 16:57:58 2021 -0700
@@ -553,6 +553,79 @@
 #define led2_GPassLED led2
 #define led3_BBusyLED led3
 
+//--------------------------------------------------
+// use BUTTON1 trigger some action
+#if defined(TARGET_MAX32630)
+#define HAS_BUTTON1_DEMO_INTERRUPT 1
+#define HAS_BUTTON2_DEMO 0
+#define HAS_BUTTON2_DEMO_INTERRUPT 0
+#elif defined(TARGET_MAX32625PICO) || defined(TARGET_MAX40108DEMOP2U9)
+#warning "TARGET_MAX32625PICO not previously tested; need to define buttons..."
+#define HAS_BUTTON1_DEMO_INTERRUPT 1
+#define HAS_BUTTON2_DEMO 0
+#define HAS_BUTTON2_DEMO_INTERRUPT 0
+#elif defined(TARGET_MAX32625)
+#define HAS_BUTTON1_DEMO_INTERRUPT 1
+#define HAS_BUTTON2_DEMO_INTERRUPT 1
+#elif defined(TARGET_MAX32620FTHR)
+#warning "TARGET_MAX32620FTHR not previously tested; need to define buttons..."
+#define BUTTON1 SW1
+#define HAS_BUTTON1_DEMO_INTERRUPT 1
+#define HAS_BUTTON2_DEMO 0
+#define HAS_BUTTON2_DEMO_INTERRUPT 0
+#elif defined(TARGET_NUCLEO_F446RE)
+#define HAS_BUTTON1_DEMO_INTERRUPT 0
+#define HAS_BUTTON2_DEMO_INTERRUPT 0
+#elif defined(TARGET_NUCLEO_F401RE)
+#define HAS_BUTTON1_DEMO_INTERRUPT 0
+#define HAS_BUTTON2_DEMO_INTERRUPT 0
+#else
+#warning "target not previously tested; need to define buttons..."
+#endif
+//
+#ifndef HAS_BUTTON1_DEMO
+#define HAS_BUTTON1_DEMO 0
+#endif
+#ifndef HAS_BUTTON2_DEMO
+#define HAS_BUTTON2_DEMO 0
+#endif
+//
+// avoid runtime error on button1 press [mbed-os-5.11]
+// instead of using InterruptIn, use DigitalIn and poll in main while(1)
+#ifndef HAS_BUTTON1_DEMO_INTERRUPT_POLLING
+#define HAS_BUTTON1_DEMO_INTERRUPT_POLLING 1
+#endif
+//
+#ifndef HAS_BUTTON1_DEMO_INTERRUPT
+#define HAS_BUTTON1_DEMO_INTERRUPT 1
+#endif
+#ifndef HAS_BUTTON2_DEMO_INTERRUPT
+#define HAS_BUTTON2_DEMO_INTERRUPT 1
+#endif
+//
+#if HAS_BUTTON1_DEMO_INTERRUPT
+# if HAS_BUTTON1_DEMO_INTERRUPT_POLLING
+// avoid runtime error on button1 press [mbed-os-5.11]
+// instead of using InterruptIn, use DigitalIn and poll in main while(1)
+DigitalIn button1(BUTTON1);
+# else
+InterruptIn button1(BUTTON1);
+# endif
+#elif HAS_BUTTON1_DEMO
+DigitalIn button1(BUTTON1);
+#endif
+#if HAS_BUTTON2_DEMO_INTERRUPT
+# if HAS_BUTTON1_DEMO_INTERRUPT_POLLING
+// avoid runtime error on button1 press [mbed-os-5.11]
+// instead of using InterruptIn, use DigitalIn and poll in main while(1)
+DigitalIn button2(BUTTON2);
+# else
+InterruptIn button2(BUTTON2);
+# endif
+#elif HAS_BUTTON2_DEMO
+DigitalIn button2(BUTTON2);
+#endif
+
 // uncrustify-0.66.1 *INDENT-OFF*
 //--------------------------------------------------
 // Declare the DigitalInOut GPIO pins
@@ -2464,6 +2537,68 @@
 uint8_t Datalogger_enable_serial = true;
 // CODE GENERATOR: example code for ADC: serial port declaration (end)
 
+
+//--------------------------------------------------
+// When user presses button BUTTON1, perform actions
+#if HAS_BUTTON1_DEMO_INTERRUPT
+void onButton1FallingEdge(void)
+{
+    //~ void SelfTest(CmdLine & cmdLine);
+    //~ SelfTest(cmdLine_serial);
+    static char* onButton1_command_table[] = {
+        "#onButton1_command_table",
+        "%L91",
+        "%H92",
+        "%L93",
+        "%H91",
+        "%L92",
+        "%H93",
+        "LR",
+        ""
+    };
+    for (int lineIndex = 0; lineIndex < 10; lineIndex++) {
+        if (onButton1_command_table[lineIndex] == NULL) { break; }
+        if (onButton1_command_table[lineIndex][0] == '\0') { break; }
+        cmdLine.clear();
+        //~ char* strIndex = onButton1_command_table[lineIndex];
+        for (char* strIndex = onButton1_command_table[lineIndex]; *strIndex != '\0'; strIndex++)
+        {
+            cmdLine.append(*strIndex);
+        }
+        cmdLine.append('\r'); // append \r invokes onEOLcommandParser to handle command
+    }
+}
+#endif // HAS_BUTTON1_DEMO_INTERRUPT
+
+//--------------------------------------------------
+// When user presses button BUTTON2, perform actions
+#if HAS_BUTTON2_DEMO_INTERRUPT
+void onButton2FallingEdge(void)
+{
+    // TBD demo configuration
+    // TODO diagnostic LED
+    // led1 = LED_OFF; led2 = LED_OFF; led3 = LED_ON;     // diagnostic rbg led BLUE
+    static char* onButton2_command_table[] = {
+        "#onButton1_command_table",
+        "%H91",
+        "%H92",
+        "%L93",
+        ""
+    };
+    for (int lineIndex = 0; lineIndex < 10; lineIndex++) {
+        if (onButton2_command_table[lineIndex] == NULL) { break; }
+        if (onButton2_command_table[lineIndex][0] == '\0') { break; }
+        cmdLine.clear();
+        //~ char* strIndex = onButton2_command_table[lineIndex];
+        for (char* strIndex = onButton2_command_table[lineIndex]; *strIndex != '\0'; strIndex++)
+        {
+            cmdLine.append(*strIndex);
+        }
+        cmdLine.append('\r'); // append \r invokes onEOLcommandParser to handle command
+    }
+}
+#endif // HAS_BUTTON2_DEMO_INTERRUPT
+
 #if USE_CMDLINE_MENUS // support CmdLine command menus
 //--------------------------------------------------
 inline void print_command_prompt()
@@ -4837,6 +4972,21 @@
         while(1) { // this code repeats forever
         // this code repeats forever
 
+#if HAS_BUTTON1_DEMO_INTERRUPT_POLLING
+        // avoid runtime error on button1 press [mbed-os-5.11]
+        // instead of using InterruptIn, use DigitalIn and poll in main while(1)
+# if HAS_BUTTON1_DEMO_INTERRUPT
+        static int button1_value_prev = 1;
+        static int button1_value_now = 1;
+        button1_value_prev = button1_value_now;
+        button1_value_now = button1.read();
+        if ((button1_value_prev - button1_value_now) == 1)
+        {
+            // on button1 falling edge (button1 press)
+            onButton1FallingEdge();
+        }
+# endif // HAS_BUTTON1_DEMO_INTERRUPT
+#endif // HAS_BUTTON1_DEMO_INTERRUPT_POLLING
 #if USE_CMDLINE_MENUS // support CmdLine command menus
             // TODO support CmdLine command menus (like on Serial_Tester); help and usual boilerplate
 #if USE_AUX_SERIAL_CMD_FORWARDING