Skip to content

Add Raspberry Pi example #160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -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"
200 changes: 96 additions & 104 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<!-- next-header -->

## [Unreleased] - ReleaseDate
- Switched to Rust version 2021 which was stabilized in Rust 1.56
- Added Raspberry Pi example

## [0.7.0] - 2021-07-08

Expand Down
15 changes: 10 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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"]
Expand Down
30 changes: 0 additions & 30 deletions build.sh

This file was deleted.

59 changes: 59 additions & 0 deletions examples/text_raspberry_pi.rs
Original file line number Diff line number Diff line change
@@ -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();
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down