Skip to content

Commit dd41e80

Browse files
authored
Upgrade to embedded-graphics 0.6.0 (#6)
* Upgrade to e-g 0.6.0 * Changelog entry * Install fewer deps * Fmt * Add associated error type * Fix examples * Fix doc examples
1 parent 5df9dc9 commit dd41e80

File tree

10 files changed

+66
-41
lines changed

10 files changed

+66
-41
lines changed

.circleci/config.yml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ target_steps: &target_steps
55
- checkout
66
- restore_cache:
77
key: v1-ssd1331-{{ .Environment.CIRCLE_JOB }}-{{ checksum "Cargo.toml" }}
8-
- run: sudo apt install -qq libsdl2-dev python-pip
9-
- run: sudo pip install linkchecker
8+
- run: sudo apt install -qq linkchecker
109
- run: rustup default ${RUST_VERSION:-stable}
1110
- run: rustup component add rustfmt
1211
- run: |
@@ -28,48 +27,48 @@ version: 2
2827
jobs:
2928
target-arm-unknown-linux-eabi:
3029
environment:
31-
- TARGET: "arm-unknown-linux-gnueabi"
30+
- TARGET: 'arm-unknown-linux-gnueabi'
3231
- DISABLE_EXAMPLES: 1
3332
<<: *target_steps
3433

3534
target-armv7-unknown-linux-gnueabihf:
3635
environment:
37-
- TARGET: "armv7-unknown-linux-gnueabihf"
36+
- TARGET: 'armv7-unknown-linux-gnueabihf'
3837
- DISABLE_EXAMPLES: 1
3938
<<: *target_steps
4039

4140
target-x86_64-unknown-linux-gnu:
4241
environment:
43-
- TARGET: "x86_64-unknown-linux-gnu"
42+
- TARGET: 'x86_64-unknown-linux-gnu'
4443
- DISABLE_EXAMPLES: 1
4544
<<: *target_steps
4645

4746
target-x86_64-unknown-linux-musl:
4847
environment:
49-
- TARGET: "x86_64-unknown-linux-musl"
48+
- TARGET: 'x86_64-unknown-linux-musl'
5049
- DISABLE_EXAMPLES: 1
5150
<<: *target_steps
5251

5352
target-thumbv6m-none-eabi:
5453
environment:
55-
- TARGET: "thumbv6m-none-eabi"
54+
- TARGET: 'thumbv6m-none-eabi'
5655
# Disable example builds as they target thumbv7 and up
5756
- DISABLE_EXAMPLES: 1
5857
<<: *target_steps
5958

6059
target-thumbv7em-none-eabi:
6160
environment:
62-
- TARGET: "thumbv7em-none-eabi"
61+
- TARGET: 'thumbv7em-none-eabi'
6362
<<: *target_steps
6463

6564
target-thumbv7em-none-eabihf:
6665
environment:
67-
- TARGET: "thumbv7em-none-eabihf"
66+
- TARGET: 'thumbv7em-none-eabihf'
6867
<<: *target_steps
6968

7069
target-thumbv7m-none-eabi:
7170
environment:
72-
- TARGET: "thumbv7m-none-eabi"
71+
- TARGET: 'thumbv7m-none-eabi'
7372
<<: *target_steps
7473

7574
build_jobs: &build_jobs
@@ -100,7 +99,7 @@ workflows:
10099
<<: *build_jobs
101100
triggers:
102101
- schedule:
103-
cron: "0 0 * * *"
102+
cron: '0 0 * * *'
104103
filters:
105104
branches:
106105
only:

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ projects using an SPI interface.
88

99
## [Unreleased] - ReleaseDate
1010

11+
### Changed
12+
13+
- **(breaking)** [#6](https://github.com/jamwaffles/ssd1331/pull/6) Upgrade to embedded-graphics 0.6.0
14+
1115
### Fixed
1216

1317
- [#4](https://github.com/jamwaffles/ssd1331/pull/4) Guard against negative pixel coordinates panicking `draw_pixel()` calls.

Cargo.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,16 @@ embedded-hal = "0.2.3"
2222

2323
[dependencies.embedded-graphics]
2424
optional = true
25-
version = "=0.6.0-alpha.3"
25+
version = "0.6.0"
2626

2727
[dev-dependencies]
2828
cortex-m = "0.6.1"
2929
cortex-m-rt = "0.6.11"
3030
panic-semihosting = "0.5.3"
3131

32-
# Turns `bmp` feature on in examples to enable `ImageBmp`
33-
[dev-dependencies.embedded-graphics]
34-
version = "=0.6.0-alpha.3"
35-
features = ["bmp"]
32+
[dev-dependencies.tinybmp]
33+
version = "0.2.2"
34+
features = [ "graphics" ]
3635

3736
[dev-dependencies.stm32f1xx-hal]
3837
version = "0.5.2"

examples/bmp.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#![no_main]
2424

2525
use cortex_m_rt::{entry, exception, ExceptionFrame};
26-
use embedded_graphics::{geometry::Point, image::ImageBmp, prelude::*};
26+
use embedded_graphics::{geometry::Point, image::Image, pixelcolor::Rgb565, prelude::*};
2727
use panic_semihosting as _;
2828
use ssd1331::{DisplayRotation, Ssd1331};
2929
use stm32f1xx_hal::{
@@ -32,6 +32,7 @@ use stm32f1xx_hal::{
3232
spi::{Mode, Phase, Polarity, Spi},
3333
stm32,
3434
};
35+
use tinybmp::Bmp;
3536

3637
#[entry]
3738
fn main() -> ! {
@@ -79,15 +80,17 @@ fn main() -> ! {
7980

8081
let (w, h) = disp.dimensions();
8182

82-
let im = ImageBmp::new(include_bytes!("./rust-pride.bmp")).unwrap();
83+
let bmp = Bmp::from_slice(include_bytes!("./rust-pride.bmp")).unwrap();
84+
85+
let im: Image<Bmp, Rgb565> = Image::new(&bmp, Point::zero());
8386

8487
// Position image in the center of the display
8588
let moved = im.translate(Point::new(
86-
(w as u32 - im.width()) as i32 / 2,
87-
(h as u32 - im.height()) as i32 / 2,
89+
(w as u32 - bmp.width()) as i32 / 2,
90+
(h as u32 - bmp.height()) as i32 / 2,
8891
));
8992

90-
moved.draw(&mut disp);
93+
moved.draw(&mut disp).unwrap();
9194

9295
disp.flush().unwrap();
9396

examples/graphics.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ fn main() -> ! {
9292
.stroke_width(1)
9393
.build(),
9494
)
95-
.draw(&mut disp);
95+
.draw(&mut disp)
96+
.unwrap();
9697

9798
Rectangle::new(Point::new(36, 16), Point::new(36 + 16, 16 + 16))
9899
.into_styled(
@@ -101,7 +102,8 @@ fn main() -> ! {
101102
.stroke_width(1)
102103
.build(),
103104
)
104-
.draw(&mut disp);
105+
.draw(&mut disp)
106+
.unwrap();
105107

106108
Circle::new(Point::new(72, 16 + 8), 8)
107109
.into_styled(
@@ -110,7 +112,8 @@ fn main() -> ! {
110112
.stroke_width(1)
111113
.build(),
112114
)
113-
.draw(&mut disp);
115+
.draw(&mut disp)
116+
.unwrap();
114117

115118
disp.flush().unwrap();
116119

examples/image.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626
#![no_main]
2727

2828
use cortex_m_rt::{entry, exception, ExceptionFrame};
29-
use embedded_graphics::{image::ImageLE, prelude::*};
29+
use embedded_graphics::{
30+
image::{Image, ImageRawLE},
31+
prelude::*,
32+
};
3033
use panic_semihosting as _;
3134
use ssd1331::{DisplayRotation::Rotate0, Ssd1331};
3235
use stm32f1xx_hal::{
@@ -82,10 +85,11 @@ fn main() -> ! {
8285

8386
// Loads an 86x64px image encoded in LE (Little Endian) format. This image is a 16BPP image of
8487
// the Rust mascot, Ferris.
85-
let im = ImageLE::new(include_bytes!("./ferris.raw"), 86, 64)
86-
.translate(Point::new((96 - 86) / 2, 0));
88+
let im = ImageRawLE::new(include_bytes!("./ferris.raw"), 86, 64);
8789

88-
im.draw(&mut disp);
90+
Image::new(&im, Point::new((96 - 86) / 2, 0))
91+
.draw(&mut disp)
92+
.unwrap();
8993

9094
disp.flush().unwrap();
9195

examples/rotation.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#![no_main]
2727

2828
use cortex_m_rt::{entry, exception, ExceptionFrame};
29-
use embedded_graphics::{image::ImageLE, pixelcolor::BinaryColor, prelude::*};
29+
use embedded_graphics::{image::ImageRawLE, pixelcolor::BinaryColor, prelude::*};
3030
use panic_semihosting as _;
3131
use ssd1331::{DisplayRotation, Ssd1331};
3232
use stm32f1xx_hal::{
@@ -86,12 +86,13 @@ fn main() -> ! {
8686

8787
// Load a 1BPP 64x64px image with LE (Little Endian) encoding of the Rust logo, white foreground
8888
// black background
89-
let im = ImageLE::<BinaryColor>::new(include_bytes!("./rust.raw"), 64, 64);
89+
let im = ImageRawLE::<BinaryColor>::new(include_bytes!("./rust.raw"), 64, 64);
9090

9191
// Map on/off image colours to Rgb565::BLACK/Rgb565::WHITE
9292
im.into_iter()
9393
.map(|p| Pixel(p.0, p.1.into()))
94-
.draw(&mut disp);
94+
.draw(&mut disp)
95+
.unwrap();
9596

9697
disp.flush().unwrap();
9798

examples/text.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,13 @@ fn main() -> ! {
9292
.text_color(Rgb565::WHITE)
9393
.build(),
9494
)
95-
.draw(&mut disp);
95+
.draw(&mut disp)
96+
.unwrap();
9697

9798
Text::new("Hello Rust!", Point::new(0, 16))
9899
.into_styled(TextStyleBuilder::new(Font6x8).text_color(rust).build())
99-
.draw(&mut disp);
100+
.draw(&mut disp)
101+
.unwrap();
100102

101103
// Macros can also be used
102104
egtext!(
@@ -109,7 +111,8 @@ fn main() -> ! {
109111
)
110112
)
111113
.translate(Point::new(0, 24))
112-
.draw(&mut disp);
114+
.draw(&mut disp)
115+
.unwrap();
113116

114117
disp.flush().unwrap();
115118

src/display.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const BUF_SIZE: usize = 96 * 64 * 2;
2222
/// use embedded_graphics::{
2323
/// fonts::{Font6x8, Text},
2424
/// geometry::Point,
25-
/// image::ImageLE,
25+
/// image::{Image, ImageRawLE},
2626
/// pixelcolor::Rgb565,
2727
/// prelude::*,
2828
/// primitives::{Circle, Line, Rectangle},
@@ -36,7 +36,9 @@ const BUF_SIZE: usize = 96 * 64 * 2;
3636
/// let dc = Pin;
3737
///
3838
/// let mut display = Ssd1331::new(spi, dc, Rotate0);
39-
/// let image = ImageLE::new(include_bytes!("../examples/ferris.raw"), 86, 64);
39+
/// let raw = ImageRawLE::new(include_bytes!("../examples/ferris.raw"), 86, 64);
40+
///
41+
/// let image: Image<ImageRawLE<Rgb565>, Rgb565> = Image::new(&raw, Point::zero());
4042
///
4143
/// // Initialise and clear the display
4244
/// display.init().unwrap();
@@ -369,20 +371,24 @@ where
369371
SPI: hal::blocking::spi::Write<u8>,
370372
DC: OutputPin,
371373
{
372-
fn draw_pixel(&mut self, pixel: drawable::Pixel<Rgb565>) {
374+
type Error = core::convert::Infallible;
375+
376+
fn draw_pixel(&mut self, pixel: drawable::Pixel<Rgb565>) -> Result<(), Self::Error> {
373377
let drawable::Pixel(pos, color) = pixel;
374378

375379
// Guard against negative values. All positive i32 values from `pos` can be represented in
376380
// the `u32`s that `set_pixel()` accepts.
377381
if pos.x < 0 || pos.y < 0 {
378-
return;
382+
return Ok(());
379383
}
380384

381385
self.set_pixel(
382386
(pos.x).try_into().unwrap(),
383387
(pos.y).try_into().unwrap(),
384388
RawU16::from(color).into_inner(),
385389
);
390+
391+
Ok(())
386392
}
387393

388394
fn size(&self) -> Size {

src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@
4646
//!
4747
//! ```rust
4848
//! # use ssd1331::test_helpers::{Spi, Pin};
49-
//! use embedded_graphics::{image::ImageBmp, prelude::*};
49+
//! use embedded_graphics::{image::Image, pixelcolor::Rgb565, prelude::*};
5050
//! use ssd1331::{DisplayRotation::Rotate0, Ssd1331};
51+
//! use tinybmp::Bmp;
5152
//!
5253
//! // Set up SPI interface and digital pin. These are stub implementations used in examples.
5354
//! let spi = Spi;
@@ -56,10 +57,12 @@
5657
//! let mut display = Ssd1331::new(spi, dc, Rotate0);
5758
//! display.init();
5859
//!
59-
//! let im = ImageBmp::new(include_bytes!("../examples/rust-pride.bmp")).unwrap();
60+
//! let bmp = Bmp::from_slice(include_bytes!("../examples/rust-pride.bmp")).unwrap();
61+
//!
62+
//! let im: Image<Bmp, Rgb565> = Image::new(&bmp, Point::zero());
6063
//!
6164
//! // Center the image on the display
62-
//! let moved = im.translate(Point::new((96 - im.width() as i32) / 2, 0));
65+
//! let moved = im.translate(Point::new((96 - bmp.width() as i32) / 2, 0));
6366
//!
6467
//! moved.draw(&mut display);
6568
//!

0 commit comments

Comments
 (0)