All of the hardware works proof of concept wise

This commit is contained in:
Sebastian 2020-09-17 22:31:48 +02:00
parent 14f2a02889
commit b8d27f374f
3 changed files with 117 additions and 55 deletions

View File

@ -4,18 +4,19 @@ edition = "2018"
readme = "README.md" readme = "README.md"
name = "reflow-firmware" name = "reflow-firmware"
version = "0.1.0" version = "0.1.0"
default-features = false
[dependencies] [dependencies]
cortex-m = "0.6" cortex-m = "0.6"
cortex-m-rt = "0.6" cortex-m-rt = "0.6"
stm32f1xx-hal = { version = "0.6.1", features = ["stm32f103", "rt"] } stm32f1xx-hal = { version = "0.6.1", features = ["stm32f103", "rt"] }
panic-semihosting = "0.5"
embedded-hal = "0.2.3" embedded-hal = "0.2.3"
rtt-target = {version = "0.2.2", features = ["cortex-m"]} rtt-target = {version = "0.2.2", features = ["cortex-m"]}
st7735-lcd = { git = "https://github.com/LongHairedHacker/st7735-lcd-rs.git", branch = "fix-short-rectangles" } st7735-lcd = { git = "https://github.com/LongHairedHacker/st7735-lcd-rs.git", branch = "release-display-interface"}
embedded-graphics = "0.6.2" embedded-graphics = "0.6.2"
tinybmp = {version ="0.2.3", features = ["graphics"]} tinybmp = {version ="0.2.3", features = ["graphics"]}
profont = "0.4.0"
arrayvec = {version = "0.5.1", default-features = false}
# this lets you use `cargo fix`! # this lets you use `cargo fix`!
[[bin]] [[bin]]

View File

