mirror of
https://github.com/LegitCamper/picocalc-os-rs.git
synced 2025-12-27 15:55:25 +00:00
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 {
|
unsafe {
|
||||||
let ptr = CALL_ABI_TABLE[CallAbiTable::Print as usize];
|
let ptr = CALL_ABI_TABLE[CallAbiTable::Print as usize];
|
||||||
let f: SleepAbi = core::mem::transmute(ptr);
|
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 alloc::boxed::Box;
|
||||||
use defmt::info;
|
use defmt::info;
|
||||||
use embassy_futures::block_on;
|
use embassy_futures::block_on;
|
||||||
|
use embassy_rp::clocks::clk_sys_freq;
|
||||||
use embassy_time::Timer;
|
use embassy_time::Timer;
|
||||||
use embedded_graphics::{
|
use embedded_graphics::{
|
||||||
Drawable,
|
Drawable,
|
||||||
@@ -26,9 +27,10 @@ pub extern "Rust" fn print(msg: &str) {
|
|||||||
defmt::info!("{:?}", msg);
|
defmt::info!("{:?}", msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub extern "Rust" fn sleep(ticks: u64) {
|
pub extern "Rust" fn sleep(ms: u64) {
|
||||||
for _ in 0..ticks {
|
let cycles_per_ms = clk_sys_freq() / 1000;
|
||||||
for _ in 0..100 {
|
for _ in 0..ms {
|
||||||
|
for _ in 0..cycles_per_ms {
|
||||||
cortex_m::asm::nop();
|
cortex_m::asm::nop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -36,10 +38,7 @@ pub extern "Rust" fn sleep(ticks: u64) {
|
|||||||
|
|
||||||
// TODO: maybe return result
|
// TODO: maybe return result
|
||||||
pub extern "Rust" fn draw_iter(pixels: &[Pixel<Rgb565>]) {
|
pub extern "Rust" fn draw_iter(pixels: &[Pixel<Rgb565>]) {
|
||||||
loop {
|
|
||||||
unsafe { FRAMEBUFFER.draw_iter(pixels.iter().copied()).unwrap() }
|
unsafe { FRAMEBUFFER.draw_iter(pixels.iter().copied()).unwrap() }
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub extern "Rust" fn get_key() -> Option<KeyEvent> {
|
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() {
|
async fn get_keys() {
|
||||||
if let Some(event) = read_keyboard_fifo().await {
|
if let Some(event) = read_keyboard_fifo().await {
|
||||||
|
if let KeyState::Pressed = event.state {
|
||||||
unsafe {
|
unsafe {
|
||||||
let _ = KEY_CACHE.enqueue(event);
|
let _ = KEY_CACHE.enqueue(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#![no_main]
|
#![no_main]
|
||||||
|
|
||||||
extern crate alloc;
|
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 alloc::{boxed::Box, string::String, vec};
|
||||||
use core::{panic::PanicInfo, pin::Pin};
|
use core::{panic::PanicInfo, pin::Pin};
|
||||||
use embedded_graphics::{
|
use embedded_graphics::{
|
||||||
@@ -10,7 +10,8 @@ use embedded_graphics::{
|
|||||||
geometry::{Dimensions, Point},
|
geometry::{Dimensions, Point},
|
||||||
mono_font::{MonoTextStyle, ascii::FONT_6X10},
|
mono_font::{MonoTextStyle, ascii::FONT_6X10},
|
||||||
pixelcolor::Rgb565,
|
pixelcolor::Rgb565,
|
||||||
prelude::RgbColor,
|
prelude::{Primitive, RgbColor, Size},
|
||||||
|
primitives::{PrimitiveStyle, Rectangle},
|
||||||
text::{Alignment, Text},
|
text::{Alignment, Text},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -28,6 +29,16 @@ pub async fn main() {
|
|||||||
let mut text = vec!['H', 'E', 'L', 'L', 'O'];
|
let mut text = vec!['H', 'E', 'L', 'L', 'O'];
|
||||||
|
|
||||||
loop {
|
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::with_alignment(
|
||||||
&text.iter().cloned().collect::<String>(),
|
&text.iter().cloned().collect::<String>(),
|
||||||
display.bounding_box().center() + Point::new(0, 15),
|
display.bounding_box().center() + Point::new(0, 15),
|
||||||
@@ -37,8 +48,6 @@ pub async fn main() {
|
|||||||
.draw(&mut display)
|
.draw(&mut display)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
embassy_time::Timer::after_millis(1000).await;
|
|
||||||
|
|
||||||
if let Some(event) = get_key() {
|
if let Some(event) = get_key() {
|
||||||
print("User got event");
|
print("User got event");
|
||||||
match event.key {
|
match event.key {
|
||||||
@@ -51,6 +60,7 @@ pub async fn main() {
|
|||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sleep(1000)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user