Skip to content
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

Embedded hal 1.0.0 #213

Merged
Merged
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
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
runner = [ "probe-rs", "run", "--chip", "STM32F103C8" ]
rustflags = [
"-C", "link-arg=-Tlink.x",
"-C", "link-arg=--nmagic",
"-C", "link-arg=-Tdefmt.x",
]

[build]
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ jobs:
- run: cargo test --doc --target x86_64-unknown-linux-gnu

test-msrv:
name: test with MSRV
name: build with MSRV
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.61
- run: cargo test --lib --target x86_64-unknown-linux-gnu
- run: cargo test --doc --target x86_64-unknown-linux-gnu
toolchain: 1.75
- run: cargo build --lib --target x86_64-unknown-linux-gnu
- run: cargo doc --target x86_64-unknown-linux-gnu
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do the examples not build with Rust 1.75.0? If so, please rename this step "build with MSRV"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specifically embassy needs 1.79 at the moment; renamed now


build:
strategy:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ SSD1306 monochrome OLED display.

## [Unreleased] - ReleaseDate

- Updated dependencies for `embedded-hal` 1.0.0.
- Switch examples to embassy STM32 PAC which implements `embedded-hal` 1.0.0 traits.
- **(breaking)** Increased MSRV to 1.75.0

### Added

- [#203](/~https://github.com/jamwaffles/ssd1306/pull/203) Added `Ssd1306::release(self)` to release the contained i2c interface.
Expand Down
24 changes: 14 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,42 @@ name = "ssd1306"
readme = "README.md"
repository = "/~https://github.com/rust-embedded-community/ssd1306"
version = "0.8.4"
edition = "2018"
edition = "2021"
exclude = [ "build.rs", "build.sh", "memory.x", "doc", "*.jpg", "*.png", "*.bmp" ]
rust-version = "1.61"
rust-version = "1.75.0"

[package.metadata.docs.rs]
targets = [ "thumbv7m-none-eabi", "thumbv7em-none-eabihf" ]

[dependencies]
embedded-hal = "0.2.5"
display-interface = "0.4.1"
display-interface-i2c = "0.4.0"
display-interface-spi = "0.4.1"
embedded-hal = "1.0.0"
display-interface = "0.5.0"
display-interface-i2c = "0.5.0"
display-interface-spi = "0.5.0"
embedded-graphics-core = { version = "0.4.0", optional = true }

[dev-dependencies]
cortex-m = "0.7.2"
cortex-m = { version = "0.7.2", features = ["critical-section-single-core"] }
cortex-m-rt = "0.7.3"
cortex-m-rtic = "1.1.4"
panic-halt = "0.2.0"
cast = { version = "0.2.6", default-features = false }
defmt = "0.3.6"
defmt-rtt = "0.4.0"
panic-probe = { version = "0.3.1", features = ["print-defmt"] }
# Used to load BMP images in various examples
tinybmp = "0.5.0"
embedded-graphics = "0.8.0"
# Used by the noise_i2c examples
rand = { version = "0.8.4", default-features = false, features = [ "small_rng" ] }
stm32f1xx-hal = { version = "0.10.0", features = [ "rt", "stm32f103" ] }
embassy-stm32 = { version = "0.1.0", git = "/~https://github.com/embassy-rs/embassy", features = [ "stm32f103c8", "memory-x", "defmt", "exti", "time-driver-tim3" , "unstable-pac"] }
embassy-time = { version = "0.3.1", git = "/~https://github.com/embassy-rs/embassy" }
embedded-hal-bus = "0.2.0"

[features]
default = ["graphics"]
graphics = ["embedded-graphics-core"]

[profile.dev]
opt-level="s"
codegen-units = 1
incremental = false

Expand Down
14 changes: 0 additions & 14 deletions build.rs

This file was deleted.

60 changes: 18 additions & 42 deletions examples/bmp_i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,55 +12,34 @@
//! Display -> Blue Pill
//! (black) GND -> GND
//! (red) +5V -> VCC
//! (yellow) SDA -> PB9
//! (green) SCL -> PB8
//! (yellow) SDA -> PB7
//! (green) SCL -> PB6
//! ```
//!
//! Run on a Blue Pill with `cargo run --example image_i2c`.

#![no_std]
#![no_main]

use cortex_m_rt::{entry, exception, ExceptionFrame};
use cortex_m::asm::nop;
use cortex_m_rt::entry;
use defmt_rtt as _;
use embassy_stm32::time::Hertz;
use embedded_graphics::{image::Image, pixelcolor::Rgb565, prelude::*};
use panic_halt as _;
use panic_probe as _;
use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306};
use stm32f1xx_hal::{
i2c::{BlockingI2c, DutyCycle, Mode},
prelude::*,
stm32,
};

