LCOV - code coverage report
Current view: top level - zephyr/display - cfb.h Coverage Total Hit
Test: new.info Lines: 61.3 % 31 19
Test Date: 2025-09-05 22:20:39

            Line data    Source code
       1            1 : /*
       2              :  * Copyright (c) 2018 PHYTEC Messtechnik GmbH
       3              :  *
       4              :  * SPDX-License-Identifier: Apache-2.0
       5              :  */
       6              : 
       7              : /**
       8              :  * @file
       9              :  * @brief Public Monochrome Character Framebuffer API
      10              :  */
      11              : 
      12              : #ifndef ZEPHYR_INCLUDE_DISPLAY_CFB_H_
      13              : #define ZEPHYR_INCLUDE_DISPLAY_CFB_H_
      14              : 
      15              : #include <zephyr/device.h>
      16              : #include <zephyr/drivers/display.h>
      17              : #include <zephyr/sys/iterable_sections.h>
      18              : 
      19              : #ifdef __cplusplus
      20              : extern "C" {
      21              : #endif
      22              : 
      23              : /**
      24              :  * @brief Public Monochrome Character Framebuffer API
      25              :  * @defgroup monochrome_character_framebuffer Monochrome Character Framebuffer
      26              :  * @ingroup utilities
      27              :  * @{
      28              :  */
      29              : 
      30            0 : enum cfb_display_param {
      31              :         CFB_DISPLAY_HEIGHT              = 0,
      32              :         CFB_DISPLAY_WIDTH,
      33              :         CFB_DISPLAY_PPT,
      34              :         CFB_DISPLAY_ROWS,
      35              :         CFB_DISPLAY_COLS,
      36              : };
      37              : 
      38            0 : enum cfb_font_caps {
      39              :         CFB_FONT_MONO_VPACKED           = BIT(0),
      40              :         CFB_FONT_MONO_HPACKED           = BIT(1),
      41              :         CFB_FONT_MSB_FIRST              = BIT(2),
      42              : };
      43              : 
      44            0 : struct cfb_font {
      45            0 :         const void *data;
      46            0 :         enum cfb_font_caps caps;
      47            0 :         uint8_t width;
      48            0 :         uint8_t height;
      49            0 :         uint8_t first_char;
      50            0 :         uint8_t last_char;
      51              : };
      52              : 
      53            0 : struct cfb_position {
      54            0 :         uint16_t x;
      55            0 :         uint16_t y;
      56              : };
      57              : 
      58              : /**
      59              :  * @brief Macro for creating a font entry.
      60              :  *
      61              :  * @param _name   Name of the font entry.
      62              :  * @param _width  Width of the font in pixels
      63              :  * @param _height Height of the font in pixels.
      64              :  * @param _caps   Font capabilities.
      65              :  * @param _data   Raw data of the font.
      66              :  * @param _fc     Character mapped to first font element.
      67              :  * @param _lc     Character mapped to last font element.
      68              :  */
      69            1 : #define FONT_ENTRY_DEFINE(_name, _width, _height, _caps, _data, _fc, _lc)      \
      70              :         static const STRUCT_SECTION_ITERABLE(cfb_font, _name) = {              \
      71              :                 .data = _data,                                                 \
      72              :                 .caps = _caps,                                                 \
      73              :                 .width = _width,                                               \
      74              :                 .height = _height,                                             \
      75              :                 .first_char = _fc,                                             \
      76              :                 .last_char = _lc,                                              \
      77              :         }
      78              : 
      79              : /**
      80              :  * @brief Print a string into the framebuffer.
      81              :  *
      82              :  * @param dev Pointer to device structure for driver instance
      83              :  * @param str String to print
      84              :  * @param x Position in X direction of the beginning of the string
      85              :  * @param y Position in Y direction of the beginning of the string
      86              :  *
      87              :  * @return 0 on success, negative value otherwise
      88              :  */
      89            1 : int cfb_print(const struct device *dev, const char *const str, uint16_t x, uint16_t y);
      90              : 
      91              : /**
      92              :  * @brief Print a string into the framebuffer.
      93              :  * For compare to cfb_print, cfb_draw_text accept non tile-aligned coords
      94              :  * and not line wrapping.
      95              :  *
      96              :  * @param dev Pointer to device structure for driver instance
      97              :  * @param str String to print
      98              :  * @param x Position in X direction of the beginning of the string
      99              :  * @param y Position in Y direction of the beginning of the string
     100              :  *
     101              :  * @return 0 on success, negative value otherwise
     102              :  */
     103            1 : int cfb_draw_text(const struct device *dev, const char *const str, int16_t x, int16_t y);
     104              : 
     105              : /**
     106              :  * @brief Draw a point.
     107              :  *
     108              :  * @param dev Pointer to device structure for driver instance
     109              :  * @param pos position of the point
     110              :  *
     111              :  * @return 0 on success, negative value otherwise
     112              :  */
     113            1 : int cfb_draw_point(const struct device *dev, const struct cfb_position *pos);
     114              : 
     115              : /**
     116              :  * @brief Draw a line.
     117              :  *
     118              :  * @param dev Pointer to device structure for driver instance
     119              :  * @param start start position of the line
     120              :  * @param end end position of the line
     121              :  *
     122              :  * @return 0 on success, negative value otherwise
     123              :  */
     124            1 : int cfb_draw_line(const struct device *dev, const struct cfb_position *start,
     125              :                   const struct cfb_position *end);
     126              : 
     127              : /**
     128              :  * @brief Draw a rectangle.
     129              :  *
     130              :  * @param dev Pointer to device structure for driver instance
     131              :  * @param start Top-Left position of the rectangle
     132              :  * @param end Bottom-Right position of the rectangle
     133              :  *
     134              :  * @return 0 on success, negative value otherwise
     135              :  */
     136            1 : int cfb_draw_rect(const struct device *dev, const struct cfb_position *start,
     137              :                   const struct cfb_position *end);
     138              : 
     139              : /**
     140              :  * @brief Draw a circle.
     141              :  *
     142              :  * @param dev Pointer to device structure for driver instance
     143              :  * @param start Center position of the circle
     144              :  * @param radius Radius of the circle
     145              :  *
     146              :  * @return 0 on success, negative value otherwise
     147              :  */
     148            1 : int cfb_draw_circle(const struct device *dev, const struct cfb_position *start, uint16_t radius);
     149              : 
     150              : /**
     151              :  * @brief Clear framebuffer.
     152              :  *
     153              :  * @param dev Pointer to device structure for driver instance
     154              :  * @param clear_display Clear the display as well
     155              :  *
     156              :  * @return 0 on success, negative value otherwise
     157              :  */
     158            1 : int cfb_framebuffer_clear(const struct device *dev, bool clear_display);
     159              : 
     160              : /**
     161              :  * @brief Invert Pixels.
     162              :  *
     163              :  * @param dev Pointer to device structure for driver instance
     164              :  *
     165              :  * @return 0 on success, negative value otherwise
     166              :  */
     167            1 : int cfb_framebuffer_invert(const struct device *dev);
     168              : 
     169              : /**
     170              :  * @brief Invert Pixels in selected area.
     171              :  *
     172              :  * @param dev Pointer to device structure for driver instance
     173              :  * @param x Position in X direction of the beginning of area
     174              :  * @param y Position in Y direction of the beginning of area
     175              :  * @param width Width of area in pixels
     176              :  * @param height Height of area in pixels
     177              :  *
     178              :  * @return 0 on success, negative value otherwise
     179              :  */
     180            1 : int cfb_invert_area(const struct device *dev, uint16_t x, uint16_t y,
     181              :                     uint16_t width, uint16_t height);
     182              : 
     183              : /**
     184              :  * @brief Finalize framebuffer and write it to display RAM,
     185              :  * invert or reorder pixels if necessary.
     186              :  *
     187              :  * @param dev Pointer to device structure for driver instance
     188              :  *
     189              :  * @return 0 on success, negative value otherwise
     190              :  */
     191            1 : int cfb_framebuffer_finalize(const struct device *dev);
     192              : 
     193              : /**
     194              :  * @brief Get display parameter.
     195              :  *
     196              :  * @param dev Pointer to device structure for driver instance
     197              :  * @param cfb_display_param One of the display parameters
     198              :  *
     199              :  * @return Display parameter value
     200              :  */
     201            1 : int cfb_get_display_parameter(const struct device *dev,
     202              :                               enum cfb_display_param);
     203              : 
     204              : /**
     205              :  * @brief Set font.
     206              :  *
     207              :  * @param dev Pointer to device structure for driver instance
     208              :  * @param idx Font index
     209              :  *
     210              :  * @return 0 on success, negative value otherwise
     211              :  */
     212            1 : int cfb_framebuffer_set_font(const struct device *dev, uint8_t idx);
     213              : 
     214              : /**
     215              :  * @brief Set font kerning (spacing between individual letters).
     216              :  *
     217              :  * @param dev Pointer to device structure for driver instance
     218              :  * @param kerning Font kerning
     219              :  *
     220              :  * @return 0 on success, negative value otherwise
     221              :  */
     222            1 : int cfb_set_kerning(const struct device *dev, int8_t kerning);
     223              : 
     224              : /**
     225              :  * @brief Get font size.
     226              :  *
     227              :  * @param dev Pointer to device structure for driver instance
     228              :  * @param idx Font index
     229              :  * @param width Pointers to the variable where the font width will be stored.
     230              :  * @param height Pointers to the variable where the font height will be stored.
     231              :  *
     232              :  * @return 0 on success, negative value otherwise
     233              :  */
     234            1 : int cfb_get_font_size(const struct device *dev, uint8_t idx, uint8_t *width,
     235              :                       uint8_t *height);
     236              : 
     237              : /**
     238              :  * @brief Get number of fonts.
     239              :  *
     240              :  * @param dev Pointer to device structure for driver instance
     241              :  *
     242              :  * @return number of fonts
     243              :  */
     244            1 : int cfb_get_numof_fonts(const struct device *dev);
     245              : 
     246              : /**
     247              :  * @brief Initialize Character Framebuffer.
     248              :  *
     249              :  * @param dev Pointer to device structure for driver instance
     250              :  *
     251              :  * @return 0 on success, negative value otherwise
     252              :  */
     253            1 : int cfb_framebuffer_init(const struct device *dev);
     254              : 
     255              : /**
     256              :  * @brief Deinitialize Character Framebuffer.
     257              :  *
     258              :  * @param dev Pointer to device structure for driver instance
     259              :  */
     260            1 : void cfb_framebuffer_deinit(const struct device *dev);
     261              : 
     262              : #ifdef __cplusplus
     263              : }
     264              : #endif
     265              : 
     266              : /**
     267              :  * @}
     268              :  */
     269              : 
     270              : #endif /* ZEPHYR_INCLUDE_DISPLAY_CFB_H_ */
        

Generated by: LCOV version 2.0-1