pub struct HT16K33<I2C> { /* private fields */ }
Expand description
The HT16K33 state and configuration.
Implementations
sourceimpl<I2C, E> HT16K33<I2C>where
I2C: Write<Error = E> + WriteRead<Error = E>,
impl<I2C, E> HT16K33<I2C>where
I2C: Write<Error = E> + WriteRead<Error = E>,
sourcepub fn new<L>(i2c: I2C, address: u8, logger: L) -> Selfwhere
L: Into<Option<Logger>>,
pub fn new<L>(i2c: I2C, address: u8, logger: L) -> Selfwhere
L: Into<Option<Logger>>,
Create an HT16K33 driver.
Arguments
i2c
- The I2C device to communicate with the HT16K33 chip.logger
- A logging instance.
Notes
logger = None
will log to the slog-stdlog
drain. This makes the library
effectively work the same as if it was just using log
instead of slog
.
Examples
// NOTE: `None` is used for the Logger in these examples for convenience,
// in practice using an actual logger is preferred.
extern crate ht16k33;
use ht16k33::i2c_mock::I2cMock;
use ht16k33::HT16K33;
// Create an I2C device.
let mut i2c = I2cMock::new(None);
// The I2C device address.
let address = 0u8;
let mut ht16k33 = HT16K33::new(i2c, address, None);
sourcepub fn initialize(&mut self) -> Result<(), E>
pub fn initialize(&mut self) -> Result<(), E>
Initialize the HT16K33.
Examples
let mut ht16k33 = HT16K33::new(i2c, address, None);
ht16k33.initialize()?;
sourcepub fn destroy(self) -> I2C
pub fn destroy(self) -> I2C
Return the given I2C device, making this device unusable.
Examples
let mut ht16k33 = HT16K33::new(i2c, address, None);
i2c = ht16k33.destroy();
sourcepub fn display_buffer(&self) -> &[DisplayData; 16]
pub fn display_buffer(&self) -> &[DisplayData; 16]
Return the current display buffer.
Examples
let mut ht16k33 = HT16K33::new(i2c, address, None);
let &buffer = ht16k33.display_buffer();
sourcepub fn oscillator(&self) -> &Oscillator
pub fn oscillator(&self) -> &Oscillator
Return the current oscillator state.
Examples
let mut ht16k33 = HT16K33::new(i2c, address, None);
let oscillator = ht16k33.oscillator();
sourcepub fn display(&self) -> &Display
pub fn display(&self) -> &Display
Return the current display state.
Examples
let mut ht16k33 = HT16K33::new(i2c, address, None);
let display = ht16k33.display();
sourcepub fn dimming(&self) -> &Dimming
pub fn dimming(&self) -> &Dimming
Return the current dimming state.
Examples
let mut ht16k33 = HT16K33::new(i2c, address, None);
let dimming = ht16k33.dimming();
sourcepub fn update_display_buffer(&mut self, location: LedLocation, enabled: bool)
pub fn update_display_buffer(&mut self, location: LedLocation, enabled: bool)
Enable/disable an LED address in the display buffer.
The buffer must be written using write_display_buffer() for the change to be displayed.
Arguments
location
- The LED location to update.enabled
- Set the LED on (true) or off (false).
Examples
use ht16k33::LedLocation;
let mut ht16k33 = HT16K33::new(i2c, address, None);
let led_location = LedLocation::new(0, 0)?;
ht16k33.update_display_buffer(led_location, true);
sourcepub fn clear_display_buffer(&mut self)
pub fn clear_display_buffer(&mut self)
Clear contents of the display buffer.
The buffer must be written using write_display_buffer() for the change to be displayed.
Examples
let mut ht16k33 = HT16K33::new(i2c, address, None);
ht16k33.clear_display_buffer();
sourcepub fn set_oscillator(&mut self, oscillator: Oscillator) -> Result<(), E>
pub fn set_oscillator(&mut self, oscillator: Oscillator) -> Result<(), E>
sourcepub fn set_display(&mut self, display: Display) -> Result<(), E>
pub fn set_display(&mut self, display: Display) -> Result<(), E>
sourcepub fn set_dimming(&mut self, dimming: Dimming) -> Result<(), E>
pub fn set_dimming(&mut self, dimming: Dimming) -> Result<(), E>
sourcepub fn write_display_buffer(&mut self) -> Result<(), E>
pub fn write_display_buffer(&mut self) -> Result<(), E>
Write the display buffer to the HT16K33 chip.
Examples
let mut ht16k33 = HT16K33::new(i2c, address, None);
ht16k33.write_display_buffer();
sourcepub fn read_display_buffer(&mut self) -> Result<(), E>
pub fn read_display_buffer(&mut self) -> Result<(), E>
Read the display buffer from the HT16K33 chip.
Examples
let mut ht16k33 = HT16K33::new(i2c, address, None);
ht16k33.read_display_buffer();