aboutsummaryrefslogtreecommitdiffstats
path: root/sw/deps/hd44780-driver/examples/stm32f30x-i2c/src
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2020-06-28 16:42:21 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2020-06-28 16:42:21 +0200
commit5d1cff57f9f5acd740a8b5f8c941beefdcc00176 (patch)
treebdfd0e394d6333aead7d3a0295ba3457bd68275d /sw/deps/hd44780-driver/examples/stm32f30x-i2c/src
parent93220f99a52dc93f9a2d5b11074f60156ef70210 (diff)
downloadpicardy-5d1cff57f9f5acd740a8b5f8c941beefdcc00176.tar.gz
picardy-5d1cff57f9f5acd740a8b5f8c941beefdcc00176.tar.bz2
picardy-5d1cff57f9f5acd740a8b5f8c941beefdcc00176.zip
sw: configure si5351
Diffstat (limited to 'sw/deps/hd44780-driver/examples/stm32f30x-i2c/src')
-rw-r--r--sw/deps/hd44780-driver/examples/stm32f30x-i2c/src/main.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/sw/deps/hd44780-driver/examples/stm32f30x-i2c/src/main.rs b/sw/deps/hd44780-driver/examples/stm32f30x-i2c/src/main.rs
new file mode 100644
index 0000000..3ecfafd
--- /dev/null
+++ b/sw/deps/hd44780-driver/examples/stm32f30x-i2c/src/main.rs
@@ -0,0 +1,52 @@
+#![no_std]
+#![no_main]
+
+extern crate panic_halt;
+
+use core::fmt::Write;
+use cortex_m_rt::entry;
+use hal::prelude::*;
+use hal::flash::FlashExt;
+use hal::i2c::I2c;
+use hd44780_driver::{Cursor, CursorBlink, Display, DisplayMode, HD44780};
+
+// Connections:
+// VSS: GND
+// VDD: 5V
+// SCL: PB6
+// SDA: PB9
+// I2C address : 0x3F
+
+const I2C_ADDRESS: u8 = 0x3F;
+
+#[entry]
+fn main() -> ! {
+ let cp = cortex_m::Peripherals::take().unwrap();
+ let dp = hal::stm32f30x::Peripherals::take().unwrap();
+
+ let mut flash = dp.FLASH.constrain();
+ let mut rcc = dp.RCC.constrain();
+ let mut gpiob = dp.GPIOB.split(&mut rcc.ahb);
+
+ let clocks = rcc.cfgr.freeze(&mut flash.acr);
+ let delay = hal::delay::Delay::new(cp.SYST, clocks);
+
+ let scl = gpiob.pb6.into_af4(&mut gpiob.moder, &mut gpiob.afrl);
+ let sda = gpiob.pb9.into_af4(&mut gpiob.moder, &mut gpiob.afrh);
+
+ let i2c = I2c::i2c1(dp.I2C1, (scl, sda), 400.khz(), clocks, &mut rcc.apb1);
+
+ let mut lcd = HD44780::new_i2c(i2c, I2C_ADDRESS, delay);
+ lcd.reset();
+ lcd.clear();
+ lcd.set_display_mode(
+ DisplayMode {
+ display: Display::On,
+ cursor_visibility: Cursor::Visible,
+ cursor_blink: CursorBlink::On,
+ }
+ );
+ let _ = lcd.write_str("Hello, world!");
+
+ loop {}
+}