Trond Enger / d7a_1x

Fork of d7a_1x by WizziLab

Revision:
75:305024138382
Parent:
66:492b1d7ba370
Child:
76:fda2e34ff19d
--- a/src/d7a_modem.cpp	Tue Dec 13 09:49:24 2016 +0000
+++ b/src/d7a_modem.cpp	Fri Dec 16 16:04:27 2016 +0000
@@ -20,7 +20,7 @@
     NotifDoneFunction notif_done;
     uint8_t nb_files;
     int8_t status;
-    DigitalInOut* reset;
+    PinName reset_pin;
     bool booted;
 } d7a_modem_ctx_t;
 
@@ -38,14 +38,11 @@
     g_modem_ctx.booted = false;
     g_modem_ctx.nb_files = 0;
     g_modem_ctx.notif_done = nd;
+    g_modem_ctx.reset_pin = reset_pin;
 
-    if (reset_pin == NC)
+    if (g_modem_ctx.reset_pin != NC)
     {
-        g_modem_ctx.reset = NULL;
-    }
-    else
-    {
-        g_modem_ctx.reset = new DigitalInOut(reset_pin, PIN_OUTPUT, OpenDrain, 1);
+        DigitalIn rst(g_modem_ctx.reset_pin);
     }
 
     err = d7a_modem_reset();
@@ -58,7 +55,11 @@
     FPRINT("\r\n");
         
     g_modem_ctx.thread->terminate();
-    *(g_modem_ctx.reset) = 1;
+    
+    if (g_modem_ctx.reset_pin != NC)
+    {   // Release reset
+        DigitalIn rst(g_modem_ctx.reset_pin);
+    }
     
     return D7A_ERR_NONE;
 }
@@ -92,22 +93,23 @@
 static void d7a_modem_hard_reset(void)
 {
     FPRINT("\r\n");
-    
-    ASSERT(g_modem_ctx.reset != NULL, "No reset PIN specified\r\n");
-    
+        
     IPRINT("MODEM Hard Reset.\r\n");
     
     // Use hardware reset
-    // Assert reset pin
-    *(g_modem_ctx.reset) = 0;
+    if (g_modem_ctx.reset_pin != NC)
+    {   // Clear reset
+        DigitalOut rst(g_modem_ctx.reset_pin, 0);
+    }
     
     // Clean buffer and queues
     d7a_com_restart();
     Thread::wait(100);
     
-    // Release reset pin
-    *(g_modem_ctx.reset) = 1;
-    
+    if (g_modem_ctx.reset_pin != NC)
+    {   // Release reset
+        DigitalIn rst(g_modem_ctx.reset_pin);
+    }
 }
 
 d7a_errors_t d7a_modem_reset(void)
@@ -116,8 +118,8 @@
     d7a_errors_t err = D7A_ERR_UNKNOWN;
     g_modem_ctx.booted = false;
 
-    //d7a_modem_soft_reset();
-    //reset_err = d7a_modem_wait_boot(5000);
+    d7a_modem_soft_reset();
+    err = d7a_modem_wait_boot(5000);
     
     if (err)
     {