99//! [`mode::GraphicsMode`](mode/graphics/struct.GraphicsMode.html), you would do something like
1010//! this:
1111//!
12- //! ```rust,ignore
13- //! let i2c = I2c::i2c1(/* snip */);
12+ //! ```rust,no_run
13+ //! use sh1106::{prelude::*, Builder};
14+ //! # let i2c = sh1106::test_helpers::I2cStub;
1415//!
1516//! let mut display: GraphicsMode<_> = Builder::new().connect_i2c(i2c).into();
16- //! display.init();
17+ //!
18+ //! display.init().unwrap();
19+ //! display.flush().unwrap();
1720//!
1821//! display.set_pixel(10, 20, 1);
22+ //!
23+ //! display.flush().unwrap();
1924//! ```
2025//!
2126//! See the [example](https://github.com/jamwaffles/sh1106/blob/master/examples/graphics_i2c.rs)
3439//!
3540//! Uses [mode::GraphicsMode] and [embedded_graphics](../embedded_graphics/index.html).
3641//!
37- //! ```rust,no-run
38- //! #![no_std]
39- //!
40- //! extern crate cortex_m;
41- //! extern crate embedded_graphics;
42- //! extern crate embedded_hal as hal;
43- //! extern crate panic_abort;
44- //! extern crate sh1106;
45- //! extern crate stm32f103xx_hal as blue_pill;
46- //!
47- //! use blue_pill::i2c::{DutyCycle, I2c, Mode};
48- //! use blue_pill::prelude::*;
49- //! use embedded_graphics::fonts::Font6x8;
50- //! use embedded_graphics::prelude::*;
51- //! use sh1106::{mode::GraphicsMode, Builder};
52- //!
53- //! fn main() {
54- //! let dp = blue_pill::stm32f103xx::Peripherals::take().unwrap();
55- //! let mut flash = dp.FLASH.constrain();
56- //! let mut rcc = dp.RCC.constrain();
57- //! let clocks = rcc.cfgr.freeze(&mut flash.acr);
58- //! let mut afio = dp.AFIO.constrain(&mut rcc.apb2);
59- //! let mut gpiob = dp.GPIOB.split(&mut rcc.apb2);
60- //! let scl = gpiob.pb8.into_alternate_open_drain(&mut gpiob.crh);
61- //! let sda = gpiob.pb9.into_alternate_open_drain(&mut gpiob.crh);
62- //!
63- //! let i2c = I2c::i2c1(
64- //! dp.I2C1,
65- //! (scl, sda),
66- //! &mut afio.mapr,
67- //! Mode::Fast {
68- //! frequency: 400_000,
69- //! duty_cycle: DutyCycle::Ratio1to1,
70- //! },
71- //! clocks,
72- //! &mut rcc.apb1,
73- //! );
74- //!
75- //! let mut display: GraphicsMode<_> = Builder::new().connect_i2c(i2c).into();
76- //!
77- //! display.init().unwrap();
78- //! display.flush().unwrap();
79- //! display.draw(Font6x8::render_str("Hello world!", 1u8.into()).into_iter());
80- //! display.draw(
81- //! Font6x8::render_str("Hello Rust!")
82- //! .translate(Coord::new(0, 16))
83- //! .into_iter(),
84- //! );
85- //! display.flush().unwrap();
86- //! }
42+ //! ```rust,no_run
43+ //! use embedded_graphics::{
44+ //! mono_font::{ascii::FONT_6X10, MonoTextStyleBuilder},
45+ //! pixelcolor::BinaryColor,
46+ //! prelude::*,
47+ //! text::{Baseline, Text},
48+ //! };
49+ //! use sh1106::{prelude::*, Builder};
50+ //! # let i2c = sh1106::test_helpers::I2cStub;
51+ //!
52+ //! let mut display: GraphicsMode<_> = Builder::new().connect_i2c(i2c).into();
53+ //!
54+ //! display.init().unwrap();
55+ //! display.flush().unwrap();
56+ //!
57+ //! let text_style = MonoTextStyleBuilder::new()
58+ //! .font(&FONT_6X10)
59+ //! .text_color(BinaryColor::On)
60+ //! .build();
61+ //!
62+ //! Text::with_baseline("Hello world!", Point::zero(), text_style, Baseline::Top)
63+ //! .draw(&mut display)
64+ //! .unwrap();
65+ //!
66+ //! Text::with_baseline("Hello Rust!", Point::new(0, 16), text_style, Baseline::Top)
67+ //! .draw(&mut display)
68+ //! .unwrap();
69+ //!
70+ //! display.flush().unwrap();
8771//! ```
8872
8973#![ no_std]
@@ -110,10 +94,12 @@ extern crate embedded_hal as hal;
11094pub mod builder;
11195mod command;
11296pub mod displayrotation;
113- mod displaysize;
97+ pub mod displaysize;
11498pub mod interface;
11599pub mod mode;
116100pub mod prelude;
117101pub mod properties;
102+ #[ doc( hidden) ]
103+ pub mod test_helpers;
118104
119105pub use crate :: builder:: { Builder , NoOutputPin } ;
0 commit comments