Maurader portado ESP32-C6 1.47inch Touch Display

Estoy tratando de portar Maurader a esta placa de desarollo si alguien me echa una mano estaria enormemente agradecido tengo parte del codigo semi funcional aca coloco algo del sketch

#include <Arduino_GFX_Library.h>
#include "esp_lcd_touch_axs5106l.h"  // TU DRIVER DE TOUCH
#include <Wire.h>
#include <WiFi.h>
#include <BLEDevice.h>
#include <BLEScan.h>

// --- CONFIGURACIÓN DE PINES (Tomada de tu Sketch) ---

#define GFX_BRIGHTNESS 255

// Touch pins
#define Touch_I2C_SDA 18
#define Touch_I2C_SCL 19
#define Touch_RST 20
#define Touch_INT 21

// Display and hardware pins
#define GFX_BL 23
#define SD_CS 4  // PIN PARA FUTURAS IMPLEMENTACIONES DE REGISTRO EN SD

  // Display setup (ST7789 172x320)
  Arduino_DataBus* bus = new Arduino_HWSPI(15 /* DC */, 14 /* CS */, 1 /* SCK */, 2 /* MOSI \*/);
Arduino_GFX* gfx = new Arduino_ST7789(bus, 22 /* RST */, 0 /* rotation */, false /* IPS */, 172 /* width */, 320 /* height */, 34 /* col offset 1 */, 0 /* row offset 1 */, 34 /* col offset 2 */, 0 /* row offset 2 \*/);

// Touch control variables
touch_data_t touch_data;
volatile uint32_t lastTouch = 0;

// --- ESTRUCTURA DEL MENÚ MARAUDER ---
enum MenuState {
  MENU_MAIN,
  MENU_WIFI_SCAN,
  MENU_BLE_SCAN,
  MENU_INFO,
  MENU_IN_ACTION  // Estado para mostrar resultados de escaneo
};

MenuState current_state = MENU_MAIN;
int selected_option = 0;

const char\* main_menu_options\[\] = {
  "Wi-Fi Scan APs",
  "Bluetooth Scan LE",
  "Display Info",
  "Return to Home"  // Opción de salida (aunque es la principal)
};
const int main_menu_size = 4;
const int menu_item_height = 30;  // Altura de cada elemento en el menú

// --- FUNCIONES DE GRÁFICOS Y MENÚ ---

void draw_text_box(int x, int y, const char\* text, bool selected) {
  int w = gfx->width();
  uint16_t bg_color = selected ? 0x07E0 /\* VERDE * / : 0x0000 /* NEGRO */;
  uint16_t fg_color = selected ? 0x0000 /* NEGRO */ : 0xFFFF /* BLANCO \*/;


  gfx->fillRect(0, y, w, menu_item_height, bg_color);
  gfx->drawRect(0, y, w, menu_item_height, 0xFFFF);
  gfx->setTextColor(fg_color);
  gfx->setCursor(10, y + 10);
  gfx->setTextSize(1);
  gfx->println(text);
  
}

void draw_main_menu() {
  gfx->fillScreen(0x0000);  // Negro
  gfx->setTextSize(2);
  gfx->setTextColor(0xF800);  // Rojo para el título


  // Título "Marauder" en grande
  gfx->setCursor((gfx->width() - 8 * 9) / 2, 10);
  gfx->println("MARAUDER");

  // Dibuja las opciones
  for (int i = 0; i < main_menu_size; i++) {
    draw_text_box(0, 50 + (i * menu_item_height), main_menu_options[i], (i == selected_option));
  }
}

// --- FUNCIÓN DE INICIALIZACIÓN DE BRIGHTNESS (Tomada de tu Sketch) ---
void setDisplayBrightness() {
  pinMode(GFX_BL, OUTPUT);
  digitalWrite(GFX_BL, HIGH);  // Tu código usa digitalWrite(HIGH) para encenderlo
}

// --- FUNCIÓN DE PROCESAMIENTO TÁCTIL (Adaptada a tu driver AXS5106L) ---
void checkTouch() {
  bsp_touch_read();
  bool touchPressed = bsp_touch_get_coordinates(&touch_data);


  if (touchPressed) {
    uint32_t now = millis();
    // Debounce y chequeo de tiempo para evitar toques continuos
    if (now - lastTouch > 500) {
      lastTouch = now;
      int touchX = touch_data.coords[0].x;
      int touchY = touch_data.coords[0].y;
      Serial.printf("Touch at: X=%d, Y=%d\n", touchX, touchY);

      // La lógica de toque se basa en el menú
      if (current_state == MENU_MAIN) {
        // Mapear el toque Y a una opción de menú
        if (touchY > 50) {
          int clicked_option = (touchY - 50) / menu_item_height;
          if (clicked_option < main_menu_size) {
            selected_option = clicked_option;

            // Determinar la nueva acción/estado
            switch (selected_option) {
              case 0: current_state = MENU_WIFI_SCAN; break;
              case 1: current_state = MENU_BLE_SCAN; break;
              case 2: current_state = MENU_INFO; break;
              case 3: /* Vuelve a casa */ break;
            }
          }
        }
        draw_main_menu();
      } else if (current_state == MENU_IN_ACTION || current_state == MENU_INFO) {
        // En el estado de resultados/información, cualquier toque regresa al menú principal
        current_state = MENU_MAIN;
        draw_main_menu();
      }
    }
  }
}

