From 643e5f1af4e957aec29a9e102e89a95b33c09ac4 Mon Sep 17 00:00:00 2001 From: finga Date: Fri, 4 Mar 2022 13:11:45 +0100 Subject: [PATCH] fw-rust: Create a SPI interface for the display In order to, later on, send data to the display create a SPI interface. --- firmware/rust/src/main.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/firmware/rust/src/main.rs b/firmware/rust/src/main.rs index 88c8d5f..bf1f68b 100644 --- a/firmware/rust/src/main.rs +++ b/firmware/rust/src/main.rs @@ -1,8 +1,13 @@ #![no_std] #![no_main] -use atmega_hal::{pins, Peripherals}; +use atmega_hal::{ + pins, + spi::{DataOrder, SerialClockRate, Settings, Spi}, + Peripherals, +}; use avr_device::interrupt; +use embedded_hal::spi::{Mode, Phase, Polarity}; use panic_halt as _; #[atmega_hal::entry] @@ -31,6 +36,23 @@ fn main() -> ! { tc0.ocr0b.write(|w| unsafe { w.bits(0) }); pins.pd5.into_output(); + // Init SPI + let (_, _) = Spi::new( + dp.SPI, + pins.pb5.into_output(), + pins.pb3.into_output(), + pins.pb4.into_pull_up_input(), + pins.pb2.into_output(), + Settings { + data_order: DataOrder::MostSignificantFirst, + clock: SerialClockRate::OscfOver2, + mode: Mode { + polarity: Polarity::IdleLow, + phase: Phase::CaptureOnFirstTransition, + }, + }, + ); + // Enable interrupts unsafe { interrupt::enable() };