diff --git a/Cargo.toml b/Cargo.toml index f1d931b..a27560d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ default-features = false cortex-m = "0.6" cortex-m-rt = "0.6" stm32f1xx-hal = { version = "0.6.1", features = ["stm32f103", "rt"] } -embedded-hal = "0.2.3" +embedded-hal = {version = "0.2.3", feature = ["unproven"]} rtt-target = {version = "0.2.2", features = ["cortex-m"]} st7735-lcd = { git = "https://github.com/LongHairedHacker/st7735-lcd-rs.git", branch = "release-display-interface"} embedded-graphics = "0.6.2" diff --git a/src/application.rs b/src/application.rs index a1ed4d8..d6a64e9 100644 --- a/src/application.rs +++ b/src/application.rs @@ -10,51 +10,65 @@ use embedded_graphics::{ }; use embedded_hal::blocking::spi; use embedded_hal::digital::v2::{InputPin, OutputPin}; +use embedded_hal::Qei; use profont::{ProFont12Point, ProFont9Point}; use rtt_target::{rprintln, rtt_init_print}; use st7735_lcd::Orientation; use stm32f1xx_hal::{ delay::Delay, - gpio, pac, + gpio::{gpioa, gpiob, gpioc, Alternate, Floating, Input, Output, PushPull}, + pac, prelude::*, - qei::QeiOptions, - rcc, + qei, rcc, spi::{Mode, Phase, Polarity, Spi, Spi1NoRemap}, stm32, - timer::Timer, + timer::{Tim3PartialRemap, Timer}, }; use tinybmp::Bmp; -pub struct App +pub struct App where BLed: OutputPin, - SPI: spi::Transfer, + SPI: spi::Transfer + spi::Write, DispCS: OutputPin, + DispDC: OutputPin, + DispRST: OutputPin, MaxCS: OutputPin, + QEI: Qei, { delay: Delay, board_led: BLed, spi: SPI, disp_cs: DispCS, + disp_dc: DispDC, + disp_rst: DispRST, max_cs: MaxCS, + qei: QEI, } pub fn setup( cp: cortex_m::peripheral::Peripherals, dp: stm32::Peripherals, ) -> App< - gpio::gpioc::PC13>, + gpioc::PC13>, Spi< pac::SPI1, Spi1NoRemap, ( - gpio::gpioa::PA5>, - gpio::gpioa::PA6>, - gpio::gpioa::PA7>, + gpioa::PA5>, + gpioa::PA6>, + gpioa::PA7>, ), >, - gpio::gpioa::PA0>, - gpio::gpioa::PA9>, + gpioa::PA0>, + gpioa::PA4>, + gpioa::PA1>, + gpioa::PA9>, + qei::Qei< + pac::TIM3, + Tim3PartialRemap, + (gpiob::PB4>, gpiob::PB5>), + >, > { // Take ownership over the raw flash and rcc devices and convert them into the corresponding // HAL structs @@ -89,7 +103,7 @@ pub fn setup( let qei = Timer::tim3(dp.TIM3, &clocks, &mut rcc.apb1).qei( (pb4, gpiob.pb5), &mut afio.mapr, - QeiOptions::default(), + qei::QeiOptions::default(), ); // SPI1 @@ -97,16 +111,16 @@ pub fn setup( let miso = gpioa.pa6; let mosi = gpioa.pa7.into_alternate_push_pull(&mut gpioa.crl); - let mut disp_cs = gpioa.pa0.into_push_pull_output(&mut gpioa.crl); - let mut max_cs = gpioa.pa9.into_push_pull_output(&mut gpioa.crh); + let disp_cs = gpioa.pa0.into_push_pull_output(&mut gpioa.crl); + let max_cs = gpioa.pa9.into_push_pull_output(&mut gpioa.crh); - let mut rst = gpioa.pa1.into_push_pull_output(&mut gpioa.crl); - let mut dc = gpioa.pa4.into_push_pull_output(&mut gpioa.crl); + let rst = gpioa.pa1.into_push_pull_output(&mut gpioa.crl); + let dc = gpioa.pa4.into_push_pull_output(&mut gpioa.crl); let mut disp_led = gpioa.pa8.into_push_pull_output(&mut gpioa.crh); disp_led.set_high().unwrap(); - let mut spi = Spi::spi1( + let spi = Spi::spi1( dp.SPI1, (sck, miso, mosi), &mut afio.mapr, @@ -124,6 +138,44 @@ pub fn setup( board_led: led, spi: spi, disp_cs: disp_cs, + disp_dc: dc, + disp_rst: rst, max_cs: max_cs, + qei: qei, + } +} + +impl + App +where + BLed: OutputPin, + SPI: spi::Transfer + spi::Write, + DispCS: OutputPin, + DispDC: OutputPin, + DispRST: OutputPin, + MaxCS: OutputPin, + QEI: Qei, +{ + pub fn run(mut self) -> ! { + let mut disp = + st7735_lcd::ST7735::new(self.spi, self.disp_dc, self.disp_rst, true, false, 160, 128); + self.disp_cs.set_low().ok().unwrap(); + disp.init(&mut self.delay).unwrap(); + disp.set_orientation(&Orientation::LandscapeSwapped) + .unwrap(); + + let style_black = PrimitiveStyleBuilder::new() + .fill_color(Rgb565::BLACK) + .build(); + Rectangle::new(Point::new(0, 0), Point::new(160, 128)) + .into_styled(style_black) + .draw(&mut disp) + .unwrap(); + + let bmp = Bmp::from_slice(include_bytes!("logo.bmp")).unwrap(); + let image = Image::new(&bmp, Point::new(16, 0)); + image.draw(&mut disp).unwrap(); + + loop {} } } diff --git a/src/main.rs b/src/main.rs index 06f3f22..391e47f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,9 +37,10 @@ fn main() -> ! { // Get access to the device specific peripherals from the peripheral access crate let dp = pac::Peripherals::take().unwrap(); - let app = application::setup(cp, dp); + let mut app = application::setup(cp, dp); + + app.run() - loop {} /* let mut disp = st7735_lcd::ST7735::new(spi, dc, rst, true, false, 160, 128);