qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

qp_surface.h (3471B)


      1 // Copyright 2022 Nick Brassel (@tzarc)
      2 // SPDX-License-Identifier: GPL-2.0-or-later
      3 #pragma once
      4 
      5 #include "qp_internal.h"
      6 
      7 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
      8 // Quantum Painter surface helpers
      9 
     10 // Helper for determining buffer size required for a surface
     11 #define SURFACE_REQUIRED_BUFFER_BYTE_SIZE(w, h, bpp) ((((w) * (h) * (bpp)) + 7) / 8)
     12 
     13 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     14 // Quantum Painter surface configurables (add to your keyboard's config.h)
     15 
     16 #ifndef SURFACE_NUM_DEVICES
     17 /**
     18  * @def This controls the maximum number of surface devices that Quantum Painter can use at any one time.
     19  *      Increasing this number allows for multiple framebuffers to be used. Each requires its own RAM allocation.
     20  */
     21 #    define SURFACE_NUM_DEVICES 1
     22 #endif
     23 
     24 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     25 // Forward declarations
     26 
     27 #ifdef QUANTUM_PAINTER_SURFACE_ENABLE
     28 
     29 // Surface struct
     30 struct surface_painter_device_t;
     31 typedef struct surface_painter_device_t surface_painter_device_t;
     32 
     33 /**
     34  * Factory method for an RGB565 surface (aka framebuffer).
     35  *
     36  * @param panel_width[in] the width of the display panel
     37  * @param panel_height[in] the height of the display panel
     38  * @param buffer[in] pointer to a preallocated uint8_t buffer of size `SURFACE_REQUIRED_BUFFER_BYTE_SIZE(panel_width, panel_height, 16)`
     39  * @return the device handle used with all drawing routines in Quantum Painter
     40  */
     41 painter_device_t qp_make_rgb565_surface(uint16_t panel_width, uint16_t panel_height, void *buffer);
     42 
     43 /**
     44  * Factory method for a 1bpp monochrome surface (aka framebuffer).
     45  *
     46  * @param panel_width[in] the width of the display panel
     47  * @param panel_height[in] the height of the display panel
     48  * @param buffer[in] pointer to a preallocated uint8_t buffer of size `SURFACE_REQUIRED_BUFFER_BYTE_SIZE(panel_width, panel_height, 1)`
     49  * @return the device handle used with all drawing routines in Quantum Painter
     50  */
     51 painter_device_t qp_make_mono1bpp_surface(uint16_t panel_width, uint16_t panel_height, void *buffer);
     52 
     53 /**
     54  * Factory method for an RGB888 surface (aka framebuffer).
     55  *
     56  * @param panel_width[in] the width of the display panel
     57  * @param panel_height[in] the height of the display panel
     58  * @param buffer[in] pointer to a preallocated uint8_t buffer of size `SURFACE_REQUIRED_BUFFER_BYTE_SIZE(panel_width, panel_height, 16)`
     59  * @return the device handle used with all drawing routines in Quantum Painter
     60  */
     61 painter_device_t qp_make_rgb888_surface(uint16_t panel_width, uint16_t panel_height, void *buffer);
     62 
     63 /**
     64  * Helper method to draw the contents of the framebuffer to the target device.
     65  *
     66  * After successful completion, the dirty area is reset.
     67  *
     68  * @param surface[in] the surface to copy from
     69  * @param target[in] the target device to copy into
     70  * @param x[in] the x-location of the original position of the framebuffer
     71  * @param y[in] the y-location of the original position of the framebuffer
     72  * @param entire_surface[in] whether the entire surface should be drawn, instead of just the dirty region
     73  * @return whether the draw operation completed successfully
     74  */
     75 bool qp_surface_draw(painter_device_t surface, painter_device_t target, uint16_t x, uint16_t y, bool entire_surface);
     76 
     77 #endif // QUANTUM_PAINTER_SURFACE_ENABLE