RP2040 Support
This commit is contained in:
parent
ef4e77edd5
commit
8db0a6e881
|
@ -26,3 +26,4 @@ Compile and export:
|
|||
|
||||
Convert to uf2:
|
||||
`uf2conv build/USBNova.ino.bin -o build/USBNova.ino.uf2`
|
||||
(To install uf2conv, install rust, then `cargo install uf2conv`)
|
13
USBNova.ino
13
USBNova.ino
|
@ -18,7 +18,7 @@ void update() {
|
|||
}
|
||||
|
||||
void setup() {
|
||||
// Start Serial (for debug)
|
||||
// Start Serial (for debug) or disable it
|
||||
debug_init();
|
||||
|
||||
// Initialize memory and check for problems
|
||||
|
@ -37,7 +37,7 @@ void setup() {
|
|||
selector::init();
|
||||
|
||||
// Start Keyboard
|
||||
if (selector::mode() == ATTACK || preferences::hidEnabled()) {
|
||||
if ((selector::mode() == ATTACK) || preferences::hidEnabled()) {
|
||||
hid::init();
|
||||
}
|
||||
|
||||
|
@ -85,20 +85,22 @@ void setup() {
|
|||
selector::changed();
|
||||
|
||||
// Start attack
|
||||
if (selector::mode() == ATTACK && !preferences::getRunOnIndicator()) {
|
||||
if ((selector::mode() == ATTACK) && !preferences::getRunOnIndicator()) {
|
||||
delay(preferences::getInitialDelay()); // Wait to give computer time to init keyboard
|
||||
attack::start(); // Start keystroke injection attack
|
||||
led::setColor(preferences::getIdleColor()); // Set LED to green
|
||||
}
|
||||
|
||||
// Setup CLI
|
||||
#ifdef ENABLE_DEBUG
|
||||
cli::init();
|
||||
#endif // ifdef ENABLE_DEBUG
|
||||
|
||||
debugln("[Started]");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
taks:update();
|
||||
tasks::update();
|
||||
cli::update();
|
||||
|
||||
if (selector::read() != ATTACK) return;
|
||||
|
@ -110,7 +112,7 @@ void loop() {
|
|||
led::setColor(preferences::getIdleColor()); // Set LED to green
|
||||
} else if (selector::changed()) {
|
||||
// ========== Setup Mode ========== //
|
||||
if (selector::mode() == SETUP && preferences::hidEnabled()) {
|
||||
if ((selector::mode() == SETUP) && preferences::hidEnabled()) {
|
||||
preferences::load(); // Reload the settings (in case the main script path changed)
|
||||
|
||||
// Attack settings
|
||||
|
@ -120,7 +122,6 @@ void loop() {
|
|||
attack::start(); // Start keystroke injection attack
|
||||
led::setColor(preferences::getSetupColor()); // Set LED to blue
|
||||
}
|
||||
|
||||
// ========== Attack Mode ========== //
|
||||
else if (selector::mode() == ATTACK) {
|
||||
// Only start the attack if run-on-indicator is disabled, or indicator actually changed
|
||||
|
|
12
config.h
12
config.h
|
@ -2,7 +2,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#define VERSION "1.1.2"
|
||||
#define VERSION "1.1.3"
|
||||
|
||||
// ===== DEBUG Settings ===== //
|
||||
// #define ENABLE_DEBUG
|
||||
|
@ -13,10 +13,20 @@
|
|||
#define READ_BUFFER 2048
|
||||
|
||||
// ===== LED Settings ===== //
|
||||
|
||||
#if defined(ARDUINO_ARCH_RP2040)
|
||||
#define LED_PIN 12
|
||||
#else // if defined(ARDUINO_ARCH_RP2040)
|
||||
#define LED_PIN 11
|
||||
#endif // if defined(ARDUINO_ARCH_RP2040)
|
||||
|
||||
// ===== SELECTOR SWITCH ===== //
|
||||
|
||||
#if defined(ARDUINO_ARCH_RP2040)
|
||||
#define SELECTOR 13
|
||||
#else // if defined(ARDUINO_ARCH_RP2040)
|
||||
#define SELECTOR A0
|
||||
#endif // if defined(ARDUINO_ARCH_RP2040)
|
||||
|
||||
// ===== Parser Settings ===== //
|
||||
#define CASE_SENSETIVE false
|
||||
|
|
1
debug.h
1
debug.h
|
@ -3,6 +3,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "config.h"
|
||||
|
||||
#ifdef ENABLE_DEBUG
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "../attack/attack.h"
|
||||
#include "../msc/msc.h"
|
||||
#include "../../config.h"
|
||||
#include "../../debug.h"
|
||||
|
||||
#define BUFFER_SIZE 1024
|
||||
|
||||
|
@ -59,38 +60,38 @@ namespace cli {
|
|||
|
||||
// ====== PUBLIC ====== //
|
||||
void init() {
|
||||
Serial.begin(115200);
|
||||
// Serial.begin(115200);
|
||||
|
||||
// error
|
||||
cli.setOnError([](cmd_error* e) {
|
||||
CommandError cmdError(e);
|
||||
|
||||
Serial.print("ERROR: ");
|
||||
Serial.println(cmdError.toString());
|
||||
debugF("ERROR: ");
|
||||
debugln(cmdError.toString());
|
||||
|
||||
if (cmdError.hasCommand()) {
|
||||
Serial.print("Did you mean \"");
|
||||
Serial.print(cmdError.getCommand().toString());
|
||||
Serial.println("\"?");
|
||||
debugF("Did you mean \"");
|
||||
debug(cmdError.getCommand().toString());
|
||||
debuglnF("\"?");
|
||||
}
|
||||
});
|
||||
|
||||
// help
|
||||
cli.addCmd("help", [](cmd* c) {
|
||||
Serial.println("[ = Available Commands =]");
|
||||
Serial.print(cli.toString());
|
||||
Serial.println("Enter any BadUSB Scripts to run it.");
|
||||
Serial.println();
|
||||
debuglnF("[ = Available Commands =]");
|
||||
debug(cli.toString());
|
||||
debuglnF("Enter any BadUSB Scripts to run it.");
|
||||
debugln();
|
||||
}).setDescription(" Get a list of available commands.");
|
||||
|
||||
// version
|
||||
cli.addCmd("version", [](cmd* c) {
|
||||
Serial.println("[ = USB Nova =]");
|
||||
Serial.print("Version ");
|
||||
Serial.println(VERSION);
|
||||
Serial.println("Source: https://github.com/spacehuhntech/usbnova");
|
||||
Serial.println("Made with <3 by Spacehuhn (spacehuhn.com)");
|
||||
Serial.println();
|
||||
debuglnF("[ = USB Nova =]");
|
||||
debugF("Version ");
|
||||
debugln(VERSION);
|
||||
debuglnF("Source: https://github.com/spacehuhntech/usbnova");
|
||||
debuglnF("Made with <3 by Spacehuhn (spacehuhn.com)");
|
||||
debugln();
|
||||
}).setDescription(" Print the firmware version.");
|
||||
|
||||
// format
|
||||
|
@ -104,8 +105,8 @@ namespace cli {
|
|||
led::setColor(preferences::getIdleColor());
|
||||
}
|
||||
|
||||
Serial.println("Done formatting!");
|
||||
Serial.println();
|
||||
debuglnF("Done formatting!");
|
||||
debugln();
|
||||
}).setDescription(" Fromat the internal memory.");
|
||||
|
||||
// reset
|
||||
|
@ -113,8 +114,8 @@ namespace cli {
|
|||
preferences::reset();
|
||||
preferences::save();
|
||||
|
||||
Serial.println("Done resetting!");
|
||||
Serial.println();
|
||||
debuglnF("Done resetting!");
|
||||
debugln();
|
||||
}).setDescription(" Reset the preferences.");
|
||||
|
||||
// TODO: preferences
|
||||
|
|
|
@ -2,14 +2,16 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "../../config.h"
|
||||
|
||||
#include <cstdint> // uint8_t
|
||||
|
||||
namespace hid {
|
||||
// Report ID
|
||||
enum RID {
|
||||
KEYBOARD = 0,
|
||||
MOUSE = 1,
|
||||
CONSUMER_CONTROL = 2, // Media, volume etc ..
|
||||
KEYBOARD = 1,
|
||||
MOUSE = 2,
|
||||
CONSUMER_CONTROL = 3, // Media, volume etc ..
|
||||
};
|
||||
|
||||
void init();
|
||||
|
|
|
@ -19,7 +19,16 @@
|
|||
|
||||
namespace format {
|
||||
// ========== PRIVATE ========= //
|
||||
#if defined(ARDUINO_ARCH_RP2040)
|
||||
// RP2040 use same flash device that store code for file system. Therefore we
|
||||
// only need to specify start address and size (no need SPI or SS)
|
||||
// By default (start=0, size=0), values that match file system setting in
|
||||
// 'Tools->Flash Size' menu selection will be used.
|
||||
Adafruit_FlashTransport_RP2040 flashTransport;
|
||||
#else // if defined(ARDUINO_ARCH_RP2040)
|
||||
Adafruit_FlashTransport_SPI flashTransport(EXTERNAL_FLASH_USE_CS, EXTERNAL_FLASH_USE_SPI);
|
||||
#endif // if defined(ARDUINO_ARCH_RP2040)
|
||||
|
||||
Adafruit_SPIFlash flash(&flashTransport);
|
||||
|
||||
// file system object from SdFat
|
||||
|
|
|
@ -23,7 +23,16 @@ namespace msc {
|
|||
|
||||
std::stack<file_element_t> file_stack;
|
||||
|
||||
#if defined(ARDUINO_ARCH_RP2040)
|
||||
// RP2040 use same flash device that store code for file system. Therefore we
|
||||
// only need to specify start address and size (no need SPI or SS)
|
||||
// By default (start=0, size=0), values that match file system setting in
|
||||
// 'Tools->Flash Size' menu selection will be used.
|
||||
Adafruit_FlashTransport_RP2040 flashTransport;
|
||||
#else // if defined(ARDUINO_ARCH_RP2040)
|
||||
Adafruit_FlashTransport_SPI flashTransport(EXTERNAL_FLASH_USE_CS, EXTERNAL_FLASH_USE_SPI);
|
||||
#endif // if defined(ARDUINO_ARCH_RP2040)
|
||||
|
||||
Adafruit_SPIFlash flash(&flashTransport);
|
||||
Adafruit_USBD_MSC usb_msc;
|
||||
|
||||
|
@ -92,10 +101,11 @@ namespace msc {
|
|||
}
|
||||
|
||||
void print() {
|
||||
Serial.println("Available files:");
|
||||
debuglnF("Available files:");
|
||||
|
||||
// Close file(s)
|
||||
if (file.isOpen()) file.close();
|
||||
|
||||
while (!file_stack.empty()) file_stack.pop();
|
||||
|
||||
SdFile root;
|
||||
|
@ -103,13 +113,13 @@ namespace msc {
|
|||
|
||||
while (file.openNext(&root, O_RDONLY)) {
|
||||
file.printFileSize(&Serial);
|
||||
Serial.write(' ');
|
||||
debugF(" ");
|
||||
file.printName(&Serial);
|
||||
if (file.isDir()) {
|
||||
// Indicate a directory.
|
||||
Serial.write('/');
|
||||
debugF("/");
|
||||
}
|
||||
Serial.println();
|
||||
debugln();
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
@ -261,6 +271,7 @@ namespace msc {
|
|||
|
||||
size_t write(const char* path, const char* buffer, size_t len) {
|
||||
FatFile wfile;
|
||||
|
||||
wfile.open(path, (O_RDWR | O_CREAT));
|
||||
if (!wfile.isOpen()) return 0;
|
||||
|
||||
|
|
Loading…
Reference in New Issue