Created
March 29, 2024 06:49
-
-
Save enaut/855c4acbcdde320f549a7a130e8393ae to your computer and use it in GitHub Desktop.
display with spi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "first-stm32" | |
version = "0.1.0" | |
authors = ["Franz Dietrich <dietrich@teilgedanken.de>"] | |
edition = "2021" | |
[dependencies] | |
cortex-m = "0.7" | |
cortex-m-rt = "0.7" | |
cortex-m-rtic = "1.1" | |
panic-halt = "0.2.0" | |
embedded-graphics = "0.8" | |
st7735-lcd = "0.10" | |
embedded-hal = "1" | |
[dependencies.stm32f4xx-hal] | |
version = "0.20.0" | |
features = ["stm32f411", "rtic1"] | |
# Set the default for dependencies. | |
[profile.dev.package."*"] | |
opt-level = "s" | |
[profile.release] | |
codegen-units = 1 | |
incremental = false | |
debug = true | |
lto = true | |
opt-level = "s" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![no_std] | |
#![no_main] | |
extern crate cortex_m; | |
extern crate cortex_m_rt as rt; | |
use hal::gpio::Speed; | |
use panic_halt as _; | |
extern crate stm32f4xx_hal as hal; | |
use cortex_m_rt::entry; | |
//use embedded_graphics::image::{Image, ImageRaw, ImageRawLE}; | |
use embedded_graphics::pixelcolor::Rgb565; | |
use embedded_graphics::prelude::*; | |
use embedded_hal::spi::SpiDevice; | |
use hal::spi::{Mode, Phase, Polarity, Spi}; | |
use hal::{pac, prelude::*, time}; | |
use st7735_lcd; | |
use st7735_lcd::Orientation; | |
#[entry] | |
fn main() -> ! { | |
let cp = cortex_m::Peripherals::take().unwrap(); | |
let dp = pac::Peripherals::take().unwrap(); | |
let mut rcc = dp.RCC.constrain(); | |
let clocks = rcc | |
.cfgr | |
.use_hse(8.MHz()) | |
.sysclk(72.MHz()) | |
.pclk1(36.MHz()) | |
.freeze(); | |
let mut gpioa = dp.GPIOA.split(); | |
let mut gpiob = dp.GPIOB.split(); | |
// SPI1 | |
let sck = gpiob | |
.pb3 | |
.into_alternate() | |
.speed(Speed::VeryHigh) | |
.internal_pull_up(true); | |
let miso = gpiob | |
.pb4 | |
.into_alternate() | |
.speed(Speed::VeryHigh) | |
.internal_pull_up(true); | |
let mosi = gpiob | |
.pb5 | |
.into_alternate() | |
.speed(Speed::VeryHigh) | |
.internal_pull_up(true); | |
let rst = gpiob.pb0.into_push_pull_output(); | |
let dc = gpiob.pb1.into_push_pull_output(); | |
let mut spi = dp.SPI3.spi( | |
(sck, miso, mosi), | |
Mode { | |
polarity: Polarity::IdleLow, | |
phase: Phase::CaptureOnFirstTransition, | |
}, | |
16.MHz(), | |
&clocks, | |
); | |
/* Spi::new( | |
dp.SPI3, | |
(sck, miso, mosi), | |
Mode { | |
polarity: Polarity::IdleLow, | |
phase: Phase::CaptureOnFirstTransition, | |
}, | |
16.MHz(), | |
&clocks, | |
); */ | |
let mut disp = st7735_lcd::ST7735::new(&mut spi, dc, rst, true, false, 160, 128); | |
//disp.init(&mut delay).unwrap(); | |
//disp.set_orientation(&Orientation::Landscape).unwrap(); | |
//disp.clear(Rgb565::BLACK); | |
//disp.set_offset(0, 25); | |
// draw ferris | |
//let image_raw: ImageRawLE<Rgb565> = ImageRaw::new(include_bytes!("./ferris.raw"), 86 * 64); | |
//let image: Image<Rgb565> = Image::new(&image_raw, Point::new(34, 8)); | |
//image.draw(&mut disp).unwrap(); | |
loop { | |
continue; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cargo build --bin display-example | |
Compiling first-stm32 v0.1.0 (/home/dietrich/Projekte/Source/first-stm32) | |
warning: unused import: `embedded_graphics::pixelcolor::Rgb565` | |
--> src/bin/display-example.rs:12:5 | |
| | |
12 | use embedded_graphics::pixelcolor::Rgb565; | |
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| | |
= note: `#[warn(unused_imports)]` on by default | |
warning: unused import: `embedded_graphics::prelude::*` | |
--> src/bin/display-example.rs:13:5 | |
| | |
13 | use embedded_graphics::prelude::*; | |
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
warning: unused import: `embedded_hal::spi::SpiDevice` | |
--> src/bin/display-example.rs:14:5 | |
| | |
14 | use embedded_hal::spi::SpiDevice; | |
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
warning: unused import: `Spi` | |
--> src/bin/display-example.rs:15:39 | |
| | |
15 | use hal::spi::{Mode, Phase, Polarity, Spi}; | |
| ^^^ | |
warning: unused import: `time` | |
--> src/bin/display-example.rs:16:28 | |
| | |
16 | use hal::{pac, prelude::*, time}; | |
| ^^^^ | |
warning: unused import: `st7735_lcd::Orientation` | |
--> src/bin/display-example.rs:18:5 | |
| | |
18 | use st7735_lcd::Orientation; | |
| ^^^^^^^^^^^^^^^^^^^^^^^ | |
error[E0277]: the trait bound `Spi<hal::pac::SPI3>: SpiDevice` is not satisfied | |
--> src/bin/display-example.rs:77:49 | |
| | |
77 | let mut disp = st7735_lcd::ST7735::new(&mut spi, dc, rst, true, false, 160, 128); | |
| ----------------------- ^^^ the trait `SpiDevice` is not implemented for `Spi<hal::pac::SPI3>` | |
| | | |
| required by a bound introduced by this call | |
| | |
= help: the trait `SpiDevice<Word>` is implemented for `&mut T` | |
= note: required for `&mut Spi<hal::pac::SPI3>` to implement `SpiDevice` | |
note: required by a bound in `ST7735::<SPI, DC, RST>::new` | |
--> /home/dietrich/.cargo/registry/src/index.crates.io-6f17d22bba15001f/st7735-lcd-0.10.0/src/lib.rs:53:10 | |
| | |
53 | SPI: spi::SpiDevice, | |
| ^^^^^^^^^^^^^^ required by this bound in `ST7735::<SPI, DC, RST>::new` | |
... | |
58 | pub fn new( | |
| --- required by a bound in this associated function | |
error[E0277]: the trait bound `Spi<hal::pac::SPI3>: SpiDevice` is not satisfied | |
--> src/bin/display-example.rs:77:20 | |
| | |
77 | let mut disp = st7735_lcd::ST7735::new(&mut spi, dc, rst, true, false, 160, 128); | |
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `SpiDevice` is not implemented for `Spi<hal::pac::SPI3>` | |
| | |
= help: the trait `SpiDevice<Word>` is implemented for `&mut T` | |
= note: required for `&mut Spi<hal::pac::SPI3>` to implement `SpiDevice` | |
note: required by a bound in `ST7735` | |
--> /home/dietrich/.cargo/registry/src/index.crates.io-6f17d22bba15001f/st7735-lcd-0.10.0/src/lib.rs:16:10 | |
| | |
14 | pub struct ST7735<SPI, DC, RST> | |
| ------ required by a bound in this struct | |
15 | where | |
16 | SPI: spi::SpiDevice, | |
| ^^^^^^^^^^^^^^ required by this bound in `ST7735` | |
For more information about this error, try `rustc --explain E0277`. | |
warning: `first-stm32` (bin "display-example") generated 6 warnings | |
error: could not compile `first-stm32` (bin "display-example") due to 2 previous errors; 6 warnings emitted |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment