Continue to Site

# [SOLVED]Some problem understanding the code

Status
Not open for further replies.

#### saur

##### Member level 2
Code:
#define SDRAM_BASE_ADDR 0x28000000

static uint16_t *fb  = (uint16_t *)SDRAM_BASE_ADDR;

void GLCD_DrawChar (unsigned int x, unsigned int y, unsigned int cw, unsigned int ch, unsigned char *c) {
unsigned int i, j, k, pixs;

k  = (cw + 7)/8;

if (k == 1) {
for (j = 0; j < ch; j++) {
pixs = *(unsigned char *)c;
c += 1;

for (i = 0; i < cw; i++) {
#if (LANDSCAPE == 0)
fb[(y+j)*PHYS_XSZ + (x+i)] = Color[(pixs >> i) & 1];
#else
fb[(x+i)*PHYS_XSZ + (y+j)] = Color[(pixs >> i) & 1];
#endif
}
}
}
else if (k == 2) {
for (j = 0; j < ch; j++) {
pixs = *(unsigned short *)c;
c += 2;

for (i = 0; i < cw; i++) {
#if (LANDSCAPE == 0)
fb[(y+j)*PHYS_XSZ + (x+i)] = Color[(pixs >> i) & 1];
#else
fb[(x+i)*PHYS_XSZ + (y+j)] = Color[(pixs >> i) & 1];
#endif
}
}
}
}

In the above code the only problem I'm facing is that, fb has been defined as a pointer. Then what does the code
Code:
 fb[(y+j)*PHYS_XSZ+(x+i)]
mean?

Here PHYS_XSZ has been defined as 240. I also understand what
Code:
Color[(pixs>>i)&1]
means.

Just help mw with the fb part of the code.

Thanks

A pointer can be addressed in different ways

Code C - [expand]1
2
*( fb + i )
fb[ i ] //are same

saur

### saur

Points: 2

#### forforum

##### Junior Member level 2
This code used to display a character at the position x,y.
LCD has matrix COLxROW RAM to store character (all characters are display on LCD).
So function will saved the character to RAM of LCD at position x,y.
PHYS_XSZ is number of characters on a line.

Status
Not open for further replies.