Skip to main content

driver_5011as/
lib.rs

1//! This library provides a very simple driver for the 5011as 7-segment display.
2//! The layout for the pins is the following: https://components101.com/sites/default/files/component_pin/7-segment-display-pin-diagr_0.png
3//!
4//! This crate provides 2 drivers for the 5011as:
5//! - [`LED5011AS`]\: Use this if all your pins have the same type (e.g. [`OutputPin<'_>`])
6//! - [`GenericLED5011AS`]: Use this if your pins don't have the same type (e.g. [`OutputPin<'_>`] and `Flex<'_>` (from esp-hal))
7//!
8//! # Usage
9//!
10//! For this example I'm using an ESP32 with `esp-hal` with the [`LED5011AS`] driver.
11//!
12//! ```rust
13//! // setup pins
14//! let peripherals = esp_hal::init(config);
15//!
16//! let cfg = OutputConfig::default();
17//!
18//! let mut a = Output::new(peripherals.GPIO6, Level::Low, cfg);
19//! let mut b = Output::new(peripherals.GPIO7, Level::Low, cfg);
20//! let mut c = Output::new(peripherals.GPIO8, Level::Low, cfg);
21//! let mut d = Output::new(peripherals.GPIO1, Level::Low, cfg);
22//! let mut e = Output::new(peripherals.GPIO0, Level::Low, cfg);
23//! let mut f = Output::new(peripherals.GPIO5, Level::Low, cfg);
24//! let mut g = Output::new(peripherals.GPIO4, Level::Low, cfg);
25//! let mut dp = Output::new(peripherals.GPIO10, Level::Low, cfg);
26//!
27//! // create LED5011AS
28//! let mut display = LED5011AS::new(
29//!    &mut a,
30//!    &mut b,
31//!    &mut c,
32//!    &mut d,
33//!    &mut e,
34//!    &mut f,
35//!    &mut g,
36//!    &mut dp,
37//! );
38//!
39//! // set a digit
40//! display.set_digit(3)?;
41//! display.set_digit(7)?;  // overrides the '3' so you don't have to clear the display inbetween
42//!
43//! // clear the display
44//! display.clear()?;
45//!
46//! // write a custom figure to the display
47//! display.write_byte(0b01110111)?;    // writes an 'A' to the display
48//! ```
49//!
50//! [`OutputPin<'_>`]: embedded_hal::digital::OutputPin
51
52#![no_std]
53#![allow(clippy::too_many_arguments)]
54
55pub use generic_driver::GenericLED5011AS;
56pub use interface::LED5011ASDriver;
57pub use simple_driver::LED5011AS;
58
59mod generic_driver;
60mod interface;
61mod simple_driver;
62
63const DIGITS: [u8; 10] = [
64    0b0111111, 0b0000110, 0b1011011, 0b1001111, 0b1100110, 0b1101101, 0b1111101, 0b0000111,
65    0b1111111, 0b1101111,
66];