ST7735 works

This commit is contained in:
Sebastian 2020-09-09 21:35:04 +02:00
parent 8249c4c3b6
commit 14f2a02889
3 changed files with 101 additions and 3 deletions

View File

@ -8,10 +8,13 @@ version = "0.1.0"
[dependencies]
cortex-m = "0.6"
cortex-m-rt = "0.6"
stm32f1xx-hal = { version = "0.5.3", features = ["stm32f103", "rt"] }
stm32f1xx-hal = { version = "0.6.1", features = ["stm32f103", "rt"] }
panic-semihosting = "0.5"
embedded-hal = "0.2.3"
rtt-target = {version = "0.2.2", features = ["cortex-m"]}
st7735-lcd = { git = "https://github.com/LongHairedHacker/st7735-lcd-rs.git", branch = "fix-short-rectangles" }
embedded-graphics = "0.6.2"
tinybmp = {version ="0.2.3", features = ["graphics"]}
# this lets you use `cargo fix`!

BIN
src/logo.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

View File

@ -5,9 +5,22 @@
extern crate panic_semihosting;
use cortex_m_rt::entry;
use embedded_graphics::image::Image;
use embedded_graphics::pixelcolor::Rgb565;
use embedded_graphics::prelude::*;
use embedded_graphics::primitives::rectangle::Rectangle;
use embedded_graphics::style::PrimitiveStyleBuilder;
use embedded_hal::digital::v2::OutputPin;
use rtt_target::{rprintln, rtt_init_print};
use stm32f1xx_hal::{delay::Delay, pac, prelude::*};
use st7735_lcd::Orientation;
use stm32f1xx_hal::{
delay::Delay,
pac,
prelude::*,
spi::{Mode, Phase, Polarity, Spi},
};
use tinybmp::Bmp;
#[entry]
fn main() -> ! {
@ -21,11 +34,17 @@ fn main() -> ! {
// Take ownership over the raw flash and rcc devices and convert them into the corresponding
// HAL structs
let mut flash = dp.FLASH.constrain();
let mut rcc = dp.RCC.constrain();
// Freeze the configuration of all the clocks in the system and store the frozen frequencies in
// `clocks`
let clocks = rcc.cfgr.freeze(&mut flash.acr);
let clocks = rcc
.cfgr
.use_hse(8.mhz())
.sysclk(72.mhz())
.pclk1(36.mhz())
.freeze(&mut flash.acr);
// Acquire the GPIOC peripheral
let mut gpioc = dp.GPIOC.split(&mut rcc.apb2);
@ -36,6 +55,82 @@ fn main() -> ! {
let mut delay = Delay::new(cp.SYST, clocks);
let mut afio = dp.AFIO.constrain(&mut rcc.apb2);
let mut gpioa = dp.GPIOA.split(&mut rcc.apb2);
// 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 disp_cs = gpioa.pa0.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();
let spi = Spi::spi1(
dp.SPI1,
(sck, miso, mosi),
&mut afio.mapr,
Mode {
polarity: Polarity::IdleLow,
phase: Phase::CaptureOnFirstTransition,
},
16.mhz(),
clocks,
&mut rcc.apb2,
);
let mut disp = st7735_lcd::ST7735::new(spi, dc, rst, true, false, 160, 128);
disp.hard_reset(&mut delay).unwrap();
disp.init(&mut 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 style_red = PrimitiveStyleBuilder::new().fill_color(Rgb565::RED).build();
let style_green = PrimitiveStyleBuilder::new()
.fill_color(Rgb565::GREEN)
.build();
let style_blue = PrimitiveStyleBuilder::new()
.fill_color(Rgb565::BLUE)
.build();
Rectangle::new(Point::new(0, 0), Point::new(10, 20))
.into_styled(style_red)
.draw(&mut disp)
.unwrap();
disp.set_pixel(10, 20, 0x07E0);
Rectangle::new(Point::new(55, 0), Point::new(105, 128))
.into_styled(style_green)
.draw(&mut disp)
.unwrap();
Rectangle::new(Point::new(110, 0), Point::new(159, 128))
.into_styled(style_blue)
.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();
// Blink using the delay function
loop {
rprintln!("blink");