Cleaner app struct

Added profiles
This commit is contained in:
Sebastian 2020-10-04 15:39:30 +02:00
parent 3e00a1f044
commit 1187021d42
3 changed files with 126 additions and 58 deletions

View File

@ -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<BLed, SPI, DispCS, DispDC, DispRST, MaxCS, QEI>
where
BLed: OutputPin,
SPI: spi::Transfer<u8> + spi::Write<u8>,
DispCS: OutputPin,
DispDC: OutputPin,
DispRST: OutputPin,
MaxCS: OutputPin,
QEI: Qei,
{
type AppSPI = Spi<
pac::SPI1,
Spi1NoRemap,
(
gpioa::PA5<Alternate<PushPull>>,
gpioa::PA6<Input<Floating>>,
gpioa::PA7<Alternate<PushPull>>,
),
>;
type AppQEI = qei::Qei<
pac::TIM3,
Tim3PartialRemap,
(gpiob::PB4<Input<Floating>>, gpiob::PB5<Input<Floating>>),
>;
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<Output<PushPull>>,
spi: AppSPI,
disp_cs: gpioa::PA0<Output<PushPull>>,
disp_dc: gpioa::PA4<Output<PushPull>>,
disp_rst: gpioa::PA1<Output<PushPull>>,
max_cs: gpioa::PA9<Output<PushPull>>,
qei: AppQEI,
}
pub fn setup(
cp: cortex_m::peripheral::Peripherals,
dp: stm32::Peripherals,
) -> App<
gpioc::PC13<Output<PushPull>>,
Spi<
pac::SPI1,
Spi1NoRemap,
(
gpioa::PA5<Alternate<PushPull>>,
gpioa::PA6<Input<Floating>>,
gpioa::PA7<Alternate<PushPull>>,
),
>,
gpioa::PA0<Output<PushPull>>,
gpioa::PA4<Output<PushPull>>,
gpioa::PA1<Output<PushPull>>,
gpioa::PA9<Output<PushPull>>,
qei::Qei<
pac::TIM3,
Tim3PartialRemap,
(gpiob::PB4<Input<Floating>>, gpiob::PB5<Input<Floating>>),
>,
> {
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<BLed, SPI, DispCS, DispDC, DispRST, MaxCS, QEI>
App<BLed, SPI, DispCS, DispDC, DispRST, MaxCS, QEI>
where
BLed: OutputPin,
SPI: spi::Transfer<u8> + spi::Write<u8>,
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();

View File

@ -27,6 +27,7 @@ use tinybmp::Bmp;
mod application;
mod max6675;
mod profiles;
#[entry]
fn main() -> ! {

94
src/profiles.rs Normal file
View File

@ -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,
},
],
},
];