clock_generator/firmware/rust/src/main.rs
finga 643e5f1af4 fw-rust: Create a SPI interface for the display
In order to, later on, send data to the display create a SPI
interface.
2022-03-06 19:20:49 +01:00

62 lines
1.4 KiB
Rust

#![no_std]
#![no_main]
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]
fn main() -> ! {
// Disable interrupts when initializing
interrupt::disable();
// Get peripherals and pins
let dp = Peripherals::take().unwrap();
let pins = pins!(dp);
// Init display backlight
let tc0 = dp.TC0;
tc0.tccr0a.write(|w| {
w.wgm0().pwm_fast();
w.com0b().match_clear();
w
});
tc0.tccr0b.write(|w| {
w.wgm02().set_bit();
w.cs0().prescale_64();
w
});
tc0.ocr0a.write(|w| unsafe { w.bits(255) });
// TODO: Use EEPROM
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() };
#[allow(clippy::empty_loop)]
loop {}
}