tm1637_embedded_hal::asynch

Struct TM1637

source
pub struct TM1637<CLK, DIO, DELAY> { /* private fields */ }
Available on crate feature async only.
Expand description

TM1637 7-segment display driver.

Implementations§

source§

impl<CLK, DIO, DELAY, ERR> TM1637<CLK, DIO, DELAY>
where CLK: OutputPin<Error = ERR>, DIO: OutputPin<Error = ERR>, DELAY: DelayNs,

source

pub fn new( clk: CLK, dio: DIO, delay: DELAY, brightness: Brightness, delay_us: u32, num_positions: u8, ) -> Self

Create a new TM1637 instance.

source

pub fn builder( clk: CLK, dio: DIO, delay: DELAY, ) -> TM1637Builder<CLK, DIO, DELAY>

Create a new TM1637Builder instance.

source

pub async fn init(&mut self) -> Result<(), ERR>

Initialize the display.

Clear the display and set the brightness level.

source

pub async fn on(&mut self) -> Result<(), ERR>

Turn the display on.

source

pub async fn off(&mut self) -> Result<(), ERR>

Turn the display off.

source

pub async fn clear(&mut self) -> Result<(), ERR>

Clear the display.

source

pub async fn write_segments_raw( &mut self, position: u8, bytes: &[u8], ) -> Result<(), ERR>

Write the given bytes to the display starting from the given position.

See TM1637::write_segments_raw_iter.

source

pub async fn write_segments_raw_iter<ITER: Iterator<Item = u8>>( &mut self, position: u8, bytes: ITER, ) -> Result<(), ERR>

Write the given bytes to the display starting from the given position.

§Notes:

Brightness level will not be written to the device on each call. Make sure to call TM1637::write_brightness or TM1637::init to set the brightness level.

source

pub async fn write_brightness( &mut self, brightness: Brightness, ) -> Result<(), ERR>

Set TM1637::brightness and write the brightness level to the display.

source

pub async fn move_segments_raw<const N: usize>( &mut self, position: u8, bytes: &[u8], delay_ms: u32, ) -> Result<(), ERR>

Move all segments across the display starting and ending at position.

If the length of the bytes is less than or equal to TM1637::num_positions - position, the bytes will only be written to the display.

N is the size of the internal window used to move the segments. Please make sure that N is equal to TM1637::num_positions. TM1637::num_positions will be removed in the future in favor of a constant generic parameter representing the number of positions.

source

pub async fn write_ascii_str( &mut self, position: u8, ascii_str: &str, ) -> Result<(), ERR>

Convert an ASCII string to a byte iterator using from_ascii_byte and write the segments to the display using TM1637::write_segments_raw_iter.

Only available when the mappings feature of this library is activated.

§Example

Write the string "Err" to the display:

let mut tm = TM1637::builder(clk_pin, dio_pin, delay)
   .brightness(Brightness::L3)
   .build();

tm.init().ok();

tm.write_ascii_str(0, "Err").ok();

On a 4-digit display, this will look like this:

+---+ +---+ +---+ +---+
| E | | r | | r | |   |
+---+ +---+ +---+ +---+
source

pub async fn move_ascii_str<const N: usize, const M: usize>( &mut self, position: u8, ascii_str: &str, delay_ms: u32, ) -> Result<(), ERR>

Convert an ASCII string to a byte array using from_ascii_byte and move the segments across the display using TM1637::move_segments_raw.

  • N is the size of the internal window used to move the segments. See TM1637::move_segments_raw for more information.
  • M is the maximum number of bytes that can be converted from the ASCII string.

Only available when the mappings feature of this library is activated.

§Example

Move the string "HELLO " across a 4-digit display:

let mut tm = TM1637::builder(clk_pin, dio_pin, delay)
   .brightness(Brightness::L3)
   .build();

tm.init().ok();

// 4 is the actual number of positions on the display.
// 6 is the maximum number of bytes that can be converted from the ASCII string.
// In case of "HELLO ", all six bytes will be converted.
tm.move_ascii_str::<4, 6>(0, "HELLO ", 500).ok();

On a 4-digit display, this will look like this:

+---+ +---+ +---+ +---+
| H | | E | | L | | L |
+---+ +---+ +---+ +---+

+---+ +---+ +---+ +---+
| E | | L | | L | | O |
+---+ +---+ +---+ +---+

+---+ +---+ +---+ +---+
| L | | L | | O | |   |
+---+ +---+ +---+ +---+

+---+ +---+ +---+ +---+
| L | | O | |   | | H |
+---+ +---+ +---+ +---+

+---+ +---+ +---+ +---+
| O | |   | | H | | E |
+---+ +---+ +---+ +---+

+---+ +---+ +---+ +---+
|   | | H | | E | | L |
+---+ +---+ +---+ +---+

+---+ +---+ +---+ +---+
| H | | E | | L | | L |
+---+ +---+ +---+ +---+

Trait Implementations§

source§

impl<CLK: Clone, DIO: Clone, DELAY: Clone> Clone for TM1637<CLK, DIO, DELAY>

source§

fn clone(&self) -> TM1637<CLK, DIO, DELAY>

Returns a copy of the value. Read more
1.6.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<CLK: Debug, DIO: Debug, DELAY: Debug> Debug for TM1637<CLK, DIO, DELAY>

source§

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

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

impl<CLK, DIO, DELAY> Format for TM1637<CLK, DIO, DELAY>
where CLK: Format, DIO: Format, DELAY: Format, Brightness: Format,

source§

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

Writes the defmt representation of self to fmt.

Auto Trait Implementations§

§

impl<CLK, DIO, DELAY> Freeze for TM1637<CLK, DIO, DELAY>
where CLK: Freeze, DIO: Freeze, DELAY: Freeze,

§

impl<CLK, DIO, DELAY> RefUnwindSafe for TM1637<CLK, DIO, DELAY>
where CLK: RefUnwindSafe, DIO: RefUnwindSafe, DELAY: RefUnwindSafe,

§

impl<CLK, DIO, DELAY> Send for TM1637<CLK, DIO, DELAY>
where CLK: Send, DIO: Send, DELAY: Send,

§

impl<CLK, DIO, DELAY> Sync for TM1637<CLK, DIO, DELAY>
where CLK: Sync, DIO: Sync, DELAY: Sync,

§

impl<CLK, DIO, DELAY> Unpin for TM1637<CLK, DIO, DELAY>
where CLK: Unpin, DIO: Unpin, DELAY: Unpin,

§

impl<CLK, DIO, DELAY> UnwindSafe for TM1637<CLK, DIO, DELAY>
where CLK: UnwindSafe, DIO: UnwindSafe, DELAY: UnwindSafe,

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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 = Infallible

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

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

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.