From 113d976502dba07a289f0b4bd133dba3a8755450 Mon Sep 17 00:00:00 2001 From: Luca Date: Mon, 10 Jul 2023 17:34:30 +0200 Subject: [PATCH] Init display --- Cargo.lock | 1 + Cargo.toml | 1 + src/main.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 087f844..bce6cde 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -360,6 +360,7 @@ name = "soldering-iron" version = "0.1.0" dependencies = [ "cortex-m-rt", + "fugit", "panic-halt", "rp-pico", "ssd1306", diff --git a/Cargo.toml b/Cargo.toml index 36b0331..0a5adc2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" [dependencies] cortex-m-rt = "0.7.3" +fugit = "0.3.7" panic-halt = "0.2.0" rp-pico = "0.7.0" ssd1306 = "0.8.0" diff --git a/src/main.rs b/src/main.rs index 5c241b8..c3f7e09 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,56 @@ #![no_std] #![no_main] +use fugit::RateExtU32; + use panic_halt as _; use rp_pico::entry; +use rp_pico::hal::clocks::{self, Clock}; +use rp_pico::hal::i2c::I2C; +use rp_pico::hal::{Sio, Watchdog}; +use rp_pico::pac::Peripherals; +use rp_pico::Pins; + +use ssd1306::prelude::*; +use ssd1306::{I2CDisplayInterface, Ssd1306}; #[entry] fn main() -> ! { + let mut p = Peripherals::take().unwrap(); + + let mut watchdog = Watchdog::new(p.WATCHDOG); + let clocks = clocks::init_clocks_and_plls( + rp_pico::XOSC_CRYSTAL_FREQ, + p.XOSC, + p.CLOCKS, + p.PLL_SYS, + p.PLL_USB, + &mut p.RESETS, + &mut watchdog, + ) + .ok() + .unwrap(); + + let sio = Sio::new(p.SIO); + let pins = Pins::new(p.IO_BANK0, p.PADS_BANK0, sio.gpio_bank0, &mut p.RESETS); + + let i2c = I2C::i2c0( + p.I2C0, + pins.gpio16.into_mode(), + pins.gpio17.into_mode(), + 400.kHz(), + &mut p.RESETS, + clocks.peripheral_clock.freq(), + ); + let mut display = Ssd1306::new( + I2CDisplayInterface::new_custom_address(i2c, 0x78), + DisplaySize128x64, + DisplayRotation::Rotate0, + ) + .into_buffered_graphics_mode(); + + display.init().unwrap(); + loop {} }