Commit a26664be authored by Mateusz Zalega's avatar Mateusz Zalega Committed by Rahix
Browse files

feat(gfx): Replace vendor implementation



This commit substitutes the vendor gfx library with a completely
new implementation.  It also adds a text-buffer mode.

Signed-off-by: Mateusz Zalega's avatarMateusz Zalega <mateusz@appliedsourcery.com>
parent e87cdd45
......@@ -2,7 +2,7 @@
/* Autogenerated */
#include "splash-screen.h"
#include "GUI_Paint.h"
#include "gfx.h"
#include "display.h"
/*
......@@ -16,19 +16,21 @@ static void bootloader_display_splash(void)
{
int idx = 0;
Color white = gfx_color(&display_screen, WHITE);
Color black = gfx_color(&display_screen, BLACK);
for (int i = 0; i < sizeof(splash); i++) {
uint16_t color = (splash[i] & 0x80) ? 0xffff : 0x0000;
Color color = (splash[i] & 0x80) ? white : black;
uint8_t length = splash[i] & 0x7f;
for (int j = 0; j < length; j++) {
uint16_t x = idx % 160;
uint16_t y = idx / 160;
Paint_SetPixel(x, y, color);
gfx_setpixel(&display_screen, x, y, color);
idx++;
}
}
LCD_Update();
gfx_update(&display_screen);
}
/*
......@@ -44,10 +46,8 @@ void bootloader_display_init(void)
*/
void bootloader_display_header(void)
{
Paint_Clear(0x0000);
Paint_DrawString_EN(0, 16 * 0, "Bootloader", &Font16, 0x0000, 0xffff);
Paint_DrawString_EN(0, 16 * 1, __DATE__, &Font16, 0x0000, 0xffff);
LCD_Update();
txt_puts(&display_textb, "Bootloader\n");
txt_puts(&display_textb, __DATE__ "\n");
}
/*
......@@ -55,6 +55,7 @@ void bootloader_display_header(void)
*/
void bootloader_display_line(int line, char *string, uint16_t color)
{
Paint_DrawString_EN(0, 16 * line, string, &Font16, 0x0000, color);
LCD_Update();
Color black = gfx_color(&display_screen, BLACK);
gfx_puts(&Font16, &display_screen, 0, 16 * line, string, color, black);
gfx_update(&display_screen);
}
......@@ -18,8 +18,9 @@
#include "modules/filesystem.h"
#include "api/interrupt-sender.h"
#include <Heart.h>
#include "GUI_Paint.h"
#include "Heart.h"
#include "gfx.h"
#include "display.h"
#include "FreeRTOS.h"
#include "task.h"
......@@ -50,8 +51,10 @@ int main(void)
card10_init();
card10_diag();
Paint_DrawImage(Heart, 0, 0, 160, 80);
LCD_Update();
gfx_copy_region_raw(
&display_screen, 0, 0, 160, 80, 2, (const void *)(Heart)
);
gfx_update(&display_screen);
/* TODO: Move this to its own function */
SCB->SCR |= SCB_SCR_SEVONPEND_Msk;
......
#include "epicardium.h"
#include "tmr_utils.h"
#include "gpio.h"
#include "GUI_DEV/GUI_Paint.h"
#include "Fonts/fonts.h"
#include "tmr.h"
#include "FreeRTOS.h"
#include "task.h"
#include "gfx.h"
#include "display.h"
#include "LCD_Driver.h"
static TaskHandle_t lock = NULL;
......@@ -30,7 +32,7 @@ int epic_disp_print(
if (cl < 0) {
return cl;
} else {
Paint_DrawString_EN(posx, posy, pString, &Font20, bg, fg);
gfx_puts(&Font20, &display_screen, posx, posy, pString, fg, bg);
return 0;
}
}
......@@ -41,7 +43,7 @@ int epic_disp_clear(uint16_t color)
if (cl < 0) {
return cl;
} else {
LCD_Clear(color);
gfx_clear_to_color(&display_screen, color);
return 0;
}
}
......@@ -52,7 +54,7 @@ int epic_disp_pixel(uint16_t x, uint16_t y, uint16_t color)
if (cl < 0) {
return cl;
} else {
Paint_SetPixel(x, y, color);
gfx_setpixel(&display_screen, x, y, color);
return 0;
}
}
......@@ -70,8 +72,15 @@ int epic_disp_line(
if (cl < 0) {
return cl;
} else {
Paint_DrawLine(
xstart, ystart, xend, yend, color, linestyle, pixelsize
/* TODO add linestyle support to gfx code */
gfx_thick_line(
&display_screen,
xstart,
ystart,
xend,
yend,
pixelsize,
color
);
return 0;
}
......@@ -87,14 +96,33 @@ int epic_disp_rect(
uint16_t pixelsize
) {
int cl = check_lock();
if (cl < 0) {
if (cl < 0)
return cl;
} else {
Paint_DrawRectangle(
xstart, ystart, xend, yend, color, fillstyle, pixelsize
switch (fillstyle) {
case FILLSTYLE_EMPTY:
gfx_rectangle(
&display_screen,
xstart,
ystart,
xend - xstart,
yend - ystart,
pixelsize,
color
);
return 0;
break;
case FILLSTYLE_FILLED:
gfx_rectangle_fill(
&display_screen,
xstart,
ystart,
xend - xstart,
yend - ystart,
color
);
break;
}
return 0;
}
int epic_disp_circ(
......@@ -106,12 +134,19 @@ int epic_disp_circ(
uint16_t pixelsize
) {
int cl = check_lock();
if (cl < 0) {
if (cl < 0)
return cl;
} else {
Paint_DrawCircle(x, y, rad, color, fillstyle, pixelsize);
return 0;
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()
......@@ -121,7 +156,7 @@ int epic_disp_update()
return cl;
}
LCD_Update();
gfx_update(&display_screen);
return 0;
}
......
......@@ -11,7 +11,9 @@
#include "gpio.h"
#include "bme680.h"
#include "bosch.h"
#include "GUI_DEV/GUI_Paint.h"
#include "gfx.h"
#include "framebuffer.h"
#include "display.h"
#include "Fonts/fonts.h"
#include "card10.h"
......@@ -73,6 +75,8 @@ int main(void)
/* Set the power mode */
rslt = bme680_set_sensor_mode(&gas_sensor);
Color white = gfx_color(&display_screen, WHITE);
Color black = gfx_color(&display_screen, BLACK);
while (1) {
TMR_Delay(MXC_TMR0, MSEC(1000), 0);
......@@ -86,13 +90,13 @@ int main(void)
char buf[128];
sprintf(buf, "T: %.2Lf degC", data.temperature / 100.0l);
Paint_DrawString_EN(0, 0, buf, &Font16, 0x0000, 0xffff);
gfx_puts(&Font16, &display_screen, 0, 0, buf, white, black);
sprintf(buf, "P: %.2Lf hPa", data.pressure / 100.0l);
Paint_DrawString_EN(0, 16, buf, &Font16, 0x0000, 0xffff);
gfx_puts(&Font16, &display_screen, 0, 16, buf, white, black);
sprintf(buf, "H: %.2Lf %%rH", data.humidity / 1000.0l);
Paint_DrawString_EN(0, 32, buf, &Font16, 0x0000, 0xffff);
gfx_puts(&Font16, &display_screen, 0, 32, buf, white, black);
//printf("%.2f,%.2f,%.2f\n", data.temperature / 100.0f,
// data.pressure / 100.0f, data.humidity / 1000.0f );
......@@ -100,12 +104,18 @@ int main(void)
if (data.status & BME680_GASM_VALID_MSK) {
printf(", G: %ld ohms", data.gas_resistance);
sprintf(buf, "G: %ld ohms", data.gas_resistance);
Paint_DrawString_EN(
0, 48, buf, &Font16, 0x0000, 0xffff
gfx_puts(
&Font16,
&display_screen,
0,
48,
buf,
white,
black
);
}
LCD_Update();
gfx_update(&display_screen);
printf("\n");
......
......@@ -6,7 +6,7 @@
#include "card10.h"
#include "bootloader-9251ea6.h"
#include "display.h"
#include "GUI_Paint.h"
#include "gfx.h"
#include "pmic.h"
#include "flc.h"
......@@ -42,29 +42,20 @@ int main(void)
pmic_set_button_callback(pmic_button);
printf("Erasing bootloader.\n");
Paint_DrawString_EN(
0, 16 * 0, "Erasing bootloader", &Font16, 0x0000, 0xffff
);
LCD_Update();
txt_puts(&display_textb, "Erasing bootloader.\n");
ICC_Disable();
int ret = FLC_MultiPageErase(0x10000000, 0x10000000 + 1024 * 64 - 1);
if (ret != E_NO_ERROR) {
printf("FLC_MultiPageErase failed with %d\n", ret);
Paint_DrawString_EN(
0, 16 * 1, "Fail.", &Font16, 0x0000, 0xffff
);
LCD_Update();
txt_puts(&display_textb, "Fail.\n");
while (1)
;
}
printf("Writing bootloader.\n");
Paint_DrawString_EN(
0, 16 * 0, "Writing bootloader ", &Font16, 0x0000, 0xffff
);
LCD_Update();
txt_puts(&display_textb, "Writing bootloader.\n");
ret = FLC_Write(
0x10000000,
......@@ -73,21 +64,15 @@ int main(void)
);
if (ret != E_NO_ERROR) {
printf("FLC_Write failed with %d\n", ret);
Paint_DrawString_EN(
0, 16 * 1, "Fail.", &Font16, 0x0000, 0xffff
);
LCD_Update();
txt_puts(&display_textb, "Fail.\n");
while (1)
;
}
ICC_Enable();
printf("Done.\n");
Paint_DrawString_EN(0, 16 * 1, "Done.", &Font16, 0x0000, 0xffff);
Paint_DrawString_EN(
0, 16 * 2, "Please restart", &Font16, 0x0000, 0xffff
);
LCD_Update();
txt_puts(&display_textb, "Done.\n");
txt_puts(&display_textb, "Please restart.\n");
while (1) {
card10_poll();
......
......@@ -7,7 +7,8 @@
#include "leds.h"
#include "card10.h"
#include "GUI_Paint.h"
#include "gfx.h"
#include "display.h"
#include "tmr_utils.h"
......@@ -21,8 +22,10 @@ int main(void)
card10_init();
card10_diag();
Paint_DrawImage(Heart, 0, 0, 160, 80);
LCD_Update();
gfx_copy_region_raw(
&display_screen, 0, 0, 160, 80, 2, (const void *)(Heart)
);
gfx_update(&display_screen);
// Release core1
core1_start((void *)0x10080000);
......
......@@ -16,7 +16,9 @@
#include "spi.h"
#include "pb.h"
#include "MAX30003.h"
#include "GUI_DEV/GUI_Paint.h"
#include "gfx.h"
#include "LCD_Driver.h"
#include "display.h"
#include "pmic.h"
#include "card10.h"
#include <stdbool.h>
......@@ -150,7 +152,7 @@ static uint8_t prev;
static void clear(void)
{
Paint_Clear(BLACK);
gfx_clear(&display_screen);
prev = Y_OFFSET;
}
......@@ -173,7 +175,7 @@ static void set(uint8_t index, int8_t val)
}
for (int i = min; i < max + 1; i++) {
LCD_SetUWORD(SIZE_X - index - 1, i, RED);
LCD_SetUWORD(SIZE_X - index - 1, i, 0xf800);
}
prev = pos;
......@@ -199,7 +201,15 @@ void update(void)
ecg_switch,
internal_pull,
scale);
Paint_DrawString_EN(0, 0, buf, &Font8, 0x0000, 0xffff);
gfx_puts(
&Font8,
&display_screen,
0,
0,
buf,
gfx_color(&display_screen, WHITE),
gfx_color(&display_screen, BLACK)
);
for (int i = 0; i < SIZE_X; i++) {
set(i, (samples[i] / scale));
......
......@@ -7,7 +7,8 @@
#include "leds.h"
#include "card10.h"
#include "GUI_Paint.h"
#include "gfx.h"
#include "display.h"
#include "tmr_utils.h"
......@@ -29,8 +30,10 @@ int main(void)
card10_init();
card10_diag();
Paint_DrawImage(Heart, 0, 0, 160, 80);
LCD_Update();
gfx_copy_region_raw(
&display_screen, 0, 0, 160, 80, 2, (const void *)(Heart)
);
gfx_update(&display_screen);
for (int i = 0; i < 11; i++) {
// leds_set_dim(i, 1);
......
......@@ -13,7 +13,8 @@
#include "gpio.h"
#include "bhy_uc_driver.h"
#include "pmic.h"
#include "GUI_DEV/GUI_Paint.h"
#include "gfx.h"
#include "display.h"
#include "card10.h"
......@@ -48,7 +49,7 @@ void draw_arrow(int angle, int color)
int x2 = x1 - sin * 30;
int y2 = y1 - cos * 30;
Paint_DrawLine(x1, y1, x2, y2, color, LINE_STYLE_SOLID, DOT_PIXEL_2X2);
gfx_thick_line(&display_screen, x1, y1, x2, y2, 2, color);
sin = sinf((angle - 140) * 2 * M_PI / 360.);
cos = cosf((angle - 140) * 2 * M_PI / 360.);
......@@ -56,7 +57,7 @@ void draw_arrow(int angle, int color)
int x3 = x2 - sin * 10;
int y3 = y2 - cos * 10;
Paint_DrawLine(x2, y2, x3, y3, color, LINE_STYLE_SOLID, DOT_PIXEL_2X2);
gfx_thick_line(&display_screen, x2, y2, x3, y3, 2, color);
sin = sinf((angle + 140) * 2 * M_PI / 360.);
cos = cosf((angle + 140) * 2 * M_PI / 360.);
......@@ -64,7 +65,7 @@ void draw_arrow(int angle, int color)
int x4 = x2 - sin * 10;
int y4 = y2 - cos * 10;
Paint_DrawLine(x2, y2, x4, y4, color, LINE_STYLE_SOLID, DOT_PIXEL_2X2);
gfx_thick_line(&display_screen, x2, y2, x4, y4, 2, color);
}
/***** Functions *****/
......@@ -81,8 +82,12 @@ static void sensors_callback_orientation(
int angle = sensor_data->data_vector.x * 360 / 32768;
if (angle != prev) {
Paint_Clear(BLACK);
int colors[] = { RED, YELLOW, YELLOW, GREEN };
gfx_clear(&display_screen);
int colors[] = { gfx_color(&display_screen, RED),
gfx_color(&display_screen, YELLOW),
gfx_color(&display_screen, YELLOW),
gfx_color(&display_screen, GREEN) };
int color = colors[sensor_data->data_vector.status];
draw_arrow(sensor_data->data_vector.x * 360 / 32768, color);
......@@ -91,12 +96,18 @@ static void sensors_callback_orientation(
//Paint_DrawString_EN(0, 0, buf, &Font12, BLACK, color);
sprintf(buf, "%3d", angle);
Paint_DrawString_EN(0, 30, buf, &Font24, BLACK, color);
Paint_DrawCircle(
57, 35, 4, color, DRAW_FILL_EMPTY, DOT_PIXEL_1X1
gfx_puts(
&Font24,
&display_screen,
0,
30,
buf,
color,
gfx_color(&display_screen, BLACK)
);
gfx_circle(&display_screen, 57, 35, 4, 2, color);
LCD_Update();
gfx_update(&display_screen);
prev = angle;
}
}
......
......@@ -5,10 +5,12 @@
/***** Includes *****/
#include "tmr_utils.h"
#include "gpio.h"
#include "GUI_DEV/GUI_Paint.h"
#include "gfx.h"
#include "display.h"
#include "Fonts/fonts.h"
#include "image/image.h"
#include "tmr.h"
#include "DEV_Config.h"
#include "card10.h"
......@@ -24,23 +26,37 @@ int main(void)
card10_init();
card10_diag();
Paint_DrawString_EN(0, 0, "123", &Font24, 0x000f, 0xfff0);
Paint_DrawString_EN(0, 23, "ABC", &Font24, BLUE, CYAN);
Paint_DrawString_CN(20, 42, "΢ѩµç×Ó", &Font24CN, WHITE, RED);
Paint_DrawRectangle(
70, 10, 100, 40, RED, DRAW_FILL_EMPTY, DOT_PIXEL_2X2
);
Paint_DrawLine(
70, 10, 100, 40, MAGENTA, LINE_STYLE_SOLID, DOT_PIXEL_2X2
Color red = gfx_color(&display_screen, RED);
Color green = gfx_color(&display_screen, GREEN);
Color yellow = gfx_color(&display_screen, YELLOW);
gfx_puts(&Font24, &display_screen, 0, 0, "123", 0x000f, 0xfff8);
gfx_puts(&Font24, &display_screen, 23, 0, "ABC", 0x000f, 0xfff8);
gfx_rectangle(&display_screen, 70, 10, 100, 40, 2, red);
gfx_thick_line(&display_screen, 70, 10, 100, 40, 2, green);
gfx_thick_line(&display_screen, 100, 10, 70, 40, 2, yellow);
gfx_circle(&display_screen, 85, 25, 22, 2, green);
gfx_copy_region_raw(
&display_screen,
120,
0,
40,
40,
2,
(const void *)(gImage_40X40)
);
Paint_DrawLine(
100, 10, 70, 40, MAGENTA, LINE_STYLE_SOLID, DOT_PIXEL_2X2
gfx_copy_region_raw(
&display_screen,
0,
0,
160,
80,
2,
(const void *)(gImage_160X80)
);
Paint_DrawCircle(85, 25, 22, GREEN, DRAW_FILL_EMPTY, DOT_PIXEL_2X2);
gfx_update(&display_screen);
Paint_DrawImage(gImage_40X40, 120, 0, 40, 40);
Paint_DrawImage(gImage_160X80, 0, 0, 160, 80);
LCD_Update();
DEV_Delay_ms(3000);
while (1) {
......
#include "LCD/LCD_Driver.h"
#include "GUI_DEV/GUI_Paint.h"
#include "framebuffer.h"
#include "gfx.h"
#include "textbuffer.h"
#include "gpio.h"
#include "tmr.h"
......@@ -11,6 +13,9 @@
/***** Globals *****/
const gpio_cfg_t DEV_DC_PIN = { PORT_1, PIN_6, GPIO_FUNC_OUT, GPIO_PAD_NONE };
struct gfx_region display_screen;
struct txt_buffer display_textb;
// Parameters for PWM output
#define PORT_PWM PORT_0 // port
#define PIN_PWM PIN_28 // pin
......@@ -93,10 +98,8 @@ void display_init(void)
PWM_Output();
LCD_SetBacklight(500);
LCD_Init();
LCD_Clear(BLACK);
Paint_NewImage(LCD_WIDTH, LCD_HEIGHT, 0, WHITE);
Paint_Clear(BLACK);
Paint_SetRotate(180);
display_screen = gfx_screen(LCD_framebuffer());
txt_init(&display_textb, &display_screen, &Font12);
gfx_clear(&display_screen);
}
#ifndef DISPLAY_H
#include "framebuffer.h"
#include "textbuffer.h"
extern struct gfx_region display_screen;
extern struct txt_buffer display_textb;
void display_init(void);
......
This diff is collapsed.
/*****************************************************************************
* | File : GUI_Paint.h
* | Author : Waveshare team
* | Function : Achieve drawing: draw points, lines, boxes, circles and
* their size, solid dotted line, solid rectangle hollow
* rectangle, solid circle hollow circle.
* | Info :
* Achieve display characters: Display a single character, string, number