Przeglądaj źródła

Add esp8266 interface

Just Call Me Koko 4 lat temu
rodzic
commit
a18b8b3004

+ 36 - 0
a32u4_marauder/a32u4_marauder.ino

@@ -0,0 +1,36 @@
+void setup() {
+  Serial.begin(115200);
+
+  delay(100);
+  
+  Serial1.begin(115200);
+
+  delay(100);
+  
+  // initialize digital pin LED_BUILTIN as an output.
+  pinMode(LED_BUILTIN, OUTPUT);
+
+  delay(100);
+
+  Serial.println("Waiting for serial data...");
+}
+
+// the loop function runs over and over again forever
+void loop() {
+  if (Serial1.available()) {
+    String input = Serial1.readString();
+
+    input.trim();
+
+    if (input == "Ping") {
+      Serial1.println("A32U4 Pong");
+      Serial.println("A32U4 Pong");
+    }
+      
+    Serial.println(input);
+    digitalWrite(LED_BUILTIN, HIGH);                      // wait for a second
+    delay(1);
+    digitalWrite(LED_BUILTIN, LOW);
+    delay(1);
+  }
+}

+ 6 - 0
esp32_marauder/Assets.h

@@ -241,6 +241,12 @@ PROGMEM static const unsigned char menu_icons[][66] = {
     0x54, 0x12, 0x1A, 0x54, 0xD0, 0x1F, 0x7C, 0xD2, 0x1B, 0x7C, 0x12, 0x1B, 
     0x38, 0xD2, 0x1B, 0x28, 0xD0, 0x1B, 0x01, 0xF8, 0x2F, 0x03, 0x00, 0x30, 
     0x1F, 0x00, 0x3E, 0x3F, 0x00, 0x3F, 0xFF, 0xC0, 0x3F, 0xFF, 0xFF, 0x3F, 
+    0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0x3F},
+    {0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0x3F, 0x1F, 0x00, 0x3C, 0xDF, 0xFF, 0x3D,  // ESP_UPDATE_ICO: 32
+    0x5F, 0x10, 0x3D, 0x5F, 0x55, 0x3D, 0x5F, 0x45, 0x3D, 0xDF, 0xFF, 0x3D, 
+    0x7F, 0x00, 0x3F, 0x5F, 0x7F, 0x3D, 0x7F, 0x71, 0x3F, 0x5F, 0x77, 0x3D, 
+    0x7F, 0x7F, 0x3F, 0x5F, 0x71, 0x3D, 0x7F, 0x75, 0x3F, 0x5F, 0x7F, 0x3D, 
+    0x7F, 0x7F, 0x3F, 0x5F, 0x00, 0x3D, 0xFF, 0xFF, 0x3F, 0x5F, 0x55, 0x3D, 
     0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0x3F}
     };
 

+ 1 - 1
esp32_marauder/Display.h

@@ -108,7 +108,7 @@ class Display
     TFT_eSPI tft = TFT_eSPI();
     TFT_eSprite img = TFT_eSprite(&tft);
     TFT_eSPI_Button key[BUTTON_ARRAY_LEN];
-    const String PROGMEM version_number = "v0.8.0";
+    const String PROGMEM version_number = "v0.9.0";
 
     bool printing = false;
     bool loading = false;

+ 17 - 0
esp32_marauder/MenuFunctions.cpp

@@ -276,6 +276,7 @@ void MenuFunctions::main(uint32_t currentTime)
   }
   if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_OFF) ||
       (wifi_scan_obj.currentScanMode == OTA_UPDATE) ||
