embassy-usb

Crates

git

Versions

default

Flavors

Skip to main content

GamepadReport

Struct GamepadReport 

Source
pub struct GamepadReport {
    pub x: i8,
    pub y: i8,
    pub z: i8,
    pub rz: i8,
    pub hat: u8,
    pub buttons: GamepadButtons,
}
Expand description

Standard USB HID Gamepad report with 8-bit axes, hat switch, and 16 buttons (7 bytes).

Fields§

§x: i8

Left stick horizontal axis (signed, positive = right).

§y: i8

Left stick vertical axis (signed, positive = down).

§z: i8

Right stick horizontal axis (signed, positive = right).

§rz: i8

Right stick vertical axis (signed, positive = down).

§hat: u8

8-direction hat switch (POV D-pad).

Values 1–8 correspond to 45° increments starting from Up (0°):

  • 1 = Up (0°)
  • 2 = Up-Right (45°)
  • 3 = Right (90°)
  • 4 = Down-Right (135°)
  • 5 = Down (180°)
  • 6 = Down-Left (225°)
  • 7 = Left (270°)
  • 8 = Up-Left (315°)
  • 0 = Released / centered (Null state)
§buttons: GamepadButtons

Button bitmask (buttons 1–16).

Implementations§

Source§

impl GamepadReport

Source

pub const HAT_CENTER: u8 = 0

Hat switch released / centered (null state).

Source

pub const HAT_UP: u8 = 1

Hat switch Up (0°).

Source

pub const HAT_UP_RIGHT: u8 = 2

Hat switch Up-Right (45°).

Source

pub const HAT_RIGHT: u8 = 3

Hat switch Right (90°).

Source

pub const HAT_DOWN_RIGHT: u8 = 4

Hat switch Down-Right (135°).

Source

pub const HAT_DOWN: u8 = 5

Hat switch Down (180°).

Source

pub const HAT_DOWN_LEFT: u8 = 6

Hat switch Down-Left (225°).

Source

pub const HAT_LEFT: u8 = 7

Hat switch Left (270°).

Source

pub const HAT_UP_LEFT: u8 = 8

Hat switch Up-Left (315°).

Source

pub const BUTTON_1: GamepadButtons

Button 1

Source

pub const BUTTON_2: GamepadButtons

Button 2

Source

pub const BUTTON_3: GamepadButtons

Button 3

Source

pub const BUTTON_4: GamepadButtons

Button 4

Source

pub const BUTTON_5: GamepadButtons

Button 5

Source

pub const BUTTON_6: GamepadButtons

Button 6

Source

pub const BUTTON_7: GamepadButtons

Button 7

Source

pub const BUTTON_8: GamepadButtons

Button 8

Source

pub const BUTTON_9: GamepadButtons

Button 9

Source

pub const BUTTON_10: GamepadButtons

Button 10

Source

pub const BUTTON_11: GamepadButtons

Button 11

Source

pub const BUTTON_12: GamepadButtons

Button 12

Source

pub const BUTTON_13: GamepadButtons

Button 13

Source

pub const BUTTON_14: GamepadButtons

Button 14

Source

pub const BUTTON_15: GamepadButtons

Button 15

Source

pub const BUTTON_16: GamepadButtons

Button 16

Source

pub const BUTTON_A: GamepadButtons = Self::BUTTON_1

Primary action button (A / Cross).

Source

pub const BUTTON_B: GamepadButtons = Self::BUTTON_2

Secondary action button (B / Circle).

Source

pub const BUTTON_X: GamepadButtons = Self::BUTTON_3

Tertiary action button (X / Square).

Source

pub const BUTTON_Y: GamepadButtons = Self::BUTTON_4

Quaternary action button (Y / Triangle).

Source

pub const BUTTON_TL: GamepadButtons = Self::BUTTON_5

Left bumper / shoulder button (L1 / LB).

Source

pub const BUTTON_TR: GamepadButtons = Self::BUTTON_6

Right bumper / shoulder button (R1 / RB).

Source

pub const BUTTON_TL2: GamepadButtons = Self::BUTTON_7

Left trigger digital button (L2 / LT).

Source

pub const BUTTON_TR2: GamepadButtons = Self::BUTTON_8

Right trigger digital button (R2 / RT).

Source

pub const BUTTON_SELECT: GamepadButtons = Self::BUTTON_9

Select / Back / Share button.

Source

pub const BUTTON_START: GamepadButtons = Self::BUTTON_10

Start / Options button.

Source

pub const BUTTON_MODE: GamepadButtons = Self::BUTTON_11

Mode / Home / Guide button.

Source

pub const BUTTON_THUMBL: GamepadButtons = Self::BUTTON_12

Left stick click (L3 / Thumbl).

Source

pub const BUTTON_THUMBR: GamepadButtons = Self::BUTTON_13

Right stick click (R3 / Thumbr).

Source

pub const DESCRIPTOR: &'static [u8]

Standard USB HID Gamepad report descriptor without report ID (7 bytes input report).

Source

pub fn parse(buf: &[u8]) -> Option<Self>

Parse a gamepad report from a byte slice. Returns None if buf is shorter than 7 bytes.

Source

pub const fn to_bytes(&self) -> [u8; 7]

Serialize the gamepad report into its 7-byte wire format.

Source

pub fn is_button_pressed(&self, button: GamepadButtons) -> bool

Returns true if the specified button is pressed.

Trait Implementations§

Source§

impl Clone for GamepadReport

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for GamepadReport

Source§

impl Debug for GamepadReport

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for GamepadReport

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for GamepadReport

Source§

impl Format for GamepadReport

Source§

fn format(&self, f: Formatter<'_>)

Writes the defmt representation of self to fmt.
Source§

impl PartialEq for GamepadReport

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for GamepadReport

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.