2020-08-14 09:25:20 +00:00
#![ cfg_attr(target_os = " none " , no_std) ]
#![ cfg_attr(target_os = " none " , no_main) ]
2020-08-29 14:09:20 +00:00
mod api ;
2021-02-14 20:42:30 +00:00
mod backend ;
use backend ::XousDisplay ;
2020-10-30 02:22:03 +00:00
mod op ;
2020-08-14 09:25:20 +00:00
2020-10-11 19:23:15 +00:00
mod logo ;
2021-03-10 20:09:35 +00:00
mod poweron ;
2021-05-01 19:36:54 +00:00
mod sleep_note ;
2020-08-14 10:46:23 +00:00
2022-01-21 07:01:56 +00:00
use api ::* ;
2020-11-27 18:05:55 +00:00
2022-01-18 19:29:53 +00:00
mod blitstr2 ;
mod wordwrap ;
#[ macro_use ]
mod style_macros ;
2021-04-02 16:53:30 +00:00
use num_traits ::FromPrimitive ;
2021-08-16 14:52:06 +00:00
use xous ::{ msg_blocking_scalar_unpack , msg_scalar_unpack , MemoryRange } ;
2021-04-02 16:53:30 +00:00
use xous_ipc ::Buffer ;
2021-03-26 12:22:33 +00:00
2021-02-26 18:12:19 +00:00
mod fontmap ;
2021-08-03 09:22:10 +00:00
use api ::BulkRead ;
2021-02-26 18:12:19 +00:00
2022-01-20 10:30:13 +00:00
use crate ::wordwrap ::* ;
use core ::ops ::Add ;
2022-01-20 16:34:12 +00:00
#[ cfg(feature = " testing " ) ]
mod testing ;
2020-10-11 19:23:15 +00:00
fn draw_boot_logo ( display : & mut XousDisplay ) {
2021-09-15 17:00:22 +00:00
display . blit_screen ( & poweron ::LOGO_MAP ) ;
2020-08-29 14:09:20 +00:00
}
2021-08-02 10:11:48 +00:00
#[ cfg(any(target_os = " none " , target_os = " xous " )) ]
2021-08-02 20:58:34 +00:00
fn map_fonts ( ) -> MemoryRange {
2021-04-02 16:53:30 +00:00
log ::trace! ( " mapping fonts " ) ;
2021-02-26 18:12:19 +00:00
// this maps an extra page if the total length happens to fall on a 4096-byte boundary, but this is ok
// because the reserved area is much larger
2021-08-02 20:58:34 +00:00
let fontlen : u32 = ( ( fontmap ::FONT_TOTAL_LEN as u32 + 8 ) & 0xFFFF_F000 ) + 0x1000 ;
2021-08-16 14:52:06 +00:00
log ::trace! (
" requesting map of length 0x{:08x} at 0x{:08x} " ,
fontlen ,
fontmap ::FONT_BASE
) ;
2021-02-26 18:12:19 +00:00
let fontregion = xous ::syscall ::map_memory (
xous ::MemoryAddress ::new ( fontmap ::FONT_BASE ) ,
None ,
fontlen as usize ,
xous ::MemoryFlags ::R ,
2021-08-16 14:52:06 +00:00
)
. expect ( " couldn't map fonts " ) ;
log ::info! (
" font base at virtual 0x{:08x}, len of 0x{:08x} " ,
fontregion . as_ptr ( ) as usize ,
usize ::from ( fontregion . len ( ) )
) ;
log ::trace! (
" mapping regular font to 0x{:08x} " ,
fontregion . as_ptr ( ) as usize + fontmap ::REGULAR_OFFSET as usize
) ;
blitstr ::map_font ( blitstr ::GlyphData ::Emoji (
( fontregion . as_ptr ( ) as usize + fontmap ::EMOJI_OFFSET ) as usize ,
) ) ;
blitstr ::map_font ( blitstr ::GlyphData ::Hanzi (
( fontregion . as_ptr ( ) as usize + fontmap ::HANZI_OFFSET ) as usize ,
) ) ;
blitstr ::map_font ( blitstr ::GlyphData ::Regular (
( fontregion . as_ptr ( ) as usize + fontmap ::REGULAR_OFFSET ) as usize ,
) ) ;
blitstr ::map_font ( blitstr ::GlyphData ::Small (
( fontregion . as_ptr ( ) as usize + fontmap ::SMALL_OFFSET ) as usize ,
) ) ;
blitstr ::map_font ( blitstr ::GlyphData ::Bold (
( fontregion . as_ptr ( ) as usize + fontmap ::BOLD_OFFSET ) as usize ,
) ) ;
2021-08-02 20:58:34 +00:00
fontregion
2021-02-26 18:12:19 +00:00
}
2021-08-02 10:11:48 +00:00
#[ cfg(not(any(target_os = " none " , target_os = " xous " ))) ]
2021-08-02 20:58:34 +00:00
fn map_fonts ( ) -> MemoryRange {
2021-02-26 18:12:19 +00:00
// does nothing
2021-08-03 08:57:54 +00:00
let fontlen : u32 = ( ( fontmap ::FONT_TOTAL_LEN as u32 + 8 ) & 0xFFFF_F000 ) + 0x1000 ;
2021-08-16 14:52:06 +00:00
let fontregion = xous ::syscall ::map_memory ( None , None , fontlen as usize , xous ::MemoryFlags ::R )
. expect ( " couldn't map dummy memory for fonts " ) ;
2021-08-02 20:58:34 +00:00
fontregion
2021-02-26 18:12:19 +00:00
}
2020-08-29 14:09:20 +00:00
#[ xous::xous_main ]
fn xmain ( ) -> ! {
2020-10-30 13:27:06 +00:00
log_server ::init_wait ( ) . unwrap ( ) ;
2021-04-06 14:38:11 +00:00
log ::set_max_level ( log ::LevelFilter ::Info ) ;
2021-04-02 16:53:30 +00:00
log ::info! ( " my PID is {} " , xous ::process ::id ( ) ) ;
2020-10-30 13:27:06 +00:00
2021-03-29 18:13:23 +00:00
let xns = xous_names ::XousNames ::new ( ) . unwrap ( ) ;
2021-06-15 09:41:14 +00:00
// these connections should be established:
// - GAM
2021-08-02 20:58:34 +00:00
// - keyrom (for verifying font maps)
2021-08-16 14:52:06 +00:00
let sid = xns
. register_name ( api ::SERVER_NAME_GFX , Some ( 2 ) )
. expect ( " can't register server " ) ;
2021-03-05 17:10:18 +00:00
2020-08-29 14:09:20 +00:00
// Create a new monochrome simulator display.
let mut display = XousDisplay ::new ( ) ;
2022-01-18 19:29:53 +00:00
//let mut fb = display.native_buffer();
//let mut b2cursor = blitstr2::Cursor::new(0, 0, 16);
//blitstr2::paint_str(&mut fb, blitstr2::ClipRect::new(0, 0, 100, 100), &mut b2cursor, "test");
2020-08-29 14:09:20 +00:00
draw_boot_logo ( & mut display ) ;
2020-08-14 10:46:23 +00:00
2021-08-02 20:58:34 +00:00
let fontregion = map_fonts ( ) ;
2021-02-26 18:12:19 +00:00
2021-05-01 19:36:54 +00:00
let mut use_sleep_note = true ;
2021-02-28 17:49:22 +00:00
if false {
// leave this test case around
// for some reason, the top right quadrant draws an extra pixel inside the fill area
// when a fill color of "Light" is specified. However, if `None` fill is specified, it
// works correctly. This is really puzzling, because the test for filled drawing happens
// after the test for border drawing.
use api ::Point ;
let mut r = Rectangle ::new ( Point ::new ( 20 , 200 ) , Point ::new ( 151 , 301 ) ) ;
r . style = DrawStyle {
fill_color : Some ( PixelColor ::Light ) ,
stroke_color : Some ( PixelColor ::Dark ) ,
stroke_width : 1 ,
} ;
let rr = RoundedRectangle ::new ( r , 16 ) ;
2021-03-05 17:10:18 +00:00
op ::rounded_rectangle ( display . native_buffer ( ) , rr , None ) ;
2021-02-28 17:49:22 +00:00
}
2021-08-16 14:52:06 +00:00
let screen_clip = Rectangle ::new ( Point ::new ( 0 , 0 ) , display . screen_size ( ) ) ;
2021-05-02 08:10:51 +00:00
display . redraw ( ) ;
2021-05-01 17:38:44 +00:00
// register a suspend/resume listener
let sr_cid = xous ::connect ( sid ) . expect ( " couldn't create suspend callback connection " ) ;
2022-01-10 05:45:56 +00:00
let mut susres = susres ::Susres ::new ( None , & xns , Opcode ::SuspendResume as u32 , sr_cid )
2021-08-16 14:52:06 +00:00
. expect ( " couldn't create suspend/resume object " ) ;
2021-05-01 17:38:44 +00:00
2021-08-02 20:58:34 +00:00
let mut bulkread = BulkRead ::default ( ) ; // holding buffer for bulk reads; wastes ~8k when not in use, but saves a lot of copy/init for each iteration of the read
2022-01-20 16:34:12 +00:00
#[ cfg(feature = " testing " ) ]
testing ::tests ( ) ;
2020-08-14 10:46:23 +00:00
loop {
2021-04-02 16:53:30 +00:00
let mut msg = xous ::receive_message ( sid ) . unwrap ( ) ;
log ::trace! ( " Message: {:?} " , msg ) ;
match FromPrimitive ::from_usize ( msg . body . id ( ) ) {
2021-05-01 17:38:44 +00:00
Some ( Opcode ::SuspendResume ) = > xous ::msg_scalar_unpack! ( msg , token , _ , _ , _ , {
2021-05-01 19:36:54 +00:00
display . suspend ( use_sleep_note ) ;
2021-08-16 14:52:06 +00:00
susres
. suspend_until_resume ( token )
. expect ( " couldn't execute suspend/resume " ) ;
2021-05-01 19:36:54 +00:00
display . resume ( use_sleep_note ) ;
} ) ,
Some ( Opcode ::SetSleepNote ) = > xous ::msg_scalar_unpack! ( msg , set_use , _ , _ , _ , {
if set_use = = 0 {
use_sleep_note = false ;
} else {
use_sleep_note = true ;
}
2021-05-01 17:38:44 +00:00
} ) ,
2021-04-02 16:53:30 +00:00
Some ( Opcode ::DrawClipObject ) = > {
2021-08-16 14:52:06 +00:00
let buffer =
unsafe { Buffer ::from_memory_message ( msg . body . memory_message ( ) . unwrap ( ) ) } ;
2021-04-02 16:53:30 +00:00
let obj = buffer . to_original ::< ClipObject , _ > ( ) . unwrap ( ) ;
log ::trace! ( " DrawClipObject {:?} " , obj ) ;
match obj . obj {
ClipObjectType ::Line ( line ) = > {
2021-07-29 14:13:44 +00:00
op ::line ( display . native_buffer ( ) , line , Some ( obj . clip ) , false ) ;
2021-08-16 14:52:06 +00:00
}
2021-07-29 14:13:44 +00:00
ClipObjectType ::XorLine ( line ) = > {
op ::line ( display . native_buffer ( ) , line , Some ( obj . clip ) , true ) ;
2021-08-16 14:52:06 +00:00
}
2021-04-02 16:53:30 +00:00
ClipObjectType ::Circ ( circ ) = > {
op ::circle ( display . native_buffer ( ) , circ , Some ( obj . clip ) ) ;
2021-08-16 14:52:06 +00:00
}
2021-04-02 16:53:30 +00:00
ClipObjectType ::Rect ( rect ) = > {
op ::rectangle ( display . native_buffer ( ) , rect , Some ( obj . clip ) ) ;
2021-08-16 14:52:06 +00:00
}
2021-04-02 16:53:30 +00:00
ClipObjectType ::RoundRect ( rr ) = > {
op ::rounded_rectangle ( display . native_buffer ( ) , rr , Some ( obj . clip ) ) ;
2021-03-05 17:10:18 +00:00
}
2021-04-02 16:53:30 +00:00
}
}
Some ( Opcode ::DrawTextView ) = > {
2021-08-16 14:52:06 +00:00
let mut buffer = unsafe {
Buffer ::from_memory_message_mut ( msg . body . memory_message_mut ( ) . unwrap ( ) )
} ;
2021-04-02 16:53:30 +00:00
let mut tv = buffer . to_original ::< TextView , _ > ( ) . unwrap ( ) ;
2021-08-16 14:52:06 +00:00
if tv . clip_rect . is_none ( ) {
continue ;
} // if no clipping rectangle is specified, nothing to draw
2021-04-02 16:53:30 +00:00
2022-01-18 19:29:53 +00:00
// this is the clipping rectangle of the canvas in screen coordinates
let clip_rect = tv . clip_rect . unwrap ( ) ;
2022-01-20 16:34:12 +00:00
// this is the translation vector to and from screen space
let screen_offset : Point = tv . clip_rect . unwrap ( ) . tl ;
2022-01-20 10:30:13 +00:00
let typeset_extent = match tv . bounds_hint {
TextBounds ::BoundingBox ( r ) = >
blitstr2 ::Pt ::new ( ( r . br ( ) . x - r . tl ( ) . x - tv . margin . x * 2 ) as usize , ( r . br ( ) . y - r . tl ( ) . y - tv . margin . y * 2 ) as usize ) ,
TextBounds ::GrowableFromBr ( br , width ) = >
blitstr2 ::Pt ::new ( width as usize - tv . margin . x as usize * 2 , br . y as usize - tv . margin . y as usize * 2 ) ,
TextBounds ::GrowableFromBl ( bl , width ) = >
blitstr2 ::Pt ::new ( width as usize - tv . margin . x as usize * 2 , bl . y as usize - tv . margin . y as usize * 2 ) ,
TextBounds ::GrowableFromTl ( tl , width ) = >
2022-01-20 18:30:58 +00:00
blitstr2 ::Pt ::new ( width as usize - tv . margin . x as usize * 2 , ( clip_rect . br ( ) . y - tl . y ) as usize - tv . margin . y as usize * 2 ) ,
TextBounds ::GrowableFromTr ( tr , width ) = >
blitstr2 ::Pt ::new ( width as usize - tv . margin . x as usize * 2 , ( clip_rect . br ( ) . y - tr . y ) as usize - tv . margin . y as usize * 2 ) ,
2022-01-18 19:29:53 +00:00
} ;
2022-01-20 10:30:13 +00:00
let mut typesetter = Typesetter ::setup (
tv . to_str ( ) ,
& typeset_extent ,
2022-01-21 07:01:56 +00:00
& tv . style ,
2022-01-20 10:30:13 +00:00
if let Some ( i ) = tv . insertion { Some ( i as usize ) } else { None }
) ;
let composition = typesetter . typeset (
if tv . ellipsis {
OverflowStrategy ::Ellipsis
} else {
OverflowStrategy ::Abort
}
) ;
2021-04-02 16:53:30 +00:00
2022-01-20 10:30:13 +00:00
let composition_top_left = match tv . bounds_hint {
TextBounds ::BoundingBox ( r ) = >
r . tl ( ) . add ( tv . margin ) ,
TextBounds ::GrowableFromBr ( br , _width ) = >
2022-01-20 16:34:12 +00:00
Point ::new ( br . x - ( composition . bb_width ( ) as i16 + tv . margin . x ) ,
br . y - ( composition . bb_height ( ) as i16 + tv . margin . y ) ) ,
2022-01-20 10:30:13 +00:00
TextBounds ::GrowableFromBl ( bl , _width ) = >
2022-01-20 16:34:12 +00:00
Point ::new ( bl . x + tv . margin . x , bl . y - ( composition . bb_height ( ) as i16 + tv . margin . y ) ) ,
2022-01-20 10:30:13 +00:00
TextBounds ::GrowableFromTl ( tl , _width ) = >
2022-01-20 18:30:58 +00:00
tl . add ( tv . margin ) ,
TextBounds ::GrowableFromTr ( tr , _width ) = >
Point ::new ( tr . x - ( composition . bb_width ( ) as i16 + tv . margin . x ) , tr . y + tv . margin . y ) ,
2022-01-20 16:34:12 +00:00
}
. add ( screen_offset ) ;
2022-01-18 19:29:53 +00:00
// compute the clear rectangle -- the border is already in screen coordinates, just add the margin around it
2022-01-20 16:34:12 +00:00
let mut clear_rect = match tv . bounds_hint {
TextBounds ::BoundingBox ( mut r ) = > {
r . translate ( screen_offset ) ;
r
}
_ = > {
// composition_top_left already had a screen_offset added when it was computed. just margin it out
let mut r = Rectangle ::new (
composition_top_left ,
composition_top_left . add ( Point ::new ( composition . bb_width ( ) as _ , composition . bb_height ( ) as _ ) )
) ;
r . margin_out ( tv . margin ) ;
r
}
} ;
2021-04-02 16:53:30 +00:00
2022-01-20 18:30:58 +00:00
log ::trace! ( " clip_rect: {:?} " , clip_rect ) ;
log ::trace! ( " composition_top_left: {:?} " , composition_top_left ) ;
log ::trace! ( " clear_rect: {:?} " , clear_rect ) ;
2022-01-20 16:34:12 +00:00
// draw the bubble/border and/or clear the background area
2021-04-02 16:53:30 +00:00
let bordercolor = if tv . draw_border {
Some ( PixelColor ::Dark )
} else {
None
} ;
let borderwidth : i16 = if tv . draw_border {
tv . border_width as i16
} else {
0
} ;
2021-06-12 20:40:50 +00:00
let fillcolor = if tv . clear_area | | tv . invert {
if tv . invert {
Some ( PixelColor ::Dark )
} else {
Some ( PixelColor ::Light )
}
2021-04-02 16:53:30 +00:00
} else {
None
} ;
clear_rect . style = DrawStyle {
fill_color : fillcolor ,
stroke_color : bordercolor ,
stroke_width : borderwidth ,
} ;
2021-07-28 15:00:25 +00:00
if ! tv . dry_run ( ) {
if tv . rounded_border . is_some ( ) {
2021-08-16 14:52:06 +00:00
op ::rounded_rectangle (
display . native_buffer ( ) ,
RoundedRectangle ::new ( clear_rect , tv . rounded_border . unwrap ( ) as _ ) ,
2022-01-20 18:30:58 +00:00
tv . clip_rect ,
2021-08-16 14:52:06 +00:00
) ;
2021-07-28 15:00:25 +00:00
} else {
op ::rectangle ( display . native_buffer ( ) , clear_rect , tv . clip_rect ) ;
}
2021-03-10 17:45:54 +00:00
}
2022-01-20 16:34:12 +00:00
// for now, if we're in braille mode, emit all text to the debug log so we can see it
2021-09-07 11:11:54 +00:00
if cfg! ( feature = " braille " ) {
log ::info! ( " {} " , tv ) ;
}
2022-01-20 10:30:13 +00:00
2022-01-18 19:29:53 +00:00
if ! tv . dry_run ( ) {
2022-01-20 18:30:58 +00:00
composition . render ( display . native_buffer ( ) , composition_top_left , tv . invert , tv . clip_rect . unwrap ( ) ) ;
2021-08-16 14:52:06 +00:00
}
2022-01-20 10:30:13 +00:00
// type mismatch for now, replace this with a simple equals once we sort that out
tv . cursor . pt . x = composition . final_cursor ( ) . pt . x as i32 ;
tv . cursor . pt . y = composition . final_cursor ( ) . pt . y as i32 ;
tv . cursor . line_height = composition . final_cursor ( ) . line_height as i32 ;
2021-04-02 16:53:30 +00:00
2022-01-20 10:30:13 +00:00
tv . bounds_computed = Some (
clear_rect
) ;
2022-01-20 18:30:58 +00:00
log ::trace! ( " cursor ret {:?}, bounds ret {:?} " , tv . cursor , tv . bounds_computed ) ;
2021-04-02 16:53:30 +00:00
// pack our data back into the buffer to return
buffer . replace ( tv ) . unwrap ( ) ;
}
Some ( Opcode ::Flush ) = > {
display . update ( ) ;
display . redraw ( ) ;
}
Some ( Opcode ::Clear ) = > {
let mut r = Rectangle ::full_screen ( ) ;
r . style = DrawStyle ::new ( PixelColor ::Light , PixelColor ::Light , 0 ) ;
2021-04-06 16:45:11 +00:00
op ::rectangle ( display . native_buffer ( ) , r , screen_clip . into ( ) )
2020-08-29 14:09:20 +00:00
}
2021-04-02 16:53:30 +00:00
Some ( Opcode ::Line ) = > msg_scalar_unpack! ( msg , p1 , p2 , style , _ , {
2021-08-16 14:52:06 +00:00
let l =
Line ::new_with_style ( Point ::from ( p1 ) , Point ::from ( p2 ) , DrawStyle ::from ( style ) ) ;
2021-07-29 14:13:44 +00:00
op ::line ( display . native_buffer ( ) , l , screen_clip . into ( ) , false ) ;
2021-04-02 16:53:30 +00:00
} ) ,
Some ( Opcode ::Rectangle ) = > msg_scalar_unpack! ( msg , tl , br , style , _ , {
2021-08-16 14:52:06 +00:00
let r = Rectangle ::new_with_style (
Point ::from ( tl ) ,
Point ::from ( br ) ,
DrawStyle ::from ( style ) ,
) ;
2021-04-06 16:45:11 +00:00
op ::rectangle ( display . native_buffer ( ) , r , screen_clip . into ( ) ) ;
2021-04-02 16:53:30 +00:00
} ) ,
Some ( Opcode ::RoundedRectangle ) = > msg_scalar_unpack! ( msg , tl , br , style , r , {
2021-08-16 14:52:06 +00:00
let rr = RoundedRectangle ::new (
Rectangle ::new_with_style (
Point ::from ( tl ) ,
Point ::from ( br ) ,
DrawStyle ::from ( style ) ,
) ,
r as _ ,
) ;
2021-04-06 16:45:11 +00:00
op ::rounded_rectangle ( display . native_buffer ( ) , rr , screen_clip . into ( ) ) ;
2021-04-02 16:53:30 +00:00
} ) ,
Some ( Opcode ::Circle ) = > msg_scalar_unpack! ( msg , center , radius , style , _ , {
2021-08-16 14:52:06 +00:00
let c = Circle ::new_with_style (
Point ::from ( center ) ,
radius as _ ,
DrawStyle ::from ( style ) ,
) ;
2021-04-06 16:45:11 +00:00
op ::circle ( display . native_buffer ( ) , c , screen_clip . into ( ) ) ;
2021-04-02 16:53:30 +00:00
} ) ,
Some ( Opcode ::ScreenSize ) = > msg_blocking_scalar_unpack! ( msg , _ , _ , _ , _ , {
let pt = display . screen_size ( ) ;
2021-08-16 14:52:06 +00:00
xous ::return_scalar2 ( msg . sender , pt . x as usize , pt . y as usize )
. expect ( " couldn't return ScreenSize request " ) ;
2021-04-02 16:53:30 +00:00
} ) ,
Some ( Opcode ::QueryGlyphProps ) = > msg_blocking_scalar_unpack! ( msg , style , _ , _ , _ , {
2022-01-21 07:01:56 +00:00
let glyph = GlyphStyle ::from ( style ) ;
2021-08-16 14:52:06 +00:00
xous ::return_scalar2 (
msg . sender ,
2021-04-02 16:53:30 +00:00
glyph . into ( ) ,
2022-01-21 07:01:56 +00:00
glyph_to_height_hint ( glyph ) ,
2021-08-16 14:52:06 +00:00
)
. expect ( " could not return QueryGlyphProps request " ) ;
2021-04-02 16:53:30 +00:00
} ) ,
Some ( Opcode ::DrawSleepScreen ) = > msg_scalar_unpack! ( msg , _ , _ , _ , _ , {
2021-09-15 17:00:22 +00:00
display . blit_screen ( & logo ::LOGO_MAP ) ;
2021-04-02 16:53:30 +00:00
display . update ( ) ;
display . redraw ( ) ;
} ) ,
2021-08-16 14:52:06 +00:00
Some ( Opcode ::Devboot ) = > msg_scalar_unpack! ( msg , ena , _ , _ , _ , {
if ena ! = 0 {
display . set_devboot ( true ) ;
} else {
display . set_devboot ( false ) ;
}
2021-07-03 13:08:39 +00:00
} ) ,
2021-08-02 20:58:34 +00:00
Some ( Opcode ::RestartBulkRead ) = > msg_blocking_scalar_unpack! ( msg , _ , _ , _ , _ , {
bulkread . from_offset = 0 ;
2021-08-16 14:52:06 +00:00
xous ::return_scalar ( msg . sender , 0 )
. expect ( " couldn't ack that bulk read pointer was reset " ) ;
2021-08-02 20:58:34 +00:00
} ) ,
Some ( Opcode ::BulkReadFonts ) = > {
let fontlen = fontmap ::FONT_TOTAL_LEN as u32 + 8 ;
2021-08-16 14:52:06 +00:00
let mut buf = unsafe {
Buffer ::from_memory_message_mut ( msg . body . memory_message_mut ( ) . unwrap ( ) )
} ;
2021-08-02 20:58:34 +00:00
//let mut bulkread = buf.as_flat::<BulkRead, _>().unwrap(); // try to skip the copy/init step by using a persistent structure
let fontslice = fontregion . as_slice ::< u8 > ( ) ;
assert! ( fontlen < = fontslice . len ( ) as u32 ) ;
if bulkread . from_offset > = fontlen {
2021-08-16 14:52:06 +00:00
log ::error! (
" BulkReadFonts attempt to read out of bound on the font area; ignoring! "
) ;
continue ;
2021-08-02 20:58:34 +00:00
}
let readlen = if bulkread . from_offset + bulkread . buf . len ( ) as u32 > fontlen {
// returns what is readable of the last bit; anything longer than the fontlen is undefined/invalid
fontlen as usize - bulkread . from_offset as usize
} else {
bulkread . buf . len ( )
} ;
2021-08-16 14:52:06 +00:00
for ( & src , dst ) in fontslice
[ bulkread . from_offset as usize .. bulkread . from_offset as usize + readlen ]
. iter ( )
. zip ( bulkread . buf . iter_mut ( ) )
{
* dst = src ;
2021-08-02 20:58:34 +00:00
}
bulkread . len = readlen as u32 ;
bulkread . from_offset + = readlen as u32 ;
buf . replace ( bulkread ) . unwrap ( ) ;
}
2021-09-15 17:00:22 +00:00
Some ( Opcode ::TestPattern ) = > msg_blocking_scalar_unpack! ( msg , duration , _ , _ , _ , {
let mut stashmem = xous ::syscall ::map_memory (
None ,
None ,
( ( backend ::FB_SIZE * 4 ) + 4096 ) & ! 4095 ,
xous ::MemoryFlags ::R | xous ::MemoryFlags ::W ,
) . expect ( " couldn't map stash frame buffer " ) ;
let stash = & mut stashmem . as_slice_mut ( ) [ .. backend ::FB_SIZE ] ;
for ( & src , dst ) in display . as_slice ( ) . iter ( ) . zip ( stash . iter_mut ( ) ) {
* dst = src ;
}
for lines in 0 .. backend ::FB_LINES { // mark all lines dirty
stash [ lines * backend ::FB_WIDTH_WORDS + ( backend ::FB_WIDTH_WORDS - 1 ) ] | = 0x1_0000 ;
}
let ticktimer = ticktimer_server ::Ticktimer ::new ( ) . unwrap ( ) ;
let start_time = ticktimer . elapsed_ms ( ) ;
let mut testmem = xous ::syscall ::map_memory (
None ,
None ,
( ( backend ::FB_SIZE * 4 ) + 4096 ) & ! 4095 ,
xous ::MemoryFlags ::R | xous ::MemoryFlags ::W ,
) . expect ( " couldn't map stash frame buffer " ) ;
let testpat = & mut testmem . as_slice_mut ( ) [ .. backend ::FB_SIZE ] ;
const DWELL : usize = 1000 ;
while ticktimer . elapsed_ms ( ) - start_time < duration as u64 {
// all black
for w in testpat . iter_mut ( ) {
* w = 0 ;
}
for lines in 0 .. backend ::FB_LINES { // mark dirty bits
testpat [ lines * backend ::FB_WIDTH_WORDS + ( backend ::FB_WIDTH_WORDS - 1 ) ] | = 0x1_0000 ;
}
display . blit_screen ( testpat ) ;
display . update ( ) ;
display . redraw ( ) ;
ticktimer . sleep_ms ( DWELL ) . unwrap ( ) ;
// all white
for w in testpat . iter_mut ( ) {
* w = 0xFFFF_FFFF ;
}
// dirty bits already set
display . blit_screen ( testpat ) ;
display . update ( ) ;
display . redraw ( ) ;
ticktimer . sleep_ms ( DWELL ) . unwrap ( ) ;
// vertical bars
for lines in 0 .. backend ::FB_LINES {
for words in 0 .. backend ::FB_WIDTH_WORDS {
testpat [ lines * backend ::FB_WIDTH_WORDS + words ] = 0xaaaa_aaaa ;
}
}
display . blit_screen ( testpat ) ;
display . update ( ) ;
display . redraw ( ) ;
ticktimer . sleep_ms ( DWELL ) . unwrap ( ) ;
for lines in 0 .. backend ::FB_LINES {
for words in 0 .. backend ::FB_WIDTH_WORDS {
testpat [ lines * backend ::FB_WIDTH_WORDS + words ] = 0x5555_5555 ;
}
}
display . blit_screen ( testpat ) ;
display . update ( ) ;
display . redraw ( ) ;
ticktimer . sleep_ms ( DWELL ) . unwrap ( ) ;
// horiz bars
for lines in 0 .. backend ::FB_LINES {
for words in 0 .. backend ::FB_WIDTH_WORDS {
if lines % 2 = = 0 {
testpat [ lines * backend ::FB_WIDTH_WORDS + words ] = 0x0 ;
} else {
testpat [ lines * backend ::FB_WIDTH_WORDS + words ] = 0xffff_ffff ;
}
}
testpat [ lines * backend ::FB_WIDTH_WORDS + ( backend ::FB_WIDTH_WORDS - 1 ) ] | = 0x1_0000 ;
}
display . blit_screen ( testpat ) ;
display . update ( ) ;
display . redraw ( ) ;
ticktimer . sleep_ms ( DWELL ) . unwrap ( ) ;
for lines in 0 .. backend ::FB_LINES {
for words in 0 .. backend ::FB_WIDTH_WORDS {
if lines % 2 = = 1 {
testpat [ lines * backend ::FB_WIDTH_WORDS + words ] = 0x0 ;
} else {
testpat [ lines * backend ::FB_WIDTH_WORDS + words ] = 0xffff_ffff ;
}
}
testpat [ lines * backend ::FB_WIDTH_WORDS + ( backend ::FB_WIDTH_WORDS - 1 ) ] | = 0x1_0000 ;
}
display . blit_screen ( testpat ) ;
display . update ( ) ;
display . redraw ( ) ;
ticktimer . sleep_ms ( DWELL ) . unwrap ( ) ;
}
display . blit_screen ( stash ) ;
xous ::return_scalar ( msg . sender , duration ) . expect ( " couldn't ack test pattern " ) ;
} ) ,
2021-06-12 20:40:50 +00:00
Some ( Opcode ::Quit ) = > break ,
2021-08-16 14:52:06 +00:00
None = > {
log ::error! ( " received opcode scalar that is not handled " ) ;
}
2020-08-29 14:09:20 +00:00
}
2020-08-14 10:46:23 +00:00
}
2021-04-05 15:50:00 +00:00
log ::trace! ( " main loop exit, destroying servers " ) ;
xns . unregister_server ( sid ) . unwrap ( ) ;
xous ::destroy_server ( sid ) . unwrap ( ) ;
log ::trace! ( " quitting " ) ;
2021-05-20 03:01:00 +00:00
xous ::terminate_process ( 0 )
2020-08-14 09:25:20 +00:00
}