logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

qp_surface.h (2968B)


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