+      (wifi_scan_obj.currentScanMode == ESP_UPDATE) ||
       (wifi_scan_obj.currentScanMode == SHOW_INFO)) {
     if (wifi_scan_obj.orient_display) {
       this->orientDisplay();
@@ -334,6 +335,7 @@ void MenuFunctions::main(uint32_t currentTime)
   if ((wifi_scan_obj.currentScanMode != WIFI_SCAN_OFF) &&
       (pressed) &&
       (wifi_scan_obj.currentScanMode != OTA_UPDATE) &&
+      (wifi_scan_obj.currentScanMode != ESP_UPDATE) &&
       (wifi_scan_obj.currentScanMode != SHOW_INFO))
   {
     // Stop the current scan
@@ -691,6 +693,7 @@ void MenuFunctions::RunSetup()
   failedUpdateMenu.list = new LinkedList<MenuNode>();
   whichUpdateMenu.list = new LinkedList<MenuNode>();
   confirmMenu.list = new LinkedList<MenuNode>();
+  espUpdateMenu.list = new LinkedList<MenuNode>();
   updateMenu.list = new LinkedList<MenuNode>();
   infoMenu.list = new LinkedList<MenuNode>();
 
@@ -719,6 +722,7 @@ void MenuFunctions::RunSetup()
   failedUpdateMenu.name = " Updating... ";
   whichUpdateMenu.name = "Select Method ";
   confirmMenu.name = " Confirm Update ";
+  espUpdateMenu.name = " ESP8266 Update ";
   updateMenu.name = " Update Firmware ";
   infoMenu.name = " Device Info ";
   bluetoothMenu.name = " Bluetooth ";
@@ -979,6 +983,19 @@ void MenuFunctions::RunSetup()
     wifi_scan_obj.currentScanMode = OTA_UPDATE;
     changeMenu(&confirmMenu);
   });
+  addNodes(&whichUpdateMenu, "ESP8266 Update", TFT_RED, NULL, ESP_UPDATE_ICO, [this]() {
+    wifi_scan_obj.currentScanMode = ESP_UPDATE;
+    changeMenu(&espUpdateMenu);
+    esp_obj.RunUpdate();
+  });
+
+  // ESP Update Menu
+  espUpdateMenu.parentMenu = &whichUpdateMenu;
+  addNodes(&espUpdateMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this]() {
+    wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF;
+    esp_obj.bootRunMode();
+    changeMenu(espUpdateMenu.parentMenu);
+  });
 
   // Confirm SD update menu
   confirmMenu.parentMenu = &whichUpdateMenu;

+ 4 - 0
esp32_marauder/MenuFunctions.h

@@ -8,6 +8,7 @@
 #include "BatteryInterface.h"
 #include "SDInterface.h"
 #include "Web.h"
+#include "esp_interface.h"
 
 
 extern Display display_obj;
@@ -15,6 +16,7 @@ extern WiFiScan wifi_scan_obj;
 extern Web web_obj;
 extern SDInterface sd_obj;
 extern BatteryInterface battery_obj;
+extern EspInterface esp_obj;
 
 // Keypad start position, key sizes and spacing
 #define KEY_X 120 // Centre of key
@@ -70,6 +72,7 @@ extern BatteryInterface battery_obj;
 #define CLEAR_ICO 29
 #define KEYBOARD_ICO 30
 #define JOIN_WIFI 31
+#define ESP_UPDATE_ICO 32
 
 PROGMEM void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p);
 PROGMEM bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data);
@@ -127,6 +130,7 @@ class MenuFunctions
     Menu whichUpdateMenu;
     Menu failedUpdateMenu;
     Menu confirmMenu;
+    Menu espUpdateMenu;
     Menu updateMenu;
     Menu infoMenu;
 

+ 1 - 0
esp32_marauder/WiFiScan.h

@@ -28,6 +28,7 @@
 
 #define OTA_UPDATE 100
 #define SHOW_INFO 101
+#define ESP_UPDATE 102
 #define WIFI_SCAN_OFF 0
 #define WIFI_SCAN_PROBE 1
 #define WIFI_SCAN_AP 2

+ 13 - 2
esp32_marauder/esp32_marauder.ino

@@ -26,6 +26,7 @@ https://www.online-utility.org/image/convert/to/XBM
 #include "BatteryInterface.h"
 #include "TemperatureInterface.h"
 #include "LedInterface.h"
