Skip to content

Commit

Permalink
bump to release 0.20.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cecio committed Dec 22, 2024
1 parent 113158f commit 08e0478
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 17 deletions.
14 changes: 7 additions & 7 deletions Dockerfile → Dockerfile.pico1
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 [email protected].0" \
&& arduino-cli lib install "Adafruit [email protected].12" \
&& arduino-cli --additional-urls https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json core install rp2040:rp2040@4.4.0 \
&& arduino-cli lib install "Adafruit TinyUSB [email protected].2" \
&& arduino-cli lib install "Adafruit [email protected].13" \
&& arduino-cli lib install "Pico PIO [email protected]" \
&& arduino-cli lib install "[email protected]" \
&& arduino-cli lib install "GFX Library for Arduino@1.4.9"
&& arduino-cli lib install "GFX Library for Arduino@1.5.0"

# 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=120\" --output-dir \"/mnt/USBvalve_out\" \"\$1\"" >> /app/entrypoint.sh \
&& chmod +x /app/entrypoint.sh

ENTRYPOINT ["/app/entrypoint.sh"]
39 changes: 39 additions & 0 deletions Dockerfile.pico2
Original file line number Diff line number Diff line change
@@ -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:[email protected] \
&& arduino-cli lib install "Adafruit TinyUSB [email protected]" \
&& arduino-cli lib install "Adafruit [email protected]" \
&& arduino-cli lib install "Pico PIO [email protected]" \
&& arduino-cli lib install "[email protected]" \
&& arduino-cli lib install "GFX Library for [email protected]"

# 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=120\" --output-dir \"/mnt/USBvalve_out\" \"\$1\"" >> /app/entrypoint.sh \
&& chmod +x /app/entrypoint.sh

ENTRYPOINT ["/app/entrypoint.sh"]
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ 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
Expand Down Expand Up @@ -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.3`
- `Adafruit TinyUSB Library` version `3.4.0`, `Pico-PIO-USB` version `0.6.1`, Board `Raspberry Pi RP2040 (4.1.1)` setting Tools=>CPU Speed at `133MHz` and Tools=>USB Stack to `Adafruit TinyUSB`
- `Adafruit_SSD1306` OLED library version `2.5.12`
- 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 suggesto 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:
```
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`.
Expand Down
28 changes: 26 additions & 2 deletions USBvalve/USBvalve.ino
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

// Uncomment the following to compile for the RP2040 based TFT round display
// https://www.raspberrypi.com/news/how-to-build-your-own-raspberry-pi-watch/
//#define PIWATCH
#define PIWATCH

#include <pio_usb.h>
#include "Adafruit_TinyUSB.h"
Expand Down Expand Up @@ -116,7 +116,7 @@ bool activeState = false;
//
// USBvalve globals
//
#define VERSION "USBvalve - 0.19.1"
#define VERSION "USBvalve - 0.20.0"
boolean readme = false;
boolean autorun = false;
boolean written = false;
Expand All @@ -126,6 +126,8 @@ boolean deleted_reported = false;
boolean hid_sent = false;
boolean hid_reported = false;

static spin_lock_t *lock;

//
// Anti-Detection settings.
//
Expand Down Expand Up @@ -159,6 +161,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);
Expand Down Expand Up @@ -537,6 +542,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" };

Expand All @@ -557,20 +565,26 @@ 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;
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;

Expand Down Expand Up @@ -608,6 +622,8 @@ void tuh_hid_report_received_cb(uint8_t dev_addr, uint8_t instance, uint8_t cons
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) {
Expand Down Expand Up @@ -727,24 +743,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.
Binary file added firmware/USBvalve-0.20.0-32-pico2.uf2
Binary file not shown.
Binary file not shown.
Binary file added firmware/USBvalve-0.20.0-64-pico2.uf2
Binary file not shown.
Binary file not shown.

0 comments on commit 08e0478

Please sign in to comment.