From c2383801efc63f26102b7322d8a5e853f97c0a3a Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Sun, 21 Jan 2024 20:01:12 -0500 Subject: [PATCH] Add necessary changes for PowerTools --- src/ec/controller.rs | 11 ++++++++++- src/ec/ports.rs | 36 ++++++++++++++++++------------------ src/ec/unnamed_power/mod.rs | 2 ++ src/lib.rs | 1 + 4 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/ec/controller.rs b/src/ec/controller.rs index d696eb2..189a0e1 100644 --- a/src/ec/controller.rs +++ b/src/ec/controller.rs @@ -20,7 +20,7 @@ pub trait ControllerGet: embedded_io::ErrorType { /// Size of values to write and read from ports. /// System endianness is assumed. -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Debug)] #[repr(u8)] pub enum ValueSize { Byte = 1, // u8 @@ -35,6 +35,7 @@ const MAX_WAIT_CHECKS: u16 = 0x07ff; #[cfg(not(feature = "std"))] const MAX_WAIT_CHECKS: u16 = 0x7fff; +#[derive(Debug)] pub struct EmbeddedController { data_address: u16, cmd_address: u16, @@ -96,6 +97,14 @@ impl EmbeddedController { pub fn set_value_size(&mut self, size: ValueSize) { self.rw_size = size; } + + pub fn data(&self) -> u16 { + self.data_address + } + + pub fn cmd(&self) -> u16 { + self.cmd_address + } } impl embedded_io::ErrorType for EmbeddedController { diff --git a/src/ec/ports.rs b/src/ec/ports.rs index 057f151..f10d4dd 100644 --- a/src/ec/ports.rs +++ b/src/ec/ports.rs @@ -5,9 +5,9 @@ mod ports_internal { pub(crate) fn outb(port: u16, val: u8) { //println!("outb port:{:#04x} value:{:#02x}", port, val); unsafe { - std::arch::asm!("out dx, al", in("dx") port, in("al") val); - //std::arch::asm!("outb %al, %dx", in("al") val, in("dx") port, options(att_syntax)); - //std::arch::asm!("out dx,al", in("al") val, in("dx") port); + core::arch::asm!("out dx, al", in("dx") port, in("al") val); + //core::arch::asm!("outb %al, %dx", in("al") val, in("dx") port, options(att_syntax)); + //core::arch::asm!("out dx,al", in("al") val, in("dx") port); } //println!("outb done"); } @@ -16,9 +16,9 @@ mod ports_internal { pub(crate) fn outw(port: u16, val: u16) { //println!("outw port:{:#04x} value:{:#02x}", port, val); unsafe { - std::arch::asm!("out dx, ax", in("dx") port, in("ax") val); - //std::arch::asm!("outb %al, %dx", in("al") val, in("dx") port, options(att_syntax)); - //std::arch::asm!("out dx,al", in("al") val, in("dx") port); + core::arch::asm!("out dx, ax", in("dx") port, in("ax") val); + //core::arch::asm!("outb %al, %dx", in("al") val, in("dx") port, options(att_syntax)); + //core::arch::asm!("out dx,al", in("al") val, in("dx") port); } //println!("outw done"); } @@ -27,9 +27,9 @@ mod ports_internal { pub(crate) fn outl(port: u16, val: u32) { //println!("outl port:{:#04x} value:{:#02x}", port, val); unsafe { - std::arch::asm!("out dx, eax", in("dx") port, in("eax") val); - //std::arch::asm!("outb %al, %dx", in("al") val, in("dx") port, options(att_syntax)); - //std::arch::asm!("out dx,al", in("al") val, in("dx") port); + core::arch::asm!("out dx, eax", in("dx") port, in("eax") val); + //core::arch::asm!("outb %al, %dx", in("al") val, in("dx") port, options(att_syntax)); + //core::arch::asm!("out dx,al", in("al") val, in("dx") port); } //println!("outl done"); } @@ -39,9 +39,9 @@ mod ports_internal { let out: u8; //println!("inb port:{:#04x}", port); unsafe { - std::arch::asm!("in al, dx", in("dx") port, lateout("al") out); - //std::arch::asm!("inb %dx, %al", in("dx") port, out("al") out, options(att_syntax)); - //std::arch::asm!("in al,dx", in("dx") port, out("al") out); + core::arch::asm!("in al, dx", in("dx") port, lateout("al") out); + //core::arch::asm!("inb %dx, %al", in("dx") port, out("al") out, options(att_syntax)); + //core::arch::asm!("in al,dx", in("dx") port, out("al") out); } //println!("inb port:{:#04x} -> value:{:#02x}", port, out); out @@ -52,9 +52,9 @@ mod ports_internal { let out: u16; //println!("inb port:{:#04x}", port); unsafe { - std::arch::asm!("in ax, dx", in("dx") port, lateout("ax") out); - //std::arch::asm!("inb %dx, %al", in("dx") port, out("al") out, options(att_syntax)); - //std::arch::asm!("in al,dx", in("dx") port, out("al") out); + core::arch::asm!("in ax, dx", in("dx") port, lateout("ax") out); + //core::arch::asm!("inb %dx, %al", in("dx") port, out("al") out, options(att_syntax)); + //core::arch::asm!("in al,dx", in("dx") port, out("al") out); } //println!("inb port:{:#04x} -> value:{:#02x}", port, out); out @@ -65,9 +65,9 @@ mod ports_internal { let out: u32; //println!("inb port:{:#04x}", port); unsafe { - std::arch::asm!("in eax, dx", in("dx") port, lateout("eax") out); - //std::arch::asm!("inb %dx, %al", in("dx") port, out("al") out, options(att_syntax)); - //std::arch::asm!("in al,dx", in("dx") port, out("al") out); + core::arch::asm!("in eax, dx", in("dx") port, lateout("eax") out); + //core::arch::asm!("inb %dx, %al", in("dx") port, out("al") out, options(att_syntax)); + //core::arch::asm!("in al,dx", in("dx") port, out("al") out); } //println!("inb port:{:#04x} -> value:{:#02x}", port, out); out diff --git a/src/ec/unnamed_power/mod.rs b/src/ec/unnamed_power/mod.rs index 45504d0..a06d034 100644 --- a/src/ec/unnamed_power/mod.rs +++ b/src/ec/unnamed_power/mod.rs @@ -1,7 +1,9 @@ mod addresses; pub use addresses::{Setting, Charge, ChargeMode, ControlBoard, BreathingColour, StaticColour}; +#[cfg(feature = "std")] pub mod raw_io; +#[derive(Debug)] pub struct UnnamedPowerEC(super::EmbeddedController); impl UnnamedPowerEC { diff --git a/src/lib.rs b/src/lib.rs index ee43710..537ff4d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ //! Low-level hardware interfaces for Valve's Steam Deck +#![cfg_attr(not(feature = "std"), no_std)] #![warn(missing_docs)] pub mod ec;