diff --git a/openrtx/include/interfaces/display.h b/openrtx/include/interfaces/display.h index 66090042..90aaf378 100644 --- a/openrtx/include/interfaces/display.h +++ b/openrtx/include/interfaces/display.h @@ -74,18 +74,6 @@ void *display_getFrameBuffer(); */ void display_terminate(); -/** - * Get screen width in pixels. - * @return screen width, in pixels. - */ -uint16_t display_screenWidth(); - -/** - * Get screen height in pixels. - * @return screen height, in pixels. - */ -uint16_t display_screenHeight(); - /** * Copy a given section, between two given rows, of framebuffer content to the * display. diff --git a/openrtx/include/interfaces/graphics.h b/openrtx/include/interfaces/graphics.h index 06985aa9..ee6b607b 100644 --- a/openrtx/include/interfaces/graphics.h +++ b/openrtx/include/interfaces/graphics.h @@ -98,20 +98,6 @@ void gfx_init(); */ void gfx_terminate(); -/** - * This function calls the correspondent method of the low level interface display.h - * Get screen width in pixels. - * @return screen width, in pixels. - */ -uint16_t gfx_screenWidth(); - -/** - * This function calls the correspondent method of the low level interface display.h - * Get screen height in pixels. - * @return screen height, in pixels. - */ -uint16_t gfx_screenHeight(); - /** * This function calls the correspondent method of the low level interface display.h * Copy a given section, between two given rows, of framebuffer content to the diff --git a/openrtx/src/graphics/graphics_bw.c b/openrtx/src/graphics/graphics_bw.c index 2c68eac8..736fac02 100644 --- a/openrtx/src/graphics/graphics_bw.c +++ b/openrtx/src/graphics/graphics_bw.c @@ -36,22 +36,17 @@ typedef enum } bw_t; bool initialized = 0; -uint16_t screen_width = 0; -uint16_t screen_height = 0; uint8_t *buf; uint16_t fbSize; void gfx_init() { display_init(); - // Set global variables and framebuffer pointer - screen_width = gfx_screenWidth(); - screen_height = gfx_screenHeight(); buf = (uint8_t *)(display_getFrameBuffer()); // Calculate framebuffer size - fbSize = (screen_height * screen_width) / 8; + fbSize = (SCREEN_HEIGHT * SCREEN_WIDTH) / 8; /* Compensate for eventual truncation error in division */ - if((fbSize * 8) < (screen_height * screen_width)) fbSize += 1; + if((fbSize * 8) < (SCREEN_HEIGHT * SCREEN_WIDTH)) fbSize += 1; fbSize *= sizeof(uint8_t); initialized = 1; } @@ -62,16 +57,6 @@ void gfx_terminate() initialized = 0; } -uint16_t gfx_screenWidth() -{ - return display_screenWidth(); -} - -uint16_t gfx_screenHeight() -{ - return display_screenHeight(); -} - void gfx_renderRows(uint8_t startRow, uint8_t endRow) { display_renderRows(startRow, endRow); @@ -120,15 +105,15 @@ void _bw_setPixel(point_t pos, bw_t bw) * Black and white 1bpp format: framebuffer is an array of uint8_t, where * each cell contains the values of eight pixels, one per bit. */ - uint16_t cell = (pos.x + pos.y*screen_width) / 8; - uint16_t elem = (pos.x + pos.y*screen_width) % 8; + uint16_t cell = (pos.x + pos.y*SCREEN_WIDTH) / 8; + uint16_t elem = (pos.x + pos.y*SCREEN_WIDTH) % 8; buf[cell] &= ~(1 << elem); buf[cell] |= (bw << elem); } void gfx_setPixel(point_t pos, color_t color) { - if (pos.x >= screen_width || pos.y >= screen_height) + if (pos.x >= SCREEN_WIDTH || pos.y >= SCREEN_HEIGHT) return; // off the screen bw_t bw = _color2bw(color); _bw_setPixel(pos, bw); @@ -155,8 +140,8 @@ void gfx_drawRect(point_t start, uint16_t width, uint16_t height, color_t color, uint16_t x_max = start.x + width; uint16_t y_max = start.y + height; bool perimeter = 0; - if(x_max > (screen_width - 1)) x_max = screen_width - 1; - if(y_max > (screen_height - 1)) y_max = screen_height - 1; + if(x_max > (SCREEN_WIDTH - 1)) x_max = SCREEN_WIDTH - 1; + if(y_max > (SCREEN_HEIGHT - 1)) y_max = SCREEN_HEIGHT - 1; for(int y = start.y; y < y_max; y++) { for(int x = start.x; x < x_max; x++) @@ -212,9 +197,9 @@ void gfx_print(point_t start, const char *text, fontSize_t size, textAlign_t ali int16_t sLen = strlen(text); // Compute amount of letters that fit till the end of the screen - if ((charWidthPixels*sLen) + start.x > screen_width) + if ((charWidthPixels*sLen) + start.x > SCREEN_WIDTH) { - sLen = (screen_width-start.x)/charWidthPixels; + sLen = (SCREEN_WIDTH-start.x)/charWidthPixels; } if (sLen < 0) return; @@ -225,10 +210,10 @@ void gfx_print(point_t start, const char *text, fontSize_t size, textAlign_t ali // left aligned, do nothing. break; case TEXT_ALIGN_CENTER: - start.x = (screen_width - (charWidthPixels * sLen))/2; + start.x = (SCREEN_WIDTH - (charWidthPixels * sLen))/2; break; case TEXT_ALIGN_RIGHT: - start.x = screen_width - (charWidthPixels * sLen); + start.x = SCREEN_WIDTH - (charWidthPixels * sLen); break; } diff --git a/openrtx/src/graphics/graphics_rgb565.c b/openrtx/src/graphics/graphics_rgb565.c index 31c2cb9e..53cf34c6 100644 --- a/openrtx/src/graphics/graphics_rgb565.c +++ b/openrtx/src/graphics/graphics_rgb565.c @@ -44,16 +44,11 @@ typedef struct } rgb565_t; bool initialized = 0; -uint16_t screen_width = 0; -uint16_t screen_height = 0; rgb565_t *buf; void gfx_init() { display_init(); - // Set global variables and framebuffer pointer - screen_width = gfx_screenWidth(); - screen_height = gfx_screenHeight(); buf = (rgb565_t *)(display_getFrameBuffer()); initialized = 1; } @@ -64,16 +59,6 @@ void gfx_terminate() initialized = 0; } -uint16_t gfx_screenWidth() -{ - return display_screenWidth(); -} - -uint16_t gfx_screenHeight() -{ - return display_screenHeight(); -} - void gfx_renderRows(uint8_t startRow, uint8_t endRow) { display_renderRows(startRow, endRow); @@ -103,28 +88,28 @@ void gfx_clearScreen() { if(!initialized) return; // Set the whole framebuffer to 0x00 = make the screen black - memset(buf, 0x00, sizeof(rgb565_t) * screen_width * screen_height); + memset(buf, 0x00, sizeof(rgb565_t) * SCREEN_WIDTH * SCREEN_HEIGHT); } void gfx_fillScreen(color_t color) { if(!initialized) return; rgb565_t color_565 = _true2highColor(color); - for(int y = 0; y < screen_height; y++) + for(int y = 0; y < SCREEN_HEIGHT; y++) { - for(int x = 0; x < screen_width; x++) + for(int x = 0; x < SCREEN_WIDTH; x++) { - buf[x + y*screen_width] = color_565; + buf[x + y*SCREEN_WIDTH] = color_565; } } } void gfx_setPixel(point_t pos, color_t color) { - if (pos.x >= screen_width || pos.y >= screen_height) + if (pos.x >= SCREEN_WIDTH || pos.y >= SCREEN_HEIGHT) return; // off the screen - buf[pos.x + pos.y*screen_width] = _true2highColor(color); + buf[pos.x + pos.y*SCREEN_WIDTH] = _true2highColor(color); } void gfx_drawLine(point_t start, point_t end, color_t color) @@ -135,7 +120,7 @@ void gfx_drawLine(point_t start, point_t end, color_t color) { for(int x = start.x; x < end.x; x++) { - buf[x + y*screen_width] = color_565; + buf[x + y*SCREEN_WIDTH] = color_565; } } } @@ -147,8 +132,8 @@ void gfx_drawRect(point_t start, uint16_t width, uint16_t height, color_t color, uint16_t x_max = start.x + width; uint16_t y_max = start.y + height; bool perimeter = 0; - if(x_max > (screen_width - 1)) x_max = screen_width - 1; - if(y_max > (screen_height - 1)) y_max = screen_height - 1; + if(x_max > (SCREEN_WIDTH - 1)) x_max = SCREEN_WIDTH - 1; + if(y_max > (SCREEN_HEIGHT - 1)) y_max = SCREEN_HEIGHT - 1; for(int y = start.y; y < y_max; y++) { for(int x = start.x; x < x_max; x++) @@ -156,7 +141,7 @@ void gfx_drawRect(point_t start, uint16_t width, uint16_t height, color_t color, if(y == start.y || y == y_max-1 || x == start.x || x == x_max-1) perimeter = 1; else perimeter = 0; // If fill is false, draw only rectangle perimeter - if(fill || perimeter) buf[x + y*screen_width] = color_565; + if(fill || perimeter) buf[x + y*SCREEN_WIDTH] = color_565; } } } @@ -200,9 +185,9 @@ void gfx_print(point_t start, const char *text, fontSize_t size, textAlign_t ali int16_t sLen = strlen(text); // Compute amount of letters that fit till the end of the screen - if ((charWidthPixels*sLen) + start.x > screen_width) + if ((charWidthPixels*sLen) + start.x > SCREEN_WIDTH) { - sLen = (screen_width-start.x)/charWidthPixels; + sLen = (SCREEN_WIDTH-start.x)/charWidthPixels; } if (sLen < 0) return; @@ -213,10 +198,10 @@ void gfx_print(point_t start, const char *text, fontSize_t size, textAlign_t ali // left aligned, do nothing. break; case TEXT_ALIGN_CENTER: - start.x = (screen_width - (charWidthPixels * sLen))/2; + start.x = (SCREEN_WIDTH - (charWidthPixels * sLen))/2; break; case TEXT_ALIGN_RIGHT: - start.x = screen_width - (charWidthPixels * sLen); + start.x = SCREEN_WIDTH - (charWidthPixels * sLen); break; } @@ -241,7 +226,7 @@ void gfx_print(point_t start, const char *text, fontSize_t size, textAlign_t ali int16_t byte = bitIndex >> 3; int16_t bitMask = 1 << (bitIndex & 7); if (currentCharData[byte] & bitMask) - buf[(start.y + vscan) * screen_width + + buf[(start.y + vscan) * SCREEN_WIDTH + start.x + hscan + i * charWidthPixels] = color_565; } } diff --git a/platform/drivers/display/HX83XX_md380.c b/platform/drivers/display/HX83XX_md380.c index f597ca3c..32282b3a 100644 --- a/platform/drivers/display/HX83XX_md380.c +++ b/platform/drivers/display/HX83XX_md380.c @@ -333,16 +333,6 @@ void display_terminate() } } -uint16_t display_screenWidth() -{ - return SCREEN_WIDTH; -} - -uint16_t display_screenHeight() -{ - return SCREEN_HEIGHT; -} - void display_renderRows(uint8_t startRow, uint8_t endRow) { /* diff --git a/platform/drivers/display/display_libSDL.c b/platform/drivers/display/display_libSDL.c index b420a613..b51f8291 100644 --- a/platform/drivers/display/display_libSDL.c +++ b/platform/drivers/display/display_libSDL.c @@ -175,16 +175,6 @@ void display_terminate() SDL_Quit(); } -uint16_t display_screenWidth() -{ - return SCREEN_WIDTH; -} - -uint16_t display_screenHeight() -{ - return SCREEN_HEIGHT; -} - void display_renderRows(uint8_t startRow, uint8_t endRow) { Uint32 *pixels = (Uint32*)renderSurface->pixels; diff --git a/tests/platform/display_test_SDL.c b/tests/platform/display_test_SDL.c index 25b1107b..8e10fa16 100644 --- a/tests/platform/display_test_SDL.c +++ b/tests/platform/display_test_SDL.c @@ -43,7 +43,7 @@ void drawRect(int x, int y, int width, int height, uint16_t color) { for(int j=x; j < x_max; j++) { - buf[j + i*display_screenWidth()] = color; + buf[j + i * SCREEN_WIDTH] = color; } } } @@ -54,13 +54,13 @@ int main() display_setBacklightLevel(254); /* Horizontal red line */ - drawRect(0, 10, display_screenWidth(), 20, 0xF800); + drawRect(0, 10, SCREEN_WIDTH, 20, 0xF800); /* Vertical blue line */ - drawRect(10, 0, 20, display_screenHeight(), 0x001F); + drawRect(10, 0, 20, SCREEN_HEIGHT, 0x001F); /* Vertical green line */ - drawRect(80, 0, 20, display_screenHeight(), 0x07e0); + drawRect(80, 0, 20, SCREEN_HEIGHT, 0x07e0); /* * Use SDL event listener to check if window close button has been pressed, diff --git a/tests/platform/x64_uC.c b/tests/platform/x64_uC.c index 12aab2f5..b457b9d0 100644 --- a/tests/platform/x64_uC.c +++ b/tests/platform/x64_uC.c @@ -97,13 +97,13 @@ static void gfxThread(void *arg) point_t origin = {0, pos}; color_t color_red = {255, 0, 0}; color_t color_white = {255, 255, 255}; - gfx_drawRect(origin, display_screenWidth(), 20, color_red, 1); + gfx_drawRect(origin, SCREEN_WIDTH, 20, color_red, 1); char *buffer = "KEK"; gfx_print(origin, buffer, FONT_SIZE_4, TEXT_ALIGN_LEFT,color_white); gfx_render(); while(gfx_renderingInProgress()) ; pos += 20; - if(pos > gfx_screenHeight() - 20) pos = 0; + if(pos > SCREEN_HEIGHT - 20) pos = 0; OSTimeDlyHMSM(0u, 0u, 0u, 100u, OS_OPT_TIME_HMSM_STRICT, &os_err); }