/*************************************************************************** * Copyright (C) 2020 by Silvano Seva IU2KWO and Niccolò Izzo IU2KIN * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 3 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, see * ***************************************************************************/ #ifndef DISPLAY_H #define DISPLAY_H #include #include /** * Standard interface for all low-level display drivers. * *********************** HOW TO MANAGE FRAMEBUFFER ***************************** * * This driver allocates the framebuffer as a block of linearly addressed memory * equivalent to an array of SCREEN_HEIGHT*SCREEN_WIDTH elements. * With respect to it, screen is indexed in this way: * * (0,0) * +-------> x * | * | o (X,Y) * | * v * y * * then to set the value of the pixel having coordinates (X,Y), framebuffer has * to be indexed in this way: buf[X + Y*SCREEN_WIDTH]. * */ /** * This function initialises the display, configures backlight control and * allocates framebuffer on the heap. After initialisation, backlight is set * to zero. * NOTE: framebuffer allocation is the first operation performed, if fails an * error message is printed on the virtual COM port and this function returns * prematurely, without configuring the display and the backlight timer. Thus, a * dark screen can be symptom of failed allocation. */ void display_init(); /** * Get pointer to framebuffer. Being this a standard interface for all the * low-level display drivers, this function returns a pointer to void: it's up * to the caller performing the correct cast to one of the standard types used * for color coding. * Changes to the framebuffer will not be reflected on the display until * display_render() or display_renderRows() are called. * * * WARNING: no bound check is performed! Do not call free() on the pointer * returned, doing so will destroy the framebuffer! * @return pointer to framebuffer. */ void *display_getFrameBuffer(); /** * When called, this function turns off backlight, shuts down backlight control * and deallocates the framebuffer. */ 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(); /** * Set screen backlight to a given level. * @param level: backlight level, from 0 (backlight off) to 255 (backlight at * full brightness). */ void display_setBacklightLevel(uint8_t level); /** * Copy a given section, between two given rows, of framebuffer content to the * display. * @param startRow: first row of the framebuffer section to be copied * @param endRow: last row of the framebuffer section to be copied */ void display_renderRows(uint8_t startRow, uint8_t endRow); /** * Copy framebuffer content to the display internal buffer. To be called * whenever there is need to update the display. */ void display_render(); /** * Check if framebuffer is being copied to the screen or not, in which case it * can be modified without problems. * @return false if rendering is not in progress. */ bool display_renderingInProgress(); #endif /* DISPLAY_H */