dice-game/src/main.rs
2025-09-10 21:46:03 +03:00

77 lines
1.8 KiB
Rust

/*!
* Blink the builtin LED - the "Hello World" of embedded programming.
*/
#![no_std]
#![no_main]
use atmega_hal::{
Usart,
spi::{self, Settings},
usart::Baudrate,
};
use embedded_hal::delay::DelayNs;
use panic_halt as _;
use crate::display::{Display, Position, Rgb565};
mod display;
type CoreClock = atmega_hal::clock::MHz8;
#[avr_device::entry]
fn main() -> ! {
let dp = atmega_hal::Peripherals::take().unwrap();
let pins = atmega_hal::pins!(dp);
let rx = pins.pd0;
let tx = pins.pd1;
let mut serial = Usart::new(
dp.USART0,
rx,
tx.into_output(),
Baudrate::<CoreClock>::new(57600),
);
let cs = pins.pb2.into_output();
let (mut spi, mut cs) = spi::Spi::new(
dp.SPI,
pins.pb5.into_output(),
pins.pb3.into_output(),
pins.pb4.into_pull_up_input(),
cs,
Settings {
data_order: spi::DataOrder::MostSignificantFirst,
clock: spi::SerialClockRate::OscfOver2,
mode: embedded_hal::spi::Mode {
polarity: embedded_hal::spi::Polarity::IdleHigh,
phase: embedded_hal::spi::Phase::CaptureOnFirstTransition,
},
},
);
let mut display = Display {
spi,
dc: pins.pb1.into_output(),
cs,
rst: pins.pd7.into_output(),
delay: atmega_hal::delay::Delay::<CoreClock>::new(),
};
display.init();
let mut delay = atmega_hal::delay::Delay::<CoreClock>::new();
let mut color = 0;
loop {
// color += 40;
delay.delay_ms(1000);
display.draw_rect(
Position { x: 0, y: 0 },
Position { x: 200, y: 200 },
Rgb565(0, 0, 255).as_color(),
);
color = color + 5 % 255;
ufmt::uwriteln!(&mut serial, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA").unwrap();
}
}