diff --git a/esp32_marauder/LedInterface.cpp b/esp32_marauder/LedInterface.cpp index bff8864..41d017a 100644 --- a/esp32_marauder/LedInterface.cpp +++ b/esp32_marauder/LedInterface.cpp @@ -6,14 +6,17 @@ LedInterface::LedInterface() { void LedInterface::RunSetup() { //Serial.println("Setting neopixel to black..."); - strip.setBrightness(0); - strip.begin(); - strip.setPixelColor(0, strip.Color(0, 0, 0)); - strip.show(); - //delay(100); - strip.setBrightness(50); - strip.setPixelColor(0, strip.Color(0, 0, 0)); - strip.show(); + #ifdef HAS_NEOPIXEL_LED + strip.setBrightness(0); + strip.begin(); + strip.setPixelColor(0, strip.Color(0, 0, 0)); + strip.show(); + //delay(100); + strip.setBrightness(50); + strip.setPixelColor(0, strip.Color(0, 0, 0)); + strip.show(); + #endif + this->initTime = millis(); } @@ -50,8 +53,10 @@ uint8_t LedInterface::getMode() { } void LedInterface::setColor(int r, int g, int b) { - strip.setPixelColor(0, strip.Color(r, g, b)); - strip.show(); + #ifdef HAS_NEOPIXEL_LED + strip.setPixelColor(0, strip.Color(r, g, b)); + strip.show(); + #endif } void LedInterface::sniffLed() { @@ -67,25 +72,29 @@ void LedInterface::ledOff() { } void LedInterface::rainbow() { - strip.setPixelColor(0, this->Wheel((0 * 256 / 100 + this->wheel_pos) % 256)); - strip.show(); + #ifdef HAS_NEOPIXEL_LED + strip.setPixelColor(0, this->Wheel((0 * 256 / 100 + this->wheel_pos) % 256)); + strip.show(); - this->current_fade_itter++; + this->current_fade_itter++; - this->wheel_pos = this->wheel_pos - this->wheel_speed; - if (this->wheel_pos < 0) - this->wheel_pos = 255; + this->wheel_pos = this->wheel_pos - this->wheel_speed; + if (this->wheel_pos < 0) + this->wheel_pos = 255; + #endif } uint32_t LedInterface::Wheel(byte WheelPos) { - WheelPos = 255 - WheelPos; - if(WheelPos < 85) { - return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3); - } - if(WheelPos < 170) { - WheelPos -= 85; - return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3); - } - WheelPos -= 170; - return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0); + #ifdef HAS_NEOPIXEL_LED + WheelPos = 255 - WheelPos; + if(WheelPos < 85) { + return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3); + } + if(WheelPos < 170) { + WheelPos -= 85; + return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3); + } + WheelPos -= 170; + return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0); + #endif } \ No newline at end of file diff --git a/esp32_marauder/SDInterface.cpp b/esp32_marauder/SDInterface.cpp index 133bb80..ac5f8d0 100644 --- a/esp32_marauder/SDInterface.cpp +++ b/esp32_marauder/SDInterface.cpp @@ -1,6 +1,10 @@ #include "SDInterface.h" #include "lang_var.h" +#ifdef HAS_C5_SD + SDInterface::SDInterface(SPIClass* spi, int cs) + : _spi(spi), _cs(cs) {} +#endif bool SDInterface::initSD() { #ifdef HAS_SD @@ -41,6 +45,9 @@ bool SDInterface::initSD() { this->spiExt = new SPIClass(); this->spiExt->begin(SPI_SCK, SPI_MISO, SPI_MOSI, SD_CS); if (!SD.begin(SD_CS, *(this->spiExt))) { + #elif defined(HAS_C5_SD) + Serial.println("Using C5 SD configuration..."); + if (!SD.begin(SD_CS, *_spi)) { #else if (!SD.begin(SD_CS)) { #endif @@ -51,19 +58,9 @@ bool SDInterface::initSD() { else { this->supported = true; this->cardType = SD.cardType(); - //if (cardType == CARD_MMC) - // Serial.println(F("SD: MMC Mounted")); - //else if(cardType == CARD_SD) - // Serial.println(F("SD: SDSC Mounted")); - //else if(cardType == CARD_SDHC) - // Serial.println(F("SD: SDHC Mounted")); - //else - // Serial.println(F("SD: UNKNOWN Card Mounted")); this->cardSizeMB = SD.cardSize() / (1024 * 1024); - //Serial.printf("SD Card Size: %lluMB\n", this->cardSizeMB); - if (this->supported) { const int NUM_DIGITS = log10(this->cardSizeMB) + 1; diff --git a/esp32_marauder/SDInterface.h b/esp32_marauder/SDInterface.h index 90c0f72..f096e48 100644 --- a/esp32_marauder/SDInterface.h +++ b/esp32_marauder/SDInterface.h @@ -28,10 +28,17 @@ class SDInterface { private: #if (defined(MARAUDER_M5STICKC) || defined(HAS_CYD_TOUCH)) SPIClass *spiExt; + #elif defined(HAS_C5_SD) + SPIClass* _spi; + int _cs; #endif bool checkDetectPin(); public: + #ifdef HAS_C5_SD + SDInterface(SPIClass* spi, int cs); + #endif + uint8_t cardType; //uint64_t cardSizeBT; //uint64_t cardSizeKB; diff --git a/esp32_marauder/WiFiScan.cpp b/esp32_marauder/WiFiScan.cpp index b2f6106..ff6e1f3 100644 --- a/esp32_marauder/WiFiScan.cpp +++ b/esp32_marauder/WiFiScan.cpp @@ -7129,10 +7129,19 @@ void WiFiScan::changeChannel() // Function to cycle to the next channel void WiFiScan::channelHop() { - this->set_channel = this->set_channel + 1; - if (this->set_channel > 14) { - this->set_channel = 1; - } + #ifndef HAS_DUAL_BAND + this->set_channel = this->set_channel + 1; + if (this->set_channel > 14) { + this->set_channel = 1; + } + #else + this->set_channel = this->dual_band_channels[this->dual_band_channel_index]; + if (this->dual_band_channel_index >= DUAL_BAND_CHANNELS) + this->dual_band_channel_index = 0; + else + this->dual_band_channel_index++; + #endif + esp_wifi_set_channel(this->set_channel, WIFI_SECOND_CHAN_NONE); delay(1); } @@ -7458,7 +7467,7 @@ void WiFiScan::main(uint32_t currentTime) (currentScanMode == WIFI_SCAN_STATION_WAR_DRIVE) || (currentScanMode == WIFI_SCAN_ALL)) { - if (currentTime - initTime >= this->channel_hop_delay * 1000) + if (currentTime - initTime >= this->channel_hop_delay * HOP_DELAY) { initTime = millis(); channelHop(); diff --git a/esp32_marauder/WiFiScan.h b/esp32_marauder/WiFiScan.h index f45e85c..576af4e 100644 --- a/esp32_marauder/WiFiScan.h +++ b/esp32_marauder/WiFiScan.h @@ -20,6 +20,9 @@ #include #include "esp_wifi.h" #include "esp_wifi_types.h" +#ifdef HAS_DUAL_BAND + #include "esp_system.h" +#endif #ifdef HAS_BT #include "esp_bt.h" #endif @@ -177,6 +180,10 @@ extern Settings settings_obj; esp_err_t esp_wifi_80211_tx(wifi_interface_t ifx, const void *buffer, int len, bool en_sys_seq); +#ifdef HAS_DUAL_BAND + esp_err_t esp_base_mac_addr_set(uint8_t *Mac); +#endif + /*struct ssid { String essid; uint8_t channel; @@ -231,6 +238,10 @@ class WiFiScan uint8_t ap_mac[6] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; uint8_t sta_mac[6] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; + uint8_t dual_band_channels[DUAL_BAND_CHANNELS] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80, 84, 88, 92, 96, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 144, 149, 153, 157, 161, 165, 169, 173, 177}; + + uint8_t dual_band_channel_index = 0; + // Settings uint mac_history_cursor = 0; uint8_t channel_hop_delay = 1; @@ -560,31 +571,35 @@ class WiFiScan wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); - wifi_init_config_t cfg2 = { \ - .event_handler = &esp_event_send_internal, \ - .osi_funcs = &g_wifi_osi_funcs, \ - .wpa_crypto_funcs = g_wifi_default_wpa_crypto_funcs, \ - .static_rx_buf_num = 6,\ - .dynamic_rx_buf_num = 6,\ - .tx_buf_type = 0,\ - .static_tx_buf_num = 1,\ - .dynamic_tx_buf_num = WIFI_DYNAMIC_TX_BUFFER_NUM,\ - .cache_tx_buf_num = 0,\ - .csi_enable = false,\ - .ampdu_rx_enable = false,\ - .ampdu_tx_enable = false,\ - .amsdu_tx_enable = false,\ - .nvs_enable = false,\ - .nano_enable = WIFI_NANO_FORMAT_ENABLED,\ - .rx_ba_win = 6,\ - .wifi_task_core_id = WIFI_TASK_CORE_ID,\ - .beacon_max_len = 752, \ - .mgmt_sbuf_num = 8, \ - .feature_caps = g_wifi_feature_caps, \ - .sta_disconnected_pm = WIFI_STA_DISCONNECTED_PM_ENABLED, \ - .espnow_max_encrypt_num = 0, \ - .magic = WIFI_INIT_CONFIG_MAGIC\ - }; + #ifndef HAS_DUAL_BAND + wifi_init_config_t cfg2 = { \ + .event_handler = &esp_event_send_internal, \ + .osi_funcs = &g_wifi_osi_funcs, \ + .wpa_crypto_funcs = g_wifi_default_wpa_crypto_funcs, \ + .static_rx_buf_num = 6,\ + .dynamic_rx_buf_num = 6,\ + .tx_buf_type = 0,\ + .static_tx_buf_num = 1,\ + .dynamic_tx_buf_num = WIFI_DYNAMIC_TX_BUFFER_NUM,\ + .cache_tx_buf_num = 0,\ + .csi_enable = false,\ + .ampdu_rx_enable = false,\ + .ampdu_tx_enable = false,\ + .amsdu_tx_enable = false,\ + .nvs_enable = false,\ + .nano_enable = WIFI_NANO_FORMAT_ENABLED,\ + .rx_ba_win = 6,\ + .wifi_task_core_id = WIFI_TASK_CORE_ID,\ + .beacon_max_len = 752, \ + .mgmt_sbuf_num = 8, \ + .feature_caps = g_wifi_feature_caps, \ + .sta_disconnected_pm = WIFI_STA_DISCONNECTED_PM_ENABLED, \ + .espnow_max_encrypt_num = 0, \ + .magic = WIFI_INIT_CONFIG_MAGIC\ + }; + #else + wifi_init_config_t cfg2 = WIFI_INIT_CONFIG_DEFAULT(); + #endif wifi_config_t ap_config; diff --git a/esp32_marauder/configs.h b/esp32_marauder/configs.h index fdd80e0..f5eb8b1 100644 --- a/esp32_marauder/configs.h +++ b/esp32_marauder/configs.h @@ -26,12 +26,15 @@ //#define MARAUDER_CYD_MICRO // 2432S028 //#define MARAUDER_CYD_2USB // Another 2432S028 but it has tWo UsBs OoOoOoO //#define MARAUDER_CYD_GUITION // ESP32-2432S024 GUITION + //#define MARAUDER_C5 //// END BOARD TARGETS - #define MARAUDER_VERSION "v1.7.2" + #define MARAUDER_VERSION "v1.8.0" #define GRAPH_REFRESH 100 + #define DUAL_BAND_CHANNELS 51 + //// HARDWARE NAMES #ifdef MARAUDER_M5STICKC #define HARDWARE_NAME "M5Stick-C Plus" @@ -69,6 +72,8 @@ #define HARDWARE_NAME "Flipper Zero Dev Board Pro" #elif defined(XIAO_ESP32_S3) #define HARDWARE_NAME "XIAO ESP32 S3" + #elif defined(MARAUDER_C5) + #define HARDWARE_NAME "ESP32-C5 DevKit" #else #define HARDWARE_NAME "ESP32" #endif @@ -351,6 +356,24 @@ //#define HAS_TEMP_SENSOR //#define HAS_GPS #endif + + #ifdef MARAUDER_C5 + //#define HAS_FLIPPER_LED + //#define FLIPPER_ZERO_HAT + //#define HAS_BATTERY + //#define HAS_BT + //#define HAS_BUTTONS + //#define HAS_NEOPIXEL_LED + //#define HAS_PWR_MGMT + //#define HAS_SCREEN + #define HAS_GPS + #define HAS_C5_SD + #define HAS_SD + #define USE_SD + #define HAS_DUAL_BAND + //#define HAS_PSRAM + //#define HAS_TEMP_SENSOR + #endif //// END BOARD FEATURES //// POWER MANAGEMENT @@ -1701,6 +1724,10 @@ #define SD_CS 3 #endif + #ifdef MARAUDER_C5 + #define SD_CS 10 + #endif + #endif //// END SD DEFINITIONS @@ -1792,6 +1819,8 @@ #define MEM_LOWER_LIM 10000 #elif defined(XIAO_ESP32_S3) #define MEM_LOWER_LIM 10000 + #elif defined(MARAUDER_C5) + #define MEM_LOWER_LIM 10000 #endif //// END MEMORY LOWER LIMIT STUFF @@ -1889,6 +1918,10 @@ #define GPS_SERIAL_INDEX 1 #define GPS_TX 6 #define GPS_RX 9 + #elif defined(MARAUDER_C5) + #define GPS_SERIAL_INDEX 1 + #define GPS_TX 14 + #define GPS_RX 13 #endif #else #define mac_history_len 100 @@ -1971,6 +2004,8 @@ #define MARAUDER_TITLE_BYTES 13578 #elif defined(MARAUDER_REV_FEATHER) #define MARAUDER_TITLE_BYTES 13578 + #elif defined(MARAUDER_C5) + #define MARAUDER_TITLE_BYTES 13578 #else #define MARAUDER_TITLE_BYTES 13578 #endif @@ -1992,7 +2027,7 @@ //// PCAP BUFFER STUFF //// STUPID CYD STUFF - #ifdef HAS_CYD_TOUCH + #if defined(HAS_CYD_TOUCH) || defined(HAS_C5_SD) #ifdef MARAUDER_CYD_MICRO #define XPT2046_IRQ 36 #define XPT2046_MOSI 32 @@ -2016,6 +2051,12 @@ #define SD_MOSI 23 #define SD_SCK 18 #endif + + #ifdef MARAUDER_C5 + #define SD_MISO 2 + #define SD_MOSI 7 + #define SD_SCK 6 + #endif #endif //// END STUPID CYD STUFF @@ -2054,4 +2095,12 @@ #endif //// END FUNNY FLIPPER LED STUFF + + //// WIFI STUFF + + #ifndef HAS_DUAL_BAND + #define HOP_DELAY 1000 + #else + #define HOP_DELAY 100 + #endif #endif diff --git a/esp32_marauder/esp32_marauder.ino b/esp32_marauder/esp32_marauder.ino index ef7e944..ab1cd0a 100644 --- a/esp32_marauder/esp32_marauder.ino +++ b/esp32_marauder/esp32_marauder.ino @@ -97,7 +97,7 @@ CommandLine cli_obj; MenuFunctions menu_function_obj; #endif -#ifdef HAS_SD +#if defined(HAS_SD) && !defined(HAS_C5_SD) SDInterface sd_obj; #endif @@ -147,9 +147,22 @@ void backlightOff() { #endif } +#ifdef HAS_C5_SD + SPIClass sharedSPI(SPI); + SDInterface sd_obj = SDInterface(&sharedSPI, SD_CS); +#endif + void setup() { - esp_spiram_init(); + #ifndef HAS_DUAL_BAND + esp_spiram_init(); + #endif + + #ifdef HAS_C5_SD + Serial.println("Starting shared SPI for C5 SD configuration..."); + sharedSPI.begin(SD_SCK, SD_MISO, SD_MOSI); + delay(100); + #endif #ifdef defined(MARAUDER_M5STICKC) && !defined(MARAUDER_M5STICKCP2) axp192_obj.begin(); @@ -175,7 +188,7 @@ void setup() digitalWrite(TFT_CS, HIGH); #endif - #ifdef HAS_SD + #if defined(HAS_SD) && !defined(HAS_C5_SD) pinMode(SD_CS, OUTPUT); delay(10); @@ -207,17 +220,6 @@ void setup() backlightOff(); - // Draw the title screen - /* - #ifdef HAS_SCREEN - #ifndef MARAUDER_MINI - display_obj.drawJpeg("/marauder3L.jpg", 0 , 0); // 240 x 320 image - #else - display_obj.drawJpeg("/marauder3L.jpg", 0, 0); - #endif - #endif - */ - #ifdef HAS_SCREEN display_obj.tft.drawCentreString("ESP32 Marauder", TFT_WIDTH/2, TFT_HEIGHT * 0.33, 1); display_obj.tft.drawCentreString("JustCallMeKoko", TFT_WIDTH/2, TFT_HEIGHT * 0.5, 1); @@ -256,12 +258,6 @@ void setup() settings_obj.begin(); - wifi_scan_obj.RunSetup(); - - //#ifdef HAS_SCREEN - // display_obj.tft.println(F(text_table0[2])); - //#endif - buffer_obj = Buffer(); #if defined(HAS_SD) // Do some SD stuff @@ -270,6 +266,8 @@ void setup() #endif + wifi_scan_obj.RunSetup(); + #ifdef HAS_SCREEN display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK); display_obj.tft.drawCentreString("Initializing...", TFT_WIDTH/2, TFT_HEIGHT * 0.82, 1); @@ -280,14 +278,6 @@ void setup() #ifdef HAS_BATTERY battery_obj.RunSetup(); #endif - - #ifdef HAS_SCREEN - //display_obj.tft.println(F(text_table0[5])); - #endif - - #ifdef HAS_SCREEN - //display_obj.tft.println(F(text_table0[6])); - #endif #ifdef HAS_BATTERY battery_obj.battery_level = battery_obj.getBatteryLevel(); @@ -304,28 +294,12 @@ void setup() led_obj.RunSetup(); #endif - #ifdef HAS_SCREEN - //display_obj.tft.println(F(text_table0[7])); - - //delay(500); - #endif - #ifdef HAS_GPS gps_obj.begin(); - //#ifdef HAS_SCREEN - //if (gps_obj.getGpsModuleStatus()) - //display_obj.tft.println("GPS Module connected"); - //else - //display_obj.tft.println("GPS Module NOT connected"); - //#endif #endif - #ifdef HAS_SCREEN - //display_obj.tft.println(F(text_table0[8])); - + #ifdef HAS_SCREEN display_obj.tft.setTextColor(TFT_WHITE, TFT_BLACK); - - //delay(2000); #endif #ifdef HAS_SCREEN