mirror of
https://github.com/Anshorei/epd-waveshare.git
synced 2026-10-03 22:06:43 +00:00
Add Bluepill example & some other minor improvements (#28)
- added bluepill example - improved ci config - travis: run fmt only once - travis: fixed target issues
This commit is contained in:
@@ -16,5 +16,32 @@ This examples used the graphics feature with VarDisplay and therefore a variable
|
||||
|
||||
This example doesn't use the graphics feature and handles all the "drawing" by itself. It also has a speeddemonstration included.
|
||||
|
||||
### epd4in2_full_blue_pill
|
||||
|
||||
Connect epd4in2 display to blue pill board:
|
||||
- BUSY -> A10
|
||||
- RST -> A9
|
||||
- DC -> A8
|
||||
- CS -> B12
|
||||
- CLK -> B13
|
||||
- DIN -> B15
|
||||
- GND -> G
|
||||
- VCC -> 3.3
|
||||
|
||||
For compiling and flashing, please refer to [TeXitois blue pill quickstart](https://github.com/TeXitoi/blue-pill-quickstart/blob/master/README.md).
|
||||
|
||||
Basically:
|
||||
|
||||
```shell
|
||||
curl https://sh.rustup.rs -sSf | sh
|
||||
rustup target add thumbv7m-none-eabi
|
||||
sudo apt-get install gdb-arm-none-eabi openocd
|
||||
cd epd4in2_full_blue_pill
|
||||
# connect ST-Link v2 to the blue pill and the computer
|
||||
# openocd in another terminal
|
||||
cargo run --release
|
||||
```
|
||||
|
||||
Ff you can't connect to openocd you might need to adapt your udev rules or use sudo ([openOCD Problems](https://rust-embedded.github.io/discovery/03-setup/linux.html#udev-rules))
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
[target.thumbv7m-none-eabi]
|
||||
|
||||
# uncomment ONE of these three option to make `cargo run` start a GDB session
|
||||
# which option to pick depends on your system
|
||||
runner = "arm-none-eabi-gdb -q -x openocd.gdb"
|
||||
# runner = "gdb-multiarch -q -x openocd.gdb"
|
||||
# runner = "gdb -q -x openocd.gdb"
|
||||
|
||||
rustflags = ["-C", "link-arg=-Tlink.x"]
|
||||
|
||||
[build]
|
||||
target = "thumbv7m-none-eabi"
|
||||
@@ -0,0 +1,19 @@
|
||||
[package]
|
||||
name = "embedded_linux_eink_example"
|
||||
version = "0.1.0"
|
||||
authors = ["Christoph Groß <christoph-gross@mailbox.org>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
|
||||
## The Only difference between this one and the one without default features sizewise seems to be a different .d-file Size (dependencies-file)
|
||||
#epd_waveshare = { path = "../../"}
|
||||
epd-waveshare = { path = "../../", default-features = false, features = ["epd4in2", "graphics"]}
|
||||
|
||||
embedded-graphics = "0.4.5"
|
||||
embedded-hal = { version = "0.2.2", features = ["unproven"] }
|
||||
|
||||
stm32f1xx-hal = { version = "0.2", features = ["rt", "stm32f103" ] }
|
||||
cortex-m = "0.5.0"
|
||||
cortex-m-rt = { version = "0.6.6", features = ["device"] }
|
||||
panic-semihosting = "0.5"
|
||||
@@ -0,0 +1,6 @@
|
||||
/* Linker script for the STM32F103C8T6 */
|
||||
MEMORY
|
||||
{
|
||||
FLASH : ORIGIN = 0x08000000, LENGTH = 64K
|
||||
RAM : ORIGIN = 0x20000000, LENGTH = 20K
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
source [find interface/stlink-v2.cfg]
|
||||
source [find target/stm32f1x.cfg]
|
||||
@@ -0,0 +1,10 @@
|
||||
target remote :3333
|
||||
set print asm-demangle on
|
||||
monitor arm semihosting enable
|
||||
|
||||
# detect unhandled exceptions, hard faults and panics
|
||||
break DefaultHandler
|
||||
break HardFault
|
||||
break rust_begin_unwind
|
||||
|
||||
load
|
||||
@@ -0,0 +1,192 @@
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
// set the panic handler
|
||||
#[allow(unused_imports)]
|
||||
use panic_semihosting;
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
use stm32f1xx_hal::prelude::*;
|
||||
use stm32f1xx_hal::{delay, spi};
|
||||
|
||||
use embedded_graphics::{
|
||||
coord::Coord,
|
||||
fonts::{Font12x16, Font6x8},
|
||||
prelude::*,
|
||||
primitives::{Circle, Line},
|
||||
Drawing,
|
||||
};
|
||||
use epd_waveshare::{
|
||||
epd4in2::Display4in2,
|
||||
graphics::{Display, DisplayRotation},
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let core = cortex_m::Peripherals::take().unwrap();
|
||||
let device = stm32f1xx_hal::stm32::Peripherals::take().unwrap();
|
||||
let mut rcc = device.RCC.constrain();
|
||||
let mut flash = device.FLASH.constrain();
|
||||
|
||||
let clocks = rcc
|
||||
.cfgr
|
||||
.use_hse(8.mhz())
|
||||
.sysclk(72.mhz())
|
||||
.pclk1(36.mhz())
|
||||
.freeze(&mut flash.acr);
|
||||
|
||||
let mut gpioa = device.GPIOA.split(&mut rcc.apb2);
|
||||
let mut gpiob = device.GPIOB.split(&mut rcc.apb2);
|
||||
|
||||
let mut delay = delay::Delay::new(core.SYST, clocks);
|
||||
|
||||
// spi setup
|
||||
let sck = gpiob.pb13.into_alternate_push_pull(&mut gpiob.crh);
|
||||
let miso = gpiob.pb14;
|
||||
let mosi = gpiob.pb15.into_alternate_push_pull(&mut gpiob.crh);
|
||||
let mut spi = spi::Spi::spi2(
|
||||
device.SPI2,
|
||||
(sck, miso, mosi),
|
||||
epd_waveshare::SPI_MODE,
|
||||
4.mhz(),
|
||||
clocks,
|
||||
&mut rcc.apb1,
|
||||
);
|
||||
// epd setup
|
||||
let mut epd4in2 = epd_waveshare::epd4in2::EPD4in2::new(
|
||||
&mut spi,
|
||||
gpiob.pb12.into_push_pull_output(&mut gpiob.crh),
|
||||
gpioa.pa10.into_floating_input(&mut gpioa.crh),
|
||||
gpioa.pa8.into_push_pull_output(&mut gpioa.crh),
|
||||
gpioa.pa9.into_push_pull_output(&mut gpioa.crh),
|
||||
&mut delay,
|
||||
)
|
||||
.unwrap();
|
||||
epd4in2.set_lut(&mut spi, Some(RefreshLUT::QUICK)).unwrap();
|
||||
epd4in2.clear_frame(&mut spi).unwrap();
|
||||
|
||||
//println!("Test all the rotations");
|
||||
let mut display = Display4in2::default();
|
||||
display.set_rotation(DisplayRotation::Rotate0);
|
||||
display.draw(
|
||||
Font6x8::render_str("Rotate 0!")
|
||||
.with_stroke(Some(Color::Black))
|
||||
.with_fill(Some(Color::White))
|
||||
.translate(Coord::new(5, 50))
|
||||
.into_iter(),
|
||||
);
|
||||
|
||||
display.set_rotation(DisplayRotation::Rotate90);
|
||||
display.draw(
|
||||
Font6x8::render_str("Rotate 90!")
|
||||
.with_stroke(Some(Color::Black))
|
||||
.with_fill(Some(Color::White))
|
||||
.translate(Coord::new(5, 50))
|
||||
.into_iter(),
|
||||
);
|
||||
|
||||
display.set_rotation(DisplayRotation::Rotate180);
|
||||
display.draw(
|
||||
Font6x8::render_str("Rotate 180!")
|
||||
.with_stroke(Some(Color::Black))
|
||||
.with_fill(Some(Color::White))
|
||||
.translate(Coord::new(5, 50))
|
||||
.into_iter(),
|
||||
);
|
||||
|
||||
display.set_rotation(DisplayRotation::Rotate270);
|
||||
display.draw(
|
||||
Font6x8::render_str("Rotate 270!")
|
||||
.with_stroke(Some(Color::Black))
|
||||
.with_fill(Some(Color::White))
|
||||
.translate(Coord::new(5, 50))
|
||||
.into_iter(),
|
||||
);
|
||||
|
||||
epd4in2.update_frame(&mut spi, &display.buffer()).unwrap();
|
||||
epd4in2
|
||||
.display_frame(&mut spi)
|
||||
.expect("display frame new graphics");
|
||||
delay.delay_ms(5000u16);
|
||||
|
||||
//println!("Now test new graphics with default rotation and some special stuff:");
|
||||
display.clear_buffer(Color::White);
|
||||
|
||||
// draw a analog clock
|
||||
display.draw(
|
||||
Circle::new(Coord::new(64, 64), 64)
|
||||
.with_stroke(Some(Color::Black))
|
||||
.into_iter(),
|
||||
);
|
||||
display.draw(
|
||||
Line::new(Coord::new(64, 64), Coord::new(0, 64))
|
||||
.with_stroke(Some(Color::Black))
|
||||
.into_iter(),
|
||||
);
|
||||
display.draw(
|
||||
Line::new(Coord::new(64, 64), Coord::new(80, 80))
|
||||
.with_stroke(Some(Color::Black))
|
||||
.into_iter(),
|
||||
);
|
||||
|
||||
// draw white on black background
|
||||
display.draw(
|
||||
Font6x8::render_str("It's working-WoB!")
|
||||
// Using Style here
|
||||
.with_style(Style {
|
||||
fill_color: Some(Color::Black),
|
||||
stroke_color: Some(Color::White),
|
||||
stroke_width: 0u8, // Has no effect on fonts
|
||||
})
|
||||
.translate(Coord::new(175, 250))
|
||||
.into_iter(),
|
||||
);
|
||||
|
||||
// use bigger/different font
|
||||
display.draw(
|
||||
Font12x16::render_str("It's working-BoW!")
|
||||
// Using Style here
|
||||
.with_style(Style {
|
||||
fill_color: Some(Color::White),
|
||||
stroke_color: Some(Color::Black),
|
||||
stroke_width: 0u8, // Has no effect on fonts
|
||||
})
|
||||
.translate(Coord::new(50, 200))
|
||||
.into_iter(),
|
||||
);
|
||||
|
||||
// a moving `Hello World!`
|
||||
let limit = 10;
|
||||
epd4in2.set_lut(&mut spi, Some(RefreshLUT::QUICK)).unwrap();
|
||||
epd4in2.clear_frame(&mut spi).unwrap();
|
||||
for i in 0..limit {
|
||||
//println!("Moving Hello World. Loop {} from {}", (i + 1), limit);
|
||||
|
||||
display.draw(
|
||||
Font6x8::render_str(" Hello World! ")
|
||||
.with_style(Style {
|
||||
fill_color: Some(Color::White),
|
||||
stroke_color: Some(Color::Black),
|
||||
stroke_width: 0u8, // Has no effect on fonts
|
||||
})
|
||||
.translate(Coord::new(5 + i * 12, 50))
|
||||
.into_iter(),
|
||||
);
|
||||
|
||||
epd4in2.update_frame(&mut spi, &display.buffer()).unwrap();
|
||||
epd4in2
|
||||
.display_frame(&mut spi)
|
||||
.expect("display frame new graphics");
|
||||
|
||||
delay.delay_ms(1_000u16);
|
||||
}
|
||||
|
||||
//println!("Finished tests - going to sleep");
|
||||
epd4in2.sleep(&mut spi).expect("epd goes to sleep");
|
||||
|
||||
loop {
|
||||
// sleep
|
||||
cortex_m::asm::wfi();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user