The application can finally do something
This commit is contained in:
parent
3887e41285
commit
3e00a1f044
|
@ -10,7 +10,7 @@ default-features = false
|
||||||
cortex-m = "0.6"
|
cortex-m = "0.6"
|
||||||
cortex-m-rt = "0.6"
|
cortex-m-rt = "0.6"
|
||||||
stm32f1xx-hal = { version = "0.6.1", features = ["stm32f103", "rt"] }
|
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"]}
|
rtt-target = {version = "0.2.2", features = ["cortex-m"]}
|
||||||
st7735-lcd = { git = "https://github.com/LongHairedHacker/st7735-lcd-rs.git", branch = "release-display-interface"}
|
st7735-lcd = { git = "https://github.com/LongHairedHacker/st7735-lcd-rs.git", branch = "release-display-interface"}
|
||||||
embedded-graphics = "0.6.2"
|
embedded-graphics = "0.6.2"
|
||||||
|
|
|
@ -10,51 +10,65 @@ use embedded_graphics::{
|
||||||
};
|
};
|
||||||
use embedded_hal::blocking::spi;
|
use embedded_hal::blocking::spi;
|
||||||
use embedded_hal::digital::v2::{InputPin, OutputPin};
|
use embedded_hal::digital::v2::{InputPin, OutputPin};
|
||||||
|
use embedded_hal::Qei;
|
||||||
use profont::{ProFont12Point, ProFont9Point};
|
use profont::{ProFont12Point, ProFont9Point};
|
||||||
use rtt_target::{rprintln, rtt_init_print};
|
use rtt_target::{rprintln, rtt_init_print};
|
||||||
use st7735_lcd::Orientation;
|
use st7735_lcd::Orientation;
|
||||||
use stm32f1xx_hal::{
|
use stm32f1xx_hal::{
|
||||||
delay::Delay,
|
delay::Delay,
|
||||||
gpio, pac,
|
gpio::{gpioa, gpiob, gpioc, Alternate, Floating, Input, Output, PushPull},
|
||||||
|
pac,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
qei::QeiOptions,
|
qei, rcc,
|
||||||
rcc,
|
|
||||||
spi::{Mode, Phase, Polarity, Spi, Spi1NoRemap},
|
spi::{Mode, Phase, Polarity, Spi, Spi1NoRemap},
|
||||||
stm32,
|
stm32,
|
||||||
timer::Timer,
|
timer::{Tim3PartialRemap, Timer},
|
||||||
};
|
};
|
||||||
use tinybmp::Bmp;
|
use tinybmp::Bmp;
|
||||||
|
|
||||||
pub struct App<BLed, SPI, DispCS, MaxCS>
|
pub struct App<BLed, SPI, DispCS, DispDC, DispRST, MaxCS, QEI>
|
||||||
where
|
where
|
||||||
BLed: OutputPin,
|
BLed: OutputPin,
|
||||||
SPI: spi::Transfer<u8>,
|
SPI: spi::Transfer<u8> + spi::Write<u8>,
|
||||||
DispCS: OutputPin,
|
DispCS: OutputPin,
|
||||||
|
DispDC: OutputPin,
|
||||||
|
DispRST: OutputPin,
|
||||||
MaxCS: OutputPin,
|
MaxCS: OutputPin,
|
||||||
|
QEI: Qei,
|
||||||
{
|
{
|
||||||
delay: Delay,
|
delay: Delay,
|
||||||
board_led: BLed,
|
board_led: BLed,
|
||||||
spi: SPI,
|
spi: SPI,
|
||||||
disp_cs: DispCS,
|
disp_cs: DispCS,
|
||||||
|
disp_dc: DispDC,
|
||||||
|
disp_rst: DispRST,
|
||||||
max_cs: MaxCS,
|
max_cs: MaxCS,
|
||||||
|
qei: QEI,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setup(
|
pub fn setup(
|
||||||
cp: cortex_m::peripheral::Peripherals,
|
cp: cortex_m::peripheral::Peripherals,
|
||||||
dp: stm32::Peripherals,
|
dp: stm32::Peripherals,
|
||||||
) -> App<
|
) -> App<
|
||||||
gpio::gpioc::PC13<gpio::Output<gpio::PushPull>>,
|
gpioc::PC13<Output<PushPull>>,
|
||||||
Spi<
|
Spi<
|
||||||
pac::SPI1,
|
pac::SPI1,
|
||||||
Spi1NoRemap,
|
Spi1NoRemap,
|
||||||
(
|
(
|
||||||
gpio::gpioa::PA5<gpio::Alternate<gpio::PushPull>>,
|
gpioa::PA5<Alternate<PushPull>>,
|
||||||
gpio::gpioa::PA6<gpio::Input<gpio::Floating>>,
|
gpioa::PA6<Input<Floating>>,
|
||||||
gpio::gpioa::PA7<gpio::Alternate<gpio::PushPull>>,
|
gpioa::PA7<Alternate<PushPull>>,
|
||||||
),
|
),
|
||||||
>,
|
>,
|
||||||
gpio::gpioa::PA0<gpio::Output<gpio::PushPull>>,
|
gpioa::PA0<Output<PushPull>>,
|
||||||
gpio::gpioa::PA9<gpio::Output<gpio::PushPull>>,
|
gpioa::PA4<Output<PushPull>>,
|
||||||
|
gpioa::PA1<Output<PushPull>>,
|
||||||
|
gpioa::PA9<Output<PushPull>>,
|
||||||
|
qei::Qei<
|
||||||
|
pac::TIM3,
|
||||||
|
Tim3PartialRemap,
|
||||||
|
(gpiob::PB4<Input<Floating>>, gpiob::PB5<Input<Floating>>),
|
||||||
|
>,
|
||||||
> {
|
> {
|
||||||
// Take ownership over the raw flash and rcc devices and convert them into the corresponding
|
// Take ownership over the raw flash and rcc devices and convert them into the corresponding
|
||||||
// HAL structs
|
// HAL structs
|
||||||
|
@ -89,7 +103,7 @@ pub fn setup(
|
||||||
let qei = Timer::tim3(dp.TIM3, &clocks, &mut rcc.apb1).qei(
|
let qei = Timer::tim3(dp.TIM3, &clocks, &mut rcc.apb1).qei(
|
||||||
(pb4, gpiob.pb5),
|
(pb4, gpiob.pb5),
|
||||||
&mut afio.mapr,
|
&mut afio.mapr,
|
||||||
QeiOptions::default(),
|
qei::QeiOptions::default(),
|
||||||
);
|
);
|
||||||
|
|
||||||
// SPI1
|
// SPI1
|
||||||
|
@ -97,16 +111,16 @@ pub fn setup(
|
||||||
let miso = gpioa.pa6;
|
let miso = gpioa.pa6;
|
||||||
let mosi = gpioa.pa7.into_alternate_push_pull(&mut gpioa.crl);
|
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 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 max_cs = gpioa.pa9.into_push_pull_output(&mut gpioa.crh);
|
||||||
|
|
||||||
let mut rst = gpioa.pa1.into_push_pull_output(&mut gpioa.crl);
|
let rst = gpioa.pa1.into_push_pull_output(&mut gpioa.crl);
|
||||||
let mut dc = gpioa.pa4.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);
|
let mut disp_led = gpioa.pa8.into_push_pull_output(&mut gpioa.crh);
|
||||||
|
|
||||||
disp_led.set_high().unwrap();
|
disp_led.set_high().unwrap();
|
||||||
|
|
||||||
let mut spi = Spi::spi1(
|
let spi = Spi::spi1(
|
||||||
dp.SPI1,
|
dp.SPI1,
|
||||||
(sck, miso, mosi),
|
(sck, miso, mosi),
|
||||||
&mut afio.mapr,
|
&mut afio.mapr,
|
||||||
|
@ -124,6 +138,44 @@ pub fn setup(
|
||||||
board_led: led,
|
board_led: led,
|
||||||
spi: spi,
|
spi: spi,
|
||||||
disp_cs: disp_cs,
|
disp_cs: disp_cs,
|
||||||
|
disp_dc: dc,
|
||||||
|
disp_rst: rst,
|
||||||
max_cs: max_cs,
|
max_cs: max_cs,
|
||||||
|
qei: qei,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<BLed, SPI, DispCS, DispDC, DispRST, MaxCS, QEI>
|
||||||
|
App<BLed, SPI, DispCS, DispDC, DispRST, MaxCS, QEI>
|
||||||
|
where
|
||||||
|
BLed: OutputPin,
|
||||||
|
SPI: spi::Transfer<u8> + spi::Write<u8>,
|
||||||
|
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 {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,9 +37,10 @@ fn main() -> ! {
|
||||||
// Get access to the device specific peripherals from the peripheral access crate
|
// Get access to the device specific peripherals from the peripheral access crate
|
||||||
let dp = pac::Peripherals::take().unwrap();
|
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);
|
let mut disp = st7735_lcd::ST7735::new(spi, dc, rst, true, false, 160, 128);
|
||||||
|
|
Loading…
Reference in New Issue