Hello !
I've been trying to use OLED in STM32 and found some library for it. I tried to also understand what happens in each in case to change something inside of the library, and I've stumbled into a understanding problem.
The OLED_DrawBitmap was quite understandable in which each byte contained 8 bit height picture info.
The screen is 128x64 so when each byte is 8 bit height then there was 1024, and the variable "k" was to read each bit in this byte. So in total the was like 8 scans from 0 to 127 of 8 bit hight picture each.
So now it's time to each bit/pixel put into OLED_SetPixel. In many OLED library there was the same setpixel function in which the buffer was an array of buffer[1024]. So I checked at the code and putted max values, x = 127 and y = 63, (SCREEN_WIDTH = 128) so buffer[127 + 128*(63/8)] = > buffer[1135] it exceeded the array.
So I didn't understand how it works and it was weird as well because I could have x = 0 and y = 0 which indicated that in coordinates 0,0 I want to add a pixel so the buffer was buffer[0] okey, but if I want now pixel x = 0 and y = 1 then the buffer was buffer[0+128(1/8)] => buffer[16], and it was weird because it wasn't a shift of 128 bits like in OLED_DrawBitmap : (inverting_mask ^ bitmap[width*i + j]) & (1 << k)); in which the shift was exactly 128 from first line to second line. But in OLED_SetPixel I don't know.
And last example here is that x = 16 and y = 0 give me the same buffer as if I choose x = 0 and y = 1.
Like I said I don't understand complitelly how it works. If somebody have an idea how it works I would be really glad to hear it.
I've been trying to use OLED in STM32 and found some library for it. I tried to also understand what happens in each in case to change something inside of the library, and I've stumbled into a understanding problem.
C:
void OLED_SetPixel(uint8_t x, uint8_t y, bool color)
{
if(x < 0 || x > SCREEN_WIDTH || y < 0 || y > SCREEN_HEIGHT)
return;
if(color == OLED_COLOR_BLACK)
buffer[x + SCREEN_WIDTH * (y / 8)] &= ~(1 << (y % 8)); // Clear bit responsible for pixel
else if(color == OLED_COLOR_WHITE)
buffer[x + SCREEN_WIDTH * (y / 8)] |= (1 << (y % 8)); // Set bit responsible for pixel
}
void OLED_DrawBitmap(uint8_t x, uint8_t y, bool invert_color, uint8_t width, uint8_t height, const uint8_t* bitmap)
{
uint8_t inverting_mask = invert_color ? 0xFF : 0x00;
for(uint8_t i = 0; i < height/8; i++)
{
for(uint8_t j = 0; j < width; j++)
{
for(uint8_t k = 0; k < 8; k++)
{
OLED_SetPixel(x + j, y + 8*i + k, (inverting_mask ^ bitmap[width*i + j]) & (1 << k));
}
}
}
}
The screen is 128x64 so when each byte is 8 bit height then there was 1024, and the variable "k" was to read each bit in this byte. So in total the was like 8 scans from 0 to 127 of 8 bit hight picture each.
So now it's time to each bit/pixel put into OLED_SetPixel. In many OLED library there was the same setpixel function in which the buffer was an array of buffer[1024]. So I checked at the code and putted max values, x = 127 and y = 63, (SCREEN_WIDTH = 128) so buffer[127 + 128*(63/8)] = > buffer[1135] it exceeded the array.
So I didn't understand how it works and it was weird as well because I could have x = 0 and y = 0 which indicated that in coordinates 0,0 I want to add a pixel so the buffer was buffer[0] okey, but if I want now pixel x = 0 and y = 1 then the buffer was buffer[0+128(1/8)] => buffer[16], and it was weird because it wasn't a shift of 128 bits like in OLED_DrawBitmap : (inverting_mask ^ bitmap[width*i + j]) & (1 << k)); in which the shift was exactly 128 from first line to second line. But in OLED_SetPixel I don't know.
And last example here is that x = 16 and y = 0 give me the same buffer as if I choose x = 0 and y = 1.
Like I said I don't understand complitelly how it works. If somebody have an idea how it works I would be really glad to hear it.