Struct tm1637_gpio_driver::TM1637Adapter
source · [−]pub struct TM1637Adapter { /* private fields */ }
Expand description
Adapter between your code and the TM1637 via GPIO interface. You can use the GPIO interface/library that you want. Just provide the corresponding “glue” functions so that this adapter can access GPIO.
Be wise when you choose a value for bit_delay_us
. This delay is important
to ensure that changed signals are actually on the pins. My experience showed
that 100 (µs) is a safe value on the Raspberry Pi.
Implementations
sourceimpl TM1637Adapter
impl TM1637Adapter
sourcepub fn new(
pin_clock_write_fn: Box<dyn Fn(GpioPinValue)>,
pin_dio_write_fn: Box<dyn Fn(GpioPinValue)>,
pin_dio_read_fn: Box<dyn Fn() -> GpioPinValue>,
bit_delay_fn: Box<dyn Fn()>
) -> Self
pub fn new(
pin_clock_write_fn: Box<dyn Fn(GpioPinValue)>,
pin_dio_write_fn: Box<dyn Fn(GpioPinValue)>,
pin_dio_read_fn: Box<dyn Fn() -> GpioPinValue>,
bit_delay_fn: Box<dyn Fn()>
) -> Self
Creates a new object to interact via GPIO with a TM1637. Activates the display and set’s the brightness to the highest value.
pin_clock_write_fn
function to write bit to CLK pinpin_dio_write_fn
function to write bit to DIO pinpin_dio_read_fn
function to read value from DIO pinbit_delay_fn
function that is invoked after a bit has been written to a pin. It depends on your hardware and your GPIO driver. Sometimes 0 is even fine.
sourcepub fn set_display_state(&mut self, ds: DisplayState)
pub fn set_display_state(&mut self, ds: DisplayState)
Sets the display state. The display state is the 3rd bit of the “display control”-command. This setting is not committed until a write operation has been made.
sourcepub fn set_brightness(&mut self, brightness: Brightness)
pub fn set_brightness(&mut self, brightness: Brightness)
Sets the brightness of the screen. The brightness are the lower 3 bits of the “display control”-command. This setting is not committed until a write operation has been made.
sourcepub fn write_segments_raw(&self, segments: &[u8], pos: u8)
pub fn write_segments_raw(&self, segments: &[u8], pos: u8)
Writes all raw segments data beginning at the position into the display registers. It uses auto increment internally to write into all further registers. This functions does an internal check so that not more than 6 registers can be addressed/written.
segments
Raw data describing the bits of the 7 segment display.n
Length of segments array.pos
The start position of the display register. While bytes are written, address is adjusted internally via auto increment. Usually this is 0, if you want to write data to all 7 segment displays.
sourcepub fn write_segment_raw(&self, segments: u8, position: u8)
pub fn write_segment_raw(&self, segments: u8, position: u8)
This uses fixed address mode (see data sheet) internally to write data to a specific position of the display. Position is 0, 1, 2, or 3.
sourcepub fn write_display_state(&self)
pub fn write_display_state(&self)
Send command that sets the display state on the micro controller.
sourcepub const fn encode_digit(digit: u8) -> u8
pub const fn encode_digit(digit: u8) -> u8
Encodes a number/digit from 0 to 9 to it’s bit representation on the display. This is not the char (ASCII) representation. It’s a number/integer.
sourcepub const fn encode_char(c: char) -> u8
pub const fn encode_char(c: char) -> u8
Encodes a char for the 7-segment display. Unknown chars will be a zero byte (space).
Uses mappings::UpCharBits
and mappings::LoCharBits
for the chars. Since there is
no representation for every char in each case (lower, upper) there will be an replacement
for lowercase charts by their uppercase counterpart and vice versa.
sourcepub fn encode_string(str: &str) -> Vec<u8>
pub fn encode_string(str: &str) -> Vec<u8>
Encodes a string for the 7-segment display. This uses
encode_char
for each character.