Team Riedel - display

Dependencies:   LCD_fonts SPI_TFT_ILI9341 CMSIS_DSP_401_without_cm4 mbed-src SDFileSystem wavfile

Files at this revision

API Documentation at this revision

Comitter:
zsaiyed
Date:
Sat Dec 12 22:50:18 2015 +0000
Parent:
4:e1ec41710eb4
Child:
6:005ff6a49217
Commit message:
added sky wire

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sat Dec 12 22:06:19 2015 +0000
+++ b/main.cpp	Sat Dec 12 22:50:18 2015 +0000
@@ -73,6 +73,65 @@
 SPI_TFT_ILI9341 TFT(PC_3, PC_2, PB_10, PB_12, PA_8, PA_11, "TFT"); // mosi, miso, sclk, cs, reset, dc
 SDFileSystem sd(PB_5, PB_4, PB_3, PC_11, "sd"); // mosi, miso, sclk, cs
 
+DigitalOut skywire_en(PA_6);
+//DigitalOut skywire_rts(PA_7);
+Serial skywire(PA_0,PA_1);
+
+volatile int rx_in=0;
+volatile int rx_out=0;
+const int buffer_size = 255;
+char rx_buffer[buffer_size+1];
+char rx_line[buffer_size];
+
+void read_line()
+{
+    int i;
+    i = 0;
+// Start Critical Section - don't interrupt while changing global buffer variables
+    __disable_irq();
+// Loop reading rx buffer characters until end of line character
+    while ((i==0) || ((rx_line[i-1] != '\r') && (rx_line[i-1] != '\n'))) {
+// Wait if buffer empty
+        if (rx_in == rx_out) {
+// End Critical Section - need to allow rx interrupt to get new characters for buffer
+            __enable_irq();
+            while (rx_in == rx_out) {
+            }
+// Start Critical Section - don't interrupt while changing global buffer variables
+            __disable_irq();
+        }
+        rx_line[i] = rx_buffer[rx_out];
+        i++;
+        rx_out = (rx_out + 1) % buffer_size;
+    }
+// End Critical Section
+    __enable_irq();
+    rx_line[i-1] = 0;
+    return;
+}
+
+int WaitForResponse(char* response)
+{
+    do {
+        do {
+            read_line();
+        } while ((unsigned char)rx_line[0] <= 32);
+//        debug_pc.printf("Waiting for: %s, Received: %s\r\n", response, rx_line);
+    } while (strncmp(rx_line, response, strlen(response)));
+    return 0;
+}
+
+void Skywire_Rx_interrupt()
+{
+// Loop just in case more than one character is in UART's receive FIFO buffer
+// Stop if buffer full
+    while ((skywire.readable()) && (((rx_in + 1) % buffer_size) != rx_out)) {
+        rx_buffer[rx_in] = skywire.getc();
+        rx_in = (rx_in + 1) % buffer_size;
+    }
+    return;
+}
+
 int main()
 {    
 /*//    arm_cfft_radix2_instance_f32 S; 
@@ -349,13 +408,13 @@
             sd.write_validation(true);
             
             //Try to mount the SD card
-            TFT.locate(10,50);
-            TFT.printf("Mounting SD card...");
-            TFT.locate(10,60);
+            int row = 50;
+            int col = 10;
+            TFT.locate(10,row); TFT.printf("Mounting SD card..."); row+=10; 
             if (sd.mount() != 0) {
-                TFT.printf("failed!");
+                TFT.locate(10,row); TFT.printf("failed!"); row+=10; 
             } else {
-                TFT.printf("mounted successfully!\r\n");
+            TFT.locate(10,row); TFT.printf("mounted successfully"); row+=10; 
             
                 // write event to log
                 TFT.locate(10,70);
@@ -363,15 +422,28 @@
                 if (fp != NULL) {
                     fprintf(fp, "eureka!\r\n");
                     fclose(fp);
-                    TFT.printf("success!\n");
+                    TFT.locate(10,row); TFT.printf("success"); row+=10; 
                 } else {
-                    TFT.printf("failed!\n");
+                    TFT.locate(10,row); TFT.printf("failed to write"); row+=10; 
                 }
                 sd.unmount();
             }
+            
+            TFT.locate(10,row); TFT.printf("Configuring Skywire"); row+=10; 
+            skywire.baud(115200);
+            skywire.attach(&Skywire_Rx_interrupt, Serial::RxIrq);
+            
+            //Turn off echo
+            skywire.printf("ATE0\r\n");
+            WaitForResponse("OK");
+            TFT.locate(10,row); TFT.printf("Connecting to the Network"); row+=10; 
+            // get IP address
+            skywire.printf("AT#SGACT=1,1\r\n");         // context activation (returns with IP address)
+            WaitForResponse("#SGACT");
+            WaitForResponse("OK");
     
             ps = ain3.read(); 
             if (ps==1)  {wait(0.5); TFT.cls();  stage=0;}
         }
     }
-}
\ No newline at end of file
+}