PulseCode

Struct PulseCode 

Source
#[repr(transparent)]
pub struct PulseCode(pub u32);
Expand description

Convenience newtype to work with pulse codes.

A PulseCode is represented as u32, with fields laid out as follows:

Bit 31Bits 30-16Bit 15Bits 14-0
level2length2level1length1

Here, level1 / length1 correspond to the signal that is send/received first, and the signal with level2 / length2 is send/received afterwards.

If length1 or length2 are zero, this implies an end marker and transmission will stop with the corresponding signal.

Tuple Fields§

§0: u32

Implementations§

Source§

impl PulseCode

Source

pub const MAX_LEN: u16 = 32_767u16

Maximum value for the length1 and length2 fields.

Source

pub const fn new( level1: Level, length1: u16, level2: Level, length2: u16, ) -> Self

Create a new instance.

Panics if length1 or length2 exceed the maximum representable range.

Source

pub const fn new_clamped( level1: Level, length1: u16, level2: Level, length2: u16, ) -> Self

Create a new instance.

If length1 or length2 exceed the maximum representable range, they will be clamped to Self::MAX_LEN.

Source

pub fn try_new( level1: Level, length1: impl TryInto<u16>, level2: Level, length2: impl TryInto<u16>, ) -> Option<Self>

Create a new instance, attempting to convert lengths to u16 first.

This is slightly more convenient when passing in longer integers (e.g. u32) resulting from a preceding calculation.

If length1 or length2 fail to convert to u16 or exceed the maximum representable range, this will return None.

Source

pub const unsafe fn new_unchecked( level1: Level, length1: u16, level2: Level, length2: u16, ) -> Self

Create a new instance without checking that code lengths are in range.

§Safety

length1 and length2 must be 15-bit wide, i.e. their MSB must be cleared.

Source

pub const fn end_marker() -> Self

Create a new instance that is an end marker with Level::Low.

This corresponds to the all-zero PulseCode, i.e. with both level and length fields set to zero, equivalent to (but more semantic than) PulseCode::from(0u32) and PulseCode::default().

Source

pub fn reset(&mut self)

Set all levels and lengths to 0.

In other words, assigns the value of PulseCode::end_marker() to self.

Source

pub const fn level1(self) -> Level

Logical output level in the first pulse code interval

Source

pub const fn level2(self) -> Level

Logical output level in the second pulse code interval

Source

pub const fn length1(self) -> u16

Length of the first pulse code interval (in clock cycles)

Source

pub const fn length2(self) -> u16

Length of the second pulse code interval (in clock cycles)

Source

pub const fn with_level1(self, level: Level) -> Self

Set level1 and return the modified PulseCode.

Source

pub const fn with_level2(self, level: Level) -> Self

Set level2 and return the modified PulseCode.

Source

pub const fn with_length1(self, length: u16) -> Option<Self>

Set length1 and return the modified PulseCode.

Returns None if length exceeds the representable range.

Source

pub const fn with_length2(self, length: u16) -> Option<Self>

Set length2 and return the modified PulseCode.

Returns None if length exceeds the representable range.

Source

pub const fn is_end_marker(self) -> bool

Return whether this pulse code contains an end marker.

Equivalent to self.length1() == 0 || self.length2() == 0.

Trait Implementations§

Source§

impl Clone for PulseCode

Available on crate feature unstable only.
Source§

fn clone(&self) -> PulseCode

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for PulseCode

Available on crate feature unstable only.
Source§

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

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

impl Default for PulseCode

Available on crate feature unstable only.
Source§

fn default() -> PulseCode

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

impl From<PulseCode> for u32

Available on crate feature unstable only.
Source§

fn from(code: PulseCode) -> u32

Converts to this type from the input type.
Source§

impl From<u32> for PulseCode

Available on crate feature unstable only.
Source§

fn from(value: u32) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for PulseCode

Available on crate feature unstable only.
Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for PulseCode

Available on crate feature unstable only.
Source§

impl Eq for PulseCode

Available on crate feature unstable only.
Source§

impl StructuralPartialEq for PulseCode

Available on crate feature unstable only.

Auto Trait Implementations§

§

impl Freeze for PulseCode

§

impl RefUnwindSafe for PulseCode

§

impl Send for PulseCode

§

impl Sync for PulseCode

§

impl Unpin for PulseCode

§

impl UnwindSafe for PulseCode

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

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

§

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
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

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> Same for T

Source§

type Output = T

Should always be Self
§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.