-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
615f193
commit 5c00eb0
Showing
9 changed files
with
426 additions
and
106 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
pub fn hsv2rgb(hue: f32, sat: f32, val: f32) -> (u8, u8, u8) { | ||
let c = val * sat; | ||
let v = (hue / 60.0) % 2.0 - 1.0; | ||
let v = if v < 0.0 { -v } else { v }; | ||
let x = c * (1.0 - v); | ||
let m = val - c; | ||
let (r, g, b) = if hue < 60.0 { | ||
(c, x, 0.0) | ||
} else if hue < 120.0 { | ||
(x, c, 0.0) | ||
} else if hue < 180.0 { | ||
(0.0, c, x) | ||
} else if hue < 240.0 { | ||
(0.0, x, c) | ||
} else if hue < 300.0 { | ||
(x, 0.0, c) | ||
} else { | ||
(c, 0.0, x) | ||
}; | ||
|
||
let r = ((r + m) * 255.0) as u8; | ||
let g = ((g + m) * 255.0) as u8; | ||
let b = ((b + m) * 255.0) as u8; | ||
|
||
(r, g, b) | ||
} | ||
|
||
pub fn rgb565(r: u8, g: u8, b: u8) -> u16 { | ||
let r = ((r as u16) & 0b11111000) << 8; | ||
let g = ((g as u16) & 0b11111100) << 3; | ||
let b = (b as u16) >> 3; | ||
r | g | b | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,66 @@ | ||
//! Screen for fun graphics | ||
use defmt::info; | ||
use embedded_hal::timer::CountDown as _; | ||
use rp_pico::hal::{fugit::ExtU32, timer::CountDown}; | ||
use rp_pico::{ | ||
hal::{ | ||
fugit::ExtU32, | ||
gpio::{DynPinId, FunctionPio1, Pin, PullDown}, | ||
pio::SM1, | ||
timer::{CountDown, Instant}, | ||
Timer, | ||
}, | ||
pac::PIO1, | ||
}; | ||
|
||
const REFRESH_RATE: u32 = 33; | ||
use crate::{ | ||
color::{hsv2rgb, rgb565}, | ||
st7789::St7789, | ||
}; | ||
|
||
const REFRESH_RATE: u32 = 50; | ||
|
||
pub struct ScreenMod<'timer> { | ||
st: St7789<'timer, PIO1, SM1, Pin<DynPinId, FunctionPio1, PullDown>>, | ||
timer: CountDown<'timer>, | ||
} | ||
|
||
impl<'timer> ScreenMod<'timer> { | ||
pub fn new(mut count_down: CountDown<'timer>) -> Self { | ||
pub fn new( | ||
st: St7789<'timer, PIO1, SM1, Pin<DynPinId, FunctionPio1, PullDown>>, | ||
mut count_down: CountDown<'timer>, | ||
) -> Self { | ||
count_down.start(REFRESH_RATE.millis()); | ||
|
||
ScreenMod { timer: count_down } | ||
ScreenMod { | ||
st: st, | ||
timer: count_down, | ||
} | ||
} | ||
|
||
pub fn clear(&mut self) { | ||
self.st.clear_framebuffer(); | ||
self.st.push_framebuffer(); | ||
self.st.backlight_off(); | ||
} | ||
|
||
pub fn clear(&mut self) {} | ||
pub fn update(&mut self, t: Instant, timer: &Timer) { | ||
if !self.timer.wait().is_ok() { | ||
return; | ||
} | ||
|
||
let t = ((t.duration_since_epoch().ticks() >> 15) % 360) as f32; | ||
let rgb = hsv2rgb(t, 1.0, 1.0); | ||
let rgb = rgb565(rgb.0, rgb.1, rgb.2); | ||
|
||
pub fn update(&mut self) {} | ||
// let time_start = timer.get_counter(); | ||
self.st.fill_framebuffer(rgb); | ||
// let elapse1 = (timer.get_counter() - time_start).to_micros(); | ||
|
||
// let time_start = timer.get_counter(); | ||
self.st.push_framebuffer(); | ||
// let elapse2 = (timer.get_counter() - time_start).to_micros(); | ||
|
||
// info!("times: fill-fb={}us, write-fb={}us", elapse1, elapse2); | ||
} | ||
} |
Oops, something went wrong.