Skip to main content
Version: FILS English

RustShips v1.0

A two-player Battleship game running on devices having a 4" touchscreen display and wireless peer-to-peer communication.

info

Author: Mîrza Daniel
GitHub Project Link: https://github.com/UPB-PMRust-Students/fils-project-2026-Danum1z

Description

RustShips is a fully embedded, wireless two-player Battleship game. Each player owns a dedicated device consisting of an STM32U545RE Nucleo-64 board connected to a 4" TFT touchscreen (ST7796S, 320×480) with action buttons and a passive buzzer. The two devices communicate wirelessly via NRF24L01+ radio modules over SPI.

Each player places a fleet of 5 ships on a 10×10 grid, then takes turns firing at the opponent's grid. The game tracks two matrices per device: my_fleet (own ships and incoming hits) and enemy_radar (shots fired and confirmed results). A dedicated button toggles between the two views.

The game features three special mechanics, each usable once per game:

  • Sonar Scan: hold the action button for 1.5 seconds to reveal a 3×3 area of the enemy grid for 1 second
  • Airstrike: double-press the action button within a 300 ms window to instantly sink an entire enemy ship
  • Ferris Repair: named after Ferris the Rust mascot — fully repair a damaged ship and move it to a new position

The entire game logic is written as a no_std Rust library (game-core) that compiles for both the real MCU and a desktop simulator built with embedded-graphics-simulator.

Motivation

The choice of this project comes from a long-standing interest in classical strategy games like Battleships and a desire to translate tactile, paper-based mechanics into a robust digital embedded system. Beyond the childhood nostalgia, this project serves as a comprehensive learning platform for several reasons:

  • Software Complexity: Developing a full-featured game from scratch in Rust requires mastering state machines and no_std logic.
  • Hardware Integration: The project offers hands-on experience with SPI bus sharing between high-resolution displays, touch controllers, and wireless radio modules.
  • Future Potential: This handheld terminal is designed as a versatile gaming platform. Its low energy consumption and independent peer-to-peer wireless link make it ideal for offline use (trains, planes, or remote trips). It establishes a foundation for a suite of offline multiplayer games like or Connect 4, Tic-Tac-Toe, or even singleplayer Sudoku.

Architecture

The project is split into three crates inside a Cargo workspace:

game-coreno_std pure logic library, no hardware dependencies. Compiles for both x86_64 (simulator) and thumbv8m.main-none-eabihf (MCU). Contains the grid, ship fleet, game state machine, special mechanics, and network message types.

simulatorstd desktop application. Uses embedded-graphics-simulator (SDL2) to render the game in a window on the development laptop. Uses the exact same game-core types as the real hardware. Used for developing and testing all game logic before using hardware.

embassy-appno_std Embassy application for the real hardware. Spawns independent async tasks that communicate via Embassy channels and signals.

Game State Machine (per device):

Placement ──► WaitingForOpponent ──► Battle ──► GameOver
├── Aiming
├── WaitingForResult
├── OpponentTurn
└── FerrisRepair

Communication protocol (NRF24L01+, peer-to-peer, no server):

Each game action is serialized into a NetworkMessage and sent to the opponent. Message types include FireShot, ShotResult, SonarRequest/Response, AirstrikeResult, FerrisRepairUpdate, and GameOver.

Log

Week 5 - 7

  • Searched for a suitable project idea
  • Adopted the BattleShips game concept
  • Defined the project logic and workflow

Week 8 - 9

  • Chose STM32U545RE + Embassy async Rust stack
  • Ordered two 4.0"SPI TFT Modules
  • Set up the Cargo workspace with game-core, simulator, and embassy-app crates
  • Implemented the grid.rs, ship.rs, and state.rs (in game-core)
  • Received the ordered TFT modules
  • Ordered two NUCLEO-U545RE-Q boards and the NRF24L01+ modules
  • Passed the Documentation Milestone

Week 10 - 11

  • Received the other ordered components
  • Learned to use KiCad Software by reading and watching tutorials
  • Started to work on KiCAD for the PCB
  • Finished the hardware prototype using breadboards and jumpers
  • Completed the KiCad schematic
  • Assigned and generated new footprints for KiCAD components
  • Completed the mecanical placement and layout of the PCB
  • Ordered and unpacked the last components needed
  • Completed the rouding on the PCB
  • Passed the Hardware Milestone

