pub fn write_config(&mut self, matrix: Matrix) -> Result<(), FlashError> {
        let mut config = [0u8; CONFIG_SIZE];
        Self::matrix_to_config(matrix, &mut config);

        if self.last_valid_index + 1 < CONFIGS_IN_PAGE {
            let next_addr = CONFIG_ADD + (self.last_valid_index + 1) * CONFIG_SIZE;
            let value = unsafe { ptr::read_volatile(next_addr as *const u8) };
            if value != 0xFF {
                log!("Found no erased flash while attempting write");
                return Err(FlashError::FlashNotErased);
            }
            self.write(next_addr, &config[..])?;
            self.last_valid_index += 1;
        } else {
            // No more space in the page, erase and go back to the start
            log!("Got to the end of page, going back to start");
            self.erase_page()?;
            self.write(CONFIG_ADD, &config[..])?;
            self.last_valid_index = 0;
        }
        Ok(())
    }
/// Tries to write a config to the next flash index, if the current index is the last one, this
/// method will erase the whole page and write to the first place. It will fail if the next
/// place to write is not already erased.
Tries to write a config to the next flash index, if the current index is the last one, this
method will erase the whole page and write to the first place. It will fail if the next
place to write is not already erased.
Tries to write a config to the next flash index if the current index is the last one this method will erase the whole page and write to the first place . It will fail if the next place to write is not already erased .
pub fn write_config(&mut self, matrix: Matrix) -> Result<(), FlashError> {
        let mut config = [0u8; CONFIG_SIZE];
        Self::matrix_to_config(matrix, &mut config);
        if self.last_valid_index + 1 < CONFIGS_IN_PAGE {
            let next_addr = CONFIG_ADD + (self.last_valid_index + 1) * CONFIG_SIZE;
            let value = unsafe { ptr::read_volatile(next_addr as *const u8) };
            if value != 0xFF {
                log!("Found no erased flash while attempting write");
                return Err(FlashError::FlashNotErased);
            }
            self.write(next_addr, &config[..])?;
            self.last_valid_index += 1;
        } else {
            // No more space in the page, erase and go back to the start
            log!("Got to the end of page, going back to start");
            self.erase_page()?;
            self.write(CONFIG_ADD, &config[..])?;
            self.last_valid_index = 0;
        }
        Ok(())
    }
pub fn write_config ( & mut self , matrix : Matrix ) -> Result < ( ) , FlashError > { let mut config = [ 0u8 ; CONFIG_SIZE ] ; Self :: matrix_to_config ( matrix , & mut config ) ; if self . last_valid_index + 1 < CONFIGS_IN_PAGE { let next_addr = CONFIG_ADD + ( self . last_valid_index + 1 ) * CONFIG_SIZE ; let value = unsafe { ptr :: read_volatile ( next_addr as * const u8 ) } ; if value != 0xFF { log ! ( " " ) ; return Err ( FlashError :: FlashNotErased ) ; } self . write ( next_addr , & config [ .. ] ) ? ; self . last_valid_index += 1 ; } else { // No more space in the page, erase and go back to the start log ! ( " " ) ; self . erase_page ( ) ? ; self . write ( CONFIG_ADD , & config [ .. ] ) ? ; self . last_valid_index = 0 ; } Ok ( ( ) ) }
Tries to write a config to the next flash index, if the current index is the last one, this
method will erase the whole page and write to the first place.
Tries to write a config to the next flash index if the current index is the last one this method will erase the whole page and write to the first place .
&mut self
matrix
Matrix
&mut self
matrix
Matrix