// --- FUNCIONALIDADES DE MARAUDER SIMPLIFICADAS ---

void display_info() {
  gfx->fillScreen(0x0000);
  gfx->setTextColor(0xFFFF);
  gfx->setTextSize(1);
  gfx->setCursor(5, 5);


  gfx->println("--- System Info (Marauder Lite) ---");
  gfx->printf("Chip: ESP32-C6\n");
  gfx->printf("WiFi: %s\n", WiFi.getMode() == WIFI_MODE_APSTA ? "AP+STA" : "STA");
  gfx->printf("MAC: %s\n", WiFi.macAddress().c_str());
  gfx->printf("Screen: ST7789 172x320\n");
  gfx->printf("Touch: AXS5106L\n");
  gfx->printf("\nTap to return to Menu\n");

  current_state = MENU_IN_ACTION;  // Espera un toque para salir
}

void wifi_scan_aps() {
  gfx->fillScreen(0x0000);
  gfx->setTextColor(0xFFFF);
  gfx->setTextSize(1);
  gfx->setCursor(5, 5);
  gfx->println("--- Scanning Wi-Fi APs ---");


  int n = WiFi.scanNetworks(false, true);  // Escaneo oculto: false, escaneo pasivo: true

  if (n == 0) {
    gfx->println("No networks found. Tap to return.");
  } else {
    gfx->printf("%d networks found:\n", n);
    // Mostrar los primeros 8 resultados
    for (int i = 0; i < n && i < 8; ++i) {
      String ssid = WiFi.SSID(i);
      if (ssid.length() > 20) ssid = ssid.substring(0, 17) + "...";
      gfx->printf("%d: %s (%d)\n", i + 1, ssid.c_str(), WiFi.RSSI(i));
    }
    gfx->printf("\nTap to return to Menu\n");
  }
  WiFi.scanDelete();  // Limpia los resultados
  current_state = MENU_IN_ACTION;
}

// Clase para manejar los resultados del escaneo BLE
class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks {
  int devices_count = 0;
  void onResult(BLEAdvertisedDevice advertisedDevice) {
    if (devices_count < 8) {
      gfx->setCursor(5, 30 + (devices_count \* 15));
      gfx->printf("MAC: %s (RSSI: %d)\\n", advertisedDevice.getAddress().toString().c_str(), advertisedDevice.getRSSI());
      devices_count++;
    }
  }
};

void ble_scan_le() {
  gfx->fillScreen(0x0000);
  gfx->setTextColor(0xFFFF);
  gfx->setTextSize(1);
  gfx->setCursor(5, 5);
  gfx->println("--- Scanning Bluetooth LE ---");


  // Inicia el escaneo BLE
  BLEDevice::init("");
  BLEScan* pBLEScan = BLEDevice::getScan();
  pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
  pBLEScan->setActiveScan(true);
  pBLEScan->start(5, false);  // Escanea por 5 segundos
  pBLEScan->stop();

  gfx->setCursor(5, 30 + (8 * 15) + 5);
  gfx->printf("\nTap to return to Menu\n");

  current_state = MENU_IN_ACTION;
}

// --- SETUP y LOOP ---

void setup() {
  Serial.begin(115200);

  // 1. Inicialización de la pantalla
  gfx->begin();
  // Tu código usa setRotation(0) pero el mapeo 172x320 sugiere Rotación 1 o 3.
  // Usaremos setRotation(1) para modo vertical estándar de Marauder.
  gfx->setRotation(1);
  gfx->fillScreen(0x0000);
  setDisplayBrightness();

  // 2. Inicialización del Touch (USANDO TUS DRIVERS)
  Wire.begin(Touch_I2C_SDA, Touch_I2C_SCL);
  bsp_touch_init(&Wire, Touch_RST, Touch_INT, gfx->getRotation(), gfx->width(), gfx->height());

  // 3. Inicialización de la lógica
  draw_main_menu();
}

void loop() {
  checkTouch();

  if (current_state == MENU_WIFI_SCAN) {
    wifi_scan_aps();
  } else if (current_state == MENU_BLE_SCAN) {
    ble_scan_le();
  } else if (current_state == MENU_INFO) {
    display_info();
  }

  // En los estados de acción (MENU_IN_ACTION, MENU_WIFI_SCAN, etc.),
  // el loop de checkTouch() se encarga de esperar el toque para volver al menú.
  delay(50);
}

Moderador:
1. Tema movido a Microcontroladores.
2. Código editado por ser visualizado correctamente con etiquetas de código

¿En qué? ¿Cuál es tu problema específico?

"Algo" no sirve de nada, sube todo el código y de acuerdo a las Normas.

Por último, ¿Qué diablos es "Maurader"?

marauder è un "firmware" per fare penetration testing con le schede esp

1 Like

Moderador

@fluffierfox_1 estas en el foro en Español, por lo tanto se pide que todos nos expresemos en este idioma.
Toleramos las hojas de datos en el idioma en que se encuentre pero nada mas.
Ahora te pido que con el método que desees edites tu respuesta usando español.
Aunque se entiende, las reglas son claras para todos.