use core::fmt;
use core::fmt::Write;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct VendorId(u16);
impl VendorId {
#[inline]
pub const fn new(id: u16) -> Self {
Self(id)
}
#[inline]
pub const fn value(self) -> u16 {
self.0
}
pub fn to_hex_string(self) -> heapless::String<4> {
let mut s = heapless::String::new();
let _ = write!(&mut s, "{:04x}", self.0);
s
}
}
impl fmt::Display for VendorId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:04x}", self.0)
}
}
impl fmt::LowerHex for VendorId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:04x}", self.0)
}
}
impl fmt::UpperHex for VendorId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:04X}", self.0)
}
}
impl From<u16> for VendorId {
fn from(id: u16) -> Self {
Self::new(id)
}
}
impl From<VendorId> for u16 {
fn from(id: VendorId) -> Self {
id.value()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct DeviceId(u16);
impl DeviceId {
#[inline]
pub const fn new(id: u16) -> Self {
Self(id)
}
#[inline]
pub const fn value(self) -> u16 {
self.0
}
pub fn to_hex_string(self) -> heapless::String<4> {
let mut s = heapless::String::new();
let _ = write!(&mut s, "{:04x}", self.0);
s
}
}
impl fmt::Display for DeviceId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:04x}", self.0)
}
}
impl fmt::LowerHex for DeviceId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:04x}", self.0)
}
}
impl fmt::UpperHex for DeviceId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:04X}", self.0)
}
}
impl From<u16> for DeviceId {
fn from(id: u16) -> Self {
Self::new(id)
}
}
impl From<DeviceId> for u16 {
fn from(id: DeviceId) -> Self {
id.value()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct SubvendorId(u16);
impl SubvendorId {
#[inline]
pub const fn new(id: u16) -> Self {
Self(id)
}
#[inline]
pub const fn value(self) -> u16 {
self.0
}
}
impl fmt::Display for SubvendorId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:04x}", self.0)
}
}
impl From<u16> for SubvendorId {
fn from(id: u16) -> Self {
Self::new(id)
}
}
impl From<SubvendorId> for u16 {
fn from(id: SubvendorId) -> Self {
id.value()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct SubdeviceId(u16);
impl SubdeviceId {
#[inline]
pub const fn new(id: u16) -> Self {
Self(id)
}
#[inline]
pub const fn value(self) -> u16 {
self.0
}
}
impl fmt::Display for SubdeviceId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:04x}", self.0)
}
}
impl From<u16> for SubdeviceId {
fn from(id: u16) -> Self {
Self::new(id)
}
}
impl From<SubdeviceId> for u16 {
fn from(id: SubdeviceId) -> Self {
id.value()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct DeviceClassId(u8);
impl DeviceClassId {
#[inline]
pub const fn new(id: u8) -> Self {
Self(id)
}
#[inline]
pub const fn value(self) -> u8 {
self.0
}
}
impl fmt::Display for DeviceClassId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:02x}", self.0)
}
}
impl From<u8> for DeviceClassId {
fn from(id: u8) -> Self {
Self::new(id)
}
}
impl From<DeviceClassId> for u8 {
fn from(id: DeviceClassId) -> Self {
id.value()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct SubClassId(u8);
impl SubClassId {
#[inline]
pub const fn new(id: u8) -> Self {
Self(id)
}
#[inline]
pub const fn value(self) -> u8 {
self.0
}
}
impl fmt::Display for SubClassId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:02x}", self.0)
}
}
impl From<u8> for SubClassId {
fn from(id: u8) -> Self {
Self::new(id)
}
}
impl From<SubClassId> for u8 {
fn from(id: SubClassId) -> Self {
id.value()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ProgInterfaceId(u8);
impl ProgInterfaceId {
#[inline]
pub const fn new(id: u8) -> Self {
Self(id)
}
#[inline]
pub const fn value(self) -> u8 {
self.0
}
}
impl fmt::Display for ProgInterfaceId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:02x}", self.0)
}
}
impl From<u8> for ProgInterfaceId {
fn from(id: u8) -> Self {
Self::new(id)
}
}
impl From<ProgInterfaceId> for u8 {
fn from(id: ProgInterfaceId) -> Self {
id.value()
}
}