reflow-firmware3.0/src/main.rs

123 lines
3.1 KiB
Rust

#![deny(unsafe_code)]
#![no_std]
#![no_main]
use arrayvec::ArrayString;
use core::fmt::Write;
use cortex_m::asm;
use cortex_m_rt::{entry, exception};
use embedded_graphics::{
drawable::Drawable, fonts::Text, image::Image, pixelcolor::BinaryColor, pixelcolor::Rgb565,
prelude::*, primitives::rectangle::Rectangle, style::PrimitiveStyleBuilder,
style::TextStyleBuilder,
};
use embedded_hal::digital::v2::{InputPin, OutputPin};
use profont::{ProFont12Point, ProFont9Point};
use rtt_target::{rprintln, rtt_init_print};
use st7735_lcd::Orientation;
use stm32f1xx_hal::{
delay::Delay,
pac,
prelude::*,
qei::QeiOptions,
spi::{Mode, Phase, Polarity, Spi},
timer::Timer,
};
use tinybmp::Bmp;
mod application;
mod max6675;
#[entry]
fn main() -> ! {
rtt_init_print!();
// Get access to the core peripherals from the cortex-m crate
let cp = cortex_m::Peripherals::take().unwrap();
// Get access to the device specific peripherals from the peripheral access crate
let dp = pac::Peripherals::take().unwrap();
let app = application::setup(cp, dp);
loop {}
/*
let mut disp = st7735_lcd::ST7735::new(spi, dc, rst, true, false, 160, 128);
disp_cs.set_low().unwrap();
disp.init(&mut delay).unwrap();
disp.set_orientation(&Orientation::LandscapeSwapped)
.unwrap();
let style_black = PrimitiveStyleBuilder::new()
.fill_color(Rgb565::BLACK)
.build();
Rectangle::new(Point::new(0, 0), Point::new(160, 128))
.into_styled(style_black)
.draw(&mut disp)
.unwrap();
let bmp = Bmp::from_slice(include_bytes!("logo.bmp")).unwrap();
let image = Image::new(&bmp, Point::new(16, 0));
image.draw(&mut disp).unwrap();
let (_spi, _dc, _rst) = disp.release();
spi = _spi;
dc = _dc;
rst = _rst;
disp_cs.set_high().unwrap();
let text_lager = TextStyleBuilder::new(ProFont12Point)
.text_color(Rgb565::WHITE)
.build();
loop {
let temp = max6675::read(&mut spi, &mut max_cs).unwrap();
rprintln!("T: {}", temp);
// Create a fixed buffer of length 12
let mut buf = ArrayString::<[_; 10]>::new();
// Output `Value: 12.35`
write!(&mut buf, "T: {}", qei.count() / 4).expect("Failed to write to buffer");
disp_cs.set_low().unwrap();
let mut disp = st7735_lcd::ST7735::new(spi, dc, rst, true, false, 160, 128);
Rectangle::new(Point::new(0, 100), Point::new(160, 128))
.into_styled(style_black)
.draw(&mut disp)
.unwrap();
Text::new(&buf, Point::new(60, 100))
.into_styled(text_lager)
.draw(&mut disp)
.unwrap();
let (_spi, _dc, _rst) = disp.release();
spi = _spi;
dc = _dc;
rst = _rst;
disp_cs.set_high().unwrap();
delay.delay_ms(250u16);
}
*/
}
#[exception]
fn PendSV() {
rprintln!("PendSV");
panic!()
}
#[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {
rprintln!("{}", info);
exit()
}
fn exit() -> ! {
loop {
asm::bkpt() // halt = exit probe-run
}
}