-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for 72x40px SSD1306 modules (#101)
* Add 72x40 display size * Add copypasta 72x40 demo * Set COM pin config correctly The display I have at least uses an alternate row connection mapping as opposed to sequential. Without this change, the display skips every second row and makes everything stretched 2x in Y * Add support for display offsets Adds offset of (28, 0) as discovered by this Reddit post: https://www.reddit.com/r/arduino/comments/bup1kf/anyone_got_one_of_these_little_beauties_working/ * Refactor 70x42 example for centered layout * Add changelog entry * Fix example * Update 70x42 example for e-g 0.6.0-alpha.3
- Loading branch information
1 parent
5be7337
commit b453204
Showing
6 changed files
with
163 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
//! Draw a square, circle and triangle on the screen using the `embedded_graphics` crate. | ||
//! | ||
//! This example is for the STM32F103 "Blue Pill" board using I2C1. | ||
//! | ||
//! Wiring connections are as follows for a CRIUS-branded display: | ||
//! | ||
//! ``` | ||
//! Display -> Blue Pill | ||
//! (black) GND -> GND | ||
//! (red) +5V -> VCC | ||
//! (yellow) SDA -> PB9 | ||
//! (green) SCL -> PB8 | ||
//! ``` | ||
//! | ||
//! Run on a Blue Pill with `cargo run --example graphics_i2c`. | ||
|
||
#![no_std] | ||
#![no_main] | ||
|
||
extern crate cortex_m; | ||
extern crate cortex_m_rt as rt; | ||
extern crate panic_semihosting; | ||
extern crate stm32f1xx_hal as hal; | ||
|
||
use cortex_m_rt::{entry, exception, ExceptionFrame}; | ||
use embedded_graphics::{ | ||
pixelcolor::BinaryColor, | ||
prelude::*, | ||
primitives::{Circle, Rectangle, Triangle}, | ||
style::PrimitiveStyleBuilder, | ||
}; | ||
use hal::{ | ||
i2c::{BlockingI2c, DutyCycle, Mode}, | ||
prelude::*, | ||
stm32, | ||
}; | ||
use ssd1306::{prelude::*, Builder}; | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
let dp = stm32::Peripherals::take().unwrap(); | ||
|
||
let mut flash = dp.FLASH.constrain(); | ||
let mut rcc = dp.RCC.constrain(); | ||
|
||
let clocks = rcc.cfgr.freeze(&mut flash.acr); | ||
|
||
let mut afio = dp.AFIO.constrain(&mut rcc.apb2); | ||
|
||
let mut gpiob = dp.GPIOB.split(&mut rcc.apb2); | ||
|
||
let scl = gpiob.pb8.into_alternate_open_drain(&mut gpiob.crh); | ||
let sda = gpiob.pb9.into_alternate_open_drain(&mut gpiob.crh); | ||
|
||
let i2c = BlockingI2c::i2c1( | ||
dp.I2C1, | ||
(scl, sda), | ||
&mut afio.mapr, | ||
Mode::Fast { | ||
frequency: 400_000.hz(), | ||
duty_cycle: DutyCycle::Ratio2to1, | ||
}, | ||
clocks, | ||
&mut rcc.apb1, | ||
1000, | ||
10, | ||
1000, | ||
1000, | ||
); | ||
|
||
let mut disp: GraphicsMode<_> = Builder::new() | ||
.size(DisplaySize::Display72x40) | ||
.connect_i2c(i2c) | ||
.into(); | ||
|
||
disp.init().unwrap(); | ||
|
||
let size = 10; | ||
let offset = Point::new(10, (42 / 2) - (size / 2) - 1); | ||
let spacing = size + 10; | ||
|
||
let style = PrimitiveStyleBuilder::new() | ||
.stroke_width(1) | ||
.stroke_color(BinaryColor::On) | ||
.build(); | ||
|
||
// screen outline | ||
// default display size is 128x64 if you don't pass a _DisplaySize_ | ||
// enum to the _Builder_ struct | ||
Rectangle::new(Point::new(0, 0), Point::new(71, 39)) | ||
.into_styled(style) | ||
.draw(&mut disp); | ||
|
||
// Triangle | ||
Triangle::new( | ||
Point::new(0, size), | ||
Point::new(size / 2, 0), | ||
Point::new(size, size), | ||
) | ||
.translate(offset) | ||
.into_styled(style) | ||
.draw(&mut disp); | ||
|
||
// Move over to next position | ||
let offset = offset + Point::new(spacing, 0); | ||
|
||
// Draw a square | ||
Rectangle::new(Point::new(0, 0), Point::new(size, size)) | ||
.translate(offset) | ||
.into_styled(style) | ||
.draw(&mut disp); | ||
|
||
// Move over a bit more | ||
let offset = offset + Point::new(spacing, 0); | ||
|
||
// Circle | ||
Circle::new(Point::new(size / 2, size / 2), size as u32 / 2) | ||
.translate(offset) | ||
.into_styled(style) | ||
.draw(&mut disp); | ||
|
||
disp.flush().unwrap(); | ||
|
||
loop {} | ||
} | ||
|
||
#[exception] | ||
fn HardFault(ef: &ExceptionFrame) -> ! { | ||
panic!("{:#?}", ef); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters