void glcd_tiny_draw_char(uint8_t x, uint8_t line, char c) { uint8_t i; /* Only works for fonts < 8 bits in height */ if (font_current.height >= 8) { return; } if (c < font_current.start_char || c > font_current.end_char) { c = '.'; } if ( line >= GLCD_LCD_HEIGHT / (font_current.height + 1) ) { return; } if ( (x+font_current.width) >= GLCD_LCD_WIDTH ) { return; } glcd_update_bbox(x, line*(font_current.height + 1), x+font_current.width, line*(font_current.height + 1) + (font_current.height + 1)); for ( i = 0; i < font_current.width; i++ ) { glcd_buffer_selected[x + (line * GLCD_LCD_WIDTH)] = *( font_current.font_table + ((c - font_current.start_char) * (font_current.width)) + i ); x++; } }
void glcd_draw_rect_thick(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t tx, uint8_t ty, uint8_t color) { int16_t i, t; if (tx == 0) { tx = 1; } if (ty == 0) { ty = 1; } for (i=x; i<x+w; i++) { /* Top and bottom sides */ for (t=0; t<(ty); t++) { glcd_set_pixel(i, y+t, color); glcd_set_pixel(i, y+h-1-t, color); } } for (i=y; i<y+h; i++) { /* Left and right sides */ for (t=0; t<(tx); t++) { glcd_set_pixel(x+t, i, color); glcd_set_pixel(x+w-1-t, i, color); } } glcd_update_bbox(x, y, x+w-1, y+h-1); }
void glcd_tiny_draw_char_xy(uint8_t x, uint8_t y, char c) { uint8_t i; uint8_t xvar, yvar; uint8_t dat; /* Only works for fonts < 8 bits in height */ /* Check all important bounds requirements are okay */ if ( (y >= GLCD_LCD_HEIGHT) || ((x+font_current.width) >= GLCD_LCD_WIDTH) || (font_current.height >= 8) || font_current.table_type != STANG) { return; } if (c < font_current.start_char || c > font_current.end_char) { c = '.'; } xvar = x; for ( i = 0; i < font_current.width; i++ ) { dat = *( font_current.font_table + ((c - font_current.start_char) * (font_current.width)) + i ); for (yvar = 0; yvar < font_current.height; yvar++) { glcd_set_pixel(xvar,y+yvar, (dat & (1<<yvar) ? 1 : 0) ); } xvar++; } glcd_update_bbox(x, y, x+font_current.width,y+font_current.height); }
void glcd_invert_pixel(uint8_t x, uint8_t y) { if ((x >= GLCD_LCD_WIDTH) || (y >= GLCD_LCD_HEIGHT)) { return; } glcd_update_bbox(x,y,x,y); glcd_buffer[x+ (y/8)*GLCD_LCD_WIDTH] ^= ( 1 << (y%8)); }
void glcd_fill_rect(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t color) { int16_t i; for (i=x; i<x+w; i++) { int16_t j; for (j=y; j<y+h; j++) { glcd_set_pixel(i, j, color); } } glcd_update_bbox(x, y, x+w-1, y+h-1); }
void glcd_draw_rect(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t color) { int16_t i; for (i=x; i<x+w; i++) { glcd_set_pixel(i, y, color); glcd_set_pixel(i, y+h-1, color); } for (i=y; i<y+h; i++) { glcd_set_pixel(x, i, color); glcd_set_pixel(x+w-1, i, color); } glcd_update_bbox(x, y, x+w-1, y+h-1); }
void glcd_scroll_line(void) { uint8_t y; uint8_t number_of_rows = GLCD_LCD_HEIGHT / 8; for (y=0; y<number_of_rows; y++) { if (y < (number_of_rows - 1)) { /* All lines except the last */ memcpy(glcd_buffer_selected + y*GLCD_LCD_WIDTH, glcd_buffer_selected + y*GLCD_LCD_WIDTH + GLCD_LCD_WIDTH, GLCD_LCD_WIDTH); } else { /* Last line, clear it */ memset(glcd_buffer_selected + (number_of_rows - 1)*GLCD_LCD_WIDTH, 0x00, GLCD_LCD_WIDTH); } } glcd_update_bbox(0,0,GLCD_LCD_WIDTH - 1,GLCD_LCD_HEIGHT - 1); }
/* Based on PCD8544 library by Limor Fried */ void glcd_set_pixel(uint8_t x, uint8_t y, uint8_t color) { if (x > (GLCD_LCD_WIDTH-1) || y > (GLCD_LCD_HEIGHT-1)) { /* don't do anything if x/y is outside bounds of display size */ return; } if (color) { /* Set black */ glcd_buffer[x+ (y/8)*GLCD_LCD_WIDTH] |= ( 1 << (y%8)); } else { /* Set white */ glcd_buffer[x+ (y/8)*GLCD_LCD_WIDTH] &= ~ (1 << (y%8)); } glcd_update_bbox(x,y,x,y); }
/* Bresenham's algorithm - based on PCD8544 library Limor Fried */ void glcd_draw_line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t color) { uint8_t steep = abs(y1 - y0) > abs(x1 - x0); uint8_t dx, dy; int8_t err; int8_t ystep; if (steep) { swap(x0, y0); swap(x1, y1); } if (x0 > x1) { swap(x0, x1); swap(y0, y1); } glcd_update_bbox( x0, y0, x1, y1 ); dx = x1 - x0; dy = abs(y1 - y0); err = dx / 2; if (y0 < y1) { ystep = 1; } else { ystep = -1; } for (; x0<=x1; x0++) { if (steep) { glcd_set_pixel(y0, x0, color); } else { glcd_set_pixel(x0, y0, color); } err -= dy; if (err < 0) { y0 += ystep; err += dx; } } }
void glcd_draw_circle(uint8_t x0, uint8_t y0, uint8_t r, uint8_t color) { int8_t f = 1 - r; int8_t ddF_x = 1; int8_t ddF_y = -2 * r; int8_t x = 0; int8_t y = r; glcd_update_bbox(x0-r, y0-r, x0+r, y0+r); glcd_set_pixel(x0, y0+r, color); glcd_set_pixel(x0, y0-r, color); glcd_set_pixel(x0+r, y0, color); glcd_set_pixel(x0-r, y0, color); while (x<y) { if (f >= 0) { y--; ddF_y += 2; f += ddF_y; } x++; ddF_x += 2; f += ddF_x; glcd_set_pixel(x0 + x, y0 + y, color); glcd_set_pixel(x0 - x, y0 + y, color); glcd_set_pixel(x0 + x, y0 - y, color); glcd_set_pixel(x0 - x, y0 - y, color); glcd_set_pixel(x0 + y, y0 + x, color); glcd_set_pixel(x0 - y, y0 + x, color); glcd_set_pixel(x0 + y, y0 - x, color); glcd_set_pixel(x0 - y, y0 - x, color); } }
void glcd_fill_circle(uint8_t x0, uint8_t y0, uint8_t r, uint8_t color) { int8_t f = 1 - r; int8_t ddF_x = 1; int8_t ddF_y = -2 * r; int8_t x = 0; int8_t y = r; int16_t i; glcd_update_bbox(x0-r, y0-r, x0+r, y0+r); for (i=y0-r; i<=y0+r; i++) { glcd_set_pixel(x0, i, color); } while (x < y) { if (f >= 0) { y--; ddF_y += 2; f += ddF_y; } x++; ddF_x += 2; f += ddF_x; for (i=y0-y; i<=y0+y; i++) { glcd_set_pixel(x0+x, i, color); glcd_set_pixel(x0-x, i, color); } for (i=y0-x; i<=y0+x; i++) { glcd_set_pixel(x0+y, i, color); glcd_set_pixel(x0-y, i, color); } } }
void glcd_clear_buffer(void) { memset(glcd_buffer_selected, 0x00, GLCD_LCD_WIDTH * GLCD_LCD_HEIGHT / 8); glcd_update_bbox(0,0,GLCD_LCD_WIDTH - 1,GLCD_LCD_HEIGHT - 1); }