mirror of
https://github.com/cecio/USBvalve.git
synced 2025-12-06 03:41:45 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c1618bc201 | ||
|
|
d756e20eb4 | ||
|
|
1387103199 | ||
|
|
f4e9ed918b | ||
|
|
c551015cd7 | ||
|
|
08e047811a | ||
|
|
113158f9ad | ||
|
|
251db8f30d |
@@ -1,9 +1,9 @@
|
||||
#
|
||||
# To Build:
|
||||
# docker build -t usbvalve/arduino-cli .
|
||||
# docker build -t usbvalve-pico1/arduino-cli -f Dockerfile.pico1 .
|
||||
#
|
||||
# To Run:
|
||||
# docker run --rm --name usbvalve -v $PWD:/mnt usbvalve/arduino-cli /mnt/USBvalve
|
||||
# docker run --rm --name usbvalve -v $PWD:/mnt usbvalve-pico1/arduino-cli /mnt/USBvalve
|
||||
#
|
||||
|
||||
FROM ubuntu:22.04
|
||||
@@ -23,17 +23,17 @@ RUN cd /app \
|
||||
&& ./install.sh \
|
||||
&& export PATH=$PATH:/app/arduino-cli/bin \
|
||||
&& arduino-cli --additional-urls https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json core search 2040 \
|
||||
&& arduino-cli --additional-urls https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json core install rp2040:rp2040 \
|
||||
&& arduino-cli lib install "Adafruit TinyUSB Library@3.3.3" \
|
||||
&& arduino-cli lib install "Adafruit SSD1306@2.5.11" \
|
||||
&& arduino-cli --additional-urls https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json core install rp2040:rp2040@4.4.2 \
|
||||
&& arduino-cli lib install "Adafruit TinyUSB Library@3.4.2" \
|
||||
&& arduino-cli lib install "Adafruit SSD1306@2.5.13" \
|
||||
&& arduino-cli lib install "Pico PIO USB@0.6.1" \
|
||||
&& arduino-cli lib install "XxHash_arduino@2.1.0" \
|
||||
&& arduino-cli lib install "GFX Library for Arduino@1.4.7"
|
||||
&& arduino-cli lib install "GFX Library for Arduino@1.5.3"
|
||||
|
||||
# Compilation setup
|
||||
RUN echo "#!/bin/bash" > /app/entrypoint.sh \
|
||||
&& echo "export PATH=\$PATH:/app/arduino-cli/bin" >> /app/entrypoint.sh \
|
||||
&& echo "arduino-cli compile --fqbn rp2040:rp2040:rpipico --board-options \"usbstack=tinyusb\" --board-options \"freq=120\" --output-dir \"/mnt/USBvalve_out\" \"\$1\"" >> /app/entrypoint.sh \
|
||||
&& echo "arduino-cli compile --fqbn rp2040:rp2040:rpipico --build-property \"build.extra_flags=-DCFG_TUD_CDC=1\" --board-options \"usbstack=tinyusb\" --board-options \"freq=240\" --output-dir \"/mnt/USBvalve_out\" \"\$1\"" >> /app/entrypoint.sh \
|
||||
&& chmod +x /app/entrypoint.sh
|
||||
|
||||
ENTRYPOINT ["/app/entrypoint.sh"]
|
||||
39
Dockerfile.pico2
Normal file
39
Dockerfile.pico2
Normal file
@@ -0,0 +1,39 @@
|
||||
#
|
||||
# To Build:
|
||||
# docker build -t usbvalve-pico2/arduino-cli -f Dockerfile.pico2 .
|
||||
#
|
||||
# To Run:
|
||||
# docker run --rm --name usbvalve -v $PWD:/mnt usbvalve-pico2/arduino-cli /mnt/USBvalve
|
||||
#
|
||||
|
||||
FROM ubuntu:22.04
|
||||
WORKDIR /app
|
||||
|
||||
# OS setup
|
||||
RUN apt-get update -y \
|
||||
&& apt-get install -y git wget python3 \
|
||||
&& apt-get autoremove -y \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||
|
||||
# arduino-cli setup
|
||||
RUN cd /app \
|
||||
&& git clone --recursive https://github.com/arduino/arduino-cli.git \
|
||||
&& cd arduino-cli \
|
||||
&& ./install.sh \
|
||||
&& export PATH=$PATH:/app/arduino-cli/bin \
|
||||
&& arduino-cli --additional-urls https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json core search 2040 \
|
||||
&& arduino-cli --additional-urls https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json core install rp2040:rp2040@4.4.2 \
|
||||
&& arduino-cli lib install "Adafruit TinyUSB Library@3.4.2" \
|
||||
&& arduino-cli lib install "Adafruit SSD1306@2.5.13" \
|
||||
&& arduino-cli lib install "Pico PIO USB@0.6.1" \
|
||||
&& arduino-cli lib install "XxHash_arduino@2.1.0" \
|
||||
&& arduino-cli lib install "GFX Library for Arduino@1.5.3"
|
||||
|
||||
# Compilation setup
|
||||
RUN echo "#!/bin/bash" > /app/entrypoint.sh \
|
||||
&& echo "export PATH=\$PATH:/app/arduino-cli/bin" >> /app/entrypoint.sh \
|
||||
&& echo "arduino-cli compile --fqbn rp2040:rp2040:rpipico2 --build-property \"build.extra_flags=-DCFG_TUD_CDC=1\" --board-options \"usbstack=tinyusb\" --board-options \"freq=240\" --output-dir \"/mnt/USBvalve_out\" \"\$1\"" >> /app/entrypoint.sh \
|
||||
&& chmod +x /app/entrypoint.sh
|
||||
|
||||
ENTRYPOINT ["/app/entrypoint.sh"]
|
||||
20
README.md
20
README.md
@@ -60,14 +60,14 @@ This is also fully compatible with the [Waveshare RP2040-LCD-1.28](https://www.w
|
||||
|
||||
If you want to build your own, you need:
|
||||
|
||||
- A Raspberry Pi Pico (or another RP2040 based board, like Arduino Nano RP2040)
|
||||
- A Raspberry Pi Pico 1 or 2 (or another RP2040 based board, like Arduino Nano RP2040)
|
||||
- an I2C OLED screen 128x64 or 128x32 (SSD1306)
|
||||
- (optional) a **USBvalve** PCB or a breadboard
|
||||
- (optional) a 3D printed spacer to isolate the screen from the board (https://www.thingiverse.com/thing:4748043), but you can use a piece of electrical tape instead
|
||||
|
||||
### Building instructions
|
||||
|
||||
> Thanks to [Tz1rf](https://github.com/Tz1rf) we have a great [Video](https://youtu.be/7ymk8hD7-Hc) explaining the building process step-by-step.
|
||||
> Thanks to [Tz1rf](https://github.com/Tz1rf) we also have two great videos: one explaining the [building](https://youtu.be/7ymk8hD7-Hc) process step-by-step, and another showing how to [upload firmware](https://youtu.be/Tp8xvrlqxUY) and use the tool.
|
||||
|
||||
Almost all the job is done directly on the board by the software, so you just need to arrange the connection with the OLED for output.
|
||||
|
||||
@@ -195,21 +195,23 @@ I grouped most of the variables you may want to modify in this section ([see Doc
|
||||
|
||||
Obviously you can also build your own firmware. To build the *standard* one I used:
|
||||
|
||||
- Arduino IDE `2.3.2`
|
||||
- `Adafruit TinyUSB Library` version `3.3.3`, `Pico-PIO-USB` version `0.6.1`, Board `Raspberry Pi RP2040 (4.0.1)` setting Tools=>CPU Speed at `120MHz` and Tools=>USB Stack to `Adafruit TinyUSB`
|
||||
- `Adafruit_SSD1306` OLED library version `2.5.11`
|
||||
- Arduino IDE `2.3.4`
|
||||
- `Adafruit TinyUSB Library` version `3.4.2`, `Pico-PIO-USB` version `0.6.1`, Board `Raspberry Pi RP2040 (4.4.0)` setting Tools=>CPU Speed at `133MHz` and Tools=>USB Stack to `Adafruit TinyUSB`
|
||||
- `Adafruit_SSD1306` OLED library version `2.5.13`
|
||||
|
||||
Remember to add `https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json` in the `Additional Board Manager URLs` to install the proper board.
|
||||
Remember to add `https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json` in the `Additional Board Manager URLs` to install the proper board. Also, starting from `TinyUSB` version `3.4.2` is necessary to force the following macro setting `DCFG_TUD_CDC=1`. I strongly suggest you to use the provided *Dockerfiles* (see below).
|
||||
|
||||
If you want to re-create a new fake filesystem, you may want to have a look to the `utils` folder, where I placed some utilities to build a new one.
|
||||
|
||||
#### Dockerfile
|
||||
|
||||
If you want to build your own firmware, after you customized it, I provide a `Dockerfile` which builds a complete **Arduino** environment and compile the firmware. Enter the following commands in the main `USBvalve` folder:
|
||||
If you want to build your own firmware, after you customized it, I provide a `Dockerfile` which builds a complete **Arduino** environment and compile the firmware. I added them for both `Pico` version 1 and 2.
|
||||
|
||||
Enter the following commands in the main `USBvalve` folder to build for Pico `v1`:
|
||||
|
||||
```
|
||||
docker build -t usbvalve/arduino-cli .
|
||||
docker run --rm --name usbvalve -v $PWD:/mnt usbvalve/arduino-cli /mnt/USBvalve
|
||||
docker build -t usbvalve-pico1/arduino-cli -f Dockerfile.pico1 .
|
||||
docker run --rm --name usbvalve -v $PWD:/mnt usbvalve-pico1/arduino-cli /mnt/USBvalve
|
||||
```
|
||||
|
||||
The firmware will be placed with extension `uf2` in folder `USBvalve_out`.
|
||||
|
||||
@@ -116,7 +116,7 @@ bool activeState = false;
|
||||
//
|
||||
// USBvalve globals
|
||||
//
|
||||
#define VERSION "USBvalve - 0.19.0"
|
||||
#define VERSION "USBvalve - 0.21.0"
|
||||
boolean readme = false;
|
||||
boolean autorun = false;
|
||||
boolean written = false;
|
||||
@@ -125,6 +125,9 @@ boolean written_reported = false;
|
||||
boolean deleted_reported = false;
|
||||
boolean hid_sent = false;
|
||||
boolean hid_reported = false;
|
||||
uint hid_event_num = 0;
|
||||
|
||||
static spin_lock_t *lock;
|
||||
|
||||
//
|
||||
// Anti-Detection settings.
|
||||
@@ -159,6 +162,9 @@ uint valid_hash = 2362816530;
|
||||
|
||||
// Core 0 Setup: will be used for the USB mass device functions
|
||||
void setup() {
|
||||
// Initialize the spinlock
|
||||
lock = spin_lock_instance(0);
|
||||
|
||||
// Change all the USB Pico settings
|
||||
TinyUSBDevice.setID(USB_VENDORID, USB_PRODUCTID);
|
||||
TinyUSBDevice.setProductDescriptor(USB_DESCRIPTOR);
|
||||
@@ -247,7 +253,12 @@ void setup() {
|
||||
// Core 1 Setup: will be used for the USB host functions for BADUSB detector
|
||||
void setup1() {
|
||||
// Set a custom clock (multiple of 12Mhz) to achieve maximum compatibility for HID
|
||||
// Differntiated between Pico 1 and Pico 2
|
||||
#ifdef PICO_RP2350
|
||||
set_sys_clock_khz(144000, true);
|
||||
#elif defined PICO_RP2040
|
||||
set_sys_clock_khz(240000, true);
|
||||
#endif
|
||||
|
||||
pio_usb_configuration_t pio_cfg = PIO_USB_DEFAULT_CONFIG;
|
||||
pio_cfg.pin_dp = HOST_PIN_DP;
|
||||
@@ -303,8 +314,22 @@ void loop() {
|
||||
}
|
||||
|
||||
if (BOOTSEL) {
|
||||
printout("\n[+] RESETTING");
|
||||
swreset();
|
||||
uint32_t press_start = to_ms_since_boot(get_absolute_time());
|
||||
while (BOOTSEL) {
|
||||
sleep_ms(10);
|
||||
}
|
||||
uint32_t press_end = to_ms_since_boot(get_absolute_time());
|
||||
uint32_t press_duration = press_end - press_start;
|
||||
|
||||
if (press_duration > 2000) { // Press duration > 2sec
|
||||
// Print the number of HID events detected so far
|
||||
char outstr[22];
|
||||
snprintf(outstr, 21, "\n[+] HID Evt# %d", hid_event_num);
|
||||
printout(outstr);
|
||||
} else {
|
||||
printout("\n[+] RESETTING");
|
||||
swreset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -537,6 +562,9 @@ static uint8_t const keycode2ascii[128][2] = { HID_KEYCODE_TO_ASCII };
|
||||
|
||||
// Invoked when device with hid interface is mounted
|
||||
void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* desc_report, uint16_t desc_len) {
|
||||
|
||||
uint32_t lock_num = spin_lock_blocking(lock);
|
||||
|
||||
uint16_t vid, pid;
|
||||
const char* protocol_str[] = { "None", "Keyboard", "Mouse" };
|
||||
|
||||
@@ -557,20 +585,27 @@ void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* desc_re
|
||||
if (!tuh_hid_receive_report(dev_addr, instance)) {
|
||||
SerialTinyUSB.printf("Error: cannot request to receive report\r\n");
|
||||
}
|
||||
|
||||
spin_unlock(lock, lock_num);
|
||||
}
|
||||
|
||||
// Invoked when device with hid interface is un-mounted
|
||||
void tuh_hid_umount_cb(uint8_t dev_addr, uint8_t instance) {
|
||||
uint32_t lock_num = spin_lock_blocking(lock);
|
||||
SerialTinyUSB.printf("HID device address = %d, instance = %d unmounted\r\n", dev_addr, instance);
|
||||
|
||||
// Reset HID sent flag
|
||||
hid_sent = false;
|
||||
hid_reported = false;
|
||||
hid_event_num = 0;
|
||||
spin_unlock(lock, lock_num);
|
||||
}
|
||||
|
||||
// Invoked when received report from device
|
||||
void tuh_hid_report_received_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len) {
|
||||
|
||||
uint32_t lock_num = spin_lock_blocking(lock);
|
||||
|
||||
static bool kbd_printed = false;
|
||||
static bool mouse_printed = false;
|
||||
|
||||
@@ -588,6 +623,7 @@ void tuh_hid_report_received_cb(uint8_t dev_addr, uint8_t instance, uint8_t cons
|
||||
mouse_printed = false;
|
||||
}
|
||||
process_kbd_report((hid_keyboard_report_t const*)report);
|
||||
hid_event_num++;
|
||||
break;
|
||||
|
||||
case HID_ITF_PROTOCOL_MOUSE:
|
||||
@@ -597,17 +633,21 @@ void tuh_hid_report_received_cb(uint8_t dev_addr, uint8_t instance, uint8_t cons
|
||||
kbd_printed = false;
|
||||
}
|
||||
process_mouse_report((hid_mouse_report_t const*)report);
|
||||
hid_event_num++;
|
||||
break;
|
||||
|
||||
default:
|
||||
// Generic report: for the time being we use kbd for this as well
|
||||
process_kbd_report((hid_keyboard_report_t const*)report);
|
||||
hid_event_num++;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!tuh_hid_receive_report(dev_addr, instance)) {
|
||||
SerialTinyUSB.println("Error: cannot request to receive report");
|
||||
}
|
||||
|
||||
spin_unlock(lock, lock_num);
|
||||
}
|
||||
|
||||
static inline bool find_key_in_report(hid_keyboard_report_t const* report, uint8_t keycode) {
|
||||
@@ -727,24 +767,32 @@ void cursor_movement(int8_t x, int8_t y, int8_t wheel) {
|
||||
|
||||
// Invoked when a device with MassStorage interface is mounted
|
||||
void tuh_msc_mount_cb(uint8_t dev_addr) {
|
||||
uint32_t lock_num = spin_lock_blocking(lock);
|
||||
printout("\n[++] Mass Device");
|
||||
SerialTinyUSB.printf("Mass Device attached, address = %d\r\n", dev_addr);
|
||||
spin_unlock(lock, lock_num);
|
||||
}
|
||||
|
||||
// Invoked when a device with MassStorage interface is unmounted
|
||||
void tuh_msc_umount_cb(uint8_t dev_addr) {
|
||||
uint32_t lock_num = spin_lock_blocking(lock);
|
||||
SerialTinyUSB.printf("Mass Device unmounted, address = %d\r\n", dev_addr);
|
||||
spin_unlock(lock, lock_num);
|
||||
}
|
||||
|
||||
// Invoked when a device with CDC (Communication Device Class) interface is mounted
|
||||
void tuh_cdc_mount_cb(uint8_t idx) {
|
||||
uint32_t lock_num = spin_lock_blocking(lock);
|
||||
printout("\n[++] CDC Device");
|
||||
SerialTinyUSB.printf("CDC Device attached, idx = %d\r\n", idx);
|
||||
spin_unlock(lock, lock_num);
|
||||
}
|
||||
|
||||
// Invoked when a device with CDC (Communication Device Class) interface is unmounted
|
||||
void tuh_cdc_umount_cb(uint8_t idx) {
|
||||
uint32_t lock_num = spin_lock_blocking(lock);
|
||||
SerialTinyUSB.printf("CDC Device unmounted, idx = %d\r\n", idx);
|
||||
spin_unlock(lock, lock_num);
|
||||
}
|
||||
|
||||
// END of OTHER Host devices detector section
|
||||
|
||||
Binary file not shown.
BIN
firmware/USBvalve-0.21.0-32-pico2.uf2
Normal file
BIN
firmware/USBvalve-0.21.0-32-pico2.uf2
Normal file
Binary file not shown.
Binary file not shown.
BIN
firmware/USBvalve-0.21.0-64-pico2.uf2
Normal file
BIN
firmware/USBvalve-0.21.0-64-pico2.uf2
Normal file
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user