That still wouldn't solve the issue with struct!
I think I have found a glitch in GCC compiler where if you define your struct in dynamic memory rather than PROGMEM, even if you use a buffer and fetch the data using memcpy_P, it will return the correct value while printing, but when you copy it again to allChars[0].bitmap , the wrong value is copied! the thing that solved the issue was adding PROGMEM to the struct like below:
typedef struct {
unsigned int ascii;
int size[2];
const PROGMEM unsigned char *bitmap;
} chars;
I have not yet encountered any compilers that are this specific and don't even allow transfer between memory spaces correctly. (Not to mention other issues with GCC linker that are brought up by david from eevblog like stack overflow without warning, etc). They really need to solve issues like this as this compiler is one of the most frequently used on different platforms.
anyways, here is the final code if anyone finds it useful (I will probably end up making a youtube video about it later):
#include "U8glib.h"
//U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE);
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0);
typedef struct {
unsigned int ascii;
int size[2];
const PROGMEM unsigned char *bitmap;
} chars;
chars allChars[1];
const unsigned char pat[] PROGMEM = {
0x00, 0x00, 0x00, //.....................
0x00, 0x00, 0x00, //.....................
0x00, 0x00, 0x00, //.....................
0x00, 0x00, 0x00, //.....................
0x00, 0x00, 0x00, //.....................
0x00, 0x00, 0x00, //.....................
0x00, 0x00, 0x00, //.....................
0x00, 0x00, 0x00, //.....................
0x00, 0x00, 0x00, //.....................
0x01, 0xfc, 0x00, //.......%%%%%%%.......
0x0f, 0xff, 0x00, //....%%%%%%%%%%%%.....
0x1f, 0xff, 0xc0, //...%%%%%%%%%%%%%%%...
0x3f, 0xff, 0xe0, //..%%%%%%%%%%%%%%%%%..
0x3f, 0xff, 0xe0, //..%%%%%%%%%%%%%%%%%..
0x7f, 0xff, 0xf0, //.%%%%%%%%%%%%%%%%%%%.
0x7f, 0xdf, 0xf0, //.%%%%%%%%%.%%%%%%%%%.
0xff, 0x8f, 0xf8, //%%%%%%%%%...%%%%%%%%%
0xff, 0x8f, 0xf8, //%%%%%%%%%...%%%%%%%%%
0xff, 0x8f, 0xf8, //%%%%%%%%%...%%%%%%%%%
0xff, 0x8f, 0xf8, //%%%%%%%%%...%%%%%%%%%
0xff, 0x8f, 0xf8, //%%%%%%%%%...%%%%%%%%%
0xff, 0x8f, 0xf8, //%%%%%%%%%...%%%%%%%%%
0xff, 0x8f, 0xf8, //%%%%%%%%%...%%%%%%%%%
0xff, 0x8f, 0xf8, //%%%%%%%%%...%%%%%%%%%
0xff, 0x8f, 0xf8, //%%%%%%%%%...%%%%%%%%%
0xff, 0x8f, 0xf8, //%%%%%%%%%...%%%%%%%%%
0xff, 0x8f, 0xf8, //%%%%%%%%%...%%%%%%%%%
0xff, 0x8f, 0xf8, //%%%%%%%%%...%%%%%%%%%
0xff, 0x8f, 0xf8, //%%%%%%%%%...%%%%%%%%%
0xff, 0x8f, 0xf8, //%%%%%%%%%...%%%%%%%%%
0xff, 0x8f, 0xf8, //%%%%%%%%%...%%%%%%%%%
0xff, 0x8f, 0xf8, //%%%%%%%%%...%%%%%%%%%
0xff, 0x8f, 0xf8, //%%%%%%%%%...%%%%%%%%%
0xff, 0x8f, 0xf8, //%%%%%%%%%...%%%%%%%%%
0xff, 0x8f, 0xf8, //%%%%%%%%%...%%%%%%%%%
0xff, 0x8f, 0xf8, //%%%%%%%%%...%%%%%%%%%
0xff, 0x8f, 0xf8, //%%%%%%%%%...%%%%%%%%%
0xff, 0x8f, 0xf8, //%%%%%%%%%...%%%%%%%%%
0xff, 0x8f, 0xf8, //%%%%%%%%%...%%%%%%%%%
0xff, 0x8f, 0xf8, //%%%%%%%%%...%%%%%%%%%
0xff, 0x8f, 0xf8, //%%%%%%%%%...%%%%%%%%%
0xff, 0x8f, 0xf8, //%%%%%%%%%...%%%%%%%%%
0xff, 0x8f, 0xf8, //%%%%%%%%%...%%%%%%%%%
0x7f, 0xdf, 0xf0, //.%%%%%%%%%.%%%%%%%%%.
0x7f, 0xff, 0xf0, //.%%%%%%%%%%%%%%%%%%%.
0x3f, 0xff, 0xe0, //..%%%%%%%%%%%%%%%%%..
0x3f, 0xff, 0xe0, //..%%%%%%%%%%%%%%%%%..
0x1f, 0xff, 0xc0, //...%%%%%%%%%%%%%%%...
0x0f, 0xff, 0x80, //....%%%%%%%%%%%%%....
0x01, 0xfc, 0x00, //.......%%%%%%%.......
0x00, 0x00, 0x00, //.....................
0x00, 0x00, 0x00, //.....................
0x00, 0x00, 0x00, //.....................
0x00, 0x00, 0x00, //.....................
0x00, 0x00, 0x00, //.....................
};
void charToBitmap(int x, int y, char chr){
for(unsigned int i=0; i<sizeof(allChars);i++){
if (allChars[i].ascii=chr){
u8g.drawBitmapP( x, y, allChars[i].size[0], allChars[i].size[1], allChars[i].bitmap);
break;
}
}
}
void draw(void) {
charToBitmap(0,0,'0');
}
void setup(void) {
allChars[0] = (chars) {48,{3,54},pat};
}
void loop(void) {
u8g.firstPage();
do {
draw();
} while( u8g.nextPage() );
}