mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
intermediate checkin
This commit is contained in:
parent
07b3dd9afa
commit
2b003f8a7d
10 changed files with 87 additions and 60 deletions
|
|
@ -21,8 +21,8 @@ riscv = "0.5.6"
|
||||||
debug-print = []
|
debug-print = []
|
||||||
print-panics = []
|
print-panics = []
|
||||||
report-memory = ["stats_alloc"]
|
report-memory = ["stats_alloc"]
|
||||||
# default = ["print-panics", "debug-print"]
|
default = ["print-panics", "debug-print"]
|
||||||
default = ["print-panics"]
|
# default = ["print-panics"]
|
||||||
|
|
||||||
[target.'cfg(any(windows, unix))'.dependencies]
|
[target.'cfg(any(windows, unix))'.dependencies]
|
||||||
lazy_static = "1.4"
|
lazy_static = "1.4"
|
||||||
|
|
|
||||||
|
|
@ -67,9 +67,9 @@ pub fn draw_string(cid: CID, s: &String<4096>) -> Result<(), xous::Error> {
|
||||||
let pos = writer.archive(&request).expect("GFX: couldn't archive String request");
|
let pos = writer.archive(&request).expect("GFX: couldn't archive String request");
|
||||||
let xous_buffer = writer.into_inner();
|
let xous_buffer = writer.into_inner();
|
||||||
|
|
||||||
log::info!("GFX: draw_string message being sent");
|
//log::info!("GFX: draw_string message being sent");
|
||||||
xous_buffer.lend(cid, pos as u32).expect("GFX: String request failure");
|
xous_buffer.lend(cid, pos as u32).expect("GFX: String request failure");
|
||||||
log::info!("GFX: draw_string completed");
|
//log::info!("GFX: draw_string completed");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -111,7 +111,9 @@ pub fn glyph_height_hint(cid: CID, glyph: GlyphStyle) -> Result<usize, xous::Err
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_textview(cid: CID, tv: &mut TextView) -> Result<(), xous::Error> {
|
pub fn draw_textview(cid: CID, tv: &mut TextView) -> Result<(), xous::Error> {
|
||||||
|
/*/
|
||||||
let mut sendable_tv = Sendable::new(tv)
|
let mut sendable_tv = Sendable::new(tv)
|
||||||
.expect("can't create sendable TextView structure");
|
.expect("can't create sendable TextView structure");
|
||||||
sendable_tv.lend_mut(cid, 0x100).map(|_| ())
|
sendable_tv.lend_mut(cid, 0x100).map(|_| ()) */
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -47,7 +47,7 @@ fn xmain() -> ! {
|
||||||
display.redraw();
|
display.redraw();
|
||||||
loop {
|
loop {
|
||||||
let msg = xous::receive_message(sid).unwrap();
|
let msg = xous::receive_message(sid).unwrap();
|
||||||
info!("GFX: Message: {:?}", msg);
|
//info!("GFX: Message: {:?}", msg);
|
||||||
if let xous::Message::Borrow(m) = &msg.body {
|
if let xous::Message::Borrow(m) = &msg.body {
|
||||||
let mut buf = unsafe { buffer::XousBuffer::from_memory_message(m) };
|
let mut buf = unsafe { buffer::XousBuffer::from_memory_message(m) };
|
||||||
let bytes = Pin::new(buf.as_ref());
|
let bytes = Pin::new(buf.as_ref());
|
||||||
|
|
@ -57,7 +57,7 @@ fn xmain() -> ! {
|
||||||
let new_value = match &*value {
|
let new_value = match &*value {
|
||||||
rkyv::Archived::<api::Opcode>::String(rkyv_s) => {
|
rkyv::Archived::<api::Opcode>::String(rkyv_s) => {
|
||||||
let s: xous::String<4096> = rkyv_s.unarchive();
|
let s: xous::String<4096> = rkyv_s.unarchive();
|
||||||
info!("GFX: unarchived string: {:?}", s);
|
//info!("GFX: unarchived string: {:?}", s);
|
||||||
blitstr::paint_str(
|
blitstr::paint_str(
|
||||||
display.native_buffer(),
|
display.native_buffer(),
|
||||||
current_string_clip.into(),
|
current_string_clip.into(),
|
||||||
|
|
@ -67,7 +67,7 @@ fn xmain() -> ! {
|
||||||
false,
|
false,
|
||||||
blitstr::xor_char
|
blitstr::xor_char
|
||||||
);
|
);
|
||||||
info!("GFX: string painted");
|
//info!("GFX: string painted");
|
||||||
},
|
},
|
||||||
rkyv::Archived::<api::Opcode>::StringXor(rkyv_s) => {
|
rkyv::Archived::<api::Opcode>::StringXor(rkyv_s) => {
|
||||||
let s: xous::String<4096> = rkyv_s.unarchive();
|
let s: xous::String<4096> = rkyv_s.unarchive();
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
|
use core::ops::Deref;
|
||||||
|
|
||||||
use heapless::consts::*;
|
use heapless::consts::*;
|
||||||
use heapless::Vec;
|
use heapless::Vec;
|
||||||
use xous::{Message, ScalarMessage};
|
use xous::{Message, ScalarMessage};
|
||||||
|
use rkyv::{RelPtr, Archive, Archived, Resolve, Resolver, Write};
|
||||||
|
use core::slice;
|
||||||
|
|
||||||
pub const REGISTER_BASIC_LISTENER: u32 = 0x1000_0000;
|
pub const REGISTER_BASIC_LISTENER: u32 = 0x1000_0000;
|
||||||
pub const REGISTER_RAW_LISTENER: u32 = 0x1000_0001;
|
pub const REGISTER_RAW_LISTENER: u32 = 0x1000_0001;
|
||||||
|
|
@ -22,9 +26,7 @@ pub struct RowCol {
|
||||||
pub r: u8,
|
pub r: u8,
|
||||||
pub c: u8,
|
pub c: u8,
|
||||||
}
|
}
|
||||||
|
#[repr(packed)]
|
||||||
#[derive(Debug)]
|
|
||||||
#[repr(C)]
|
|
||||||
pub struct KeyRawStates {
|
pub struct KeyRawStates {
|
||||||
mid: u32,
|
mid: u32,
|
||||||
pub keydowns: Vec<RowCol, U16>,
|
pub keydowns: Vec<RowCol, U16>,
|
||||||
|
|
@ -46,15 +48,61 @@ impl KeyRawStates {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn copy(&self) -> KeyRawStates {
|
pub fn copy(&self) -> KeyRawStates {
|
||||||
let mut krs = KeyRawStates::new();
|
let mut krs = KeyRawStates::new();
|
||||||
for kd in self.keydowns.iter() {
|
unsafe { // because KeyRawStates is *packed*
|
||||||
krs.keydowns.push(*kd).unwrap();
|
for kd in self.keydowns.iter() {
|
||||||
}
|
krs.keydowns.push(*kd).unwrap();
|
||||||
for ku in self.keyups.iter() {
|
}
|
||||||
krs.keyups.push(*ku).unwrap();
|
for ku in self.keyups.iter() {
|
||||||
|
krs.keyups.push(*ku).unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
krs
|
krs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl Clone for KeyRawStates {
|
||||||
|
fn clone(&self) -> KeyRawStates {
|
||||||
|
self.copy()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Deref for KeyRawStates {
|
||||||
|
type Target = [u8];
|
||||||
|
fn deref(&self) -> &[u8] {
|
||||||
|
unsafe {
|
||||||
|
slice::from_raw_parts(self as *const KeyRawStates as *const u8, core::mem::size_of::<KeyRawStates>())
|
||||||
|
as &[u8]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// warning: this rkyv code is totally untested
|
||||||
|
pub struct ArchivedKeyRawStates {
|
||||||
|
ptr: RelPtr,
|
||||||
|
len: u32,
|
||||||
|
}
|
||||||
|
pub struct KeyRawStatesResolver {
|
||||||
|
bytes_pos: usize,
|
||||||
|
}
|
||||||
|
impl Resolve<KeyRawStates> for KeyRawStatesResolver {
|
||||||
|
type Archived = ArchivedKeyRawStates;
|
||||||
|
fn resolve(self, pos: usize, value: &KeyRawStates) -> Self::Archived {
|
||||||
|
Self::Archived {
|
||||||
|
ptr: unsafe {
|
||||||
|
rkyv::RelPtr::new(pos + rkyv::offset_of!(ArchivedKeyRawStates, ptr), self.bytes_pos)
|
||||||
|
},
|
||||||
|
len: value.deref().len() as u32,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Archive for KeyRawStates {
|
||||||
|
type Archived = ArchivedKeyRawStates;
|
||||||
|
type Resolver = KeyRawStatesResolver;
|
||||||
|
|
||||||
|
fn archive<W: Write + ?Sized>(&self, writer: &mut W) -> Result<Self::Resolver, W::Error> {
|
||||||
|
let bytes_pos = writer.pos();
|
||||||
|
writer.write( self.deref())?;
|
||||||
|
Ok(Self::Resolver { bytes_pos })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, rkyv::Archive)]
|
#[derive(Debug, Copy, Clone, rkyv::Archive)]
|
||||||
pub enum KeyMap {
|
pub enum KeyMap {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
mod api;
|
mod api;
|
||||||
use api::*;
|
use api::*;
|
||||||
use xous::ipc::Sendable;
|
|
||||||
|
|
||||||
use heapless::Vec;
|
use heapless::Vec;
|
||||||
use heapless::consts::*;
|
use heapless::consts::*;
|
||||||
|
|
@ -18,6 +17,7 @@ use log::{error, info};
|
||||||
use core::pin::Pin;
|
use core::pin::Pin;
|
||||||
use xous::buffer;
|
use xous::buffer;
|
||||||
use rkyv::{archived_value_mut, Unarchive};
|
use rkyv::{archived_value_mut, Unarchive};
|
||||||
|
use rkyv::Write;
|
||||||
|
|
||||||
/// Compute the dvorak key mapping of row/col to key tuples
|
/// Compute the dvorak key mapping of row/col to key tuples
|
||||||
fn map_dvorak(code: RowCol) -> ScanCode {
|
fn map_dvorak(code: RowCol) -> ScanCode {
|
||||||
|
|
@ -875,6 +875,8 @@ fn xmain() -> ! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// this code is totally untested
|
||||||
if keyups.is_some() || keydowns.is_some() {
|
if keyups.is_some() || keydowns.is_some() {
|
||||||
// send the raw codes
|
// send the raw codes
|
||||||
for conn in raw_conns.iter() {
|
for conn in raw_conns.iter() {
|
||||||
|
|
@ -889,9 +891,10 @@ fn xmain() -> ! {
|
||||||
rs.keydowns.push(k).unwrap();
|
rs.keydowns.push(k).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let sendable_rs = Sendable::new(rs).expect("KBD: can't create sendable raw codes structure");
|
let mut writer = rkyv::ArchiveBuffer::new(xous::XousBuffer::new(4096));
|
||||||
sendable_rs.send(*conn, KeyRawStates::new().mid() as u32) // tortured syntax to stick with the abstraction that message ID comes from the struct
|
let pos = writer.archive(&rs).expect("couldn't archive request");
|
||||||
.expect("KBD: can't send raw code");
|
let mut xous_buffer = writer.into_inner();
|
||||||
|
xous_buffer.send(*conn, pos as u32).expect("KBD: can't send raw code");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -258,7 +258,7 @@ fn reader_thread(mut output: implementation::OutputWriter) {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
xous::Message::Move(msg) => {
|
xous::Message::Move(msg) => {
|
||||||
String::from_message(msg)
|
String<4000>::from_message(msg)
|
||||||
.map(|log_entry: String<4000>| {
|
.map(|log_entry: String<4000>| {
|
||||||
writeln!(
|
writeln!(
|
||||||
output,
|
output,
|
||||||
|
|
@ -285,7 +285,7 @@ fn reader_thread(mut output: implementation::OutputWriter) {
|
||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
xous::Message::MutableBorrow(msg) => {
|
xous::Message::MutableBorrow(msg) => {
|
||||||
String::from_message(msg)
|
String<4000>::from_message(msg)
|
||||||
.map(|mut log_entry: String<4000>| {
|
.map(|mut log_entry: String<4000>| {
|
||||||
writeln!(
|
writeln!(
|
||||||
output,
|
output,
|
||||||
|
|
@ -324,7 +324,7 @@ fn some_main() -> ! {
|
||||||
)
|
)
|
||||||
.expect("couldn't map GPIO CSR range");
|
.expect("couldn't map GPIO CSR range");
|
||||||
let mut gpio = CSR::new(gpio_base.as_mut_ptr() as *mut u32);
|
let mut gpio = CSR::new(gpio_base.as_mut_ptr() as *mut u32);
|
||||||
gpio.wfo(utra::gpio::UARTSEL_UARTSEL, 1); // 0 = kernel, 1 = log, 2 = app_uart
|
gpio.wfo(utra::gpio::UARTSEL_UARTSEL, 0); // 0 = kernel, 1 = log, 2 = app_uart
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut output = implementation::init();
|
let mut output = implementation::init();
|
||||||
|
|
|
||||||
|
|
@ -175,6 +175,10 @@ fn shell_main() -> ! {
|
||||||
// make a thread to catch responses from the COM
|
// make a thread to catch responses from the COM
|
||||||
xous::create_thread_simple(event_thread, 0).unwrap();
|
xous::create_thread_simple(event_thread, 0).unwrap();
|
||||||
info!("SHELL: COM responder thread started");
|
info!("SHELL: COM responder thread started");
|
||||||
|
let start_time: u64 = ticktimer_server::elapsed_ms(ticktimer_conn).unwrap();
|
||||||
|
while ticktimer_server::elapsed_ms(ticktimer_conn).unwrap() - start_time < 1000 {
|
||||||
|
xous::yield_slice();
|
||||||
|
}
|
||||||
|
|
||||||
let screensize = graphics_server::screen_size(graphics_conn).expect("Couldn't get screen size");
|
let screensize = graphics_server::screen_size(graphics_conn).expect("Couldn't get screen size");
|
||||||
|
|
||||||
|
|
@ -236,7 +240,7 @@ fn shell_main() -> ! {
|
||||||
graphics_server::set_cursor(graphics_conn, status_cursor).expect("can't set cursor");
|
graphics_server::set_cursor(graphics_conn, status_cursor).expect("can't set cursor");
|
||||||
//info!("SHELL: debug0");
|
//info!("SHELL: debug0");
|
||||||
graphics_server::draw_string(graphics_conn, &string_buffer).expect("unable to draw string");
|
graphics_server::draw_string(graphics_conn, &string_buffer).expect("unable to draw string");
|
||||||
info!("SHELL: debug1");
|
//info!("SHELL: debug1");
|
||||||
status_cursor.pt.x = 95;
|
status_cursor.pt.x = 95;
|
||||||
string_buffer.clear();
|
string_buffer.clear();
|
||||||
write!(
|
write!(
|
||||||
|
|
@ -246,8 +250,9 @@ fn shell_main() -> ! {
|
||||||
)
|
)
|
||||||
.expect("Can't write");
|
.expect("Can't write");
|
||||||
graphics_server::set_cursor(graphics_conn, status_cursor).expect("can't set cursor");
|
graphics_server::set_cursor(graphics_conn, status_cursor).expect("can't set cursor");
|
||||||
info!("SHELL: debug2");
|
//info!("SHELL: debug2");
|
||||||
graphics_server::draw_string(graphics_conn, &string_buffer).expect("unable to draw string");
|
graphics_server::draw_string(graphics_conn, &string_buffer).expect("unable to draw string");
|
||||||
|
//info!("SHELL: debug3");
|
||||||
status_cursor.pt.x = 190;
|
status_cursor.pt.x = 190;
|
||||||
string_buffer.clear();
|
string_buffer.clear();
|
||||||
write!(
|
write!(
|
||||||
|
|
@ -373,19 +378,6 @@ fn shell_main() -> ! {
|
||||||
)
|
)
|
||||||
.expect("unable to draw to screen");
|
.expect("unable to draw to screen");
|
||||||
|
|
||||||
/* test code to exhaust memory allocation
|
|
||||||
let mut iter = 0;
|
|
||||||
info!("Test memory allocation");
|
|
||||||
loop {
|
|
||||||
let lookup = Lookup::new();
|
|
||||||
let mut sendable_lookup = Sendable::new(lookup)
|
|
||||||
.expect("can't create sendable lookup structure");
|
|
||||||
write!(sendable_lookup.name, "A test Name!").unwrap();
|
|
||||||
sendable_lookup.lend_mut(ns_conn, sendable_lookup.mid()).expect("nameserver lookup failure!");
|
|
||||||
info!("memtest: iter {}", iter);
|
|
||||||
iter += 1;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
// Periodic tasks
|
// Periodic tasks
|
||||||
if let Ok(elapsed_time) = ticktimer_server::elapsed_ms(ticktimer_conn) {
|
if let Ok(elapsed_time) = ticktimer_server::elapsed_ms(ticktimer_conn) {
|
||||||
if elapsed_time - last_time > 500 {
|
if elapsed_time - last_time > 500 {
|
||||||
|
|
|
||||||
|
|
@ -78,21 +78,3 @@ pub fn request_connection_blocking(name: &str) -> Result<xous::CID, xous::Error>
|
||||||
xous::yield_slice();
|
xous::yield_slice();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// /// API for other processes to re-use the Registration record for brokering requests
|
|
||||||
// pub fn request_core(
|
|
||||||
// name: &str,
|
|
||||||
// conn: xous::CID,
|
|
||||||
// subtype: u16,
|
|
||||||
// ) -> Result<xous::Result, xous::Error> {
|
|
||||||
// let registration = api::default();
|
|
||||||
// let mut sendable_registration =
|
|
||||||
// Sendable::new(registration).expect("can't create sendable registration structure");
|
|
||||||
// // sendable_registration.set_subtype(subtype);
|
|
||||||
// write!(sendable_registration.name, "{}", name).unwrap();
|
|
||||||
// sendable_registration
|
|
||||||
// .lend(conn, api::ID_REGISTER_NAME | (subtype as u32))
|
|
||||||
// .expect("event request registration failure!");
|
|
||||||
|
|
||||||
// Ok(xous::Result::Ok)
|
|
||||||
// }
|
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ impl<'a> XousBuffer<'a> {
|
||||||
id: id as usize,
|
id: id as usize,
|
||||||
buf: self.valid,
|
buf: self.valid,
|
||||||
offset: None,
|
offset: None,
|
||||||
valid: None,
|
valid: crate::MemorySize::new(self.slice.len()),
|
||||||
};
|
};
|
||||||
send_message(connection, Message::MutableBorrow(msg))
|
send_message(connection, Message::MutableBorrow(msg))
|
||||||
}
|
}
|
||||||
|
|
@ -70,7 +70,7 @@ impl<'a> XousBuffer<'a> {
|
||||||
id: id as usize,
|
id: id as usize,
|
||||||
buf: self.valid,
|
buf: self.valid,
|
||||||
offset: None,
|
offset: None,
|
||||||
valid: None,
|
valid: crate::MemorySize::new(self.slice.len()),
|
||||||
};
|
};
|
||||||
send_message(connection, Message::Borrow(msg))
|
send_message(connection, Message::Borrow(msg))
|
||||||
}
|
}
|
||||||
|
|
@ -94,7 +94,6 @@ impl<'a> XousBuffer<'a> {
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> core::convert::AsRef<[u8]> for XousBuffer<'a> {
|
impl<'a> core::convert::AsRef<[u8]> for XousBuffer<'a> {
|
||||||
fn as_ref(&self) -> &[u8] {
|
fn as_ref(&self) -> &[u8] {
|
||||||
self.slice
|
self.slice
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,7 @@ impl<const N: usize> String<N> {
|
||||||
xous_buffer.lend(connection, pos as u32)
|
xous_buffer.lend(connection, pos as u32)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
/// Move this string from the client into the server.
|
/// Move this string from the client into the server.
|
||||||
pub fn send(
|
pub fn send(
|
||||||
self,
|
self,
|
||||||
|
|
@ -72,7 +73,7 @@ impl<const N: usize> String<N> {
|
||||||
|
|
||||||
xous_buffer.send(connection, pos as u32)
|
xous_buffer.send(connection, pos as u32)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
/// Clear the contents of this String and set the length to 0
|
/// Clear the contents of this String and set the length to 0
|
||||||
pub fn clear(&mut self) {
|
pub fn clear(&mut self) {
|
||||||
self.len = 0;
|
self.len = 0;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue