screen tearing kinda poop
This commit is contained in:
@@ -40,13 +40,13 @@ pub fn print(msg: &str) {
|
||||
}
|
||||
}
|
||||
|
||||
pub type SleepAbi = extern "Rust" fn(ticks: u64);
|
||||
pub type SleepAbi = extern "Rust" fn(ms: u64);
|
||||
|
||||
pub fn sleep(ticks: u64) {
|
||||
pub fn sleep(ms: u64) {
|
||||
unsafe {
|
||||
let ptr = CALL_ABI_TABLE[CallAbiTable::Print as usize];
|
||||
let f: SleepAbi = core::mem::transmute(ptr);
|
||||
f(ticks);
|
||||
f(ms);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ use abi_sys::{DrawIterAbi, GetKeyAbi, Pixel, PrintAbi, SleepAbi};
|
||||
use alloc::boxed::Box;
|
||||
use defmt::info;
|
||||
use embassy_futures::block_on;
|
||||
use embassy_rp::clocks::clk_sys_freq;
|
||||
use embassy_time::Timer;
|
||||
use embedded_graphics::{
|
||||
Drawable,
|
||||
@@ -26,9 +27,10 @@ pub extern "Rust" fn print(msg: &str) {
|
||||
defmt::info!("{:?}", msg);
|
||||
}
|
||||
|
||||
pub extern "Rust" fn sleep(ticks: u64) {
|
||||
for _ in 0..ticks {
|
||||
for _ in 0..100 {
|
||||
pub extern "Rust" fn sleep(ms: u64) {
|
||||
let cycles_per_ms = clk_sys_freq() / 1000;
|
||||
for _ in 0..ms {
|
||||
for _ in 0..cycles_per_ms {
|
||||
cortex_m::asm::nop();
|
||||
}
|
||||
}
|
||||
@@ -36,10 +38,7 @@ pub extern "Rust" fn sleep(ticks: u64) {
|
||||
|
||||
// TODO: maybe return result
|
||||
pub extern "Rust" fn draw_iter(pixels: &[Pixel<Rgb565>]) {
|
||||
loop {
|
||||
unsafe { FRAMEBUFFER.draw_iter(pixels.iter().copied()).unwrap() }
|
||||
return;
|
||||
}
|
||||
unsafe { FRAMEBUFFER.draw_iter(pixels.iter().copied()).unwrap() }
|
||||
}
|
||||
|
||||
pub extern "Rust" fn get_key() -> Option<KeyEvent> {
|
||||
|
||||
@@ -259,8 +259,10 @@ static mut KEY_CACHE: Queue<KeyEvent, 32> = Queue::new();
|
||||
|
||||
async fn get_keys() {
|
||||
if let Some(event) = read_keyboard_fifo().await {
|
||||
unsafe {
|
||||
let _ = KEY_CACHE.enqueue(event);
|
||||
if let KeyState::Pressed = event.state {
|
||||
unsafe {
|
||||
let _ = KEY_CACHE.enqueue(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#![no_main]
|
||||
|
||||
extern crate alloc;
|
||||
use abi::{KeyCode, display::Display, embassy_time, get_key, print};
|
||||
use abi::{KeyCode, display::Display, embassy_time, get_key, print, sleep};
|
||||
use alloc::{boxed::Box, string::String, vec};
|
||||
use core::{panic::PanicInfo, pin::Pin};
|
||||
use embedded_graphics::{
|
||||
@@ -10,7 +10,8 @@ use embedded_graphics::{
|
||||
geometry::{Dimensions, Point},
|
||||
mono_font::{MonoTextStyle, ascii::FONT_6X10},
|
||||
pixelcolor::Rgb565,
|
||||
prelude::RgbColor,
|
||||
prelude::{Primitive, RgbColor, Size},
|
||||
primitives::{PrimitiveStyle, Rectangle},
|
||||
text::{Alignment, Text},
|
||||
};
|
||||
|
||||
@@ -28,6 +29,16 @@ pub async fn main() {
|
||||
let mut text = vec!['H', 'E', 'L', 'L', 'O'];
|
||||
|
||||
loop {
|
||||
// First, clear the text area
|
||||
let text_area = Rectangle::new(
|
||||
display.bounding_box().center() + Point::new(0, 0),
|
||||
Size::new(320, 320),
|
||||
);
|
||||
Rectangle::new(text_area.top_left, text_area.size)
|
||||
.into_styled(PrimitiveStyle::with_fill(Rgb565::BLACK))
|
||||
.draw(&mut display)
|
||||
.unwrap();
|
||||
|
||||
Text::with_alignment(
|
||||
&text.iter().cloned().collect::<String>(),
|
||||
display.bounding_box().center() + Point::new(0, 15),
|
||||
@@ -37,8 +48,6 @@ pub async fn main() {
|
||||
.draw(&mut display)
|
||||
.unwrap();
|
||||
|
||||
embassy_time::Timer::after_millis(1000).await;
|
||||
|
||||
if let Some(event) = get_key() {
|
||||
print("User got event");
|
||||
match event.key {
|
||||
@@ -51,6 +60,7 @@ pub async fn main() {
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
sleep(1000)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user