feat: lcd works in my head
This commit is contained in:
parent
806a5ac871
commit
7e5f33f1c6
3 changed files with 95 additions and 0 deletions
36
Cargo.lock
generated
36
Cargo.lock
generated
|
@ -38,6 +38,12 @@ version = "0.13.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "46afbd2983a5d5a7bd740ccb198caf5b82f45c40c09c0eed36052d91cb92e719"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
||||
|
||||
[[package]]
|
||||
name = "cast"
|
||||
version = "0.3.0"
|
||||
|
@ -104,6 +110,34 @@ dependencies = [
|
|||
"num",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hash32"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hd44780-driver"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aab2b13fdeaed7dde9133a57c28b2cbde4a8fc8c3196b5631428aad114857d3a"
|
||||
dependencies = [
|
||||
"embedded-hal",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heapless"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad"
|
||||
dependencies = [
|
||||
"hash32",
|
||||
"stable_deref_trait",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nb"
|
||||
version = "0.1.3"
|
||||
|
@ -125,6 +159,8 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"cortex-m",
|
||||
"cortex-m-rt",
|
||||
"hd44780-driver",
|
||||
"heapless",
|
||||
"panic-halt",
|
||||
"stm32l0xx-hal",
|
||||
]
|
||||
|
|
|
@ -12,3 +12,5 @@ hal = { package = "stm32l0xx-hal", version = "0.10.0", features = [
|
|||
cortex-m-rt = "0.7.5"
|
||||
panic-halt = "1.0.0"
|
||||
cortex-m = "0.7.7"
|
||||
hd44780-driver = "0.4.0"
|
||||
heapless = "0.8.0"
|
||||
|
|
57
examples/lcd.rs
Executable file
57
examples/lcd.rs
Executable file
|
@ -0,0 +1,57 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
extern crate panic_halt;
|
||||
|
||||
use core::fmt::Write;
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
use hal::{pac, prelude::*, rcc::Config};
|
||||
use hd44780_driver::HD44780;
|
||||
use heapless::Vec;
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let dp = pac::Peripherals::take().unwrap();
|
||||
let cp = cortex_m::Peripherals::take().unwrap();
|
||||
|
||||
let mut rcc = dp.RCC.freeze(Config::hsi16());
|
||||
|
||||
let gpioa = dp.GPIOA.split(&mut rcc);
|
||||
let _gpiob = dp.GPIOB.split(&mut rcc);
|
||||
let gpioc = dp.GPIOC.split(&mut rcc);
|
||||
|
||||
let d0 = gpioc.pc0.into_push_pull_output();
|
||||
let d1 = gpioc.pc1.into_push_pull_output();
|
||||
let d2 = gpioc.pc2.into_push_pull_output();
|
||||
let d3 = gpioc.pc3.into_push_pull_output();
|
||||
let d4 = gpioc.pc4.into_push_pull_output();
|
||||
let d5 = gpioc.pc5.into_push_pull_output();
|
||||
let d6 = gpioc.pc6.into_push_pull_output();
|
||||
let d7 = gpioc.pc7.into_push_pull_output();
|
||||
|
||||
let rs = gpioc.pc8.into_push_pull_output();
|
||||
let en = gpioc.pc9.into_push_pull_output();
|
||||
|
||||
let mut delay = cp.SYST.delay(rcc.clocks);
|
||||
|
||||
let mut led = gpioa.pa5.into_push_pull_output();
|
||||
let mut lcd = HD44780::new_8bit(rs, en, d0, d1, d2, d3, d4, d5, d6, d7, &mut delay).unwrap();
|
||||
|
||||
let mut i = 0;
|
||||
let mut buf: Vec<u8, 40> = Vec::new();
|
||||
loop {
|
||||
lcd.write_str("Hello world!", &mut delay).unwrap();
|
||||
led.set_high().unwrap();
|
||||
|
||||
delay.delay_ms(500_u16);
|
||||
|
||||
led.set_low().unwrap();
|
||||
write!(buf, "hello: {i}").unwrap();
|
||||
lcd.write_bytes(&buf, &mut delay).unwrap();
|
||||
|
||||
delay.delay_ms(500_u16);
|
||||
|
||||
i += 1;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue