diff --git a/src/application.rs b/src/application.rs index d6a64e9..624b5e4 100644 --- a/src/application.rs +++ b/src/application.rs @@ -1,5 +1,4 @@ use arrayvec::ArrayString; -use core::convert::Infallible; use core::fmt::Write; use cortex_m::asm; use cortex_m_rt::{entry, exception}; @@ -8,9 +7,8 @@ use embedded_graphics::{ prelude::*, primitives::rectangle::Rectangle, style::PrimitiveStyleBuilder, style::TextStyleBuilder, }; -use embedded_hal::blocking::spi; + use embedded_hal::digital::v2::{InputPin, OutputPin}; -use embedded_hal::Qei; use profont::{ProFont12Point, ProFont9Point}; use rtt_target::{rprintln, rtt_init_print}; use st7735_lcd::Orientation; @@ -26,50 +24,34 @@ use stm32f1xx_hal::{ }; use tinybmp::Bmp; -pub struct App -where - BLed: OutputPin, - SPI: spi::Transfer + spi::Write, - DispCS: OutputPin, - DispDC: OutputPin, - DispRST: OutputPin, - MaxCS: OutputPin, - QEI: Qei, -{ +type AppSPI = Spi< + pac::SPI1, + Spi1NoRemap, + ( + gpioa::PA5>, + gpioa::PA6>, + gpioa::PA7>, + ), +>; + +type AppQEI = qei::Qei< + pac::TIM3, + Tim3PartialRemap, + (gpiob::PB4>, gpiob::PB5>), +>; + +pub struct App { delay: Delay, - board_led: BLed, - spi: SPI, - disp_cs: DispCS, - disp_dc: DispDC, - disp_rst: DispRST, - max_cs: MaxCS, - qei: QEI, + board_led: gpioc::PC13>, + spi: AppSPI, + disp_cs: gpioa::PA0>, + disp_dc: gpioa::PA4>, + disp_rst: gpioa::PA1>, + max_cs: gpioa::PA9>, + qei: AppQEI, } -pub fn setup( - cp: cortex_m::peripheral::Peripherals, - dp: stm32::Peripherals, -) -> App< - gpioc::PC13>, - Spi< - pac::SPI1, - Spi1NoRemap, - ( - gpioa::PA5>, - gpioa::PA6>, - gpioa::PA7>, - ), - >, - gpioa::PA0>, - gpioa::PA4>, - gpioa::PA1>, - gpioa::PA9>, - qei::Qei< - pac::TIM3, - Tim3PartialRemap, - (gpiob::PB4>, gpiob::PB5>), - >, -> { +pub fn setup(cp: cortex_m::peripheral::Peripherals, dp: stm32::Peripherals) -> App { // Take ownership over the raw flash and rcc devices and convert them into the corresponding // HAL structs let mut flash = dp.FLASH.constrain(); @@ -91,9 +73,9 @@ pub fn setup( // Configure gpio C pin 13 as a push-pull output. The `crh` register is passed to the function // in order to configure the port. For pins 0-7, crl should be passed instead. - let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh); + let led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh); - let mut delay = Delay::new(cp.SYST, clocks); + let delay = Delay::new(cp.SYST, clocks); let gpiob = dp.GPIOB.split(&mut rcc.apb2); let mut afio = dp.AFIO.constrain(&mut rcc.apb2); @@ -145,21 +127,12 @@ pub fn setup( } } -impl - App -where - BLed: OutputPin, - SPI: spi::Transfer + spi::Write, - DispCS: OutputPin, - DispDC: OutputPin, - DispRST: OutputPin, - MaxCS: OutputPin, - QEI: Qei, -{ +impl App { pub fn run(mut self) -> ! { let mut disp = st7735_lcd::ST7735::new(self.spi, self.disp_dc, self.disp_rst, true, false, 160, 128); - self.disp_cs.set_low().ok().unwrap(); + self.disp_cs.set_low().unwrap(); + disp.init(&mut self.delay).unwrap(); disp.set_orientation(&Orientation::LandscapeSwapped) .unwrap(); diff --git a/src/main.rs b/src/main.rs index 391e47f..68ead16 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,6 +27,7 @@ use tinybmp::Bmp; mod application; mod max6675; +mod profiles; #[entry] fn main() -> ! { diff --git a/src/profiles.rs b/src/profiles.rs new file mode 100644 index 0000000..d96388a --- /dev/null +++ b/src/profiles.rs @@ -0,0 +1,94 @@ +pub struct ReflowProfile { + name: &'static str, + points: [ProfilePoint; 6], +} + +pub struct ProfilePoint { + time: f32, + temp: f32, +} + +impl ReflowProfile { + pub fn get_name(&self) -> &'static str { + self.name + } + + pub fn get_temp(&self, time: f32) -> f32 { + let mut pos = 0; + while time > self.points[pos].time && pos < 6 { + pos += 1; + } + + if pos == 0 { + self.points[0].temp + } else if pos == 6 { + self.points[5].temp + } else { + let delta = (self.points[pos].temp - self.points[pos - 1].temp) + / (self.points[pos].time - self.points[pos - 1].time); + + (time - self.points[pos - 1].time) * delta + } + } +} + +pub const REFLOW_PROFILES: [ReflowProfile; 2] = [ + ReflowProfile { + name: "Profile 1", + points: [ + ProfilePoint { + time: 0f32, + temp: 0f32, + }, + ProfilePoint { + time: 0f32, + temp: 0f32, + }, + ProfilePoint { + time: 0f32, + temp: 0f32, + }, + ProfilePoint { + time: 0f32, + temp: 0f32, + }, + ProfilePoint { + time: 0f32, + temp: 0f32, + }, + ProfilePoint { + time: 0f32, + temp: 0f32, + }, + ], + }, + ReflowProfile { + name: "Profile 2", + points: [ + ProfilePoint { + time: 0f32, + temp: 0f32, + }, + ProfilePoint { + time: 0f32, + temp: 0f32, + }, + ProfilePoint { + time: 0f32, + temp: 0f32, + }, + ProfilePoint { + time: 0f32, + temp: 0f32, + }, + ProfilePoint { + time: 0f32, + temp: 0f32, + }, + ProfilePoint { + time: 0f32, + temp: 0f32, + }, + ], + }, +];