I am using an Atmel AVR and am trying to access data from a structure which is stored in flash (program) memory.
The structure is:
typedef struct {
uint8_t width;
uint8_t height; // row number 0 to 5
uint8_t images; // how many frames does this bitmap have
uint8_t data[]; // the actual pixel data
} bitmap_t;
the data is:
__flash static const bitmap_t bmp_stereo2 = {14,1,1,{126,129,60,66,24,36,60,60,36,24,66,60,129,126}};
I'm trying to access the data with (partial code shown)...
void lcd_bitmap2(const bitmap_t *bit, uint8_t id, uint8_t posx, uint8_t posy) {
uint8_t x;
uint8_t y;
const uint8_t bw = pgm_read_byte(&bit->width); // this works -- I can print out to serial
const uint8_t bh = pgm_read_byte(&bit->height); //this also works -- I can print out to serial
// this doesn't work
const uint8_t *data = pgm_read_word(&bit->data); // I get: - initialization makes pointer from integer without a cast [enabled by default]
const uint8_t *data = (uint8_t *)pgm_read_word(&bit->data); // this also doen't work (no warning, but wrong data read out)
//rest of function...
So I can access the width, height and image variable, but not the data part of the structure. It all works if I don't store in flash - It's my retrieval and only has a problem with the data array part of the structure (width, height and image are read ok)