diff --git a/.cargo/config b/.cargo/config index 3d6d7d45..4d76cba5 100644 --- a/.cargo/config +++ b/.cargo/config @@ -1,8 +1,13 @@ +[build] +target = "thumbv7m-none-eabi" + +#STM32F103C8 examples [target.'cfg(all(target_arch = "arm", target_os = "none"))'] runner = "probe-run --chip STM32F103C8" rustflags = [ "-C", "link-arg=-Tlink.x", ] -[build] -target = "thumbv7m-none-eabi" +#Raspberry pi examples +[target.armv7-unknown-linux-gnueabihf] +linker = "arm-linux-gnueabihf-gcc" \ No newline at end of file diff --git a/.circleci/config.yml b/.circleci/config.yml index 2ec99586..827aef4b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,106 +1,98 @@ -target_steps: &target_steps - docker: - - image: cimg/rust:1.51.0 - steps: - - checkout - - restore_cache: - key: v3-ssd1306-{{ .Environment.CIRCLE_JOB }}-{{ checksum "Cargo.toml" }} - - run: rustup self update - - run: rustup default ${RUST_VERSION:-stable} - - run: rustup component add rustfmt - - run: cargo update - - run: | - SYSROOT=$(rustc --print sysroot) - - if [[ ! "$SYSROOT" =~ "$TARGET" ]]; then - rustup target add $TARGET - else - echo "Target $TARGET is already installed" - fi - - run: ./build.sh - - save_cache: - key: v3-ssd1306-{{ .Environment.CIRCLE_JOB }}-{{ checksum "Cargo.toml" }} - paths: - - ./target - - /home/circleci/.cargo/registry - -version: 2 +version: 2.1 +executors: + rust-image: + docker: + - image: cimg/rust:1.56.0 +commands: + prepare: + description: Prepare the rust image by updating rust and a + parameters: + target: + type: string + default: thumbv7m-none-eabi + steps: + - checkout + - run: rustup self update + - run: rustup target add << parameters.target >> + - run: cargo update jobs: - target-arm-unknown-linux-eabi: - environment: - - TARGET: "arm-unknown-linux-gnueabi" - - DISABLE_EXAMPLES: 1 - <<: *target_steps - - target-armv7-unknown-linux-gnueabihf: - environment: - - TARGET: "armv7-unknown-linux-gnueabihf" - - DISABLE_EXAMPLES: 1 - <<: *target_steps - - target-x86_64-unknown-linux-gnu: - environment: - - TARGET: "x86_64-unknown-linux-gnu" - - DISABLE_EXAMPLES: 1 - <<: *target_steps - - target-x86_64-unknown-linux-musl: - environment: - - TARGET: "x86_64-unknown-linux-musl" - - DISABLE_EXAMPLES: 1 - <<: *target_steps - - target-thumbv6m-none-eabi: - environment: - - TARGET: "thumbv6m-none-eabi" - # Disable example builds as they target thumbv7 and up - - DISABLE_EXAMPLES: 1 - <<: *target_steps - - target-thumbv7em-none-eabi: - environment: - - TARGET: "thumbv7em-none-eabi" - <<: *target_steps - - target-thumbv7em-none-eabihf: - environment: - - TARGET: "thumbv7em-none-eabihf" - <<: *target_steps - - target-thumbv7m-none-eabi: - environment: - - TARGET: "thumbv7m-none-eabi" - <<: *target_steps - -build_jobs: &build_jobs - jobs: - # Raspberry Pi 1 - - target-arm-unknown-linux-eabi - - # Raspberry Pi 2, 3, etc - - target-armv7-unknown-linux-gnueabihf - - # Linux - - target-x86_64-unknown-linux-gnu - - target-x86_64-unknown-linux-musl - - # Bare metal - - target-thumbv6m-none-eabi - - target-thumbv7em-none-eabi - - target-thumbv7em-none-eabihf - - target-thumbv7m-none-eabi - + check_style_guidelines: + executor: rust-image + steps: + - checkout + - run: rustup component add rustfmt + - run: cargo fmt --all -- --check + run_tests: + executor: rust-image + steps: + - checkout + - run: cargo test --lib --target x86_64-unknown-linux-gnu + - run: cargo test --doc --target x86_64-unknown-linux-gnu + build: + executor: rust-image + parameters: + target: + type: string + default: thumbv7m-none-eabi + steps: + - prepare: + target: << parameters.target >> + - run: cargo build --target << parameters.target >> --all-features --release + - run: cargo doc --all-features --target << parameters.target >> + build_STM32F103_examples: + executor: rust-image + steps: + - prepare: + target: thumbv7m-none-eabi + - run: cargo build --target thumbv7m-none-eabi --example bmp_i2c + - run: cargo build --target thumbv7m-none-eabi --example graphics + - run: cargo build --target thumbv7m-none-eabi --example graphics_i2c + - run: cargo build --target thumbv7m-none-eabi --example graphics_i2c_72x40 + - run: cargo build --target thumbv7m-none-eabi --example graphics_i2c_128x32 + - run: cargo build --target thumbv7m-none-eabi --example image_i2c + - run: cargo build --target thumbv7m-none-eabi --example noise_i2c + - run: cargo build --target thumbv7m-none-eabi --example pixelsquare + - run: cargo build --target thumbv7m-none-eabi --example rotation_i2c + - run: cargo build --target thumbv7m-none-eabi --example rtic_brightness + - run: cargo build --target thumbv7m-none-eabi --example rtic_dvd + - run: cargo build --target thumbv7m-none-eabi --example terminal_i2c + - run: cargo build --target thumbv7m-none-eabi --example text_i2c + build_raspberry_pi_examples: + executor: rust-image + steps: + - prepare: + target: armv7-unknown-linux-gnueabihf + - run: sudo apt update + - run: sudo apt install -y gcc-arm-linux-gnueabihf + - run: cargo build --target armv7-unknown-linux-gnueabihf --example text_raspberry_pi workflows: - version: 2 - build_all: - <<: *build_jobs - # # Build every day - # nightly: - # <<: *build_jobs - # triggers: - # - schedule: - # cron: "0 0 * * *" - # filters: - # branches: - # only: - # - master + build_all_targets: + jobs: + - check_style_guidelines + - run_tests + - build: + name: build-target-arm-unknown-linux-gnueabi + target: arm-unknown-linux-gnueabi + - build: + name: build-target-armv7-unknown-linux-gnueabihf + target: armv7-unknown-linux-gnueabihf + - build: + name: build-target-x86_64-unknown-linux-gnu + target: x86_64-unknown-linux-gnu + - build: + name: build-target-x86_64-unknown-linux-musl + target: x86_64-unknown-linux-musl + - build: + name: build-target-thumbv6m-none-eabi + target: thumbv6m-none-eabi + - build: + name: build-target-thumbv7em-none-eabi + target: thumbv7em-none-eabi + - build: + name: build-target-thumbv7em-none-eabihf + target: thumbv7em-none-eabihf + - build: + name: build-target-thumbv7m-none-eabi + target: thumbv7m-none-eabi + - build_STM32F103_examples + - build_raspberry_pi_examples \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 732e4ba6..43d5510a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ ## [Unreleased] - ReleaseDate +- Switched to Rust version 2021 which was stabilized in Rust 1.56 +- Added Raspberry Pi example ## [0.7.0] - 2021-07-08 diff --git a/Cargo.toml b/Cargo.toml index 4edf0bf1..34488e95 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,8 +9,8 @@ name = "ssd1306" readme = "README.md" repository = "https://github.com/jamwaffles/ssd1306" version = "0.7.0" -edition = "2018" -exclude = [ "build.rs", "build.sh", "memory.x", "doc", "*.jpg", "*.png", "*.bmp" ] +edition = "2021" +exclude = [ "build.rs", "memory.x", "doc", "*.jpg", "*.png", "*.bmp" ] [badges] circle-ci = { repository = "jamwaffles/ssd1306", branch = "master" } @@ -26,18 +26,23 @@ display-interface-spi = "0.4.1" embedded-graphics-core = { version = "0.3.2", optional = true } [dev-dependencies] +embedded-graphics = "0.7.1" + +#dev dependencies for stm32f103 examples +[target.'cfg(all(target_arch = "arm", target_os = "none"))'.dev-dependencies] cortex-m = "0.7.2" cortex-m-rt = "0.6.14" cortex-m-rtic = "0.5.6" panic-halt = "0.2.0" cast = { version = "0.2.6", default-features = false } -# Used to load BMP images in various examples tinybmp = "0.3.1" -embedded-graphics = "0.7.1" -# Used by the noise_i2c examples rand = { version = "0.8.4", default-features = false, features = [ "small_rng" ] } stm32f1xx-hal = { version = "0.7.0", features = [ "rt", "stm32f103" ] } +#dev dependencies for raspberry pi examples +[target.'cfg(all(target_arch = "arm", target_os = "linux"))'.dev-dependencies] +linux-embedded-hal = "0.3.2" + [features] default = ["graphics"] graphics = ["embedded-graphics-core"] diff --git a/build.sh b/build.sh deleted file mode 100755 index 78cea182..00000000 --- a/build.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/sh - -# Exit early on error -set -e - -# Print commands as they're run -set -x - -if [ -z $TARGET ]; then - echo "TARGET environment variable required but not set" - - exit 1 -fi - -cargo fmt --all -- --check - -cargo build --target $TARGET --all-features --release - -cargo test --lib --target x86_64-unknown-linux-gnu -cargo test --doc --target x86_64-unknown-linux-gnu - -if [ -z $DISABLE_EXAMPLES ]; then - cargo build --target $TARGET --all-features --examples -fi - -# Remove stale docs - the linkchecker might miss links to old files if they're not removed -cargo clean --doc -cargo clean --doc --target $TARGET - -cargo doc --all-features --target $TARGET diff --git a/examples/text_raspberry_pi.rs b/examples/text_raspberry_pi.rs new file mode 100644 index 00000000..ce8e2eac --- /dev/null +++ b/examples/text_raspberry_pi.rs @@ -0,0 +1,59 @@ +//! Print "Hello world!" and on a 128x64 display +//! connected to the i2c bus of a Raspberry Pi. Before running this example +//! make sure the i2c interface is enabled by configuring the Raspberry Pi: +//! +//! ``` +//! sudo raspi-config +//! ``` +//! +//! Select `3. Interface options` and enable the i2c interface. Reboot +//! the system with `sudo reboot` +//! +//! +//! Wiring the display to the Raspberry pi 4: +//! +//! ``` +//! Pin 1 -> 3.3v power +//! Pin 3 -> GPIO 2 (SDA) +//! Pin 5 -> GPIO 3 (SCL) +//! Pin 6 -> Ground +//! ``` +//! +//! Run this example on a raspberry pi: `cargo run --example text_raspberry_pi` +//! +//! If you want to build this example on a different system, you first have to install +//! the GNU C compiler for the armhf architecture by running +//! `sudo apt install gcc-arm-linux-gnueabihf` +//! +use embedded_graphics::{ + mono_font::{ascii::FONT_6X10, MonoTextStyleBuilder}, + pixelcolor::BinaryColor, + prelude::*, + text::{Baseline, Text}, +}; +use linux_embedded_hal::I2cdev; +use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306}; + +fn main() { + let i2c = I2cdev::new("/dev/i2c-1").unwrap(); + + let interface = I2CDisplayInterface::new(i2c); + let mut display = Ssd1306::new(interface, DisplaySize128x64, DisplayRotation::Rotate0) + .into_buffered_graphics_mode(); + display.init().unwrap(); + + let text_style = MonoTextStyleBuilder::new() + .font(&FONT_6X10) + .text_color(BinaryColor::On) + .build(); + + Text::with_baseline("Hello world!", Point::zero(), text_style, Baseline::Top) + .draw(&mut display) + .unwrap(); + + Text::with_baseline("Hello Rust!", Point::new(0, 16), text_style, Baseline::Top) + .draw(&mut display) + .unwrap(); + + display.flush().unwrap(); +} diff --git a/src/lib.rs b/src/lib.rs index c5c89651..cbe150ee 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -106,7 +106,7 @@ #![deny(unstable_features)] #![deny(unused_import_braces)] #![deny(unused_qualifications)] -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] mod brightness; pub mod command;