samtal - after something to eat, my brain got into gear, so I think my suggestion that the second one is nicer:
Then either
void write_flash(byte* demo_data[], uint page, uint offset, uint demo_cells) { FlashUnit* flash_aligned_data = (FlashUnit*)demo_data; // or = (FlashUnit*)&demo_data[0];
or
case 'w': write_flash((FlashUnit*)demo_data, page, 0, demo_cells); //write_flash(int page, int offset, int num_cells) break;
I like the second one because I'd like to keep the read_flash and write_flash APIs similar.
Is horrible.
I think I might make the APIs:
uint16 read_flash(uint8 page, uint16 offset, uint16 num_cells) {...}
void write_flash(uint16 demo_data[],char page, uint16 offset, uint16 demo_cells) {...}
into
int read_flash(byte buffer[], uint num_bytes, uint page_num, uint page_offset) {...}
// returns the number of bytes read
int write_flash(byte buffer[], uint num_bytes, uint page_num, uint page_offset) {...}
// returns the number of bytes written or -1 if an error
...
case 'w':
write_flash(demo_data, sizeof(demo_data), page_numb, 0); //write_flash(int page, int offset, int num_cells)
break;
If I understand correctly, what you want is something to copy flash to an array variable, or an array variable to flash. Is that correct?
In that case the API might be:
int read_flash(byte ram_buffer[], byte flash_buffer[], uint num_bytes) {...}
// returns the number of bytes copied from flash_buffer into ram_buffer
// this is identical to memcpy()
int write_flash(byte flash_buffer[], byte ram_buffer[], uint num_bytes) {...}
// returns the number of bytes written from ram_buffer to flash_buffer
// or <0 if an error. This looks like memcpy() BUT
// this requires flash_buffer to be a valid flash memory address
and let the code in the functions sort out the details.
If you have the names of the two variables (one in flash, and one in RAM), they should do the 'right thing'.
Assuming the variable stored in flash (that is being written to) is on its own page, it should be straightforward.
It is a bit more tricky if the variable stored in flash shares a page with other stuff, but I assume you are avoiding that.
(full disclosure: I am not a member of LeafLabs staff.)