Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

u8x8_draw_hvtile.c #1328

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions cppsrc/U8g2lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ class U8G2 : public Print
/* u8x8 interface */
uint8_t getCols(void) { return u8x8_GetCols(u8g2_GetU8x8(&u8g2)); }
uint8_t getRows(void) { return u8x8_GetRows(u8g2_GetU8x8(&u8g2)); }
void drawTile(uint8_t x, uint8_t y, uint8_t cnt, uint8_t *tile_ptr) {
u8x8_DrawTile(u8g2_GetU8x8(&u8g2), x, y, cnt, tile_ptr); }
void drawTile(uint8_t tx, uint8_t ty, uint8_t tile_cnt, uint8_t *tile_ptr) { /* for legacy compatiablity */
u8x8_DrawTile(u8g2_GetU8x8(&u8g2), tx, ty, tile_cnt, 1/*copies*/, tile_cnt/*tile_buffer_width*/, tile_ptr); }
void drawTile(uint8_t tx, uint8_t ty, uint8_t tile_cnt, uint8_t copies, uint8_t tile_buffer_width, uint8_t *tile_ptr) {
u8x8_DrawTile(u8g2_GetU8x8(&u8g2), tx, ty, tile_cnt, copies, tile_buffer_width, tile_ptr); }

#ifdef U8X8_WITH_USER_PTR
void *getUserPtr() { return u8g2_GetUserPtr(&u8g2); }
Expand Down
964 changes: 962 additions & 2 deletions cppsrc/U8x8lib.h

Large diffs are not rendered by default.

23 changes: 15 additions & 8 deletions csrc/u8g2_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static void u8g2_send_tile_row(u8g2_t *u8g2, uint8_t src_tile_row, uint8_t dest_
offset *= w;
offset *= 8;
ptr += offset;
u8x8_DrawTile(u8g2_GetU8x8(u8g2), 0, dest_tile_row, w, ptr);
u8x8_DrawTile(u8g2_GetU8x8(u8g2), 0/*tx*/, dest_tile_row/*ty*/, w/*tile_cnt*/, 1/*copies*/, w/*tile_buffer_width*/, ptr);
}

/*
Expand Down Expand Up @@ -153,25 +153,32 @@ uint8_t u8g2_NextPage(u8g2_t *u8g2)
void u8g2_UpdateDisplayArea(u8g2_t *u8g2, uint8_t tx, uint8_t ty, uint8_t tw, uint8_t th)
{
uint16_t page_size;
uint8_t tile_buffer_width;
uint8_t *ptr;

/* check, whether we are in full buffer mode */
if ( u8g2->tile_buf_height != u8g2_GetU8x8(u8g2)->display_info->tile_height )
return; /* not in full buffer mode, do nothing */

page_size = u8g2->pixel_buf_width; /* 8*u8g2->u8g2_GetU8x8(u8g2)->display_info->tile_width */

tile_buffer_width = u8g2_GetU8x8(u8g2)->display_info->tile_width;
page_size = u8g2->pixel_buf_width; /* 8*u8g2_GetU8x8(u8g2)->display_info->tile_width */

ptr = u8g2_GetBufferPtr(u8g2);
ptr += tx*8;

if(u8g2->ll_hvline == u8g2_ll_hvline_vertical_top_lsb){
ptr += tx*8; /* 8 bytes across per tile, stacked vertically */
}else{
ptr += tx; /* 1 byte across per tile, stacked horizontally */
}
ptr += page_size*ty;

while( th > 0 )
{
u8x8_DrawTile( u8g2_GetU8x8(u8g2), tx, ty, tw, ptr );
u8x8_DrawTile( u8g2_GetU8x8(u8g2), tx, ty, tw/*tile_cnt*/, 1/*copies*/, tile_buffer_width, ptr );
ptr += page_size;
ty++;
th--;
}
}
}

/* same as sendBuffer, but does not send the ePaper refresh message */
Expand Down
31 changes: 27 additions & 4 deletions csrc/u8x8.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,7 @@ typedef struct u8x8_tile_struct u8x8_tile_t;
typedef uint8_t (*u8x8_msg_cb)(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
typedef uint16_t (*u8x8_char_cb)(u8x8_t *u8x8, uint8_t b);



typedef uint8_t (*u8x8_draw_hvtile_cb)(u8x8_t *u8x8, uint8_t tx, uint8_t ty, uint8_t tile_cnt, uint8_t copies, uint8_t tile_buffer_width, uint8_t *tile_ptr);

//struct u8x8_mcd_struct
//{
Expand All @@ -215,6 +214,7 @@ struct u8x8_tile_struct
uint8_t cnt; /* number of tiles */
uint8_t x_pos; /* tile x position */
uint8_t y_pos; /* tile y position */
uint8_t buffer_width; /* tile width of buffer */
};


