@@ -1734,15 +1734,57 @@ pub extern "C" fn time_clock_set(time: common::Time) {
17341734/// Configuration data is, to the BIOS, just a block of bytes of a given
17351735/// length. How it stores them is up to the BIOS - it could be EEPROM, or
17361736/// battery-backed SRAM.
1737- pub extern "C" fn configuration_get ( _buffer : FfiBuffer ) -> ApiResult < usize > {
1738- ApiResult :: Err ( CError :: Unimplemented )
1737+ pub extern "C" fn configuration_get ( mut buffer : FfiBuffer ) -> ApiResult < usize > {
1738+ let mut lock = HARDWARE . lock ( ) ;
1739+ let hw = lock. as_mut ( ) . unwrap ( ) ;
1740+ let Some ( slice) = buffer. as_mut_slice ( ) else {
1741+ return ApiResult :: Err ( CError :: Unimplemented ) ;
1742+ } ;
1743+ match hw. rtc . configuration_get ( hw. i2c . acquire_i2c ( ) , slice) {
1744+ Ok ( n) => {
1745+ defmt:: info!( "Config Read {:x}" , & slice[ 0 ..usize :: from( n) ] ) ;
1746+ ApiResult :: Ok ( usize:: from ( n) )
1747+ }
1748+ Err ( rtc:: Error :: NoRtcFound ) => {
1749+ defmt:: info!( "Can't get config - no RTC present" ) ;
1750+ ApiResult :: Err ( CError :: InvalidDevice )
1751+ }
1752+ Err ( rtc:: Error :: DriverBug ) => {
1753+ defmt:: warn!( "Can't get config - Driver Bug" ) ;
1754+ ApiResult :: Err ( CError :: DeviceError ( 0 ) )
1755+ }
1756+ Err ( rtc:: Error :: Bus ( e) ) => {
1757+ defmt:: warn!( "Can't get config - bus error {:?}" , e) ;
1758+ ApiResult :: Err ( CError :: DeviceError ( 1 ) )
1759+ }
1760+ }
17391761}
17401762
17411763/// Set the configuration data block.
17421764///
17431765/// See `configuration_get`.
1744- pub extern "C" fn configuration_set ( _buffer : FfiByteSlice ) -> ApiResult < ( ) > {
1745- ApiResult :: Err ( CError :: Unimplemented )
1766+ pub extern "C" fn configuration_set ( buffer : FfiByteSlice ) -> ApiResult < ( ) > {
1767+ defmt:: info!( "Config save {:x}" , buffer. as_slice( ) ) ;
1768+ let mut lock = HARDWARE . lock ( ) ;
1769+ let hw = lock. as_mut ( ) . unwrap ( ) ;
1770+ match hw
1771+ . rtc
1772+ . configuration_set ( hw. i2c . acquire_i2c ( ) , buffer. as_slice ( ) )
1773+ {
1774+ Ok ( ( ) ) => ApiResult :: Ok ( ( ) ) ,
1775+ Err ( rtc:: Error :: NoRtcFound ) => {
1776+ defmt:: info!( "Can't save config - no RTC present" ) ;
1777+ ApiResult :: Err ( CError :: InvalidDevice )
1778+ }
1779+ Err ( rtc:: Error :: DriverBug ) => {
1780+ defmt:: warn!( "Can't save config - Driver Bug" ) ;
1781+ ApiResult :: Err ( CError :: DeviceError ( 0 ) )
1782+ }
1783+ Err ( rtc:: Error :: Bus ( e) ) => {
1784+ defmt:: warn!( "Can't save config - bus error {:?}" , e) ;
1785+ ApiResult :: Err ( CError :: DeviceError ( 0 ) )
1786+ }
1787+ }
17461788}
17471789
17481790/// Does this Neotron BIOS support this video mode?
@@ -1760,6 +1802,7 @@ pub extern "C" fn video_is_valid_mode(mode: common::video::Mode) -> bool {
17601802/// pointer to a block of size `Mode::frame_size_bytes()` to
17611803/// `video_set_framebuffer` before any video will appear.
17621804pub extern "C" fn video_set_mode ( mode : common:: video:: Mode ) -> ApiResult < ( ) > {
1805+ defmt:: info!( "Changing to mode {}" , mode. as_u8( ) ) ;
17631806 if vga:: set_video_mode ( mode) {
17641807 ApiResult :: Ok ( ( ) )
17651808 } else {
@@ -1790,7 +1833,12 @@ pub extern "C" fn video_get_mode() -> common::video::Mode {
17901833/// to provide the 'basic' text buffer experience from reserves, so this
17911834/// function will never return `null` on start-up.
17921835pub extern "C" fn video_get_framebuffer ( ) -> * mut u8 {
1793- unsafe { vga:: GLYPH_ATTR_ARRAY . as_mut_ptr ( ) as * mut u8 }
1836+ let ptr = vga:: CUSTOM_FB . load ( Ordering :: Relaxed ) ;
1837+ if ptr. is_null ( ) {
1838+ unsafe { vga:: GLYPH_ATTR_ARRAY . as_mut_ptr ( ) as * mut u8 }
1839+ } else {
1840+ ptr
1841+ }
17941842}
17951843
17961844/// Set the framebuffer address.
@@ -1804,8 +1852,9 @@ pub extern "C" fn video_get_framebuffer() -> *mut u8 {
18041852///
18051853/// The pointer must point to enough video memory to handle the current video
18061854/// mode, and any future video mode you set.
1807- pub unsafe extern "C" fn video_set_framebuffer ( _buffer : * const u8 ) -> ApiResult < ( ) > {
1808- ApiResult :: Err ( CError :: Unimplemented )
1855+ pub unsafe extern "C" fn video_set_framebuffer ( buffer : * const u8 ) -> ApiResult < ( ) > {
1856+ vga:: CUSTOM_FB . store ( buffer as * mut u8 , Ordering :: Relaxed ) ;
1857+ ApiResult :: Ok ( ( ) )
18091858}
18101859
18111860/// Find out whether the given video mode needs more VRAM than we currently have.
@@ -2398,7 +2447,9 @@ extern "C" fn block_dev_eject(_dev_id: u8) -> ApiResult<()> {
23982447/// Sleep the CPU until the next interrupt.
23992448extern "C" fn power_idle ( ) {
24002449 if !INTERRUPT_PENDING . load ( Ordering :: Relaxed ) {
2401- cortex_m:: asm:: wfe ( ) ;
2450+ unsafe {
2451+ core:: arch:: asm!( "wfe" ) ;
2452+ }
24022453 }
24032454}
24042455
0 commit comments