@@ -1475,27 +1475,32 @@ pub extern "C" fn video_wait_for_line(line: u16) {
14751475 }
14761476}
14771477
1478- /// Read the RGB palette. Currently we only have two colours and you can't
1479- /// change them.
1478+ /// Read the RGB palette.
14801479extern "C" fn video_get_palette ( index : u8 ) -> common:: Option < common:: video:: RGBColour > {
1481- match index {
1482- 0 => common:: Option :: Some ( vga:: colours:: BLUE . into ( ) ) ,
1483- 1 => common:: Option :: Some ( vga:: colours:: YELLOW . into ( ) ) ,
1484- _ => common:: Option :: None ,
1485- }
1480+ let raw_u16 = vga:: VIDEO_PALETTE [ index as usize ] . load ( Ordering :: Relaxed ) ;
1481+ let our_colour = vga:: RGBColour ( raw_u16) ;
1482+ // Convert from our 12-bit colour type to the public 24-bit colour type
1483+ common:: Option :: Some ( our_colour. into ( ) )
14861484}
14871485
1488- /// Update the RGB palette
1489- extern "C" fn video_set_palette ( _index : u8 , _rgb : common:: video:: RGBColour ) {
1490- // TODO set the palette when we actually have one
1486+ /// Update the RGB palette.
1487+ extern "C" fn video_set_palette ( index : u8 , rgb : common:: video:: RGBColour ) {
1488+ // Convert from their 24-bit colour type to our 12-bit colour type
1489+ let our_colour: vga:: RGBColour = rgb. into ( ) ;
1490+ // Store it
1491+ vga:: VIDEO_PALETTE [ index as usize ] . store ( our_colour. 0 , Ordering :: Relaxed ) ;
14911492}
14921493
14931494/// Update all the RGB palette
14941495unsafe extern "C" fn video_set_whole_palette (
1495- _palette : * const common:: video:: RGBColour ,
1496- _length : usize ,
1496+ palette : * const common:: video:: RGBColour ,
1497+ length : usize ,
14971498) {
1498- // TODO set the palette when we actually have one
1499+ // Don't let them set more than 255 entries
1500+ let num_entries = length. min ( 255 ) ;
1501+ for i in 0 ..num_entries {
1502+ video_set_palette ( i as u8 , palette. add ( i) . read ( ) )
1503+ }
14991504}
15001505
15011506extern "C" fn i2c_bus_get_info ( _i2c_bus : u8 ) -> common:: Option < common:: i2c:: BusInfo > {
@@ -1676,6 +1681,7 @@ extern "C" fn block_dev_eject(_dev_id: u8) -> common::Result<()> {
16761681/// Sleep the CPU until the next interrupt.
16771682extern "C" fn power_idle ( ) {
16781683 if !INTERRUPT_PENDING . load ( Ordering :: Relaxed ) {
1684+ defmt:: debug!( "Idle..." ) ;
16791685 cortex_m:: asm:: wfe ( ) ;
16801686 }
16811687}
0 commit comments