Expand Down Expand Up @@ -328,6 +328,7 @@ struct u8x8_struct
const u8x8_display_info_t *display_info;
u8x8_char_cb next_cb; /* procedure, which will be used to get the next char from the string */
u8x8_msg_cb display_cb;
u8x8_draw_hvtile_cb draw_hvtile_cb; /* draw hvtile procedure */
u8x8_msg_cb cad_cb;
u8x8_msg_cb byte_cb;
u8x8_msg_cb gpio_and_delay_cb;
Expand Down Expand Up @@ -474,12 +475,13 @@ void u8x8_d_helper_display_init(u8x8_t *u8g2);
/*
Name: U8X8_MSG_DISPLAY_DRAW_TILE
Args:
arg_int: How often to repeat this tile pattern
arg_int: How many copies of this tile pattern
arg_ptr: pointer to u8x8_tile_t
uint8_t *tile_ptr; pointer to one or more tiles (number is "cnt")
uint8_t cnt; number of tiles
uint8_t x_pos; first tile x position
uint8_t y_pos; first tile y position
uint8_t buffer_width tile width of buffer
Tasks:
One tile has exactly 8 bytes (8x8 pixel monochrome bitmap).
The lowest bit of the first byte is the upper left corner
Expand Down Expand Up @@ -531,10 +533,16 @@ uint8_t u8x8_dummy_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
void u8x8_SetupDefaults(u8x8_t *u8x8); /* do not use this, use u8x8_Setup() instead */

void u8x8_Setup(u8x8_t *u8x8, u8x8_msg_cb display_cb, u8x8_msg_cb cad_cb, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb);
/*
draw_hvtile_cb: one of:
u8x8_draw_hvtile_vertical_top_lsb
u8x8_draw_hvtile_horizontal_right_lsb
*/
void u8x8_SetupTile(u8x8_t *u8x8, u8x8_draw_hvtile_cb draw_hvtile_cb);

/*==========================================*/
/* u8x8_display.c */
uint8_t u8x8_DrawTile(u8x8_t *u8x8, uint8_t x, uint8_t y, uint8_t cnt, uint8_t *tile_ptr);
uint8_t u8x8_DrawTile(u8x8_t *u8x8, uint8_t tx, uint8_t ty, uint8_t tile_cnt, uint8_t copies, uint8_t tile_buffer_width, uint8_t *tile_ptr);

/*
After a call to u8x8_SetupDefaults,
Expand All @@ -561,7 +569,22 @@ void u8x8_FillDisplay(u8x8_t *u8x8);
void u8x8_RefreshDisplay(u8x8_t *u8x8); // make RAM content visible on the display (Dec 16: SSD1606 only)
void u8x8_ClearLine(u8x8_t *u8x8, uint8_t line);

/*==========================================*/
/* u8x8_draw_hvtile.c */
/*
Called by u8x8 to adjust tile buffer pixel byte orentiation for display.
Vertical or Horizontal stacked
x,y tile position
tile_cnt number of tiles to draw
copies number of copies of tile pattern to draw
tile_buffer_width tile width of buffer being used for drawing
tile_ptr tile buffer
*/

/* SSD13xx, UC17xx, UC16xx */
uint8_t u8x8_draw_hvtile_vertical_top_lsb(u8x8_t *u8x8, uint8_t tx, uint8_t ty, uint8_t tile_cnt, uint8_t copies, uint8_t tile_buffer_width, uint8_t *tile_ptr);
/* SH1122, LD7032, ST7920, ST7986, LC7981, T6963, SED1330, RA8835, MAX7219, LS0 */
uint8_t u8x8_draw_hvtile_horizontal_right_lsb(u8x8_t *u8x8, uint8_t tx, uint8_t ty, uint8_t tile_cnt, uint8_t copies, uint8_t tile_buffer_width, uint8_t *tile_ptr);

