A Hardware Hacking Tool with Web-Based CLI That Speaks Every Protocol
C arduinobluetoothcan-busdebuggingeepromesp32flipperzerogpiohardware-hackingi2cjtagopenocdprotocolspwmradiorfidspisubghzuartwifi
add sd card support for spi
Geofa28cad53f60
diff --git a/platformio.ini b/platformio.iniindex e9b3db61..c32e2291 100644--- a/platformio.ini+++ b/platformio.ini@@ -100,10 +100,10 @@ build_flags =-DI2C_FREQ=100000; --- SPI ---- -DSPI_CS_PIN=26- -DSPI_CLK_PIN=25- -DSPI_MISO_PIN=32- -DSPI_MOSI_PIN=33+ -DSPI_CS_PIN=33+ -DSPI_CLK_PIN=0+ -DSPI_MISO_PIN=25+ -DSPI_MOSI_PIN=26; --- Infrared ----DIR_TX_PIN=19diff --git a/src/Controllers/SpiController.cpp b/src/Controllers/SpiController.cppindex 6cc28c7e..d598c59a 100644--- a/src/Controllers/SpiController.cpp+++ b/src/Controllers/SpiController.cpp@@ -1,9 +1,9 @@#include "SpiController.h"SpiController::SpiController(ITerminalView& terminalView, IInput& terminalInput,- SpiService& service, ArgTransformer& argTransformer,+ SpiService& spiService, SdService& sdService, ArgTransformer& argTransformer,UserInputManager& userInputManager)- : terminalView(terminalView), terminalInput(terminalInput), spiService(service), argTransformer(argTransformer), userInputManager(userInputManager) {}+ : terminalView(terminalView), terminalInput(terminalInput), spiService(spiService), sdService(sdService), argTransformer(argTransformer), userInputManager(userInputManager) {}/*Entry point for command@@ -14,6 +14,10 @@ void SpiController::handleCommand(const TerminalCommand& cmd) {handleSniff();}+ else if(cmd.getRoot() == "sdcard") {+ handleSdCard();+ }+else if (cmd.getRoot() == "flash") {if (cmd.getSubcommand() == "probe") {handleFlashProbe();@@ -21,6 +25,8 @@ void SpiController::handleCommand(const TerminalCommand& cmd) {handleFlashRead(cmd);} else if (cmd.getSubcommand() == "write") {handleFlashWrite(cmd);+ } else if (cmd.getRoot() == "sdcard") {+ handleSdCard();} else if (cmd.getSubcommand() == "erase") {handleFlashErase(cmd);} else {@@ -148,6 +154,9 @@ void SpiController::handleFlashRead(const TerminalCommand& cmd) {terminalView.println("");}+/*+Flash Read In Chunks+*/void SpiController::readFlashInChunks(uint32_t address, uint32_t length) {uint8_t buffer[1024];uint32_t remaining = length;@@ -341,6 +350,47 @@ void SpiController::handleHelp() {terminalView.println("");}+/*+SD Card+*/+void SpiController::handleSdCard() {++ terminalView.println("SD Card: Mounting...");+ delay(500); // let the user see this ^++ bool success = sdService.configure(+ state.getSpiCLKPin(),+ state.getSpiMISOPin(),+ state.getSpiMOSIPin(),+ state.getSpiCSPin()+ );++ if (!success) {+ terminalView.println("SD Card: Mount failed. Check config and wiring and try again.\n");+ return;+ }++ terminalView.println("SD Card: Mounted successfully.\n");++ // Root content+ auto elements = sdService.listElements("/");+ if (elements.empty()) {+ terminalView.println("[Root is empty]");+ } else {+ terminalView.println("Root content:");+ for (const auto& item : elements) {+ terminalView.println(" - " + item);+ }+ }++ terminalView.println("");+ terminalView.println(" [INFO] SD card interface is not yet fully implemented.");+ terminalView.println(" You can use the USB Stick mode to mount the card");+ terminalView.println(" as a USB drive and access it from your computer.\n");++ sdService.close();+}+/*Config*/diff --git a/src/Controllers/SpiController.h b/src/Controllers/SpiController.hindex f52b7483..4b24489d 100644--- a/src/Controllers/SpiController.h+++ b/src/Controllers/SpiController.h@@ -5,6 +5,7 @@#include <vector>#include "Interfaces/ITerminalView.h"#include "Services/SpiService.h"+#include "Services/SdService.h"#include "Interfaces/IInput.h"#include "Models/TerminalCommand.h"#include "Models/ByteCode.h"@@ -16,7 +17,7 @@class SpiController {public:// Constructor- SpiController(ITerminalView& terminalView, IInput& terminalInput, SpiService& service, ArgTransformer& argTransformer, UserInputManager& userInputManager);+ SpiController(ITerminalView& terminalView, IInput& terminalInput, SpiService& spiService, SdService& sdService, ArgTransformer& argTransformer, UserInputManager& userInputManager);// Entry point for handle raw user commandvoid handleCommand(const TerminalCommand& cmd);@@ -31,6 +32,7 @@ private:ITerminalView& terminalView;IInput& terminalInput;SpiService& spiService;+ SdService& sdService;ArgTransformer& argTransformer;UserInputManager& userInputManager;GlobalState& state = GlobalState::getInstance();@@ -52,6 +54,9 @@ private:// Erase flash memoryvoid handleFlashErase(const TerminalCommand& cmd);+ // SD operations+ void handleSdCard();+// Configure SPI bus parametersvoid handleConfig();diff --git a/src/Providers/DependencyProvider.cpp b/src/Providers/DependencyProvider.cppindex b5a9d878..db768878 100644--- a/src/Providers/DependencyProvider.cpp+++ b/src/Providers/DependencyProvider.cpp@@ -34,7 +34,7 @@ DependencyProvider::DependencyProvider(ITerminalView& terminalView, IDeviceView&infraredController(terminalView, terminalInput, infraredService, argTransformer, userInputManager),utilityController(terminalView, terminalInput, pinService, userInputManager),hdUartController(terminalView, terminalInput, deviceInput, hdUartService, uartService, argTransformer, userInputManager),- spiController(terminalView, terminalInput, spiService, argTransformer, userInputManager),+ spiController(terminalView, terminalInput, spiService, sdService, argTransformer, userInputManager),jtagController(terminalView, terminalInput),twoWireController(terminalView, terminalInput),threeWireController(terminalView, terminalInput),