librazer

Crates.iolibrazer
lib.rslibrazer
version0.8.2
created_at2025-12-26 22:54:32.259054+00
updated_at2025-12-27 21:42:13.035008+00
descriptionLibrary for controlling Razer laptop BIOS settings via USB HID
homepage
repositoryhttps://github.com/stvnksslr/razer-ctl
max_upload_size
id2006376
size63,707
Steven Kessler (stvnksslr)

documentation

README

librazer

A Rust library for controlling Razer laptop BIOS settings via USB HID protocol.

Crates.io Documentation License: MIT

Features

  • Cross-platform support (Linux and Windows)
  • Automatic device detection
  • Performance mode control (Silent, Balanced, Custom)
  • Fan control (Auto, Manual RPM, Max Speed)
  • CPU/GPU boost configuration
  • Keyboard backlight brightness
  • Lid logo control (on supported models)
  • Battery care mode
  • Compile-time feature validation per device

Installation

Add to your Cargo.toml:

[dependencies]
librazer = "0.7"

Linux Requirements

Install libudev-dev for USB HID support:

# Debian/Ubuntu
sudo apt install libudev-dev

# Fedora
sudo dnf install systemd-devel

Usage

Auto-detect and connect

use librazer::{device::Device, command};

fn main() -> anyhow::Result<()> {
    // Auto-detect connected Razer laptop
    let device = Device::detect()?;

    println!("Connected to: {}", device.info.name);

    // Get current performance mode
    let (perf_mode, fan_mode) = command::get_perf_mode(&device)?;
    println!("Performance: {:?}, Fan: {:?}", perf_mode, fan_mode);

    Ok(())
}

Set performance mode

use librazer::{device::Device, command, types::PerfMode};

fn main() -> anyhow::Result<()> {
    let device = Device::detect()?;

    // Set to silent mode for better battery life
    command::set_perf_mode(&device, PerfMode::Silent)?;

    Ok(())
}

Custom CPU/GPU boost

use librazer::{device::Device, command, types::{PerfMode, CpuBoost, GpuBoost}};

fn main() -> anyhow::Result<()> {
    let device = Device::detect()?;

    // Enable custom mode first
    command::set_perf_mode(&device, PerfMode::Custom)?;

    // Configure boost levels
    command::set_cpu_boost(&device, CpuBoost::High)?;
    command::set_gpu_boost(&device, GpuBoost::Medium)?;

    Ok(())
}

Manual fan control

use librazer::{device::Device, command, types::{PerfMode, FanMode}};

fn main() -> anyhow::Result<()> {
    let device = Device::detect()?;

    // Switch to balanced mode (required for manual fan)
    command::set_perf_mode(&device, PerfMode::Balanced)?;
    command::set_fan_mode(&device, FanMode::Manual)?;

    // Set fan speed (2000-5000 RPM)
    command::set_fan_rpm(&device, 3500)?;

    Ok(())
}

Other settings

use librazer::{device::Device, command, types::{BatteryCare, LogoMode, LightsAlwaysOn}};

fn main() -> anyhow::Result<()> {
    let device = Device::detect()?;

    // Enable battery care (limits charging to 80%)
    command::set_battery_care(&device, BatteryCare::Enable)?;

    // Set keyboard brightness (0-255)
    command::set_keyboard_brightness(&device, 128)?;

    // Set logo mode (if supported)
    command::set_logo_mode(&device, LogoMode::Static)?;

    // Keep lights on when sleeping
    command::set_lights_always_on(&device, LightsAlwaysOn::Enable)?;

    Ok(())
}

Supported Devices

Model Model Number Features
Razer Blade 14" (2023) Mercury RZ09-0482X Perf, Fan, Keyboard, Battery Care, Lights Always On
Razer Blade 16" (2023) Black RZ09-0483T Perf, Fan, Keyboard, Logo, Battery Care, Lights Always On

Adding Device Support

  1. Find your device's USB PID: lsusb | grep 1532
  2. Get model number from Razer support (format: RZ09-XXXXX)
  3. Add a Descriptor entry in src/descriptor.rs:
Descriptor {
    model_number_prefix: "RZ09-XXXXX",
    name: "Razer Blade XX\" (Year)",
    pid: 0xXXXX,
    features: &[
        feature::BATTERYCARE,
        feature::FAN,
        feature::KBDBACKLIGHT,
        feature::PERF,
    ],
},

Protocol

Communication uses 90-byte USB HID feature reports:

Bytes Purpose
0-1 Status + transaction ID
2-7 Protocol metadata (data_size, command_class, command_id)
8-87 Command arguments (80 bytes)
88 CRC (XOR of bytes 2-87)
89 Reserved

Razer vendor ID: 0x1532

Acknowledgments

License

MIT

Commit count: 0

cargo fmt