remove heapless, go to libstd for all collections!!!!

*fistpump*
This commit is contained in:
bunnie 2021-08-04 01:25:32 +08:00
parent 34d44ee9e7
commit 8b83fb7c65
20 changed files with 123 additions and 334 deletions

190
Cargo.lock generated
View file

@ -64,27 +64,6 @@ version = "1.0.38"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "afddf7f520a80dbf76e6f50a35bca42a2331ef227a28b3b6dc5c2e2338d114b1" checksum = "afddf7f520a80dbf76e6f50a35bca42a2331ef227a28b3b6dc5c2e2338d114b1"
[[package]]
name = "as-slice"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45403b49e3954a4b8428a0ac21a4b7afadccf92bfd96273f1a58cd4812496ae0"
dependencies = [
"generic-array 0.12.4",
"generic-array 0.13.3",
"generic-array 0.14.4",
"stable_deref_trait",
]
[[package]]
name = "atomic-polyfill"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30302dda7a66f8c55932ebf208f7def840743ff64d495e9ceffcd97c18f11d39"
dependencies = [
"cortex-m",
]
[[package]] [[package]]
name = "atty" name = "atty"
version = "0.2.14" version = "0.2.14"
@ -116,15 +95,6 @@ dependencies = [
"rustc-demangle", "rustc-demangle",
] ]
[[package]]
name = "bare-metal"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5deb64efa5bd81e31fcd1938615a6d98c82eafcbcd787162b6f63b91d6bac5b3"
dependencies = [
"rustc_version",
]
[[package]] [[package]]
name = "base64" name = "base64"
version = "0.13.0" version = "0.13.0"
@ -188,12 +158,6 @@ dependencies = [
"which 3.1.1", "which 3.1.1",
] ]
[[package]]
name = "bitfield"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46afbd2983a5d5a7bd740ccb198caf5b82f45c40c09c0eed36052d91cb92e719"
[[package]] [[package]]
name = "bitflags" name = "bitflags"
version = "1.2.1" version = "1.2.1"
@ -222,7 +186,7 @@ version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4"
dependencies = [ dependencies = [
"generic-array 0.14.4", "generic-array",
] ]
[[package]] [[package]]
@ -363,7 +327,7 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ee52072ec15386f770805afd189a01c8841be8696bed250fa2f13c4c0d6dfb7" checksum = "7ee52072ec15386f770805afd189a01c8841be8696bed250fa2f13c4c0d6dfb7"
dependencies = [ dependencies = [
"generic-array 0.14.4", "generic-array",
] ]
[[package]] [[package]]
@ -477,18 +441,6 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
[[package]]
name = "cortex-m"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "643a210c1bdc23d0db511e2a576082f4ff4dcae9d0c37f50b431b8f8439d6d6b"
dependencies = [
"bare-metal",
"bitfield",
"embedded-hal",
"volatile-register",
]
[[package]] [[package]]
name = "cpufeatures" name = "cpufeatures"
version = "0.1.4" version = "0.1.4"
@ -579,7 +531,7 @@ version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066"
dependencies = [ dependencies = [
"generic-array 0.14.4", "generic-array",
] ]
[[package]] [[package]]
@ -610,16 +562,6 @@ dependencies = [
"zeroize", "zeroize",
] ]
[[package]]
name = "embedded-hal"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db184d3fa27bc7a2344250394c0264144dfe0bc81a4401801dcb964b8dd172ad"
dependencies = [
"nb 0.1.3",
"void",
]
[[package]] [[package]]
name = "encoding_rs" name = "encoding_rs"
version = "0.8.28" version = "0.8.28"
@ -754,7 +696,6 @@ dependencies = [
"content-plugin-api", "content-plugin-api",
"enum_dispatch", "enum_dispatch",
"graphics-server", "graphics-server",
"heapless 0.7.0",
"ime-plugin-api", "ime-plugin-api",
"ime-plugin-shell", "ime-plugin-shell",
"keyboard", "keyboard",
@ -773,24 +714,6 @@ dependencies = [
"xous-names", "xous-names",
] ]
[[package]]
name = "generic-array"
version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd"
dependencies = [
"typenum",
]
[[package]]
name = "generic-array"
version = "0.13.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f797e67af32588215eaaab8327027ee8e71b9dd0b2b26996aedf20c030fce309"
dependencies = [
"typenum",
]
[[package]] [[package]]
name = "generic-array" name = "generic-array"
version = "0.14.4" version = "0.14.4"
@ -829,8 +752,6 @@ name = "graphics-server"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"blitstr-ref", "blitstr-ref",
"hash32 0.2.1",
"hash32-derive",
"keyboard", "keyboard",
"log", "log",
"log-server", "log-server",
@ -846,15 +767,6 @@ dependencies = [
"xous-names", "xous-names",
] ]
[[package]]
name = "hash32"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4041af86e63ac4298ce40e5cca669066e75b6f1aa3390fe2561ffa5e1d9f4cc"
dependencies = [
"byteorder",
]
[[package]] [[package]]
name = "hash32" name = "hash32"
version = "0.2.1" version = "0.2.1"
@ -875,29 +787,6 @@ dependencies = [
"syn 0.13.11", "syn 0.13.11",
] ]
[[package]]
name = "heapless"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74911a68a1658cfcfb61bc0ccfbd536e3b6e906f8c2f7883ee50157e3e2184f1"
dependencies = [
"as-slice",
"generic-array 0.13.3",
"hash32 0.1.1",
"stable_deref_trait",
]
[[package]]
name = "heapless"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e94c13b78b595d2adbd708bce276664f1047f98fc32ddbf463b4c191158334a6"
dependencies = [
"atomic-polyfill",
"hash32 0.2.1",
"stable_deref_trait",
]
[[package]] [[package]]
name = "hermit-abi" name = "hermit-abi"
version = "0.1.18" version = "0.1.18"
@ -993,7 +882,6 @@ dependencies = [
name = "ime-plugin-shell" name = "ime-plugin-shell"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"heapless 0.5.6",
"ime-plugin-api", "ime-plugin-api",
"log", "log",
"log-server", "log-server",
@ -1037,7 +925,6 @@ dependencies = [
name = "keyboard" name = "keyboard"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"heapless 0.7.0",
"llio", "llio",
"log", "log",
"log-server", "log-server",
@ -1084,7 +971,6 @@ dependencies = [
name = "llio" name = "llio"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"heapless 0.7.0",
"log", "log",
"log-server", "log-server",
"num-derive", "num-derive",
@ -1174,21 +1060,6 @@ dependencies = [
"autocfg", "autocfg",
] ]
[[package]]
name = "nb"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "801d31da0513b6ec5214e9bf433a77966320625a37860f910be265be6e18d06f"
dependencies = [
"nb 1.0.0",
]
[[package]]
name = "nb"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "546c37ac5d9e56f55e73b677106873d9d9f5190605e41a856503623648488cae"
[[package]] [[package]]
name = "nix" name = "nix"
version = "0.20.0" version = "0.20.0"
@ -1689,15 +1560,6 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1956f5517128a2b6f23ab2dadf1a976f4f5b27962e7724c2bf3d45e539ec098c" checksum = "1956f5517128a2b6f23ab2dadf1a976f4f5b27962e7724c2bf3d45e539ec098c"
[[package]]
name = "rustc_version"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
dependencies = [
"semver",
]
[[package]] [[package]]
name = "ryu" name = "ryu"
version = "1.0.5" version = "1.0.5"
@ -1732,21 +1594,6 @@ dependencies = [
"version-compare", "version-compare",
] ]
[[package]]
name = "semver"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
dependencies = [
"semver-parser",
]
[[package]]
name = "semver-parser"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.123" version = "1.0.123"
@ -1794,7 +1641,6 @@ dependencies = [
"engine-sha512", "engine-sha512",
"gam", "gam",
"graphics-server", "graphics-server",
"heapless 0.7.0",
"hex", "hex",
"ime-plugin-api", "ime-plugin-api",
"ime-plugin-shell", "ime-plugin-shell",
@ -1866,12 +1712,6 @@ dependencies = [
"xous-names", "xous-names",
] ]
[[package]]
name = "stable_deref_trait"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
[[package]] [[package]]
name = "status" name = "status"
version = "0.1.0" version = "0.1.0"
@ -2052,7 +1892,6 @@ dependencies = [
name = "ticktimer-server" name = "ticktimer-server"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"heapless 0.7.0",
"log", "log",
"log-server", "log-server",
"num-derive", "num-derive",
@ -2155,12 +1994,6 @@ dependencies = [
"svd2utra", "svd2utra",
] ]
[[package]]
name = "vcell"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77439c1b53d2303b20d9459b1ade71a83c716e3f9c34f3228c00e6f185d6c002"
[[package]] [[package]]
name = "vec_map" name = "vec_map"
version = "0.8.2" version = "0.8.2"
@ -2189,21 +2022,6 @@ version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
[[package]]
name = "void"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
[[package]]
name = "volatile-register"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d67cb4616d99b940db1d6bd28844ff97108b498a6ca850e5b6191a532063286"
dependencies = [
"vcell",
]
[[package]] [[package]]
name = "wasi" name = "wasi"
version = "0.10.2+wasi-snapshot-preview1" version = "0.10.2+wasi-snapshot-preview1"
@ -2509,7 +2327,7 @@ dependencies = [
name = "xous-names" name = "xous-names"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"hash32 0.2.1", "hash32",
"hash32-derive", "hash32-derive",
"log", "log",
"log-server", "log-server",

View file

@ -7,7 +7,6 @@ version = "0.1.0"
[dependencies] [dependencies]
com_rs-ref = {path = "../../imports/com_rs-ref"} com_rs-ref = {path = "../../imports/com_rs-ref"}
#heapless = "0.7"
log = "0.4" log = "0.4"
log-server = {path = "../log-server"} log-server = {path = "../log-server"}
ticktimer-server = {path = "../ticktimer-server"} ticktimer-server = {path = "../ticktimer-server"}

View file

@ -76,9 +76,6 @@ mod implementation {
ticktimer, ticktimer,
workqueue: Vec::new(), workqueue: Vec::new(),
busy: false, busy: false,
//tx_queue: Vec::new(),
//rx_queue: Vec::new(),
//in_progress: false,
stby_current: None, stby_current: None,
}; };
@ -148,7 +145,7 @@ mod implementation {
pub fn process_queue(&mut self) -> Option<xous::CID> { pub fn process_queue(&mut self) -> Option<xous::CID> {
if !self.workqueue.is_empty() && !self.busy { if !self.workqueue.is_empty() && !self.busy {
self.busy = true; self.busy = true;
let work_descriptor = self.workqueue.swap_remove(0); // not quite FIFO, but Vec does not support FIFO (best we can do with "heapless") let work_descriptor = self.workqueue.remove(0);
let ret = if work_descriptor.work.verb == ComState::STAT.verb { let ret = if work_descriptor.work.verb == ComState::STAT.verb {
let stats = self.get_battstats(); let stats = self.get_battstats();
match return_battstats(work_descriptor.sender, stats) { match return_battstats(work_descriptor.sender, stats) {
@ -204,10 +201,8 @@ mod implementation {
use com_rs::*; use com_rs::*;
use log::error; use log::error;
use heapless::Vec;
pub struct XousCom { pub struct XousCom {
pub workqueue: Vec<WorkRequest, 64>, pub workqueue: Vec<WorkRequest>,
busy: bool, busy: bool,
} }
@ -242,7 +237,7 @@ mod implementation {
pub fn process_queue(&mut self) -> Option<xous::CID> { pub fn process_queue(&mut self) -> Option<xous::CID> {
if !self.workqueue.is_empty() && !self.busy { if !self.workqueue.is_empty() && !self.busy {
self.busy = true; self.busy = true;
let work_descriptor = self.workqueue.swap_remove(0); // not quite FIFO, but Vec does not support FIFO (best we can do with "heapless") let work_descriptor = self.workqueue.remove(0);
let ret = if work_descriptor.work.verb == ComState::STAT.verb { let ret = if work_descriptor.work.verb == ComState::STAT.verb {
let stats = self.get_battstats(); let stats = self.get_battstats();
match return_battstats(work_descriptor.sender, stats) { match return_battstats(work_descriptor.sender, stats) {

View file

@ -10,7 +10,6 @@ blitstr-ref = {path = "../../imports/blitstr-ref"}
com = {path = "../com"} # used by the backlight setting on the main menu thread com = {path = "../com"} # used by the backlight setting on the main menu thread
content-plugin-api = {path = "../content-plugin-api"} content-plugin-api = {path = "../content-plugin-api"}
graphics-server = {path = "../graphics-server"} graphics-server = {path = "../graphics-server"}
heapless = "0.7" # used for creating a sortable heap of canvas objects
ime-plugin-api = {path = "../ime-plugin-api"} ime-plugin-api = {path = "../ime-plugin-api"}
ime-plugin-shell = {path = "../ime-plugin-shell"} ime-plugin-shell = {path = "../ime-plugin-shell"}
keyboard = {path = "../keyboard"} keyboard = {path = "../keyboard"}

View file

@ -1,6 +1,7 @@
use std::collections::HashMap;
use std::collections::BinaryHeap;
use core::cmp::Ordering; use core::cmp::Ordering;
use heapless::binary_heap::{BinaryHeap, Max};
use heapless::FnvIndexMap;
use graphics_server::*; use graphics_server::*;
use log::{error, info}; use log::{error, info};
@ -145,7 +146,7 @@ impl PartialEq for Canvas {
impl Eq for Canvas {} impl Eq for Canvas {}
pub fn deface(gfx: &graphics_server::Gfx, trng: &trng::Trng, canvases: &mut FnvIndexMap<Gid, Canvas, 32>) -> bool { pub fn deface(gfx: &graphics_server::Gfx, trng: &trng::Trng, canvases: &mut HashMap<Gid, Canvas>) -> bool {
// first check if any need defacing, if not, then we're done // first check if any need defacing, if not, then we're done
let mut needs_defacing = false; let mut needs_defacing = false;
let mut defaced = false; // this is set if any drawing actually happens let mut defaced = false; // this is set if any drawing actually happens
@ -230,19 +231,19 @@ pub fn deface(gfx: &graphics_server::Gfx, trng: &trng::Trng, canvases: &mut FnvI
} }
// we use the "screen" parameter to determine when we can turn off drawing to canvases that are off-screen // we use the "screen" parameter to determine when we can turn off drawing to canvases that are off-screen
pub fn recompute_canvases(canvases: &FnvIndexMap<Gid, Canvas, 32>, screen: Rectangle) -> FnvIndexMap<Gid, Canvas, 32> { pub fn recompute_canvases(canvases: &HashMap<Gid, Canvas>, screen: Rectangle) -> HashMap<Gid, Canvas> {
let debug = false; let debug = false;
// first, sort canvases by trust_level. Canvas implements ord/eq based on the trust_level attribute // first, sort canvases by trust_level. Canvas implements ord/eq based on the trust_level attribute
// so jush pushing it into a max binary heap does the trick. // so jush pushing it into a max binary heap does the trick.
if debug { info!("CANVAS: recompute canvas"); } if debug { info!("CANVAS: recompute canvas"); }
let mut sorted_clipregions: BinaryHeap<Canvas, Max, 32> = BinaryHeap::new(); let mut sorted_clipregions: BinaryHeap<Canvas> = BinaryHeap::new();
for (&k, &c) in canvases.iter() { for (&k, &c) in canvases.iter() {
if debug { info!(" CANVAS: sorting gid {:?}, canvas {:?}", k, c);} if debug { info!(" CANVAS: sorting gid {:?}, canvas {:?}", k, c);}
sorted_clipregions.push(c).unwrap(); // always succeeds because incoming type is the same size sorted_clipregions.push(c); // always succeeds because incoming type is the same size
} }
// now, descend through trust levels and compute intersections, putting the updated drawable states into higher_clipregions // now, descend through trust levels and compute intersections, putting the updated drawable states into higher_clipregions
let mut higher_clipregions: BinaryHeap<Canvas, Max, 32> = BinaryHeap::new(); let mut higher_clipregions: BinaryHeap<Canvas> = BinaryHeap::new();
let mut trust_level: u8 = 255; let mut trust_level: u8 = 255;
// sorted_clipregions is a Max heap keyed on trust, so popping the elements off will return them sorted from most to least trusted // sorted_clipregions is a Max heap keyed on trust, so popping the elements off will return them sorted from most to least trusted
if debug{info!("CANVAS: received screen argument of {:?}", screen);} if debug{info!("CANVAS: received screen argument of {:?}", screen);}
@ -271,18 +272,18 @@ pub fn recompute_canvases(canvases: &FnvIndexMap<Gid, Canvas, 32>, screen: Recta
} }
} }
canvas.set_drawable(drawable); canvas.set_drawable(drawable);
higher_clipregions.push(canvas).unwrap(); higher_clipregions.push(canvas);
} else { } else {
break; break;
} }
} }
// create a new index map out of the recomputed higher_clipregions // create a new index map out of the recomputed higher_clipregions
let mut map: FnvIndexMap<Gid, Canvas, 32> = FnvIndexMap::new(); let mut map: HashMap<Gid, Canvas> = HashMap::new();
if debug { info!("CANVAS: reconstituting index map");} if debug { info!("CANVAS: reconstituting index map");}
for &c in higher_clipregions.iter() { for &c in higher_clipregions.iter() {
if debug { info!(" CANVAS: inserting gid {:?}, canvas {:?}", c.gid(), c);} if debug { info!(" CANVAS: inserting gid {:?}, canvas {:?}", c.gid(), c);}
map.insert(c.gid(), c).unwrap(); map.insert(c.gid(), c);
} }
map map

View file

@ -1,6 +1,7 @@
use std::collections::HashMap;
use crate::Canvas; use crate::Canvas;
use heapless::FnvIndexMap;
use blitstr_ref as blitstr; use blitstr_ref as blitstr;
use blitstr::GlyphStyle; use blitstr::GlyphStyle;
use graphics_server::*; use graphics_server::*;
@ -26,7 +27,7 @@ pub(crate) struct ChatLayout {
impl ChatLayout { impl ChatLayout {
// pass in the status canvas so we can size around it, but we can't draw on it // pass in the status canvas so we can size around it, but we can't draw on it
pub fn init(gfx: &graphics_server::Gfx, trng: &trng::Trng, base_trust: u8, pub fn init(gfx: &graphics_server::Gfx, trng: &trng::Trng, base_trust: u8,
status_canvas: &Canvas, canvases: &mut FnvIndexMap<Gid, Canvas, {crate::MAX_CANVASES}>) -> Result<ChatLayout, xous::Error> { status_canvas: &Canvas, canvases: &mut HashMap<Gid, Canvas>) -> Result<ChatLayout, xous::Error> {
let screensize = gfx.screen_size().expect("Couldn't get screen size"); let screensize = gfx.screen_size().expect("Couldn't get screen size");
// get the height of various text regions to compute the layout // get the height of various text regions to compute the layout
let small_height: i16 = gfx.glyph_height_hint(GlyphStyle::Small).expect("couldn't get glyph height") as i16; let small_height: i16 = gfx.glyph_height_hint(GlyphStyle::Small).expect("couldn't get glyph height") as i16;
@ -46,20 +47,20 @@ impl ChatLayout {
checked_base_trust - 2, checked_base_trust - 2,
&trng, None &trng, None
).expect("couldn't create predictive text canvas"); ).expect("couldn't create predictive text canvas");
canvases.insert(predictive_canvas.gid(), predictive_canvas).expect("couldn't store predictive canvas"); canvases.insert(predictive_canvas.gid(), predictive_canvas);
let min_input_height = regular_height + margin*2; let min_input_height = regular_height + margin*2;
let input_canvas = Canvas::new( let input_canvas = Canvas::new(
Rectangle::new_v_stack(predictive_canvas.clip_rect(), -min_input_height), Rectangle::new_v_stack(predictive_canvas.clip_rect(), -min_input_height),
checked_base_trust - 2, &trng, None checked_base_trust - 2, &trng, None
).expect("couldn't create input text canvas"); ).expect("couldn't create input text canvas");
canvases.insert(input_canvas.gid(), input_canvas).expect("couldn't store input canvas"); canvases.insert(input_canvas.gid(), input_canvas);
let content_canvas = Canvas::new( let content_canvas = Canvas::new(
Rectangle::new_v_span(status_canvas.clip_rect(), input_canvas.clip_rect()), Rectangle::new_v_span(status_canvas.clip_rect(), input_canvas.clip_rect()),
checked_base_trust / 2, &trng, None checked_base_trust / 2, &trng, None
).expect("couldn't create content canvas"); ).expect("couldn't create content canvas");
canvases.insert(content_canvas.gid(), content_canvas).expect("can't store content canvas"); canvases.insert(content_canvas.gid(), content_canvas);
Ok(ChatLayout { Ok(ChatLayout {
content: content_canvas.gid(), content: content_canvas.gid(),
@ -78,7 +79,7 @@ impl LayoutApi for ChatLayout {
fn behavior(&self) -> LayoutBehavior { fn behavior(&self) -> LayoutBehavior {
LayoutBehavior::App LayoutBehavior::App
} }
fn clear(&self, gfx: &graphics_server::Gfx, canvases: &mut FnvIndexMap<Gid, Canvas, {crate::MAX_CANVASES}>) -> Result<(), xous::Error> { fn clear(&self, gfx: &graphics_server::Gfx, canvases: &mut HashMap<Gid, Canvas>) -> Result<(), xous::Error> {
let input_canvas = canvases.get(&self.input).expect("couldn't find input canvas"); let input_canvas = canvases.get(&self.input).expect("couldn't find input canvas");
let content_canvas = canvases.get(&self.content).expect("couldn't find content canvas"); let content_canvas = canvases.get(&self.content).expect("couldn't find content canvas");
let predictive_canvas = canvases.get(&self.predictive).expect("couldn't find predictive canvas"); let predictive_canvas = canvases.get(&self.predictive).expect("couldn't find predictive canvas");
@ -96,7 +97,7 @@ impl LayoutApi for ChatLayout {
gfx.draw_rectangle(rect).expect("can't clear canvas"); gfx.draw_rectangle(rect).expect("can't clear canvas");
Ok(()) Ok(())
} }
fn resize_height(&mut self, gfx: &graphics_server::Gfx, new_height: i16, status_canvas: &Canvas, canvases: &mut FnvIndexMap<Gid, Canvas, {crate::MAX_CANVASES}>) -> Result<Point, xous::Error> { fn resize_height(&mut self, gfx: &graphics_server::Gfx, new_height: i16, status_canvas: &Canvas, canvases: &mut HashMap<Gid, Canvas>) -> Result<Point, xous::Error> {
let input_canvas = canvases.get(&self.input).expect("couldn't find input canvas"); let input_canvas = canvases.get(&self.input).expect("couldn't find input canvas");
let predictive_canvas = canvases.get(&self.predictive).expect("couldn't find predictive canvas"); let predictive_canvas = canvases.get(&self.predictive).expect("couldn't find predictive canvas");
@ -136,7 +137,7 @@ impl LayoutApi for ChatLayout {
fn get_content_canvas(&self) -> Gid { fn get_content_canvas(&self) -> Gid {
self.content self.content
} }
fn set_visibility_state(&mut self, onscreen: bool, canvases: &mut FnvIndexMap<Gid, Canvas, {crate::MAX_CANVASES}>) { fn set_visibility_state(&mut self, onscreen: bool, canvases: &mut HashMap<Gid, Canvas>) {
log::debug!("request modal to onscreen {} from self.visible {}", onscreen, self.visible); log::debug!("request modal to onscreen {} from self.visible {}", onscreen, self.visible);
if onscreen == self.visible { if onscreen == self.visible {
log::trace!("chatlayout: no change to visibility, moving on"); log::trace!("chatlayout: no change to visibility, moving on");
@ -179,7 +180,7 @@ pub(crate) struct MenuLayout {
visible: bool, visible: bool,
} }
impl MenuLayout { impl MenuLayout {
pub fn init(gfx: &graphics_server::Gfx, trng: &trng::Trng, base_trust: u8, canvases: &mut FnvIndexMap<Gid, Canvas, {crate::MAX_CANVASES}>) -> Result<MenuLayout, xous::Error> { pub fn init(gfx: &graphics_server::Gfx, trng: &trng::Trng, base_trust: u8, canvases: &mut HashMap<Gid, Canvas>) -> Result<MenuLayout, xous::Error> {
let screensize = gfx.screen_size().expect("Couldn't get screen size"); let screensize = gfx.screen_size().expect("Couldn't get screen size");
// get the height of various text regions to compute the layout // get the height of various text regions to compute the layout
let height: i16 = gfx.glyph_height_hint(GlyphStyle::Regular).expect("couldn't get glyph height") as i16; let height: i16 = gfx.glyph_height_hint(GlyphStyle::Regular).expect("couldn't get glyph height") as i16;
@ -198,7 +199,7 @@ impl MenuLayout {
Rectangle::new_coords(MENU_X_PAD, MENU_Y_PAD, screensize.x - MENU_X_PAD, MENU_Y_PAD + height), Rectangle::new_coords(MENU_X_PAD, MENU_Y_PAD, screensize.x - MENU_X_PAD, MENU_Y_PAD + height),
checked_base_trust - 1, &trng, None checked_base_trust - 1, &trng, None
).expect("couldn't create menu canvas"); ).expect("couldn't create menu canvas");
canvases.insert(menu_canvas.gid(), menu_canvas).expect("can't store menu canvas"); canvases.insert(menu_canvas.gid(), menu_canvas);
Ok(MenuLayout { Ok(MenuLayout {
menu: menu_canvas.gid(), menu: menu_canvas.gid(),
@ -215,14 +216,14 @@ impl LayoutApi for MenuLayout {
fn behavior(&self) -> LayoutBehavior { fn behavior(&self) -> LayoutBehavior {
LayoutBehavior::Alert LayoutBehavior::Alert
} }
fn clear(&self, gfx: &graphics_server::Gfx, canvases: &mut FnvIndexMap<Gid, Canvas, {crate::MAX_CANVASES}>) -> Result<(), xous::Error> { fn clear(&self, gfx: &graphics_server::Gfx, canvases: &mut HashMap<Gid, Canvas>) -> Result<(), xous::Error> {
let menu_canvas = canvases.get(&self.menu).expect("couldn't find menu canvas"); let menu_canvas = canvases.get(&self.menu).expect("couldn't find menu canvas");
let mut rect = menu_canvas.clip_rect(); let mut rect = menu_canvas.clip_rect();
rect.style = DrawStyle {fill_color: Some(PixelColor::Light), stroke_color: None, stroke_width: 0,}; rect.style = DrawStyle {fill_color: Some(PixelColor::Light), stroke_color: None, stroke_width: 0,};
gfx.draw_rectangle(rect) gfx.draw_rectangle(rect)
} }
fn resize_height(&mut self, _gfx: &graphics_server::Gfx, new_height: i16, _status_canvas: &Canvas, canvases: &mut FnvIndexMap<Gid, Canvas, {crate::MAX_CANVASES}>) -> Result<Point, xous::Error> { fn resize_height(&mut self, _gfx: &graphics_server::Gfx, new_height: i16, _status_canvas: &Canvas, canvases: &mut HashMap<Gid, Canvas>) -> Result<Point, xous::Error> {
let menu_canvas = canvases.get_mut(&self.menu).expect("couldn't find menu canvas"); let menu_canvas = canvases.get_mut(&self.menu).expect("couldn't find menu canvas");
let orig_rect = menu_canvas.clip_rect(); let orig_rect = menu_canvas.clip_rect();
@ -243,7 +244,7 @@ impl LayoutApi for MenuLayout {
fn get_content_canvas(&self) -> Gid { fn get_content_canvas(&self) -> Gid {
self.menu self.menu
} }
fn set_visibility_state(&mut self, onscreen: bool, canvases: &mut FnvIndexMap<Gid, Canvas, {crate::MAX_CANVASES}>) { fn set_visibility_state(&mut self, onscreen: bool, canvases: &mut HashMap<Gid, Canvas>) {
log::debug!("menu entering set_visibilty_state, self.visible {}, onscreen {}", self.visible, onscreen); log::debug!("menu entering set_visibilty_state, self.visible {}, onscreen {}", self.visible, onscreen);
if onscreen == self.visible { if onscreen == self.visible {
// nothing to do // nothing to do
@ -281,7 +282,7 @@ pub(crate) struct ModalLayout {
modal_y_max: i16, modal_y_max: i16,
} }
impl ModalLayout { impl ModalLayout {
pub fn init(gfx: &graphics_server::Gfx, trng: &trng::Trng, base_trust: u8, canvases: &mut FnvIndexMap<Gid, Canvas, {crate::MAX_CANVASES}>) -> Result<ModalLayout, xous::Error> { pub fn init(gfx: &graphics_server::Gfx, trng: &trng::Trng, base_trust: u8, canvases: &mut HashMap<Gid, Canvas>) -> Result<ModalLayout, xous::Error> {
let screensize = gfx.screen_size().expect("Couldn't get screen size"); let screensize = gfx.screen_size().expect("Couldn't get screen size");
// get the height of various text regions to compute the layout // get the height of various text regions to compute the layout
let height: i16 = gfx.glyph_height_hint(GlyphStyle::Regular).expect("couldn't get glyph height") as i16; let height: i16 = gfx.glyph_height_hint(GlyphStyle::Regular).expect("couldn't get glyph height") as i16;
@ -299,7 +300,7 @@ impl ModalLayout {
Rectangle::new_coords(MODAL_X_PAD, MODAL_Y_PAD, screensize.x - MODAL_X_PAD, crate::api::MODAL_Y_MAX), Rectangle::new_coords(MODAL_X_PAD, MODAL_Y_PAD, screensize.x - MODAL_X_PAD, crate::api::MODAL_Y_MAX),
checked_base_trust, &trng, None checked_base_trust, &trng, None
).expect("couldn't create modal canvas"); ).expect("couldn't create modal canvas");
canvases.insert(modal_canvas.gid(), modal_canvas).expect("can't store modal canvas"); canvases.insert(modal_canvas.gid(), modal_canvas);
Ok(ModalLayout { Ok(ModalLayout {
modal: modal_canvas.gid(), modal: modal_canvas.gid(),
@ -317,14 +318,14 @@ impl LayoutApi for ModalLayout {
fn behavior(&self) -> LayoutBehavior { fn behavior(&self) -> LayoutBehavior {
LayoutBehavior::Alert LayoutBehavior::Alert
} }
fn clear(&self, gfx: &graphics_server::Gfx, canvases: &mut FnvIndexMap<Gid, Canvas, {crate::MAX_CANVASES}>) -> Result<(), xous::Error> { fn clear(&self, gfx: &graphics_server::Gfx, canvases: &mut HashMap<Gid, Canvas>) -> Result<(), xous::Error> {
let modal_canvas = canvases.get(&self.modal).expect("couldn't find modal canvas"); let modal_canvas = canvases.get(&self.modal).expect("couldn't find modal canvas");
let mut rect = modal_canvas.clip_rect(); let mut rect = modal_canvas.clip_rect();
rect.style = DrawStyle {fill_color: Some(PixelColor::Light), stroke_color: None, stroke_width: 0,}; rect.style = DrawStyle {fill_color: Some(PixelColor::Light), stroke_color: None, stroke_width: 0,};
gfx.draw_rectangle(rect) gfx.draw_rectangle(rect)
} }
fn resize_height(&mut self, _gfx: &graphics_server::Gfx, new_height: i16, _status_canvas: &Canvas, canvases: &mut FnvIndexMap<Gid, Canvas, {crate::MAX_CANVASES}>) -> Result<Point, xous::Error> { fn resize_height(&mut self, _gfx: &graphics_server::Gfx, new_height: i16, _status_canvas: &Canvas, canvases: &mut HashMap<Gid, Canvas>) -> Result<Point, xous::Error> {
let modal_canvas = canvases.get_mut(&self.modal).expect("couldn't find modal canvas"); let modal_canvas = canvases.get_mut(&self.modal).expect("couldn't find modal canvas");
let orig_rect = modal_canvas.clip_rect(); let orig_rect = modal_canvas.clip_rect();
@ -345,7 +346,7 @@ impl LayoutApi for ModalLayout {
fn get_content_canvas(&self) -> Gid { fn get_content_canvas(&self) -> Gid {
self.modal self.modal
} }
fn set_visibility_state(&mut self, onscreen: bool, canvases: &mut FnvIndexMap<Gid, Canvas, {crate::MAX_CANVASES}>) { fn set_visibility_state(&mut self, onscreen: bool, canvases: &mut HashMap<Gid, Canvas>) {
log::debug!("modal box entering set_visibilty_state, self.visible {}, onscreen {}", self.visible, onscreen); log::debug!("modal box entering set_visibilty_state, self.visible {}, onscreen {}", self.visible, onscreen);
if onscreen == self.visible { if onscreen == self.visible {
// nothing to do // nothing to do

View file

@ -16,7 +16,7 @@ use ime_plugin_api::{ImeFrontEndApi, ImefDescriptor};
use log::info; use log::info;
use heapless::FnvIndexMap; use std::collections::HashMap;
use num_traits::*; use num_traits::*;
use xous_ipc::{Buffer, String}; use xous_ipc::{Buffer, String};
@ -40,16 +40,16 @@ pub(crate) enum LayoutBehavior {
#[enum_dispatch] #[enum_dispatch]
pub(crate) trait LayoutApi { pub(crate) trait LayoutApi {
fn clear(&self, gfx: &graphics_server::Gfx, canvases: &mut FnvIndexMap<Gid, Canvas, {crate::MAX_CANVASES}>) -> Result<(), xous::Error>; fn clear(&self, gfx: &graphics_server::Gfx, canvases: &mut HashMap<Gid, Canvas>) -> Result<(), xous::Error>;
// for Chats, this resizes the height of the input area; for menus, it resizes the overall height // for Chats, this resizes the height of the input area; for menus, it resizes the overall height
fn resize_height(&mut self, gfx: &graphics_server::Gfx, new_height: i16, status_canvas: &Canvas, canvases: &mut FnvIndexMap<Gid, Canvas, {crate::MAX_CANVASES}>) -> Result<Point, xous::Error>; fn resize_height(&mut self, gfx: &graphics_server::Gfx, new_height: i16, status_canvas: &Canvas, canvases: &mut HashMap<Gid, Canvas>) -> Result<Point, xous::Error>;
fn get_input_canvas(&self) -> Option<Gid> { None } fn get_input_canvas(&self) -> Option<Gid> { None }
fn get_prediction_canvas(&self) -> Option<Gid> { None } fn get_prediction_canvas(&self) -> Option<Gid> { None }
fn get_content_canvas(&self) -> Gid; // layouts always have a content canvas fn get_content_canvas(&self) -> Gid; // layouts always have a content canvas
// when the argument is true, the context is moved "onscreen" by moving the canvases into the screen clipping rectangle // when the argument is true, the context is moved "onscreen" by moving the canvases into the screen clipping rectangle
// when false, the context is moved "offscreen" by moving the canvases outside the screen clipping rectangle // when false, the context is moved "offscreen" by moving the canvases outside the screen clipping rectangle
// note that this visibility state is an independent variable from the trust level draw-ability // note that this visibility state is an independent variable from the trust level draw-ability
fn set_visibility_state(&mut self, onscreen: bool, canvases: &mut FnvIndexMap<Gid, Canvas, {crate::MAX_CANVASES}>); fn set_visibility_state(&mut self, onscreen: bool, canvases: &mut HashMap<Gid, Canvas>);
fn behavior(&self) -> LayoutBehavior; fn behavior(&self) -> LayoutBehavior;
} }
@ -147,7 +147,7 @@ impl ContextManager {
gfx: &graphics_server::Gfx, gfx: &graphics_server::Gfx,
trng: &trng::Trng, trng: &trng::Trng,
status_canvas: &Canvas, status_canvas: &Canvas,
canvases: &mut FnvIndexMap<Gid, Canvas, MAX_CANVASES>, canvases: &mut HashMap<Gid, Canvas>,
trust_level: u8, trust_level: u8,
registration: UxRegistration) registration: UxRegistration)
-> Option<[u32; 4]> { -> Option<[u32; 4]> {
@ -277,7 +277,7 @@ impl ContextManager {
gam_token: [u32; 4], gam_token: [u32; 4],
new_height: i16, new_height: i16,
status_canvas: &Canvas, status_canvas: &Canvas,
canvases: &mut FnvIndexMap<Gid, Canvas, MAX_CANVASES>) -> Option<Point> { canvases: &mut HashMap<Gid, Canvas>) -> Option<Point> {
for maybe_context in self.contexts.iter_mut() { for maybe_context in self.contexts.iter_mut() {
if let Some(context) = maybe_context { if let Some(context) = maybe_context {
@ -295,7 +295,7 @@ impl ContextManager {
app_token: [u32; 4], app_token: [u32; 4],
new_height: i16, new_height: i16,
status_canvas: &Canvas, status_canvas: &Canvas,
canvases: &mut FnvIndexMap<Gid, Canvas, MAX_CANVASES>) -> Option<Point> { canvases: &mut HashMap<Gid, Canvas>) -> Option<Point> {
for maybe_context in self.contexts.iter_mut() { for maybe_context in self.contexts.iter_mut() {
if let Some(context) = maybe_context { if let Some(context) = maybe_context {
@ -329,7 +329,7 @@ impl ContextManager {
} }
pub(crate) fn activate(&mut self, pub(crate) fn activate(&mut self,
gfx: &graphics_server::Gfx, gfx: &graphics_server::Gfx,
canvases: &mut FnvIndexMap<Gid, Canvas, MAX_CANVASES>, canvases: &mut HashMap<Gid, Canvas>,
token: [u32; 4], token: [u32; 4],
clear: bool, clear: bool,
) { ) {
@ -438,7 +438,7 @@ impl ContextManager {
} }
pub(crate) fn revert_focus(&mut self, pub(crate) fn revert_focus(&mut self,
gfx: &graphics_server::Gfx, gfx: &graphics_server::Gfx,
canvases: &mut FnvIndexMap<Gid, Canvas, MAX_CANVASES>, canvases: &mut HashMap<Gid, Canvas>,
) { ) {
if let Some(last) = self.last_context { if let Some(last) = self.last_context {
self.activate(gfx, canvases, last, false); self.activate(gfx, canvases, last, false);
@ -494,7 +494,7 @@ impl ContextManager {
} }
pub(crate) fn key_event(&mut self, keys: [char; 4], pub(crate) fn key_event(&mut self, keys: [char; 4],
gfx: &graphics_server::Gfx, gfx: &graphics_server::Gfx,
canvases: &mut FnvIndexMap<Gid, Canvas, MAX_CANVASES>, canvases: &mut HashMap<Gid, Canvas>,
) { ) {
// only pop up the menu if the primary key hit is the menu key (search just the first entry of keys); reject multi-key hits // only pop up the menu if the primary key hit is the menu key (search just the first entry of keys); reject multi-key hits
// only pop up the menu if it isn't already popped up // only pop up the menu if it isn't already popped up
@ -559,7 +559,7 @@ impl ContextManager {
pub(crate) fn raise_menu(&mut self, pub(crate) fn raise_menu(&mut self,
name: &str, name: &str,
gfx: &graphics_server::Gfx, gfx: &graphics_server::Gfx,
canvases: &mut FnvIndexMap<Gid, Canvas, MAX_CANVASES>, canvases: &mut HashMap<Gid, Canvas>,
) { ) {
log::debug!("looking for menu {}", name); log::debug!("looking for menu {}", name);
if let Some(token) = self.find_app_token_by_name(name) { if let Some(token) = self.find_app_token_by_name(name) {
@ -607,7 +607,7 @@ fn xmain() -> ! {
let mut context_mgr = ContextManager::new(&xns); let mut context_mgr = ContextManager::new(&xns);
// a map of canvases accessable by Gid // a map of canvases accessable by Gid
let mut canvases: FnvIndexMap<Gid, Canvas, MAX_CANVASES> = FnvIndexMap::new(); let mut canvases: HashMap<Gid, Canvas> = HashMap::new();
let screensize = gfx.screen_size().expect("Couldn't get screen size"); let screensize = gfx.screen_size().expect("Couldn't get screen size");
let small_height: i16 = gfx.glyph_height_hint(GlyphStyle::Small).expect("couldn't get glyph height") as i16; let small_height: i16 = gfx.glyph_height_hint(GlyphStyle::Small).expect("couldn't get glyph height") as i16;
@ -617,7 +617,7 @@ fn xmain() -> ! {
Rectangle::new_coords(0, 0, screensize.x, small_height * 2), Rectangle::new_coords(0, 0, screensize.x, small_height * 2),
255, &trng, None 255, &trng, None
).expect("couldn't create status canvas"); ).expect("couldn't create status canvas");
canvases.insert(status_canvas.gid(), status_canvas).expect("can't store status canvus"); canvases.insert(status_canvas.gid(), status_canvas);
canvases = recompute_canvases(&canvases, Rectangle::new(Point::new(0, 0), screensize)); canvases = recompute_canvases(&canvases, Rectangle::new(Point::new(0, 0), screensize));
// initialize the status bar -- this needs to start late, after the IMEF and most other things are initialized // initialize the status bar -- this needs to start late, after the IMEF and most other things are initialized

View file

@ -7,8 +7,6 @@ version = "0.1.0"
[dependencies] [dependencies]
blitstr-ref = {path = "../../imports/blitstr-ref"} blitstr-ref = {path = "../../imports/blitstr-ref"}
hash32 = "0.2"
hash32-derive = "0.1.0"
keyboard = {path = "../keyboard"} keyboard = {path = "../keyboard"}
log = "0.4" log = "0.4"
log-server = {path = "../log-server"} log-server = {path = "../log-server"}

View file

@ -24,7 +24,7 @@ pub mod text;
pub use text::*; pub use text::*;
use hash32::{Hash, Hasher}; use std::hash::{Hash, Hasher};
//////////////// IPC APIs //////////////// IPC APIs
#[derive(Debug, Copy, Clone, PartialEq, Eq, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] #[derive(Debug, Copy, Clone, PartialEq, Eq, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
@ -36,7 +36,7 @@ impl Gid {
pub fn new(id: [u32; 4]) -> Self { Gid{gid: id} } pub fn new(id: [u32; 4]) -> Self { Gid{gid: id} }
pub fn gid(&self) -> [u32; 4] { self.gid } pub fn gid(&self) -> [u32; 4] { self.gid }
} }
impl hash32::Hash for Gid { impl Hash for Gid {
fn hash<H>(&self, state: &mut H) fn hash<H>(&self, state: &mut H)
where where
H: Hasher, H: Hasher,

View file

@ -6,7 +6,6 @@ name = "ime-plugin-shell"
version = "0.1.0" version = "0.1.0"
[dependencies] [dependencies]
heapless = "0.5.6"
ime-plugin-api = {path = "../ime-plugin-api"} ime-plugin-api = {path = "../ime-plugin-api"}
log = "0.4" log = "0.4"
log-server = {path = "../log-server"} log-server = {path = "../log-server"}

View file

@ -4,8 +4,6 @@
use ime_plugin_api::*; use ime_plugin_api::*;
use log::{error, info}; use log::{error, info};
use heapless::spsc::Queue;
use heapless::consts::*;
use xous_ipc::{String, Buffer}; use xous_ipc::{String, Buffer};
use num_traits::FromPrimitive; use num_traits::FromPrimitive;
@ -21,20 +19,20 @@ fn xmain() -> ! {
let ime_sh_sid = xns.register_name(ime_plugin_shell::SERVER_NAME_IME_PLUGIN_SHELL, Some(1)).expect("can't register server"); let ime_sh_sid = xns.register_name(ime_plugin_shell::SERVER_NAME_IME_PLUGIN_SHELL, Some(1)).expect("can't register server");
log::trace!("registered with NS -- {:?}", ime_sh_sid); log::trace!("registered with NS -- {:?}", ime_sh_sid);
let mut history: Queue<String<64>, U4> = Queue::new(); // this has 2^4 elements = 16??? or does it just have 4 elements. let mut history: Vec<String<64>> = Vec::new();
let history_max = 4; let history_max = 4;
if false { // loads defaults into the predictor array to test things if false { // loads defaults into the predictor array to test things
use core::fmt::Write as CoreWriter; use core::fmt::Write as CoreWriter;
let mut test1: String::<64> = String::new(); let mut test1: String::<64> = String::new();
write!(test1, "This〰should overflow the box").unwrap(); write!(test1, "This〰should overflow the box").unwrap();
history.enqueue(test1).unwrap(); history.push(test1);
let mut test2: String::<64> = String::new(); let mut test2: String::<64> = String::new();
write!(test2, "Another string too long").unwrap(); write!(test2, "Another string too long").unwrap();
history.enqueue(test2).unwrap(); history.push(test2);
let mut test3: String::<64> = String::new(); let mut test3: String::<64> = String::new();
write!(test3, "未雨绸缪").unwrap(); write!(test3, "未雨绸缪").unwrap();
history.enqueue(test3).unwrap(); history.push(test3);
} }
let mytriggers = PredictionTriggers { let mytriggers = PredictionTriggers {
@ -61,9 +59,9 @@ fn xmain() -> ! {
write!(local_s, "{}", s.as_str()).expect("overflowed history variable"); write!(local_s, "{}", s.as_str()).expect("overflowed history variable");
log::trace!("storing history value | {}", s.as_str()); log::trace!("storing history value | {}", s.as_str());
if history.len() == history_max { if history.len() == history_max {
history.dequeue().expect("couldn't dequeue history"); history.remove(0);
} }
history.enqueue(local_s).expect("couldn't store history"); history.push(local_s);
log::trace!("history has length {}", history.len()); log::trace!("history has length {}", history.len());
} }
Some(Opcode::Prediction) => { Some(Opcode::Prediction) => {
@ -108,15 +106,9 @@ fn xmain() -> ! {
} }
Some(Opcode::Unpick) => { Some(Opcode::Unpick) => {
if history.len() == 1 { if history.len() == 1 {
history.dequeue().expect("couldn't dequeue in Unpick (1)"); history.remove(0);
} else if history.len() > 1 { } else if history.len() > 1 {
// rotate everything around except the last entry let _ = history.pop(); // discard the last entry
for _ in 0 .. history.len() - 1 {
let s = history.dequeue().expect("couldn't dequee in Unpick (>1)");
history.enqueue(s).expect("couldn't enqueue in Unpick");
}
// discard the last entry
history.dequeue().expect("couldn't dequeue in Unpick (>1 last)");
} }
// in case of 0 length, do nothing // in case of 0 length, do nothing
} }

View file

@ -15,8 +15,6 @@ xous-names = {path = "../xous-names"}
llio = {path = "../llio"} llio = {path = "../llio"}
susres = {path = "../susres"} susres = {path = "../susres"}
heapless = "0.7"
num-derive = {version = "0.3", default-features = false} num-derive = {version = "0.3", default-features = false}
num-traits = {version = "0.2", default-features = false} num-traits = {version = "0.2", default-features = false}
rkyv = {version = "0.4.3", default-features = false, features = ["const_generics"]} rkyv = {version = "0.4.3", default-features = false, features = ["const_generics"]}

View file

@ -4,8 +4,6 @@
mod api; mod api;
use api::*; use api::*;
use heapless::Vec;
use log::info; use log::info;
use num_traits::*; use num_traits::*;
@ -170,8 +168,6 @@ mod implementation {
use num_traits::ToPrimitive; use num_traits::ToPrimitive;
use susres::{RegManager, RegOrField, SuspendResume}; use susres::{RegManager, RegOrField, SuspendResume};
use heapless::Vec;
/// note: the code is structured to use at most 16 rows or 16 cols /// note: the code is structured to use at most 16 rows or 16 cols
const KBD_ROWS: usize = 9; const KBD_ROWS: usize = 9;
const KBD_COLS: usize = 10; const KBD_COLS: usize = 10;
@ -411,7 +407,7 @@ mod implementation {
krs krs
} }
pub fn track_chord(&mut self, keyups: Option<Vec<RowCol, 16>>, keydowns: Option<Vec<RowCol, 16>>) -> Vec<char, 4> { pub fn track_chord(&mut self, keyups: Option<Vec<RowCol>>, keydowns: Option<Vec<RowCol>>) -> Vec<char> {
/* /*
Chording algorithm: Chording algorithm:
@ -430,7 +426,7 @@ mod implementation {
} }
} }
log::trace!("self.chord: {:?}", self.chord); log::trace!("self.chord: {:?}", self.chord);
let mut keystates: Vec<char, 4> = Vec::new(); let mut keystates: Vec<char> = Vec::new();
let now = self.ticktimer.elapsed_ms(); let now = self.ticktimer.elapsed_ms();
if was_idle && self.chord_active != 0 { if was_idle && self.chord_active != 0 {
@ -501,31 +497,31 @@ mod implementation {
_ => None, _ => None,
}; };
if let Some(key) = keychar { if let Some(key) = keychar {
keystates.push(key).unwrap(); keystates.push(key);
} }
let up = self.chord[6][4]; let up = self.chord[6][4];
if up { keystates.push('↑').unwrap(); } if up { keystates.push('↑'); }
let left = self.chord[8][3]; let left = self.chord[8][3];
if left { keystates.push('←').unwrap(); } if left { keystates.push('←'); }
let right = self.chord[3][6]; let right = self.chord[3][6];
if right { keystates.push('→').unwrap(); } if right { keystates.push('→'); }
let down = self.chord[8][2]; let down = self.chord[8][2];
if down { keystates.push('↓').unwrap(); } if down { keystates.push('↓'); }
let center = self.chord[5][2]; let center = self.chord[5][2];
if center { keystates.push('∴').unwrap(); } if center { keystates.push('∴'); }
let space = self.chord[2][3]; let space = self.chord[2][3];
if space { keystates.push(' ').unwrap(); } if space { keystates.push(' '); }
let esc = self.chord[8][6]; let esc = self.chord[8][6];
let bs: char = 0x8_u8.into(); // back space let bs: char = 0x8_u8.into(); // back space
if esc { keystates.push(bs).unwrap(); } if esc { keystates.push(bs); }
let func = self.chord[7][5]; let func = self.chord[7][5];
let cr: char = 0xd_u8.into(); // carriage return let cr: char = 0xd_u8.into(); // carriage return
if func { keystates.push(cr).unwrap(); } if func { keystates.push(cr); }
log::trace!("up {}, left {}, right {}, down, {}, center, {}, space {}, esc {}, func {}", log::trace!("up {}, left {}, right {}, down, {}, center, {}, space {}, esc {}, func {}",
up, left, right, down, center, space, esc, func); up, left, right, down, center, space, esc, func);
@ -547,7 +543,7 @@ mod implementation {
keystates keystates
} }
pub fn track_keys(&mut self, keyups: Option<Vec<RowCol, 16>>, keydowns: Option<Vec<RowCol, 16>>) -> Vec<char, 4> { pub fn track_keys(&mut self, keyups: Option<Vec<RowCol>>, keydowns: Option<Vec<RowCol>>) -> Vec<char> {
/* /*
"conventional" keyboard algorithm. The goals of this are to differentiate "conventional" keyboard algorithm. The goals of this are to differentiate
the cases of "shift", "alt", and "hold". the cases of "shift", "alt", and "hold".
@ -558,7 +554,7 @@ mod implementation {
then for all others, we note the down time, and compare it to the current time then for all others, we note the down time, and compare it to the current time
to determine if a "hold" modifier applies to determine if a "hold" modifier applies
*/ */
let mut ks: Vec<char, 4> = Vec::new(); let mut ks: Vec<char> = Vec::new();
// first check for shift and alt keys // first check for shift and alt keys
if let Some(kds) = &keydowns { if let Some(kds) = &keydowns {
@ -594,9 +590,9 @@ mod implementation {
} }
} }
} }
let keyups_noshift: Option<Vec<RowCol, 16>> = let keyups_noshift: Option<Vec<RowCol>> =
if let Some(kus) = &keyups { if let Some(kus) = &keyups {
let mut ku_ns: Vec<RowCol, 16> = Vec::new(); let mut ku_ns: Vec<RowCol> = Vec::new();
for &rc in kus.iter() { for &rc in kus.iter() {
match self.map { match self.map {
KeyMap::Azerty => { KeyMap::Azerty => {
@ -611,7 +607,7 @@ mod implementation {
} }
self.shift_down = false; self.shift_down = false;
} else { } else {
ku_ns.push(RowCol{r: rc.r as _, c: rc.c as _}).unwrap(); ku_ns.push(RowCol{r: rc.r as _, c: rc.c as _});
} }
}, },
_ => { // the rest just have one color of shift _ => { // the rest just have one color of shift
@ -625,7 +621,7 @@ mod implementation {
self.shift_down = false; self.shift_down = false;
} else { } else {
//info!("adding non-shift entry {:?}", rc); //info!("adding non-shift entry {:?}", rc);
ku_ns.push(RowCol{r: rc.r as _, c: rc.c as _}).unwrap(); ku_ns.push(RowCol{r: rc.r as _, c: rc.c as _});
} }
} }
} }
@ -663,8 +659,6 @@ mod implementation {
hold = false; hold = false;
} }
fn report_ok(k: char) -> Result<(), ()> { log::error!("ran out of space saving char: {}", k); Ok(()) }
if let Some(kus) = &keyups_noshift { if let Some(kus) = &keyups_noshift {
for &rc in kus.iter() { for &rc in kus.iter() {
// info!("interpreting keyups_noshift entry {:?}", rc); // info!("interpreting keyups_noshift entry {:?}", rc);
@ -688,38 +682,38 @@ mod implementation {
KeyMap::Azerty => { KeyMap::Azerty => {
if self.shift_down || self.shift_up { if self.shift_down || self.shift_up {
if let Some(shiftcode) = code.shift { if let Some(shiftcode) = code.shift {
ks.push(shiftcode).or_else(report_ok).ok(); ks.push(shiftcode);
} else if let Some(keycode) = code.key { } else if let Some(keycode) = code.key {
ks.push(keycode).or_else(report_ok).ok(); ks.push(keycode);
} }
self.shift_down = false; self.shift_down = false;
self.shift_up = false; self.shift_up = false;
} else if self.alt_down || self.alt_up { } else if self.alt_down || self.alt_up {
if let Some(altcode) = code.alt { if let Some(altcode) = code.alt {
ks.push(altcode).or_else(report_ok).ok(); ks.push(altcode);
} else if let Some(shiftcode) = code.shift { } else if let Some(shiftcode) = code.shift {
ks.push(shiftcode).or_else(report_ok).ok(); ks.push(shiftcode);
} else if let Some(keycode) = code.key { } else if let Some(keycode) = code.key {
ks.push(keycode).or_else(report_ok).ok(); ks.push(keycode);
} }
self.alt_down = false; self.alt_down = false;
self.alt_up = false; self.alt_up = false;
} else if hold { } else if hold {
if let Some(holdcode) = code.hold { if let Some(holdcode) = code.hold {
ks.push(holdcode).or_else(report_ok).ok(); ks.push(holdcode);
} }
} else { } else {
if let Some(keycode) = code.key { if let Some(keycode) = code.key {
ks.push(keycode).or_else(report_ok).ok(); ks.push(keycode);
} }
} }
}, },
_ => { _ => {
if self.shift_down || self.alt_down || self.shift_up || self.alt_up { if self.shift_down || self.alt_down || self.shift_up || self.alt_up {
if let Some(shiftcode) = code.shift { if let Some(shiftcode) = code.shift {
ks.push(shiftcode).or_else(report_ok).ok(); ks.push(shiftcode);
} else if let Some(keycode) = code.key { } else if let Some(keycode) = code.key {
ks.push(keycode).or_else(report_ok).ok(); ks.push(keycode);
} }
self.shift_down = false; self.shift_down = false;
self.alt_down = false; self.alt_down = false;
@ -727,12 +721,12 @@ mod implementation {
self.alt_up = false; self.alt_up = false;
} else if hold { } else if hold {
if let Some(holdcode) = code.hold { if let Some(holdcode) = code.hold {
ks.push(holdcode).or_else(report_ok).ok(); ks.push(holdcode);
} }
} else { } else {
if let Some(keycode) = code.key { if let Some(keycode) = code.key {
// info!("appeding normal key '{}'", keycode); // info!("appeding normal key '{}'", keycode);
ks.push(keycode).or_else(report_ok).ok(); ks.push(keycode);
} }
} }
} }
@ -744,7 +738,7 @@ mod implementation {
if hold && ((now - self.rate_timestamp) >= self.rate as u64) && self.repeating_key.is_some() { if hold && ((now - self.rate_timestamp) >= self.rate as u64) && self.repeating_key.is_some() {
self.rate_timestamp = now; self.rate_timestamp = now;
if let Some(repeatkey) = self.repeating_key { if let Some(repeatkey) = self.repeating_key {
ks.push(repeatkey).or_else(report_ok).ok(); ks.push(repeatkey);
} }
} }
@ -756,7 +750,6 @@ mod implementation {
// a stub to try to avoid breaking hosted mode for as long as possible. // a stub to try to avoid breaking hosted mode for as long as possible.
#[cfg(not(any(target_os = "none", target_os = "xous")))] #[cfg(not(any(target_os = "none", target_os = "xous")))]
mod implementation { mod implementation {
use heapless::Vec;
use crate::api::*; use crate::api::*;
//use crate::{map_dvorak, map_qwerty}; //use crate::{map_dvorak, map_qwerty};
@ -793,11 +786,11 @@ mod implementation {
KeyRawStates::new() KeyRawStates::new()
} }
pub fn track_chord(&mut self, _keyups: Option<Vec<RowCol, 16>>, _keydowns: Option<Vec<RowCol, 16>>) -> Vec<char, 4> { pub fn track_chord(&mut self, _keyups: Option<Vec<RowCol>>, _keydowns: Option<Vec<RowCol>>) -> Vec<char> {
Vec::new() Vec::new()
} }
pub fn track_keys(&mut self, _keyups: Option<Vec<RowCol, 16>>, _keydowns: Option<Vec<RowCol, 16>>) -> Vec<char, 4> { pub fn track_keys(&mut self, _keyups: Option<Vec<RowCol>>, _keydowns: Option<Vec<RowCol>>) -> Vec<char> {
Vec::new() Vec::new()
} }
@ -956,6 +949,8 @@ fn xmain() -> ! {
// send rawstates on to rawstate listeners // send rawstates on to rawstate listeners
send_rawstates(&mut raw_conns, &rawstates); send_rawstates(&mut raw_conns, &rawstates);
///// TODO: the comment below predates the addition of libstd to Xous. We need to fix this still,
///// for now we have just refactored out the heapless crate.
// GROSS: we copy our IPC-compatible RowColVec type into a heapless::Vec for further processing // GROSS: we copy our IPC-compatible RowColVec type into a heapless::Vec for further processing
// this code can probably be cleaned up and improved quite a bit to reduce CPU time. // this code can probably be cleaned up and improved quite a bit to reduce CPU time.
// We don't use heapless::Vec for the IPC because we can't serialize the object with a trait natively // We don't use heapless::Vec for the IPC because we can't serialize the object with a trait natively
@ -965,16 +960,16 @@ fn xmain() -> ! {
// and push(), len() etc. which doesn't really make sense to re-implement. But, maybe someone much // and push(), len() etc. which doesn't really make sense to re-implement. But, maybe someone much
// more clever than I could do extend RowColVec to have these feature and get rid of this ugly copy // more clever than I could do extend RowColVec to have these feature and get rid of this ugly copy
// step and make the rest of this routine operate natively on RowColVec types.... // step and make the rest of this routine operate natively on RowColVec types....
let mut keyups_core: Vec<RowCol, 16> = Vec::new(); let mut keyups_core: Vec<RowCol> = Vec::new();
let mut keydowns_core: Vec<RowCol, 16> = Vec::new(); let mut keydowns_core: Vec<RowCol> = Vec::new();
for i in 0..rawstates.keyups.len() { for i in 0..rawstates.keyups.len() {
if let Some(rc) = rawstates.keyups.get(i) { if let Some(rc) = rawstates.keyups.get(i) {
keyups_core.push(rc).unwrap(); keyups_core.push(rc);
} }
} }
for i in 0..rawstates.keydowns.len() { for i in 0..rawstates.keydowns.len() {
if let Some(rc) = rawstates.keydowns.get(i) { if let Some(rc) = rawstates.keydowns.get(i) {
keydowns_core.push(rc).unwrap(); keydowns_core.push(rc);
} }
} }
let keyups = if keyups_core.len() > 0 { let keyups = if keyups_core.len() > 0 {
@ -990,7 +985,7 @@ fn xmain() -> ! {
// interpret scancodes // interpret scancodes
// the track_* functions track the keyup/keydowns to modify keys with shift, hold, and chord state // the track_* functions track the keyup/keydowns to modify keys with shift, hold, and chord state
let kc: Vec<char, 4> = match kbd.get_map() { let kc: Vec<char> = match kbd.get_map() {
KeyMap::Braille => { KeyMap::Braille => {
kbd.track_chord(keyups, keydowns) kbd.track_chord(keyups, keydowns)
}, },

View file

@ -18,8 +18,6 @@ num-derive = {version = "0.3", default-features = false}
num-traits = {version = "0.2", default-features = false} num-traits = {version = "0.2", default-features = false}
rkyv = {version = "0.4.3", default-features = false, features = ["const_generics"]} rkyv = {version = "0.4.3", default-features = false, features = ["const_generics"]}
heapless = "0.7"
[target.'cfg(not(any(windows,unix)))'.dependencies] [target.'cfg(not(any(windows,unix)))'.dependencies]
utralib = {path = "../../utralib"} utralib = {path = "../../utralib"}

View file

@ -4,7 +4,6 @@ use utralib::*;
use num_traits::ToPrimitive; use num_traits::ToPrimitive;
use susres::{RegManager, RegOrField, SuspendResume}; use susres::{RegManager, RegOrField, SuspendResume};
use heapless::spsc::Queue;
#[derive(Eq, PartialEq)] #[derive(Eq, PartialEq)]
enum I2cState { enum I2cState {
@ -55,7 +54,7 @@ pub(crate) struct I2cStateMachine {
listener: Option<xous::SID>, listener: Option<xous::SID>,
error: bool, // set if the interrupt handler encountered some kind of error error: bool, // set if the interrupt handler encountered some kind of error
workqueue: Queue<I2cTransaction, 8>, workqueue: Vec<I2cTransaction>,
} }
impl I2cStateMachine { impl I2cStateMachine {
@ -82,7 +81,7 @@ impl I2cStateMachine {
listener: None, listener: None,
error: false, error: false,
workqueue: Queue::new(), workqueue: Vec::new(),
}; };
// disable interrupt, just in case it's enabled from e.g. a warm boot // disable interrupt, just in case it's enabled from e.g. a warm boot
@ -130,10 +129,8 @@ impl I2cStateMachine {
if self.workqueue.is_empty() && self.state == I2cState::Idle && self.listener == None { if self.workqueue.is_empty() && self.state == I2cState::Idle && self.listener == None {
self.checked_initiate(transaction) self.checked_initiate(transaction)
} else { } else {
match self.workqueue.enqueue(transaction) { self.workqueue.push(transaction);
Ok(_) => return I2cStatus::ResponseInProgress, I2cStatus::ResponseInProgress
_ => return I2cStatus::ResponseBusy,
}
} }
} }
@ -219,12 +216,13 @@ impl I2cStateMachine {
} else { } else {
log::trace!("completed with transaction, but no listener! {:?}", trans); log::trace!("completed with transaction, but no listener! {:?}", trans);
}; };
if let Some(work) = self.workqueue.dequeue() { if self.workqueue.len() > 0 {
let work = self.workqueue.remove(0);
if self.checked_initiate(work) != I2cStatus::ResponseInProgress { if self.checked_initiate(work) != I2cStatus::ResponseInProgress {
log::error!("Unable to initiate I2C transaction even though machine should be idle: {:?}.", work); log::error!("Unable to initiate I2C transaction even though machine should be idle: {:?}.", work);
log::error!("Probably, the I2C engine is going off the rails from here..."); log::error!("Probably, the I2C engine is going off the rails from here...");
} }
}; }
Ok(()) Ok(())
} }

View file

@ -31,7 +31,6 @@ engine-25519 = {path="../engine-25519"}
spinor = {path="../spinor"} spinor = {path="../spinor"}
root-keys = {path="../root-keys"} root-keys = {path="../root-keys"}
heapless = "0.7"
trng = {path = "../trng"} trng = {path = "../trng"}
num-derive = {version = "0.3", default-features = false} num-derive = {version = "0.3", default-features = false}

View file

@ -2,7 +2,7 @@ use xous::{MessageEnvelope};
use xous_ipc::String; use xous_ipc::String;
use core::fmt::Write; use core::fmt::Write;
use heapless::FnvIndexMap; use std::collections::HashMap;
/////////////////////////// Common items to all commands /////////////////////////// Common items to all commands
pub trait ShellCmdApi<'a> { pub trait ShellCmdApi<'a> {
// user implemented: // user implemented:
@ -44,7 +44,7 @@ pub struct CommonEnv {
com: com::Com, com: com::Com,
ticktimer: ticktimer_server::Ticktimer, ticktimer: ticktimer_server::Ticktimer,
gam: gam::Gam, gam: gam::Gam,
cb_registrations: heapless::FnvIndexMap::<u32, String::<256>, 8>, cb_registrations: HashMap::<u32, String::<256>>,
trng: Trng, trng: Trng,
xns: xous_names::XousNames, xns: xous_names::XousNames,
} }
@ -58,7 +58,7 @@ impl CommonEnv {
break; break;
} }
} }
self.cb_registrations.insert(key, verb).unwrap(); self.cb_registrations.insert(key, verb);
key key
} }
} }
@ -132,7 +132,7 @@ impl CmdEnv {
com: com::Com::new(&xns).expect("could't connect to COM"), com: com::Com::new(&xns).expect("could't connect to COM"),
ticktimer: ticktimer, ticktimer: ticktimer,
gam: gam::Gam::new(&xns).expect("couldn't connect to GAM"), gam: gam::Gam::new(&xns).expect("couldn't connect to GAM"),
cb_registrations: FnvIndexMap::new(), cb_registrations: HashMap::new(),
trng: Trng::new(&xns).unwrap(), trng: Trng::new(&xns).unwrap(),
xns: xous_names::XousNames::new().unwrap(), xns: xous_names::XousNames::new().unwrap(),
}; };

View file

@ -38,8 +38,6 @@ use graphics_server::{Gid, Point, Rectangle, TextBounds, TextView, DrawStyle, Gl
use xous::MessageEnvelope; use xous::MessageEnvelope;
use xous_ipc::{String, Buffer}; use xous_ipc::{String, Buffer};
use heapless::spsc::Queue;
#[doc = include_str!("../README.md")] #[doc = include_str!("../README.md")]
mod cmds; mod cmds;
use cmds::*; use cmds::*;
@ -61,7 +59,8 @@ struct Repl {
msg: Option<MessageEnvelope>, msg: Option<MessageEnvelope>,
// record our input history // record our input history
history: Queue::<History, 16>, history: Vec::<History>,
history_len: usize,
content: Gid, content: Gid,
gam: gam::Gam, gam: gam::Gam,
@ -104,7 +103,8 @@ impl Repl{
Repl { Repl {
input: None, input: None,
msg: None, msg: None,
history: Queue::new(), history: Vec::new(),
history_len: 10,
content, content,
gam, gam,
screensize, screensize,
@ -133,10 +133,10 @@ impl Repl{
} }
fn circular_push(&mut self, item: History) { fn circular_push(&mut self, item: History) {
if self.history.len() == self.history.capacity() { if self.history.len() >= self.history_len {
self.history.dequeue().expect("couldn't dequeue historye"); self.history.remove(0);
} }
self.history.enqueue(item).expect("couldn't store input line"); self.history.push(item);
} }
/// update the loop, in response to various inputs /// update the loop, in response to various inputs

View file

@ -6,7 +6,6 @@ name = "ticktimer-server"
version = "0.1.0" version = "0.1.0"
[dependencies] [dependencies]
heapless = "0.7"
log = "0.4" log = "0.4"
log-server = {path = "../log-server"} log-server = {path = "../log-server"}
xous = {path = "../../xous-rs"} xous = {path = "../../xous-rs"}

View file

@ -5,7 +5,8 @@
mod api; mod api;
use heapless::binary_heap::{BinaryHeap, Min}; use std::collections::BinaryHeap;
use std::cmp::Reverse;
use log::{error, info}; use log::{error, info};
@ -449,14 +450,14 @@ use implementation::*;
fn recalculate_sleep( fn recalculate_sleep(
ticktimer: &mut XousTickTimer, ticktimer: &mut XousTickTimer,
sleep_heap: &mut BinaryHeap<SleepRequest, Min, 64>, sleep_heap: &mut BinaryHeap<Reverse<SleepRequest>>, // min-heap with Reverse
new: Option<SleepRequest>, new: Option<SleepRequest>,
) { ) {
// If there's a sleep request ongoing now, grab it. // If there's a sleep request ongoing now, grab it.
if let Some(current) = ticktimer.stop_interrupt() { if let Some(current) = ticktimer.stop_interrupt() {
#[cfg(feature = "debug-print")] #[cfg(feature = "debug-print")]
info!("Existing request was {:?}", current); info!("Existing request was {:?}", current);
sleep_heap.push(current).expect("couldn't push to heap") sleep_heap.push(Reverse(current));
} else { } else {
#[cfg(feature = "debug-print")] #[cfg(feature = "debug-print")]
info!("There was no existing request"); info!("There was no existing request");
@ -472,15 +473,14 @@ fn recalculate_sleep(
#[cfg(feature = "debug-print")] #[cfg(feature = "debug-print")]
info!("Modified, the request was: {:?}", request); info!("Modified, the request was: {:?}", request);
sleep_heap sleep_heap
.push(request) .push(Reverse(request));
.expect("couldn't push new sleep to heap");
} else { } else {
#[cfg(feature = "debug-print")] #[cfg(feature = "debug-print")]
info!("No new sleep request"); info!("No new sleep request");
} }
// If there are items in the sleep heap, take the next item that will expire. // If there are items in the sleep heap, take the next item that will expire.
if let Some(next_response) = sleep_heap.pop() { if let Some(Reverse(next_response)) = sleep_heap.pop() {
#[cfg(feature = "debug-print")] #[cfg(feature = "debug-print")]
info!( info!(
"scheduling a response at {} to {} (heap: {:?})", "scheduling a response at {} to {} (heap: {:?})",
@ -492,7 +492,7 @@ fn recalculate_sleep(
#[xous::xous_main] #[xous::xous_main]
fn xmain() -> ! { fn xmain() -> ! {
let mut sleep_heap: BinaryHeap<SleepRequest, Min, 64> = BinaryHeap::new(); let mut sleep_heap: BinaryHeap<Reverse<SleepRequest>> = BinaryHeap::new(); // Reverse wrapping makes this a min-heap
log_server::init_wait().unwrap(); log_server::init_wait().unwrap();
log::set_max_level(log::LevelFilter::Info); log::set_max_level(log::LevelFilter::Info);