2022-11-07 13:29:42 -06:00
|
|
|
use crate::device_interface::CharacterDevice;
|
2022-02-09 07:08:40 -06:00
|
|
|
|
2022-02-12 03:25:02 -06:00
|
|
|
#[derive(Debug)]
|
2022-02-09 07:08:40 -06:00
|
|
|
pub struct DevUnicode {
|
|
|
|
pub next_write_char: char,
|
|
|
|
pub next_read_char: char,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl CharacterDevice for DevUnicode {
|
|
|
|
fn can_read(&self) -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
|
|
|
fn can_write(&self) -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
|
|
|
fn read_char(&mut self) -> Option<char> {
|
|
|
|
let c = self.next_read_char;
|
|
|
|
self.next_read_char = add1_char(c);
|
|
|
|
|
|
|
|
Some(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn write_char(&mut self, c: char) -> bool {
|
|
|
|
if self.next_write_char != c {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
true
|
|
|
|
}
|
2022-03-02 08:38:22 -06:00
|
|
|
|
|
|
|
fn reset(&mut self) {
|
|
|
|
self.next_write_char = 0x00 as char;
|
|
|
|
self.next_read_char = 0x00 as char;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn initialize(&mut self) -> bool {
|
|
|
|
true
|
|
|
|
}
|
2022-02-09 07:08:40 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn add1_char(c: char) -> char {
|
|
|
|
if c == char::MAX {
|
|
|
|
return 0x00 as char;
|
|
|
|
}
|
2022-04-11 17:23:11 -05:00
|
|
|
|
2022-02-09 07:08:40 -06:00
|
|
|
char::from_u32(c as u32 + 1).unwrap()
|
|
|
|
}
|