Week 12 - 13

  • Sent the PCB files for production to JLCPCB
  • Updated the KiCAD images for the web documentation page
  • PCB files sent to JLCPCB for production
  • Implemented the full simulator game loop main.rs with two-player local split-screen
  • Built display.rs which renders both player panels, grids, ships, hit/miss markers, specials
  • Implemented input.rs with keyboard-to-InputEvent mapping with timing logic
  • Implemented fake_network.rs to simulate the NRF24L01+ link between two players as in-process channel pair
  • Wired all three special abilities end-to-end in the simulator: Sonar Scan, Airstrike, and Ferris Repair
  • Fixed numerous game logic bugs across game-core (placement validation, cursor and key press behavior, view toggle, Ferris Repair, Airstrike, Sonar Scan, radar sync, game states)
  • Playtested full games including all specials, edge cases, and win conditions
  • Still waiting for the PCB to arrive

Week 14

  • Finally received the long-awaited PCB

Hardware

Each player's device consists of:

  • STM32U545RE-Q Nucleo-64: Arm Cortex-M33 microcontroller running at up to 160 MHz, 512 KB flash, 274 KB SRAM. Runs the Embassy async runtime with multiple concurrent tasks.
  • Power Management Subsystem: Powered by a 3.7V LiPo battery. Includes a TP4056 module for USB-C charging, a custom P-Channel MOSFET auto-power latch circuit for software-controlled shutdown, and a 3.3V Buck-Boost converter to provide stable voltage to the MCU and peripherals.
  • 4.0" TFT LCD (ST7796S, 320×480): Connected via SPI. Displays both game grids, ship positions, hit/miss markers, and special ability highlights. Driven by the mipidsi crate with embedded-graphics.
  • XPT2046 resistive touch controller: Shares the SPI bus with the display (separate CS pin). Used for cell selection on the touchscreen.
  • NRF24L01+ radio module: Connected via SPI. Provides 2.4 GHz peer-to-peer wireless communication between the two devices. No server or router required.
  • Passive buzzer: Driven via PWM. Provides audio feedback for shots, hits, sinks, special abilities, and win/lose outcomes.
  • Navigation buttons: Arrow buttons (up/down/left/right) for cursor movement and ship placement, plus Action, View-Toggle, and Rotate buttons.

Prototype

Hardware Prototype

Schematics

1. Schematic Design

The schematic integrates the STM32 Nucleo, nRF24L01+ transceiver, SPI TFT Display, and a custom P-Channel MOSFET auto-power latch circuit for battery management.

System Schematic Figure 1: Full system schematic including power management, MCU, and peripherals.

2. PCB Layout and Routing (2D)

The board has been floorplanned to accommodate a comfortable handheld form factor. Critical components (like the nRF24 decoupling capacitors) have been placed as close to their target pins as possible.

2D PCB Routing Figure 2: Current 2-layer copper routing (Front: Red, Back: Blue).

3. 3D Render

This is the physical representation of the board, which will be used to design the 3D-printed enclosure.

3D PCB Render - Front 3D PCB Render - Back Figure 3: 3D visualization of the assembled PCB (front and back).

Bill of Materials

DeviceUsagePrice
STM32U545RE Nucleo-64Main microcontroller board (×2)130 RON × 2
4.0" TFT LCD ST7796S 320×480Touchscreen display (×2)130 RON × 2
NRF24L01+ module2.4GHz wireless link (×2)7 RON × 2
TP4056 Charger moduleCharger module (x2)4 Ron × 2
Buck-Boost 3V3Constant and regulated 3.3V voltage (x2)15 Ron × 2
Tantalum CapacitorsHelp the radio transmission (x6)4 RON × 6
LEDsIllumination + feedback4 Ron × 3
ResisistorsFor leds and power management20 RON
Push buttonsNavigation + action input (×2 sets)0.36 RON × 20
Jumper wires + breadboardPrototyping connections~12 RON
PCBCircuit board (x5)~ 50 RON
Total (approximated)~ 700 RON

Software

LibraryDescriptionUsage
embassyAsync embedded frameworkTask scheduler, async SPI/GPIO/PWM drivers for STM32U5
mipidsiMIPI display driverDrives the ST7796S TFT display over SPI
embedded-graphics2D graphics libraryDraws grids, ships, cursors, highlights, text
embedded-graphics-simulatorSDL2-based simulatorRuns the full game on laptop for logic testing
xpt2046Resistive touch driverReads touch coordinates from XPT2046 controller
heaplessFixed-size collectionsStack-allocated Vec/Queue replacements for no_std
defmtEmbedded loggingRTT-based debug logging via probe-rs
  1. Battleship - Wikipedia: General rules and history of the classic board game.
  2. Sea Battle (App Store): A popular mobile version that inspired the digital UI and special mechanics.
  3. Embassy - Async Rust for Embedded: Documentation for the framework powering the game's concurrency.