Skip to content
Snippets Groups Projects
Select Git revision
  • fd96a857577d504ae363b5daa88fbd7cf081b8d0
  • master default protected
  • koalo/bhi160-works-but-dirty
  • ch3/splashscreen
  • m
  • rahix/simple_menu
  • ios-workarounds
  • koalo/wip/i2c-for-python
  • genofire/ble-rewrite
  • renze/safe_mode
  • renze/hatchery_apps
  • schneider/fundamental-test
  • koalo/factory-reset
  • msgctl/gfx_rle
  • msgctl/faultscreen
  • msgctl/textbuffer_api
  • schneider/bonding
  • schneider/bootloader-update-9a0d158
  • schneider/bsec
  • rahix/bma
  • rahix/bhi
  • v1.2
  • v1.1
  • v1.0
  • release-1
  • bootloader-v1
  • v0.0
27 results

flash-all.gdb

Blame
  • Forked from card10 / firmware
    Source project has a limited visibility.
    textbuffer.c 4.70 KiB
    #include "textbuffer.h"
    #include "gfx.h"
    #include <string.h>
    
    void txt_init(struct txt_buffer *txtb, struct gfx_region *reg, sFONT *f)
    {
    	txtb->reg           = reg;
    	txtb->font          = f;
    	txtb->cursor_column = 0;
    	txtb->cursor_row    = 0;
    	txtb->fg_color      = gfx_color_rgb_f(reg, 1.0f, 1.0f, 1.0f);
    	txtb->bg_color      = gfx_color_rgb_f(reg, .0f, .0f, .0f);
    	txtb->draw_cursor   = 1;
    	txtb->auto_update   = 1;
    }
    
    static inline size_t width_(struct txt_buffer *tm)
    {
    	return tm->reg->width / tm->font->Width;
    }
    
    static inline size_t height_(struct txt_buffer *tm)
    {
    	return tm->reg->height / tm->font->Height;
    }
    
    size_t txt_width(struct txt_buffer *tm)
    {
    	return width_(tm);
    }
    
    size_t txt_height(struct txt_buffer *tm)
    {
    	return height_(tm);
    }
    
    static void scrollup(struct txt_buffer *tm)
    {
    	const int last_row     = height_(tm) - 1;
    	const size_t line_size = width_(tm) * sizeof(struct txt_glyph);
    
    	for (int row = 0; row < last_row; row++)
    		memcpy(&tm->text[row][0], &tm->text[row + 1][0], line_size);
    	for (int col = 0; col < width_(tm); col++) {
    		struct txt_glyph *g = &tm->text[last_row][col];
    		g->ch               = ' ';
    		g->fg_color         = tm->fg_color;
    		g->bg_color         = tm->bg_color;
    	}
    }
    
    static void newline(struct txt_buffer *tm)
    {
    	const int last_row = height_(tm) - 1;
    
    	scrollup(tm);
    	tm->cursor_row    = last_row;
    	tm->cursor_column = 0;
    }
    
    static inline void advance_cursor(struct txt_buffer *tm)
    {
    	const int last_row = height_(tm) - 1;
    
    	tm->cursor_column++;
    	if (tm->cursor_column >= width_(tm)) {
    		tm->cursor_column = 0;
    		tm->cursor_row++;
    		if (tm->cursor_row > last_row)
    			newline(tm);