EasyCAT LAB - EtherCAT master legacy example

Dependencies:   SOEM SPI_STMPE610 SPI_TFT_ILI9341 TFT_fonts

The EasyCAT LAB is a complete educational and experimental EtherCAT® system, composed of one master and two slaves .

/media/uploads/EasyCAT/easycat_lab.jpg

/media/uploads/EasyCAT/components.jpg

Revision:
5:550a1222dcba
Parent:
3:6ee00ee90d4c
Child:
6:4b39b4dee215
--- a/main.cpp	Fri May 07 09:47:30 2021 +0000
+++ b/main.cpp	Fri May 28 08:55:23 2021 +0000
@@ -26,6 +26,18 @@
 // www.ethercat.org     
 
 
+//******************************************************************************
+
+//#define ADA_TFT       // IMPORTANT!!! 
+
+                        // If your EasyCAT LAB uses the Adafruit TFT
+                        // you must uncomment this define
+                        
+                        // If your EasyCAT LAB uses the Seeed Studio TFT
+                        // you must comment this define                                                  
+
+//******************************************************************************
+
 #define ETH_TXBUFNB 16
 #define ETH_RXBUFNB 16
 
@@ -42,6 +54,7 @@
 #include "Arial28x28.h"
 #include "font_big.h"
 #include "soem_start.h"
+#include "SPI_STMPE610.h"
 
 #define CYCLE_TIME 1000                 // master cycle time in uS                    
                                         // 1000 = 1mS 
@@ -65,8 +78,16 @@
 #define PIN_MOSI        D11                         // TFT display SPI
 #define PIN_MISO        D12                         //
 #define PIN_SCLK        D13                         //
-#define PIN_CS_TFT      D5                          //
-#define PIN_DC_TFT      D6                          //
+
+#if defined ADA_TFT                                 // pins for the Adafruit TFT                      
+    #define PIN_CS_TFT  D10                         //                 
+    #define PIN_DC_TFT  D9                          //                     
+    #define PIN_CS_TSC  D8                          // 
+    
+#else                                               // pins for the SeeedStudio TFT
+    #define PIN_CS_TFT  D5                          //    
+    #define PIN_DC_TFT  D6                          //
+#endif                                              //
 
 
 //---- touchscreen parameters --------------------------------------------------
@@ -171,6 +192,10 @@
 
 SPI_TFT_ILI9341 TFT(PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TFT, NC, PIN_DC_TFT);
 
+#if defined ADA_TFT             // touchscreen controller for the Adafruit TFT       
+    SPI_STMPE610 TSC(PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TSC);             
+#endif
+
 Ticker SampleTicker;
 Thread thread;
 
@@ -291,8 +316,13 @@
   
     TFT.background(Black);                                          // init TFT  
     TFT.cls();                                                      //
-    TFT.set_orientation(3);                                         // 
-
+    
+    #if defined ADA_TFT
+        TFT.set_orientation(1);     
+    #else
+        TFT.set_orientation(3);                                        
+    #endif    
+    
     DrawBanner();     
         
     NetworkError = false;  
@@ -592,37 +622,42 @@
 void TouchScreenManagement()
 {                   
     uint16_t X;
-    uint16_t Y;
-    
+    uint16_t Y;  
     int i;
-            
-               
-    if (TouchRead(&X, &Y))                                          // the touchscreen has been tapped
+    
+    #if defined ADA_TFT                                             // if the touchscreen has been tapped
+        if (TSC.GetPoint(&X, &Y))                                   //
+    #else                                                           //
+        if (TouchRead(&X, &Y))                                      //   
+    #endif       
     {    
         TimeTouchReleased = SysMilliS();
-                                                                    // check if it is the side menu
+        
+        if(TouchWasReleased)
+        {                                                           // check if it is the side menu
                                                                     // decrement slave button
-        if ((X>MENU_X) && (X>MENU_X+MENU_WIDTH/2) && (Y>MENU_HEIGHT) && (Y<MENU_HEIGHT*2))
-        {                                                           //
-            VisuSlave--;
-            
-            if (VisuSlave == 0)                                     //
-                VisuSlave = SLAVE_NUM;                              //      
+            if ((X>MENU_X) && (X>MENU_X+MENU_WIDTH/2) && (Y>MENU_HEIGHT) && (Y<MENU_HEIGHT*2))
+            {                                                       //
+                VisuSlave--;
+                
+                if (VisuSlave == 0)                                 //
+                    VisuSlave = SLAVE_NUM;                          //      
                                                                     // the visualized slave has changed 
-            DrawSlaveFixedParts();                                  // draw the new slave fixed parts   
-        }                                                           //
-                     
+                DrawSlaveFixedParts();                              // draw the new slave fixed parts   
+            }                                                       //
+                   
                                                                     // check if it is the side menu
                                                                     // increment slave button                                                                        
-        if ((X>MENU_X) && (X<MENU_X+MENU_WIDTH/2) && (Y>MENU_HEIGHT) && (Y<MENU_HEIGHT*2))
-        {                                                           //
-            VisuSlave++;
-            
-            if (VisuSlave > SLAVE_NUM)                              //    
-                VisuSlave = LAB_1;                                  //                
+            if ((X>MENU_X) && (X<MENU_X+MENU_WIDTH/2) && (Y>MENU_HEIGHT) && (Y<MENU_HEIGHT*2))
+            {                                                       //
+                VisuSlave++;
+                
+                if (VisuSlave > SLAVE_NUM)                          //    
+                    VisuSlave = LAB_1;                              //                
                                                                     // the visualized slave has changed 
-            DrawSlaveFixedParts();                                  // draw the new slave fixed parts     
-        }                                                           //
+                DrawSlaveFixedParts();                              // draw the new slave fixed parts     
+            }                                                       //
+        }        
         
         switch (VisuSlave)                                          // check which slave is visualized on the TFT
         {                      
@@ -909,7 +944,15 @@
     TFT.printf("www.easycatshield.com"); 
     
     TFT.locate(30, 180);
-    TFT.printf("https://openethercatsociety.github.io/");     
+    TFT.printf("https://openethercatsociety.github.io/"); 
+    
+    TFT.foreground(Red);    
+    TFT.locate(30, 220);    
+    #if defined ADA_TFT                                 
+        TFT.printf("Adafruit TFT");   
+    #else
+        TFT.printf("Seeed Studio TFT");
+    #endif          
 }