Added missing primitives
This commit is contained in:
parent
fe3f1dea1f
commit
307b3d6e72
136
back.txt
136
back.txt
|
@ -1,136 +0,0 @@
|
|||
#![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 printer;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
fn configure_peripherals(rcc: &mut hcl::platform::rcc::RCC,
|
||||
gpio: &mut gpio::GPIO,
|
||||
usart: &mut usart::USART) {
|
||||
rcc.apb2_enable.configure(|a| a
|
||||
.set_gpio_a(true)
|
||||
.set_spi1(true));
|
||||
rcc.apb1_enable.configure(|a| a
|
||||
.set_usart2(true));
|
||||
|
||||
gpio.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)
|
||||
// NSS1
|
||||
.set_mode(4, gpio::PinMode::Output50MHz)
|
||||
.set_output_config(4, 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);
|
||||
configure_peripherals(&mut p.rcc, &mut p.gpio_a, &mut p.usart2);
|
||||
|
||||
let mut printer = UsartPrinter::init(p.usart2);
|
||||
|
||||
let mut spi = p.spi1;
|
||||
spi.configure(|s| s
|
||||
.set_enabled(true)
|
||||
.set_master_mode(true)
|
||||
.set_slave_select_output_enabled(true)
|
||||
.set_bidi_tx(false)
|
||||
.set_clock_divider(128)
|
||||
.set_data_16bit(true)
|
||||
.set_clock_idles_high(false)
|
||||
.set_lsb_first(false)
|
||||
.set_clock_skip_first(true));
|
||||
|
||||
loop {
|
||||
|
||||
p.gpio_a.reset_bit(4);
|
||||
spi.set_data(0xFFFF);
|
||||
|
||||
while !spi.rx_buffer_not_empty() {
|
||||
}
|
||||
|
||||
let i = spi.data() >> 3;
|
||||
let temp = (i as f32) * 0.25;
|
||||
|
||||
while spi.busy() {
|
||||
}
|
||||
p.gpio_a.set_bit(4);
|
||||
|
||||
|
||||
|
||||
let x = format!("> {}\r\n", temp).into_bytes();
|
||||
|
||||
printer.print(x);
|
||||
|
||||
for y in 0u32..0xFFFFFF {
|
||||
unsafe { asm!("nop" :::: "volatile") };
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
entry_point!(main);
|
||||
fn main(scs: scs::Instance, p: hcl::platform::Instance) {
|
||||
declare_thread_stack!(stack, 4096);
|
||||
|
||||
unsafe {
|
||||
hcl::set_process_stack(&stack);
|
||||
hcl::use_process_stack(true);
|
||||
}
|
||||
|
||||
run(scs, p);
|
||||
}
|
|
@ -415,9 +415,41 @@ impl<SPIAddr, GPIOAddr> St7735IO<SPIAddr, GPIOAddr>
|
|||
self.write_command(&Command::MADCTL(param));
|
||||
}
|
||||
|
||||
pub fn draw_pixel(&mut self, x : u8, y : u8, color : u16) {
|
||||
if x >= self.st7735.width || y >= self.st7735.height {
|
||||
return;
|
||||
}
|
||||
|
||||
self.set_addr_win(x, y, x+1, y+1);
|
||||
|
||||
self.set_rs();
|
||||
self.reset_cs();
|
||||
|
||||
self.write_color_bytes(color);
|
||||
|
||||
self.set_cs();
|
||||
}
|
||||
|
||||
pub fn fill_rect(&mut self, x : u8, y : u8, w : u8, h : u8, color: u16) {
|
||||
|
||||
if x >= self.st7735.width || y >= self.st7735.height {
|
||||
return;
|
||||
}
|
||||
|
||||
let w = if (x + w - 1) >= self.st7735.width {
|
||||
self.st7735.width - x
|
||||
}
|
||||
else {
|
||||
w
|
||||
};
|
||||
|
||||
let h = if (y + h - 1) >= self.st7735.height {
|
||||
self.st7735.height - y
|
||||
}
|
||||
else {
|
||||
h
|
||||
};
|
||||
|
||||
self.set_addr_win(x, y, x + w - 1, y + h - 1);
|
||||
|
||||
self.set_rs();
|
||||
|
@ -432,6 +464,14 @@ impl<SPIAddr, GPIOAddr> St7735IO<SPIAddr, GPIOAddr>
|
|||
self.set_cs();
|
||||
}
|
||||
|
||||
pub fn draw_fast_vline(&mut self, x : u8, y : u8, h : u8, color : u16) {
|
||||
self.fill_rect(x, y, 1, h, color);
|
||||
}
|
||||
|
||||
pub fn draw_fast_hline(&mut self, x : u8, y : u8, w : u8, color : u16) {
|
||||
self.fill_rect(x, y, w, 1, color);
|
||||
}
|
||||
|
||||
pub fn done(mut self) -> (St7735, PeripheralRef<spi::SPI, SPIAddr>, PeripheralRef<gpio::GPIO, GPIOAddr>) {
|
||||
self.set_cs();
|
||||
self.spi.set_enabled(false);
|
||||
|
|
Loading…
Reference in New Issue