Struct avr_boot::PageBuffer

source ·
pub struct PageBuffer { /* private fields */ }
Expand description

Representation of the spm page buffer.

The page buffer is a special area of memory which is write-only, and only writable using the spm instruction. Setting a value in the buffer does not write to the program memory - that only happens when PageBuffer::store is called

Example

use avr_boot::PageBuffer;

let address:u16 = 0x1000;
let buff = PageBuffer::new(address);
for w in buff.iter() {
    w.set(0xabcd);
}
buff.store();

A whole page is written in one go, so if you only want to change part of a page, you need to make sure you have loaded the rest of the page into the buffer first.

There is only one physical buffer in the system, so you should make sure only one of these structs ever exists at any time. This rule is not enforced.

The page address will be aligned downwards to the nearest starting page address

Implementations§

The buffer length in words, the value will change depending on the MCU compilation target

Create a new PageBuffer with the given address.

Example
use avr_boot::PageBuffer;

let buff = PageBuffer::new(0x101fu16);
assert_eq!(0x1000u16, buff.address().into());

The page address will be aligned downwards to the nearest starting page address

Get the base page address to be operated on

Example
use avr_boot::{PageBuffer, Address};

let buff = PageBuffer::new(0x1000u16);
assert_eq!(Address::from(0x1000u16), buff.address());

The page address will be aligned downwards to the nearest starting page address

Fill the buffer from a slice

Example
use avr_boot::{DataPage, PageBuffer};

let address: u16 = 0x1000;
let data = DataPage(core::array::from_fn(|_| 0x69));
let buff = PageBuffer::new(address);
buff.copy_from(&data);
buff.store();
Example
use avr_boot::PageBuffer;

let address: u16 = 0x1000;
let data = [0xff; avr_boot::SPM_PAGESIZE_BYTES];
let buff = PageBuffer::new(address);
buff.copy_from(&data);
buff.store();

Fill the buffer from a slice and store it immediately

Example
use avr_boot::{DataPage, PageBuffer};

let address: u16 = 0x1000;
let data = DataPage(core::array::from_fn(|_| 0x69));
let buff = PageBuffer::new(address);
buff.copy_from(&data);
buff.store();

Fill the buffer by repeatedly calling the callback function

Example
use avr_boot::PageBuffer;

let address:u16 = 0x1000;
let buff = PageBuffer::new(address);
buff.fill_from_fn(|| Some(0x1234));
buff.store();

Fill the buffer by repeatedly polling an iterator.

Example
use avr_boot::PageBuffer;
use core::iter;

let page_address:u16 = 0x1000;
let buff = PageBuffer::new(page_address);
buff.fill_from_iter(iter::repeat(0x69));
buff.store();

Erase the page from program memory, then write the contents of the buffer to it

Iterate the buffer as writable word cells

Example
use avr_boot::PageBuffer;

let address: u16 = 0x1000;
let buff = PageBuffer::new(address);
for w in buff.iter() {
    w.set(0x69);
}
buff.store();

Trait Implementations§

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.