diff --git a/Cargo.lock b/Cargo.lock index 8c89787..e68673b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "libm" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de" + [[package]] name = "nova" version = "0.1.0" +dependencies = [ + "libm", +] diff --git a/Cargo.toml b/Cargo.toml index c8de713..8de0a0e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,3 +11,6 @@ opt-level = 0 [profile.release] panic = "abort" + +[dependencies] +libm = "0.2.15" diff --git a/src/lib.rs b/src/lib.rs index 2f92229..34e4c56 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,6 +8,7 @@ pub mod configuration; pub mod framebuffer; pub mod irq_interrupt; pub mod mailbox; +pub mod math; pub mod timer; pub fn mmio_read(address: u32) -> u32 { diff --git a/src/main.rs b/src/main.rs index 591688f..b7df778 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,7 @@ use nova::{ framebuffer::{print_display_resolution, FrameBuffer}, irq_interrupt::enable_irq_source, mailbox::read_soc_temp, + math::polar_to_cartesian, peripherals::{ gpio::{ 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(); print_display_resolution(); - fb.draw_line(10, 10, 1000, 10); - fb.draw_line(1000, 20, 10, 20); + for a in 0..360 { + 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_fill(800, 800, 900, 900); fb.draw_square_fill(1000, 800, 1200, 700); diff --git a/src/math.rs b/src/math.rs new file mode 100644 index 0000000..4597857 --- /dev/null +++ b/src/math.rs @@ -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) +}