+#include "esp_interface.h"
 //#include "icons.h"
 
 /*
@@ -48,6 +49,7 @@ Buffer buffer_obj;
 BatteryInterface battery_obj;
 TemperatureInterface temp_obj;
 LedInterface led_obj;
+EspInterface esp_obj;
 
 Adafruit_NeoPixel strip = Adafruit_NeoPixel(Pixels, PIN, NEO_GRB + NEO_KHZ800);
 
@@ -70,6 +72,8 @@ void setup()
   Serial.begin(115200);
   
   Serial.begin(115200);
+
+  esp_obj.begin();
   
   display_obj.RunSetup();
   display_obj.tft.setTextColor(TFT_CYAN, TFT_BLACK);
@@ -173,13 +177,14 @@ void loop()
   // Update all of our objects
   //if ((!display_obj.draw_tft) &&
   //    (wifi_scan_obj.currentScanMode != OTA_UPDATE))
-  if (!display_obj.draw_tft)
+  if ((!display_obj.draw_tft) && (wifi_scan_obj.currentScanMode != ESP_UPDATE))
   {
-    display_obj.main(wifi_scan_obj.currentScanMode); 
+    display_obj.main(wifi_scan_obj.currentScanMode);
     wifi_scan_obj.main(currentTime);
     sd_obj.main();
     battery_obj.main(currentTime);
     temp_obj.main(currentTime);
+    esp_obj.main(currentTime);
     //led_obj.main(currentTime);
     //if ((wifi_scan_obj.currentScanMode != WIFI_ATTACK_BEACON_SPAM))
     if ((wifi_scan_obj.currentScanMode != WIFI_PACKET_MONITOR) &&
@@ -194,6 +199,12 @@ void loop()
   {
     display_obj.drawStylus();
   }
+  else if (wifi_scan_obj.currentScanMode == ESP_UPDATE) {
+    display_obj.main(wifi_scan_obj.currentScanMode);
+    menu_function_obj.main(currentTime);
+    esp_obj.program();
+    delay(1);
+  }
   //else
   //{
   //  web_obj.main();

+ 81 - 0
esp32_marauder/esp_interface.cpp

@@ -0,0 +1,81 @@
+#include "esp_interface.h"
+
+HardwareSerial MySerial(1);
+
+void EspInterface::begin() {
+  pinMode(ESP_RST, OUTPUT);
+  pinMode(ESP_ZERO, OUTPUT);
+
+  delay(100);
+
+  digitalWrite(ESP_ZERO, HIGH);
+
+  MySerial.begin(BAUD, SERIAL_8N1, 27, 26);
+
+  this->bootRunMode();
+}
+
+void EspInterface::RunUpdate() {
+  this->bootProgramMode();
+  
+  display_obj.tft.setTextWrap(true);
+  display_obj.tft.setFreeFont(NULL);
+  display_obj.tft.setCursor(0, 100);
+  display_obj.tft.setTextSize(1);
+  display_obj.tft.setTextColor(TFT_GREEN);
+
+  display_obj.tft.println("Waiting for serial data...");
+
+  display_obj.tft.setTextColor(TFT_WHITE);
+}
+
+void EspInterface::bootProgramMode() {
+  Serial.println("[!] Setting ESP12 in program mode...");
+  digitalWrite(ESP_ZERO, LOW);
+  delay(100);
+  digitalWrite(ESP_RST, LOW);
+  delay(100);
+  digitalWrite(ESP_RST, HIGH);
+  delay(100);
+  digitalWrite(ESP_ZERO, HIGH);
+  Serial.println("[!] Complete");
+  Serial.end();
+  Serial.begin(BAUD);
+}
+
+void EspInterface::bootRunMode() {
+  Serial.end();
+  Serial.begin(115200);
+  Serial.println("[!] Setting ESP12 in run mode...");
+  digitalWrite(ESP_ZERO, HIGH);
+  delay(100);
+  digitalWrite(ESP_RST, LOW);
+  delay(100);
+  digitalWrite(ESP_RST, HIGH);
+  delay(100);
+  digitalWrite(ESP_ZERO, HIGH);
+  Serial.println("[!] Complete");
+}
+
+void EspInterface::program() {
+  if (MySerial.available()) {
+    Serial.write((uint8_t)MySerial.read());
+  }
+
+  if (Serial.available()) {
+    display_obj.tft.print(".");
+    while (Serial.available()) {
+      MySerial.write((uint8_t)Serial.read());
+    }
+  }
+}
+
+void EspInterface::main(uint32_t current_time) {
+  if (MySerial.available()) {
+    Serial.write((uint8_t)MySerial.read());
+  }
+
+  if (Serial.available()) {
+    MySerial.write((uint8_t)Serial.read());
+  }
+}

+ 26 - 0
esp32_marauder/esp_interface.h

@@ -0,0 +1,26 @@
+#ifndef esp_interface_h
+#define esp_interface_h
+
+#include "Display.h"
+#include <HardwareSerial.h>
+
+#define ESP_RST  14
+#define ESP_ZERO 13
+#define BAUD     57600
+
+extern Display display_obj;
+
+class EspInterface {
+  public:
+    bool supported = false;
+
+    void RunUpdate();
+    void bootProgramMode();
+    void bootRunMode();
+    void begin();
+
+    void program();
+    void main(uint32_t current_time);
+};
+
+#endif

+ 13 - 0
esp8266_marauder/esp8266_marauder.ino

@@ -0,0 +1,13 @@
+// the setup function runs once when you press reset or power the board
+void setup() {
+  // initialize digital pin LED_BUILTIN as an output.
+  pinMode(LED_BUILTIN, OUTPUT);
+}
+
+// the loop function runs over and over again forever
+void loop() {
+  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
+  delay(1000);                       // wait for a second
+  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
+  delay(1000);                       // wait for a second
+}