From d937f4b25617e89609f5b221d3acbbb370bda9c2 Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Sat, 20 Sep 2025 18:19:33 +0200 Subject: [PATCH] Updated documentation. Renamed to only CMDR Joystick --- Justfile | 4 ++-- README.md | 4 ++-- rp2040/Cargo.toml | 6 +++--- rp2040/src/axis.rs | 2 +- rp2040/src/board.rs | 2 ++ rp2040/src/button_matrix.rs | 2 +- rp2040/src/buttons.rs | 2 +- rp2040/src/calibration.rs | 2 +- rp2040/src/hardware.rs | 4 ++-- rp2040/src/joystick.rs | 2 +- rp2040/src/lib.rs | 2 +- rp2040/src/main.rs | 24 ++++++++++++------------ rp2040/src/mapping.rs | 2 +- rp2040/src/status.rs | 2 +- rp2040/src/storage.rs | 2 +- rp2040/src/usb_report.rs | 2 +- 16 files changed, 33 insertions(+), 31 deletions(-) diff --git a/Justfile b/Justfile index 530cc4e..f35571c 100644 --- a/Justfile +++ b/Justfile @@ -10,8 +10,8 @@ test: build-uf2: cd rp2040 && cargo build --release --target thumbv6m-none-eabi - cd rp2040 && cargo objcopy --release --target thumbv6m-none-eabi -- -O binary target/thumbv6m-none-eabi/release/cmdr-joystick-25.bin - cd rp2040 && python3 uf2conv.py target/thumbv6m-none-eabi/release/cmdr-joystick-25.bin --base 0x10000000 --family 0xe48bff56 --convert --output target/firmware.uf2 + cd rp2040 && cargo objcopy --release --target thumbv6m-none-eabi -- -O binary target/thumbv6m-none-eabi/release/cmdr-joystick.bin + cd rp2040 && python3 uf2conv.py target/thumbv6m-none-eabi/release/cmdr-joystick.bin --base 0x10000000 --family 0xe48bff56 --convert --output target/firmware.uf2 clean: cargo clean --manifest-path rp2040/Cargo.toml diff --git a/README.md b/README.md index 3595110..f007a5c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# CMDR Joystick 25 +# CMDR Joystick USB HID joystick firmware + hardware: 2 hall‑effect gimbals, 2 physical hat switches, and a 5x5 button matrix (plus 2 extra buttons). The firmware exposes @@ -111,7 +111,7 @@ Config Layer (holding CONFIG button) - 1x Bottom case (3D printed) - 1x Top plate (3D printed) - 2x Hat swith top (3D printed) [stl](/mCAD/Hat_Castle_Short_scale_99_99_130.stl) -- 1x Custom PCB (CMDR Joystick 25 rev A) +- 1x Custom PCB (CMDR Joystick rev A) - ![pcb_top](/eCAD/cmdr-joystick/cmdr-joystick_rev_a_board_top.png) - ![pcb_bottom](/eCAD/cmdr-joystick/cmdr-joystick_rev_a_board_bottom.png) - Gerber files: [zip](/eCAD/cmdr-joystick/cmdr-joystick_rev_a_gerber.zip) diff --git a/rp2040/Cargo.toml b/rp2040/Cargo.toml index 7f852f2..c8b9a6a 100644 --- a/rp2040/Cargo.toml +++ b/rp2040/Cargo.toml @@ -1,8 +1,8 @@ [package] -name = "cmdr-joystick-25" +name = "cmdr-joystick" version = "0.2.0" edition = "2021" -# Firmware crate for the CMDR Joystick 25 (RP2040) +# Firmware crate for the CMDR Joystick (RP2040) [dependencies] # Core embedded + RP2040 HAL stack (aligned with rp2040-hal v0.11) @@ -65,7 +65,7 @@ overflow-checks = false path = "src/lib.rs" [[bin]] -name = "cmdr-joystick-25" +name = "cmdr-joystick" path = "src/main.rs" bench = false test = false diff --git a/rp2040/src/axis.rs b/rp2040/src/axis.rs index ea6aac6..5d716e2 100644 --- a/rp2040/src/axis.rs +++ b/rp2040/src/axis.rs @@ -1,4 +1,4 @@ -//! Axis processing for CMDR Joystick 25 +//! Axis processing for CMDR Joystick //! //! Responsibilities //! - Apply gimbal mode compensation (M10/M7) to raw ADC readings diff --git a/rp2040/src/board.rs b/rp2040/src/board.rs index 7af0e88..3d07a1d 100644 --- a/rp2040/src/board.rs +++ b/rp2040/src/board.rs @@ -1,3 +1,5 @@ +//! Board bring-up and peripheral wiring for the CMDR Joystick firmware. + use crate::button_matrix::{ButtonMatrix, MatrixPins}; use crate::hardware::{self, BoardPins}; use crate::status::StatusLed; diff --git a/rp2040/src/button_matrix.rs b/rp2040/src/button_matrix.rs index 4e395ae..551b076 100644 --- a/rp2040/src/button_matrix.rs +++ b/rp2040/src/button_matrix.rs @@ -1,4 +1,4 @@ -//! Button matrix scanner for CMDR Joystick 25. +//! Button matrix scanner for CMDR Joystick. //! //! Mirrors the refactor performed for the keyboard firmware: the matrix owns //! concrete pins, exposes a small `MatrixPinAccess` trait, and keeps the diff --git a/rp2040/src/buttons.rs b/rp2040/src/buttons.rs index cbaddee..f0236ae 100644 --- a/rp2040/src/buttons.rs +++ b/rp2040/src/buttons.rs @@ -1,4 +1,4 @@ -//! Button processing for CMDR Joystick 25 +//! Button processing for CMDR Joystick //! //! Responsibilities //! - Integrate button matrix results and extra pins diff --git a/rp2040/src/calibration.rs b/rp2040/src/calibration.rs index 583b333..174554e 100644 --- a/rp2040/src/calibration.rs +++ b/rp2040/src/calibration.rs @@ -1,4 +1,4 @@ -//! Calibration management for CMDR Joystick 25 +//! Calibration management for CMDR Joystick //! //! Responsibilities //! - Manage the calibration lifecycle (start/active/stop) diff --git a/rp2040/src/hardware.rs b/rp2040/src/hardware.rs index b3ab261..64535cf 100644 --- a/rp2040/src/hardware.rs +++ b/rp2040/src/hardware.rs @@ -1,4 +1,4 @@ -//! Hardware configuration for CMDR Joystick 25 (RP2040) +//! Hardware configuration for CMDR Joystick (RP2040) //! //! Mirrors the structure introduced for the CMDR Keyboard firmware so that //! bring-up, pin management, and timing constants follow the same layout. @@ -37,7 +37,7 @@ pub const EEPROM_DATA_LENGTH: usize = 25; /// USB string descriptors. pub mod usb { pub const MANUFACTURER: &str = "CMtec"; - pub const PRODUCT: &str = "CMDR Joystick 25"; + pub const PRODUCT: &str = "CMDR Joystick"; pub const SERIAL_NUMBER: &str = "0001"; } diff --git a/rp2040/src/joystick.rs b/rp2040/src/joystick.rs index 236dc7e..3ea2b26 100644 --- a/rp2040/src/joystick.rs +++ b/rp2040/src/joystick.rs @@ -1,4 +1,4 @@ -//! Runtime state for the CMDR Joystick 25. +//! Runtime state for the CMDR Joystick. //! //! This mirrors the `KeyboardState` abstraction from the keyboard refactor and //! concentrates axis/button/calibration logic alongside USB bookkeeping. diff --git a/rp2040/src/lib.rs b/rp2040/src/lib.rs index 45efd5f..7c4381a 100644 --- a/rp2040/src/lib.rs +++ b/rp2040/src/lib.rs @@ -1,6 +1,6 @@ #![cfg_attr(not(feature = "std"), no_std)] -//! CMDR Joystick 25 firmware library for RP2040. +//! CMDR Joystick firmware library for RP2040. //! //! This crate provides the reusable building blocks that power the main //! firmware: axis processing, button handling, calibration and storage, USB diff --git a/rp2040/src/main.rs b/rp2040/src/main.rs index cd1ee21..f2fc33f 100644 --- a/rp2040/src/main.rs +++ b/rp2040/src/main.rs @@ -1,11 +1,12 @@ +//! Firmware entry orchestrating the CMDR Joystick runtime loop. #![no_std] #![no_main] -use cmdr_joystick_25::buttons::SpecialAction; -use cmdr_joystick_25::hardware::{self, timers}; -use cmdr_joystick_25::status::StatusMode; -use cmdr_joystick_25::usb_joystick_device::JoystickConfig; -use cmdr_joystick_25::{bootloader, Board, BoardParts, JoystickState}; +use cmdr_joystick::buttons::SpecialAction; +use cmdr_joystick::hardware::{self, timers}; +use cmdr_joystick::status::StatusMode; +use cmdr_joystick::usb_joystick_device::JoystickConfig; +use cmdr_joystick::{bootloader, Board, BoardParts, JoystickState}; use embedded_hal_0_2::adc::OneShot; use embedded_hal_0_2::timer::CountDown; use fugit::ExtU32; @@ -13,8 +14,8 @@ use panic_halt as _; use usb_device::prelude::*; use usbd_human_interface_device::prelude::{UsbHidClassBuilder, UsbHidError}; -#[unsafe(link_section = ".boot2")] -#[unsafe(no_mangle)] +#[link_section = ".boot2"] +#[no_mangle] #[used] pub static BOOT2_FIRMWARE: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080; @@ -74,6 +75,7 @@ fn main() -> ! { usb_tick.start(timers::USB_UPDATE_INTERVAL_MS.millis()); let mut status_time_ms: u32 = 0; + let mut suspended_scan_counter: u8 = 0; // Main control loop: service USB, process inputs, and emit reports. loop { @@ -93,12 +95,10 @@ fn main() -> ! { // Slow the scan cadence when USB is suspended to save power. let should_scan = if state.usb_state().suspended { - static mut SUSPENDED_SCAN_COUNTER: u8 = 0; - unsafe { - SUSPENDED_SCAN_COUNTER = (SUSPENDED_SCAN_COUNTER + 1) % 10; - SUSPENDED_SCAN_COUNTER == 0 - } + suspended_scan_counter = suspended_scan_counter.wrapping_add(1) % 10; + suspended_scan_counter == 0 } else { + suspended_scan_counter = 0; true }; diff --git a/rp2040/src/mapping.rs b/rp2040/src/mapping.rs index c94047f..a2020c4 100644 --- a/rp2040/src/mapping.rs +++ b/rp2040/src/mapping.rs @@ -1,4 +1,4 @@ -//! Button-to-USB mapping for CMDR Joystick 25 +//! Button-to-USB mapping for CMDR Joystick //! //! This module defines the hardware button indices (matrix layout and extras) //! and their mapping to USB joystick button numbers and HAT directions. diff --git a/rp2040/src/status.rs b/rp2040/src/status.rs index 02f3625..80a27f9 100644 --- a/rp2040/src/status.rs +++ b/rp2040/src/status.rs @@ -1,4 +1,4 @@ -//! WS2812 status LED driver for CMDR Joystick 25 +//! WS2812 status LED driver for CMDR Joystick //! //! Provides a small helper around `ws2812_pio` to display firmware state on a //! single WS2812 RGB LED using RP2040 PIO. The driver offers simple modes diff --git a/rp2040/src/storage.rs b/rp2040/src/storage.rs index 1655cd2..6fdd140 100644 --- a/rp2040/src/storage.rs +++ b/rp2040/src/storage.rs @@ -1,4 +1,4 @@ -//! EEPROM storage for CMDR Joystick 25 +//! EEPROM storage for CMDR Joystick //! //! Provides helpers to read/write per‑axis calibration and gimbal mode to an //! external 24x‑series EEPROM. The API is closure‑based to allow testing on diff --git a/rp2040/src/usb_report.rs b/rp2040/src/usb_report.rs index 76b4206..a719732 100644 --- a/rp2040/src/usb_report.rs +++ b/rp2040/src/usb_report.rs @@ -1,4 +1,4 @@ -//! USB HID report generation for CMDR Joystick 25 +//! USB HID report generation for CMDR Joystick //! //! Converts processed axis values and button states into a `JoystickReport` //! that matches the HID descriptor defined in `usb_joystick_device.rs`.