Skip to content
Snippets Groups Projects
Select Git revision
  • 8653530c2959a1eafb74b14084af4b1cc4dbeb8d
  • master default protected
  • sonopard/display-pixels-drawimage
  • TilCreator/firmware-master
  • rahix/simple_menu
  • genofire/leds_rgb_get_state
  • genofire/rockets-state
  • genofire/ble-follow-py
  • hauke/ble-cleanups
  • plaetzchen/ios-workaround
  • blinkisync-as-preload
  • genofire/haule-ble-fs-deactive
  • schneider/max30001-pycardium
  • schneider/max30001-epicaridum
  • schneider/max30001
  • schneider/stream-locks
  • ios-workarounds
  • schneider/fundamental-test
  • schneider/ble-buffers
  • schneider/maxim-sdk-update
  • ch3/splashscreen
  • v1.8
  • v1.7
  • v1.6
  • v1.5
  • v1.4
  • v1.3
  • v1.2
  • v1.1
  • v1.0
  • release-1
  • bootloader-v1
  • v0.0
33 results

display.c

Blame
  • Forked from card10 / firmware
    Source project has a limited visibility.
    display.c 4.02 KiB
    #include "display.h"
    #include "Fonts/fonts.h"
    #include "FreeRTOS.h"
    #include "LCD_Driver.h"
    #include "epicardium.h"
    #include "gfx.h"
    #include "gpio.h"
    #include "task.h"
    #include "tmr.h"
    #include "tmr_utils.h"
    
    static TaskHandle_t lock = NULL;
    
    static int check_lock()
    {
    	TaskHandle_t task = xTaskGetCurrentTaskHandle();
    	if (task != lock) {
    		return -EBUSY;
    	} else {
    		return 0;
    	}
    }
    
    int epic_disp_print(
    	uint16_t posx,
    	uint16_t posy,
    	const char *pString,
    	uint16_t fg,
    	uint16_t bg
    ) {
    	return epic_disp_print_adv(DISP_FONT20, posx, posy, pString, fg, bg);
    }
    
    static const sFONT *font_map[] = {
    	[DISP_FONT8] = &Font8,   [DISP_FONT12] = &Font12,
    	[DISP_FONT16] = &Font16, [DISP_FONT20] = &Font20,
    	[DISP_FONT24] = &Font24,
    };
    
    int epic_disp_print_adv(
    	uint8_t font,
    	uint16_t posx,
    	uint16_t posy,
    	const char *pString,
    	uint16_t fg,
    	uint16_t bg
    ) {
    	int cl = check_lock();
    	if (font >= (sizeof(font_map) / sizeof(sFONT *))) {
    		return -EINVAL;
    	}
    	if (cl < 0) {
    		return cl;
    	} else {
    		gfx_puts(
    			font_map[font],
    			&display_screen,
    			posx,
    			posy,
    			pString,
    			fg,
    			bg
    		);
    		return 0;
    	}
    }
    
    int epic_disp_clear(uint16_t color)
    {
    	int cl = check_lock();
    	if (cl < 0) {
    		return cl;
    	} else {
    		gfx_clear_to_color(&display_screen, color);
    		return 0;
    	}
    }
    
    int epic_disp_pixels(
    	const uint8_t *data,
    	size_t data_length,
    	uint8_t offset_x,
    	uint8_t offset_y
    ) {
    	int cl = check_lock();
    
    	if (cl < 0) {
    		return cl;
    	} else {
    		for (int i = 0; i < data_length; i += 4) {
    			uint8_t x = data[i] + offset_x;
    			uint8_t y = data[i + 1] + offset_y;
    
    			uint16_t color = (data[i + 3] << 8) | data[i + 2];
    
    			// no checks nessesary (done in gfx)
    			gfx_setpixel(&display_screen, x, y, color);
    		}
    		return 0;
    	}
    }
    
    int epic_disp_pixel(uint16_t x, uint16_t y, uint16_t color)
    {
    	int cl = check_lock();
    	if (cl < 0) {
    		return cl;
    	} else {
    		// no checks nessesary (done in gfx)
    		gfx_setpixel(&display_screen, x, y, color);
    		return 0;
    	}
    }
    
    int epic_disp_line(
    	uint16_t xstart,
    	uint16_t ystart,
    	uint16_t xend,
    	uint16_t yend,
    	uint16_t color,
    	enum disp_linestyle linestyle,
    	uint16_t pixelsize
    ) {
    	int cl = check_lock();
    	if (cl < 0) {
    		return cl;
    	} else {
    		/* TODO add linestyle support to gfx code */
    		gfx_line(
    			&display_screen,
    			xstart,
    			ystart,
    			xend,
    			yend,
    			pixelsize,
    			color
    		);
    		return 0;
    	}
    }
    
    int epic_disp_rect(
    	uint16_t xstart,
    	uint16_t ystart,
    	uint16_t xend,
    	uint16_t yend,
    	uint16_t color,
    	enum disp_fillstyle fillstyle,
    	uint16_t pixelsize
    ) {
    	int cl = check_lock();
    	if (cl < 0)
    		return cl;
    
    	switch (fillstyle) {
    	case FILLSTYLE_EMPTY:
    		gfx_rectangle(
    			&display_screen,
    			xstart,
    			ystart,
    			xend - xstart,
    			yend - ystart,
    			pixelsize,
    			color
    		);
    		break;
    	case FILLSTYLE_FILLED:
    		gfx_rectangle_fill(
    			&display_screen,
    			xstart,
    			ystart,
    			xend - xstart,
    			yend - ystart,
    			color
    		);
    		break;
    	}
    	return 0;
    }
    
    int epic_disp_circ(
    	uint16_t x,
    	uint16_t y,
    	uint16_t rad,
    	uint16_t color,
    	enum disp_fillstyle fillstyle,
    	uint16_t pixelsize
    ) {
    	int cl = check_lock();
    	if (cl < 0)
    		return cl;
    
    	switch (fillstyle) {
    	case FILLSTYLE_EMPTY:
    		gfx_circle(&display_screen, x, y, rad, pixelsize, color);
    		break;
    	case FILLSTYLE_FILLED:
    		gfx_circle_fill(&display_screen, x, y, rad, color);
    		break;
    	}
    
    	return 0;
    }
    
    int epic_disp_update()
    {
    	int cl = check_lock();
    	if (cl < 0) {
    		return cl;
    	}
    
    	gfx_update(&display_screen);
    	return 0;
    }
    
    int epic_disp_framebuffer(union disp_framebuffer *fb)
    {
    	int cl = check_lock();
    	if (cl < 0) {
    		return cl;
    	}
    
    	LCD_Set(fb->raw, sizeof(fb->raw));
    	return 0;
    }
    
    int epic_disp_backlight(uint16_t brightness)
    {
    	/* TODO: lock? */
    	LCD_SetBacklight(brightness);
    	return 0;
    }
    
    int epic_disp_open()
    {
    	TaskHandle_t task = xTaskGetCurrentTaskHandle();
    	if (lock == task) {
    		return 0;
    	} else if (lock == NULL) {
    		lock = task;
    		return 0;
    	} else {
    		return -EBUSY;
    	}
    }
    
    int epic_disp_close()
    {
    	if (check_lock() < 0 && lock != NULL) {
    		return -EBUSY;
    	} else {
    		lock = NULL;
    		return 0;
    	}
    }
    
    void disp_forcelock()
    {
    	TaskHandle_t task = xTaskGetCurrentTaskHandle();
    	lock              = task;
    }