167 lines
4.5 KiB
Rust
167 lines
4.5 KiB
Rust
#![no_std]
|
|
#![feature(asm, used, const_fn, naked_functions, alloc, box_syntax)]
|
|
#![no_main]
|
|
#![feature(extern_prelude)]
|
|
|
|
#[macro_use]
|
|
extern crate hcl;
|
|
|
|
#[macro_use]
|
|
extern crate alloc;
|
|
|
|
use core::mem;
|
|
use hcl::platform::gpio;
|
|
use hcl::platform::irq;
|
|
use hcl::platform::rcc;
|
|
use hcl::platform::scs;
|
|
use hcl::platform::timer;
|
|
use hcl::platform::usart;
|
|
use hcl::platform::dma;
|
|
use hcl::dma::*;
|
|
|
|
mod systick;
|
|
mod printer;
|
|
mod max6675;
|
|
mod st7735;
|
|
|
|
use printer::UsartPrinter;
|
|
|
|
|
|
fn configure_clocks(rcc: &mut rcc::RCC) {
|
|
rcc.clock_control.set_hse_on(true);
|
|
while !rcc.clock_control.hse_ready() {}
|
|
|
|
rcc.clock_config
|
|
.configure(|c| {
|
|
c.set_pll_multiplier(10)
|
|
.set_pll_source(rcc::PllSource::HsiDiv2)
|
|
});
|
|
|
|
rcc.clock_control.set_pll_on(true);
|
|
while !rcc.clock_control.pll_ready() {}
|
|
|
|
rcc.clock_config
|
|
.switch_clock_source(rcc::SystemClockSource::Pll);
|
|
}
|
|
|
|
|
|
|
|
hcl_ivt!{
|
|
systick => systick::isr;
|
|
}
|
|
|
|
fn configure_peripherals(rcc: &mut hcl::platform::rcc::RCC,
|
|
gpio_a: &mut gpio::GPIO,
|
|
gpio_c: &mut gpio::GPIO,
|
|
usart: &mut usart::USART) {
|
|
rcc.apb2_enable
|
|
.configure(|a| a.set_gpio_a(true).set_gpio_c(true).set_spi1(true));
|
|
rcc.apb1_enable.configure(|a| a.set_usart2(true));
|
|
|
|
gpio_a.configure(|g| {
|
|
g.set_mode(2, gpio::PinMode::Output50MHz)
|
|
.set_output_config(2, gpio::OutputConfig::AfPushPull)
|
|
.set_mode(3, gpio::PinMode::Output50MHz)
|
|
.set_output_config(3, gpio::OutputConfig::AfPushPull)
|
|
// SCK1
|
|
.set_mode(5, gpio::PinMode::Output50MHz)
|
|
.set_output_config(5, gpio::OutputConfig::AfPushPull)
|
|
// MOSI1
|
|
.set_mode(7, gpio::PinMode::Output50MHz)
|
|
.set_output_config(7, gpio::OutputConfig::AfPushPull)
|
|
// MISO1
|
|
.set_mode(6, gpio::PinMode::Input)
|
|
.set_input_config(6, gpio::InputConfig::PullUpDown)
|
|
// SS MAX6675
|
|
.set_mode(9, gpio::PinMode::Output50MHz)
|
|
.set_output_config(9, gpio::OutputConfig::PushPull)
|
|
// ST7735 cs pin
|
|
.set_mode(0, gpio::PinMode::Output50MHz)
|
|
.set_output_config(0, gpio::OutputConfig::PushPull)
|
|
// ST7735 rst pin
|
|
.set_mode(1, gpio::PinMode::Output50MHz)
|
|
.set_output_config(1, gpio::OutputConfig::PushPull)
|
|
// ST7735 rs pin
|
|
.set_mode(4, gpio::PinMode::Output50MHz)
|
|
.set_output_config(4, gpio::OutputConfig::PushPull)
|
|
// ST7735 led pin
|
|
.set_mode(8, gpio::PinMode::Output50MHz)
|
|
.set_output_config(8, gpio::OutputConfig::PushPull)
|
|
});
|
|
|
|
gpio_c.configure(|g| {
|
|
g.set_mode(13, gpio::PinMode::Output50MHz)
|
|
.set_output_config(13, gpio::OutputConfig::PushPull)
|
|
});
|
|
|
|
|
|
usart.configure(|u| {
|
|
u.set_enabled(true)
|
|
.set_tx_enabled(true)
|
|
.set_baudgen((21, 11))
|
|
}); // 115.2 kbaud
|
|
}
|
|
|
|
|
|
// allowing inlining into main() breaks the stack, since main() must be naked to set up a process stack.
|
|
#[inline(never)]
|
|
fn run(mut scs: scs::Instance, mut p: hcl::platform::Instance) {
|
|
configure_clocks(&mut p.rcc);
|
|
systick::configure(&mut scs.systick);
|
|
configure_peripherals(&mut p.rcc, &mut p.gpio_a, &mut p.gpio_c, &mut p.usart2);
|
|
|
|
//let mut printer = UsartPrinter::init(p.usart2);
|
|
|
|
|
|
let mut spi = p.spi1;
|
|
let mut gpio = p.gpio_a;
|
|
|
|
let mut st7735 = st7735::St7735::new(st7735::DisplayType::RED_18_BLACKTAB, 0, 1, 4, 8);
|
|
|
|
let mut st7735io = st7735.start(spi, gpio);
|
|
loop {
|
|
st7735io.init();
|
|
st7735io.fill_rect(0, 0, 128, 160, 0x00, 0x00);
|
|
st7735io.fill_rect(4, 4, 60, 76, 0x00, 0x1F);
|
|
st7735io.fill_rect(4, 80, 60, 76, 0xF8, 0x00);
|
|
st7735io.fill_rect(64, 4, 60, 76, 0x07, 0xE0);
|
|
st7735io.fill_rect(64, 80, 60, 76, 0xFF, 0xE0);
|
|
systick::delay_ms(2000);
|
|
}
|
|
let (st7735, mut spi, mut gpio) = st7735io.done();
|
|
|
|
/*
|
|
loop {
|
|
|
|
|
|
|
|
let res = max6675::read(&mut spi, &mut gpio, 9);
|
|
|
|
let msg = match res {
|
|
Ok(temp) => format!("> {}\r\n", temp).into_bytes(),
|
|
Err(err) => format!("Error > {}\r\n", err).into_bytes(),
|
|
};
|
|
|
|
printer.print(msg);
|
|
|
|
let old = p.gpio_c.output();
|
|
p.gpio_c.set_output(old ^ (1<<13));
|
|
|
|
systick::delay_ms(1000);
|
|
}
|
|
*/
|
|
}
|
|
|
|
|
|
entry_point!(main);
|
|
fn main(scs: scs::Instance, p: hcl::platform::Instance) {
|
|
declare_thread_stack!(stack, 3072);
|
|
|
|
unsafe {
|
|
hcl::set_process_stack(&stack);
|
|
hcl::use_process_stack(true);
|
|
}
|
|
|
|
run(scs, p);
|
|
}
|