From 1bb574c4fa859b80e4c05dff9c5c1252dc399fde Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Mon, 18 Jul 2022 21:30:43 +0200 Subject: [PATCH] Reorganised graphics module and moved graphics.h from interfaces to core folder --- meson.build | 2 +- .../include/{interfaces => core}/graphics.h | 57 +++++-------- openrtx/include/core/ui.h | 2 +- openrtx/src/core/{graphics.cpp => graphics.c} | 81 +++++++++++++------ openrtx/src/core/openrtx.c | 5 +- openrtx/src/core/threads.c | 2 +- platform/targets/linux/platform.c | 1 - 7 files changed, 81 insertions(+), 69 deletions(-) rename openrtx/include/{interfaces => core}/graphics.h (90%) rename openrtx/src/core/{graphics.cpp => graphics.c} (94%) diff --git a/meson.build b/meson.build index ed6670fe..a420d500 100644 --- a/meson.build +++ b/meson.build @@ -22,7 +22,7 @@ def = {} openrtx_src = ['openrtx/src/core/state.c', 'openrtx/src/core/threads.c', 'openrtx/src/core/battery.c', - 'openrtx/src/core/graphics.cpp', + 'openrtx/src/core/graphics.c', 'openrtx/src/core/input.c', 'openrtx/src/core/utils.c', 'openrtx/src/core/queue.c', diff --git a/openrtx/include/interfaces/graphics.h b/openrtx/include/core/graphics.h similarity index 90% rename from openrtx/include/interfaces/graphics.h rename to openrtx/include/core/graphics.h index 011834ca..0941f409 100644 --- a/openrtx/include/interfaces/graphics.h +++ b/openrtx/include/core/graphics.h @@ -20,24 +20,12 @@ #ifndef GRAPHICS_H #define GRAPHICS_H -#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include #ifdef __cplusplus -#include - extern "C" { #endif @@ -108,18 +96,6 @@ typedef enum TEXT_ALIGN_RIGHT } textAlign_t; -/** - * Selection of the fonts, ordered by the fontSize_t enum. - */ -static GFXfont const fonts[] = { TomThumb, // 5pt - FreeSans6pt7b, // 6pt - FreeSans8pt7b, // 8pt - FreeSans9pt7b, // 9pt - FreeSans10pt7b, // 10pt - FreeSans12pt7b, // 12pt - FreeSans16pt7b, // 16pt - FreeSans18pt7b, // 16pt - FreeSans24pt7b }; // 24pt /** * This function calls the correspondent method of the low level interface display.h @@ -219,7 +195,8 @@ void gfx_drawVLine(int16_t x, uint16_t width, color_t color); * @param color: border and fill color, in color_t format. * @param fill: if true the rectangle will be solid, otherwise it will be empty with a 1-pixel border */ -void gfx_drawRect(point_t start, uint16_t width, uint16_t height, color_t color, bool fill); +void gfx_drawRect(point_t start, uint16_t width, uint16_t height, color_t color, + bool fill); /** * Draw the outline of a circle of specified radius and color. @@ -294,7 +271,8 @@ void gfx_printError(const char *text, fontSize_t size); * @param height: battery icon height * @param percentage: battery charge percentage */ -void gfx_drawBattery(point_t start, uint16_t width, uint16_t height, uint8_t percentage); +void gfx_drawBattery(point_t start, uint16_t width, uint16_t height, + uint8_t percentage); /** * Function to draw Smeter of arbitrary size. @@ -306,7 +284,8 @@ void gfx_drawBattery(point_t start, uint16_t width, uint16_t height, uint8_t per * @param squelch: squelch level in percentage * @param color: color of the squelch bar */ -void gfx_drawSmeter(point_t start, uint16_t width, uint16_t height, float rssi, float squelch, color_t color); +void gfx_drawSmeter(point_t start, uint16_t width, uint16_t height, float rssi, + float squelch, color_t color); /** * Function to draw Smeter + level meter of arbitrary size. @@ -318,7 +297,8 @@ void gfx_drawSmeter(point_t start, uint16_t width, uint16_t height, float rssi, * @param rssi: rssi level in dBm * @param level: level in range {0, 255} */ -void gfx_drawSmeterLevel(point_t start, uint16_t width, uint16_t height, float rssi, uint8_t level); +void gfx_drawSmeterLevel(point_t start, uint16_t width, uint16_t height, + float rssi, uint8_t level); /** * Function to draw GPS SNR bar graph of arbitrary size. @@ -329,7 +309,8 @@ void gfx_drawSmeterLevel(point_t start, uint16_t width, uint16_t height, float r * @param sats: pointer to the array of satellites data * @param active_sats: bitset representing which sats are part of the fix */ -void gfx_drawGPSgraph(point_t start, uint16_t width, uint16_t height, gpssat_t *sats, uint32_t active_sats); +void gfx_drawGPSgraph(point_t start, uint16_t width, uint16_t height, + gpssat_t *sats, uint32_t active_sats); /** * Function to draw a compass of arbitrary size. @@ -341,18 +322,20 @@ void gfx_drawGPSgraph(point_t start, uint16_t width, uint16_t height, gpssat_t * */ void gfx_drawGPScompass(point_t start, uint16_t radius, float deg, bool active); -#ifdef __cplusplus -} - /** * Function to plot a collection of data on the screen. * Starting coordinates are relative to the top left point. * @param start: Plot start point, in pixel coordinates. * @param width: Plot width * @param height: Plot height - * @param data: pointer to the deque containing data + * @param data: pointer to data buffer + * @param len: data length, in elements */ -void gfx_plotData(point_t start, uint16_t width, uint16_t height, std::deque data); +void gfx_plotData(point_t start, uint16_t width, uint16_t height, + const int16_t *data, size_t len); + +#ifdef __cplusplus +} #endif #endif /* GRAPHICS_H */ diff --git a/openrtx/include/core/ui.h b/openrtx/include/core/ui.h index 6ce691a6..20980ae5 100644 --- a/openrtx/include/core/ui.h +++ b/openrtx/include/core/ui.h @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include #include diff --git a/openrtx/src/core/graphics.cpp b/openrtx/src/core/graphics.c similarity index 94% rename from openrtx/src/core/graphics.cpp rename to openrtx/src/core/graphics.c index 1442dbf9..88411d1f 100644 --- a/openrtx/src/core/graphics.cpp +++ b/openrtx/src/core/graphics.c @@ -22,22 +22,48 @@ * It is suitable for both color, grayscale and B/W display */ -#include +#include +#include +#include #include #include -#include -#include #include -#include -#include -#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // Variable swap macro #define DEG_RAD 0.017453292519943295769236907684886 #define SIN(x) sinf((x) * DEG_RAD) #define COS(x) cosf((x) * DEG_RAD) +/** + * Fonts, ordered by the fontSize_t enum. + */ +static const GFXfont fonts[] = { TomThumb, // 5pt + FreeSans6pt7b, // 6pt + FreeSans8pt7b, // 8pt + FreeSans9pt7b, // 9pt + FreeSans10pt7b, // 10pt + FreeSans12pt7b, // 12pt + FreeSans16pt7b, // 16pt + FreeSans18pt7b, // 16pt + FreeSans24pt7b // 24pt + }; + #ifdef PIX_FMT_RGB565 + /* This specialization is meant for an RGB565 little endian pixel format. * Thus, to accomodate for the endianness, the fields in struct rgb565_t have to * be written in reversed order. @@ -46,14 +72,17 @@ * page: http://mjfrazer.org/mjfrazer/bitfields/ */ +#define PIXEL_T rgb565_t + typedef struct { uint16_t b : 5; uint16_t g : 6; uint16_t r : 5; -} rgb565_t; +} +rgb565_t; -rgb565_t _true2highColor(color_t true_color) +static rgb565_t _true2highColor(color_t true_color) { rgb565_t high_color; high_color.r = true_color.r >> 3; @@ -63,21 +92,24 @@ rgb565_t _true2highColor(color_t true_color) return high_color; } -#define PIXEL_T rgb565_t #elif defined PIX_FMT_BW + /** * This specialization is meant for black and white pixel format. * It is suitable for monochromatic displays with 1 bit per pixel, * it will have RGB and grayscale counterparts */ +#define PIXEL_T uint8_t + typedef enum { WHITE = 0, BLACK = 1, -} bw_t; +} +bw_t; -bw_t _color2bw(color_t true_color) +static bw_t _color2bw(color_t true_color) { if(true_color.r == 0 && true_color.g == 0 && @@ -87,15 +119,14 @@ bw_t _color2bw(color_t true_color) return BLACK; } -#define PIXEL_T uint8_t #else #error Please define a pixel format type into hwconfig.h or meson.build #endif -bool initialized = 0; -PIXEL_T *buf; -uint16_t fbSize; -char text[32]; +static bool initialized = 0; +static PIXEL_T *buf; +static uint16_t fbSize; +static char text[32]; void gfx_init() { @@ -894,23 +925,22 @@ void gfx_drawGPScompass(point_t start, gfx_print(n_pos, FONT_SIZE_6PT, TEXT_ALIGN_LEFT, white, "N"); } -void gfx_plotData(point_t start, - uint16_t width, - uint16_t height, - std::deque data) +void gfx_plotData(point_t start, uint16_t width, uint16_t height, + const int16_t *data, size_t len) { - gfx_clearScreen(); uint16_t horizontal_pos = start.x; color_t white = {255, 255, 255, 255}; - point_t prev_pos {0, 0}, pos{0, 0}; + point_t prev_pos = {0, 0}; + point_t pos = {0, 0}; bool first_iteration = true; - for (auto d : data) + for (size_t i = 0; i < len; i++) { horizontal_pos++; - if (horizontal_pos > start.x + width) + if (horizontal_pos > (start.x + width)) break; pos.x = horizontal_pos; - pos.y = start.y + height / 2 + (float) d * 4 / (2 * SHRT_MAX) * height; + pos.y = start.y + (height / 2) + + ((data[i] * 4) / (2 * SHRT_MAX) * height); if (pos.y > SCREEN_HEIGHT) pos.y = SCREEN_HEIGHT; if (!first_iteration) @@ -919,5 +949,4 @@ void gfx_plotData(point_t start, if (first_iteration) first_iteration = false; } - gfx_render(); } diff --git a/openrtx/src/core/openrtx.c b/openrtx/src/core/openrtx.c index e33d9071..394fcb2a 100644 --- a/openrtx/src/core/openrtx.c +++ b/openrtx/src/core/openrtx.c @@ -19,12 +19,13 @@ ***************************************************************************/ #include -#include +#include #include #include #include -#include +#include #include +#include #include extern void *dev_task(void *arg); diff --git a/openrtx/src/core/threads.c b/openrtx/src/core/threads.c index 2c111709..69e08006 100644 --- a/openrtx/src/core/threads.c +++ b/openrtx/src/core/threads.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/platform/targets/linux/platform.c b/platform/targets/linux/platform.c index 45b994ad..99f0c03c 100644 --- a/platform/targets/linux/platform.c +++ b/platform/targets/linux/platform.c @@ -16,7 +16,6 @@ ***************************************************************************/ #include -#include #include #include #include