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_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 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
|
#ifdef TEST
|
||||||
extern uint8_t buffer_oled[SSD1306_BUF_SIZE];
|
extern uint8_t buffer_oled[SSD1306_BUF_SIZE];
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -236,38 +236,83 @@ void ssd1306_clear_buffer (uint8_t width, uint8_t height, uint8_t pos_x, uint8_t
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
//void next(void)
|
void next(const uint8_t* bitmap, uint8_t bitmap_width, uint8_t bitmap_height, int8_t pos_x, int8_t pos_y)
|
||||||
//{
|
{
|
||||||
// uint16_t tmp;
|
if (bitmap_width + pos_x < 0 || bitmap_height + pos_y < 0) return;
|
||||||
// for(uint8_t col = col_start; col < col_end; col++, bitmap_col++)
|
|
||||||
// {
|
uint16_t tmp, bitmap_idx, bitmap_max_idx;
|
||||||
// tmp = buffer_oled[page_start * SSD1306_LCDWIDTH + col] & (0xFF >> (8 - pos_y%8));
|
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;
|
||||||
// for( uint8_t page = page_start; page < page_end; page++, bitmap_row++ )
|
|
||||||
// {
|
if (pos_x < 0)
|
||||||
// bitmap_idx = bitmap_width * bitmap_row + bitmap_col;
|
{
|
||||||
//
|
bitmap_col = pos_x * -1;
|
||||||
// if (bitmap_idx < bitmap_max_idx)
|
buf_col_first = 0;
|
||||||
// {
|
}
|
||||||
//// mask_buf = 0xFF;
|
else
|
||||||
//
|
{
|
||||||
// pixels_left = bitmap_height - bitmap_row * 8; //poprawic
|
bitmap_col = 0;
|
||||||
// if (pixels_left < 8)
|
buf_col_first = pos_x;
|
||||||
// {
|
}
|
||||||
// mask_buf = 0xFF >> pixels_left;
|
|
||||||
// }
|
if (pos_y < 0)
|
||||||
//
|
{
|
||||||
// tmp &= ~(mask_buf); // mask_buf zeruje tylko to co zostanie nadpisane
|
bitmap_row_first = (pos_y * -1) / 8;
|
||||||
// tmp |= bitmap[bitmap_idx] << pos_y%8; // mask_data maskuje tylko starsza czesc bajtu
|
buf_row_first = 0;
|
||||||
// }
|
}
|
||||||
//
|
else
|
||||||
// buffer_oled[page * SSD1306_LCDWIDTH + col] = (uint8_t) tmp;
|
{
|
||||||
// tmp = tmp >> 8;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ void tearDown(void)
|
|||||||
void test_wrtie_to_buffer_at_pos_0_0_height_8pt(void)
|
void test_wrtie_to_buffer_at_pos_0_0_height_8pt(void)
|
||||||
{
|
{
|
||||||
// uint8_t data[8] = {};
|
// uint8_t data[8] = {};
|
||||||
ssd1306_write_to_buffer(picture_8pt, SSD1306_LCDWIDTH, 8, 0, 0);
|
next(picture_8pt, SSD1306_LCDWIDTH, 8, 0, 0);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_UINT8_ARRAY(posX_0_posY_0_8pt, buffer_oled, SSD1306_BUF_SIZE);
|
TEST_ASSERT_EQUAL_UINT8_ARRAY(posX_0_posY_0_8pt, buffer_oled, SSD1306_BUF_SIZE);
|
||||||
// TEST_ASSERT_EQUAL_UINT8(0xFF, buffer_oled[8]);
|
// TEST_ASSERT_EQUAL_UINT8(0xFF, buffer_oled[8]);
|
||||||
@@ -29,14 +29,14 @@ void test_wrtie_to_buffer_at_pos_0_0_height_8pt(void)
|
|||||||
void test_wrtie_to_buffer_at_pos_1_0_height_8pt(void)
|
void test_wrtie_to_buffer_at_pos_1_0_height_8pt(void)
|
||||||
{
|
{
|
||||||
// uint8_t data[8] = {};
|
// uint8_t data[8] = {};
|
||||||
ssd1306_write_to_buffer(picture_8pt, SSD1306_LCDWIDTH, 8, 0, 1);
|
next(picture_8pt, SSD1306_LCDWIDTH, 8, 0, 1);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_UINT8_ARRAY(posX_0_posY_1_8pt, buffer_oled, SSD1306_BUF_SIZE);
|
TEST_ASSERT_EQUAL_UINT8_ARRAY(posX_0_posY_1_8pt, buffer_oled, SSD1306_BUF_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_wrtie_to_buffer_at_pos_7_0_height_8pt(void)
|
void test_wrtie_to_buffer_at_pos_7_0_height_8pt(void)
|
||||||
{
|
{
|
||||||
ssd1306_write_to_buffer(picture_8pt, SSD1306_LCDWIDTH, 8, 0, 7);
|
next(picture_8pt, SSD1306_LCDWIDTH, 8, 0, 7);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_UINT8_ARRAY(posX_0_posY_7_8pt, buffer_oled, SSD1306_BUF_SIZE);
|
TEST_ASSERT_EQUAL_UINT8_ARRAY(posX_0_posY_7_8pt, buffer_oled, SSD1306_BUF_SIZE);
|
||||||
}
|
}
|
||||||
@@ -44,7 +44,7 @@ void test_wrtie_to_buffer_at_pos_7_0_height_8pt(void)
|
|||||||
void test_wrtie_to_buffer_at_pos_0_0_height_16pt(void)
|
void test_wrtie_to_buffer_at_pos_0_0_height_16pt(void)
|
||||||
{
|
{
|
||||||
// uint8_t data[8] = {};
|
// uint8_t data[8] = {};
|
||||||
ssd1306_write_to_buffer(picture_16pt, SSD1306_LCDWIDTH, 16, 0, 0);
|
next(picture_16pt, SSD1306_LCDWIDTH, 16, 0, 0);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_UINT8_ARRAY(posX_0_posY_0_16pt, buffer_oled, SSD1306_BUF_SIZE);
|
TEST_ASSERT_EQUAL_UINT8_ARRAY(posX_0_posY_0_16pt, buffer_oled, SSD1306_BUF_SIZE);
|
||||||
// TEST_ASSERT_EQUAL_UINT8(0xFF, buffer_oled[8]);
|
// TEST_ASSERT_EQUAL_UINT8(0xFF, buffer_oled[8]);
|
||||||
@@ -53,14 +53,14 @@ void test_wrtie_to_buffer_at_pos_0_0_height_16pt(void)
|
|||||||
void test_wrtie_to_buffer_at_pos_1_0_height_16pt(void)
|
void test_wrtie_to_buffer_at_pos_1_0_height_16pt(void)
|
||||||
{
|
{
|
||||||
// uint8_t data[8] = {};
|
// uint8_t data[8] = {};
|
||||||
ssd1306_write_to_buffer(picture_16pt, SSD1306_LCDWIDTH, 16, 0, 1);
|
next(picture_16pt, SSD1306_LCDWIDTH, 16, 0, 1);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_UINT8_ARRAY(posX_0_posY_1_16pt, buffer_oled, SSD1306_BUF_SIZE);
|
TEST_ASSERT_EQUAL_UINT8_ARRAY(posX_0_posY_1_16pt, buffer_oled, SSD1306_BUF_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_wrtie_to_buffer_at_pos_7_0_height_16pt(void)
|
void test_wrtie_to_buffer_at_pos_7_0_height_16pt(void)
|
||||||
{
|
{
|
||||||
ssd1306_write_to_buffer(picture_16pt, SSD1306_LCDWIDTH, 16, 0, 7);
|
next(picture_16pt, SSD1306_LCDWIDTH, 16, 0, 7);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_UINT8_ARRAY(posX_0_posY_7_16pt, buffer_oled, SSD1306_BUF_SIZE);
|
TEST_ASSERT_EQUAL_UINT8_ARRAY(posX_0_posY_7_16pt, buffer_oled, SSD1306_BUF_SIZE);
|
||||||
}
|
}
|
||||||
@@ -68,7 +68,7 @@ void test_wrtie_to_buffer_at_pos_7_0_height_16pt(void)
|
|||||||
void test_wrtie_to_buffer_at_pos_0_0_height_12pt(void)
|
void test_wrtie_to_buffer_at_pos_0_0_height_12pt(void)
|
||||||
{
|
{
|
||||||
// uint8_t data[8] = {};
|
// uint8_t data[8] = {};
|
||||||
ssd1306_write_to_buffer(picture_12pt, SSD1306_LCDWIDTH, 12, 0, 0);
|
next(picture_12pt, SSD1306_LCDWIDTH, 12, 0, 0);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_UINT8_ARRAY(posX_0_posY_0_12pt, buffer_oled, SSD1306_BUF_SIZE);
|
TEST_ASSERT_EQUAL_UINT8_ARRAY(posX_0_posY_0_12pt, buffer_oled, SSD1306_BUF_SIZE);
|
||||||
// TEST_ASSERT_EQUAL_UINT8(0xFF, buffer_oled[8]);
|
// TEST_ASSERT_EQUAL_UINT8(0xFF, buffer_oled[8]);
|
||||||
@@ -77,7 +77,7 @@ void test_wrtie_to_buffer_at_pos_0_0_height_12pt(void)
|
|||||||
void test_wrtie_to_buffer_at_pos_1_0_height_12pt(void)
|
void test_wrtie_to_buffer_at_pos_1_0_height_12pt(void)
|
||||||
{
|
{
|
||||||
// uint8_t data[8] = {};
|
// uint8_t data[8] = {};
|
||||||
ssd1306_write_to_buffer(picture_12pt, SSD1306_LCDWIDTH, 12, 0, 1);
|
next(picture_12pt, SSD1306_LCDWIDTH, 12, 0, 1);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_UINT8_ARRAY(posX_0_posY_1_12pt, buffer_oled, SSD1306_BUF_SIZE);
|
TEST_ASSERT_EQUAL_UINT8_ARRAY(posX_0_posY_1_12pt, buffer_oled, SSD1306_BUF_SIZE);
|
||||||
}
|
}
|
||||||
@@ -85,7 +85,7 @@ void test_wrtie_to_buffer_at_pos_1_0_height_12pt(void)
|
|||||||
void test_wrtie_to_buffer_at_pos_0_4_height_12pt(void)
|
void test_wrtie_to_buffer_at_pos_0_4_height_12pt(void)
|
||||||
{
|
{
|
||||||
// uint8_t data[8] = {};
|
// uint8_t data[8] = {};
|
||||||
ssd1306_write_to_buffer(picture_12pt, SSD1306_LCDWIDTH, 12, 0, 4);
|
next(picture_12pt, SSD1306_LCDWIDTH, 12, 0, 4);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_UINT8_ARRAY(posX_0_posY_4_12pt, buffer_oled, SSD1306_BUF_SIZE);
|
TEST_ASSERT_EQUAL_UINT8_ARRAY(posX_0_posY_4_12pt, buffer_oled, SSD1306_BUF_SIZE);
|
||||||
// TEST_ASSERT_EQUAL_UINT8(0xFF, buffer_oled[8]);
|
// TEST_ASSERT_EQUAL_UINT8(0xFF, buffer_oled[8]);
|
||||||
@@ -93,7 +93,7 @@ void test_wrtie_to_buffer_at_pos_0_4_height_12pt(void)
|
|||||||
|
|
||||||
void test_wrtie_to_buffer_at_pos_7_0_height_12pt(void)
|
void test_wrtie_to_buffer_at_pos_7_0_height_12pt(void)
|
||||||
{
|
{
|
||||||
ssd1306_write_to_buffer(picture_12pt, SSD1306_LCDWIDTH, 12, 0, 7);
|
next(picture_12pt, SSD1306_LCDWIDTH, 12, 0, 7);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_UINT8_ARRAY(posX_0_posY_7_12pt, buffer_oled, SSD1306_BUF_SIZE);
|
TEST_ASSERT_EQUAL_HEX8_ARRAY(posX_0_posY_7_12pt, buffer_oled, SSD1306_BUF_SIZE);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user