For a display driver in an arm project, I want to access the buffer as 2D array to access it like this:
e.g. display_buffer[2][113]=0xff;
To write the buffer out to the display via I2C I want to write the whole buffer out, but need to prepend it with 0x40.
io_write(I2C_0_io, (uint8_t *)buf, 513); //where buf should be 0x40,content, of, display_buffer,...
Is there a way to declare display_buffer[4][128]
so that it has one byte before it and a pointer that points to it?
I tried
uint8_t *_display_buffer = (uint8_t*)513;
uint8_t *display_buffer[4][128]=_display_buffer+1;
but of course the compiler thought that this was not a good idea ('invalid initializer')
You need to define _display_buffer
as an array large enough to hold your 2D array plus 1 byte, and display_buffer
as a pointer to an array (which you can index as a 2D array) instead of a 2D array:
uint8_t _display_buffer[513] = { 0x40 };
uint8_t (*display_buffer)[128]=(uint8_t (*)[128])(_display_buffer+1);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.