How salim-mrw/usb-rubber works
Project Type and Purpose
• This is an Arduino “library” (open-source tool) that wraps the native Arduino Keyboard/HID API.
• Purpose: expose simple functions (begin, print, press, end) to send USB keyboard HID reports from ATmega32u4-based boards to a host computer.
File Structure
• Top‐level files: LICENSE, README.md, library.properties (defines library metadata for Arduino IDE), keywords.txt (for syntax highlighting).
• examples/: Contains a single example (“open_POWERSHELL.ino”) showing how user code invokes the library.
• src/: Contains usbrubber.cpp/h – core implementation of the usbrubber class.
Pull Insights from README
• Target hardware: Arduino Leonardo, Micro, Nano (ATmega32u4).
• Dependency: Arduino core’s Keyboard.h (native USB HID driver).
• Core functionality: initialize HID, send text, press single keys, terminate HID session.
a. Hardware
• ATmega32u4-based Arduino board (Leonardo, Micro or Nano).
• USB physical connection to host.
b. Firmware Software Layers
• User Sketch (example .ino)
• usbrubber Library (src/usbrubber.cpp/h)
• Arduino HID Core (Keyboard.h, built into Arduino framework)
c. Host System
• USB HID Driver (OS kernel component)
• User shell/application (e.g., PowerShell on Windows)
Relationships & Data Flow
• User Sketch calls usbrubber.begin() → usbrubber wraps Keyboard.begin()
• Sketch calls usbrubber.print()/press() → usbrubber constructs HID reports → Keyboard.sendReport()
• USB controller on ATmega32u4 sends HID packets to Host
• OS HID Driver on the host interprets packets as keystrokes → routes to active application (PowerShell, text editor, etc.)
• usbrubber.end() calls Keyboard.end() to release HID interface
Architectural Patterns & Design Principles
• Facade/Wrapper Pattern: usbrubber abstracts the complexity of raw HID calls behind simple methods.
• Layered Architecture: clear separation between
• Application layer (user sketch)
• Library layer (usbrubber API)
• Framework layer (Arduino core)
• Hardware layer (USB controller & MCU)
• Host layer (OS HID stack)
Relevant Technologies & Frameworks
• C++ (Arduino flavor)
• Arduino IDE build system (via library.properties)
• ATmega32u4 USB-HID peripheral
• OS USB HID drivers (Windows, macOS, Linux)