Subdirectory provided by Embedded Artists

Dependencies:   DM_FATFileSystem DM_HttpServer DM_USBHost EthernetInterface USBDevice mbed-rpc mbed-rtos mbed-src

Dependents:   lpc4088_displaymodule_hello_world_Sept_2018

Fork of DMSupport by Embedded Artists

Revision:
2:887c6b45e7fa
Parent:
0:6b68dac0d986
Child:
3:2fa7755f2cef
--- a/DMBoard.cpp	Fri Nov 21 11:46:48 2014 +0000
+++ b/DMBoard.cpp	Tue Dec 02 15:21:18 2014 +0000
@@ -26,6 +26,20 @@
  * Defines and typedefs
  *****************************************************************************/
 
+#if defined(DM_BOARD_DISABLE_STANDARD_PRINTF)
+class DevNull : public Stream {
+ 
+public:
+    DevNull(const char *name=NULL) : Stream(name) {}
+ 
+protected:
+    virtual int _getc()      {return 0;}
+    virtual int _putc(int c) {return c;}
+};
+ 
+static DevNull null("null");
+#endif
+
 /******************************************************************************
  * Local variables
  *****************************************************************************/
@@ -56,10 +70,12 @@
 
 DMBoard::~DMBoard()
 {
+#if defined(DM_BOARD_USE_TOUCH)
   if (_touch != NULL) {
     delete _touch;
     _touch = NULL;
   }
+#endif
 }
 
 DMBoard::BoardError DMBoard::readConfiguration()
@@ -72,16 +88,16 @@
   mem.powerDown();
 #if 0  
   uint8_t* p = buff;
-  printf("\n-------\nBEFORE:\n-------\n");
+  _logger.printf("\n-------\nBEFORE:\n-------\n");
   for (int i = 0; i < 63; i++) {
     for (int j = 0; j < 4; j++) {
-      printf("0x%04x  %02x %02x %02x %02x %02x %02x %02x %02x  %02x %02x %02x %02x %02x %02x %02x %02x\n",
+      _logger.printf("0x%04x  %02x %02x %02x %02x %02x %02x %02x %02x  %02x %02x %02x %02x %02x %02x %02x %02x\n",
         i,
         p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7],
         p[8],p[9],p[10],p[11],p[12],p[13],p[14],p[15]);
       p += 16;
     }
-    printf("\n");
+    _logger.printf("\n");
   }
   
   // find first non-zero page and write to that
@@ -94,7 +110,7 @@
       }
     }
     if (zeroPage) {
-      printf("Will fill page 0x%04x (%d) with 0x00..0x3f\n", page, page);
+      _logger.printf("Will fill page 0x%04x (%d) with 0x00..0x3f\n", page, page);
       p = buff;
       for (int i = 0; i < mem.pageSize(); i++) {
         *p++ = i;
@@ -103,16 +119,16 @@
       memset(buff, 0, mem.memorySize());
       mem.read(0, 0, buff, mem.memorySize());
       p = buff;
-      printf("\n-------\nAFTER:\n-------\n");
+      _logger.printf("\n-------\nAFTER:\n-------\n");
       for (int i = 0; i < 63; i++) {
         for (int j = 0; j < 4; j++) {
-          printf("0x%04x  %02x %02x %02x %02x %02x %02x %02x %02x  %02x %02x %02x %02x %02x %02x %02x %02x\n",
+          _logger.printf("0x%04x  %02x %02x %02x %02x %02x %02x %02x %02x  %02x %02x %02x %02x %02x %02x %02x %02x\n",
             i,
             p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7],
             p[8],p[9],p[10],p[11],p[12],p[13],p[14],p[15]);
           p += 16;
         }
-        printf("\n");
+        _logger.printf("\n");
       }
       break;
     }
@@ -199,6 +215,17 @@
       _led3 = 0;
       _led4 = 0;
 
+      // Make sure that the logger is always initialized even if
+      // other initialization tasks fail
+      _logger.init();
+
+#if defined(DM_BOARD_DISABLE_STANDARD_PRINTF)
+      // Kill all ouput of calls to printf() so that there is no
+      // simultaneous calls into the non-thread-safe standard libraries.
+      // User code should use the RtosLogger anyway.
+      freopen("/null", "w", stdout);
+#endif
+
 #if defined(DM_BOARD_USE_QSPI) && !defined(DM_BOARD_USE_QSPI_FS)
       if (SPIFI::instance().init() != SPIFI::Ok) {
         err = SpifiError;
@@ -206,14 +233,6 @@
       }
 #endif
       
-#if defined(DM_BOARD_USE_FAST_UART)
-      // This works because both the default serial (used by printf) and the s instance
-      // (used by s.printf) would use the same underlying UART code so setting the baudrate
-      // in one affects the other.
-      Serial s(USBTX, USBRX);
-      s.baud(115200);
-#endif
-
       readConfiguration();
       
 #if defined(DM_BOARD_USE_DISPLAY)
@@ -240,19 +259,19 @@
   return err;
 }
 
-void DMBoard::setLED(int led, bool on)
+void DMBoard::setLED(Leds led, bool on)
 {
   switch(led) {
-    case 1:
+    case Led1:
       _led1 = (on ? 0 : 1);
       break;
-    case 2:
+    case Led2:
       _led2 = (on ? 0 : 1);
       break;
-    case 3:
+    case Led3:
       _led3 = (on ? 1 : 0);
       break;
-    case 4:
+    case Led4:
       _led4 = (on ? 1 : 0);
       break;
   }