Draw a line in each direction

This commit is contained in:
2025-07-27 11:03:52 +02:00
parent 80c4c3604c
commit a4250898c0
5 changed files with 24 additions and 2 deletions

9
Cargo.lock generated
View File

@@ -2,6 +2,15 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 4 version = 4
[[package]]
name = "libm"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de"
[[package]] [[package]]
name = "nova" name = "nova"
version = "0.1.0" version = "0.1.0"
dependencies = [
"libm",
]

View File

@@ -11,3 +11,6 @@ opt-level = 0
[profile.release] [profile.release]
panic = "abort" panic = "abort"
[dependencies]
libm = "0.2.15"

View File

@@ -8,6 +8,7 @@ pub mod configuration;
pub mod framebuffer; pub mod framebuffer;
pub mod irq_interrupt; pub mod irq_interrupt;
pub mod mailbox; pub mod mailbox;
pub mod math;
pub mod timer; pub mod timer;
pub fn mmio_read(address: u32) -> u32 { pub fn mmio_read(address: u32) -> u32 {

View File

@@ -12,6 +12,7 @@ use nova::{
framebuffer::{print_display_resolution, FrameBuffer}, framebuffer::{print_display_resolution, FrameBuffer},
irq_interrupt::enable_irq_source, irq_interrupt::enable_irq_source,
mailbox::read_soc_temp, mailbox::read_soc_temp,
math::polar_to_cartesian,
peripherals::{ peripherals::{
gpio::{ gpio::{
blink_gpio, gpio_pull_up, set_falling_edge_detect, set_gpio_function, GPIOFunction, blink_gpio, gpio_pull_up, set_falling_edge_detect, set_gpio_function, GPIOFunction,
@@ -97,8 +98,11 @@ pub extern "C" fn kernel_main() -> ! {
let fb = FrameBuffer::new(); let fb = FrameBuffer::new();
print_display_resolution(); print_display_resolution();
fb.draw_line(10, 10, 1000, 10); for a in 0..360 {
fb.draw_line(1000, 20, 10, 20); let (x, y) = polar_to_cartesian(100.0, a as f32);
fb.draw_line(150, 150, (150.0 + x) as u32, (150.0 + y) as u32);
}
fb.draw_square(500, 500, 600, 700); fb.draw_square(500, 500, 600, 700);
fb.draw_square_fill(800, 800, 900, 900); fb.draw_square_fill(800, 800, 900, 900);
fb.draw_square_fill(1000, 800, 1200, 700); fb.draw_square_fill(1000, 800, 1200, 700);

5
src/math.rs Normal file
View File

@@ -0,0 +1,5 @@
pub fn polar_to_cartesian(r: f32, theta_rad: f32) -> (f32, f32) {
let x = r * libm::cosf(theta_rad);
let y = r * libm::sinf(theta_rad);
(x, y)
}