/*==========================================*/
/* Command Arg Data (CAD) Interface */
Expand Down
21 changes: 14 additions & 7 deletions csrc/u8x8_8x8.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ void u8x8_DrawGlyph(u8x8_t *u8x8, uint8_t x, uint8_t y, uint8_t encoding)
do
{
u8x8_get_glyph_data(u8x8, encoding, buf, tile);
u8x8_DrawTile(u8x8, xx, y, 1, buf);
u8x8->draw_hvtile_cb(u8x8, xx, y, 1/*tile_cnt*/, 1/*copies*/, 1/*tile_buffer_width*/, buf);
// u8x8_DrawTile(u8x8, xx, y, 1, buf);
tile++;
xx++;
} while( xx < th );
Expand Down Expand Up @@ -191,16 +192,20 @@ static void u8x8_draw_2x2_subglyph(u8x8_t *u8x8, uint8_t x, uint8_t y, uint8_t e
buf2[i] = t & 255;
}
u8x8_upscale_buf(buf2, buf);
u8x8_DrawTile(u8x8, x, y, 1, buf);
u8x8->draw_hvtile_cb(u8x8, x, y, 1/*tile_cnt*/, 1/*copies*/, 1/*tile_buffer_width*/, buf);
// u8x8_DrawTile(u8x8, x, y, 1, buf);

u8x8_upscale_buf(buf2+4, buf);
u8x8_DrawTile(u8x8, x+1, y, 1, buf);
u8x8->draw_hvtile_cb(u8x8, x+1, y, 1/*tile_cnt*/, 1/*copies*/, 1/*tile_buffer_width*/, buf);
// u8x8_DrawTile(u8x8, x+1, y, 1, buf);

u8x8_upscale_buf(buf1, buf);
u8x8_DrawTile(u8x8, x, y+1, 1, buf);
u8x8->draw_hvtile_cb(u8x8, x, y+1, 1/*tile_cnt*/, 1/*copies*/, 1/*tile_buffer_width*/, buf);
// u8x8_DrawTile(u8x8, x, y+1, 1, buf);

u8x8_upscale_buf(buf1+4, buf);
u8x8_DrawTile(u8x8, x+1, y+1, 1, buf);
u8x8->draw_hvtile_cb(u8x8, x+1, y+1, 1/*tile_cnt*/, 1/*copies*/, 1/*tile_buffer_width*/, buf);
// u8x8_DrawTile(u8x8, x+1, y+1, 1, buf);
}


Expand Down Expand Up @@ -242,8 +247,10 @@ static void u8x8_draw_1x2_subglyph(u8x8_t *u8x8, uint8_t x, uint8_t y, uint8_t e
buf1[i] = t >> 8;
buf2[i] = t & 255;
}
u8x8_DrawTile(u8x8, x, y, 1, buf2);
u8x8_DrawTile(u8x8, x, y+1, 1, buf1);
u8x8->draw_hvtile_cb(u8x8, x, y, 1/*tile_cnt*/, 1/*copies*/, 1/*tile_buffer_width*/, buf2);
u8x8->draw_hvtile_cb(u8x8, x, y+1, 1/*tile_cnt*/, 1/*copies*/, 1/*tile_buffer_width*/, buf1);
// u8x8_DrawTile(u8x8, x, y, 1, buf2);
// u8x8_DrawTile(u8x8, x, y+1, 1, buf1);
}

void u8x8_Draw1x2Glyph(u8x8_t *u8x8, uint8_t x, uint8_t y, uint8_t encoding)
Expand Down
39 changes: 31 additions & 8 deletions csrc/u8x8_capture.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ static void u8x8_capture_memory_copy(uint8_t *dest, uint8_t *src, uint16_t cnt)
}
}

