Skip to content

Commit ae5bf46

Browse files
authored
Big cleanup/updates (#1)
* Package upgrades, fix lib code * Fix/update all examples * Simplify crate structure a bunch Need to update/populate docs but this compiles at least * Fix examples * Test lib/doc examples in CI * Check doc links in CI * Nicer message when TARGET is undefined * Check formatting in CI * Add nightly rustfmt config for doc formatting * Fix doc tests * Move module docs onto structs Makes things much more discoverable when browsing * Update docs to be more accurate * Update and test README example in CI * Add changelog * fixup! Check doc links in CI * Add custom error type for more flexibility * Remove builder, consolidate properties/display.rs * Add basic migration guide to changelog/readme * Ignore README examples, fix copypasta * Fix bugs in command definitions * Improve display init procedure * Fix rotation example * Polish BMP and rotation examples * Use e-g Triangle primitive instead of lines * Bump changelog * Run nightly cargo format * Remove debugging/dev examples * Update README example
1 parent 96757b9 commit ae5bf46

29 files changed

+889
-887
lines changed

.travis.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,18 @@ matrix:
3838
- rust: nightly
3939

4040
install:
41+
- pip install linkchecker --user
4142
- rustup component add rust-src
43+
- rustup component add rustfmt
44+
- rustup target add thumbv7m-none-eabi
4245
- |
43-
SYSROOT=$(rustc --print sysroot)
46+
SYSROOT=$(rustc --print sysroot)
4447
45-
if [[ ! "$SYSROOT" =~ "$TARGET" ]]; then
46-
rustup target add $TARGET
47-
else
48-
echo "Target $TARGET is already installed"
49-
fi
48+
if [[ ! "$SYSROOT" =~ "$TARGET" ]]; then
49+
rustup target add $TARGET
50+
else
51+
echo "Target $TARGET is already installed"
52+
fi
5053
- source ~/.cargo/env || true
5154

5255
script:

CHANGELOG.md

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# Changelog
2+
3+
`ssd1331` is a Rust driver for the SSD1331 OLED display driver/module. It implements the
4+
`embedded-hal` traits to allow easy integration with embedded Rust projects using an SPI interface.
5+
6+
## Unreleased
7+
8+
- None
9+
10+
### Added
11+
12+
- None
13+
14+
### Changed
15+
16+
- None
17+
18+
### Fixed
19+
20+
- None
21+
22+
### Security
23+
24+
- None
25+
26+
## 0.2.0-alpha.1
27+
28+
The driver has been drastically simplified with removal of the `RawMode` and `GraphicsMode` structs, as well as the `Builder`.
29+
30+
[embedded-graphics](https://crates.io/crates/embedded-graphics) is also upgraded to version `0.6.0-alpha.2`, so there may be breaking changes around uses of embedded-graphics.
31+
32+
### Migrating from 0.1 to 0.2
33+
34+
Version 0.1.x
35+
36+
```rust
37+
use ssd1331::{prelude::*, Builder};
38+
39+
let mut disp: GraphicsMode<_> = Builder::new().connect_spi(spi, dc).into();
40+
41+
disp.reset(&mut rst, &mut delay);
42+
disp.init().unwrap();
43+
disp.flush().unwrap();
44+
45+
disp.get_dimensions();
46+
disp.get_rotation();
47+
```
48+
49+
Version 0.2.x
50+
51+
```rust
52+
use ssd1331::{Ssd1331, DisplayRotation};
53+
54+
let mut disp = Ssd1331::new(spi, dc, DisplayRotation::Rotate0);
55+
56+
disp.reset(&mut rst, &mut delay).unwrap();
57+
disp.init().unwrap();
58+
disp.flush().unwrap();
59+
60+
disp.dimensions();
61+
disp.rotation();
62+
```
63+
64+
### Added
65+
66+
- Added `ssd1331::Error` enum with pin (if DC pin fails to set) and communication error (if SPI write fails) variants. The return type of fallible methods has changed from `Result<(), ()>` to `Result<(), ssd1331::Error<CommE, PinE>>`. `CommE` and `PinE` default to `()` so no user code changes should be required.
67+
68+
### Changed
69+
70+
- Upgraded [embedded-graphics](https://crates.io/crates/embedded-graphics) to 0.6.0-alpha.2
71+
- **(breaking)** `display.get_dimensions()` is renamed to `display.dimensions()`
72+
- **(breaking)** The `Builder` struct has been removed. Use `Ssd1331::new()` instead. Code that looked like this:
73+
74+
```rust
75+
use ssd1331::{prelude::*, Builder};
76+
77+
let mut disp: GraphicsMode<_> = Builder::new().connect_spi(spi, dc).into();
78+
79+
disp.reset(&mut rst, &mut delay);
80+
disp.init().unwrap();
81+
disp.flush().unwrap();
82+
```
83+
84+
Should now look like this:
85+
86+
```rust
87+
use ssd1331::{Ssd1331, DisplayRotation};
88+
89+
let mut disp = Ssd1331::new(spi, dc, DisplayRotation::Rotate0);
90+
91+
disp.reset(&mut rst, &mut delay).unwrap();
92+
disp.init().unwrap();
93+
disp.flush().unwrap();
94+
```
95+
96+
- **(breaking)** Crate import structure has been simplified. Imports that looked like this:
97+
98+
```rust
99+
use ssd1331::prelude::*;
100+
use ssd1331::Builder;
101+
```
102+
103+
Should now look like this:
104+
105+
```rust
106+
use ssd1331::{Ssd1331, DisplayRotation};
107+
```
108+
109+
See above items about removal of `Builder` struct.
110+
111+
### Deprecated
112+
113+
- None
114+
115+
### Removed
116+
117+
- **(breaking)** Removed `RawMode` and `GraphicsMode` traits. The `.set_pixel()` and `.draw()` methods can now be used directly on the `Ssd1331` struct.
118+
- **(breaking)** Removed `Builder` struct.
119+
120+
### Fixed
121+
122+
- None
123+
124+
### Security
125+
126+
- None

Cargo.toml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,24 @@ branch = "master"
1616
repository = "jamwaffles/ssd1331"
1717

1818
[dependencies]
19-
embedded-hal = "0.2.2"
19+
embedded-hal = "0.2.3"
2020

2121
[dependencies.embedded-graphics]
2222
optional = true
23-
version = "0.4.5"
23+
version = "0.6.0-alpha.2"
24+
25+
# Turns `bmp` feature on in examples to enable `ImageBmp`
26+
[dev-dependencies.embedded-graphics]
27+
version = "0.6.0-alpha.2"
28+
features = ["bmp"]
2429

2530
[dev-dependencies]
26-
cortex-m = "0.5.8"
27-
cortex-m-rt = "0.6.7"
28-
panic-semihosting = "0.5.1"
31+
cortex-m = "0.6.1"
32+
cortex-m-rt = "0.6.11"
33+
panic-semihosting = "0.5.3"
2934

3035
[dev-dependencies.stm32f1xx-hal]
31-
version = "0.2.0"
36+
version = "0.5.2"
3237
features = [ "rt", "stm32f103" ]
3338

3439
[features]

README.md

Lines changed: 59 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,22 @@ You can also export images directly from The GIMP by saving as `.bmp` and choosi
2323

2424
## [Examples](examples)
2525

26-
Load a BMP and display it in the center of the display. From [`examples/bmp.rs`](examples/bmp.rs):
26+
Load a BMP image of the Rust logo and display it in the center of the display. From
27+
[`examples/bmp.rs`](examples/bmp.rs):
2728

28-
```rust
29+
```rust,ignore
2930
#![no_std]
3031
#![no_main]
3132
32-
extern crate cortex_m;
33-
extern crate cortex_m_rt as rt;
34-
extern crate panic_semihosting;
35-
extern crate stm32f1xx_hal as hal;
36-
3733
use cortex_m_rt::ExceptionFrame;
3834
use cortex_m_rt::{entry, exception};
39-
use embedded_graphics::image::Image1BPP;
40-
use embedded_graphics::prelude::*;
41-
use hal::i2c::{BlockingI2c, DutyCycle, Mode};
42-
use hal::prelude::*;
43-
use hal::stm32;
44-
use ssd1331::prelude::*;
45-
use ssd1331::Builder;
35+
use embedded_graphics::{geometry::Point, image::ImageBmp, prelude::*};
36+
use panic_semihosting as _;
37+
use ssd1331::{Ssd1331, DisplayRotation::Rotate0};
38+
use stm32f1xx_hal::delay::Delay;
39+
use stm32f1xx_hal::prelude::*;
40+
use stm32f1xx_hal::spi::{Mode, Phase, Polarity, Spi};
41+
use stm32f1xx_hal::stm32;
4642
4743
#[entry]
4844
fn main() -> ! {
@@ -59,6 +55,8 @@ fn main() -> ! {
5955
let sck = gpioa.pa5.into_alternate_push_pull(&mut gpioa.crl);
6056
let miso = gpioa.pa6;
6157
let mosi = gpioa.pa7.into_alternate_push_pull(&mut gpioa.crl);
58+
let mut delay = Delay::new(cp.SYST, clocks);
59+
let mut rst = gpiob.pb0.into_push_pull_output(&mut gpiob.crl);
6260
let dc = gpiob.pb1.into_push_pull_output(&mut gpiob.crl);
6361
6462
let spi = Spi::spi1(
@@ -74,19 +72,24 @@ fn main() -> ! {
7472
&mut rcc.apb2,
7573
);
7674
77-
let mut disp: GraphicsMode<_> = Builder::new().connect_spi(spi, dc).into();
75+
let mut disp = Ssd1331::new(spi, dc, DisplayRotation::Rotate0);
7876
77+
disp.reset(&mut rst, &mut delay).unwrap();
7978
disp.init().unwrap();
8079
disp.flush().unwrap();
8180
82-
// 16BPP, RGB565-format BMP image
81+
let (w, h) = disp.dimensions();
82+
8383
let im = ImageBmp::new(include_bytes!("./rust-pride.bmp")).unwrap();
8484
85-
let centered = im.translate(Coord::new((96 - im.width() as i32) / 2, 0));
85+
// Position image in the center of the display
86+
let moved = im.translate(Point::new(
87+
(w as u32 - im.width()) as i32 / 2,
88+
(h as u32 - im.height()) as i32 / 2,
89+
));
8690
87-
disp.draw(centered.into_iter());
91+
disp.draw(moved.into_iter());
8892
89-
disp.draw(im.into_iter());
9093
disp.flush().unwrap();
9194
9295
loop {}
@@ -96,18 +99,51 @@ fn main() -> ! {
9699
fn HardFault(ef: &ExceptionFrame) -> ! {
97100
panic!("{:#?}", ef);
98101
}
99-
100102
```
101103

102104
![Rust rainbow demo image.](readme_pride.jpg?raw=true)
103105

106+
## Migrating from 0.1 to 0.2
107+
108+
The full changelog can be found [here](CHANGELOG.md). A tl;dr version is shown below.
109+
110+
Version 0.1.x
111+
112+
```rust,ignore
113+
use ssd1331::{prelude::*, Builder};
114+
115+
let mut disp: GraphicsMode<_> = Builder::new().connect_spi(spi, dc).into();
116+
117+
disp.reset(&mut rst, &mut delay);
118+
disp.init().unwrap();
119+
disp.flush().unwrap();
120+
121+
disp.get_dimensions();
122+
disp.get_rotation();
123+
```
124+
125+
Version 0.2.x
126+
127+
```rust,ignore
128+
use ssd1331::{Ssd1331, DisplayRotation};
129+
130+
let mut disp = Ssd1331::new(spi, dc, DisplayRotation::Rotate0);
131+
132+
disp.reset(&mut rst, &mut delay).unwrap();
133+
disp.init().unwrap();
134+
disp.flush().unwrap();
135+
136+
disp.dimensions();
137+
disp.rotation();
138+
```
139+
104140
## License
105141

106142
Licensed under either of
107143

108-
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or
109-
http://www.apache.org/licenses/LICENSE-2.0)
110-
- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
144+
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or
145+
http://www.apache.org/licenses/LICENSE-2.0)
146+
- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
111147

112148
at your option.
113149

build.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use std::env;
2-
use std::fs::File;
3-
use std::io::Write;
4-
use std::path::PathBuf;
1+
use std::{env, fs::File, io::Write, path::PathBuf};
52

63
pub fn main() {
74
// Put the linker script somewhere the linker can find it

build.sh

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
11
#!/bin/sh
22

3+
# Exit early on error
34
set -e
45

6+
# Print commands as they're run
7+
set -x
8+
9+
if [ -z $TARGET ]; then
10+
echo "TARGET environment variable required but not set"
11+
12+
exit 1
13+
fi
14+
15+
cargo fmt --all -- --check
16+
517
cargo build --target $TARGET --all-features --release
618

19+
cargo test --lib --target x86_64-unknown-linux-gnu
20+
21+
# Always test docs against thumbv7m target as the complete readme example needs to compile against it
22+
cargo test --doc --target thumbv7m-none-eabi
23+
724
if [ -z $DISABLE_EXAMPLES ]; then
825
cargo build --target $TARGET --all-features --examples
9-
fi
26+
fi
27+
28+
cargo doc --all-features --target $TARGET
29+
30+
linkchecker target/$TARGET/doc/ssd1331/index.html

0 commit comments

Comments
 (0)