Compare commits

..

2 Commits

Author SHA1 Message Date
D4VID 015769cbdc Rename buttons
3 months ago
D4VID c7165476b1 More screen control
3 months ago

@ -30,8 +30,8 @@ pub enum ScreenMode {
pub struct Screen {} pub struct Screen {}
impl Screen { impl Screen {
const SCREEN_CLEAR: u32 = 0x0000_0001; const SCREEN_CLEAR : u32 = 0x0000_0001;
const SCREEN_DISPLAY: u32 = 0x0000_0100; const SCREEN_DISPLAY : u32 = 0x0000_0100;
#[inline] #[inline]
pub fn init(mode: ScreenMode) { pub fn init(mode: ScreenMode) {
@ -48,6 +48,33 @@ impl Screen {
} }
} }
#[inline] #[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) { pub fn turn_pixel_on(x: u8, y: u8) {
unsafe { unsafe {
let mut row = read_volatile(SCREEN_POINTER.offset(y as isize)); let mut row = read_volatile(SCREEN_POINTER.offset(y as isize));
@ -73,8 +100,8 @@ impl Screen {
pub struct TextDisplay {} pub struct TextDisplay {}
impl TextDisplay { impl TextDisplay {
const TEXT_CLEAR: u32 = 0x0000_0001; const TEXT_CLEAR : u32 = 0x0000_0001;
const TEXT_DISPLAY: u32 = 0x0000_0100; const TEXT_DISPLAY : u32 = 0x0000_0100;
#[inline] #[inline]
pub fn init(&self) { pub fn init(&self) {
@ -126,14 +153,14 @@ impl RNG {
pub struct Buttons {} pub struct Buttons {}
impl Buttons { impl Buttons {
pub const RIGHT_RIGHT : u8 = 0b00000001; pub const A : u8 = 0b00000001;
pub const RIGHT_DOWN : u8 = 0b00000010; pub const B : u8 = 0b00000010;
pub const RIGHT_LEFT : u8 = 0b00000100; pub const X : u8 = 0b00000100;
pub const RIGHT_UP : u8 = 0b00001000; pub const Y : u8 = 0b00001000;
pub const LEFT_RIGHT : u8 = 0b00010000; pub const RIGHT : u8 = 0b00010000;
pub const LEFT_DOWN : u8 = 0b00100000; pub const DOWN : u8 = 0b00100000;
pub const LEFT_LEFT : u8 = 0b01000000; pub const LEFT : u8 = 0b01000000;
pub const LEFT_UP : u8 = 0b10000000; pub const UP : u8 = 0b10000000;
#[inline] #[inline]
pub fn read() -> u8 { pub fn read() -> u8 {

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

Loading…
Cancel
Save