static void u8x8_capture_DrawTiles(u8x8_capture_t *capture, uint8_t tx, uint8_t ty, uint8_t tile_cnt, uint8_t *tile_ptr)
/* vertical top lsb memory architecture */
static void u8x8_capture_DrawTiles_1(u8x8_capture_t *capture, uint8_t tx, uint8_t ty, uint8_t tile_cnt, uint8_t tile_buffer_width, uint8_t *tile_ptr)
{
uint8_t *dest_ptr = capture->buffer;
//printf("tile pos: %d %d, cnt=%d\n", tx, ty, tile_cnt);
Expand All @@ -212,22 +213,44 @@ static void u8x8_capture_DrawTiles(u8x8_capture_t *capture, uint8_t tx, uint8_t
u8x8_capture_memory_copy(dest_ptr, tile_ptr, tile_cnt*8);
}

/* horizontal right lsb memory architecture */
/* SH1122, LD7032, ST7920, ST7986, LC7981, T6963, SED1330, RA8835, MAX7219, LS0 */
static void u8x8_capture_DrawTiles_2(u8x8_capture_t *capture, uint8_t tx, uint8_t ty, uint8_t tile_cnt, uint8_t tile_buffer_width, uint8_t *tile_ptr)
{
uint8_t *dest_ptr = capture->buffer;
//printf("tile pos: %d %d, cnt=%d\n", tx, ty, tile_cnt);
if ( dest_ptr == NULL )
return;
dest_ptr += (uint16_t)ty*capture->tile_width*8;
dest_ptr += (uint16_t)tx;
for(int i=0;i<8;i++){ /* 8x copy = 8x pixel rows per tile */
u8x8_capture_memory_copy(dest_ptr, tile_ptr, tile_cnt);
dest_ptr += capture->tile_width;
tile_ptr += tile_buffer_width;
}
}
uint8_t u8x8_d_capture(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
if ( msg == U8X8_MSG_DISPLAY_DRAW_TILE )
{
uint8_t x, y, c;
uint8_t tx, ty, tc, tw, arg;
uint8_t *ptr;
x = ((u8x8_tile_t *)arg_ptr)->x_pos;
y = ((u8x8_tile_t *)arg_ptr)->y_pos;
c = ((u8x8_tile_t *)arg_ptr)->cnt;
tx = ((u8x8_tile_t *)arg_ptr)->x_pos;
ty = ((u8x8_tile_t *)arg_ptr)->y_pos;
tc = ((u8x8_tile_t *)arg_ptr)->cnt;
tw = ((u8x8_tile_t *)arg_ptr)->buffer_width;
ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
arg = arg_int;
do
{
u8x8_capture_DrawTiles(&u8x8_capture, x, y, c, ptr);
if(u8x8->ll_hvtile == u8x8_ll_hvtile_vertical_top_lsb){
u8x8_capture_DrawTiles_1(&u8x8_capture, tx, ty, tc, tw, ptr);
}else{
u8x8_capture_DrawTiles_2(&u8x8_capture, tx, ty, tc, tw, ptr);
}
x += c;
arg_int--;
} while( arg_int > 0 );
arg--;
} while( arg > 0 ); /* arg_int = number of copies of tile pattern */
}
return u8x8_capture.old_cb(u8x8, msg, arg_int, arg_ptr);
}
Expand Down
37 changes: 13 additions & 24 deletions csrc/u8x8_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,16 @@ void u8x8_d_helper_display_init(u8x8_t *u8x8)
/*==========================================*/
/* official functions */

uint8_t u8x8_DrawTile(u8x8_t *u8x8, uint8_t x, uint8_t y, uint8_t cnt, uint8_t *tile_ptr)
uint8_t u8x8_DrawTile(u8x8_t *u8x8, uint8_t tx, uint8_t ty, uint8_t tile_cnt, uint8_t copies, uint8_t tile_buffer_width, uint8_t *tile_ptr)
{
u8x8_tile_t tile;
tile.x_pos = x;
tile.y_pos = y;
tile.cnt = cnt;
tile.x_pos = tx;
tile.y_pos = ty;
tile.cnt = tile_cnt;
tile.buffer_width = tile_buffer_width;
tile.tile_ptr = tile_ptr;
return u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_DRAW_TILE, 1, (void *)&tile);

return u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_DRAW_TILE, copies, (void *)&tile);
}

/* should be implemented as macro */
Expand Down Expand Up @@ -122,20 +124,11 @@ void u8x8_RefreshDisplay(u8x8_t *u8x8)

void u8x8_ClearDisplayWithTile(u8x8_t *u8x8, const uint8_t *buf)
{
u8x8_tile_t tile;
uint8_t h;

tile.x_pos = 0;
tile.cnt = 1;
tile.tile_ptr = (uint8_t *)buf; /* tile_ptr should be const, but isn't */

h = u8x8->display_info->tile_height;
tile.y_pos = 0;
do
{
u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_DRAW_TILE, u8x8->display_info->tile_width, (void *)&tile);
tile.y_pos++;
} while( tile.y_pos < h );
uint8_t line=0;
do {
u8x8->draw_hvtile_cb(u8x8, 0/*tx*/, line/*ty*/, 1/*tile_cnt*/, u8x8->display_info->tile_width/*copies*/, 1/*tile_buffer_width*/, buf);
line++;
} while( line < u8x8->display_info->tile_height );
}

void u8x8_ClearDisplay(u8x8_t *u8x8)
Expand All @@ -156,10 +149,6 @@ void u8x8_ClearLine(u8x8_t *u8x8, uint8_t line)
u8x8_tile_t tile;
if ( line < u8x8->display_info->tile_height )
{
tile.x_pos = 0;
tile.y_pos = line;
tile.cnt = 1;
tile.tile_ptr = (uint8_t *)buf; /* tile_ptr should be const, but isn't */
u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_DRAW_TILE, u8x8->display_info->tile_width, (void *)&tile);
u8x8->draw_hvtile_cb(u8x8, 0/*tx*/, line/*ty*/, 1/*tile_cnt*/, u8x8->display_info->tile_width/*copies*/, 1/*tile_buffer_width*/, buf);
}
}
Loading