@ -2,26 +2,31 @@
#![no_std] #![no_std]
#![no_main] #![no_main]
extern crate panic_semihosting; use arrayvec::ArrayString;
use core::fmt::Write;
use cortex_m_rt::entry; use cortex_m::asm;
use embedded_graphics::image::Image; use cortex_m_rt::{entry, exception};
use embedded_graphics::pixelcolor::Rgb565; use embedded_graphics::{
use embedded_graphics::prelude::*; drawable::Drawable, fonts::Text, image::Image, pixelcolor::BinaryColor, pixelcolor::Rgb565,
use embedded_graphics::primitives::rectangle::Rectangle; prelude::*, primitives::rectangle::Rectangle, style::PrimitiveStyleBuilder,
use embedded_graphics::style::PrimitiveStyleBuilder; style::TextStyleBuilder,
use embedded_hal::digital::v2::OutputPin; };
use embedded_hal::digital::v2::{InputPin, OutputPin};
use profont::{ProFont12Point, ProFont9Point};
use rtt_target::{rprintln, rtt_init_print}; use rtt_target::{rprintln, rtt_init_print};
use st7735_lcd::Orientation; use st7735_lcd::Orientation;
use stm32f1xx_hal::{ use stm32f1xx_hal::{
delay::Delay, delay::Delay,
pac, pac,
prelude::*, prelude::*,
qei::QeiOptions,
spi::{Mode, Phase, Polarity, Spi}, spi::{Mode, Phase, Polarity, Spi},
timer::Timer,
}; };
use tinybmp::Bmp; use tinybmp::Bmp;
mod max6675;
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
rtt_init_print!(); rtt_init_print!();
@ -48,6 +53,7 @@ fn main() -> ! {
// Acquire the GPIOC peripheral // Acquire the GPIOC peripheral
let mut gpioc = dp.GPIOC.split(&mut rcc.apb2); let mut gpioc = dp.GPIOC.split(&mut rcc.apb2);
let mut gpioa = dp.GPIOA.split(&mut rcc.apb2);
// Configure gpio C pin 13 as a push-pull output. The `crh` register is passed to the function // 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. // in order to configure the port. For pins 0-7, crl should be passed instead.
@ -55,24 +61,32 @@ fn main() -> ! {
let mut delay = Delay::new(cp.SYST, clocks); let mut delay = Delay::new(cp.SYST, clocks);
let gpiob = dp.GPIOB.split(&mut rcc.apb2);
let mut afio = dp.AFIO.constrain(&mut rcc.apb2); let mut afio = dp.AFIO.constrain(&mut rcc.apb2);
let mut gpioa = dp.GPIOA.split(&mut rcc.apb2); let (_, _, pb4) = afio.mapr.disable_jtag(gpioa.pa15, gpiob.pb3, gpiob.pb4);
let qei = Timer::tim3(dp.TIM3, &clocks, &mut rcc.apb1).qei(
(pb4, gpiob.pb5),
&mut afio.mapr,
QeiOptions::default(),
);
// SPI1 // SPI1
let sck = gpioa.pa5.into_alternate_push_pull(&mut gpioa.crl); let sck = gpioa.pa5.into_alternate_push_pull(&mut gpioa.crl);
let miso = gpioa.pa6; let miso = gpioa.pa6;
let mosi = gpioa.pa7.into_alternate_push_pull(&mut gpioa.crl); let mosi = gpioa.pa7.into_alternate_push_pull(&mut gpioa.crl);
let disp_cs = gpioa.pa0.into_push_pull_output(&mut gpioa.crl); let mut disp_cs = gpioa.pa0.into_push_pull_output(&mut gpioa.crl);
let mut max_cs = gpioa.pa9.into_push_pull_output(&mut gpioa.crh);
let rst = gpioa.pa1.into_push_pull_output(&mut gpioa.crl); let mut rst = gpioa.pa1.into_push_pull_output(&mut gpioa.crl);
let dc = gpioa.pa4.into_push_pull_output(&mut gpioa.crl); let mut dc = gpioa.pa4.into_push_pull_output(&mut gpioa.crl);
let mut disp_led = gpioa.pa8.into_push_pull_output(&mut gpioa.crh); let mut disp_led = gpioa.pa8.into_push_pull_output(&mut gpioa.crh);
disp_led.set_high(); disp_led.set_high().unwrap();
let spi = Spi::spi1( let mut spi = Spi::spi1(
dp.SPI1, dp.SPI1,
(sck, miso, mosi), (sck, miso, mosi),
&mut afio.mapr, &mut afio.mapr,
@ -86,8 +100,7 @@ fn main() -> ! {
); );
let mut disp = st7735_lcd::ST7735::new(spi, dc, rst, true, false, 160, 128); let mut disp = st7735_lcd::ST7735::new(spi, dc, rst, true, false, 160, 128);
disp_cs.set_low().unwrap();
disp.hard_reset(&mut delay).unwrap();
disp.init(&mut delay).unwrap(); disp.init(&mut delay).unwrap();
disp.set_orientation(&Orientation::LandscapeSwapped) disp.set_orientation(&Orientation::LandscapeSwapped)
.unwrap(); .unwrap();
@ -100,44 +113,66 @@ fn main() -> ! {
.draw(&mut disp) .draw(&mut disp)
.unwrap(); .unwrap();
/*
let style_red = PrimitiveStyleBuilder::new().fill_color(Rgb565::RED).build();
let style_green = PrimitiveStyleBuilder::new()
.fill_color(Rgb565::GREEN)
.build();
let style_blue = PrimitiveStyleBuilder::new()
.fill_color(Rgb565::BLUE)
.build();
Rectangle::new(Point::new(0, 0), Point::new(10, 20))
.into_styled(style_red)
.draw(&mut disp)
.unwrap();
disp.set_pixel(10, 20, 0x07E0);
Rectangle::new(Point::new(55, 0), Point::new(105, 128))
.into_styled(style_green)
.draw(&mut disp)
.unwrap();
Rectangle::new(Point::new(110, 0), Point::new(159, 128))
.into_styled(style_blue)
.draw(&mut disp)
.unwrap();
*/
let bmp = Bmp::from_slice(include_bytes!("logo.bmp")).unwrap(); let bmp = Bmp::from_slice(include_bytes!("logo.bmp")).unwrap();
let image = Image::new(&bmp, Point::new(16, 0)); let image = Image::new(&bmp, Point::new(16, 0));
image.draw(&mut disp).unwrap(); image.draw(&mut disp).unwrap();
// Blink using the delay function 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 { loop {
rprintln!("blink"); let temp = max6675::read(&mut spi, &mut max_cs).unwrap();
led.set_high().unwrap(); rprintln!("T: {}", temp);
delay.delay_ms(1000u16);
rprintln!("blonk"); // Create a fixed buffer of length 12
led.set_low().unwrap(); let mut buf = ArrayString::<[_; 10]>::new();
delay.delay_ms(1000u16); // 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
} }
} }

26
src/max6675.rs Normal file
View File

@ -0,0 +1,26 @@
use embedded_hal::blocking::spi;
use embedded_hal::digital::v2::OutputPin;
pub fn read<SPI, NSS>(spi: &mut SPI, nss_pin: &mut NSS) -> Result<f32, &'static str>
where
SPI: spi::Transfer<u8>,
NSS: OutputPin,
{
let mut buffer = [0u8, 0u8];
nss_pin.set_low();
let res = spi.transfer(&mut buffer);
nss_pin.set_high();
let raw_result = match res {
Ok(value) => (value[0] as u16) << 8 | (value[1] as u16),
Err(_) => return Err("SPI transfer failed"),
};
if raw_result & (1 << 2) != 0 {
Err("MAX6675: Termocouple measures open")
} else {
let result = ((raw_result >> 3) as f32) * 0.25;
Ok(result)
}
}