More screen control

master
D4VID 3 months ago
parent a951102ab8
commit c7165476b1

@ -30,8 +30,8 @@ pub enum ScreenMode {
pub struct Screen {}
impl Screen {
const SCREEN_CLEAR: u32 = 0x0000_0001;
const SCREEN_DISPLAY: u32 = 0x0000_0100;
const SCREEN_CLEAR : u32 = 0x0000_0001;
const SCREEN_DISPLAY : u32 = 0x0000_0100;
#[inline]
pub fn init(mode: ScreenMode) {
@ -48,6 +48,33 @@ impl Screen {
}
}
#[inline]
pub fn clear() {
unsafe {
// Write a 1 to the screen clear byte
write_volatile(SCREEN_CONTROL_POINTER as *mut u8, 1);
write_volatile(SCREEN_CONTROL_POINTER as *mut u8, 0);
}
}
#[inline]
pub fn display() {
unsafe {
// Write a 1 to the screen display byte
write_volatile((SCREEN_CONTROL_POINTER as *mut u8).byte_offset(1), 1);
write_volatile((SCREEN_CONTROL_POINTER as *mut u8).byte_offset(1), 0);
}
}
#[inline]
pub fn change_mode(mode: ScreenMode) {
match mode {
ScreenMode::AlwaysDisplay => unsafe {
write_volatile((SCREEN_CONTROL_POINTER as *mut u8).byte_offset(1), 1);
},
ScreenMode::Buffered => unsafe {
write_volatile((SCREEN_CONTROL_POINTER as *mut u8).byte_offset(1), 0);
},
}
}
#[inline]
pub fn turn_pixel_on(x: u8, y: u8) {
unsafe {
let mut row = read_volatile(SCREEN_POINTER.offset(y as isize));
@ -73,8 +100,8 @@ impl Screen {
pub struct TextDisplay {}
impl TextDisplay {
const TEXT_CLEAR: u32 = 0x0000_0001;
const TEXT_DISPLAY: u32 = 0x0000_0100;
const TEXT_CLEAR : u32 = 0x0000_0001;
const TEXT_DISPLAY : u32 = 0x0000_0100;
#[inline]
pub fn init(&self) {

@ -18,12 +18,16 @@ const HELLO_WORLD: &str = " Hello world!";
#[entry]
fn main() -> ! {
NumberDisplay::display_number(0);
Screen::init(ScreenMode::AlwaysDisplay);
Screen::init(ScreenMode::Buffered);
let mut text = TextDisplay{};
text.init();
for i in 0..32 {
Screen::set_line(i, 1 << i);
}
Screen::display();
Screen::clear();
Screen::display();
Screen::change_mode(ScreenMode::AlwaysDisplay);
unsafe {
write_volatile(SCREEN_POINTER, 0x001166ff);
write_volatile(SCREEN_POINTER.offset(1), 0xAAAAAAAA);

Loading…
Cancel
Save