nowa wersja write_to_buffer
This commit is contained in:
@@ -85,6 +85,8 @@ void ssd1306_set_pixel(uint8_t x, uint8_t y, uint8_t bw);
|
||||
void ssd1306_write_to_buffer(const uint8_t* data, uint8_t width, uint8_t height, int8_t pos_x, int8_t pos_y);
|
||||
void ssd1306_clear_buffer (uint8_t width, uint8_t height, uint8_t pos_x, uint8_t pos_y);
|
||||
|
||||
void next(const uint8_t* bitmap, uint8_t bitmap_width, uint8_t bitmap_height, int8_t pos_x, int8_t pos_y);
|
||||
|
||||
#ifdef TEST
|
||||
extern uint8_t buffer_oled[SSD1306_BUF_SIZE];
|
||||
#endif
|
||||
|
||||
@@ -236,38 +236,83 @@ void ssd1306_clear_buffer (uint8_t width, uint8_t height, uint8_t pos_x, uint8_t
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
//void next(void)
|
||||
//{
|
||||
// uint16_t tmp;
|
||||
// for(uint8_t col = col_start; col < col_end; col++, bitmap_col++)
|
||||
// {
|
||||
// tmp = buffer_oled[page_start * SSD1306_LCDWIDTH + col] & (0xFF >> (8 - pos_y%8));
|
||||
//
|
||||
// for( uint8_t page = page_start; page < page_end; page++, bitmap_row++ )
|
||||
// {
|
||||
// bitmap_idx = bitmap_width * bitmap_row + bitmap_col;
|
||||
//
|
||||
// if (bitmap_idx < bitmap_max_idx)
|
||||
// {
|
||||
//// mask_buf = 0xFF;
|
||||
//
|
||||
// pixels_left = bitmap_height - bitmap_row * 8; //poprawic
|
||||
// if (pixels_left < 8)
|
||||
// {
|
||||
// mask_buf = 0xFF >> pixels_left;
|
||||
// }
|
||||
//
|
||||
// tmp &= ~(mask_buf); // mask_buf zeruje tylko to co zostanie nadpisane
|
||||
// tmp |= bitmap[bitmap_idx] << pos_y%8; // mask_data maskuje tylko starsza czesc bajtu
|
||||
// }
|
||||
//
|
||||
// buffer_oled[page * SSD1306_LCDWIDTH + col] = (uint8_t) tmp;
|
||||
// tmp = tmp >> 8;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
||||
//
|
||||
//
|
||||
|
||||
void next(const uint8_t* bitmap, uint8_t bitmap_width, uint8_t bitmap_height, int8_t pos_x, int8_t pos_y)
|
||||
{
|
||||
if (bitmap_width + pos_x < 0 || bitmap_height + pos_y < 0) return;
|
||||
|
||||
uint16_t tmp, bitmap_idx, bitmap_max_idx;
|
||||
uint8_t buf_row_first, buf_row_last, buf_col_first, buf_col_last, bitmap_col, bitmap_row, bitmap_row_first;
|
||||
uint8_t mask_buf;
|
||||
|
||||
if (pos_x < 0)
|
||||
{
|
||||
bitmap_col = pos_x * -1;
|
||||
buf_col_first = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
bitmap_col = 0;
|
||||
buf_col_first = pos_x;
|
||||
}
|
||||
|
||||
if (pos_y < 0)
|
||||
{
|
||||
bitmap_row_first = (pos_y * -1) / 8;
|
||||
buf_row_first = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
bitmap_row_first = 0;
|
||||
buf_row_first = pos_y / 8;
|
||||
}
|
||||
|
||||
bitmap_max_idx = bitmap_width * ((bitmap_height + 7) / 8);
|
||||
buf_col_last = (bitmap_width + pos_x) > SSD1306_LCDWIDTH ? SSD1306_LCDWIDTH : (bitmap_width + pos_x);
|
||||
// buf_row_last = (bitmap_height + pos_y) > SSD1306_LCDHEIGHT ? SSD1306_LCDHEIGHT / 8: (bitmap_height + pos_y + 7) / 8;
|
||||
if (bitmap_height + pos_y > SSD1306_LCDHEIGHT)
|
||||
{
|
||||
buf_row_last = SSD1306_LCDHEIGHT / 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
buf_row_last = (bitmap_height + pos_y + 7) / 8;
|
||||
}
|
||||
|
||||
for(uint8_t col = buf_col_first; col < buf_col_last; col++, bitmap_col++)
|
||||
{
|
||||
tmp = 0;
|
||||
bitmap_row = bitmap_row_first;
|
||||
for( uint8_t buf_row = buf_row_first; buf_row < buf_row_last; buf_row++, bitmap_row++ )
|
||||
{
|
||||
bitmap_idx = bitmap_width * bitmap_row + bitmap_col;
|
||||
|
||||
mask_buf = 0;
|
||||
|
||||
if (bitmap_row == 0)
|
||||
{
|
||||
mask_buf |= 0xFF >> (8 - pos_y%8);
|
||||
}
|
||||
|
||||
uint8_t shifted_pixels_left = (pos_y + bitmap_height) - bitmap_row * 8;
|
||||
if (shifted_pixels_left < 8)
|
||||
{
|
||||
mask_buf |= (0xFF << shifted_pixels_left);
|
||||
}
|
||||
|
||||
tmp |= buffer_oled[buf_row * SSD1306_LCDWIDTH + col] & mask_buf;
|
||||
|
||||
if (bitmap_idx < bitmap_max_idx)
|
||||
{
|
||||
tmp |= bitmap[bitmap_idx] << pos_y%8;
|
||||
}
|
||||
|
||||
buffer_oled[buf_row * SSD1306_LCDWIDTH + col] = (uint8_t) tmp;
|
||||
tmp = tmp >> 8;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user