use tinybmp::Bmp;

#[entry]
fn main() -> ! {
let dp = stm32::Peripherals::take().unwrap();

let mut flash = dp.FLASH.constrain();
let rcc = dp.RCC.constrain();

let clocks = rcc.cfgr.freeze(&mut flash.acr);

let mut afio = dp.AFIO.constrain();

let mut gpiob = dp.GPIOB.split();

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,
1000,
10,
1000,
1000,
let p = embassy_stm32::init(Default::default());
let i2c = embassy_stm32::i2c::I2c::new_blocking(
p.I2C1,
p.PB6,
p.PB7,
Hertz::khz(400),
Default::default(),
);

let interface = I2CDisplayInterface::new(i2c);
Expand All @@ -80,10 +59,7 @@ fn main() -> ! {

display.flush().unwrap();

loop {}
}

#[exception]
unsafe fn HardFault(ef: &ExceptionFrame) -> ! {
panic!("{:#?}", ef);
loop {
nop()
}
}
78 changes: 27 additions & 51 deletions examples/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,74 +9,53 @@
//! ```
//! GND -> GND
//! 3V3 -> VCC
//! PA5 -> SCL
//! PA7 -> SDA
//! PA5 -> SCL (D0)
//! PA7 -> SDA (D1)
//! PB0 -> RST
//! PB1 -> D/C
//! PB10 -> CS
//! ```
//!
//! Run on a Blue Pill with `cargo run --example graphics`.

#![no_std]
#![no_main]

use cortex_m_rt::{entry, exception, ExceptionFrame};
use cortex_m::asm::nop;
use cortex_m_rt::entry;
use defmt_rtt as _;
use embassy_stm32::{
gpio,
spi::{self, Spi},
time::Hertz,
};
use embedded_graphics::{
pixelcolor::BinaryColor,
prelude::*,
primitives::{Circle, PrimitiveStyleBuilder, Rectangle, Triangle},
};
use panic_halt as _;
use panic_probe as _;
use ssd1306::{prelude::*, Ssd1306};
use stm32f1xx_hal::{
prelude::*,
spi::{Mode, Phase, Polarity, Spi},
stm32,
timer::Timer,
};

#[entry]
fn main() -> ! {
let cp = cortex_m::Peripherals::take().unwrap();
let dp = stm32::Peripherals::take().unwrap();

let mut flash = dp.FLASH.constrain();
let rcc = dp.RCC.constrain();

let clocks = rcc.cfgr.freeze(&mut flash.acr);

let mut afio = dp.AFIO.constrain();

let mut gpioa = dp.GPIOA.split();
let mut gpiob = dp.GPIOB.split();
let p = embassy_stm32::init(Default::default());
let mut config = spi::Config::default();
config.frequency = Hertz::mhz(8);
let spi = Spi::new_blocking_txonly(p.SPI1, p.PA5, p.PA7, config);

// SPI1
let sck = gpioa.pa5.into_alternate_push_pull(&mut gpioa.crl);
let miso = gpioa.pa6;
let mosi = gpioa.pa7.into_alternate_push_pull(&mut gpioa.crl);
let mut rst = gpio::Output::new(p.PB0, gpio::Level::Low, gpio::Speed::Low);
let dc = gpio::Output::new(p.PB1, gpio::Level::Low, gpio::Speed::Low);
let cs = gpio::Output::new(p.PB10, gpio::Level::Low, gpio::Speed::Low);
let spi = embedded_hal_bus::spi::ExclusiveDevice::new_no_delay(spi, cs).unwrap();

let mut delay = Timer::syst(cp.SYST, &clocks).delay();

let mut rst = gpiob.pb0.into_push_pull_output(&mut gpiob.crl);
let dc = gpiob.pb1.into_push_pull_output(&mut gpiob.crl);

let spi = Spi::spi1(
dp.SPI1,
(sck, miso, mosi),
&mut afio.mapr,
Mode {
polarity: Polarity::IdleLow,
phase: Phase::CaptureOnFirstTransition,
},
8.MHz(),
clocks,
);

let interface = display_interface_spi::SPIInterfaceNoCS::new(spi, dc);
let interface = display_interface_spi::SPIInterface::new(spi, dc);
let mut display = Ssd1306::new(interface, DisplaySize128x64, DisplayRotation::Rotate0)
.into_buffered_graphics_mode();

display.reset(&mut rst, &mut delay).unwrap();
display
.reset(&mut rst, &mut embassy_time::Delay {})
.unwrap();
display.init().unwrap();

let yoffset = 20;
Expand Down Expand Up @@ -118,10 +97,7 @@ fn main() -> ! {

display.flush().unwrap();

loop {}
}

#[exception]
unsafe fn HardFault(ef: &ExceptionFrame) -> ! {
panic!("{:#?}", ef);
loop {
nop()
}
}
59 changes: 17 additions & 42 deletions examples/graphics_i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,58 +8,36 @@
//! Display -> Blue Pill
//! (black) GND -> GND
//! (red) +5V -> VCC
//! (yellow) SDA -> PB9
//! (green) SCL -> PB8
//! (yellow) SDA -> PB7
//! (green) SCL -> PB6
//! ```
//!
//! Run on a Blue Pill with `cargo run --example graphics_i2c`.

#![no_std]
#![no_main]

use cortex_m_rt::{entry, exception, ExceptionFrame};
use cortex_m::asm::nop;
use cortex_m_rt::entry;
use defmt_rtt as _;
use embassy_stm32::time::Hertz;
use embedded_graphics::{
pixelcolor::BinaryColor,
prelude::*,
primitives::{Circle, PrimitiveStyleBuilder, Rectangle, Triangle},
};
use panic_halt as _;
use panic_probe as _;
use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306};
use stm32f1xx_hal::{
i2c::{BlockingI2c, DutyCycle, Mode},
prelude::*,
stm32,
};

#[entry]
fn main() -> ! {
let dp = stm32::Peripherals::take().unwrap();

let mut flash = dp.FLASH.constrain();
let rcc = dp.RCC.constrain();

let clocks = rcc.cfgr.freeze(&mut flash.acr);

let mut afio = dp.AFIO.constrain();

let mut gpiob = dp.GPIOB.split();

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,
1000,
10,
1000,
1000,
let p = embassy_stm32::init(Default::default());
let i2c = embassy_stm32::i2c::I2c::new_blocking(
p.I2C1,
p.PB6,
p.PB7,
Hertz::khz(400),
Default::default(),
);

let interface = I2CDisplayInterface::new(i2c);
Expand Down Expand Up @@ -106,10 +84,7 @@ fn main() -> ! {

display.flush().unwrap();

loop {}
}

#[exception]
unsafe fn HardFault(ef: &ExceptionFrame) -> ! {
panic!("{:#?}", ef);
loop {
nop()
}
}
Loading